:root {
  --bg: #faf8f5; --surface: #fff; --text: #1f1d1a; --muted: #77716a; --line: #e6e1da;
  --accent: #b5452f; --accent-text: #fff; --ok: #2f7d4f; --bad: #c0392b;
  --lv-ok: #77716a; --lv-hi: #b5452f; --lv-ind: #2a64a8; --sel: #fbe9d0;
  --zh: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614; --surface: #211f1c; --text: #ece7e0; --muted: #9a938a; --line: #34302b;
    --accent: #e0745c; --accent-text: #1a1210; --ok: #5cbf86; --bad: #ef6a5b;
    --lv-ok: #9a938a; --lv-hi: #f08a70; --lv-ind: #6aa5ec; --sel: #3d2e1c;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 system-ui, var(--zh); }
a { color: var(--accent); }
nav { display: flex; gap: 4px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
nav a { text-decoration: none; color: var(--text); padding: 4px 10px; border-radius: 6px; }
nav a:hover { background: var(--sel); }
nav .brand { font-weight: 700; color: var(--accent); margin-right: auto; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1, h2 { line-height: 1.3; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
kbd { font-size: 11px; opacity: .6; margin-left: 4px; }

.btn { display: inline-block; padding: 9px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.again { border-color: var(--bad); color: var(--bad); } .btn.good { border-color: var(--ok); color: var(--ok); }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.actions.center { justify-content: center; }

.hero { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 28px; } .stat span { color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.bar-cell { width: 40%; }
.bar { position: relative; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar i, .bar u { position: absolute; left: 0; top: 0; bottom: 0; }
.bar i { background: color-mix(in srgb, var(--accent) 40%, transparent); } .bar u { background: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px 20px; text-align: center; min-height: 220px; }
.hanzi { font-family: var(--zh); font-size: 64px; line-height: 1.2; cursor: pointer; }
.pinyin { color: var(--accent); font-size: 20px; margin-top: 8px; }
.gloss { font-size: 18px; margin: 8px 0; }
.examples { font-family: var(--zh); color: var(--muted); margin-top: 12px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs button { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 20px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 14px; }
.tabs button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.game .prompt { font-family: var(--zh); font-size: 48px; line-height: 1.3; }
.game .prompt.sentence { font-size: 22px; text-align: left; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.options button, .match button, .pieces button { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; cursor: pointer; }
.options.big button { font-family: var(--zh); font-size: 22px; }
.options button:hover:not(:disabled), .match button:hover, .pieces button:hover:not(:disabled) { border-color: var(--accent); }
.right { background: color-mix(in srgb, var(--ok) 20%, var(--bg)) !important; border-color: var(--ok) !important; }
.wrong { background: color-mix(in srgb, var(--bad) 20%, var(--bg)) !important; border-color: var(--bad) !important; }
.sel { background: var(--sel) !important; border-color: var(--accent) !important; }
.feedback { margin-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.match { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.match button { min-height: 64px; font-size: 14px; }
.match button.zh { font-family: var(--zh); font-size: 24px; }
.built { font-family: var(--zh); font-size: 26px; min-height: 52px; border-bottom: 2px solid var(--line); margin-bottom: 16px; padding: 6px; border-radius: 6px; }
.pieces { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pieces button { font-family: var(--zh); font-size: 22px; }
.pieces button:disabled { opacity: .25; }

.articles { padding-left: 18px; } .articles li { margin: 6px 0; }
.reader { font-family: var(--zh); font-size: 20px; line-height: 2; }
.reader h1 { font-size: 26px; }
.w { cursor: pointer; border-bottom: 2px solid transparent; }
.w.lv-hi { color: var(--lv-hi); border-color: color-mix(in srgb, var(--lv-hi) 40%, transparent); }
.w.lv-ind { color: var(--lv-ind); border-color: color-mix(in srgb, var(--lv-ind) 40%, transparent); }
.w.deck { border-bottom-style: dotted; }
.fade-ok .w.lv-ok { border-color: transparent; }
.w:hover { background: var(--sel); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.legend .w { cursor: default; }
.pop { position: absolute; width: 270px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; box-shadow: 0 6px 24px rgb(0 0 0 / .18); z-index: 10; font-size: 15px; }
.hanzi-sm { font-family: var(--zh); font-size: 30px; }
.pop .btn { margin-top: 8px; }

.lingo td.zh, .zh-sm { font-family: var(--zh); cursor: pointer; }
.lingo td.zh { font-size: 24px; white-space: nowrap; }
.grammar td:first-child { width: 38%; font-family: var(--zh); }
details { margin: 10px 0; } summary { cursor: pointer; font-weight: 600; }
.settings { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.settings label { display: flex; flex-direction: column; gap: 4px; }
.settings select, .settings input { padding: 8px; font: inherit; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }

.today { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px 12px; }
.today.complete { border: 2px solid var(--ok); }
.today h2 { margin: 10px 0 6px; font-size: 20px; }
.today-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; }
.today .bar { margin-top: 4px; }
.today .status { margin: 12px 0 0; }
.counter { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.counter b { color: var(--text); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--accent); color: var(--accent-text); margin-bottom: 6px; }
mark { background: var(--sel); color: var(--accent); font-weight: 700; padding: 0 2px; border-radius: 3px; }
.example-sentence { font-family: var(--zh); font-size: 18px; max-width: 560px; text-align: left; }
.countdown { padding: 12px 16px; margin-bottom: 12px; border-radius: 10px; background: var(--accent); color: var(--accent-text); }
.countdown b { font-size: 26px; }
.steps { list-style: none; padding: 0; display: grid; gap: 8px; }
.steps a { display: flex; flex-direction: column; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; }
.steps a span { color: var(--muted); font-size: 14px; }
.steps li.now a { border: 2px solid var(--accent); }
.steps li.now b::after { content: "  ← now"; color: var(--accent); font-weight: 400; font-size: 14px; }
.steps li.done a { opacity: .6; }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; margin-bottom: 12px; border: 2px solid var(--accent); border-radius: 10px; background: var(--sel); }

.spk { display: inline-flex; gap: 2px; vertical-align: middle; }
.spk button, .para-spk { background: none; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 15px; padding: 1px 6px; color: var(--text); }
.spk button:hover, .para-spk:hover { border-color: var(--accent); }
.para-spk { font-size: 13px; opacity: .6; }
.big-spk { font-size: 56px; background: none; border: 2px solid var(--line); border-radius: 50%; width: 110px; height: 110px; cursor: pointer; }
.big-spk:hover { border-color: var(--accent); }
.ex, [data-say].zh-sm { cursor: pointer; }
.ex:hover, [data-say].zh-sm:hover { color: var(--accent); }

@media (max-width: 520px) {
  .hanzi { font-size: 48px; } .game .prompt { font-size: 36px; }
  .options { grid-template-columns: 1fr; } .match { grid-template-columns: repeat(2, 1fr); }
  .bar-cell { display: none; }
}
