/* ─────────────────────────────────────────────
   MATH HEROES — Bright Kid Arcade Design System
   ───────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap');

:root {
  /* Core */
  --c-bg-from: #6ed7ff;
  --c-bg-mid:  #ffe66d;
  --c-bg-to:   #ff8fb3;

  /* Accents */
  --c-purple:  #7c3aed;
  --c-purple-2:#5b21b6;
  --c-pink:    #ef3f8f;
  --c-yellow:  #ffd23f;
  --c-green:   #12b886;
  --c-red:     #e03131;
  --c-blue:    #168aad;
  --c-orange:  #f76707;
  --c-lime:    #74b816;

  /* Surfaces */
  --c-surface:       rgba(255,255,255,0.72);
  --c-surface-hover: rgba(255,255,255,0.92);
  --c-surface-card:  rgba(255,255,255,0.88);
  --c-glass-border:  rgba(43,45,66,0.14);
  --c-focus:         #2f80ed;

  /* Text */
  --c-text:       #24304f;
  --c-text-muted: #59627a;

  /* Semantic */
  --c-success: #2dd4bf;
  --c-error:   #fb7185;

  /* Spacing (8px grid) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px;

  /* Radii */
  --r-sm: 8px; --r-md: 16px; --r-lg: 24px; --r-xl: 32px; --r-full: 9999px;

  /* Shadows */
  --shadow-glow-purple: 0 10px 28px rgba(124,58,237,0.24);
  --shadow-glow-pink:   0 10px 28px rgba(239,63,143,0.24);
  --shadow-card:        0 12px 0 rgba(36,48,79,0.10), 0 18px 32px rgba(36,48,79,0.16);
  --shadow-btn:         0 6px 0 rgba(36,48,79,0.16);

  /* Transitions */
  --t-fast:   120ms ease;
  --t-mid:    220ms ease;
  --t-slow:   350ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─────── RESET ─────── */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 3px;
}

html, body {
  font-family: 'Fredoka', system-ui, sans-serif;
  font-weight: 500;
  color: var(--c-text);
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 10%, rgba(255,255,255,0.88) 0 8%, transparent 9%),
    radial-gradient(circle at 82% 12%, rgba(255,255,255,0.72) 0 9%, transparent 10%),
    linear-gradient(160deg, var(--c-bg-from) 0%, #b7f5ff 34%, var(--c-bg-mid) 68%, var(--c-bg-to) 100%);
  background-color: var(--c-bg-from); /* solid fallback — no white flash before gradient paints */
  background-attachment: fixed;
  overflow-x: hidden;
  overscroll-behavior: none; /* kill rubber-band / pull-to-refresh bounce inside the app (WebView/APK) */
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ─────── FLOATING MATH CONFETTI (pure CSS) ─────── */
.bg-stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

/* Generate 28 star dots via pseudo-elements and :nth-child tricks using multiple box-shadows */
.bg-stars::before,
.bg-stars::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: var(--r-sm);
  background: #ffffff;
  animation: twinkle 3s ease-in-out infinite;
}

.bg-stars::before {
  box-shadow:
    10vw 8vh 0 0 #ffcf33,
    22vw 35vh 0 2px #ff8fb3,
    35vw 12vh 0 0 #7c3aed,
    48vw 55vh 0 2px #12b886,
    62vw 20vh 0 0 #168aad,
    78vw 42vh 0 2px #ffcf33,
    88vw 15vh 0 0 #ef3f8f,
    5vw  68vh 0 2px #7c3aed,
    18vw 82vh 0 0 #12b886,
    55vw 75vh 0 2px #168aad,
    72vw 88vh 0 0 #ffcf33,
    92vw 60vh 0 2px #ef3f8f,
    40vw 92vh 0 0 #7c3aed,
    95vw 32vh 0 2px #12b886;
  animation-delay: 0s;
}

.bg-stars::after {
  box-shadow:
    15vw 25vh 0 2px #12b886,
    28vw 60vh 0 0 #ffcf33,
    42vw 18vh 0 2px #ef3f8f,
    58vw 38vh 0 0 #7c3aed,
    70vw 72vh 0 2px #168aad,
    83vw 8vh  0 0 #ffcf33,
    3vw  45vh 0 2px #ef3f8f,
    96vw 80vh 0 0 #12b886,
    50vw 5vh  0 2px #168aad,
    30vw 95vh 0 0 #ffcf33,
    65vw 52vh 0 2px #7c3aed,
    12vw 15vh 0 0 #12b886,
    80vw 28vh 0 2px #ef3f8f,
    45vw 65vh 0 0 #168aad;
  animation-delay: 1.5s;
}

/* Floating emoji decorations */
.float-shape {
  position: absolute;
  left: var(--x);
  top:  var(--y);
  font-size: var(--size);
  font-weight: 700;
  color: var(--color);
  animation: float var(--dur, 6s) ease-in-out infinite;
  animation-delay: var(--delay);
  opacity: 0.4;
}
/* School-supply emojis read as full-color objects — let them show up more
   so the school theme is obvious and playful. */
.float-emoji {
  opacity: 0.7;
  filter: drop-shadow(0 2px 5px rgba(36,48,79,0.18));
}
.float-shape:nth-child(1)  { --x: 10%; --y: 15%; --size: 40px; --delay: 0s;   --dur: 6s;   --color: #7c3aed; }
.float-shape:nth-child(2)  { --x: 80%; --y: 10%; --size: 28px; --delay: 1.5s; --dur: 7s;   --color: #ef3f8f; }
.float-shape:nth-child(3)  { --x: 15%; --y: 80%; --size: 36px; --delay: 2s;   --dur: 6.5s; --color: #168aad; }
.float-shape:nth-child(4)  { --x: 88%; --y: 60%; --size: 32px; --delay: 0.5s; --dur: 7.5s; --color: #12b886; }
.float-shape:nth-child(5)  { --x: 50%; --y: 5%;  --size: 24px; --delay: 1s;   --dur: 6s;   --color: #f76707; }
.float-shape:nth-child(6)  { --x: 5%;  --y: 50%; --size: 28px; --delay: 2.5s; --dur: 8s;   --color: #7c3aed; }
.float-shape:nth-child(7)  { --x: 92%; --y: 85%; --size: 26px; --delay: 0.8s; --dur: 6.8s; --color: #ef3f8f; }
.float-shape:nth-child(8)  { --x: 22%; --y: 38%; --size: 44px; --delay: 0.3s; --dur: 7.2s; }
.float-shape:nth-child(9)  { --x: 70%; --y: 30%; --size: 40px; --delay: 1.8s; --dur: 8.5s; }
.float-shape:nth-child(10) { --x: 60%; --y: 72%; --size: 42px; --delay: 1.2s; --dur: 6.4s; }
.float-shape:nth-child(11) { --x: 30%; --y: 60%; --size: 40px; --delay: 2.2s; --dur: 7.6s; }
.float-shape:nth-child(12) { --x: 82%; --y: 44%; --size: 38px; --delay: 0.9s; --dur: 8.2s; }
.float-shape:nth-child(13) { --x: 40%; --y: 88%; --size: 40px; --delay: 1.6s; --dur: 6.9s; }
.float-shape:nth-child(14) { --x: 12%; --y: 32%; --size: 42px; --delay: 2.8s; --dur: 7.8s; }
.float-shape:nth-child(15) { --x: 64%; --y: 16%; --size: 30px; --delay: 0.6s; --dur: 6.2s; --color: #168aad; }
.float-shape:nth-child(16) { --x: 36%; --y: 24%; --size: 24px; --delay: 2.1s; --dur: 7.4s; --color: #f76707; }
.float-shape:nth-child(17) { --x: 48%; --y: 54%; --size: 42px; --delay: 1.4s; --dur: 8.8s; }
.float-shape:nth-child(18) { --x: 90%; --y: 24%; --size: 34px; --delay: 0.4s; --dur: 6.6s; }

@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-30px) rotate(15deg); }
}

/* ─────── SCREENS ─────── */
.screen {
  display: none;
  min-height: 100dvh;
  padding: var(--sp-6) var(--sp-5);
  /* Respect notch / status bar / gesture bar on phones + in the APK WebView.
     Plain padding above is the fallback; max() only ever ADDS inset, never removes. */
  padding:
    max(var(--sp-6), env(safe-area-inset-top))
    max(var(--sp-5), env(safe-area-inset-right))
    max(var(--sp-6), env(safe-area-inset-bottom))
    max(var(--sp-5), env(safe-area-inset-left));
  position: relative;
  z-index: 1;
  animation: screen-in 250ms ease forwards;
}
.screen.active {
  display: flex;
  flex-direction: column;
  /* Own the vertical scroll: any screen taller than the viewport scrolls
     cleanly instead of clipping its bottom content (choices, modal buttons,
     long level paths). overscroll-behavior:none on body kills the bounce. */
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─────── GLASS CARD ─────── */
.glass {
  background: var(--c-surface-card);
  border: 2px solid rgba(255,255,255,0.84);
  border-radius: var(--r-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
}

/* ─────── TYPOGRAPHY ─────── */
h1 {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 0;
  background: linear-gradient(135deg, var(--c-purple), var(--c-pink), var(--c-orange));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: var(--sp-3) 0 var(--sp-2);
  line-height: 1.1;
  filter: drop-shadow(0 3px 0 rgba(255,255,255,0.75));
}

.subtitle {
  color: var(--c-text-muted);
  font-size: 16px;
  margin-bottom: var(--sp-3);
}

/* ─────── HOME SCREEN ─────── */
.hero { text-align: center; padding-top: 4vh; }
.hero-compact { padding-top: var(--sp-6); }
.profile-title { font-size: 48px; }

/* ─────── FREEMIUM GATE ─────── */
.level-btn.premium-locked {
  position: relative;
  filter: saturate(0.3);
  opacity: 0.85;
}
.level-btn.premium-locked .crown { visibility: hidden; }
.lock-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  font-size: 19px;
  filter: drop-shadow(0 2px 0 rgba(36,48,79,0.2));
}

.unlock-card { text-align: center; }
.unlock-emoji { font-size: 52px; line-height: 1; margin-bottom: var(--sp-3); }
.unlock-copy { line-height: 1.5; margin: var(--sp-3) 0 var(--sp-4); }
.grownup-gate {
  background: rgba(36,48,79,0.06);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
}
.gate-q { font-size: 14px; margin-bottom: var(--sp-2); }
.unlock-note { font-size: 12px; opacity: 0.65; margin-top: var(--sp-3); }

/* Back from "Who's Playing?" to the active player's home (hidden on first launch) */
#screen-profiles { position: relative; }
.profiles-back {
  position: absolute;
  top: max(var(--sp-6), env(safe-area-inset-top));
  left: max(var(--sp-5), env(safe-area-inset-left));
  z-index: 2;
}

/* Dragon mascot */
.dragon {
  display: inline-block;
  animation: bob 2s ease-in-out infinite;
  position: relative;
  width: 220px;
  height: 220px;
}

/* Purple glow halo behind dragon */
.dragon::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,210,63,0.48) 0%, transparent 70%);
  animation: halo-pulse 2s ease-in-out infinite;
}

@keyframes halo-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
  50%       { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-10px) rotate(3deg); }
}

/* Tap tricks — kids poke the mascot. Animate the SVG (not .dragon) so the
   bob animation on the wrapper keeps running underneath the trick. */
.dragon { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.dragon.boing  .dragon-svg { animation: dragon-boing 0.7s cubic-bezier(0.34, 1.56, 0.64, 1); }
.dragon.twirl  .dragon-svg { animation: dragon-twirl 0.8s cubic-bezier(0.34, 1.56, 0.64, 1); }
.dragon.wiggle .dragon-svg { animation: dragon-wiggle 0.6s ease-in-out; }

@keyframes dragon-boing {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.25, 0.75); }
  55%  { transform: scale(0.84, 1.2) translateY(-26px); }
  75%  { transform: scale(1.1, 0.92); }
  100% { transform: scale(1); }
}
@keyframes dragon-twirl {
  0%   { transform: rotate(0deg) scale(1); }
  55%  { transform: rotate(360deg) scale(1.18); }
  100% { transform: rotate(360deg) scale(1); }
}
@keyframes dragon-wiggle {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-14deg); }
  40% { transform: rotate(12deg); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(6deg); }
}

.dragon-svg {
  filter: drop-shadow(0 10px 0 rgba(36,48,79,0.12)) drop-shadow(0 16px 28px rgba(124,58,237,0.28));
  position: relative;
  z-index: 1;
}

/* Mode buttons */
.modes {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  width: 100%;
  max-width: 480px;
  margin: var(--sp-6) auto 0;
}

.mode-btn {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 32px;
  grid-template-rows: auto auto;
  grid-template-areas: "emoji title arrow" "emoji sub arrow";
  align-items: center;
  gap: var(--sp-1) 0;
  background: var(--c-surface-card);
  border: 3px solid rgba(255,255,255,0.9);
  border-left: 10px solid transparent;
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 6px 0 rgba(36,48,79,0.12), var(--shadow-card);
  transition: transform var(--t-mid), box-shadow var(--t-mid), background var(--t-mid);
  position: relative;
  overflow: hidden;
  min-height: 80px;
}

.mode-btn[data-mode="classic"] { border-left-color: var(--c-purple); }
.mode-btn[data-mode="story"]   { border-left-color: var(--c-green); }
.mode-btn[data-mode="speed"]   { border-left-color: var(--c-orange); }
.mode-btn[data-mode="logic"]   { border-left-color: var(--c-blue); }

.mode-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 9px 0 rgba(36,48,79,0.12), var(--shadow-card), var(--shadow-glow-purple);
  background: var(--c-surface-hover);
}
.mode-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(36,48,79,0.12), 0 3px 8px rgba(36,48,79,0.16);
}

.mode-emoji { grid-area: emoji; font-size: 56px; text-align: center; line-height: 1; }
.mode-title {
  grid-area: title;
  font-size: 20px;
  font-weight: 700;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.mode-sub   { grid-area: sub;   font-size: 14px; color: var(--c-text-muted); font-weight: 600; }
.mode-arrow { grid-area: arrow; font-size: 20px; color: var(--c-text-muted); font-weight: 700; }

.ai-badge {
  font-size: 12px;
  background: #d3fff1;
  border: 1px solid rgba(18,184,134,0.38);
  color: #087f5b;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-full);
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* ─────── REWARDS PANEL ─────── */
.rewards-panel {
  width: 100%;
  max-width: 520px;
  margin: var(--sp-5) auto 0;
  display: grid;
  grid-template-columns: 1.35fr 0.85fr;
  gap: var(--sp-3);
}

.reward-card {
  min-height: 96px;
  border-radius: var(--r-lg);
  border: 3px solid rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.86);
  box-shadow: 0 8px 0 rgba(36,48,79,0.10), 0 14px 24px rgba(36,48,79,0.12);
  padding: var(--sp-4);
  text-align: left;
  overflow: hidden;
}

.quest-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.92), rgba(255,243,191,0.94));
}

.coins-card {
  background: linear-gradient(135deg, #fff8dc, #ffd23f);
}

.achievements-card {
  grid-column: 1 / -1;
  min-height: 88px;
}

.reward-kicker {
  color: var(--c-text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.reward-title,
.coin-total {
  color: var(--c-text);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  margin-top: var(--sp-1);
}

.shop-open-btn {
  width: 100%;
  min-height: 40px;
  margin-top: var(--sp-3);
  border: 2px solid rgba(255,255,255,0.78);
  border-radius: var(--r-full);
  background: var(--c-text);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  box-shadow: 0 4px 0 rgba(36,48,79,0.14);
}
.shop-open-btn:hover { transform: translateY(-1px); }
.shop-open-btn:active { transform: translateY(2px); box-shadow: none; }

.quest-progress {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.quest-bar {
  flex: 1;
  height: 18px;
  border-radius: var(--r-full);
  background: rgba(36,48,79,0.12);
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.82);
}

.quest-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c-green), var(--c-yellow), var(--c-pink));
  transition: width var(--t-slow);
}

#daily-quest-text {
  min-width: 48px;
  text-align: right;
  color: var(--c-text);
  font-size: 14px;
  font-weight: 700;
}

.achievement-shelf {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.achievement-chip {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  border-radius: var(--r-full);
  padding: var(--sp-2) var(--sp-3);
  background: #eef8ff;
  color: var(--c-text);
  font-size: 14px;
  font-weight: 700;
  border: 2px solid rgba(22,138,173,0.18);
}

.achievement-chip.locked {
  background: rgba(36,48,79,0.08);
  color: rgba(36,48,79,0.46);
  border-color: rgba(36,48,79,0.08);
}

/* ─────── HOME MISSIONS ─────── */
.mission-panel {
  width: 100%;
  max-width: 520px;
  margin: var(--sp-5) auto 0;
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.82);
  box-shadow: 0 8px 0 rgba(36,48,79,0.10), 0 14px 24px rgba(36,48,79,0.12);
  padding: var(--sp-4);
  overflow: hidden;
  position: relative;
}

.mission-panel::before {
  content: '';
  position: absolute;
  inset: -40% auto auto -20%;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,210,63,0.32), transparent 68%);
  pointer-events: none;
}

.mission-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  position: relative;
}

.mission-panel h2 {
  color: var(--c-text);
  font-size: 24px;
  line-height: 1.2;
}

.mission-burst {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, #ffd23f, #ff8fb3);
  font-size: 28px;
  box-shadow: 0 5px 0 rgba(36,48,79,0.12);
  animation: burst-wiggle 1.6s ease-in-out infinite;
}

.mission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  position: relative;
}

.mission-card {
  min-height: 132px;
  border-radius: var(--r-md);
  border: 2px solid rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.84);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  box-shadow: 0 5px 0 rgba(36,48,79,0.08);
}

.mission-card.green { background: linear-gradient(135deg, #d3fff1, rgba(255,255,255,0.86)); }
.mission-card.orange { background: linear-gradient(135deg, #fff3bf, rgba(255,255,255,0.86)); }
.mission-card.purple { background: linear-gradient(135deg, #ede9fe, rgba(255,255,255,0.86)); }

.mission-icon {
  font-size: 28px;
  line-height: 1;
}

.mission-title {
  color: var(--c-text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.mission-card p {
  color: var(--c-text-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  min-height: 32px;
}

.mission-mini-bar {
  height: 10px;
  border-radius: var(--r-full);
  background: rgba(36,48,79,0.12);
  overflow: hidden;
  margin-top: auto;
}

.mission-mini-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c-green), var(--c-yellow), var(--c-pink));
  transition: width var(--t-slow);
}

@keyframes burst-wiggle {
  0%, 100% { transform: rotate(-5deg) scale(1); }
  50% { transform: rotate(7deg) scale(1.08); }
}

/* ─────── HERO SHOP ─────── */
.shop-coins {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-full);
  background: #fff3bf;
  color: #7c2d12;
  font-size: 16px;
  font-weight: 700;
  border: 2px solid rgba(255,255,255,0.86);
}

.shop-hero-preview {
  width: 100%;
  max-width: 520px;
  margin: var(--sp-6) auto 0;
  text-align: center;
}

.shop-mascot,
.mascot-stage {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.shop-mascot {
  width: 144px;
  height: 144px;
  border-radius: var(--r-xl);
  background: rgba(255,255,255,0.86);
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow: var(--shadow-card);
  font-size: 72px;
  margin-bottom: var(--sp-3);
}

.shop-preview-item,
.mascot-cosmetic {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%) rotate(-6deg);
  font-size: 32px;
  z-index: 4;
  pointer-events: none;
  filter: drop-shadow(0 4px 0 rgba(36,48,79,0.14));
}

.shop-preview-pet,
.mascot-pet {
  position: absolute;
  right: -22px;
  bottom: 0;
  font-size: 28px;
  z-index: 4;
  pointer-events: none;
  animation: pet-bob 1.4s ease-in-out infinite;
  filter: drop-shadow(0 4px 0 rgba(36,48,79,0.12));
}

.shop-grid {
  width: 100%;
  max-width: 720px;
  margin: var(--sp-5) auto var(--sp-8);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}

.shop-item {
  min-height: 168px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.88);
  box-shadow: 0 8px 0 rgba(36,48,79,0.10), 0 14px 24px rgba(36,48,79,0.12);
  padding: var(--sp-4);
}

.shop-item.equipped {
  border-color: rgba(18,184,134,0.55);
  box-shadow: 0 8px 0 rgba(18,184,134,0.16), 0 14px 28px rgba(18,184,134,0.16);
}

.shop-item-top {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
}

.shop-item-icon {
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  background: #fff3bf;
  font-size: 32px;
}

.shop-item-name {
  color: var(--c-text);
  font-size: 20px;
  font-weight: 700;
}

.shop-item-copy {
  color: var(--c-text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.shop-buy-btn {
  margin-top: auto;
  min-height: 48px;
  border: 0;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-purple), var(--c-pink));
  color: white;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(36,48,79,0.15);
}
.shop-buy-btn:disabled {
  opacity: 0.54;
  cursor: not-allowed;
}

@keyframes pet-bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-6px) rotate(4deg); }
}

/* Active player chip */
.active-player-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: 0 0 var(--sp-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text-muted);
  min-height: 32px;
  width: fit-content;
  margin-left: auto;
  background: var(--c-surface);
  border: 2px solid rgba(255,255,255,0.88);
  border-radius: var(--r-full);
  padding: var(--sp-1) var(--sp-3);
}

/* Home footer */
.home-foot {
  text-align: center;
  margin-top: auto;
  padding: var(--sp-6) 0 var(--sp-3);
  font-size: 14px;
  color: var(--c-text-muted);
}

.best {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 14px;
  color: #7c2d12;
  font-weight: 600;
}

/* ─────── BUTTONS ─────── */
.btn-primary {
  background: linear-gradient(135deg, var(--c-purple), var(--c-pink));
  color: white;
  border: 3px solid rgba(255,255,255,0.7);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-6);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(36,48,79,0.20), 0 12px 24px rgba(124,58,237,0.28);
  transition: transform var(--t-mid), box-shadow var(--t-mid);
  min-height: 48px;
}
.btn-primary:hover  { transform: translateY(-1px); box-shadow: 0 8px 0 rgba(36,48,79,0.16), 0 16px 28px rgba(124,58,237,0.30); }
.btn-primary:active { transform: translateY(2px); box-shadow: var(--shadow-btn); }
.btn-primary:disabled,
.btn-secondary:disabled,
.choice:disabled,
.hint-btn:disabled,
.mode-btn:disabled,
.iconbtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-secondary {
  background: var(--c-surface-card);
  border: 2px solid rgba(255,255,255,0.9);
  color: var(--c-text);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-6);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
  transition: transform var(--t-mid), background var(--t-mid);
  min-height: 48px;
}
.btn-secondary:hover  { background: var(--c-surface-hover); }
.btn-secondary:active { transform: translateY(2px); }

.footer-action {
  display: block;
  min-width: 184px;
  margin: 0 auto;
}

.switch-player-btn {
  display: block;
  min-width: 160px;
  margin: var(--sp-3) auto 0;
  font-size: 14px;
}

.music-toggle-btn {
  width: 48px;
  height: 48px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--c-text);
  font-size: 22px;
  cursor: pointer;
  opacity: 0.82;
  transition: transform var(--t-fast), background var(--t-fast), opacity var(--t-fast);
}
.music-toggle-btn:hover {
  background: var(--c-surface);
  opacity: 1;
  transform: translateY(-1px);
}
.music-toggle-btn:active { transform: translateY(1px); }
.music-toggle-home { margin-top: var(--sp-2); }
.music-toggle-compact {
  width: 48px;
  height: 48px;
  font-size: 18px;
}

/* ─────── PROFILE SCREEN ─────── */
.profiles-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
  max-width: 420px;
  margin: var(--sp-6) auto 0;
  padding: 0 var(--sp-2);
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--c-surface-card);
  border: 1px solid var(--c-glass-border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  text-align: center;
  box-shadow: var(--shadow-card);
}
.empty-emoji {
  display: block;
  font-size: 48px;
  margin-bottom: var(--sp-3);
}
.empty-title {
  color: var(--c-text);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: var(--sp-2);
}
.empty-copy {
  color: var(--c-text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  background: var(--c-surface-card);
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-4);
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
  transition: transform var(--t-mid), border-color var(--t-mid), box-shadow var(--t-mid);
  min-height: 130px;
}
.profile-card:hover  {
  border-color: var(--c-purple);
  box-shadow: var(--shadow-card), var(--shadow-glow-purple);
  transform: translateY(-2px);
}
.profile-card:active { transform: scale(0.96); }

/* Avatar circle */
.profile-avatar-wrap {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-purple-2), var(--c-pink));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  box-shadow: 0 6px 0 rgba(36,48,79,0.16), 0 12px 20px rgba(124,58,237,0.22);
}

/* Legacy: if JS writes .profile-avatar directly */
.profile-avatar { font-size: 48px; }

.profile-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text);
  text-align: center;
}

/* "Add Player" dashed card */
.profile-card-add {
  border: 2px dashed rgba(167,139,250,0.4);
  animation: add-pulse 2s ease-in-out infinite;
}
.profile-card-add .add-icon {
  font-size: 32px;
  color: var(--c-purple);
  font-weight: 300;
  line-height: 1;
}
.profile-card-add .profile-name { color: var(--c-text-muted); }

@keyframes add-pulse {
  0%, 100% { border-color: rgba(167,139,250,0.3); }
  50%       { border-color: rgba(167,139,250,0.7); }
}

/* Selected profile: purple ring + glow */
.profile-card.active-profile {
  border-color: var(--c-purple);
  box-shadow: var(--shadow-card), 0 0 0 3px rgba(167,139,250,0.35);
}

/* ─────── PROFILE MODAL ─────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36,48,79,0.45);
  backdrop-filter: blur(6px);
  display: flex;
  /* Align to top + scroll so a tall modal (or one with the on-screen keyboard
     open) never clips its Save/Cancel buttons; it stays centered when it fits. */
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 100;
  padding: var(--sp-6);
}

/* Keep the card vertically centered when there's room, scroll when there isn't. */
.modal-overlay .modal-card { margin: auto; }

.modal-card {
  background: #fffdf7;
  border: 3px solid rgba(255,255,255,0.95);
  border-radius: var(--r-xl);
  padding: var(--sp-8) var(--sp-6);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-card), var(--shadow-glow-purple);
}

.modal-card h2 {
  font-size: 24px;
  background: linear-gradient(135deg, var(--c-purple), var(--c-pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: var(--sp-4);
}

.profile-name-input {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: white;
  border: 2px solid rgba(36,48,79,0.16);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
  outline: none;
  transition: border-color var(--t-mid), box-shadow var(--t-mid);
}
.profile-name-input::placeholder { color: var(--c-text-muted); }
.profile-name-input:focus {
  border-color: var(--c-purple);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.2);
}
.profile-name-input.error {
  border-color: var(--c-error);
  box-shadow: 0 0 0 3px rgba(251,113,133,0.18);
}
.field-label {
  color: var(--c-text-muted);
  font-size: 14px;
  margin: var(--sp-4) 0 var(--sp-2);
}
.modal-actions {
  display: flex;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}
.modal-actions > button { flex: 1; }

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
}
.avatar-opt {
  background: var(--c-surface);
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  font-size: 28px;
  padding: var(--sp-2);
  cursor: pointer;
  transition: border-color var(--t-fast), transform var(--t-fast), background var(--t-fast);
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-opt:hover { background: var(--c-surface-hover); }
.avatar-opt.selected {
  border-color: var(--c-purple);
  background: rgba(167,139,250,0.2);
  transform: scale(1.12);
  box-shadow: var(--shadow-glow-purple);
}
.avatar-opt:active { transform: scale(0.94); }

/* ─────── GAME BAR ─────── */
.game-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--c-surface-card);
  border: 3px solid rgba(255,255,255,0.9);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-full);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
}

.bar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
  flex: 1;
  text-align: center;
}

.iconbtn {
  background: var(--c-surface);
  border: 2px solid rgba(255,255,255,0.92);
  font-size: 20px;
  cursor: pointer;
  color: var(--c-text);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-weight: 700;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast);
}
.iconbtn:hover  { background: var(--c-surface-hover); }
.iconbtn:active { background: rgba(255,255,255,0.2); }

.stats {
  display: flex;
  gap: var(--sp-3);
  margin-left: auto;
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text);
  flex-wrap: wrap;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: rgba(255,255,255,0.82);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  min-height: 32px;
}
.stat-emoji { font-size: 16px; }

#timer.urgent { color: var(--c-red); animation: pulse-timer 0.5s ease-in-out infinite; }
@keyframes pulse-timer { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ─────── PLAYER BADGE ─────── */
.bar-player {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text-muted);
  white-space: nowrap;
  background: rgba(255,255,255,0.82);
  padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-2);
  border-radius: var(--r-full);
}
.badge-avatar { font-size: 18px; }
.badge-name { max-width: 80px; overflow: hidden; text-overflow: ellipsis; color: var(--c-text); }

/* ─────── GAME SCREEN ─────── */
.play {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* center when it fits, but never clip: if content is taller than the play
     area it grows and the screen (overflow-y:auto) scrolls to reveal it. */
  justify-content: center;
  gap: var(--sp-5);
  padding: var(--sp-5) var(--sp-2);
  position: relative;
  overflow: visible;
}

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.score-pop,
.spark-pop {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 3;
  pointer-events: none;
  animation: score-float 760ms ease-out forwards;
}

.score-pop {
  min-width: 64px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: #ffffff;
  border: 3px solid rgba(255,255,255,0.9);
  color: var(--c-purple);
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 6px 0 rgba(36,48,79,0.12), 0 14px 24px rgba(36,48,79,0.16);
}

.spark-pop {
  font-size: 28px;
  filter: drop-shadow(0 4px 0 rgba(36,48,79,0.12));
}

/* Soft, friendly encouragement after a wrong answer (blue, not red) */
.encourage-pop {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 3;
  pointer-events: none;
  padding: 6px 16px;
  border-radius: var(--r-full);
  background: #ffffff;
  border: 3px solid rgba(255,255,255,0.9);
  color: #3b82f6;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 6px 0 rgba(36,48,79,0.12), 0 14px 24px rgba(36,48,79,0.16);
  animation: score-float 950ms ease-out forwards;
}

@keyframes score-float {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(0.72) rotate(-5deg); }
  24% { opacity: 1; transform: translate(-50%, -4px) scale(1.08) rotate(3deg); }
  100% { opacity: 0; transform: translate(-50%, -72px) scale(0.9) rotate(8deg); }
}

.combo-badge {
  position: absolute;
  top: var(--sp-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  min-height: 48px;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-full);
  background: linear-gradient(135deg, #ffd23f, #ff8fb3);
  border: 3px solid rgba(255,255,255,0.9);
  color: #7c2d12;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 8px 0 rgba(36,48,79,0.12), 0 16px 28px rgba(239,63,143,0.2);
  animation: combo-in 900ms var(--t-slow) forwards;
}

@keyframes combo-in {
  0% { opacity: 0; transform: translate(-50%, -24px) scale(0.72) rotate(-5deg); }
  24% { opacity: 1; transform: translate(-50%, 4px) scale(1.08) rotate(2deg); }
  72% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -18px) scale(0.92); }
}

.game-status {
  width: 100%;
  max-width: 520px;
  min-height: 48px;
  border: 2px solid rgba(255,255,255,0.88);
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.82);
  color: var(--c-text);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: var(--shadow-card);
}
.game-status.loading::before {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(36,48,79,0.18);
  border-top-color: var(--c-green);
  animation: spin 0.8s linear infinite;
}
.game-status.error {
  border-color: rgba(251,113,133,0.55);
  background: #ffe3e3;
  color: #9b1c1c;
}
.game-status.success {
  border-color: rgba(45,212,191,0.55);
  background: #d3fff1;
  color: #087f5b;
}
@keyframes spin { to { transform: rotate(360deg); } }

.mascot-inline {
  font-size: 64px;
  animation: bob 2s ease-in-out infinite;
  transition: transform 0.3s;
  display: inline-block;
  filter: drop-shadow(0 8px 0 rgba(36,48,79,0.12)) drop-shadow(0 16px 24px rgba(124,58,237,0.18));
  position: relative;
  z-index: 3;
}
.mascot-inline.happy {
  animation: spin-joy 1.15s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  /* bright golden glow so it stands out, even over confetti */
  filter: drop-shadow(0 6px 0 rgba(36,48,79,0.12)) drop-shadow(0 0 22px rgba(255,210,63,0.95));
  z-index: 6;
}
.mascot-inline.sad   { animation: shake 0.45s ease-out forwards; filter: grayscale(0.5); }
.mascot-inline.hot-streak {
  animation: mascot-fire 800ms ease-in-out infinite;
  filter: drop-shadow(0 8px 0 rgba(36,48,79,0.12)) drop-shadow(0 0 22px rgba(255,210,63,0.75));
}
.mascot-inline.hot-streak::after {
  content: '🔥';
  position: absolute;
  right: -18px;
  top: -10px;
  font-size: 28px;
  animation: flame-pop 700ms ease-in-out infinite;
}

@keyframes spin-joy {
  0%   { transform: translateY(0)     scale(1)    rotate(0deg);   }
  22%  { transform: translateY(-34px) scale(1.75) rotate(200deg); }
  42%  { transform: translateY(0)     scale(1.2)  rotate(360deg); }
  56%  { transform: translateY(-16px) scale(1.32) rotate(360deg); }
  70%  { transform: translateY(0)     scale(1.1)  rotate(372deg); }
  84%  { transform: translateY(-7px)  scale(1.06) rotate(351deg); }
  100% { transform: translateY(0)     scale(1)    rotate(360deg); }
}

@keyframes mascot-fire {
  0%, 100% { transform: translateY(0) rotate(-4deg) scale(1); }
  50% { transform: translateY(-8px) rotate(4deg) scale(1.08); }
}

@keyframes flame-pop {
  0%, 100% { transform: translateY(0) scale(1) rotate(-8deg); }
  50% { transform: translateY(-5px) scale(1.18) rotate(8deg); }
}

/* ─────── STAR RUSH POWER METER ─────── */
.power-panel {
  width: 100%;
  max-width: 520px;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.84);
  box-shadow: 0 8px 0 rgba(36,48,79,0.10), 0 14px 24px rgba(36,48,79,0.12);
  padding: var(--sp-3) var(--sp-4);
  position: relative;
  overflow: hidden;
}

.power-panel::after {
  content: '✦';
  position: absolute;
  right: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  color: rgba(124,58,237,0.22);
  font-size: 56px;
  font-weight: 700;
}

.power-panel.rush-active {
  background: linear-gradient(135deg, #fff3bf, #ffd6e7, #ede9fe);
  animation: rush-glow 900ms ease-in-out infinite;
}

.power-copy {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
  position: relative;
  z-index: 1;
}

.power-label {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: var(--c-text);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: var(--sp-1) var(--sp-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.power-copy strong {
  color: var(--c-text);
  font-size: 16px;
  line-height: 1.2;
}

.power-meter {
  height: 18px;
  border-radius: var(--r-full);
  background: rgba(36,48,79,0.12);
  border: 2px solid rgba(255,255,255,0.84);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.power-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c-blue), var(--c-green), var(--c-yellow), var(--c-pink));
  transition: width var(--t-slow);
}

.power-panel.rush-active .power-meter span {
  background-size: 200% 100%;
  animation: power-flow 700ms linear infinite;
}

@keyframes rush-glow {
  0%, 100% { box-shadow: 0 8px 0 rgba(36,48,79,0.10), 0 0 0 rgba(255,210,63,0); }
  50% { box-shadow: 0 8px 0 rgba(36,48,79,0.10), 0 0 28px rgba(255,210,63,0.55); }
}

@keyframes power-flow {
  from { background-position: 0% 50%; }
  to { background-position: 200% 50%; }
}

/* Problem display */
.problem-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-5);
  max-width: 600px;
  width: 100%;
  background: rgba(255,255,255,0.86);
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-card);
}

.problem-box.loading {
  min-height: 144px;
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, rgba(255,255,255,0.66), rgba(255,255,255,0.96), rgba(255,255,255,0.66));
  background-size: 200% 100%;
  animation: skeleton 1.1s ease-in-out infinite;
}
@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.problem {
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.01em;
  color: var(--c-text);
  padding: var(--sp-2);
  line-height: 1.35;
  white-space: pre-line;
}

.problem.equation {
  font-size: 80px;
  background: linear-gradient(135deg, var(--c-purple) 0%, var(--c-pink) 45%, var(--c-orange) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  line-height: 1.1;
}

.problem.logic-problem {
  font-size: 32px;
  color: var(--c-text);
  line-height: 1.2;
}

/* Number sequences (comma lists): smaller type, and `pre` instead of pre-line
   so the whole sequence stays on one row — only the \n before "□ = ?" breaks. */
.problem.equation.seq {
  font-size: clamp(24px, 9vw, 44px);
  white-space: pre;
}

/* Word problems (Daily Challenge, rounding): sentence-size, not equation-size */
.problem.equation.wordy {
  font-size: clamp(20px, 6vw, 30px);
  line-height: 1.4;
}

/* Roman numerals: Fredoka's tight kerning merges IV into an N-looking blob —
   air the letters out and size down a touch so LXVIII still fits. */
.problem.equation.roman {
  letter-spacing: 0.14em;
  font-size: clamp(36px, 11vw, 64px);
}

/* On a correct answer the □ ring turns into the found number, and a bare
   "= ?" equation gets its ? swapped for the answer (.answer-reveal) — both
   green with a pop. Needs its own text color — the parent's
   background-clip:text doesn't reach into a span with its own background. */
.problem .answer-reveal,
.problem .blank.blank-filled {
  mask: none;
  -webkit-mask: none;
  background: none;
  width: auto;
  height: auto;
  padding: 0 0.04em;
  color: var(--c-green);
  -webkit-text-fill-color: var(--c-green);
  display: inline-block;
  animation: blank-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes blank-pop {
  0%   { transform: scale(0.2); opacity: 0; }
  60%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); }
}

/* The □ placeholder is DRAWN with CSS (not the font glyph, whose outline is a
   hairline) so the stroke is as chunky as the digits. A rounded gradient ring
   with a true transparent hole in the middle, made with the mask-composite
   "gradient border" trick (border-image can't do rounded corners). */
/* Opt emoji out of the gradient text-clip so they keep their real colors
   (keep the span inline — inline-block breaks the parent's clip, see .blank). */
.problem .emoji-glyph {
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  -webkit-text-fill-color: initial;
  color: #24304f;
  font-size: 0.82em;
}

.problem .blank {
  display: inline-block;
  box-sizing: border-box;
  width: 0.74em;
  height: 0.74em;
  vertical-align: -0.02em;
  margin: 0 0.07em;
  padding: 0.2em;
  border-radius: 0.22em;
  background: linear-gradient(135deg, var(--c-purple) 0%, var(--c-pink) 50%, var(--c-orange) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
}

.problem-emoji { font-size: 36px; }

.logic-visual {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}

.clock-visual {
  width: min(100%, 220px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, #eef8ff, #fff3bf);
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow: 0 6px 0 rgba(36,48,79,0.10);
  padding: var(--sp-2);
}

.clock-visual svg {
  width: 176px;
  height: 176px;
}

.clock-face {
  fill: #ffffff;
  stroke: #168aad;
  stroke-width: 8;
}

.clock-marks text {
  fill: var(--c-text);
  font-family: 'Fredoka', system-ui, sans-serif;
  font-size: 22px;
  font-weight: 700;
}

/* Hands rotate via the SVG transform attribute rotate(angle 110 110), which
   centers itself. Do NOT add transform-origin here — it compounds with the
   attribute's center and throws rotated hands off-canvas (invisible clock). */
.clock-hand {
  stroke: var(--c-text);
  stroke-linecap: round;
}

.clock-hand.hour {
  stroke-width: 10;
}

.clock-hand.minute {
  stroke: var(--c-pink);
  stroke-width: 6;
}

.clock-center,
.clock-pin {
  fill: var(--c-purple);
}

.logic-groups {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: var(--sp-3);
}

.logic-group,
.logic-remainder,
.logic-empty {
  min-height: 72px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  border-radius: var(--r-md);
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow: 0 5px 0 rgba(36,48,79,0.10);
}

.logic-group {
  background: #e7f5ff;
}

.logic-group.full {
  border-color: rgba(18,184,134,0.42);
  background: #d3fff1;
}

.logic-group-label {
  flex-basis: 100%;
  color: var(--c-text-muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.logic-empty {
  grid-column: 1 / -1;
  color: var(--c-text-muted);
  font-size: 14px;
  font-weight: 700;
  background: rgba(255,255,255,0.58);
  border-style: dashed;
}

.logic-remainder {
  width: min(100%, 320px);
  min-width: 112px;
  padding: var(--sp-3);
  background: #fff3bf;
  border-color: rgba(247,103,7,0.32);
}

.logic-remainder::before {
  content: 'Loose balls';
  flex-basis: 100%;
  color: #7c2d12;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}

.logic-ball {
  width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  border: 0;
  background: linear-gradient(135deg, #2f80ed, #12b886);
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.45), 0 3px 0 rgba(36,48,79,0.12);
}

.logic-ball-btn {
  width: 32px;
  height: 32px;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

.logic-ball-btn:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.45), 0 6px 0 rgba(36,48,79,0.14);
}

.logic-ball-btn:active {
  transform: translateY(1px) scale(0.96);
}

.logic-ball.leftover {
  background: linear-gradient(135deg, #f76707, #ffd23f);
}

.logic-caption {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: rgba(255,255,255,0.84);
  border: 2px solid rgba(255,255,255,0.9);
  color: var(--c-text);
  font-size: 14px;
  font-weight: 700;
  padding: var(--sp-2) var(--sp-4);
}

.logic-live {
  color: var(--c-text-muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.logic-shape-target,
.logic-shape-sequence {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-3);
}

.logic-sequence-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.logic-sequence-item.next-slot {
  width: 72px;
  height: 72px;
  border-radius: var(--r-md);
  border: 3px dashed rgba(36,48,79,0.22);
  background: rgba(255,255,255,0.62);
  color: var(--c-text-muted);
  font-size: 32px;
  font-weight: 700;
}

.logic-shape {
  width: 80px;
  height: 80px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.82);
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow: 0 5px 0 rgba(36,48,79,0.10);
}

.logic-shape-cell {
  border-radius: var(--r-sm);
  background: rgba(36,48,79,0.10);
}

.logic-shape-cell.active {
  background: linear-gradient(135deg, var(--c-blue), var(--c-green));
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.45), 0 3px 0 rgba(36,48,79,0.12);
}

.logic-shape-choice {
  min-height: 132px;
  padding: var(--sp-3);
}

.logic-shape-choice .logic-shape {
  width: 88px;
  height: 88px;
  box-shadow: none;
}

.logic-symbol-board {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-2);
}

.logic-symbol-row {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.78);
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 4px 0 rgba(36,48,79,0.08);
}

.logic-symbol-icon {
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.logic-symbol-op {
  color: var(--c-text-muted);
  font-size: 24px;
  font-weight: 700;
}

.logic-symbol-total {
  min-width: 48px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  background: #eef8ff;
  color: var(--c-text);
  font-size: 24px;
  font-weight: 700;
  padding: 0 var(--sp-2);
}

.logic-symbol-total.unknown {
  background: #fff3bf;
  color: #7c2d12;
}

.logic-icon-sequence {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-3);
}

.logic-icon-tile {
  min-width: 72px;
  min-height: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.82);
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow: 0 5px 0 rgba(36,48,79,0.10);
  font-size: 32px;
  font-weight: 700;
  padding: var(--sp-2);
}

.logic-icon-tile.next-slot {
  border-style: dashed;
  color: var(--c-text-muted);
  background: rgba(255,255,255,0.62);
}

.logic-icon-choice {
  font-size: 36px;
  min-height: 104px;
}

.geometry-board {
  width: min(100%, 360px);
  min-height: 152px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.76);
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow: 0 5px 0 rgba(36,48,79,0.10);
  padding: var(--sp-3);
}

.geometry-board svg {
  width: 100%;
  max-width: 300px;
  height: auto;
  overflow: visible;
}

.geometry-board text {
  fill: var(--c-text);
  font-family: 'Fredoka', system-ui, sans-serif;
  font-size: 18px;
  font-weight: 700;
}

.geometry-fraction-square {
  width: min(100%, 280px);
  aspect-ratio: 1;
  display: grid;
  background: #ffffff;
  border: 6px solid #ffffff;
  border-radius: var(--r-md);
  box-shadow: 0 6px 0 rgba(36,48,79,0.12), 0 0 0 3px #168aad;
  overflow: hidden;
}

.geometry-fraction-part {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: #dff6ff;
  border: 3px solid #168aad;
}

.geometry-fraction-part.active {
  background: linear-gradient(135deg, #cc5de8, #845ef7);
  color: #ffffff;
}

.geometry-missing-fraction {
  width: 72px;
  display: grid;
  justify-items: center;
  line-height: 1;
  color: inherit;
  filter: drop-shadow(0 3px 0 rgba(36,48,79,0.18));
}

.geometry-missing-fraction strong,
.geometry-missing-fraction em {
  width: 100%;
  min-height: 60px;
  display: grid;
  place-items: center;
  font-size: 56px;
  font-style: normal;
  font-weight: 700;
}

.geometry-missing-fraction em {
  border-top: 6px solid currentColor;
}

.geometry-area-grid {
  width: min(100%, 260px);
  display: grid;
  gap: 4px;
  padding: var(--sp-2);
  border-radius: var(--r-md);
  background: #e7f5ff;
  border: 3px solid rgba(22,138,173,0.32);
}

.geometry-area-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  background: linear-gradient(135deg, #6ed7ff, #12b886);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.5);
}

.geometry-area-label {
  margin-left: var(--sp-4);
  min-width: 72px;
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  background: #fff3bf;
  color: #7c2d12;
  font-size: 24px;
  font-weight: 700;
  padding: var(--sp-2);
}

.geometry-symmetry-shape {
  width: 144px;
  height: 112px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-lg);
  background: #ede9fe;
  color: var(--c-purple);
  font-size: 92px;
  line-height: 1;
}

.geometry-symmetry-shape.symmetry-circle {
  border-radius: 50%;
}

.geometry-symmetry-shape.symmetry-arrow {
  clip-path: polygon(50% 0, 100% 52%, 70% 52%, 70% 100%, 30% 100%, 30% 52%, 0 52%);
  background: linear-gradient(135deg, #ffd23f, #ff8fb3);
  color: transparent;
}

.geometry-mirror-line {
  position: absolute;
  inset: 8px auto 8px 50%;
  width: 4px;
  border-radius: var(--r-full);
  background: repeating-linear-gradient(180deg, rgba(36,48,79,0.48) 0 8px, transparent 8px 14px);
  transform: translateX(-50%);
}

.geometry-choice {
  background: linear-gradient(135deg, #ffffff, #eef8ff);
}

.problem.flash-good { animation: zoom-good 0.5s ease-out; }
.problem.flash-bad  { animation: shake 0.45s; }
/* Each new question bounces in ("fill: backwards", never "both" — see the
   choice-in gotcha: "both" pins the final transform and kills later states). */
.problem.problem-in { animation: problem-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards; }
@keyframes problem-in {
  0%   { transform: scale(0.45) rotate(-4deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes zoom-good { 0% { transform: scale(1); } 50% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes shake     { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

/* ─────── PROGRESS DOTS ─────── */
.progress-bar-wrap {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}
.progress-bar-wrap.hidden { display: none !important; }

.progress-dots {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
}
.progress-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(36,48,79,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  line-height: 1;
  transition: background 0.25s, transform 0.2s;
}
/* A filled dot IS a gold star (textContent set in updateProgressDots) —
   the circle chrome goes away and the star spins in with an overshoot. */
.progress-dot.filled {
  background: transparent;
  transform: scale(1.25);
  filter: drop-shadow(0 3px 0 rgba(36,48,79,0.15));
  animation: star-spin-in 480ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Named distinctly from the result card's `star-pop` — duplicate @keyframes
   names silently resolve to whichever is defined last in the file. */
@keyframes star-spin-in {
  0%   { transform: scale(0) rotate(-120deg); opacity: 0.4; }
  65%  { transform: scale(1.6) rotate(14deg); opacity: 1; }
  100% { transform: scale(1.25) rotate(0deg); }
}

/* ─────── CHOICE BUTTONS ─────── */
.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
  width: 100%;
  max-width: 440px;
}

.choice {
  background: #ffffff;
  border: 3px solid rgba(255,255,255,0.92);
  border-radius: var(--r-md);
  padding: var(--sp-5) var(--sp-4);
  font-family: inherit;
  font-size: 28px;
  font-weight: 700;
  color: var(--c-text);
  cursor: pointer;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 7px 0 rgba(124,77,255,0.30), 0 9px 0 rgba(36,48,79,0.12), 0 16px 22px rgba(36,48,79,0.18);
  transition: transform var(--t-mid), box-shadow var(--t-mid), background var(--t-mid);
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* `backwards` (not `both`): hold the pre-entrance state, but DON'T pin the final
     transform afterwards — otherwise it overrides the :hover/:active press motion. */
  animation: choice-in 260ms var(--t-slow) backwards;
}
.choice:nth-child(1) { animation-delay: 0ms; }
.choice:nth-child(2) { animation-delay: 45ms; }
.choice:nth-child(3) { animation-delay: 90ms; }
.choice:nth-child(4) { animation-delay: 135ms; }

@keyframes choice-in {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.choice:hover  {
  transform: translateY(-3px);
  background: #fff8dc;
  box-shadow: 0 10px 0 rgba(124,77,255,0.32), 0 12px 0 rgba(36,48,79,0.12), 0 22px 28px rgba(36,48,79,0.22), 0 0 14px rgba(167,139,250,0.3);
}
/* Press the button physically down into its own shadow lip */
.choice:active {
  transform: translateY(6px);
  box-shadow: 0 1px 0 rgba(124,77,255,0.30), 0 2px 0 rgba(36,48,79,0.12), 0 4px 8px rgba(36,48,79,0.18);
}
.choice:disabled { transform: none; }

.choice[data-state="right"] {
  background: linear-gradient(135deg, #0ca678, var(--c-green)) !important;
  border-color: var(--c-green) !important;
  color: white;
  box-shadow: 0 0 20px rgba(52,211,153,0.5) !important;
  animation: pop 0.4s var(--t-slow);
}
.choice[data-state="wrong"] {
  background: linear-gradient(135deg, #c92a2a, var(--c-red)) !important;
  border-color: var(--c-red) !important;
  color: white;
  box-shadow: 0 0 20px rgba(248,113,113,0.5) !important;
  animation: shake 0.45s ease-out;
}

.logic-check-choice {
  grid-column: 1 / -1;
  max-width: 280px;
  width: 100%;
  margin: 0 auto;
}

@keyframes pop { 0% { transform: scale(1); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* Locked state */
.choices.locked .choice {
  pointer-events: none;
  cursor: default;
}
.choices.locked .choice[data-state] { opacity: 1; }
.choices.locked .choice:not([data-state]) {
  opacity: 0.36;
  transform: scale(0.94);
  filter: saturate(0.65);
}

/* ─────── HINT BUTTON ─────── */
.play-actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
}

.hint-btn {
  background: #fff3bf;
  border: 2px solid rgba(247,103,7,0.32);
  border-radius: var(--r-full);
  padding: var(--sp-3) var(--sp-5);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--c-orange);
  cursor: pointer;
  min-height: 48px;
  transition: transform var(--t-fast), opacity 0.2s, background var(--t-fast);
}
.hint-btn:hover  { background: rgba(251,146,60,0.25); }
.hint-btn:active { transform: translateY(2px); }
.hint-btn:disabled { opacity: 0.35; cursor: default; }
.hint-btn.loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: var(--sp-2);
  border-radius: 50%;
  border: 2px solid rgba(251,146,60,0.25);
  border-top-color: var(--c-orange);
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}

/* ─────── CHEER TEXT ─────── */
.cheer {
  min-height: 32px;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  background: linear-gradient(135deg, var(--c-purple), var(--c-pink), var(--c-orange));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  transition: opacity 0.25s;
  padding: 0 var(--sp-3);
  line-height: 1.3;
}
.cheer.show { opacity: 1; }
.cheer.hint-mode {
  background: none;
  color: #7c2d12;
  font-size: 14px;
  font-weight: 600;
}

/* ─────── LEVEL PICKER ─────── */
.levels-path {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-width: 400px;
  width: 100%;
  margin: var(--sp-5) auto var(--sp-8);
  padding: 0 var(--sp-2);
  gap: 0;
}

.path-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

/* Horizontal connector */
.path-connector {
  flex: 1;
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    rgba(124,58,237,0.36) 0,
    rgba(124,58,237,0.36) 6px,
    transparent 6px,
    transparent 14px
  );
  border-radius: var(--r-full);
  margin: 0 var(--sp-1);
}

/* Vertical connector between rows */
.path-vconnector {
  width: 4px;
  height: 28px;
  background: repeating-linear-gradient(
    180deg,
    rgba(124,58,237,0.36) 0,
    rgba(124,58,237,0.36) 6px,
    transparent 6px,
    transparent 14px
  );
  border-radius: var(--r-full);
  margin: var(--sp-1) 0;
}

/* Level nodes */
.path-node {
  flex: 0 0 auto;
  width: 80px;
  height: 80px;
  position: relative;
  border: none;
  border-radius: 50%;
  padding: 0;
  font-family: inherit;
  font-size: 24px;
  font-weight: 700;
  color: #1a1a2e;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(36,48,79,0.16), 0 14px 24px rgba(36,48,79,0.16);
  transition: transform var(--t-mid), box-shadow var(--t-mid);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
}
.path-node:hover {
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 11px 0 rgba(36,48,79,0.18), 0 18px 26px rgba(36,48,79,0.2);
}
.path-node:active {
  transform: translateY(5px) scale(0.99);
  box-shadow: 0 2px 0 rgba(36,48,79,0.16), 0 4px 8px rgba(36,48,79,0.18);
}

.path-node .lbl {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: rgba(26,26,46,0.7);
}

/* Difficulty gradients */
.path-node[data-difficulty="easy"]   { background: linear-gradient(135deg,#fef3c7,#fbbf24); }
.path-node[data-difficulty="medium"] { background: linear-gradient(135deg,#bfdbfe,#60a5fa); }
.path-node[data-difficulty="hard"]   { background: linear-gradient(135deg,#fbcfe8,#f472b6); }
.path-node[data-difficulty="expert"] { background: linear-gradient(135deg,#fecaca,#f87171); color: #7f1d1d; }
.path-node[data-difficulty="expert"] .lbl { color: rgba(127,29,19,0.7); }

/* Crown icon */
.path-node .crown {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s;
}
.path-node.cleared .crown { opacity: 1; }

/* Cleared node */
.path-node.cleared {
  opacity: 1;
  box-shadow: 0 6px 0 rgba(36,48,79,0.14), 0 0 0 3px rgba(18,184,134,0.42);
}

/* Current/next level: pulsing glow ring */
.path-node.current-level {
  animation: node-pulse 1.8s ease-in-out infinite;
}

@keyframes node-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(167,139,250,0.6), 0 6px 16px rgba(0,0,0,0.2); }
  50%       { box-shadow: 0 0 0 10px rgba(167,139,250,0), 0 6px 16px rgba(0,0,0,0.2); }
}

/* Locked nodes */
.path-node.locked-level {
  opacity: 0.55;
  filter: grayscale(0.3);
  cursor: default;
}

/* Daily Challenge */
.path-node.daily-challenge-node {
  background: linear-gradient(135deg, #fbbf24, #fb923c, #fbbf24) !important;
  background-size: 200% 200% !important;
  animation: node-pulse 1.8s ease-in-out infinite, daily-shimmer 3s ease-in-out infinite !important;
  color: #7c2d12 !important;
  box-shadow: 0 6px 24px rgba(251,191,36,0.55), 0 0 0 2px rgba(251,191,36,0.3) !important;
  font-size: 18px;
}
.path-node.daily-challenge-node .lbl { color: #92400e !important; }

@keyframes daily-shimmer {
  0%, 100% { background-position: 0% 50%; }
  50%       { background-position: 100% 50%; }
}

.daily-done {
  font-size: 12px;
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
}

/* ─────── RESUME BUTTON ─────── */
.resume-wrap {
  max-width: 400px;
  width: 100%;
  margin: var(--sp-3) auto 0;
  padding: 0 var(--sp-2);
}

.resume-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--c-purple-2), var(--c-pink));
  color: white;
  border: none;
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-5);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(36,48,79,0.18), 0 14px 24px rgba(124,58,237,0.25);
  transition: transform var(--t-mid);
  min-height: 52px;
}
.resume-btn:hover  { transform: translateY(-1px); }
.resume-btn:active { transform: translateY(2px); }

/* ─────── RESULT SCREEN ─────── */
#screen-result.active {
  align-items: center;
  justify-content: center;
}

.result-card {
  background: rgba(255,255,255,0.9);
  border: 3px solid rgba(255,255,255,0.94);
  border-radius: var(--r-xl);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: var(--sp-10) var(--sp-8);
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-card), 0 18px 44px rgba(124,58,237,0.18);
}

.result-mascot {
  font-size: 80px;
  animation: bounce-mascot 1.2s ease-in-out infinite;
  display: inline-block;
}

@keyframes bounce-mascot {
  0%, 100% { transform: translateY(0) scale(1); }
  50%       { transform: translateY(-14px) scale(1.05); }
}

.result-card h2 {
  font-size: 32px;
  margin: var(--sp-3) 0 var(--sp-2);
  background: linear-gradient(135deg, var(--c-purple), var(--c-pink), var(--c-orange));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.result-card p {
  color: var(--c-text-muted);
  font-size: 16px;
  margin-bottom: var(--sp-5);
}

.result-stars {
  font-size: 40px;
  margin-bottom: var(--sp-6);
  letter-spacing: 4px;
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
}

/* Star stagger pop-in */
.result-stars .star {
  display: inline-block;
  animation: star-pop 0.4s var(--t-slow) backwards;
}
.result-stars .star:nth-child(1) { animation-delay: 0.1s; }
.result-stars .star:nth-child(2) { animation-delay: 0.25s; }
.result-stars .star:nth-child(3) { animation-delay: 0.4s; }

/* Stars lost to mistakes: dimmed empty slots */
.result-stars .star-missed {
  filter: grayscale(1);
  opacity: 0.28;
}

@keyframes star-pop {
  0%   { transform: scale(0); opacity: 0; }
  70%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* ─────── PROGRESS BAR (unused but kept) ─────── */
.progress-bar { display: none; }

/* ─────── REDUCED MOTION ─────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-name: none !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 520px) {
  .screen {
    padding: var(--sp-4);
    padding:
      max(var(--sp-4), env(safe-area-inset-top))
      max(var(--sp-4), env(safe-area-inset-right))
      max(var(--sp-4), env(safe-area-inset-bottom))
      max(var(--sp-4), env(safe-area-inset-left));
  }

  #screen-game.screen {
    min-height: 100dvh;
    padding: var(--sp-2);
    padding:
      max(var(--sp-2), env(safe-area-inset-top))
      max(var(--sp-2), env(safe-area-inset-right))
      max(var(--sp-2), env(safe-area-inset-bottom))
      max(var(--sp-2), env(safe-area-inset-left));
  }

  .game-bar {
    border-radius: var(--r-lg);
    align-items: flex-start;
  }

  #screen-game .game-bar {
    gap: var(--sp-2);
    padding: var(--sp-2);
    align-items: center;
    border-radius: var(--r-md);
  }

  .stats {
    gap: var(--sp-2);
  }

  #screen-game .stats {
    gap: var(--sp-1);
  }

  #screen-game .stat {
    min-height: 28px;
    padding: 2px var(--sp-2);
    font-size: 12px;
  }

  #screen-game .bar-player {
    min-height: 32px;
    padding: 2px var(--sp-2);
  }

  #screen-game .badge-name {
    max-width: 54px;
  }

  #screen-game .iconbtn,
  #screen-game .music-toggle-compact {
    min-width: 40px;
    width: 40px;
    min-height: 40px;
    height: 40px;
    padding: 0;
  }

  .mode-btn {
    grid-template-columns: 64px minmax(0, 1fr) 32px;
    min-height: 88px;
    padding: var(--sp-4);
  }

  .mode-emoji { font-size: 48px; }

  .rewards-panel {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }

  .achievements-card {
    grid-column: auto;
  }

  .mission-grid {
    grid-template-columns: 1fr;
  }

  .mission-card {
    min-height: 104px;
  }

  .power-copy {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--sp-2);
  }

  .shop-grid {
    grid-template-columns: 1fr;
  }

  h1,
  .profile-title {
    font-size: 32px;
  }

  .problem {
    font-size: 24px;
  }

  #screen-game .play {
    justify-content: flex-start;
    gap: var(--sp-2);
    padding: var(--sp-2) 0 0;
    /* No hardcoded height guess: the screen (height:100dvh, overflow-y:auto)
       owns the scroll, so tall content is reachable instead of clipped. */
    overflow: visible;
  }

  #screen-game .mascot-inline {
    font-size: 60px;
  }

  #screen-game .mascot-cosmetic {
    top: -14px;
    font-size: 24px;
  }

  #screen-game .mascot-pet {
    right: -18px;
    font-size: 22px;
  }

  #screen-game .power-panel {
    min-height: 52px;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-md);
  }

  #screen-game .power-panel::after {
    font-size: 40px;
    right: var(--sp-3);
  }

  #screen-game .power-copy {
    flex-direction: row;
    align-items: center;
    gap: var(--sp-2);
  }

  #screen-game .power-label {
    min-height: 28px;
    padding: 2px var(--sp-2);
    font-size: 11px;
  }

  #screen-game .power-copy strong {
    font-size: 14px;
  }

  #screen-game .power-meter {
    height: 12px;
  }

  #screen-game .game-status {
    min-height: 36px;
    padding: var(--sp-2) var(--sp-3);
    font-size: 12px;
    line-height: 1.3;
    border-radius: var(--r-sm);
  }

  .problem-box {
    padding: var(--sp-4);
  }

  #screen-game .problem-box {
    gap: var(--sp-1);
    padding: var(--sp-3);
    border-radius: var(--r-lg);
  }

  .logic-caption {
    width: 100%;
    text-align: center;
    line-height: 1.4;
  }

  .logic-shape,
  .logic-shape-choice .logic-shape {
    width: 68px;
    height: 68px;
    gap: var(--sp-1);
  }

  .logic-sequence-item.next-slot,
  .logic-icon-tile {
    min-width: 60px;
    width: 60px;
    min-height: 60px;
    height: 60px;
    font-size: 28px;
  }

  .logic-shape-sequence,
  .logic-icon-sequence {
    gap: var(--sp-2);
    padding: var(--sp-2);
  }

  .logic-symbol-row {
    gap: var(--sp-1);
    min-height: 52px;
  }

  .logic-symbol-icon {
    min-width: 32px;
    font-size: 24px;
  }

  .logic-symbol-op {
    font-size: 20px;
  }

  .logic-symbol-total {
    min-width: 40px;
    font-size: 20px;
  }

  #screen-game .geometry-board {
    min-height: 112px;
    padding: var(--sp-2);
  }

  #screen-game .geometry-board svg {
    max-width: 240px;
  }

  #screen-game .geometry-board text {
    font-size: 16px;
  }

  #screen-game .geometry-area-grid {
    max-width: 200px;
    gap: 3px;
  }

  #screen-game .geometry-area-label {
    min-width: 56px;
    min-height: 44px;
    margin-left: var(--sp-2);
    font-size: 18px;
  }

  #screen-game .geometry-symmetry-shape {
    width: 112px;
    height: 88px;
    font-size: 72px;
  }

  .problem.equation {
    font-size: 48px;
  }

  #screen-game .problem.equation {
    font-size: clamp(40px, 13vw, 56px);
  }

  #screen-game .problem.equation.seq {
    font-size: clamp(24px, 9vw, 44px);
  }

  #screen-game .problem.equation.wordy {
    font-size: clamp(19px, 6vw, 28px);
    line-height: 1.4;
  }

  #screen-game .problem.logic-problem,
  #screen-game .problem {
    font-size: clamp(20px, 6vw, 28px);
    line-height: 1.2;
    padding: 0;
  }

  #screen-game .problem-emoji {
    font-size: 28px;
  }

  #screen-game .progress-dots {
    gap: var(--sp-2);
  }

  #screen-game .progress-dot {
    width: 11px;
    height: 11px;
  }

  .path-node {
    width: 72px;
    height: 72px;
  }

  .choices {
    gap: var(--sp-3);
  }

  #screen-game .choices {
    gap: var(--sp-2);
    max-width: 100%;
  }

  .choice {
    min-height: 68px;
    font-size: 24px;
  }

  #screen-game .choice {
    min-height: 56px;
    padding: var(--sp-3) var(--sp-2);
    border-radius: var(--r-md);
    font-size: clamp(20px, 7vw, 26px);
  }

  #screen-game .hint-btn {
    min-height: 40px;
    padding: var(--sp-2) var(--sp-4);
    font-size: 13px;
  }

  #screen-game .cheer {
    min-height: 24px;
    font-size: 18px;
    line-height: 1.2;
  }

  #screen-game .cheer.hint-mode {
    font-size: 12px;
    line-height: 1.25;
  }

  .modal-actions {
    flex-direction: column;
  }
}

/* Short viewports (small/older phones, landscape): shrink the home hero so a
   playable mode button sits within reach instead of below a 220px dragon. */
@media (max-height: 740px) {
  .hero { padding-top: var(--sp-2); }
  .dragon,
  .dragon-svg { width: 150px; height: 150px; }
  .dragon::before { width: 124px; height: 124px; }
  h1,
  .profile-title { font-size: 40px; }
  .modes { margin-top: var(--sp-4); }
}

@media (max-width: 380px), (max-height: 720px) {
  /* Keep the mascot VISIBLE even on short screens (was display:none) — just
     compact. The play screen owns its own scroll, so it still fits. */
  #screen-game .mascot-inline {
    font-size: 46px;
  }

  #screen-game .play {
    gap: var(--sp-2);
  }

  #screen-game .problem-box {
    padding: var(--sp-2);
  }

  #screen-game .power-panel {
    min-height: 44px;
  }

  #screen-game .power-copy strong {
    font-size: 12px;
  }

  #screen-game .choices {
    gap: var(--sp-1);
  }

  #screen-game .choice {
    min-height: 50px;
    padding: var(--sp-2);
  }

  #screen-game .geometry-board {
    min-height: 96px;
  }

  #screen-game .geometry-board svg {
    max-width: 210px;
  }

  #screen-game .geometry-area-grid {
    max-width: 176px;
  }

  #screen-game .logic-caption,
  #screen-game .logic-live {
    font-size: 12px;
  }
}
