/* kidenv design system — the polished, kid-friendly baseline every app starts from.
   Build to these tokens and components: it's how a generated app reaches "app-store" polish.
   See DESIGN.md for the rules and CHECKLIST.md for the gate. Vanilla CSS, zero deps. */

/* ══ Mathvaders theme override ══════════════════════════════════════════════
   Deep-space arcade night palette. Neon green lasers, hot pink accents,
   cosmic purple surfaces. Distinct from every other kidenv app.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* Mathvaders custom tokens */
  --neon:         #39ff14;   /* electric green — lasers, primary highlights */
  --neon-ink:     #001800;   /* text on neon */
  --hot:          #ff2dbd;   /* hot pink — streaks, bonus, wave banners */
  --cosmic:       #6b2fff;   /* cosmic purple — brand override */
  --star-bg:      #07050f;   /* near-black starfield */
  --arena-bg:     #0c0a1a;   /* slightly lighter arena background */
  --hud-bg:       rgba(6, 4, 20, 0.92);
  --alien-glow:   rgba(57, 255, 20, 0.35);
  --alien-wrong-glow: rgba(255, 45, 45, 0.55);

  /* --- Palette: bright and friendly, never harsh. Tuned for AA contrast on --surface. --- */
  --brand:        #6b2fff;   /* cosmic purple */
  --brand-ink:    #ffffff;   /* text on --brand */
  --accent:       #ff5fa2;   /* playful highlight */
  --sun:          #ffb020;   /* warm secondary (amber) */

  /* Feedback colors — encouraging, not shaming. "Try again" is a calm slate, never red. */
  --go:           #1faa59;   /* start / correct / success (green) */
  --go-ink:       #ffffff;
  --stop:         #ff6b5e;   /* stop / pause (warm coral, not alarm-red) */
  --stop-ink:     #3a0d09;
  --calm:         #6b7a99;   /* gentle "try again" — neutral, low-anxiety */

  /* Surfaces & ink (light theme defaults; dark overrides below). */
  --surface:      #fbf7ff;   /* page background */
  --card:         #ffffff;   /* raised surface */
  --ink:          #1b1633;   /* primary text — ~13:1 on --surface */
  --ink-soft:     #4b4668;   /* secondary text — ~6:1 on --surface */
  --line:         #e7e0f5;   /* hairlines / borders */

  /* Shape, space, type. Generous and rounded reads as friendly. */
  --radius:       18px;
  --radius-lg:    28px;
  --tap-min:      64px;                       /* min touch target for kid hands (> WCAG 44px) */
  --tap-primary:  clamp(72px, 11vh, 104px);   /* hero buttons */
  --gap:          clamp(0.75rem, 2.5vw, 1.25rem);
  --pad:          clamp(1rem, 4vw, 2rem);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --shadow:    0 6px 20px rgba(40, 20, 90, 0.12);
  --shadow-lg: 0 14px 40px rgba(40, 20, 90, 0.20);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #131022;
    --card:    #1f1a38;
    --ink:     #f3f0ff;
    --ink-soft:#bfb6e0;
    --line:    #322b54;
    --shadow:    0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  font: clamp(16px, 2.4vw, 19px)/1.5 var(--font);
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 50% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 60%),
    var(--surface);
  /* Respect notches / gesture bars on phones. */
  padding:
    max(var(--pad), env(safe-area-inset-top))
    max(var(--pad), env(safe-area-inset-right))
    max(var(--pad), env(safe-area-inset-bottom))
    max(var(--pad), env(safe-area-inset-left));
  display: grid;
  place-items: center;
}

/* --- Layout helpers --- */
.app { width: min(36rem, 100%); display: grid; gap: var(--gap); justify-items: center; text-align: center; }
.stack { display: grid; gap: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: var(--gap); justify-content: center; }

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--pad);
  width: 100%;
}

/* --- Typography --- */
h1 { font-size: clamp(2rem, 7vw, 3.25rem); line-height: 1.1; margin: 0 0 0.25em; }
h2 { font-size: clamp(1.3rem, 4.5vw, 1.9rem); margin: 0 0 0.4em; }
p  { color: var(--ink-soft); margin: 0.4em 0; }
.lead { font-size: 1.1em; color: var(--ink-soft); }

/* --- Buttons: big, rounded, obvious. The core kid interaction. --- */
.btn {
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  color: var(--brand-ink);
  background: var(--brand);
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0 clamp(1.1rem, 4vw, 1.8rem);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.05); box-shadow: var(--shadow-lg); }
.btn:active { transform: translateY(2px) scale(0.98); }
.btn:focus-visible { outline: 4px solid color-mix(in srgb, var(--brand) 55%, white); outline-offset: 3px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; box-shadow: none; filter: none; transform: none; }

/* Big hero buttons (Start/Stop/Reset-style primary actions). */
.btn-xl { min-height: var(--tap-primary); font-size: clamp(1.1rem, 3.5vw, 1.5rem); border-radius: var(--radius-lg); padding: 0 clamp(1.5rem, 6vw, 2.5rem); }

/* Semantic variants. */
.btn-go   { background: var(--go);   color: var(--go-ink); }
.btn-stop { background: var(--stop); color: var(--stop-ink); }
.btn-cool { background: var(--sun);  color: #3a2600; }
.btn-ghost { background: color-mix(in srgb, var(--brand) 12%, var(--card)); color: var(--ink); box-shadow: none; }

/* --- Big readout (timers, scores, counters) --- */
.display {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(3rem, 16vw, 6rem);
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ink);
}

/* --- Motion: opt every animation out for kids/parents who need calm. --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* A friendly little celebratory pop helper (used sparingly; honors reduced-motion above). */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
.pop { animation: pop 0.4s ease; }

/* --- Settings kit ---------------------------------------------------------------------------
   Every app ships a tweakable Settings panel (DESIGN.md rule 12). These are the on-token building
   blocks: a gear button that opens a .sheet (a styled <dialog>), with big kid-friendly controls —
   a .range slider, a .switch toggle, and a .segmented picker — laid out as .field rows. Theme them
   per app, but keep the tokens so contrast/size stay correct. All animation honors reduced-motion. */

/* Round icon button (the ⚙ gear). Still meets the tap-min target. */
.btn-icon {
  -webkit-tap-highlight-color: transparent;
  appearance: none; border: 0; cursor: pointer; font: inherit;
  width: var(--tap-min); height: var(--tap-min); min-width: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.6rem; line-height: 1; border-radius: 50%;
  color: var(--ink); background: color-mix(in srgb, var(--brand) 12%, var(--card));
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn-icon:hover { filter: brightness(1.05); }
.btn-icon:active { transform: scale(0.94); }
.btn-icon:focus-visible { outline: 4px solid color-mix(in srgb, var(--brand) 55%, white); outline-offset: 3px; }

/* Settings sheet — a centered <dialog>. Use dialog.showModal()/close() to open/dismiss. */
.sheet {
  border: 0; padding: 0; color: var(--ink); background: transparent;
  max-width: min(30rem, 94vw); width: 100%;
}
.sheet::backdrop { background: rgba(20, 12, 45, 0.55); backdrop-filter: blur(2px); }
.sheet .sheet-body {
  background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: var(--pad); display: grid; gap: var(--gap); text-align: left;
}
.sheet[open] { animation: sheet-in 0.18s ease; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

/* A labelled control row. */
.field { display: grid; gap: 0.4rem; }
.field > .field-label { font-weight: 800; color: var(--ink); }
.field > .field-hint { font-size: 0.85em; color: var(--ink-soft); }

/* Big, friendly range slider. */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 36px; background: transparent; cursor: pointer; }
.range:focus-visible { outline: 4px solid color-mix(in srgb, var(--brand) 55%, white); outline-offset: 4px; border-radius: var(--radius); }
.range::-webkit-slider-runnable-track { height: 14px; border-radius: 999px; background: color-mix(in srgb, var(--brand) 22%, var(--card)); }
.range::-moz-range-track { height: 14px; border-radius: 999px; background: color-mix(in srgb, var(--brand) 22%, var(--card)); }
.range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 32px; height: 32px; margin-top: -9px; border-radius: 50%; background: var(--brand); box-shadow: var(--shadow); border: 3px solid var(--card); }
.range::-moz-range-thumb { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); box-shadow: var(--shadow); border: 3px solid var(--card); }

/* Toggle switch (e.g. Sound on/off). Markup: <button class="switch" role="switch" aria-checked="true">. */
.switch {
  appearance: none; border: 0; cursor: pointer; position: relative;
  width: 68px; height: 38px; min-width: 68px; border-radius: 999px; padding: 0;
  background: var(--calm); box-shadow: inset 0 1px 4px rgba(0,0,0,0.25);
  transition: background 0.15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 30px; height: 30px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.switch[aria-checked="true"] { background: var(--go); }
.switch[aria-checked="true"]::after { transform: translateX(30px); }
.switch:focus-visible { outline: 4px solid color-mix(in srgb, var(--brand) 55%, white); outline-offset: 3px; }

/* Segmented control (e.g. Easy | Medium | Hard). Buttons inside get .seg; active uses aria-pressed. */
.segmented { display: flex; gap: 6px; background: color-mix(in srgb, var(--brand) 10%, var(--card)); padding: 6px; border-radius: var(--radius); }
.segmented .seg {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 800; flex: 1;
  min-height: 52px; border-radius: calc(var(--radius) - 6px); color: var(--ink-soft); background: transparent;
}
.segmented .seg[aria-pressed="true"] { color: var(--brand-ink); background: var(--brand); box-shadow: var(--shadow); }
.segmented .seg:focus-visible { outline: 4px solid color-mix(in srgb, var(--brand) 55%, white); outline-offset: 2px; }

/* ══════════════════════════════════════════════════════════════════════════════
   MATHVADERS — App-specific game styles
   Deep-space arcade theme: starfield, aliens, lasers, HUD.
   ══════════════════════════════════════════════════════════════════════════════ */

/* Reset body for full-screen game layout */
body {
  background: var(--star-bg);
  padding: 0;
  display: block;
  overflow: hidden;
  height: 100svh;
  max-height: 100svh;
}

/* ── Screen management ───────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--star-bg);
  overflow: hidden;
}
.screen.active {
  display: flex;
}

/* ── Starfield background ────────────────────────────────────────────────── */
.stars, .stars-arena {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.star {
  position: absolute;
  border-radius: 50%;
  background: #ffffff;
  opacity: 0.7;
}
/* Stars are positioned and sized via JS at runtime for variety */

/* ── Title screen ────────────────────────────────────────────────────────── */
#screen-title {
  background: radial-gradient(ellipse at 50% 30%, #160d36 0%, var(--star-bg) 70%);
}

.title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1.5rem, 4vh, 2.5rem);
  padding: var(--pad);
  text-align: center;
}

.title-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.logo-alien {
  font-size: clamp(4rem, 15vw, 7rem);
  animation: bob 2.2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px var(--neon));
}

@keyframes bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-12px) scale(1.04); }
}

.game-title {
  font-size: clamp(2.8rem, 11vw, 5.5rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--neon);
  text-shadow: 0 0 20px rgba(57, 255, 20, 0.7), 0 0 40px rgba(57, 255, 20, 0.3);
  margin: 0;
  font-family: monospace, "Courier New", serif;
  line-height: 1;
}

.game-sub {
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: var(--hot);
  margin: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.btn-neon {
  background: var(--neon);
  color: var(--neon-ink);
  box-shadow: 0 0 20px rgba(57, 255, 20, 0.5), var(--shadow);
  font-family: monospace, "Courier New", serif;
  letter-spacing: 0.06em;
  font-weight: 900;
  font-size: clamp(1rem, 4vw, 1.4rem);
  text-transform: uppercase;
}
.btn-neon:hover { filter: brightness(1.1); box-shadow: 0 0 30px rgba(57, 255, 20, 0.8), var(--shadow-lg); }

.hiscore-display {
  font-size: 1rem;
  color: var(--hot);
  font-family: monospace;
  letter-spacing: 0.05em;
  min-height: 1.4em;
}

.settings-gear {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 10;
  background: rgba(107, 47, 255, 0.3);
  color: var(--neon);
  border: 1px solid rgba(57, 255, 20, 0.3);
}

/* ── In-game HUD ─────────────────────────────────────────────────────────── */
#screen-game {
  display: none;
  flex-direction: column;
  background: var(--arena-bg);
  overflow: hidden;
}
#screen-game.active { display: flex; }

.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* Right padding leaves room for the 64px absolute-positioned .hud-gear + 8px gap */
  padding: max(8px, env(safe-area-inset-top, 8px)) max(76px, calc(env(safe-area-inset-right, 0px) + 76px)) 8px max(16px, env(safe-area-inset-left, 16px));
  background: var(--hud-bg);
  border-bottom: 1px solid rgba(57, 255, 20, 0.2);
  flex-shrink: 0;
  z-index: 5;
  gap: 8px;
}

.hud-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}
.hud-center { min-width: 60px; }

.hud-label {
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: rgba(57, 255, 20, 0.6);
  font-family: monospace;
  text-transform: uppercase;
}

.hud-val {
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 900;
  color: var(--neon);
  font-family: monospace;
  letter-spacing: 0.04em;
  line-height: 1;
}

.hud-gear {
  position: absolute;
  top: max(8px, env(safe-area-inset-top, 8px));
  right: max(8px, env(safe-area-inset-right, 8px));
  z-index: 20;
  width: var(--tap-min);
  height: var(--tap-min);
  min-width: var(--tap-min);
  font-size: 1.4rem;
  background: rgba(107, 47, 255, 0.2);
  color: rgba(57, 255, 20, 0.7);
  border: 1px solid rgba(57, 255, 20, 0.2);
}

/* ── Streak bar ──────────────────────────────────────────────────────────── */
.streak-bar {
  text-align: center;
  font-family: monospace;
  font-size: clamp(0.75rem, 2.5vw, 0.95rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--hot);
  min-height: 22px;
  padding: 2px 0;
  flex-shrink: 0;
  background: transparent;
  text-shadow: 0 0 8px rgba(255, 45, 189, 0.6);
  z-index: 3;
}

/* ── Game arena ──────────────────────────────────────────────────────────── */
.game-arena {
  flex: 1;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.ground-line {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--neon) 20%, var(--neon) 80%, transparent);
  box-shadow: 0 0 8px var(--neon);
  opacity: 0.6;
}

/* ── Alien sprites ───────────────────────────────────────────────────────── */
.alien {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  z-index: 2;
  transition: transform 0.08s ease, filter 0.1s ease;
  /* Min 72px touch target */
  min-width: 72px;
  min-height: 72px;
  justify-content: center;
  padding: 6px;
  /* Space-themed card background */
  background: rgba(8, 5, 24, 0.82);
  border: 1.5px solid rgba(57, 255, 20, 0.28);
  border-radius: 14px;
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.12), inset 0 1px 0 rgba(255,255,255,0.06);
}
.alien:hover {
  transform: scale(1.06);
  border-color: rgba(57, 255, 20, 0.6);
  box-shadow: 0 0 18px rgba(57, 255, 20, 0.3);
}
.alien:active {
  transform: scale(0.96);
}

.alien:focus-visible {
  outline: 3px solid var(--neon);
  outline-offset: 4px;
  border-radius: 12px;
}

.alien-body {
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--alien-glow));
  pointer-events: none;
}

.alien-answer {
  background: rgba(0, 0, 0, 0.75);
  border: 1.5px solid var(--neon);
  border-radius: 8px;
  color: var(--neon);
  font-family: monospace;
  font-weight: 900;
  font-size: clamp(1rem, 4vw, 1.4rem);
  padding: 2px 10px;
  margin-top: 2px;
  letter-spacing: 0.05em;
  box-shadow: 0 0 6px rgba(57, 255, 20, 0.3);
  pointer-events: none;
  white-space: nowrap;
}

/* Alien states */
.alien.alien-correct .alien-body { filter: drop-shadow(0 0 20px var(--neon)); }
.alien.alien-wrong .alien-body   { filter: drop-shadow(0 0 20px rgba(255,45,45,0.8)); }
.alien.alien-wrong .alien-answer { border-color: #ff2d2d; color: #ff7777; box-shadow: 0 0 6px rgba(255,45,45,0.4); }

@keyframes alien-blast {
  0%   { transform: scale(1) rotate(0deg); opacity: 1; }
  40%  { transform: scale(1.6) rotate(-15deg); opacity: 0.8; }
  100% { transform: scale(0) rotate(30deg); opacity: 0; }
}
.alien.blasting {
  animation: alien-blast 0.28s ease-out forwards;
  pointer-events: none;
}

@keyframes alien-hit-wrong {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-8px); }
  40%  { transform: translateX(8px); }
  60%  { transform: translateX(-6px); }
  80%  { transform: translateX(6px); }
  100% { transform: translateX(0); }
}
.alien.shaking {
  animation: alien-hit-wrong 0.35s ease;
}

/* Power-up drop */
.powerup {
  position: absolute;
  z-index: 3;
  font-size: 2rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  animation: powerup-float 0.5s ease infinite alternate;
  min-width: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 12px var(--hot);
}

@keyframes powerup-float {
  from { transform: scale(1); }
  to   { transform: scale(1.1); }
}

/* ── Question panel ──────────────────────────────────────────────────────── */
.question-panel {
  flex-shrink: 0;
  background: var(--hud-bg);
  border-top: 1px solid rgba(57, 255, 20, 0.2);
  padding: 8px max(16px, env(safe-area-inset-right, 16px)) max(8px, env(safe-area-inset-bottom, 8px)) max(16px, env(safe-area-inset-left, 16px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 5;
}

.question-box {
  display: flex;
  align-items: center;
  gap: 0.4em;
  flex-wrap: wrap;
  justify-content: center;
}

.question-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(57, 255, 20, 0.55);
  font-family: monospace;
}

.question-text {
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 900;
  color: #ffffff;
  font-family: monospace;
  letter-spacing: 0.04em;
  text-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.question-eq {
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 900;
  color: var(--hot);
  font-family: monospace;
}

.ship-wrap {
  position: relative;
  width: 100%;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-ship {
  font-size: 1.8rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(57, 255, 20, 0.5));
  transition: transform 0.1s ease;
}

.laser-beam {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  background: linear-gradient(to top, var(--neon), transparent);
  border-radius: 2px;
  bottom: 100%;
  height: 0;
  box-shadow: 0 0 6px var(--neon);
  transition: none;
  pointer-events: none;
}

@keyframes laser-fire {
  0%   { height: 0; opacity: 1; }
  60%  { height: min(300px, 40vh); opacity: 1; }
  100% { height: min(300px, 40vh); opacity: 0; }
}
.laser-beam.firing {
  animation: laser-fire 0.22s ease-out forwards;
}

/* ── Feedback overlay ────────────────────────────────────────────────────── */
.feedback-overlay {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 10;
  font-size: clamp(1.8rem, 8vw, 3rem);
  font-weight: 900;
  font-family: monospace;
  letter-spacing: 0.06em;
  text-align: center;
  opacity: 0;
}

@keyframes feedback-pop {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
  30%  { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  70%  { opacity: 0.8; transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(0.9); }
}
.feedback-overlay.show-correct {
  animation: feedback-pop 0.45s ease-out forwards;
  color: var(--neon);
  text-shadow: 0 0 20px rgba(57, 255, 20, 0.8);
}
.feedback-overlay.show-wrong {
  animation: feedback-pop 0.45s ease-out forwards;
  color: #ff7070;
  text-shadow: 0 0 20px rgba(255,70,70,0.7);
}

/* ── Wave complete & Game over screens ───────────────────────────────────── */
#screen-wave, #screen-gameover {
  background: radial-gradient(ellipse at 50% 40%, #180a38 0%, var(--star-bg) 70%);
}

.result-card {
  position: relative;
  z-index: 1;
  background: rgba(15, 10, 35, 0.92);
  border: 1.5px solid rgba(57, 255, 20, 0.35);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 40px rgba(57, 255, 20, 0.12), var(--shadow-lg);
  padding: clamp(1.5rem, 5vw, 2.5rem);
  width: min(420px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1rem, 3vh, 1.6rem);
  text-align: center;
}

.gameover-card {
  border-color: rgba(255, 45, 45, 0.4);
  box-shadow: 0 0 40px rgba(255, 45, 45, 0.1), var(--shadow-lg);
}

.result-icon {
  font-size: clamp(3rem, 12vw, 5rem);
}

.result-title {
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 900;
  color: var(--neon);
  font-family: monospace;
  letter-spacing: 0.06em;
  margin: 0;
  text-shadow: 0 0 15px rgba(57, 255, 20, 0.5);
}

.gameover-card .result-title {
  color: #ff7070;
  text-shadow: 0 0 15px rgba(255, 70, 70, 0.5);
}

.result-sub {
  color: var(--ink-soft);
  margin: 0;
  font-size: 1rem;
}

.result-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(57, 255, 20, 0.06);
  border-radius: 10px;
  border: 1px solid rgba(57, 255, 20, 0.12);
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-family: monospace;
}

.stat-val {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--neon);
  font-family: monospace;
}

.streak-col { color: var(--hot); }
.new-record { color: #ffd700; }

/* ── Confetti ────────────────────────────────────────────────────────────── */
.confetti-burst {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confetti-fall 1s ease-out forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(120px) rotate(360deg); opacity: 0; }
}

/* ── Settings sheet — Mathvaders skin ────────────────────────────────────── */
.sheet {
  border: 1px solid rgba(57, 255, 20, 0.3);
  background: rgba(10, 7, 28, 0.97);
}
.sheet .sheet-body {
  background: rgba(15, 10, 35, 0.98);
  border-radius: var(--radius-lg);
}
.sheet h2 { color: var(--neon) !important; font-family: monospace; letter-spacing: 0.06em; }

/* Operations toggles layout */
.ops-toggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: color-mix(in srgb, var(--brand) 10%, var(--card));
  padding: 6px;
  border-radius: var(--radius);
}
.ops-toggles .seg { min-width: 60px; flex: 1; }

/* ── Keyboard hint ────────────────────────────────────────────────────────── */
.kb-hint {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 0.65rem;
  color: rgba(57, 255, 20, 0.3);
  font-family: monospace;
  pointer-events: none;
  z-index: 5;
}

/* ── Reduced motion: freeze all the game animations ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .logo-alien, .alien, .laser-beam, .confetti-piece, .powerup, .feedback-overlay {
    animation: none !important;
    transition: none !important;
  }
}

/* ── Responsive: very small screens ─────────────────────────────────────── */
@media (max-width: 360px) {
  .alien-body { font-size: 1.6rem; }
  .alien-answer { font-size: 0.9rem; padding: 1px 6px; }
  .question-text, .question-eq { font-size: 1.4rem; }
  .game-title { font-size: 2.2rem; }
}

/* ── Landscape phone: shrink vertical items ──────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .logo-alien { font-size: 2.5rem; }
  .game-title { font-size: 2rem; }
  .game-sub { display: none; }
  .question-panel { padding: 4px 16px; }
}

