:root {
  --bg: #f4f5fb; --surface: #ffffff; --text: #1f2333; --muted: #6b7085; --line: #e3e5ef;
  --primary: #4f46e5; --primary-2: #4338ca; --on-primary: #fff;
  --ok: #16a34a; --ok-bg: #dcfce7; --bad: #dc2626; --bad-bg: #fee2e2;
  --flame: #f97316; --gold: #eab308; --mark: #fde68a; --shadow: 0 2px 0 rgba(20, 20, 60, .08);
  --radius: 18px; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1220; --surface: #1a1e30; --text: #eef0f8; --muted: #9aa0b8; --line: #2c3150;
    --primary: #818cf8; --primary-2: #6366f1; --on-primary: #0f1220; --ok-bg: #12351f; --bad-bg: #3f1518;
    --mark: #7c5b0a; --shadow: 0 2px 0 rgba(0, 0, 0, .35); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 18px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; min-height: 100dvh; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); overscroll-behavior: none; }
h1 { font-size: 1.5rem; margin: .4em 0 .5em; } h2 { font-size: 1.1rem; color: var(--muted); margin: 1.2em 0 .4em; }
small { color: var(--muted); }
.hidden { display: none !important; }
.screen { max-width: 560px; margin: 0 auto; padding: 12px 16px 110px; animation: fade .25s ease-out; }
.screen.center { display: flex; flex-direction: column; justify-content: center; min-height: 85vh; text-align: center; }
.boot { text-align: center; padding-top: 40vh; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; box-shadow: var(--shadow); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hint { color: var(--flame); font-weight: 600; margin: .5em 0 0; }
.error { color: var(--bad); }
/* buttons */
.btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; padding: 10px 18px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 0 var(--line); transition: transform .06s, box-shadow .06s; touch-action: manipulation; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn small { font-weight: 500; font-size: .8rem; }
.btn.primary { background: var(--primary); border-color: var(--primary-2); color: var(--on-primary); box-shadow: 0 4px 0 var(--primary-2); }
.btn.secondary { border-color: var(--primary); color: var(--primary); }
.btn.danger { background: var(--bad); border-color: #991b1b; color: #fff; box-shadow: 0 4px 0 #991b1b; }
.btn.xl { width: 100%; min-height: 60px; font-size: 1.15rem; margin: 8px 0; }
.btn[disabled] { opacity: .75; }
.btn.right, .tok.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.btn.wrong, .tok.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.tok.missed { border-color: var(--bad); border-style: dashed; color: var(--bad); }
.icon-btn { min-width: 48px; min-height: 48px; border: 0; background: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; }
/* home */
.topbar { display: flex; justify-content: space-between; gap: 6px; margin: 6px 0; }
.stat { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 1.05rem; min-height: 44px; }
.stat.flame span { filter: grayscale(1); opacity: .6; } .stat.flame.lit span { filter: none; opacity: 1; animation: flicker 1.6s infinite; }
.hello { margin-top: .6em; }
.goal-row { display: flex; gap: 12px; align-items: center; } .goal-icon { font-size: 2rem; }
.goal.done { border-color: var(--ok); }
.countdown { border-color: var(--flame); }
.bar { height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.bar.gold i { background: var(--gold); } .bar.good i { background: var(--ok); } .bar.weak i { background: var(--flame); }
/* tabbar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); z-index: 5; }
.tab { flex: 1; min-height: 56px; border: 0; background: none; color: var(--muted); font: inherit; display: flex;
  flex-direction: column; align-items: center; justify-content: center; cursor: pointer; border-radius: 12px; }
.tab span { font-size: 1.35rem; } .tab small { font-size: .7rem; } .tab.active { color: var(--primary); background: var(--bg); }
.tab.active small { color: var(--primary); font-weight: 700; }
/* exercise */
.exercise { padding-bottom: 24px; }
.session-top { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--bg); padding: 6px 0; z-index: 2; }
.session-top .bar { flex: 1; margin: 0; height: 16px; } .bar.progress i { background: var(--ok); }
.xp-pill { font-weight: 700; color: var(--gold); min-width: 54px; text-align: right; }
.retry-tag { color: var(--flame); font-weight: 700; margin: 6px 0; }
.instr { color: var(--muted); font-weight: 600; margin: 14px 0 8px; }
.sentence { font-size: 1.35rem; line-height: 1.6; background: var(--surface); border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); }
.sentence.math { font-size: 1.6rem; text-align: center; }
mark { background: var(--mark); color: inherit; padding: 0 4px; border-radius: 6px; font-weight: 700; }
.gap { display: inline-block; min-width: 3.2em; border-bottom: 3px solid var(--primary); text-align: center; font-weight: 700; color: var(--primary); }
.gap.filled { color: var(--ok); border-color: var(--ok); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.grid2 .btn { min-height: 72px; font-size: 1.1rem; }
.stack { display: grid; gap: 12px; margin-top: 14px; } .stack .btn { min-height: 60px; font-size: 1.2rem; }
.tokens { display: flex; flex-wrap: wrap; align-items: center; row-gap: 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 8px; margin: 10px 0; }
.tok { min-height: 48px; padding: 6px 10px; font: inherit; font-size: 1.2rem; border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg); color: var(--text); cursor: pointer; }
.tok.on { border-color: var(--primary); color: var(--primary); font-weight: 700; }
.tok.picked { outline: 3px solid var(--primary); }
.gapbtn { min-width: 26px; min-height: 48px; padding: 0 3px; border: 0; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; opacity: .55; }
.gapbtn.picked { opacity: 1; color: var(--primary); outline: 3px solid var(--primary); border-radius: 8px; }
.tts-row { display: flex; gap: 14px; justify-content: center; margin: 14px 0; }
.big-icon { min-width: 88px; min-height: 88px; font-size: 2.2rem; border-radius: 50%; }
.text-input, .code-input { width: 100%; min-height: 58px; font-size: 1.4rem; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--text); margin: 8px 0; }
.text-input:focus, .code-input:focus { outline: none; border-color: var(--primary); }
.code-input { text-align: center; letter-spacing: .2em; text-transform: uppercase; }
.num-display { min-height: 64px; font-size: 2rem; font-weight: 700; text-align: center; background: var(--surface);
  border: 2px solid var(--primary); border-radius: 14px; margin: 12px 0; padding: 8px; display: flex; justify-content: center; gap: 8px; flex-direction: row-reverse; }
.num-display .unit { color: var(--muted); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.numpad .key { min-height: 64px; font-size: 1.6rem; }
/* feedback */
.feedback { position: sticky; bottom: 0; margin: 16px -16px 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0; animation: slide .22s ease-out; }
.feedback.ok { background: var(--ok-bg); } .feedback.bad { background: var(--bad-bg); }
.fb-head { font-size: 1.25rem; font-weight: 800; } .feedback.ok .fb-head { color: var(--ok); } .feedback.bad .fb-head { color: var(--bad); }
.xp-gain { color: var(--gold); margin-left: 6px; animation: pop .5s ease-out; display: inline-block; }
.expl { margin: 8px 0; }
.solution { font-size: 1.25rem; font-weight: 700; margin: 4px 0; }
.diff { font-size: 1.25rem; margin: 4px 0; } .diff-label { margin: 6px 0 0; font-size: .9rem; color: var(--muted); }
.d-ins { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 2px; background: rgba(220, 38, 38, .15); }
.d-del { color: var(--ok); text-decoration: underline; text-decoration-thickness: 3px; font-weight: 800; background: rgba(22, 163, 74, .15); }
/* summary, badges, celebrate */
.big-emoji { font-size: 4.2rem; animation: pop .5s ease-out; }
.sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.sum-grid div { background: var(--surface); border-radius: 16px; padding: 12px 4px; border: 1px solid var(--line); }
.sum-grid b { display: block; font-size: 1.5rem; }
.badges { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.badge { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; text-align: center; opacity: .55; }
.badge.earned { opacity: 1; border-color: var(--gold); } .badge .emoji { font-size: 2.2rem; } .badge b, .badge small { display: block; }
.reward.reached { border-color: var(--gold); } .reward.delivered { opacity: .7; }
.overlay { position: fixed; inset: 0; background: rgba(15, 18, 32, .75); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.celebrate { background: var(--surface); border-radius: 26px; padding: 26px 20px; max-width: 420px; width: 100%; text-align: center; position: relative; overflow: hidden; animation: pop .35s ease-out; }
.confetti i { position: absolute; top: -10px; width: 9px; height: 14px; border-radius: 3px; animation: fall 2.2s linear infinite; }
.confetti i:nth-child(4n) { background: var(--primary); } .confetti i:nth-child(4n+1) { background: var(--gold); }
.confetti i:nth-child(4n+2) { background: var(--ok); } .confetti i:nth-child(4n+3) { background: var(--flame); }
.confetti i:nth-child(1) { left: 4%; animation-delay: 0s } .confetti i:nth-child(2) { left: 12%; animation-delay: .4s } .confetti i:nth-child(3) { left: 20%; animation-delay: .9s }
.confetti i:nth-child(4) { left: 28%; animation-delay: .2s } .confetti i:nth-child(5) { left: 36%; animation-delay: 1.1s } .confetti i:nth-child(6) { left: 44%; animation-delay: .6s }
.confetti i:nth-child(7) { left: 52%; animation-delay: 1.4s } .confetti i:nth-child(8) { left: 60%; animation-delay: .3s } .confetti i:nth-child(9) { left: 68%; animation-delay: .8s }
.confetti i:nth-child(10) { left: 76%; animation-delay: 1.2s } .confetti i:nth-child(11) { left: 84%; animation-delay: .5s } .confetti i:nth-child(12) { left: 92%; animation-delay: 1s }
.confetti i:nth-child(n+13) { animation-duration: 2.8s; } .confetti i:nth-child(13) { left: 8% } .confetti i:nth-child(14) { left: 16% } .confetti i:nth-child(15) { left: 24% }
.confetti i:nth-child(16) { left: 32% } .confetti i:nth-child(17) { left: 40% } .confetti i:nth-child(18) { left: 48% } .confetti i:nth-child(19) { left: 56% }
.confetti i:nth-child(20) { left: 64% } .confetti i:nth-child(21) { left: 72% } .confetti i:nth-child(22) { left: 80% } .confetti i:nth-child(23) { left: 88% } .confetti i:nth-child(24) { left: 96% }
.offline { position: fixed; top: env(safe-area-inset-top); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  font-size: .85rem; padding: 6px 14px; border-radius: 0 0 12px 12px; z-index: 30; }
.login .code-input { margin-top: 4px; }
ol { padding-left: 1.3em; } li { margin: 4px 0; }
textarea.write { width: 100%; min-height: 220px; font: inherit; padding: 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); color: var(--text); }
.checklist { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; } .checklist span { font-size: .9rem; }
.charcard { display: flex; justify-content: center; } .charcard svg { width: 220px; height: 220px; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes slide { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes flicker { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12) rotate(-4deg); } }
@keyframes fall { to { transform: translateY(520px) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
