:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #f0ede8;
  --text: #1d1b22;
  --muted: #6b6876;
  --border: #e5e1db;
  --primary: #5b4fe0;
  --primary-2: #8f7fff;
  --primary-soft: #ecebff;
  --on-primary: #ffffff;
  --accent: #ff7a59;
  --accent-soft: #ffece5;
  --ok: #1a8f5a;
  --ok-soft: #e1f5ea;
  --bad: #d23f48;
  --bad-soft: #fde7e8;
  --gold: #f2a516;
  --shadow: 0 1px 2px rgba(20, 16, 40, .05), 0 6px 20px rgba(20, 16, 40, .06);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131218; --surface: #1d1b24; --surface-2: #282631; --text: #f2f0f7; --muted: #a29eaf;
    --border: #34313f; --primary: #8b80ff; --primary-2: #b3a9ff; --primary-soft: #2a2650; --on-primary: #14112e;
    --accent: #ff8f72; --accent-soft: #3a2219; --ok: #41d394; --ok-soft: #163126; --bad: #ff6f76; --bad-soft: #3b1c20;
    --gold: #ffc24a; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131218; --surface: #1d1b24; --surface-2: #282631; --text: #f2f0f7; --muted: #a29eaf;
  --border: #34313f; --primary: #8b80ff; --primary-2: #b3a9ff; --primary-soft: #2a2650; --on-primary: #14112e;
  --accent: #ff8f72; --accent-soft: #3a2219; --ok: #41d394; --ok-soft: #163126; --bad: #ff6f76; --bad-soft: #3b1c20;
  --gold: #ffc24a; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.wrap { max-width: 560px; margin: 0 auto; padding: 20px 16px 110px; min-height: 100vh; }
.wrap.full { padding-bottom: 180px; }
.stack > * + * { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px 20px; border: 0; border-radius: 16px;
  background: var(--primary); color: var(--on-primary);
  font-weight: 800; font-size: 16px; letter-spacing: .2px;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--primary) 65%, #000);
  transition: transform .08s, box-shadow .08s, opacity .2s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--primary) 65%, #000); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: var(--surface); color: var(--text); box-shadow: 0 0 0 2px var(--border) inset, 0 3px 0 var(--border); }
.btn.ghost:active { box-shadow: 0 0 0 2px var(--border) inset; }
.btn.ok { background: var(--ok); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--ok) 65%, #000); }
.btn.bad { background: var(--bad); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--bad) 65%, #000); }
.link { background: none; border: 0; color: var(--primary); font-weight: 700; padding: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card.hero {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--on-primary); border: 0; position: relative; overflow: hidden;
}
.card.hero::after { content: ''; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: rgba(255,255,255,.12); right: -70px; top: -90px; }
.card.hero .btn { background: var(--surface); color: var(--primary); box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--primary-soft); color: var(--primary); }
.hero .tag { background: rgba(255,255,255,.2); color: inherit; }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Top bar & nav ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand img { width: 32px; height: 32px; }
.stats { display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); font-weight: 800; font-size: 14px; }
.pill .fire { color: var(--accent); }
.pill .gem { color: var(--primary); }
.pill.off .fire { filter: grayscale(1); opacity: .5; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.nav-inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.nav button { background: none; border: 0; padding: 8px 4px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 700; color: var(--muted); }
.nav button span { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.nav button.on { color: var(--primary); background: var(--primary-soft); }
.nav button.on span { filter: none; opacity: 1; }

/* ---------- Welcome ---------- */
.welcome { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 32px 16px; max-width: 480px; margin: 0 auto; }
.welcome-art { font-size: 72px; text-align: center; margin-bottom: 8px; animation: float 4s ease-in-out infinite; }
.welcome h1 { font-size: 34px; line-height: 1.15; text-align: center; letter-spacing: -.5px; }
.welcome h1 em { font-style: normal; color: var(--primary); }
.features { display: grid; gap: 12px; margin: 28px 0; }
.feature { display: flex; gap: 14px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; }
.feature b { display: block; }
.feature .ic { font-size: 26px; line-height: 1; }
@keyframes float { 50% { transform: translateY(-8px); } }

/* ---------- Progress ---------- */
.bar { height: 14px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .45s cubic-bezier(.3,1.4,.6,1); }
.bar.thin { height: 8px; }
.bar.green > i { background: linear-gradient(90deg, var(--ok), color-mix(in srgb, var(--ok) 60%, #fff)); }

.session-top { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.session-top .bar { flex: 1; }

/* ---------- Exercise ---------- */
.ex-label { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; color: var(--primary); margin-bottom: 8px; }
.ex-q { font-size: 24px; font-weight: 800; line-height: 1.3; letter-spacing: -.2px; margin-bottom: 24px; }
.ex-sub { color: var(--muted); margin-top: -16px; margin-bottom: 24px; }
.passage { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 14px; padding: 16px; margin-bottom: 20px; font-size: 17px; }

.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; padding: 15px 18px; border-radius: 16px; font-size: 17px; font-weight: 600;
  background: var(--surface); border: 2px solid var(--border); box-shadow: 0 3px 0 var(--border);
  transition: border-color .15s, background .15s, transform .08s;
}
.opt:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.opt:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--border); }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 3px 0 var(--primary); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); box-shadow: 0 3px 0 var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); box-shadow: 0 3px 0 var(--bad); animation: shake .35s; }
.opt:disabled { cursor: default; }
.opt .k { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border); font-size: 13px; margin-right: 12px; color: var(--muted); }

.answer-line { min-height: 64px; border-bottom: 2px solid var(--border); padding: 8px 0; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; margin-bottom: 28px; }
.answer-line.two { min-height: 112px; background: repeating-linear-gradient(transparent 0 54px, var(--border) 54px 56px); border-bottom: 0; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 10px 16px; border-radius: 14px; font-size: 17px; font-weight: 600;
  background: var(--surface); border: 2px solid var(--border); box-shadow: 0 3px 0 var(--border);
}
.answer-line .chip:last-child { animation: pop .18s; }
.chip.used { visibility: hidden; }
.chip.ghosted { background: var(--surface-2); color: transparent; box-shadow: none; animation: none; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .opt { text-align: center; padding: 14px 10px; font-size: 16px; }
.match .opt.done { opacity: .35; border-color: var(--ok); background: var(--ok-soft); box-shadow: none; }

.fill-sentence { font-size: 22px; font-weight: 700; line-height: 2.2; margin-bottom: 8px; }
.fill-input { display: inline-block; width: 8ch; min-width: 6ch; border: 0; border-bottom: 3px solid var(--primary); background: var(--primary-soft); border-radius: 8px 8px 0 0; padding: 2px 8px; font-weight: 800; text-align: center; outline: none; }
.textarea { width: 100%; min-height: 120px; resize: none; border-radius: 16px; border: 2px solid var(--border); background: var(--surface); padding: 14px 16px; font-size: 17px; outline: none; }
.textarea:focus, .fill-input:focus { border-color: var(--primary); }

.audio-row { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 8px 0 28px; }
.play { width: 96px; height: 96px; border-radius: 28px; border: 0; background: var(--primary); color: var(--on-primary); font-size: 40px; box-shadow: 0 5px 0 color-mix(in srgb, var(--primary) 60%, #000); }
.play:active { transform: translateY(3px); box-shadow: 0 2px 0 color-mix(in srgb, var(--primary) 60%, #000); }
.play.slow { width: 64px; height: 64px; border-radius: 20px; font-size: 22px; background: var(--primary-soft); color: var(--primary); box-shadow: 0 4px 0 color-mix(in srgb, var(--primary) 30%, transparent); }
.mic { width: 110px; height: 110px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 44px; box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 60%, #000); display: block; margin: 8px auto 16px; }
.mic.listening { animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); } 100% { box-shadow: 0 0 0 26px transparent; } }
.speak-target { font-size: 22px; font-weight: 700; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.speak-target .w.hit { color: var(--ok); }
.speak-target .w.miss { color: var(--bad); text-decoration: underline dotted; }
.srs-word { text-align: center; font-size: 38px; font-weight: 800; margin: 8px 0 4px; letter-spacing: -.5px; }

/* ---------- Bottom action / feedback ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
}
.dock-inner { max-width: 560px; margin: 0 auto; display: grid; gap: 10px; }
.dock.fb-ok { background: var(--ok-soft); border-color: transparent; animation: up .25s ease-out; }
.dock.fb-bad { background: var(--bad-soft); border-color: transparent; animation: up .25s ease-out; }
.fb-title { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.fb-ok .fb-title { color: var(--ok); }
.fb-bad .fb-title { color: var(--bad); }
.fb-text { font-size: 15px; }
.fb-text b { font-weight: 800; }
.fb-tip { font-size: 14px; background: color-mix(in srgb, var(--surface) 70%, transparent); border-radius: 12px; padding: 10px 12px; }
.dock .row .btn.ghost { width: auto; }

@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- Home ---------- */
.greet h1 { font-size: 26px; letter-spacing: -.3px; }
.mission-emoji { font-size: 44px; line-height: 1; }
.steps { display: grid; gap: 8px; margin: 18px 0; position: relative; z-index: 1; }
.step { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.step i { font-style: normal; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.22); font-size: 13px; font-weight: 800; }
.hero > * { position: relative; z-index: 1; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 12px; text-align: center; }
.stat b { display: block; font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 110px; margin-top: 14px; }
.week .d { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week .col { width: 100%; max-width: 30px; border-radius: 8px; background: var(--surface-2); min-height: 6px; transition: height .5s; }
.week .col.on { background: linear-gradient(180deg, var(--primary-2), var(--primary)); }
.week .d small { font-size: 12px; font-weight: 700; color: var(--muted); }
.week .d.today small { color: var(--primary); }

.section-title { font-size: 18px; font-weight: 800; margin: 28px 0 12px; }
.list-btn { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; }
.list-btn:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.list-btn .ic { font-size: 26px; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); flex-shrink: 0; }
.list-btn .chev { color: var(--muted); font-size: 20px; }

/* ---------- Map ---------- */
.level-block { position: relative; padding-left: 28px; }
.level-block::before { content: ''; position: absolute; left: 11px; top: 30px; bottom: -16px; width: 3px; background: var(--border); border-radius: 3px; }
.level-block:last-child::before { display: none; }
.level-dot { position: absolute; left: 0; top: 4px; width: 25px; height: 25px; border-radius: 50%; background: var(--surface-2); border: 3px solid var(--border); }
.level-block.current .level-dot { background: var(--primary); border-color: var(--primary-soft); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
.level-block.past .level-dot { background: var(--ok); border-color: var(--ok-soft); }
.level-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.level-head h3 { font-size: 20px; font-weight: 800; }
.mission-item .ic { background: var(--primary-soft); }
.mission-item.done .ic { background: var(--ok-soft); }
.mission-item.locked { opacity: .55; }
.check { color: var(--ok); font-weight: 800; }

/* ---------- Results ---------- */
.level-badge { width: 120px; height: 120px; margin: 8px auto 16px; border-radius: 36px; display: grid; place-items: center; font-size: 46px; font-weight: 800; letter-spacing: -1px; color: var(--on-primary); background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 12px 30px color-mix(in srgb, var(--primary) 35%, transparent); animation: pop .5s cubic-bezier(.3,1.6,.5,1); transform: rotate(-4deg); }
.radar { display: block; margin: 0 auto; max-width: 320px; width: 100%; height: auto; overflow: visible; }
.radar text { font-size: 11px; font-weight: 700; fill: var(--muted); font-family: inherit; }
.radar .grid { fill: none; stroke: var(--border); }
.radar .area { fill: color-mix(in srgb, var(--primary) 25%, transparent); stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; }
.radar .pt { fill: var(--primary); }

.skill-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 12px; align-items: center; font-size: 14px; font-weight: 600; }

/* ---------- Summary ---------- */
.summary-emoji { font-size: 80px; text-align: center; animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
.summary h1 { text-align: center; font-size: 28px; letter-spacing: -.3px; }
.big-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.big-stats .stat { border-width: 2px; }
.big-stats .stat:nth-child(1) { border-color: var(--gold); }
.big-stats .stat:nth-child(1) b { color: var(--gold); }
.big-stats .stat:nth-child(2) { border-color: var(--ok); }
.big-stats .stat:nth-child(2) b { color: var(--ok); }
.big-stats .stat:nth-child(3) { border-color: var(--accent); }
.big-stats .stat:nth-child(3) b { color: var(--accent); }
.word-list { display: flex; flex-wrap: wrap; gap: 8px; }
.word-list .tag { font-size: 14px; }

.mistake { padding: 16px; }
.mistake .q { font-weight: 700; }
.mistake .a { color: var(--ok); font-weight: 700; }
.mistake .e { font-size: 14px; color: var(--muted); margin-top: 4px; }
.empty { text-align: center; padding: 40px 20px; }
.empty .ic { font-size: 56px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 380px) {
  .ex-q { font-size: 21px; }
  .welcome h1 { font-size: 28px; }
}
