[hidden] { display: none !important; }
:root {
  --bg: #f5f5fa; --card: #ffffff; --text: #171826; --muted: #626679; --line: #e3e4ee; --track: #ececf4;
  --accent: #6d5dfc; --accent-soft: #ebe8ff; --good: #16a34a; --warn: #d97706; --bad: #dc2626;
  --hl: #fff3c4; --new: #6d5dfc;
  /* grammar colours */
  --m: #2563eb; --f: #db2777; --n: #16a34a; --prt: #d97706;
  --nom: #64748b; --gen: #9333ea; --dat: #0891b2; --acc: #dc2626; --ins: #16a34a; --pre: #d97706;
  --t1: #e11d48; --t2: #ea8a00; --t3: #16a34a; --t4: #2563eb; --t5: #8a8fa3;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e0f17; --card: #171826; --text: #e8e9f1; --muted: #9a9db0; --line: #272a3b; --track: #24263a;
  --accent: #8b7dff; --accent-soft: #25224a; --good: #22c55e; --warn: #f59e0b; --bad: #f87171;
  --hl: #3a3420; --new: #a99fff;
  --m: #60a5fa; --f: #f472b6; --n: #4ade80; --prt: #fbbf24;
  --nom: #94a3b8; --gen: #c084fc; --dat: #22d3ee; --acc: #f87171; --ins: #4ade80; --pre: #fbbf24;
  --t1: #fb7185; --t2: #fbbf24; --t3: #4ade80; --t4: #60a5fa; --t5: #9a9db0;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans KR", "Malgun Gothic", "PingFang SC", "Microsoft YaHei", sans-serif; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; }
@media (max-width: 520px) { .brand span { display: none; } }
.langs { display: flex; gap: 4px; flex: 1; justify-content: center; }
.langs button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.langs button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.langs button .dim { opacity: .55; font-size: 11px; margin-left: 3px; }
.streak { font-size: 14px; white-space: nowrap; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; border: 0; background: none; padding: 6px 0 7px; cursor: pointer; color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tabs button span { font-size: 19px; line-height: 1.1; filter: grayscale(.6); }
.tabs button.on { color: var(--accent); font-weight: 700; }
.tabs button.on span { filter: none; }

main { max-width: 860px; margin: 0 auto; padding: 14px 14px 30px; }
h1 { font-size: 20px; margin: 4px 0 12px; } h2 { font-size: 16px; margin: 0 0 8px; } h3 { font-size: 15px; margin: 14px 0 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.plain { background: var(--card); color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: default; }
.chip { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; background: var(--track); color: var(--muted); }
.chip.main { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.bar { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.big { font-size: 26px; font-weight: 700; }
input[type=text], input[type=number], textarea, select { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.scroll { overflow-x: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 6px 12px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--accent); color: #fff; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.list-item .title { font-weight: 600; }
.pct { min-width: 46px; text-align: center; border-radius: 8px; padding: 3px 4px; font-weight: 700; font-size: 13px; }
.pct.ok { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pct.mid { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pct.hard { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }

/* reader */
.reader-tools { position: sticky; top: 49px; z-index: 5; background: var(--bg); padding: 6px 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.reader-tools .btn { padding: 5px 10px; font-size: 14px; }
.story { font-size: var(--fs, 21px); line-height: 2.05; }
.story.zh, .story.ko { line-height: 2.4; }
.sen { padding: 4px 6px; margin: 0 -6px 6px; border-radius: 8px; transition: background .2s; }
.sen.playing { background: var(--hl); }
.sen .num { font-size: 11px; color: var(--muted); cursor: pointer; user-select: none; margin-right: 4px; vertical-align: super; }
.sen .tr { display: block; font-size: 15px; line-height: 1.45; color: var(--muted); margin-top: 2px; }
.w { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.w.s-new { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--new) 60%, transparent); }
.w.s-learning { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.w.sel { outline: 2px solid var(--accent); }
.colors .w.c-prt { color: var(--prt); }
.colors .w.c-m { color: var(--m); } .colors .w.c-f { color: var(--f); } .colors .w.c-n { color: var(--n); }
.colors .w.c-gen { color: var(--gen); } .colors .w.c-dat { color: var(--dat); } .colors .w.c-acc { color: var(--acc); } .colors .w.c-ins { color: var(--ins); } .colors .w.c-pre { color: var(--pre); }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); }
ruby rt { font-size: 0.5em; color: var(--muted); font-weight: 400; }
.legend { font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); }
.legend b { font-weight: 600; }

/* lookup sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 30px rgba(0,0,0,.25); padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); max-height: 70vh; overflow-y: auto; }
.sheet .lemma { font-size: 28px; font-weight: 700; }
.sheet .pron { color: var(--muted); font-size: 16px; }
.sheet .gloss { font-size: 18px; margin: 4px 0; }
.sheet .meta { font-size: 14px; margin: 3px 0; }
.sheet .close { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.sheet .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.note-ff { background: color-mix(in srgb, var(--bad) 13%, transparent); border-radius: 8px; padding: 5px 8px; font-size: 14px; }

.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal > .card { width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto; }
#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50; }
#toast.on { opacity: .95; }

/* review + quiz */
.flash { text-align: center; padding: 22px 10px; }
.flash .front { font-size: 24px; line-height: 1.8; }
.flash .front b { color: var(--accent); }
.flash .back { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 14px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
.rate button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 4px; cursor: pointer; font-weight: 600; }
.rate button small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.rate .r1 { color: var(--bad); } .rate .r2 { color: var(--warn); } .rate .r3 { color: var(--good); } .rate .r4 { color: var(--accent); }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 12px; }
.opts button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 6px; cursor: pointer; font-size: 18px; }
.opts button.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 18%, transparent); }
.opts button.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, transparent); }
.q-prompt { font-size: 22px; line-height: 1.8; text-align: center; }
.q-prompt .blank { display: inline-block; min-width: 2.2em; border-bottom: 2px solid var(--accent); }
.q-prompt b { color: var(--accent); }
.huge { font-size: 64px; line-height: 1.2; }
.diff .ok { color: var(--good); } .diff .miss { color: var(--bad); text-decoration: underline; }
.play { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 15px; flex: none; }
.play.big { width: 64px; height: 64px; font-size: 26px; }
.tile-table td { font-size: 18px; }
.tile-table td.k { font-size: 26px; }
.answer { white-space: pre-wrap; line-height: 1.55; }
.rec { background: var(--bad) !important; border-color: var(--bad) !important; color: #fff !important; }
