/* ============ tokens & themes ============ */
:root {
  --font: 'Baloo 2', ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ink: #1f2440; --muted: #5d6585; --card: #ffffff; --line: #e3e7f3;
  --ok: #2f9e44; --bad: #e03131; --gold: #fab005;
  --radius: 22px; --shadow: 0 8px 0 rgba(20, 30, 70, .10), 0 14px 30px rgba(20, 30, 70, .10);
  --bg1: #b2f2bb; --bg2: #e6fcf5; --accent: #2f9e44; --accent2: #66a80f; --accent-ink: #fff;
}
body[data-theme="jungle"] { --bg1: #b2f2bb; --bg2: #e9fac8; --accent: #2f9e44; --accent2: #66a80f; }
body[data-theme="ocean"]  { --bg1: #a5d8ff; --bg2: #e3fafc; --accent: #1971c2; --accent2: #0c8599; }
body[data-theme="space"]  { --bg1: #d0bfff; --bg2: #f3f0ff; --accent: #6741d9; --accent2: #c2255c; }

@media (prefers-color-scheme: dark) {
  :root { --ink: #eef1ff; --muted: #a8b0cf; --card: #1d2240; --line: #2f3663; --shadow: 0 8px 0 rgba(0,0,0,.35), 0 14px 30px rgba(0,0,0,.35); }
  body[data-theme="jungle"] { --bg1: #12301c; --bg2: #0d1f14; }
  body[data-theme="ocean"]  { --bg1: #0b2545; --bg2: #081a30; }
  body[data-theme="space"]  { --bg1: #24164d; --bg2: #120c2b; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--font); color: var(--ink); min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg1), var(--bg2)) fixed;
  transition: background .6s;
}
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }
h1, h2 { margin: 0; line-height: 1.15; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ============ buttons ============ */
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.btn {
  background: var(--card); color: var(--ink); border-radius: 16px; padding: 12px 20px; font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 5px 0 var(--line); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: linear-gradient(180deg, var(--accent2), var(--accent)); color: var(--accent-ink); box-shadow: 0 5px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.btn.primary:active { box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.btn.ghost { background: transparent; box-shadow: none; border: 2px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: .95rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }

/* ============ top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.2rem; white-space: nowrap; }
.pills { display: flex; gap: 6px; align-items: center; }
.pill { background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 2px 10px; font-weight: 700; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.pill.icon { padding: 2px 8px; }
.xpbar { width: 52px; height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; display: inline-block; }
.xpbar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #ff922b); transition: width .6s; }
@media (max-width: 420px) { .brand { font-size: 0; } .brand::first-letter { font-size: 1.4rem; } .xpbar { width: 34px; } }

.screen { display: none; }
.screen.active { display: block; animation: enter .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes enter { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ============ worlds ============ */
.hero { text-align: center; margin: 18px 0 20px; }
.hero h1 { font-size: clamp(1.5rem, 5vw, 2.1rem); }
.hero-emoji { font-size: 4rem; }
.worlds { display: grid; gap: 14px; }
.world {
  position: relative; overflow: hidden; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 18px; border-radius: var(--radius); text-align: left; color: #fff; box-shadow: var(--shadow); transition: transform .15s;
}
.world:hover { transform: translateY(-3px) rotate(-.4deg); }
.world:active { transform: scale(.98); }
.world[data-theme="jungle"] { background: linear-gradient(135deg, #37b24d, #74b816); }
.world[data-theme="ocean"]  { background: linear-gradient(135deg, #1c7ed6, #15aabf); }
.world[data-theme="space"]  { background: linear-gradient(135deg, #5f3dc4, #c2255c); }
.world .w-emoji { font-size: 3rem; filter: drop-shadow(0 4px 6px rgba(0,0,0,.25)); }
.world .w-name { font-size: 1.4rem; font-weight: 800; }
.world .w-sub { opacity: .9; font-size: .95rem; }
.world .w-bar { height: 8px; background: rgba(255,255,255,.3); border-radius: 8px; margin-top: 6px; overflow: hidden; }
.world .w-bar span { display: block; height: 100%; background: #fff; border-radius: 8px; }
.world .w-stars { font-weight: 800; font-size: 1.1rem; text-align: right; }

/* ============ map ============ */
.map-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; }
.map-head h2 { font-size: 1.5rem; }
.mascot-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.mascot { font-size: 3rem; line-height: 1; }
.mascot.small { font-size: 2rem; }
.bubble { position: relative; background: var(--card); border-radius: 18px; padding: 10px 14px; box-shadow: var(--shadow); font-weight: 600; }
.bubble::before { content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%); border: 8px solid transparent; border-right-color: var(--card); border-left: 0; }
.btn.sprint { width: 100%; margin-bottom: 18px; background: linear-gradient(90deg, #ff922b, #f76707); color: #fff; box-shadow: 0 5px 0 #c2410c; display: flex; justify-content: space-between; }

.path { position: relative; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 10px 0 30px; }
.node-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.node {
  width: 78px; height: 78px; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; position: relative;
  background: var(--card); border: 4px solid var(--line); box-shadow: 0 6px 0 var(--line); transition: transform .12s;
}
.node:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--line); }
.node.open { background: linear-gradient(180deg, var(--accent2), var(--accent)); border-color: #fff; box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 60%, #000); animation: pulse 1.6s infinite; }
.node.done { border-color: var(--gold); }
.node.locked { filter: grayscale(1); opacity: .55; }
.node.boss { width: 104px; height: 104px; font-size: 3rem; }
.node .d-badge { position: absolute; bottom: -6px; right: -6px; font-size: .7rem; font-weight: 800; background: var(--ink); color: var(--card); border-radius: 999px; padding: 0 7px; }
.node-stars { font-size: 1rem; letter-spacing: 1px; color: var(--gold); min-height: 1.3em; text-shadow: 0 1px 0 rgba(0,0,0,.2); }
.node-label { font-size: .8rem; font-weight: 700; color: var(--muted); }
.dots { width: 6px; height: 18px; border-left: 6px dotted color-mix(in srgb, var(--accent) 45%, transparent); }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* ============ play ============ */
.play-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; }
.qprogress { flex: 1; display: flex; gap: 4px; }
.qprogress span { flex: 1; height: 12px; border-radius: 6px; background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid var(--line); transition: background .3s; }
.qprogress span.ok { background: var(--ok); }
.qprogress span.bad { background: var(--bad); }
.qprogress span.now { background: var(--gold); }
.hearts { font-size: 1.3rem; white-space: nowrap; }
.hearts .lost { filter: grayscale(1); opacity: .35; }
.timer { font-weight: 800; font-size: 1.4rem; min-width: 3.2ch; text-align: right; color: #e8590c; }
.timer.urgent { color: var(--bad); animation: pulse .5s infinite; }

.boss-zone { text-align: center; margin-bottom: 8px; }
.boss { font-size: 4.5rem; line-height: 1.1; display: inline-block; animation: bob 2s ease-in-out infinite; }
.boss.hit { animation: hit .45s; }
.boss.attack { animation: attack .5s; }
.bosshp { height: 14px; max-width: 260px; margin: 4px auto 0; background: color-mix(in srgb, var(--card) 70%, transparent); border-radius: 8px; overflow: hidden; border: 2px solid var(--card); }
.bosshp span { display: block; height: 100%; background: linear-gradient(90deg, #fa5252, #ff922b); transition: width .4s; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.qcard { position: relative; }
.qtag { font-size: .85rem; font-weight: 700; color: var(--muted); }
.question { font-size: clamp(1.35rem, 4.6vw, 1.9rem); font-weight: 700; margin: 6px 0 14px; overflow-wrap: anywhere; min-height: 2.4em; }
.question sup { font-size: .6em; }
.combo { position: absolute; top: 14px; right: 16px; font-weight: 800; color: #e8590c; font-size: 1.1rem; }

.answer-box {
  min-height: 60px; border-radius: 16px; border: 3px solid var(--line); background: color-mix(in srgb, var(--bg2) 50%, var(--card));
  font-size: 2rem; font-weight: 800; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; letter-spacing: 1px;
}
.answer-box.ok { border-color: var(--ok); color: var(--ok); }
.answer-box.bad { border-color: var(--bad); color: var(--bad); }
.caret { width: 3px; height: 1.1em; background: var(--accent); margin-left: 3px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.key { padding: 12px 0; font-size: 1.45rem; font-weight: 800; border-radius: 14px; background: color-mix(in srgb, var(--bg2) 55%, var(--card)); box-shadow: 0 4px 0 var(--line); }
.key:active, .key.press { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.key.op { color: var(--accent); }
.key.go { grid-row: span 2; background: linear-gradient(180deg, var(--accent2), var(--accent)); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { padding: 18px 8px; font-size: 1.35rem; font-weight: 800; border-radius: 16px; background: color-mix(in srgb, var(--bg2) 55%, var(--card)); box-shadow: 0 5px 0 var(--line); transition: transform .08s; }
.choice:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.choice.right { background: var(--ok); color: #fff; box-shadow: 0 5px 0 #1b5e20; }
.choice.wrong { background: var(--bad); color: #fff; box-shadow: 0 5px 0 #8b0000; }

.play-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.hint-box { margin-top: 10px; padding: 10px 14px; border-radius: 14px; background: #fff3bf; color: #5c3c00; font-weight: 600; animation: enter .25s; }

.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(720px, 100%); z-index: 20;
  background: var(--card); border-radius: 24px 24px 0 0; padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.25); border-top: 6px solid var(--bad); animation: sheet .3s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes sheet { from { transform: translate(-50%, 100%); } }
.sheet-title { font-size: 1.4rem; font-weight: 800; color: var(--bad); }
.sheet-answer { font-size: 1.15rem; margin: 4px 0; }
.sheet-answer b { font-size: 1.4rem; color: var(--ok); }
.sheet-explain { background: color-mix(in srgb, var(--bg2) 55%, var(--card)); border-radius: 12px; padding: 10px 12px; margin: 8px 0 14px; font-weight: 600; overflow-wrap: anywhere; }

/* ============ result ============ */
.result { text-align: center; margin-top: 20px; padding: 28px 20px; }
.result-emoji { font-size: 5rem; }
.result h1 { font-size: 2rem; margin-top: 4px; }
.stars { font-size: 3.2rem; margin: 10px 0; letter-spacing: 4px; }
.stars span { display: inline-block; filter: grayscale(1); opacity: .3; }
.stars span.on { filter: none; opacity: 1; animation: star .5s cubic-bezier(.2, 1.6, .4, 1) both; }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ============ fx ============ */
.fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.float-text { position: fixed; z-index: 51; transform: translateX(-50%); font-weight: 800; font-size: 1.6rem; color: var(--ok); pointer-events: none; text-shadow: 0 2px 0 #fff; animation: floatUp 1.1s ease-out forwards; }
.float-text.bad { color: var(--bad); }
.float-text.gold { color: #e8590c; font-size: 2rem; }
.toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 40; background: var(--ink); color: var(--card); padding: 10px 18px; border-radius: 999px; font-weight: 800; animation: enter .3s; }
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, 0) scale(.8); } 20% { transform: translate(-50%, -10px) scale(1.15); } to { opacity: 0; transform: translate(-50%, -70px) scale(1); } }
@keyframes star { from { transform: scale(0) rotate(-90deg); } to { transform: none; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes hit { 0% { transform: none; } 20% { transform: translateX(-10px) rotate(-12deg) scale(.9); filter: brightness(2); } 50% { transform: translateX(10px) rotate(10deg); } 100% { transform: none; } }
@keyframes attack { 0% { transform: none; } 40% { transform: scale(1.35) translateY(14px); } 100% { transform: none; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes popIn { from { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.1); } to { transform: none; opacity: 1; } }
@keyframes flash { from { box-shadow: inset 0 0 0 200vmax rgba(224, 49, 49, .25); } to { box-shadow: inset 0 0 0 200vmax rgba(224, 49, 49, 0); } }
.bob { animation: bob 2.4s ease-in-out infinite; }
.pop { animation: popIn .5s cubic-bezier(.2, 1.4, .4, 1); }
.shake { animation: shake .4s; }
.correct-pop { animation: qIn .25s ease-out; }
@keyframes qIn { from { transform: translateY(8px); opacity: .5; } to { transform: none; opacity: 1; } }
body.flash::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 30; animation: flash .5s forwards; }

footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============ account ============ */
.pill.account { cursor: pointer; max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; }
.pill.account.signed { border-color: var(--accent); }
.dialog {
  border: 0; border-radius: var(--radius); padding: 22px 20px 18px; width: min(400px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: var(--shadow); font-family: var(--font); position: relative;
}
.dialog::backdrop { background: rgba(15, 20, 45, .45); backdrop-filter: blur(3px); }
.dialog[open] { animation: qIn .25s ease-out; }
.dialog-x { position: absolute; top: 10px; right: 12px; font-size: 1.1rem; color: var(--muted); padding: 4px 8px; }
.dialog-emoji { font-size: 2.4rem; text-align: center; }
.dialog h2 { text-align: center; margin: 4px 0; }
.tabs { display: flex; background: var(--line); border-radius: 14px; padding: 4px; margin: 8px 0 14px; }
.tabs button { flex: 1; padding: 8px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 2px 0 var(--line); }
#acctForm label { display: block; font-weight: 700; margin-bottom: 10px; font-size: .95rem; }
#acctForm input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 1.05rem;
  border: 2px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
}
#acctForm input:focus { outline: none; border-color: var(--accent); }
.acct-error { color: var(--bad); min-height: 1.2em; margin: 2px 0 8px; font-weight: 700; font-size: .92rem; }
.small-note { font-size: .88rem; margin: 10px 0 0; line-height: 1.35; }
#acctSigned { text-align: center; }
#acctSigned .btn { margin-top: 14px; }
@media (max-width: 420px) {
  .topbar { padding: 10px 10px; }
  .pills { gap: 4px; }
  .pill { padding: 2px 7px; }
  .pill.account { max-width: 6.5em; }
}
@media (max-width: 350px) { .xp-pill .xpbar { display: none; } .pill.account { max-width: 5em; } }
.pills { min-width: 0; } .pill.account { min-width: 2.4em; flex-shrink: 1; display: inline-block; }
