:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --bg: #060610;
  --panel: rgba(11, 14, 24, 0.88);
  --panel-soft: rgba(15, 19, 33, 0.92);
  --text: #f4f3ff;
  --muted: #b9b6d9;
  --border: rgba(155, 195, 255, 0.25);
  --neon-pink: #ff4fd8;
  --neon-cyan: #3de7ff;
  --fire-amber: #ffb454;
  --primary: linear-gradient(135deg, #ff6df5, #3de7ff);
  --shadow: 0 24px 40px rgba(5, 6, 15, 0.7);
  --glow: radial-gradient(800px 420px at 50% -120px, rgba(255, 93, 217, 0.2), transparent 60%);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

html,
body {
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  position: relative;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 20%, rgba(61, 231, 255, 0.12), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(255, 79, 216, 0.12), transparent 50%),
    radial-gradient(circle at 50% 80%, rgba(255, 180, 84, 0.15), transparent 55%),
    linear-gradient(160deg, #060610, #120c24 40%, #120e2d 70%, #04040c);
  z-index: -2;
  animation: drift 20s ease-in-out infinite alternate;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.03) 0,
    rgba(255, 255, 255, 0.03) 2px,
    rgba(0, 0, 0, 0.02) 2px,
    rgba(0, 0, 0, 0.02) 4px
  );
  mix-blend-mode: soft-light;
  opacity: 0.3;
  z-index: -1;
}

@keyframes drift {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    transform: translate3d(-2%, 2%, 0) scale(1.02);
  }
}

.app {
  width: min(480px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px
    calc(14px + env(safe-area-inset-bottom, 0px));
  gap: 12px;
  background: var(--panel);
  border: 1px solid rgba(86, 175, 255, 0.25);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.pulse {
  animation: pulseHit 120ms ease-out;
}

@keyframes pulseHit {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.995);
  }
  100% {
    transform: scale(1);
  }
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  flex-wrap: wrap;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--neon-cyan);
  text-shadow: 0 0 12px rgba(61, 231, 255, 0.6);
}

.marquee {
  position: relative;
}

.marquee::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--neon-pink), var(--neon-cyan), transparent);
  opacity: 0.7;
}

.brand-subline {
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  text-shadow: 0 0 10px rgba(61, 231, 255, 0.25);
}

.station-line {
  animation: station-flicker 7s ease-in-out infinite;
}

@keyframes station-flicker {
  0%,
  100% {
    opacity: 0.92;
  }
  48% {
    opacity: 0.85;
  }
  50% {
    opacity: 0.7;
  }
  52% {
    opacity: 0.88;
  }
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(10, 16, 34, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 18px rgba(4, 6, 18, 0.45);
  font-size: 0.78rem;
  position: relative;
  overflow: visible;
}

.scoreboard strong {
  font-size: 1rem;
}

.best-score {
  font-size: 0.75rem;
  color: var(--muted);
}

.gate-charge {
  font-size: 0.65rem;
  color: var(--fire-amber);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.pause-button {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
}

.score-fireworks {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 8px;
  height: 8px;
  pointer-events: none;
  opacity: 0;
}

.score-fireworks::before,
.score-fireworks::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow:
    0 -12px #ff6b6b,
    10px -6px #ffd93d,
    12px 6px #6c63ff,
    0 12px #4dd599,
    -12px 6px #4dabf7,
    -10px -6px #ff8fab;
  opacity: 0;
  transform: scale(0.4);
}

.score-fireworks::after {
  box-shadow:
    0 -16px #f9c74f,
    14px -2px #f94144,
    12px 12px #577590,
    0 16px #43aa8b,
    -12px 12px #577590,
    -14px -2px #f3722c;
  transform: scale(0.3);
}

.score-fireworks.is-active::before {
  animation: score-burst 0.7s ease-out;
}

.score-fireworks.is-active::after {
  animation: score-burst 0.7s ease-out 0.05s;
}

@keyframes score-burst {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

.stage {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.screen {
  width: 100%;
  height: 100%;
  background: var(--panel-soft);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: translateY(18px) scale(0.98);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.screen.is-active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.screen--game {
  justify-content: flex-start;
  gap: 12px;
  position: relative;
}

.screen h1,
.screen h2 {
  margin: 0;
  font-weight: 700;
}

.screen p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

button {
  border: none;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    filter 0.15s ease;
}

button:active {
  transform: translateY(2px) scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.primary {
  background: var(--primary);
  color: #05040d;
  box-shadow: 0 12px 28px rgba(255, 79, 216, 0.35);
}

.primary:hover {
  filter: brightness(1.05);
}

.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
}

#gameCanvas {
  width: 100%;
  max-width: 420px;
  max-height: min(58vh, 420px);
  aspect-ratio: 1;
  border-radius: 18px;
  background: rgba(6, 6, 16, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: block;
  margin-top: 6px;
  touch-action: none;
  box-shadow:
    0 0 0 1px rgba(255, 79, 216, 0.15),
    0 20px 40px rgba(5, 5, 20, 0.6);
}

#gameCanvas:focus-visible {
  outline: 2px solid rgba(61, 231, 255, 0.7);
  outline-offset: 3px;
}

#gameCanvas:active {
  outline: none;
}

.game-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

button {
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 8, 16, 0.6);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  background: rgba(14, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 20px 28px;
  box-shadow: 0 16px 30px rgba(4, 6, 18, 0.55);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  min-width: min(220px, 90%);
}

.overlay--countdown .overlay-card {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text);
}

.overlay--pause h3 {
  margin: 0;
  font-size: 1.3rem;
}

.toast {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -10px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(11, 16, 30, 0.78);
  border: 1px solid rgba(61, 231, 255, 0.35);
  color: var(--text);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow:
    0 8px 20px rgba(10, 16, 34, 0.45),
    0 0 14px rgba(61, 231, 255, 0.2);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.is-active {
  opacity: 1;
  transform: translate(-50%, 0);
}

.final-score {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--neon-pink);
}

.summary-new-best {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--neon-cyan);
  text-shadow: 0 0 12px rgba(61, 231, 255, 0.45);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.summary-meta {
  width: 100%;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.summary-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 110px;
}

.summary-stat strong {
  color: var(--text);
  font-size: 1rem;
}

.menu-hero {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-card {
  width: min(360px, 100%);
  background: rgba(15, 19, 33, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 24px;
  padding: 22px;
  box-shadow:
    0 0 20px rgba(61, 231, 255, 0.15),
    0 12px 24px rgba(5, 6, 18, 0.55);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.65rem;
  color: var(--neon-cyan);
}

.hero-tagline {
  font-size: 1.1rem;
  color: var(--text);
  text-shadow: 0 0 12px rgba(255, 79, 216, 0.35);
}

.menu-stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.menu-stats {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  align-self: center;
}

.menu-profile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
}

.menu-profile strong {
  font-size: 1.05rem;
  color: var(--text);
}

.leaderboard-section {
  width: 100%;
  display: flex;
  justify-content: center;
}

.leaderboard-card {
  width: min(360px, 100%);
  background: rgba(14, 18, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 12px 22px rgba(4, 6, 18, 0.55);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.leaderboard-status {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.leaderboard-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.9rem;
  color: var(--text);
}

.leaderboard-row span:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.leaderboard-head {
  background: rgba(61, 231, 255, 0.12);
  border-color: rgba(61, 231, 255, 0.3);
  color: var(--text);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.leaderboard-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
}

.input-field {
  width: 100%;
}

.input-field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(8, 10, 20, 0.8);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.input-field input:focus-visible {
  outline: 2px solid rgba(61, 231, 255, 0.6);
  outline-offset: 2px;
}

.form-hint {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.warning-text {
  font-size: 0.8rem;
  color: var(--fire-amber);
  text-align: center;
}

.score-submit {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.menu-toggles .ghost {
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.menu-toggles {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.how-to-play {
  width: 100%;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: left;
}

.how-to-play summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  outline: none;
}

.how-to-play p {
  margin: 8px 0 0;
  color: var(--muted);
}

.menu-footer {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.version {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.storm-overlay {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    130deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.02) 8px,
    rgba(0, 0, 0, 0.03) 16px
  );
  mix-blend-mode: screen;
  animation: storm-drift 1.4s linear infinite;
  transition: opacity 0.3s ease;
}

.storm-active .storm-overlay {
  opacity: 0.45;
}

.storm-active #gameCanvas {
  filter: brightness(0.75) saturate(0.9);
}

.storm-active {
  animation: storm-shake 0.6s ease-in-out infinite;
}

@keyframes storm-drift {
  0% {
    transform: translate3d(-10%, -10%, 0);
  }
  100% {
    transform: translate3d(10%, 10%, 0);
  }
}

@keyframes storm-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  25% {
    transform: translate3d(1px, -1px, 0);
  }
  50% {
    transform: translate3d(-1px, 1px, 0);
  }
  75% {
    transform: translate3d(1px, 1px, 0);
  }
}

@media (min-width: 600px) {
  .menu-actions {
    flex-direction: row;
    justify-content: center;
  }

  button {
    min-width: 160px;
  }

  /* Desktop-only scroll to avoid iOS Safari overflow painting issues. */
  .leaderboard-body {
    max-height: min(240px, 40vh);
    overflow-y: auto;
  }
}

@media (max-width: 480px) {
  .app {
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px
      calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .hud {
    padding: 4px 6px;
    gap: 8px;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .scoreboard {
    width: 100%;
    justify-content: space-between;
    gap: 6px 10px;
  }

  .screen {
    padding: 16px;
    gap: 14px;
  }

  .hero-card {
    padding: 18px;
    gap: 12px;
  }

  .hero-tagline {
    font-size: 1rem;
  }

  .menu-toggles .ghost {
    font-size: 0.8rem;
  }

  .game-hint {
    font-size: 0.78rem;
  }

  #gameCanvas {
    max-height: min(55vh, 360px);
  }

  .brand-subline {
    font-size: 0.55rem;
  }
}

@supports (height: 100dvh) {
  .app {
    min-height: 100dvh;
  }
}

/* Keep layout clipping defaults to preserve the iPhone-safe proportions. */
