:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1f1e;
  --muted: #5d6663;
  --line: #e1ded5;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #d9efec;
  --accent: #c2410c;
  --good: #15803d;
  --good-soft: #dcf2e3;
  --bad: #b91c1c;
  --bad-soft: #fbe0e0;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  --radius: 16px;
  --han: "PingFang SC", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101413; --surface: #181e1c; --surface-2: #212927; --text: #eceeed; --muted: #a0aaa7;
    --line: #2b3431; --brand: #2dd4bf; --brand-ink: #062a26; --brand-soft: #123532; --accent: #fb923c;
    --good: #4ade80; --good-soft: #14301e; --bad: #f87171; --bad-soft: #3a1a1a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 110px;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
a { color: var(--brand); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }
.han { font-family: var(--han); }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  background: var(--brand); color: var(--brand-ink); font: 600 22px var(--han);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 18px; }
.brand-text span { font-size: 13px; color: var(--muted); }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.account .who { color: var(--muted); font-size: 14px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- layout ---- */
main { max-width: 960px; margin: 0 auto; padding: 24px 16px; outline: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.lessons { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600;
  text-decoration: none; color: var(--text); min-height: 44px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- home ---- */
.hero { display: grid; gap: 16px; grid-template-columns: 1.4fr 1fr; align-items: stretch; margin-bottom: 24px; }
.hero h1 { font-size: clamp(26px, 5vw, 38px); }
.hero .han-big { font: 600 clamp(40px, 9vw, 64px) var(--han); color: var(--brand); }
.goal { display: flex; align-items: center; gap: 16px; }
.goal-ring { width: 84px; height: 84px; flex: none; position: relative; }
.goal-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.goal-ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 4; }
.ring-fg { fill: none; stroke: var(--brand); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset .4s; }
.banner { background: var(--brand-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px; }

.lesson-card { display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: inherit; transition: transform .15s; }
.lesson-card:hover { transform: translateY(-2px); }
.lesson-card .icon { font-size: 30px; }
.lesson-card h3 { margin: 0; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.done { background: var(--good-soft); color: var(--good); }

/* ---- lesson ---- */
.tabs { display: flex; gap: 6px; margin: 16px 0; }
.tab { padding: 8px 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; color: var(--text); }
.tab.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.flash {
  width: 100%; min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 28px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
}
.flash .hanzi { font: 600 clamp(48px, 14vw, 92px)/1.1 var(--han); }
.flash .pinyin { font-size: 26px; color: var(--brand); font-weight: 600; }
.flash .english { font-size: 22px; }
.flash .hint { color: var(--muted); font-size: 14px; }
.flash.known { border-color: var(--good); }
.deck-nav { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
table.words { width: 100%; border-collapse: collapse; margin-top: 18px; }
table.words th, table.words td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.words th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
table.words td.hz { font: 600 22px var(--han); }
.tick { color: var(--good); font-weight: 700; }

/* ---- quiz ---- */
.quiz-q { text-align: center; padding: 20px 8px 8px; }
.quiz-q .prompt { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .05em; }
.quiz-q .big { font: 600 clamp(40px, 12vw, 72px)/1.15 var(--han); margin: 10px 0; }
.quiz-q .big.text { font-family: inherit; font-size: clamp(26px, 6vw, 40px); }
.options { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-top: 16px; }
@media (max-width: 520px) { .options { grid-template-columns: 1fr; } }
.opt { text-align: left; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-size: 18px; min-height: 56px; }
.opt.han { font-size: 26px; }
.opt:hover:not([disabled]) { border-color: var(--brand); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.feedback { margin-top: 14px; padding: 12px 16px; border-radius: 12px; }
.feedback.ok { background: var(--good-soft); }
.feedback.no { background: var(--bad-soft); }
.score-big { font-size: 56px; font-weight: 800; color: var(--brand); }

/* ---- progress ---- */
.stat { text-align: center; }
.stat .n { font-size: 32px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 14px; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; min-width: 0; }
.chart .b { width: 100%; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 3px; opacity: .85; }
.chart .b.goal-hit { opacity: 1; }
.chart .d { font-size: 11px; color: var(--muted); }
.goal-line { font-size: 13px; color: var(--muted); }

/* ---- auth form ---- */
.auth { max-width: 420px; margin: 20px auto; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; min-height: 46px; }
.error { color: var(--bad); background: var(--bad-soft); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }

/* ---- timer dock ---- */
.dock {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 14px; padding: 10px 14px 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow), 0 10px 40px rgba(0,0,0,.18);
  max-width: calc(100vw - 20px);
}
.dock-ring { width: 46px; height: 46px; flex: none; }
.dock-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.dock-ring .ring-fg { stroke-dasharray: 119.38; stroke-dashoffset: 0; }
.dock.break .ring-fg { stroke: var(--accent); }
.dock-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.dock-time { font: 700 26px/1 ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
.dock-actions { display: flex; gap: 6px; }
.dock.running { border-color: var(--brand); }

/* ---- toast & modal ---- */
.toast { position: fixed; left: 50%; top: 76px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100vw - 24px); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 22px; padding: 28px; max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.modal .emoji { font-size: 54px; }
.modal .row { justify-content: center; margin-top: 18px; }

@media (max-width: 720px) {
  .dock { left: 10px; right: 10px; transform: none; justify-content: space-between; bottom: 10px; }
  .dock-info { flex: 1; min-width: 0; }
  .hero { grid-template-columns: 1fr; }
  .brand-text span { display: none; }
  .nav { margin-left: 0; }
  .nav a { padding: 8px; }
  .topbar { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
