:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #1f2a30;
  --muted: #5d6b73;
  --border: #ddd6c8;
  --accent: #1d5c63;
  --accent-text: #ffffff;
  --water: #dcebf0;
  --land: #c9d2d6;
  --land-dim: #dde3e5;
  --land-stroke: #ffffff;
  --context: #e6e3da;
  /* Candidate highlight colors: bordering candidates never share one. */
  --hl-0: #f29b38;
  --hl-1: #5a9ee3;
  --hl-2: #a77de0;
  --hl-3: #ecd04a;
  --hl-stroke: #26323a;
  --arrow: #3f4b53;
  --correct: #23935f;
  --wrong: #d23f4c;
  --danger: #b3261e;
  /* Stars: gold for earned levels, teal-blue for maxed states. */
  --gold: #e8a512;
  --gold-soft: #fbe7b0;
  --permanent: #1fa3c4;
  --pip-empty: #d7dcdf;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181c;
    --surface: #1b252b;
    --text: #e8edef;
    --muted: #9fb0b8;
    --border: #2e3b42;
    --accent: #4fb3bf;
    --accent-text: #0b1214;
    --water: #16252d;
    --land: #43535c;
    --land-dim: #2b373e;
    --land-stroke: #11181c;
    --context: #1f2a30;
    --hl-0: #f29b38;
    --hl-1: #5f9fe6;
    --hl-2: #b08ae6;
    --hl-3: #e6cc47;
    --hl-stroke: #f4f7f8;
    --arrow: #c7d2d7;
    --correct: #33b679;
    --wrong: #f0606c;
    --danger: #f2817a;
    --gold: #f2b631;
    --gold-soft: #4a3d1c;
    --permanent: #43c3e0;
    --pip-empty: #3a4850;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ---- screens ------------------------------------------------------- */

.screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 32px;
  -webkit-overflow-scrolling: touch;
}

.center { display: flex; flex-direction: column; align-items: center; text-align: center; justify-content: center; }
.center-text { text-align: center; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
}
.topbar-actions { display: flex; gap: 8px; }
.app-title { display: flex; align-items: center; gap: 10px; font-size: 1.5rem; margin: 0 4px; color: var(--accent); }
.app-mark { width: 1.6em; height: auto; flex: none; }
.screen-title { font-size: 1.25rem; margin: 0; }
.icon-btn-spacer { width: 48px; }

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  flex: none;
}

/* ---- buttons, cards ------------------------------------------------ */

.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.big { font-size: 1.15rem; min-height: 58px; }
.btn.small { min-height: 40px; font-size: 0.85rem; padding: 6px 10px; }
.btn.danger { color: var(--danger); margin-top: 32px; }
.btn:active { transform: scale(0.98); }
.btn + .btn { margin-top: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 1.35rem; font-weight: 700; }
.eyebrow { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.next-desc { margin: 4px 0 14px; }
.next-desc p { margin: 0; }
/* The warm-up card's how-to-play: a one-line hook, then three short steps. */
.next-desc .how-hook { margin: 6px 0 12px; font-size: 1.05rem; color: var(--text); }
.how-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.how-steps li { display: flex; gap: 10px; align-items: baseline; }
.how-steps li > :first-child { flex: none; width: 1.4em; text-align: center; color: var(--gold); }
.how-steps strong { color: var(--text); }
/* The home card's map: each state shaded by its level, filling in with 💎. */
.next-map { position: relative; aspect-ratio: 975 / 610; margin: -4px 0 8px; }
.next-map .map-wrap { margin: 0; }
.resume { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-color: var(--accent); }
.resume .btn { width: auto; flex: none; }

.section-title { font-size: 1.05rem; margin: 22px 0 10px; }

/* ---- game ---------------------------------------------------------- */

.game-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 4px;
}
.game-stat { flex: 1; display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: 1.1rem; }
.game-stat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; text-align: center; line-height: 1.1; }

.prompt {
  text-align: center;
  padding: 4px 12px 8px;
}
.prompt-label { display: block; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.prompt-name { display: block; font-size: 2rem; font-weight: 800; line-height: 1.15; }

.map-area { flex: 1; min-height: 200px; position: relative; }

.game-footer {
  padding: 8px 16px 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
}
.hint, .result { margin: 0; text-align: center; min-height: 2.9em; display: flex; align-items: center; justify-content: center; }
.hint { color: var(--muted); }
.result { font-size: 1.1rem; font-weight: 700; line-height: 1.3; }
.result.correct { color: var(--correct); }
.result.wrong { color: var(--wrong); }
.debug-bar { display: flex; gap: 6px; }
.debug-bar .btn { font-size: 0.75rem; }
.debug-bar .btn + .btn { margin-top: 0; }

/* ---- map ----------------------------------------------------------- */

.map-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--water);
  border-radius: var(--radius);
  margin: 0 8px;
}
.map-wrap.zoomable .map { touch-action: none; }
.map { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }

.state {
  fill: var(--land);
  stroke: var(--land-stroke);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  pointer-events: none;
  transition: fill 0.2s;
}
.state.tappable { pointer-events: auto; cursor: pointer; }
.state.inert { fill: var(--land-dim); }
.state.candidate, .state.revealed { stroke: var(--hl-stroke); stroke-width: 2.5; }
.state.revealed { fill-opacity: 0.45; stroke-width: 1.5; }
.state.hl-0 { fill: var(--hl-0); }
.state.hl-1 { fill: var(--hl-1); }
.state.hl-2 { fill: var(--hl-2); }
.state.hl-3 { fill: var(--hl-3); }
/* After the palette so the reveal colors win. */
.state.correct { fill: var(--correct); stroke: var(--hl-stroke); stroke-width: 2.5; }
.state.wrong { fill: var(--wrong); stroke: var(--hl-stroke); stroke-width: 2.5; }

.context { fill: var(--context); stroke: none; pointer-events: none; }

/* Magnifier bubbles: an enlarged copy of a tiny state, with an arrow to it. */
.bubble { pointer-events: none; }
.bubble.tappable { pointer-events: auto; cursor: pointer; }
.bubble-hit { fill: transparent; }
.bubble-bg { fill: var(--surface); }
.bubble-ring { fill: none; stroke: var(--hl-stroke); stroke-width: 2; vector-effect: non-scaling-stroke; }
.bubble-shape { fill: var(--land); stroke: var(--hl-stroke); stroke-width: 1; vector-effect: non-scaling-stroke; }
.bubble-arrow { stroke: var(--arrow); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.arrowhead { fill: var(--arrow); }
.bubble.hl-0 .bubble-shape, .bubble.hl-0 .bubble-ring { --c: var(--hl-0); }
.bubble.hl-1 .bubble-shape, .bubble.hl-1 .bubble-ring { --c: var(--hl-1); }
.bubble.hl-2 .bubble-shape, .bubble.hl-2 .bubble-ring { --c: var(--hl-2); }
.bubble.hl-3 .bubble-shape, .bubble.hl-3 .bubble-ring { --c: var(--hl-3); }
.bubble.correct .bubble-shape, .bubble.correct .bubble-ring { --c: var(--correct); }
.bubble.wrong .bubble-shape, .bubble.wrong .bubble-ring { --c: var(--wrong); }
.bubble[class*="hl-"] .bubble-shape, .bubble.correct .bubble-shape, .bubble.wrong .bubble-shape { fill: var(--c); }
.bubble[class*="hl-"] .bubble-ring, .bubble.correct .bubble-ring, .bubble.wrong .bubble-ring { stroke: var(--c); stroke-width: 3; }
.bubble.revealed .bubble-shape { fill-opacity: 0.45; }
.ring .bubble-ring { fill: transparent; stroke-dasharray: 5 3; }
.ring.revealed .bubble-ring { stroke-opacity: 0.6; }
.hidden { display: none; }

.map-labels { position: absolute; inset: 0; pointer-events: none; }
.map-label {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 7px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.map-label.correct { background: var(--correct); color: #fff; border-color: transparent; font-size: 0.95rem; }
.map-label.wrong { background: var(--wrong); color: #fff; border-color: transparent; font-size: 0.95rem; }

/* Top-right: usually empty Arctic Canada, away from the Atlantic bubbles and Hawaii. */
.zoom-controls {
  position: absolute;
  right: 8px;
  top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom-controls button {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.3rem;
  font-weight: 700;
  opacity: 0.92;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---- stars and progress -------------------------------------------- */

.meter { display: inline-flex; flex-direction: column; align-items: stretch; gap: 3px; vertical-align: middle; }
.pips { display: inline-flex; align-items: center; gap: 3px; }
.pip {
  width: 18px;
  height: 18px;
  background: var(--pip-empty);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.pip.on { background: var(--gold); }
.meter.maxed .pip.on { background: var(--permanent); }
.pip.gain { animation: pip-gain 0.55s cubic-bezier(.3, 1.6, .5, 1) var(--delay, 0ms) both; }
.meter-tag { font-size: 0.95em; margin-left: 2px; line-height: 1; }
.meter-tag.gain { animation: pip-gain 0.6s cubic-bezier(.3, 1.6, .5, 1) calc(var(--delay, 0ms) + 150ms) both; }

@keyframes pip-gain {
  0% { transform: scale(0) rotate(-90deg); background: var(--pip-empty); }
  60% { transform: scale(1.6) rotate(15deg); }
  100% { transform: scale(1) rotate(0); }
}

/* XP toward the next level, under the stars. Fills from --from to --to. */
.xp-bar { display: block; height: 4px; border-radius: 2px; background: var(--pip-empty); overflow: hidden; }
.xp-fill {
  display: block;
  height: 100%;
  width: var(--to);
  border-radius: 2px;
  background: var(--gold);
  animation: xp-fill 0.9s cubic-bezier(.3, 1.2, .5, 1) calc(var(--delay, 0ms) + 200ms) both;
}
.meter.maxed .xp-fill { background: var(--permanent); }
@keyframes xp-fill {
  from { width: var(--from); }
  to { width: var(--to); }
}

/* Under the target name during a round. */
.meter-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-height: 28px;
  margin-top: 2px;
}
.meter-row .pip { width: 22px; height: 22px; }
.meter-note { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.float {
  position: absolute;
  /* Beside the stars, rising, so it never covers the state's name. */
  left: calc(50% + 48px);
  top: 2px;
  font-weight: 800;
  pointer-events: none;
  animation: float-up 1.1s ease-out forwards;
}
.float.up { color: var(--gold); }
.float.down { color: var(--wrong); }
@keyframes float-up {
  0% { transform: translate(0, 6px) scale(0.8); opacity: 0; }
  20% { transform: translate(0, 0) scale(1.2); opacity: 1; }
  100% { transform: translate(8px, -14px) scale(1); opacity: 0; }
}
.burst, .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}
.burst { animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) both; }
.burst.unlock, .badge.unlock { background: var(--gold); color: #2b1d00; }
.burst.gem, .badge.gem { background: var(--permanent); color: #00222b; }
.burst.gem { animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) both, shimmer 1.6s linear 0.6s infinite; }
.burst.fire, .badge.fire { background: var(--gold-soft); color: var(--text); }
.burst.lost, .badge.lost { background: color-mix(in srgb, var(--wrong) 18%, var(--surface)); color: var(--wrong); }
@keyframes burst-in {
  0% { transform: scale(0.2); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shimmer { 50% { filter: brightness(1.25) saturate(1.3); } }

#g-goal { display: inline-block; }
#g-goal.bump { animation: bump 0.7s cubic-bezier(.3, 1.6, .5, 1); color: var(--gold); }
@keyframes bump { 40% { transform: scale(1.5); } }

.progress-label { font-size: 0.95rem; margin: 6px 0 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.progress-label strong { font-size: 1.3rem; }
.progress-sub { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.progress-track {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: var(--pip-empty);
  overflow: hidden;
  margin-bottom: 14px;
}
.progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 7px;
  transition: width 1.2s cubic-bezier(.3, 1.2, .5, 1);
}
/* Stacked: level 2+ underneath, then level 3+, then maxed on top. */
.progress-fill.l2 { background: color-mix(in srgb, var(--gold) 45%, var(--pip-empty)); }
.progress-fill.l3 { background: linear-gradient(90deg, var(--gold), color-mix(in srgb, var(--gold) 70%, #fff)); }
.progress-fill.l4 { background: var(--permanent); }
.delta { font-weight: 800; padding: 0 8px; border-radius: 999px; animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) 1.4s both; }
.delta.up { background: var(--gold); color: #2b1d00; }

.stage-picker { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 4px 0 12px; }
.stage-picker label { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.stage-picker input { width: 72px; font: inherit; text-align: center; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.stage-picker .btn { width: auto; flex: none; min-width: 48px; }

.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 1000; overflow: hidden; }
.confetti { position: absolute; left: 0; top: 0; width: 9px; height: 13px; border-radius: 2px; }
.confetti.emoji { width: auto; height: auto; background: none; font-size: 20px; }

/* ---- end screen ---------------------------------------------------- */

.end-head { text-align: center; }
.end-emoji { font-size: 3.5rem; margin-top: 4px; animation: burst-in 0.7s cubic-bezier(.3, 1.6, .5, 1) both; }
.end-score { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.level-card { margin-top: 10px; }
.end-message { font-size: 1.05rem; margin: 0; font-weight: 600; }
.stack { width: 100%; max-width: 420px; margin-top: 16px; }
.end-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 452px; /* 420px of buttons plus the padding */
  margin: 0 auto;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
}
.end-footer-row { display: flex; gap: 8px; }
.end-footer-row .btn { flex: 1; margin: 0; }

.round-list { list-style: none; margin: 0; padding: 0; }
.round-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 6px;
  animation: row-in 0.35s ease-out var(--delay, 0ms) both;
}
.round-list .mark { font-weight: 800; width: 1.2em; text-align: center; }
.round-list .right .mark { color: var(--correct); }
.round-list .missed .mark { color: var(--wrong); }
.round-list .round-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-list .badge { font-size: 0.75rem; padding: 2px 8px; animation: burst-in 0.5s cubic-bezier(.3, 1.6, .5, 1) calc(var(--delay, 0ms) + 450ms) both; }
@keyframes row-in {
  from { transform: translateX(-16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
}
.chip small { color: var(--muted); font-weight: 500; }

/* ---- help ---------------------------------------------------------- */

.prose h2 { font-size: 1.1rem; margin: 22px 0 6px; }
.prose li { margin-bottom: 6px; }
.tag { padding: 0 6px; border-radius: 6px; color: #fff; font-weight: 700; white-space: nowrap; }
.tag.correct { background: var(--correct); }
.tag.wrong { background: var(--wrong); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }
.row input { width: 80px; font: inherit; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* ---- stats --------------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.tile .value { font-size: 1.6rem; font-weight: 800; }
.tile .label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.stats-map { position: relative; aspect-ratio: 975 / 610; }
.stats-map .map-wrap { margin: 0; }
.stats-map .state { pointer-events: auto; cursor: pointer; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend-bar { flex: 1; min-width: 80px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, hsl(5 70% 55%), hsl(45 85% 55%), hsl(150 55% 40%)); }
.legend-none::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--land-dim); margin-right: 4px; vertical-align: -1px; }

.level-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.level-table th, .level-table td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--border); }
.level-table th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; }

/* ---- dialog -------------------------------------------------------- */

.dialog {
  border: none;
  border-radius: 18px;
  padding: 20px;
  width: min(92vw, 420px);
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog.celebrate { text-align: center; animation: burst-in 0.5s cubic-bezier(.3, 1.6, .5, 1); }
.dialog.celebrate h2 { font-size: 1.6rem; }
.dialog h2 { margin: 0 0 8px; font-size: 1.3rem; }
.dialog p { margin: 0 0 8px; }
.dialog .stack { margin-top: 12px; }

/* ---- warm-up build-up ---------------------------------------------- */

/* The home card when one state is left. */
.next-up.final {
  border: 2px solid var(--gold);
  animation: final-glow 1.8s ease-in-out infinite;
}
.next-up.final .eyebrow { color: var(--gold); }
@keyframes final-glow {
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 35%, transparent), 0 0 24px color-mix(in srgb, var(--gold) 60%, transparent); }
}

.burst.grand { background: linear-gradient(90deg, var(--gold), #ffe48a, var(--gold)); color: #2b1d00; font-size: 1.05rem; animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) both, shimmer 1.2s linear 0.6s infinite; }
.burst.victory { background: linear-gradient(90deg, var(--permanent), #b8f1ff, var(--gold), var(--permanent)); background-size: 200% 100%; color: #04222b; font-size: 1.1rem; animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) both, shimmer 1.2s linear 0.6s infinite; }
.banner.gem .banner-box { background: linear-gradient(160deg, #e6fbff, #7fd8ec 55%, #1fa3c4); color: #04222b; }
.btn.finale-next { background: linear-gradient(90deg, #c98a0a, var(--gold), #c98a0a); color: #2b1d00; animation: final-glow 1.4s ease-in-out infinite; }

/* Big in-game announcement. --tier (set per banner, 4 by default) scales its
   size, glow, entrance and pulse, so the countdown to victory keeps building. */
.banner {
  --tier: 4;
  --slam: calc(1 + var(--tier) * 0.3);
  --pulse: calc(1 + var(--tier) * 0.008);
  --glow: #fff8;
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
  animation: fade-in 0.25s ease-out both;
  cursor: pointer;
}
.banner-box {
  width: min(100%, calc(344px + var(--tier) * 24px));
  text-align: center;
  padding: 24px 20px 16px;
  border-radius: 22px;
  background: linear-gradient(160deg, #fff4cc, #f7c948 55%, #e8a512);
  color: #2b1d00;
  box-shadow: 0 0 0 4px #fff8, 0 0 calc(var(--tier) * 12px) var(--glow), 0 20px 60px rgba(0, 0, 0, 0.45);
  animation: slam-in 0.55s cubic-bezier(.2, 1.6, .4, 1) both, banner-pulse 1.4s ease-in-out 0.6s infinite;
}
.banner.gem { --glow: #7fd8ecaa; }
.banner.grand .banner-box { background: linear-gradient(160deg, #1b2a55, #0b1430); color: #fff4cc; box-shadow: 0 0 0 3px #f2b631, 0 0 calc(var(--tier) * 15px) #f2b63199; }
.banner-emoji { font-size: calc(2.4rem + var(--tier) * 0.4rem); line-height: 1; animation: burst-in 0.7s cubic-bezier(.3, 1.6, .5, 1) 0.2s both; }
.banner-title { font-size: calc(1.4rem + var(--tier) * 0.15rem); font-weight: 900; line-height: 1.1; margin: 8px 0; letter-spacing: -0.01em; }
.banner-body { font-size: 1.1rem; }
.banner-tap { margin-top: 14px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.7; }
@keyframes slam-in {
  from { transform: scale(var(--slam)) rotate(-4deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes banner-pulse { 50% { transform: scale(var(--pulse)); } }

/* A region conquered: good news, but not the main event. */
.banner.quiet { background: rgba(0, 0, 0, 0.3); }
.banner.quiet .banner-box {
  width: min(100%, 320px);
  padding: 18px 18px 12px;
  background: linear-gradient(160deg, #fffaf0, #fbe7a8);
  box-shadow: 0 0 0 3px #fff8, 0 12px 40px rgba(0, 0, 0, 0.35);
  animation: pop-in 0.35s ease-out both;
}
.banner.quiet .banner-emoji { font-size: 2.6rem; }
.banner.quiet .banner-title { font-size: 1.4rem; }
.banner.quiet .banner-body { font-size: 1rem; }
@keyframes pop-in { from { transform: scale(0.85); opacity: 0; } }

/* All 50 maxed: the biggest moment of the game. */
.banner.champion { background: rgba(0, 0, 0, 0.65); }
.banner.champion .banner-box {
  background: linear-gradient(120deg, #1fa3c4, #b8f1ff, #fff, #ffe48a, #c99a1a, #ffe48a, #b8f1ff, #1fa3c4);
  background-size: 300% 100%;
  color: #04222b;
  animation: slam-in 0.7s cubic-bezier(.2, 1.6, .4, 1) both, banner-pulse 1.1s ease-in-out 0.7s infinite,
    champion-shift 3s linear infinite, champion-glow 1.1s ease-in-out 0.7s infinite;
}
.banner.champion .banner-emoji { animation: champion-spin 0.9s cubic-bezier(.3, 1.6, .5, 1) 0.25s both; }
.banner.champion .banner-title { font-size: 2.6rem; }
.banner.champion .banner-body { font-size: 1.2rem; }
@keyframes champion-shift { to { background-position: 300% 0; } }
@keyframes champion-glow {
  0%, 100% { box-shadow: 0 0 0 4px #fff, 0 0 60px #43c3e0, 0 20px 60px rgba(0, 0, 0, 0.5); }
  50% { box-shadow: 0 0 0 4px #ffe48a, 0 0 110px #f2b631, 0 20px 60px rgba(0, 0, 0, 0.5); }
}
@keyframes champion-spin { from { transform: scale(0) rotate(-540deg); } }
@keyframes fade-in { from { opacity: 0; } }

/* ---- achievements -------------------------------------------------- */

.icon-btn { position: relative; }
.icon-btn.unseen::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--wrong);
  border: 2px solid var(--surface);
}
#ach-btn:not([hidden]) { animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) both; }

.ach-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.ach {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.ach.earned { border-color: var(--gold); background: linear-gradient(135deg, var(--gold-soft), var(--surface) 70%); }
.ach-icon {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  border-radius: 50%;
  background: var(--bg);
}
.ach.earned .ach-icon { background: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 35%, transparent); }
.ach.locked .ach-icon { filter: grayscale(1); opacity: 0.5; }
.ach.locked .ach-title { color: var(--muted); }
.ach-text { min-width: 0; }
.ach-title { font-weight: 800; }
.ach-desc { font-size: 0.85rem; color: var(--muted); line-height: 1.3; }
.ach-date { font-size: 0.72rem; color: var(--muted); margin-top: 2px; font-weight: 600; }
.ach.pop { animation: burst-in 0.5s cubic-bezier(.3, 1.6, .5, 1) var(--delay) both; }

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 50%;
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 10px 18px 10px 10px;
  border-radius: 999px;
  background: #1b2a55;
  color: #fff4cc;
  box-shadow: 0 0 0 2px #f2b631, 0 8px 24px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -150%);
  pointer-events: none;
}
.toast.in { animation: toast-in 0.45s cubic-bezier(.3, 1.5, .5, 1) both; }
.toast.out { animation: toast-out 0.3s ease-in both; }
.toast-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; font-size: 1.4rem; border-radius: 50%; background: #f2b631; }
.toast-text { display: flex; flex-direction: column; line-height: 1.2; }
.toast-eyebrow { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; white-space: nowrap; }
@keyframes toast-in {
  from { transform: translate(-50%, -150%); }
  to { transform: translate(-50%, 0); }
}
@keyframes toast-out {
  from { transform: translate(-50%, 0); }
  to { transform: translate(-50%, -150%); }
}

/* ---- warm-up finale ------------------------------------------------ */
/* A night-sky look in both themes, unlike any other screen. */

:root {
  --finale-gold: #f2b631;
  --night: #0b1430;
  --night-2: #1b2a55;
  --night-text: #fff4cc;
}

.finale, .reveal {
  max-width: none;
  background: radial-gradient(ellipse at 50% 30%, var(--night-2), var(--night) 70%);
  color: var(--night-text);
  overflow: hidden;
}
.finale-inner {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow-y: auto;
}
.finale-eyebrow { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.3em; color: var(--finale-gold); font-weight: 700; }
.finale-map { position: relative; width: 100%; aspect-ratio: 975 / 610; margin: 8px 0; }
.finale-map .map-wrap, .title-map .map-wrap { margin: 0; background: transparent; border-radius: 0; }
.finale-map .context { fill: #ffffff0d; }
.finale-map .state { fill: #2a3b6b; stroke: var(--night); transition: none; }
.finale-map .state.lit {
  transform-box: fill-box;
  transform-origin: center;
  animation: state-pop 0.6s ease-out both;
}
@keyframes state-pop {
  0% { filter: brightness(2.2); transform: scale(1.35); }
  100% { filter: none; transform: none; }
}
.finale-map.all-lit .map { animation: map-glow 2.2s ease-in-out infinite; }
@keyframes map-glow {
  50% { filter: drop-shadow(0 0 10px var(--finale-gold)) brightness(1.15); }
}
.finale-count { font-size: 1.5rem; font-weight: 900; color: var(--finale-gold); font-variant-numeric: tabular-nums; }
.finale-count.done { animation: burst-in 0.6s cubic-bezier(.3, 1.6, .5, 1) both; font-size: 1.9rem; }
.finale-head { margin-top: 8px; width: 100%; }
.finale-emoji { font-size: 4rem; line-height: 1; animation: burst-in 0.8s cubic-bezier(.3, 1.6, .5, 1) both; }
.finale-title {
  margin: 6px 0 0;
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 900;
  line-height: 1.05;
  animation: slam-in 0.6s cubic-bezier(.2, 1.6, .4, 1) 0.15s both;
}
.finale-sub { margin: 6px 0 14px; opacity: 0.85; animation: fade-in 0.6s ease-out 0.5s both; }
.finale-stats { display: flex; gap: 8px; justify-content: center; margin-bottom: 18px; animation: fade-in 0.6s ease-out 0.7s both; }
.finale-stat { flex: 1; max-width: 120px; padding: 8px; border-radius: 12px; background: #ffffff12; border: 1px solid #ffffff22; }
.finale-stat .value { font-size: 1.4rem; font-weight: 800; }
.finale-stat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.btn.finale-btn {
  max-width: 420px;
  margin: 0 auto;
  background: linear-gradient(90deg, #c98a0a, var(--finale-gold), #c98a0a);
  color: #2b1d00;
  border-color: transparent;
  font-weight: 800;
}
.finale-head .finale-btn { animation: fade-in 0.6s ease-out 1.2s both, final-glow 1.6s ease-in-out 1.8s infinite; --gold: var(--finale-gold); }

/* ---- the reveal ---------------------------------------------------- */

.reveal { position: relative; background: #000; justify-content: center; }
.reveal.shake { animation: shake 0.5s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  20%, 60% { transform: translate(-8px, 4px); }
  40%, 80% { transform: translate(8px, -4px); }
}
.reveal-skip {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  right: 12px;
  z-index: 2;
  background: none;
  border: 1px solid #ffffff44;
  color: #ffffffaa;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}

.reveal-lines {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 24px;
  font-family: Georgia, "Times New Roman", serif;
  text-align: center;
  transition: opacity 0.8s ease-in;
}
.reveal-lines.fade-out { opacity: 0; }
.reveal-line { margin: 0 0 18px; font-size: 1.35rem; line-height: 1.35; min-height: 1.35em; transition: opacity 0.6s; animation: fade-in 0.4s ease-out both; }
.reveal-line:not(:last-child) { opacity: 0.45; }
.reveal-line.em { color: var(--finale-gold); }
.reveal-line.big { font-size: 1.9rem; font-weight: 700; margin-top: 30px; color: #fff; }

.title-card {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
}
.title-map {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(140vw, 1100px);
  aspect-ratio: 975 / 610;
  transform: translate(-50%, -50%);
  opacity: 0.22;
  animation: title-map-in 3s ease-out both;
  pointer-events: none;
}
.title-map .context { fill: none; }
.title-map .state { fill: var(--finale-gold); stroke: #000; }
@keyframes title-map-in {
  from { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}
.title-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; animation: flash 0.7s ease-out 0.85s both; }
@keyframes flash { 10% { opacity: 0.85; } 100% { opacity: 0; } }
.title-logo {
  position: relative;
  margin: 0;
  display: flex;
  flex-direction: column;
  font-size: clamp(3.2rem, 17vw, 7rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.04em;
  background: linear-gradient(100deg, #a8740a 0%, #ffe48a 30%, #fff 42%, #ffe48a 54%, #c99a1a 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #6b4800) drop-shadow(0 0 30px #f2b63188);
  animation: logo-slam 0.6s cubic-bezier(.5, 0, .7, 1) 0.3s both, shine 3s linear 1.2s infinite;
}
@keyframes logo-slam {
  from { transform: scale(4); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes shine {
  from { background-position: 100% 0; }
  to { background-position: -150% 0; }
}
.title-sub {
  position: relative;
  margin-top: 18px;
  font-size: clamp(0.8rem, 3.6vw, 1.3rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  white-space: nowrap;
  text-transform: uppercase;
  color: #fff;
  animation: sub-in 0.8s ease-out 1.3s both;
}
@keyframes sub-in {
  from { opacity: 0; letter-spacing: 0.8em; }
}
.title-press {
  position: relative;
  margin-top: 48px;
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--finale-gold);
  opacity: 0;
}
.title-card.ready { cursor: pointer; }
.title-card.ready .title-press { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.overview {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 16px;
  min-height: 0;
  background: radial-gradient(ellipse at 50% 20%, var(--night-2), transparent 70%);
  animation: fade-in 0.6s ease-out both;
}
.overview-eyebrow { text-align: center; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.3em; color: var(--finale-gold); font-weight: 700; margin-bottom: 8px; }
.overview-track {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.overview-track::-webkit-scrollbar { display: none; }
.ov-card {
  flex: 0 0 100%;
  scroll-snap-align: center;
  overflow-y: auto;
  padding: 8px 6px;
  text-align: center;
}
.ov-card h2 { margin: 4px 0 10px; font-size: 1.7rem; color: #fff; }
.ov-icon { font-size: 3.4rem; line-height: 1.1; }
.ov-card.seen .ov-icon { animation: burst-in 0.7s cubic-bezier(.3, 1.6, .5, 1) both; }
.ov-body { font-size: 1.05rem; line-height: 1.45; }
.ov-body p { margin: 0 0 12px; }
.ov-body strong { color: var(--finale-gold); }
.ov-caption { font-size: 0.85rem; opacity: 0.7; }

.stairs { display: flex; align-items: flex-end; gap: 8px; height: 140px; margin: 8px 4px 6px; }
.stair { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.stair-bar {
  height: var(--h);
  border-radius: 8px 8px 2px 2px;
  background: linear-gradient(180deg, var(--finale-gold), #a8740a);
  color: #2b1d00;
  font-weight: 800;
  font-size: 0.85rem;
  padding-top: 2px;
  transform-origin: bottom;
}
.ov-card.seen .stair-bar { animation: grow 0.6s cubic-bezier(.3, 1.4, .5, 1) var(--delay) both; }
@keyframes grow { from { transform: scaleY(0); } }
.stair-label { font-size: 0.75rem; opacity: 0.75; margin-top: 4px; }
.stair-label::before { content: "Stage "; }
.stair:not(:first-child) .stair-label::before { content: ""; }

.ov-levels { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 8px; }
.ov-level { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 250px; white-space: nowrap; padding: 8px 12px; border-radius: 12px; background: #ffffff12; }
.ov-level span:last-child { font-weight: 700; }
.ov-level .pip { width: 24px; height: 24px; }
.ov-level .pip:not(.on) { background: #ffffff30; }
.ov-level .xp-bar { display: none; }

.ov-achs { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.ov-achs .ach { background: #ffffff12; border-color: var(--finale-gold); color: var(--night-text); box-shadow: none; }
.ov-achs .ach-desc, .ov-achs .ach-date { color: #fff4ccaa; }
.ov-achs .ach.pop { animation: none; }
.ov-card.seen .ov-achs .ach.pop { animation: burst-in 0.5s cubic-bezier(.3, 1.6, .5, 1) var(--delay) both; }

.overview-dots { display: flex; justify-content: center; gap: 4px; margin: 10px 0 12px; }
.dot { width: 28px; height: 28px; padding: 0; border: none; background: none; cursor: pointer; display: grid; place-items: center; }
.dot::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #ffffff40; transition: transform 0.2s, background 0.2s; }
.dot.on::before { background: var(--finale-gold); transform: scale(1.3); }
#overview-next.go { animation: final-glow 1.4s ease-in-out infinite; --gold: var(--finale-gold); }

/* Landscape phones: put the prompt beside the bar to give the map height. */
@media (orientation: landscape) and (max-height: 500px) {
  .game-bar { padding-top: 4px; }
  .prompt { padding: 0 12px 4px; }
  .prompt-name { font-size: 1.5rem; display: inline; }
  .prompt-label { display: inline; margin-right: 8px; }
  .game-footer { min-height: 0; flex-direction: row; align-items: center; }
  .game-footer .btn.big { width: auto; min-width: 140px; }
  .result, .hint { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---- victory ------------------------------------------------------- */
/* The warm-up finale's night sky, turned to diamonds. */

.victory { position: relative; justify-content: center; }
.victory.shake { animation: shake 0.5s cubic-bezier(.36, .07, .19, .97); }
.victory .finale-map .state.lit { animation-duration: 0.8s; }
.victory .finale-map.all-lit .map { animation: gem-glow 2.2s ease-in-out infinite; }
@keyframes gem-glow {
  50% { filter: drop-shadow(0 0 12px var(--permanent)) brightness(1.2); }
}
.victory .finale-count { color: #8fe6f8; }
/* "safe": when the title and stats overflow, scroll from the top instead of clipping it. */
.victory .finale-inner { justify-content: safe center; }
.victory .finale-map { transition: width 0.6s ease-in-out; }
.victory-scene.done .finale-map { width: 62%; }
.victory-logo {
  flex-direction: row;
  justify-content: center;
  font-size: clamp(2.6rem, 13vw, 5.5rem);
  background-image: linear-gradient(100deg, #1fa3c4 0%, #b8f1ff 30%, #fff 42%, #ffe48a 54%, #c99a1a 100%);
  filter: drop-shadow(0 4px 0 #0b4a5a) drop-shadow(0 0 30px #43c3e088);
}
.victory-head .title-sub { margin-top: 10px; animation-delay: 1s; }
.victory-medal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 16px 0 12px;
  animation: fade-in 0.6s ease-out 1.3s both;
}
.victory-medal .medal { font-size: 3.5rem; line-height: 1; animation: burst-in 0.8s cubic-bezier(.3, 1.6, .5, 1) 1.3s both; }
.victory-medal strong { color: var(--finale-gold); }
.victory-head .finale-stats { animation-delay: 1.5s; }
.victory-achs { margin: 0 auto 18px; max-width: 420px; }
.victory-achs .ach.pop { animation: burst-in 0.5s cubic-bezier(.3, 1.6, .5, 1) var(--delay) both; }
.victory-head .finale-btn { animation-delay: 2.4s, 3s; }
