:root {
  --bg0: #081127;
  --bg1: #1b1f4b;
  --bg2: #321f5e;
  --line: #b6e7ff;
  --frame: #0f1433;
  --hud: #101a40;
  --hud-line: #36c8ff;
  --hud-text: #b5f3ff;
  --accent: #ff8c2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Courier New", "Lucida Console", monospace;
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 107, 61, 0.2) 0%, transparent 40%),
    radial-gradient(circle at 75% 16%, rgba(85, 220, 255, 0.2) 0%, transparent 45%),
    linear-gradient(180deg, var(--bg2) 0%, var(--bg1) 45%, var(--bg0) 100%);
  color: var(--hud-text);
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.frame {
  width: min(980px, 96vw);
  position: relative;
  border: 4px solid var(--hud-line);
  box-shadow:
    0 0 0 4px rgba(0, 0, 0, 0.38),
    0 0 34px rgba(41, 201, 255, 0.32),
    12px 12px 0 rgba(0, 0, 0, 0.35);
  background: linear-gradient(180deg, #202a5c 0%, var(--frame) 100%);
}

.hud {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 3px solid var(--hud-line);
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 2px,
      rgba(0, 0, 0, 0.05) 2px,
      rgba(0, 0, 0, 0.05) 4px
    ),
    var(--hud);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-shadow: 0 0 8px rgba(99, 227, 255, 0.55);
}

.hud > div {
  white-space: nowrap;
}

.hud-left {
  justify-self: start;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.hud-center {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.hud-right {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

#score {
  text-align: left;
}

#timer {
  min-width: 0;
  text-align: left;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  box-shadow: none;
}

#muteAllBtn {
  position: absolute;
  top: 2px;
  right: 8px;
  z-index: 6;
}

.hud-audio-btn {
  display: inline-flex;
}

.hud-audio-btn.is-muted {
  background-image: url("images/speakermute.png");
}

#state {
  display: none;
}

#combo {
  justify-self: center;
  min-width: 210px;
  text-align: center;
  padding: 6px 12px;
  border: 2px solid #a9f5ff;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 193, 104, 0.25), transparent 48%),
    linear-gradient(180deg, rgba(46, 84, 162, 0.92) 0%, rgba(22, 48, 101, 0.92) 100%);
  box-shadow:
    inset 0 0 12px rgba(66, 224, 255, 0.24),
    0 0 14px rgba(110, 240, 255, 0.2);
  color: #fff5bf;
  letter-spacing: 1.3px;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#comboText {
  position: relative;
  z-index: 1;
}

.combo-progress {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  position: relative;
  z-index: 1;
}

.combo-step {
  width: 20px;
  height: 16px;
  border-radius: 2px;
  position: relative;
  border: 1px solid #244e58;
  background:
    linear-gradient(180deg, rgba(16, 40, 48, 0.95) 0%, rgba(9, 24, 30, 0.98) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(34, 90, 103, 0.55),
    inset 0 -1px 2px rgba(0, 0, 0, 0.58),
    0 0 4px rgba(0, 0, 0, 0.48);
  transition: background-color 170ms ease, box-shadow 170ms ease, border-color 170ms ease, transform 170ms ease, filter 170ms ease, opacity 170ms ease;
  opacity: 0.84;
}

.combo-step::before {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 2px;
  height: 2px;
  border-radius: 2px;
  background: rgba(196, 247, 255, 0.26);
}

.combo-step::after {
  content: "";
  position: absolute;
  inset: -5px -4px;
  border-radius: 5px;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(106, 242, 255, 0.42) 0%, rgba(37, 196, 230, 0.08) 65%, rgba(37, 196, 230, 0) 100%);
  transition: opacity 170ms ease;
}

.combo-step.is-active {
  border-color: #7bfbff;
  background:
    linear-gradient(180deg, rgba(229, 254, 255, 0.98) 0%, rgba(80, 239, 255, 0.95) 45%, rgba(0, 205, 242, 0.92) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(205, 255, 255, 0.7),
    inset 0 -1px 1px rgba(2, 81, 96, 0.45),
    0 0 10px rgba(89, 246, 255, 0.92),
    0 0 20px rgba(52, 225, 255, 0.78),
    0 0 30px rgba(26, 188, 245, 0.58);
  transform: translateY(-1px);
  animation: combo-segment-glow 1.3s ease-in-out infinite, combo-segment-glitch 2s steps(1, end) infinite;
  filter: saturate(1.15);
  opacity: 1;
}

.combo-step.is-active::after {
  opacity: 0.95;
}

#combo.is-fever .combo-step {
  border-color: #ff7fbd;
  background:
    linear-gradient(180deg, rgba(255, 223, 246, 0.98) 0%, rgba(255, 116, 192, 0.95) 46%, rgba(233, 42, 136, 0.94) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 221, 245, 0.62),
    inset 0 -1px 1px rgba(112, 16, 66, 0.48),
    0 0 11px rgba(255, 109, 179, 0.88),
    0 0 22px rgba(255, 67, 150, 0.78),
    0 0 32px rgba(224, 28, 132, 0.62);
  animation-duration: 1.05s, 1.85s;
}

#combo.is-fever .combo-step::after {
  background: radial-gradient(ellipse at center, rgba(255, 126, 199, 0.52) 0%, rgba(255, 63, 153, 0.1) 66%, rgba(255, 63, 153, 0) 100%);
}

.combo-step.is-active:nth-child(2n) {
  animation-delay: 0.2s;
}

.combo-step.is-active:nth-child(3n) {
  animation-delay: 0.38s;
}

#combo::before,
#combo::after {
  content: "✦";
  position: absolute;
  opacity: 0;
  color: #fff8d1;
  text-shadow: 0 0 10px rgba(255, 247, 183, 0.7);
}

#combo::before {
  left: 10px;
  top: 4px;
}

#combo::after {
  right: 10px;
  bottom: 3px;
}

#combo.combo-up {
  animation: combo-pop 360ms ease-out;
}

#combo.combo-up::before {
  animation: combo-spark-left 520ms ease-out;
}

#combo.combo-up::after {
  animation: combo-spark-right 520ms ease-out;
}

.mobile-controls-row {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 48px;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}

.controls {
  display: flex;
  pointer-events: auto;
}

.controls-right {
  justify-content: flex-end;
}

.controls-stack {
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.charge-btn {
  display: none;
  width: 82px;
  height: 82px;
  border-radius: 8px;
  border-color: #ff8b8b;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 187, 187, 0.44) 0%, rgba(255, 187, 187, 0) 62%),
    linear-gradient(180deg, #9f2424 0%, #6d1717 100%);
  color: #ffe8e8;
  box-shadow:
    0 0 0 2px rgba(255, 116, 116, 0.2),
    0 0 16px rgba(255, 82, 82, 0.36);
  animation: charge-radiate 1.4s ease-out infinite;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  padding: 8px;
  white-space: normal;
  line-height: 1.1;
  text-align: center;
}

.charge-btn.is-charging {
  border-color: #ffd56a;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 236, 173, 0.46) 0%, rgba(255, 236, 173, 0) 62%),
    linear-gradient(180deg, #5c4a14 0%, #3d2f0d 100%);
  color: #ffefbf;
  box-shadow:
    0 0 0 2px rgba(255, 205, 102, 0.22),
    0 0 18px rgba(255, 205, 102, 0.36);
}

.toggle-btn {
  border: 2px solid #88efff;
  background: linear-gradient(180deg, #16356a 0%, #0f244a 100%);
  color: #bff6ff;
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  padding: 7px 10px;
  cursor: pointer;
}

.toggle-btn.is-muted {
  border-color: #ff8d8d;
  background: linear-gradient(180deg, #6c1f2a 0%, #42151d 100%);
  color: #ffd6d6;
}

.toggle-btn.is-active {
  border-color: #ffd790;
  background: linear-gradient(180deg, #714716 0%, #4c2e0f 100%);
  color: #ffe8c4;
  box-shadow: 0 0 12px rgba(255, 200, 100, 0.28);
}

.audio-icon-btn {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-image: url("images/speaker.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 44px 44px;
  box-shadow: none;
  cursor: pointer;
  font-size: 0;
  line-height: 0;
}

.audio-icon-btn.is-muted {
  background-image: url("images/speakermute.png");
}

.audio-icon-btn:hover {
  filter: brightness(1.08);
}

.audio-icon-btn:focus-visible {
  outline: 2px solid rgba(146, 222, 255, 0.92);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.splash {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 139, 78, 0.32) 0%, transparent 36%),
    radial-gradient(circle at 80% 24%, rgba(74, 242, 255, 0.28) 0%, transparent 42%),
    rgba(7, 12, 32, 0.86);
}

.splash.hidden {
  display: none;
}

.splash-card {
  width: min(560px, 90%);
  border: 3px solid #95f3ff;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 2px,
      rgba(0, 0, 0, 0.08) 2px,
      rgba(0, 0, 0, 0.08) 4px
    ),
    #131f4a;
  box-shadow:
    0 0 0 3px rgba(0, 0, 0, 0.45),
    0 0 34px rgba(103, 233, 255, 0.28);
  padding: 20px 20px 16px;
  text-align: center;
  text-transform: uppercase;
}

.splash-kicker {
  color: #9eeeff;
  letter-spacing: 1.2px;
  font-size: 12px;
  margin-bottom: 4px;
}

.splash h1 {
  margin: 0 0 8px;
  line-height: 0;
}

.splash h1.stinger {
  animation: splash-stinger 1150ms ease-out;
}

.splash-title-image {
  display: block;
  width: min(440px, 92%);
  height: auto;
  margin: 0 auto;
}

.splash p {
  margin: 6px 0;
  color: #c7f7ff;
  font-size: 12px;
  letter-spacing: 0.6px;
}

.splash-subtitle {
  margin: 0 0 10px;
  color: #d7f6ff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-shadow:
    0 0 5px rgba(215, 246, 255, 0.7),
    0 0 12px rgba(101, 235, 255, 0.5),
    0 0 22px rgba(56, 198, 255, 0.35);
}

.splash-start {
  margin-top: 0;
}

.splash-start:disabled {
  opacity: 0.5;
  cursor: default;
}

.splash-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.level-label {
  color: #c7f7ff;
  font-size: 12px;
  letter-spacing: 0.7px;
}

.level-select {
  border: 2px solid #88efff;
  background: linear-gradient(180deg, #16356a 0%, #0f244a 100%);
  color: #bff6ff;
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 6px 8px;
  box-shadow: 0 0 10px rgba(78, 226, 255, 0.28);
  outline: none;
}

.level-select:focus {
  border-color: #ffd790;
  box-shadow: 0 0 14px rgba(255, 202, 104, 0.36);
}

.level-select option {
  background: #102651;
  color: #bff6ff;
}

.level-select:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.run-summary {
  margin: 12px 0 6px;
  color: #ffe4b0;
  font-size: 12px;
  letter-spacing: 0.8px;
}

.score-submit {
  margin: 6px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.initials-input {
  width: 74px;
  border: 2px solid #88efff;
  background: linear-gradient(180deg, #16356a 0%, #0f244a 100%);
  color: #fff2cc;
  font-family: "Courier New", "Lucida Console", monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  padding: 4px 6px;
  outline: none;
}

.initials-input:focus {
  border-color: #ffd790;
  box-shadow: 0 0 12px rgba(255, 200, 100, 0.32);
}

.score-submit-status {
  margin: 8px 0 0;
  min-height: 16px;
  color: #bdeeff;
  font-size: 11px;
  letter-spacing: 0.6px;
}

.score-submit-status.error {
  color: #ffc6c6;
}

.leaderboard-wrap {
  margin-top: 12px;
  border: 2px solid #6bd7ff;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 2px,
      rgba(0, 0, 0, 0.06) 2px,
      rgba(0, 0, 0, 0.06) 4px
    ),
    rgba(9, 22, 55, 0.9);
  padding: 10px 12px;
}

.leaderboard-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.leaderboard-tab {
  padding: 5px 10px;
  font-size: 11px;
}

.leaderboard-title {
  color: #ffe0a2;
  font-size: 12px;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.leaderboard-list {
  margin: 0;
  padding: 0 0 0 20px;
  color: #d6f8ff;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  min-height: 108px;
}

.leaderboard-status {
  margin: 6px 0 0;
  color: #9bdff6;
  font-size: 11px;
  letter-spacing: 0.6px;
}

@keyframes splash-stinger {
  0% {
    transform: scale(0.82);
    opacity: 0;
    letter-spacing: 8px;
    filter: blur(2px);
  }
  55% {
    transform: scale(1.08);
    opacity: 1;
    letter-spacing: 3px;
    filter: blur(0);
  }
  100% {
    transform: scale(1);
    opacity: 1;
    letter-spacing: 2px;
    filter: blur(0);
  }
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

.help {
  padding: 8px 14px 12px;
  border-top: 3px solid var(--hud-line);
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 2px,
      rgba(0, 0, 0, 0.05) 2px,
      rgba(0, 0, 0, 0.05) 4px
    ),
    var(--hud);
  color: #9de5ff;
  font-size: 12px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

@media (max-width: 760px) {
  .frame {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .hud {
    grid-template-columns: 1fr;
    justify-items: center;
    row-gap: 7px;
    font-size: 12px;
  }

  .hud-left,
  .hud-right {
    justify-self: center;
  }

  #combo {
    min-width: 190px;
  }

  .hud-right {
    gap: 8px;
  }

  .mobile-controls-row {
    position: static;
    order: 3;
    width: 100%;
    margin: 10px 0 12px;
    padding: 0 12px;
    align-items: flex-end;
    pointer-events: auto;
  }

  .help {
    display: none;
  }

  .controls {
    z-index: 1;
  }

  #state {
    display: none;
  }

  .controls-right {
    align-items: flex-end;
  }

  .charge-btn {
    display: inline-block;
    font-size: 12px;
    letter-spacing: 0.6px;
  }
}

@keyframes charge-radiate {
  0% {
    box-shadow:
      0 0 0 0 rgba(255, 120, 120, 0.3),
      0 0 16px rgba(255, 82, 82, 0.36);
  }
  70% {
    box-shadow:
      0 0 0 11px rgba(255, 120, 120, 0),
      0 0 22px rgba(255, 120, 120, 0.46);
  }
  100% {
    box-shadow:
      0 0 0 0 rgba(255, 120, 120, 0),
      0 0 16px rgba(255, 82, 82, 0.36);
  }
}

@keyframes combo-pop {
  0% {
    transform: scale(0.9);
    box-shadow:
      inset 0 0 12px rgba(66, 224, 255, 0.2),
      0 0 8px rgba(110, 240, 255, 0.16);
  }
  55% {
    transform: scale(1.08);
    box-shadow:
      inset 0 0 18px rgba(255, 209, 125, 0.35),
      0 0 20px rgba(255, 226, 140, 0.34);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes combo-spark-left {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5); }
  40% { opacity: 1; transform: translate(-5px, -6px) scale(1.05); }
  100% { opacity: 0; transform: translate(-11px, -11px) scale(0.75); }
}

@keyframes combo-spark-right {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5); }
  40% { opacity: 1; transform: translate(6px, 5px) scale(1.05); }
  100% { opacity: 0; transform: translate(11px, 10px) scale(0.75); }
}

@keyframes combo-segment-glow {
  0% {
    box-shadow:
      inset 0 0 0 1px rgba(205, 255, 255, 0.62),
      inset 0 -1px 1px rgba(2, 81, 96, 0.45),
      0 0 9px rgba(89, 246, 255, 0.82),
      0 0 18px rgba(52, 225, 255, 0.66),
      0 0 26px rgba(26, 188, 245, 0.5);
  }
  55% {
    box-shadow:
      inset 0 0 0 1px rgba(225, 255, 255, 0.74),
      inset 0 -1px 1px rgba(2, 81, 96, 0.52),
      0 0 13px rgba(118, 250, 255, 0.98),
      0 0 26px rgba(68, 231, 255, 0.84),
      0 0 38px rgba(29, 193, 250, 0.66);
  }
  100% {
    box-shadow:
      inset 0 0 0 1px rgba(205, 255, 255, 0.62),
      inset 0 -1px 1px rgba(2, 81, 96, 0.45),
      0 0 9px rgba(89, 246, 255, 0.82),
      0 0 18px rgba(52, 225, 255, 0.66),
      0 0 26px rgba(26, 188, 245, 0.5);
  }
}

@keyframes combo-segment-glitch {
  0%, 84%, 100% {
    transform: translateY(-1px) scaleX(1);
    filter: saturate(1.15) brightness(1);
  }
  85% {
    transform: translateY(-1px) translateX(1px) scaleX(1.04);
    filter: saturate(1.2) brightness(1.06);
  }
  87% {
    transform: translateY(-1px) translateX(-1px) scaleX(0.97);
    filter: saturate(1.05) brightness(0.95);
  }
  90% {
    transform: translateY(-1px) scaleX(1.02);
    filter: saturate(1.22) brightness(1.08);
  }
}
