/* Baloo 2 draws the pinyin macron vowels (ā ē ī ō ū) with a detached bar. These code points only — never the
   Vietnamese letters ă đ ĩ ũ ơ ư — come from a system font instead. */
@font-face { font-family: 'Pinyin Marks'; src: local('Arial'), local('Helvetica Neue'), local('Helvetica'), local('Roboto'), local('Segoe UI'), local('Noto Sans');
  unicode-range: U+0100-0101, U+0112-0113, U+011A-011B, U+012A-012B, U+014C-014D, U+016A-016B, U+01CD-01DC; }
/* ============ tokens & themes ============ */
:root {
  --font: 'Pinyin Marks', '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: 26px; --shadow: 0 8px 0 var(--edge-l), 0 16px 30px rgba(27, 31, 59, .14);
  --bg1: #b2f2bb; --bg2: #e6fcf5; --accent: #2f9e44; --accent2: #66a80f; --accent-ink: #fff;
}
body[data-theme="jungle"] { --bg1: #b2f2bb; --bg2: #e9fac8; --accent: #2f9e44; --accent2: #66a80f; --edge: #1e6b2e; --edge-l: #a9ddb3; }
body[data-theme="ocean"]  { --bg1: #a5d8ff; --bg2: #e3fafc; --accent: #1971c2; --accent2: #0c8599; --edge: #0e4a85; --edge-l: #a9cdee; }
body[data-theme="space"]  { --bg1: #d0bfff; --bg2: #f3f0ff; --accent: #6741d9; --accent2: #c2255c; --edge: #3f2789; --edge-l: #cbbdf3; }
:root { --edge: #1e6b2e; --edge-l: #a9ddb3; --clay: 0 14px 24px rgba(27, 31, 59, .16); }

@media (prefers-color-scheme: dark) {
  :root { --ink: #eef1ff; --muted: #a8b0cf; --card: #1d2240; --line: #2f3663; --shadow: 0 8px 0 rgba(0,0,0,.4), 0 14px 30px rgba(0,0,0,.35); --edge-l: #2f3663; }
  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 ============ */
:focus-visible { outline: 3px solid #ffc531; outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.btn {
  background: var(--card); color: var(--ink); border-radius: 18px; padding: 12px 20px; min-height: 48px; font-weight: 800; font-size: 1.05rem;
  box-shadow: 0 5px 0 var(--edge-l), var(--clay); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--edge-l), 0 4px 8px rgba(27, 31, 59, .12); }
.btn.primary { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent)); color: var(--accent-ink); box-shadow: 0 6px 0 var(--edge), var(--clay); }
.btn.primary:active { box-shadow: 0 2px 0 var(--edge), 0 4px 8px rgba(27, 31, 59, .12); }
.btn.ghost { background: transparent; box-shadow: none; border: 2px solid var(--line); }
.btn.ghost:active { transform: translateY(2px); box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: .95rem; min-height: 44px; }
.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; min-height: 36px; font-weight: 700; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.pill.icon { padding: 2px 8px; }
.pill.icon.music-btn { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; border-radius: 14px; position: relative; box-shadow: 0 3px 0 var(--edge-l); }
.pill.icon.music-btn:active { transform: translateY(3px); box-shadow: none; }
.pill.icon.music-btn.on { color: var(--accent); border-color: var(--accent); }
.music-btn { position: relative; } .music-btn svg { display: block; } .music-btn .mute-slash { position: absolute; inset: 0; margin: auto; color: var(--muted); }
.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: screenIn .42s cubic-bezier(.2, .9, .3, 1.1) both; }
@keyframes screenIn { from { opacity: 0; transform: translateX(26px) scale(.985); } to { opacity: 1; transform: none; } }
@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 {
  --we: #1e6b2e;
  position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 16px; border-radius: 26px; text-align: left; color: #fff;
  box-shadow: 0 8px 0 var(--we), 0 18px 28px rgba(27, 31, 59, .22);
  transform: perspective(800px) rotateX(5deg) rotateY(var(--tilt, 0deg)); transition: transform .15s, box-shadow .15s;
}
.world:nth-child(odd) { --tilt: -1.5deg; } .world:nth-child(even) { --tilt: 1.5deg; }
.world::after { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0) 45%); }
@media (hover: hover) { .world:hover { transform: perspective(800px) rotateX(2deg) rotateY(calc(var(--tilt, 0deg) * -1)) translateY(-4px); } }
.world:active { transform: perspective(800px) rotateX(5deg) translateY(6px); box-shadow: 0 2px 0 var(--we), 0 6px 10px rgba(27, 31, 59, .2); }
.world[data-theme="jungle"] { --we: #1e6b2e; background: linear-gradient(135deg, #3fbf58, #2f9e44 55%, #66a80f); }
.world[data-theme="ocean"]  { --we: #0e4a85; background: linear-gradient(135deg, #3b9ae8, #1971c2 55%, #0c8599); }
.world[data-theme="space"]  { --we: #3f2789; background: linear-gradient(135deg, #8564e8, #6741d9 55%, #c2255c); }
.world[data-theme="gold"]   { --we: #9a3412; background: linear-gradient(135deg, #f08c00, #e8590c); }   /* portal card only (Checkpoint) */
.world[data-theme="red"]    { --we: #862e2e; background: linear-gradient(135deg, #f03e3e, #c92a2a 55%, #e8590c); }   /* portal card only (YCT) */
.world[data-theme="jade"]   { --we: #0b5345; background: linear-gradient(135deg, #12b886, #0b7a5e 55%, #c99a06); }   /* portal card only (Lucky in China) */
.world[data-theme="globe"]  { --we: #8a4b00; background: linear-gradient(135deg, #fab005, #e67700 55%, #1971c2); }   /* portal card only (Lucky in the World) */
.world .w-emoji { font-size: 2.6rem; width: 68px; height: 68px; display: grid; place-items: center; border-radius: 22px; background: rgba(255,255,255,.22); box-shadow: inset 0 -5px 0 rgba(0,0,0,.15); filter: drop-shadow(0 3px 4px rgba(0,0,0,.2)); }
.world .w-name { font-size: 1.4rem; font-weight: 800; }
.world .w-sub { opacity: .9; font-size: .95rem; }
.world .w-bar { height: 9px; 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: 20px 20px 20px 6px; 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; min-height: 58px; border-radius: 18px; background: linear-gradient(180deg, #ff9f43, #f76707); color: #fff; box-shadow: 0 6px 0 #9a3412, var(--clay); display: flex; justify-content: space-between; }
.btn.sprint:active { box-shadow: 0 2px 0 #9a3412, 0 4px 8px rgba(27, 31, 59, .12); }

.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: 76px; height: 70px; border-radius: 26px; display: grid; place-items: center; font-size: 2rem; position: relative;
  background: linear-gradient(180deg, var(--card), color-mix(in srgb, var(--accent) 8%, var(--card))); border: 4px solid var(--card); color: var(--ink);
  box-shadow: 0 8px 0 var(--edge-l), 0 14px 22px rgba(27, 31, 59, .18); transition: transform .1s, box-shadow .1s;
}
.node:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--edge-l), 0 4px 8px rgba(27, 31, 59, .15); }
.node.open { background: linear-gradient(180deg, #ffd95e, #ffc531); border-color: #fff; box-shadow: 0 8px 0 #e8a400, 0 0 0 0 rgba(255, 197, 49, .6), 0 14px 22px rgba(27, 31, 59, .18); animation: glow 1.6s ease-in-out infinite; }
.node.open:active { animation: none; transform: translateY(6px); box-shadow: 0 2px 0 #e8a400; }
.node.done { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 75%, #fff), var(--accent)); color: #fff; box-shadow: 0 8px 0 var(--edge), 0 14px 22px rgba(27, 31, 59, .18); }
.node.locked { background: #d5d8e3; border-color: #eceef5; color: #7b8099; box-shadow: 0 8px 0 #aeb3c6; filter: grayscale(1); opacity: .75; }
@keyframes glow { 0%, 100% { transform: scale(1); box-shadow: 0 8px 0 #e8a400, 0 0 0 0 rgba(255, 197, 49, .55), 0 14px 22px rgba(27, 31, 59, .18); } 50% { transform: scale(1.06); box-shadow: 0 8px 0 #e8a400, 0 0 0 14px rgba(255, 197, 49, 0), 0 14px 22px rgba(27, 31, 59, .18); } }
.node.boss { width: 108px; height: 96px; border-radius: 34px; font-size: 3rem; }
.node .d-badge { position: absolute; bottom: -8px; right: -6px; box-shadow: 0 2px 0 rgba(0,0,0,.25); 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: #e8a400; min-height: 1.3em; text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.node-label { font-size: .8rem; font-weight: 800; color: var(--ink); background: rgba(255,255,255,.85); border-radius: 10px; padding: 0 8px; }
.dots { width: 6px; height: 18px; border-left: 6px dotted color-mix(in srgb, var(--accent) 55%, transparent); border-radius: 3px; }
@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; box-shadow: 0 2px 0 rgba(27,31,59,.08); 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); }
.qprogress span.done { background: var(--muted); }
.btn.exam { width: 100%; margin: -8px 0 18px; min-height: 58px; background: linear-gradient(180deg, #5c7cfa, #364fc7); color: #fff; box-shadow: 0 6px 0 #253a9c, var(--clay); display: flex; justify-content: space-between; gap: 8px; }
.btn.exam:active { box-shadow: 0 2px 0 #253a9c, 0 4px 8px rgba(27, 31, 59, .12); }
.choice.picked { outline: 3px solid var(--gold); }
.exam-review { text-align: left; margin-top: 16px; }
.exam-review h3 { margin: 14px 0 6px; }
.exam-table { width: 100%; border-collapse: collapse; }
.exam-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.exam-table td.num { white-space: nowrap; text-align: right; }
.exam-table .bar { display: block; height: 8px; border-radius: 4px; background: var(--line); min-width: 60px; }
.exam-table .bar span { display: block; height: 100%; border-radius: 4px; background: var(--ok); }
.exam-item { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin: 8px 0; }
.exam-item summary { cursor: pointer; font-weight: 700; }
.exam-item .ok { color: var(--ok); } .exam-item .bad { color: var(--bad); }
.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: 28px; box-shadow: var(--shadow); padding: 20px; }
.qcard { position: relative; border-radius: 28px; box-shadow: 0 9px 0 var(--edge-l), 0 20px 34px rgba(27, 31, 59, .14); transform: perspective(900px) rotateX(3deg); transform-origin: 50% 100%; }
.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: 62px; border-radius: 18px; border: 3px solid var(--edge-l); box-shadow: inset 0 3px 0 rgba(27,31,59,.06); 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; min-height: 52px; font-size: 1.45rem; font-weight: 800; border-radius: 16px; background: linear-gradient(180deg, var(--card), color-mix(in srgb, var(--bg2) 55%, var(--card))); box-shadow: 0 5px 0 var(--edge-l), 0 8px 12px rgba(27, 31, 59, .08); transition: transform .06s, box-shadow .06s; }
.key:active, .key.press { transform: translateY(4px); box-shadow: 0 1px 0 var(--edge-l); }
.key.op { color: var(--accent); }
.key.go { grid-row: span 2; background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent)); color: #fff; box-shadow: 0 5px 0 var(--edge), 0 8px 12px rgba(27, 31, 59, .12); }
.key.go:active { box-shadow: 0 1px 0 var(--edge); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { min-height: 72px; padding: 16px 8px; font-size: 1.35rem; font-weight: 800; border-radius: 22px; border: 3px solid var(--line); background: var(--card); color: var(--ink); box-shadow: 0 7px 0 var(--edge-l), 0 12px 16px rgba(27, 31, 59, .08); transition: transform .08s, box-shadow .08s; }
@media (hover: hover) { .choice:hover:not(.right):not(.wrong) { transform: translateY(-2px); } }
.choice:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--edge-l); }
.choice.right { background: linear-gradient(180deg, #51cf66, #2f9e44); border-color: #1e6b2e; color: #fff; box-shadow: 0 7px 0 #1e6b2e; animation: popIn .35s cubic-bezier(.2, 1.4, .4, 1); }
.choice.wrong { background: linear-gradient(180deg, #ff6b6b, #e03131); border-color: #8b1a1a; color: #fff; box-shadow: 0 7px 0 #8b1a1a; animation: shake .4s; }

.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: 30px 30px 0 0; padding: 22px 20px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 0 rgba(224, 49, 49, .35), 0 -14px 40px rgba(27, 31, 59, .28); border-top: 6px solid var(--bad); animation: sheet .3s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes sheet { from { transform: translate(-50%, 100%); } }
.sheet::before { content: ''; position: absolute; top: 8px; left: 50%; width: 44px; height: 5px; margin-left: -22px; border-radius: 3px; background: var(--line); }
.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: 16px; box-shadow: 0 3px 0 var(--edge-l); padding: 10px 12px; margin: 8px 0 14px; font-weight: 600; overflow-wrap: anywhere; }

/* ============ result ============ */
.result { text-align: center; margin-top: 20px; padding: 28px 20px; border-radius: 32px; box-shadow: 0 10px 0 var(--edge-l), 0 26px 44px rgba(27, 31, 59, .18); }
.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: drop-shadow(0 4px 0 #e8a400); opacity: 1; animation: star .6s cubic-bezier(.2, 1.6, .4, 1) both; }
.stars span.on:nth-child(2) { animation-delay: .18s; } .stars span.on:nth-child(3) { animation-delay: .36s; }
.result .btn { min-height: 52px; }
.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); } 70% { transform: scale(1.3) rotate(8deg); } 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; }
  .world, .world:hover, .qcard { transform: 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; }
  /* the music button made the bar overflow on phones: same size as the other icon pills, drop the tiny XP bar */
  .pill.icon.music-btn { width: 36px; height: 36px; min-height: 36px; flex: 0 0 36px; border-radius: 12px; }
  .xp-pill .xpbar { display: none; }
}
@media (max-width: 380px) { .pills { gap: 3px; } .pill.icon { padding: 2px 5px; } .pill.account { max-width: 4.6em; } }
@media (max-width: 340px) { .pill.icon.music-btn { display: none; } }
@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; }

/* ============ rewards ============ */
.gallery-btn { width: 100%; margin: 10px 0 4px; }
.reward-btn { display: block; margin: 6px auto 12px; background: linear-gradient(180deg, #ffd43b, #fab005); color: #5c3d00; box-shadow: 0 6px 0 #c98a00, var(--clay); animation: pulse 1.6s ease-in-out infinite; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.tile { background: var(--card); border-radius: 20px; padding: 6px 6px 8px; box-shadow: 0 5px 0 var(--edge-l); text-align: center; font-weight: 700; font-size: .85rem; line-height: 1.2; }
.tile canvas, .tile .lock { width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; display: block; margin-bottom: 6px; }
.tile .lock { display: grid; place-items: center; background: var(--line); font-size: 1.8rem; color: var(--muted); }
.tile.locked { opacity: .65; cursor: default; }
.tile.cert { grid-column: 1 / -1; }
.tile.cert canvas, .tile.cert .lock { aspect-ratio: 2000 / 1414; height: auto; }
.map-head .btn { white-space: nowrap; flex-shrink: 0; }
.tile small { display: block; color: var(--muted); font-weight: 500; }
.reward-dialog { width: min(760px, calc(100vw - 24px)); padding: 18px 16px 16px; }
.reward-dialog h2 { font-size: 1.3rem; margin: 0 28px 10px; }
.reward-frame canvas { width: 100%; height: auto; display: block; border-radius: 12px; box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.reward-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
@media (prefers-reduced-motion: reduce) { .reward-btn { animation: none; } }

/* ============ theory: mindmap tree ============ */
:root {
  --v-a: #1c7ed6; --v-b: #e8590c; --v-c: #2f9e44; --v-d: #d6336c; --v-r: #e03131; --v-soft: #edf2ff;
  --br-number: #339af0; --br-algebra: #fd7e14; --br-geometry: #40c057; --br-stats: #f06595;
}
@media (prefers-color-scheme: dark) {
  :root { --v-a: #74c0fc; --v-b: #ffa94d; --v-c: #69db7c; --v-d: #f783ac; --v-r: #ff8787; --v-soft: #262d55; }
}
.map-extras { display: flex; gap: 8px; margin: 10px 0 4px; }
.map-extras .btn { flex: 1; margin: 0; width: auto; padding: 12px 8px; }
.br-0 { --branch: var(--br-number); } .br-1 { --branch: var(--br-algebra); } .br-2 { --branch: var(--br-geometry); } .br-3 { --branch: var(--br-stats); } .br-4 { --branch: #7950f2; }
.br-number { --branch: var(--br-number); } .br-algebra { --branch: var(--br-algebra); }
.br-geometry { --branch: var(--br-geometry); } .br-stats { --branch: var(--br-stats); }

.mm-root {
  display: inline-flex; flex-direction: column; align-items: flex-start; margin: 10px 0 0; padding: 10px 18px; border-radius: 18px;
  background: linear-gradient(180deg, var(--accent2), var(--accent)); color: #fff; font-weight: 800; font-size: 1.2rem; box-shadow: var(--shadow);
}
.mm-root small { font-weight: 600; opacity: .85; font-size: .8rem; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree { padding-left: 22px; }
.tree ul { padding-left: 26px; }
.tree li { position: relative; padding: 8px 0 0 22px; }
/* elbow from the parent's line into this node */
.tree li::before {
  content: ''; position: absolute; left: 0; top: 0; width: 18px; height: 30px;
  border-left: 3px solid var(--branch, var(--accent)); border-bottom: 3px solid var(--branch, var(--accent)); border-bottom-left-radius: 14px;
}
/* line continuing down to the next sibling */
.tree li:not(:last-child)::after { content: ''; position: absolute; left: 0; top: 27px; bottom: 0; border-left: 3px solid var(--branch, var(--accent)); }
.tree > li > ul > li { --branch: inherit; }
.mm-strand {
  display: inline-flex; gap: 8px; align-items: center; padding: 8px 14px; border-radius: 999px; font-weight: 800; color: #fff;
  background: var(--branch); box-shadow: 0 4px 0 color-mix(in srgb, var(--branch) 60%, #000);
}
.mm-strand span { background: rgba(255,255,255,.3); border-radius: 999px; padding: 0 8px; font-size: .85rem; }
li.collapsed > ul { display: none; }
li.collapsed > .mm-strand { opacity: .8; }
.mm-leaf {
  display: flex; gap: 10px; align-items: center; text-align: left; width: 100%; padding: 8px 12px; border-radius: 16px;
  background: var(--card); border: 2px solid color-mix(in srgb, var(--branch) 45%, var(--line)); box-shadow: 0 3px 0 var(--line);
  transition: transform .1s;
}
.mm-leaf:hover { transform: translateX(3px); }
.mm-leaf b { display: block; line-height: 1.2; }
.mm-leaf small { display: block; color: var(--muted); font-size: .82rem; line-height: 1.25; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mm-emoji { font-size: 1.6rem; flex-shrink: 0; width: 1.6em; text-align: center; }
.tree.compact .mm-leaf { padding: 6px 10px; }
.tree.compact .mm-emoji { font-size: 1.2rem; }

/* ============ theory: lesson card ============ */
.theory-dialog { width: min(640px, calc(100vw - 16px)); max-height: calc(100vh - 24px); padding: 0; display: none; }
.theory-dialog[open] { display: flex; flex-direction: column; }
.th-body { overflow-y: auto; padding: 18px 16px 8px; }
.th-body h2 { font-size: 1.35rem; margin: 2px 30px 8px 0; text-align: left; }
.th-body h3 { font-size: 1.02rem; margin: 16px 0 6px; }
.th-crumb { display: inline-block; font-size: .8rem; font-weight: 800; color: #fff; background: var(--branch); border-radius: 999px; padding: 2px 10px; }
.th-idea { font-size: 1.1rem; font-weight: 700; background: color-mix(in srgb, var(--gold) 18%, var(--card)); border-radius: 14px; padding: 10px 12px; margin: 6px 0 10px; }
.th-visual { background: var(--v-soft); border-radius: 16px; padding: 6px; }
.th-visual svg { width: 100%; height: auto; display: block; }
.th-analogy { margin-top: 10px; padding: 10px 12px; border-left: 4px solid var(--accent); border-radius: 0 12px 12px 0; background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.th-points { margin: 0; padding-left: 1.2em; } .th-points li { margin: 4px 0; }
.th-example { border: 2px dashed var(--line); border-radius: 14px; padding: 10px 12px; }
.th-q { font-weight: 700; margin: 0 0 6px; }
.th-steps { margin: 0 0 6px; padding-left: 1.3em; } .th-steps li { margin: 3px 0; }
.th-answer { margin: 4px 0; font-size: 1.05rem; }
.reveal { animation: qIn .3s ease-out; }
.th-terms { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.th-terms span { background: var(--line); border-radius: 999px; padding: 3px 10px; font-size: .9rem; }
/* Chinese lesson cards (Lucky in China): tap a Chinese run to hear it; pinyin after it, can be hidden */
.zh-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin: -4px 0 8px; }
.zh-run { cursor: pointer; border-bottom: 2px dotted var(--acc, #c92a2a); border-radius: 2px; font-size: 1.08em; }
.zh-short { white-space: nowrap; }
.zh-run:hover, .zh-run:focus-visible, .zh-run.saying { background: rgba(255, 197, 49, .35); outline: none; }
.zh-py { color: var(--muted); font-size: .88em; font-style: italic; }
.py-off .zh-py { display: none; }
.th-nav { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); }
.sheet-actions { display: flex; gap: 8px; } .sheet-actions .btn { flex: 1; }

/* SVG palette for theory visuals (see js/theory/SCHEMA.md) */
/* Lines and paths never get the browser's default black fill; a colour class can still fill them. */
.th-visual path, .th-visual polyline, .th-visual line { fill: none; }
.th-visual rect, .th-visual circle, .th-visual ellipse, .th-visual polygon, .th-visual path, .th-visual polyline, .th-visual line { stroke-linejoin: round; }
.th-visual .t { font: 600 14px var(--font); fill: var(--ink); }
.th-visual .t-sm { font: 600 11px var(--font); fill: var(--muted); }
.th-visual .t-b { font-weight: 800; }
.th-visual .f-ink { fill: var(--ink); } .th-visual .f-muted { fill: var(--muted); } .th-visual .f-acc { fill: var(--accent); }
.th-visual .f-a { fill: var(--v-a); } .th-visual .f-b { fill: var(--v-b); } .th-visual .f-c { fill: var(--v-c); } .th-visual .f-d { fill: var(--v-d); } .th-visual .f-r { fill: var(--v-r); } .th-visual .s-r { stroke: var(--v-r); }
.th-visual .f-soft { fill: color-mix(in srgb, var(--accent) 14%, var(--card)); } .th-visual .f-paper { fill: var(--card); }
.th-visual .s-ink { stroke: var(--ink); } .th-visual .s-muted { stroke: var(--muted); } .th-visual .s-acc { stroke: var(--accent); }
.th-visual .s-a { stroke: var(--v-a); } .th-visual .s-b { stroke: var(--v-b); } .th-visual .s-c { stroke: var(--v-c); } .th-visual .s-d { stroke: var(--v-d); }

/* ============ answer types: text input, read-aloud, question diagram ============ */
.text-area { display: flex; gap: 8px; margin-top: 10px; }
.text-area input {
  flex: 1; min-width: 0; font: inherit; font-size: 1.3rem; font-weight: 700; padding: 10px 14px;
  border: 3px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink);
}
.text-area input:focus { outline: none; border-color: var(--accent); }
.text-area input.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--card)); }
.text-area input.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--card)); }
.say-btn { display: block; margin: 4px auto 0; font-size: 1.3rem; }
.q-visual { margin: 8px 0; border-radius: 14px; background: var(--v-soft, #edf2ff); padding: 4px; }
.q-visual svg { width: 100%; height: auto; display: block; max-height: 220px; }
a.pill, a.btn { color: inherit; text-decoration: none; }

/* ============ reading passage, long questions, credit ============ */
.q-passage { text-align: left; font-size: 1rem; font-weight: 500; line-height: 1.5; background: color-mix(in srgb, var(--accent) 8%, var(--card));
  border-left: 4px solid var(--accent); border-radius: 12px; padding: 10px 14px; margin: 4px 0 10px; max-height: 42vh; overflow-y: auto; }
.q-passage p { margin: 0 0 .6em; } .q-passage p:last-child { margin-bottom: 0; }
.question.long { font-size: clamp(1.1rem, 3.8vw, 1.4rem); line-height: 1.35; }
.credit { display: block; margin-top: 4px; font-weight: 700; letter-spacing: .04em; opacity: .85; }

@media (prefers-color-scheme: dark) {
  .node.locked { background: #343a5c; border-color: #454d78; color: #8e96bd; box-shadow: 0 8px 0 #232846; }
  .node-label { background: rgba(29, 34, 64, .85); }
  .choice { border-color: var(--line); }
}
.node-label { margin-top: 6px; }

/* Chinese games: pinyin line under the question (tap to hide/show) */
.q-py { margin: -8px 0 12px; font-size: 1.05rem; color: var(--muted); letter-spacing: .02em; cursor: pointer; user-select: none; }
.q-py.off { font-size: .8rem; opacity: .7; }
:lang(zh) .question, .zh .question, .zh .choice, .zh .q-passage { font-family: var(--font), "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
/* YCT speaking practice */
.speak-card { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.speak-zh { font-size: clamp(2rem, 9vw, 3.2rem); font-weight: 800; line-height: 1.2; font-family: var(--font), "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
.speak-card .q-py { margin: 0; cursor: default; }
.speak-zh.speak-en { font-size: clamp(1.3rem, 5vw, 1.8rem); line-height: 1.3; }
.speak-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.speak-out { min-height: 3em; } .speak-out p { margin: .3em 0; }
.speak-note { font-size: .8rem; text-align: center; margin-top: 12px; }
