:root {
  --ink: #1f2a4d;
  --ink-soft: #55608a;
  --card: #ffffff;
  --sky-1: #7cc8fb;
  --sky-2: #b9e3ff;
  --orange: #ff8a3d;
  --orange-d: #d4621b;
  --teal: #1fc3a5;
  --teal-d: #12907a;
  --yellow: #ffd23f;
  --yellow-d: #d9a90f;
  --pink: #ff5d8f;
  --purple: #8b6cff;
  --good: #22b573;
  --bad: #ff5d5d;
  --land: #dfe7f5;
  --radius: 26px;
  --shadow: 0 6px 0 rgba(31, 42, 77, 0.12), 0 18px 40px rgba(31, 42, 77, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Fredoka", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 55%, #e8f6ff 100%) fixed;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* drifting clouds */
.sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.cloud {
  position: absolute; width: 180px; height: 56px; background: #fff; border-radius: 60px; opacity: .75;
  animation: drift 60s linear infinite;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; top: -38px; left: 26px; }
.cloud::after { width: 64px; height: 64px; top: -26px; left: 92px; }
.c1 { top: 8%; left: -200px; }
.c2 { top: 32%; left: -200px; transform: scale(.7); animation-duration: 85s; animation-delay: -40s; }
.c3 { top: 70%; left: -200px; transform: scale(.9); animation-duration: 75s; animation-delay: -20s; opacity: .5; }
@keyframes drift { to { left: calc(100% + 200px); } }

main {
  position: relative; z-index: 1;
  max-width: 760px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(16px, 4vw, 28px); margin-bottom: 18px;
}
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.1; }
h2 { font-size: 1.4rem; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 1.1rem; border: 0; cursor: pointer; color: #fff;
  padding: .7em 1.2em; border-radius: 18px; position: relative; top: 0;
  transition: top .08s, box-shadow .08s, filter .15s; touch-action: manipulation; white-space: nowrap;
}
.btn:active { top: 4px; }
.btn:disabled { filter: grayscale(.7) opacity(.6); cursor: default; }
.btn-primary { background: var(--orange); box-shadow: 0 5px 0 var(--orange-d); }
.btn-primary:active { box-shadow: 0 1px 0 var(--orange-d); }
.btn-teal { background: var(--teal); box-shadow: 0 5px 0 var(--teal-d); }
.btn-teal:active { box-shadow: 0 1px 0 var(--teal-d); }
.btn-clue { background: var(--yellow); color: var(--ink); box-shadow: 0 5px 0 var(--yellow-d); font-size: 1rem; }
.btn-clue:active { box-shadow: 0 1px 0 var(--yellow-d); }
.btn-big { font-size: 1.35rem; padding: .75em 1.6em; width: 100%; }
.btn:focus-visible, .link-btn:focus-visible, .answer-input:focus-visible, .icon-btn:focus-visible {
  outline: 4px solid var(--purple); outline-offset: 3px;
}
.link-btn {
  font: inherit; background: none; border: 0; color: var(--ink-soft); text-decoration: underline;
  cursor: pointer; padding: .6em; font-size: 1rem;
}
.icon-btn {
  font-size: 1.4rem; width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.85); box-shadow: 0 3px 0 rgba(31,42,77,.15);
}
.mute { position: fixed; z-index: 5; top: max(12px, env(safe-area-inset-top)); right: 12px; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 12px 0 18px; }
.logo-badge {
  width: 84px; height: 84px; margin: 0 auto 8px; display: grid; place-items: center; font-size: 46px;
  background: var(--yellow); border-radius: 28px; box-shadow: 0 6px 0 var(--yellow-d);
  transform: rotate(-8deg); animation: bob 3s ease-in-out infinite;
}
.hero h1 {
  font-size: clamp(2.6rem, 10vw, 4rem); font-weight: 700; color: #fff; letter-spacing: .5px;
  text-shadow: 0 4px 0 rgba(31,42,77,.25);
}
.hero h1 span { color: var(--yellow); }
.tagline { margin: 0; font-size: 1.15rem; color: var(--ink); font-weight: 500; }
.steps { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 10px; }
.steps li { display: flex; gap: 12px; align-items: center; font-size: 1.05rem; line-height: 1.35; }
.step-ico {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; font-size: 1.4rem;
  background: #f1f5ff; border-radius: 14px;
}
.region-pill {
  display: inline-block; margin: 0 0 14px; padding: .35em .9em; border-radius: 999px;
  background: #eef9f6; color: var(--teal-d); font-weight: 600;
}

/* ---------- mode picker ---------- */
.mode-pick { margin: 0 0 14px; }
.mode-q { margin: 0 0 8px; font-weight: 600; font-size: 1.1rem; }
.mode-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-opt {
  font: inherit; color: var(--ink); text-align: left; cursor: pointer; display: grid; gap: 2px;
  padding: .7em .9em; border-radius: 18px; border: 3px solid #dfe5f3; background: #fbfcff;
  box-shadow: 0 4px 0 #dfe5f3; transition: border-color .15s, background .15s, transform .15s;
}
.mode-opt b { font-size: 1.2rem; }
.mode-opt small { color: var(--ink-soft); font-size: .92rem; line-height: 1.25; }
.mode-opt[aria-checked="true"] { border-color: var(--purple); background: #f3efff; box-shadow: 0 4px 0 var(--purple); transform: translateY(-2px); }
.mode-opt:focus-visible { outline: 4px solid var(--purple); outline-offset: 3px; }
.mode-note { margin: 8px 0 0; color: var(--ink-soft); font-size: .98rem; min-height: 1.3em; }
.board-mode { font-size: .9rem; font-weight: 600; color: var(--purple); background: #f3efff; padding: .2em .6em; border-radius: 999px; vertical-align: middle; }

/* ---------- multiple choice ---------- */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.choice-btn {
  font: inherit; font-weight: 600; font-size: 1.12rem; color: var(--ink); cursor: pointer; line-height: 1.2;
  padding: .75em .6em; border-radius: 18px; border: 3px solid #dfe5f3; background: #fff;
  box-shadow: 0 5px 0 #dfe5f3; position: relative; top: 0; touch-action: manipulation;
  transition: top .08s, box-shadow .08s, background .2s, border-color .2s;
}
.choice-btn:hover:not(:disabled) { border-color: var(--purple); }
.choice-btn:active:not(:disabled) { top: 4px; box-shadow: 0 1px 0 #dfe5f3; }
.choice-btn:focus-visible { outline: 4px solid var(--purple); outline-offset: 3px; }
.choice-btn kbd { font: inherit; font-size: .8rem; color: #9aa3bf; margin-right: .35em; }
.choice-btn.wrong { background: #ffe9e9; border-color: var(--bad); color: #c44; box-shadow: none; top: 4px; text-decoration: line-through; animation: shake .4s; }
.choice-btn.right { background: var(--good); border-color: var(--good); color: #fff; box-shadow: 0 5px 0 #178a56; animation: pop .45s; }
.choice-btn.right kbd { color: #d6ffe9; }
.choice-btn:disabled { cursor: default; }
.choice-btn:disabled:not(.right):not(.wrong) { opacity: .55; }
.bonus .choices { margin-top: 10px; }

/* ---------- leaderboard ---------- */
.board { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; counter-reset: rank; }
.board li {
  counter-increment: rank; display: grid; grid-template-columns: 2.2em 1fr auto; align-items: center; gap: 8px;
  padding: .5em .8em; border-radius: 14px; background: #f5f8ff; font-size: 1.05rem;
}
.board li::before { content: counter(rank); font-weight: 700; color: var(--ink-soft); text-align: center; }
.board li:nth-child(1)::before { content: "🥇"; }
.board li:nth-child(2)::before { content: "🥈"; }
.board li:nth-child(3)::before { content: "🥉"; }
.board .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .who small { font-weight: 400; color: var(--ink-soft); margin-left: 6px; }
.board .pts { font-weight: 700; color: var(--orange-d); }
.board li.me { background: #fff4c2; outline: 3px solid var(--yellow); animation: pop .5s; }
.board .empty { grid-template-columns: 1fr; color: var(--ink-soft); background: none; text-align: center; }
.board li.empty::before { content: none; }

/* ---------- game ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 60px 14px 0; }
.progress { display: flex; gap: 6px; flex-wrap: wrap; }
.dot {
  width: 22px; height: 22px; border-radius: 50%; background: rgba(255,255,255,.6);
  display: grid; place-items: center; font-size: 12px; transition: transform .2s;
}
.dot.now { background: #fff; transform: scale(1.25); box-shadow: 0 0 0 3px var(--orange); }
.dot.t0 { background: var(--good); } .dot.t1 { background: var(--teal); } .dot.t2 { background: var(--yellow); }
.dot.miss { background: #c9d2e6; }
.score-pill {
  background: #fff; border-radius: 999px; padding: .3em .9em; font-weight: 700; font-size: 1.25rem;
  box-shadow: 0 3px 0 rgba(31,42,77,.15); white-space: nowrap;
}
.score-pill.bump { animation: pop .45s; }

.stage-card { position: relative; }
.tiers { display: flex; gap: 6px; flex-wrap: wrap; padding-right: 64px; }
.tier {
  padding: .3em .75em; border-radius: 999px; font-size: .95rem; font-weight: 600;
  background: #eef1f8; color: #9aa3bf; transition: all .25s;
}
.tier.on { background: var(--purple); color: #fff; transform: scale(1.05); }
.tier.done { background: #e4ddff; color: var(--purple); }

.timer { position: absolute; top: 12px; right: 14px; width: 58px; height: 58px; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 5; }
.timer-bg { stroke: #eef1f8; }
.timer-fg { stroke: var(--teal); stroke-linecap: round; stroke-dasharray: 119.4; transition: stroke .3s; }
.timer.low .timer-fg { stroke: var(--bad); }
.timer.low { animation: wiggle .5s ease-in-out infinite; }
#timer-num {
  position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 1.3rem;
}
.timer.paused { opacity: .35; animation: none; }

.stage {
  position: relative; margin: 10px 0 6px; height: clamp(220px, 42dvh, 380px);
  border-radius: 20px; background:
    radial-gradient(circle at 30% 25%, #fff 0, transparent 60%),
    repeating-linear-gradient(45deg, #f4f8ff 0 14px, #eef4ff 14px 28px);
  overflow: hidden;
}
.shape-svg, .map-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.shape-svg { padding: 6%; transition: all .55s cubic-bezier(.5,1.6,.4,1); }
.shape-svg .state-shape {
  stroke-linejoin: round; stroke-width: 4; vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 6px 0 rgba(31,42,77,.15));
}
.shape-svg.drawing .state-shape { animation: draw 1.6s ease-out forwards, fillin .6s 1.1s ease-out forwards; }
.shape-svg.floating .float { animation: float 4s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
/* once the map is showing, the shape tucks into the corner */
.stage.with-map .shape-svg {
  inset: auto auto 8px 8px; width: 28%; height: 34%; padding: 4px;
  background: rgba(255,255,255,.9); border-radius: 14px; box-shadow: 0 3px 0 rgba(31,42,77,.12);
}
.map-svg { animation: fadein .5s ease-out; }
.stage:not(.with-map) .map-svg { display: none; }
.map-svg .land { fill: var(--land); }
.map-svg .borders { fill: none; stroke: #fff; stroke-width: 1; stroke-linejoin: round; }
.map-svg .target { stroke: #fff; stroke-width: 1.2; animation: blink 1.2s ease-in-out infinite; }
.map-svg .ring { fill: none; stroke: var(--pink); stroke-width: 3; transform-box: fill-box; transform-origin: center; animation: ring 1.6s ease-out infinite; }
.map-svg .ring2 { animation-delay: .8s; }

.facts { list-style: none; padding: 0; margin: 10px 0 4px; display: grid; gap: 8px; }
.facts li {
  background: #fff8db; border: 2px solid #ffe58a; border-radius: 16px; padding: .55em .8em; font-size: 1.02rem;
  line-height: 1.35; animation: slidein .45s backwards;
}
.facts li:nth-child(2) { animation-delay: .25s; }
.facts li:nth-child(3) { animation-delay: .5s; }
.facts li::before { content: "📜 "; }

.answer-row { display: flex; gap: 10px; margin-top: 12px; }
.answer-input {
  flex: 1; min-width: 0; font: inherit; font-size: 1.25rem; padding: .55em .8em; color: var(--ink);
  border: 3px solid #dfe5f3; border-radius: 18px; background: #fbfcff; transition: border-color .2s;
}
.answer-input:focus { border-color: var(--purple); outline: none; }
.answer-input.shake { animation: shake .4s; border-color: var(--bad); }
.under-row { display: flex; justify-content: center; margin-top: 14px; }
.feedback { min-height: 1.5em; margin: 10px 0 0; text-align: center; font-weight: 600; font-size: 1.1rem; }
.feedback.bad { color: var(--bad); }
.feedback.good { color: var(--good); }

.result { margin-top: 14px; animation: slidein .4s; }
.result-head { display: flex; align-items: center; gap: 14px; }
.result-emoji { font-size: 3rem; animation: pop .6s; }
.result-title { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.result-sub { color: var(--ink-soft); font-size: 1.05rem; margin-top: 2px; }
.bonus { margin-top: 14px; padding: 14px; border-radius: 18px; background: #eafaf6; border: 2px dashed var(--teal); }
.bonus-q { margin: 0; font-size: 1.15rem; font-weight: 600; }
.bonus .link-btn { display: block; margin: 6px auto 0; }
#next { margin-top: 16px; }

/* ---------- end ---------- */
.end-card { text-align: center; }
.trophy { font-size: 4.5rem; animation: bob 2.4s ease-in-out infinite; }
.end-title { font-size: 2rem; margin-bottom: .2em; }
.end-score { font-size: 2.6rem; font-weight: 700; color: var(--orange); margin: 0; }
.end-stats { color: var(--ink-soft); font-size: 1.1rem; margin: 4px 0 14px; }
.recap { list-style: none; padding: 0; margin: 0 0 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; text-align: left; }
.recap li { background: #f5f8ff; border-radius: 14px; padding: .5em .7em; font-size: .98rem; line-height: 1.3; }
.recap b { display: block; }
.recap small { color: var(--ink-soft); }
.name-form { background: #fff8db; border-radius: 18px; padding: 14px; margin-bottom: 18px; }
.name-form p { margin: 0; font-size: 1.1rem; }
.board-title { margin-top: 6px; }
.end-card .board { text-align: left; margin-bottom: 18px; }
.end-actions { display: grid; gap: 4px; }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 10; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px;
  animation: fall linear forwards;
}

/* ---------- animations ---------- */
@keyframes draw { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
@keyframes fillin { from { fill-opacity: 0; } to { fill-opacity: 1; } }
@keyframes float { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-6px) rotate(-4deg); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes slidein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 0%,100% { fill-opacity: 1; } 50% { fill-opacity: .55; } }
@keyframes ring { from { transform: scale(.4); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

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

/* ---------- small screens ---------- */
@media (max-width: 520px) {
  .choice-btn { font-size: 1.02rem; padding: .7em .4em; }
  .choice-btn kbd { display: none; }
  .mode-opt b { font-size: 1.08rem; }
  .progress { gap: 4px; }
  .dot { width: 16px; height: 16px; font-size: 10px; }
  .answer-row .btn { padding: .7em .9em; }
  .tier { font-size: .85rem; padding: .25em .6em; }
  .timer { width: 50px; height: 50px; top: 10px; right: 10px; }
  .tiers { padding-right: 56px; }
  .result-title { font-size: 1.45rem; }
  .steps li { font-size: 1rem; }
}
/* phones in landscape / short screens: keep input visible above the keyboard */
@media (max-height: 560px) {
  .stage { height: 46dvh; }
  .hero { padding: 0 0 10px; }
  .logo-badge { display: none; }
}
