:root {
  --bg: #f6f7f9; --card: #ffffff; --ink: #14202e; --muted: #5b6b7c;
  --accent: #1b2a41; --accent-ink: #ffffff; --line: #e2e6eb;
  --ok: #2e7d4f; --warn: #b7791f; --bad: #b3261e; --soft: #eef1f5;
  --hanja: #8a2d1f; --leech-bg: #fff4e5; --leech-fg: #8a4b00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1722; --card: #182334; --ink: #e9eef5; --muted: #9fb0c3;
    --accent: #6fa8ff; --accent-ink: #0b1220; --line: #26344a;
    --ok: #6fcf97; --warn: #f2c14e; --bad: #ff7b72; --soft: #1f2c40;
    --hanja: #ffb08a; --leech-bg: #3a2a12; --leech-fg: #f5c98a;
  }
}
:root[data-theme="dark"] {
  --leech-bg: #3a2a12; --leech-fg: #f5c98a;
  --bg: #0f1722; --card: #182334; --ink: #e9eef5; --muted: #9fb0c3;
  --accent: #6fa8ff; --accent-ink: #0b1220; --line: #26344a;
  --ok: #6fcf97; --warn: #f2c14e; --bad: #ff7b72; --soft: #1f2c40;
  --hanja: #ffb08a;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "PingFang TC", "Noto Sans CJK TC", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.top h1 { font-size: 18px; margin: 0; letter-spacing: .02em; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; }
.view { flex: 1; padding: 16px 16px calc(env(safe-area-inset-bottom) + 84px); max-width: 640px; width: 100%; margin: 0 auto; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; 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; color: var(--muted); padding: 8px 0 6px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; }
.tabs button .ic { font-size: 20px; line-height: 1; }
.tabs button.active { color: var(--accent); font-weight: 600; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 0 8px; }
h2:first-child { margin-top: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card + .card { margin-top: 12px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.flash { min-height: 260px; display: flex; flex-direction: column; justify-content: center; text-align: center; cursor: pointer; user-select: none; }
.flash .front { font-size: 40px; font-weight: 700; letter-spacing: .01em; }
.flash .front.grammar { font-size: 28px; }
.flash .pos { color: var(--muted); font-size: 13px; margin-top: 4px; }
/* Pictograms are drawn for a white page, so they sit on a white tile in dark mode too. */
.flash .pic { width: 132px; height: 132px; margin: 12px auto 6px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 14px; }
.flash .pic .picimg { width: 118px; height: 118px; }
.flash .pic .picemoji { font-size: 80px; line-height: 1; }
.item .bpic { width: 28px; height: 28px; vertical-align: middle; margin-right: 6px; background: #fff; border-radius: 6px; }
.item .bemoji { margin-right: 6px; }
.leech { background: var(--leech-bg); color: var(--leech-fg); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; }
.flash .hint { color: var(--muted); font-size: 13px; margin-top: 24px; }
.pron { font-size: 15px; color: var(--muted); margin-top: 4px; }
.pron .said { color: var(--ink); }
.rr { font-family: ui-monospace, Menlo, monospace; font-size: .9em; letter-spacing: .02em; }
button.say { border: 0; background: var(--soft); color: var(--ink); border-radius: 999px; width: 34px; height: 34px; font-size: 16px; vertical-align: middle; margin-left: 4px; }
.flash .front button.say { width: 40px; height: 40px; font-size: 18px; }
.hanja { font-size: 34px; color: var(--hanja); font-weight: 600; margin-top: 10px; letter-spacing: .08em; }
.hanja.none { font-size: 14px; color: var(--muted); font-weight: 400; letter-spacing: 0; }
.zh { font-size: 20px; margin-top: 6px; }
.en { color: var(--muted); margin-top: 2px; }
.ex { text-align: left; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 15px; }
.ex .k { font-weight: 600; }
.ex .t { color: var(--muted); font-size: 14px; }
.ex + .ex { margin-top: 8px; border-top: 0; padding-top: 0; }
.note { font-size: 14px; color: var(--muted); margin-top: 10px; text-align: left; }
.check { display: inline-block; background: var(--warn); color: #000; border-radius: 6px; font-size: 11px; padding: 0 6px; margin-left: 6px; vertical-align: middle; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
button.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 12px 8px; font-size: 15px; font-weight: 600; min-height: 48px; }
button.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.btn.again { color: var(--bad); } button.btn.hard { color: var(--warn); } button.btn.good { color: var(--ok); } button.btn.easy { color: var(--accent); }
button.btn small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
button.btn.primary small { color: inherit; opacity: .8; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.item .row b { font-size: 17px; }
.item .meta { font-size: 13px; color: var(--muted); }
.item .hj { color: var(--hanja); font-weight: 600; margin-left: 6px; }
.item.open .more { display: block; }
.more { display: none; margin-top: 8px; font-size: 14px; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 11px; background: var(--soft); color: var(--muted); }
.pill.int { background: #e3ecff; color: #1e4bb8; } .pill.adv { background: #ffe6e0; color: #a1301a; } .pill.beg { background: #e5f6ea; color: #1f6b3b; }
:root[data-theme="dark"] .pill.int { background:#213556; color:#9dbcff } :root[data-theme="dark"] .pill.adv { background:#4a271f; color:#ffb3a3 } :root[data-theme="dark"] .pill.beg { background:#1e3a2a; color:#9ee0b4 }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.int { background:#213556; color:#9dbcff } :root:not([data-theme="light"]) .pill.adv { background:#4a271f; color:#ffb3a3 } :root:not([data-theme="light"]) .pill.beg { background:#1e3a2a; color:#9ee0b4 } }
.unit { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.unit .bar { flex: 1; height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.unit .bar i { display: block; height: 100%; background: var(--ok); }
.unit.locked { opacity: .55; }
.unit.current { border-color: var(--accent); }
input:not([type=checkbox]):not([type=file]), select, textarea { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.chips { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.form label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
.form label.inline { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.form input[type=checkbox] { width: 18px; height: 18px; }
dialog { border: 0; border-radius: 16px; padding: 16px; width: min(92vw, 520px); background: var(--card); color: var(--ink); max-height: 90dvh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.5); }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.empty b { display: block; font-size: 20px; color: var(--ink); margin-bottom: 6px; }
.tip { font-size: 13px; color: var(--muted); }
.tip ol { padding-left: 18px; margin: 6px 0 0; }
.progress-line { height: 6px; background: var(--soft); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress-line i { display: block; height: 100%; background: var(--accent); }

/* ---- Cantonese app ---- */
:root { --t1: #c62828; --t2: #e65100; --t3: #2e7d32; --t4: #1565c0; --t5: #6a1b9a; --t6: #6d4c41; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --t1: #ff8a80; --t2: #ffb74d; --t3: #81c784; --t4: #64b5f6; --t5: #ce93d8; --t6: #bcaaa4; } }
:root[data-theme="dark"] { --t1: #ff8a80; --t2: #ffb74d; --t3: #81c784; --t4: #64b5f6; --t5: #ce93d8; --t6: #bcaaa4; }
.syl { display: inline-block; margin: 0 .1em; white-space: nowrap; }
.syl sup { font-size: .5em; margin-left: 1px; font-weight: 700; }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); } .t6 { color: var(--t6); }
.front.hgline { font-size: 38px; line-height: 1.35; }
.hg { font-weight: 600; }
.ex .k.hg { font-size: 20px; line-height: 1.5; }
.jp { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--muted); margin-top: 4px; }
.ex .t.jp { margin: 2px 0; }
.bridge { margin-top: 10px; font-size: 15px; }
.bpair { display: inline-flex; align-items: baseline; gap: 4px; margin: 4px 8px 0 0; padding: 2px 8px; background: var(--soft); border-radius: 8px; }
.bch { color: var(--hanja); font-size: 20px; } .bko { font-weight: 600; } .bko.none { color: var(--muted); } .bhg { color: var(--muted); }
.badge-cant { display: inline-block; background: var(--soft); color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.pill.a0 { background: #e0f2f1; color: #00695c; } .pill.a1 { background: #fff3e0; color: #b45309; } .pill.a2 { background: #ede7f6; color: #5e35b1; }
:root[data-theme="dark"] .pill.a0 { background:#173a37; color:#80cbc4 } :root[data-theme="dark"] .pill.a1 { background:#3d2f14; color:#ffcc80 } :root[data-theme="dark"] .pill.a2 { background:#2a2144; color:#b39ddb }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.a0 { background:#173a37; color:#80cbc4 } :root:not([data-theme="light"]) .pill.a1 { background:#3d2f14; color:#ffcc80 } :root:not([data-theme="light"]) .pill.a2 { background:#2a2144; color:#b39ddb } }
.exrow { margin-top: 6px; }
.chars { font-size: 18px; color: var(--hanja); margin-top: 4px; }
.front.ko-front { font-size: 30px; font-weight: 700; }
.tonekey .tk { display: grid; grid-template-columns: 56px 44px 1fr auto; align-items: center; gap: 6px; padding: 4px 0; }
.tonekey .tk .hg { font-size: 22px; }
.tonekey .contour { font-size: 22px; font-weight: 700; text-align: center; }
.tonekey .tkl { font-size: 14px; }
.speech-log { white-space: pre-wrap; word-break: break-word; font: 12px/1.45 ui-monospace, Menlo, monospace; color: var(--muted); margin: 10px 0 0; min-height: 1em; }

/* Quiz */
.qunit { cursor: pointer; }
.qunit .qunit-name { flex: 1; }
.unit.passed { border-color: var(--ok); }
.qprompt { text-align: center; }
.qprompt .qword { font-size: 30px; font-weight: 700; margin: 8px 0 4px; }
.qprompt .qsentence { font-size: 19px; line-height: 1.5; margin: 8px 0; }
.qprompt .qreplay { width: 56px; height: 56px; font-size: 26px; margin: 8px auto 4px; display: block; }
.qopts { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 12px 0; }
.qopts.qtones { grid-template-columns: repeat(3, 1fr); }
.qopt { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 18px; font-weight: 600; text-align: center; cursor: pointer; }
.qopt:has(button.say) { flex-direction: row; gap: 10px; }
.qopt small { font-size: 12px; font-weight: 400; color: var(--muted); }
.qopt .qko { font-size: 20px; }
.qtones .qopt span { font-size: 24px; }
.qopt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--card)); }
.qopt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.qopt.dim { opacity: .55; }
.qresult { text-align: center; }
.qresult .qscore { font-size: 32px; font-weight: 700; }
.qverdict { margin-top: 6px; font-weight: 600; }
.qverdict.pass { color: var(--ok); } .qverdict.notyet { color: var(--warn); }
.qmiss { padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.qhome { margin-top: 12px; }

/* Mongolian: Latin reading aid and the letter key */
.mnlat { color: var(--muted); font-size: 14px; letter-spacing: .02em; }
.flash .mnlat { margin-top: 2px; }
.letters { display: grid; gap: 6px; }
.letters .lt { display: grid; grid-template-columns: 44px 36px 1fr auto; align-items: center; gap: 8px; }
.letters .lt b { font-size: 20px; }

/* English: IPA line */
.ipa { color: var(--muted); font-size: 15px; font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", system-ui, sans-serif; }
.flash .ipa { margin-top: 2px; }
/* ♪ Songs tab (Korean app) */
.songs .btn + h2 { margin-top: 14px; }
.song-row input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.song-lines { gap: 6px; }
.song-line .k { font-size: 17px; font-weight: 600; }
.song-line .rr { color: var(--muted); font-size: 13px; }
.song-line .zh, .song-line .en { font-size: 14px; margin-top: 2px; }
.song-line.plain { padding: 4px 12px; }
.song-gap { height: 8px; }
.song-point { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.song-point .btn { display: block; margin-top: 6px; }
.song-chip { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.in-reviews { display: block; margin-top: 6px; color: var(--accent); font-weight: 600; }
.song-msg { margin-bottom: 10px; }
