/* ─────────────────────────────────────────────────────────────────────
   LWF — warm editorial theme.

   Palette is a warm/cool duotone on a putty ground, with roles kept strict
   so state reads at a glance without reading any text:
     --accent (emerald)  = "you can act on this"  (links, buttons, active nav)
     --gold   (marigold) = "you've achieved this" (learned words, answered)
   Cool for action, warm for progress. --danger (brick) stays separate from
   both so an error never looks like a normal control.

   Two typefaces, clearly distinct: Newsreader (a reading serif) carries the
   voice — headings, story English, editorial copy — and Public Sans handles
   the working UI, pinyin and data. The hanzi themselves are the display type.
   ───────────────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  /* Red on white. A single hue carried across tones: a vivid scarlet for
     anything interactive, deeper reds for weight and state, soft rose washes
     for fills -- everything else stays white and quiet. */
  --bg: #ffffff;          /* white page */
  --surface: #ffffff;     /* cards sit on white, defined by their rule */
  --surface-alt: #fdf4f5; /* faintest rose, for insets */
  --ink: #1c1416;         /* near-black with a red-warm cast */
  --ink-soft: #7d6165;
  --ink-faint: #a98d90;
  --line: #f2dfe1;        /* hairline rule, rose */
  --line-soft: #f7ebec;   /* fainter rule, row separators */
  --line-strong: #e6bcc0;
  --accent: #e01b39;      /* scarlet — interactive */
  --accent-strong: #b30f2b;
  --accent-wash: #fce7ea;
  --gold: #8e1023;        /* deep crimson — achieved (distinct from the bright
                             interactive red by being deep, not by hue) */
  --gold-strong: #6e0c1c;
  --gold-wash: #fbe0e4;   /* learned rows, answered cards */
  --gold-line: #f0c2c8;
  --danger: #7a0b1a;      /* deepest red, so errors read grave, not clickable */
  --danger-wash: #fbe0e2;
  /* HSK levels deepen from a light rose to a dark crimson as difficulty
     climbs -- a single-hue intensity scale that stays inside the red theme. */
  --lv1: #e8869a; --lv2: #e05c74; --lv3: #d6304e;
  --lv4: #bb1f3c; --lv5: #99162f; --lv6: #6e0f1e;
  --cjk: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC";
  /* One sleek geometric sans for everything. Headings just take more weight
     and tighter tracking -- no separate display face. */
  --sans: "Sora", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, var(--cjk), sans-serif;
  --serif: var(--sans);  /* legacy alias -- the serif is gone */
  --radius: 10px;
  --radius-sm: 7px;
  --radius-xs: 5px;
  --shadow: 0 1px 2px rgba(28, 20, 22, 0.04), 0 6px 18px rgba(190, 20, 50, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main { max-width: 1040px; margin: 0 auto; padding: 44px 24px 104px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── top bar ───────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: baseline; gap: 36px; flex-wrap: wrap;
  /* Full-bleed background and border, but the row's content lines up with the
     1040px page column so the wordmark sits directly above the page title. */
  padding: 18px max(24px, calc((100% - 1040px) / 2 + 24px)) 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand {
  display: inline-flex; align-items: baseline; gap: 10px;
  text-decoration: none; color: var(--ink);
}
.brand-word {
  font-weight: 800; font-size: 1.4rem;
  letter-spacing: -0.03em; line-height: 1; color: var(--accent);
}
.brand-tag {
  font-size: 0.75rem; font-weight: 500; color: var(--ink-faint);
  letter-spacing: 0.01em;
}
.topbar nav { display: flex; gap: 26px; align-items: baseline; flex-wrap: wrap; }
.topbar nav a {
  color: var(--ink-soft); text-decoration: none;
  font-size: 1rem; font-weight: 500;
  padding: 2px 0 5px;
  border-bottom: 2px solid transparent;
  transition: color 0.14s, border-color 0.14s;
}
.topbar nav a:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
/* Current page: emerald word with a matching underline — a quiet "you are here". */
.topbar nav a.current { color: var(--accent); border-bottom-color: var(--accent); }

/* ── account strip in the top bar ──────────────────────────────────── */
.account { margin-left: auto; display: flex; align-items: baseline; gap: 14px; }
.account a { text-decoration: none; font-weight: 500; font-size: 0.9375rem; color: var(--ink-soft); }
.account a:hover { color: var(--ink); }
.account-name { font-weight: 600; font-size: 0.9375rem; color: var(--ink); }
.account-cta {
  padding: 7px 15px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--surface) !important;
  font-weight: 600 !important;
}
.account-cta:hover { background: var(--accent-strong); color: #fff !important; }
.role-chip {
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--gold-line); background: transparent;
  color: var(--gold-strong); font-size: 0.75rem; font-weight: 600;
}
/* Sign out is a POST (so a foreign page can't trigger it) dressed as a link. */
.linkish {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--ink-soft); font: inherit; font-size: 0.9375rem; font-weight: 500;
}
.linkish:hover { color: var(--danger); }

/* ── headings & links ──────────────────────────────────────────────── */
/* Sleek display: heavy weight, tight tracking -- the type does the work. */
h1 {
  font-weight: 800; font-size: clamp(2rem, 1.4rem + 2.6vw, 2.9rem);
  letter-spacing: -0.035em; line-height: 1.05; color: var(--ink);
  margin: 0 0 22px;
}
/* Short scarlet rule directly under the page title — marks the masthead. */
.page-head { margin-bottom: 28px; }
.page-head h1 { margin-bottom: 0; }
.page-head h1::after {
  content: ""; display: block; width: 40px; height: 3px; margin-top: 16px;
  background: var(--accent); border-radius: 3px;
}
.page-head .lede {
  font-size: 1.15rem; font-weight: 400; line-height: 1.5;
  color: var(--ink-soft); margin: 16px 0 0; max-width: 60ch;
}
h2 {
  font-weight: 700; font-size: 1.45rem;
  letter-spacing: -0.025em; color: var(--ink); margin: 40px 0 14px;
}

a { color: var(--accent-strong); text-decoration: underline;
    text-decoration-thickness: 1px; text-underline-offset: 2px;
    text-decoration-color: var(--line-strong); transition: text-decoration-color 0.14s; }
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ── tables ────────────────────────────────────────────────────────── */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  margin: 14px 0 30px;
}
th, td { text-align: left; padding: 15px 18px; border-bottom: 1px solid var(--line-soft); }
tbody tr:last-child td { border-bottom: none; }
th {
  color: var(--ink-soft); font-weight: 600; font-size: 0.8125rem;
  background: transparent; border-bottom: 1px solid var(--line);
}
td { font-size: 1.0625rem; }
tbody tr { transition: background 0.12s; }
tbody tr:hover td { background: var(--accent-wash); }

/* A learned row warms to a faint gold with a left rail — progress you can
   scan down a long list without reading a word. */
tr.is-done td { background: var(--gold-wash); }
tr.is-done:hover td { background: #ecdcb5; }
tr.is-done td:first-child { box-shadow: inset 3px 0 0 var(--gold); }

/* ── cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 30px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}

/* ── pills / chips ─────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--accent-wash); background: var(--accent-wash);
  color: var(--accent-strong);
}
.pill.done { border-color: var(--gold-line); background: var(--gold-wash); color: var(--gold-strong); }
.level-chip {
  display: inline-block; padding: 3px 10px; border-radius: var(--radius-xs);
  border: 1px solid currentColor; background: transparent;
  color: var(--ink-soft); font-size: 0.8125rem; font-weight: 600;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.level-chip.lv1 { color: var(--lv1); } .level-chip.lv2 { color: var(--lv2); }
.level-chip.lv3 { color: var(--lv3); } .level-chip.lv4 { color: var(--lv4); }
.level-chip.lv5 { color: var(--lv5); } .level-chip.lv6 { color: var(--lv6); }

/* ── progress bars ─────────────────────────────────────────────────── */
.progress-bar {
  height: 8px; border-radius: 999px; background: var(--line-soft);
  overflow: hidden; min-width: 120px;
}
.progress-bar > span { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.progress-bar.done > span { background: var(--gold); }

/* ── filters ───────────────────────────────────────────────────────── */
.filter-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-label {
  font-size: 0.8125rem; font-weight: 600; color: var(--ink-soft); min-width: 46px;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters a {
  padding: 7px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink-soft); font-size: 0.9375rem; font-weight: 500;
  background: var(--surface); transition: all 0.12s;
}
.filters a:hover { border-color: var(--line-strong); color: var(--ink); }
.filters a.active { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.filters input[type=text] {
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-size: 0.9375rem; font-family: inherit; min-width: 260px;
}
.filters input[type=text]:focus { outline: none; border-color: var(--accent); }

/* ── compact toolbar (vocabulary, set editing) ─────────────────────── */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.toolbar-search {
  flex: 1 1 280px; min-width: 220px;
  padding: 10px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
  font-size: 1rem; font-family: inherit;
}
.toolbar-search:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.toolbar select {
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
  font-size: 0.9375rem; font-weight: 500; font-family: inherit; cursor: pointer;
}
.toolbar select:hover { border-color: var(--line-strong); }
.toolbar select:focus { outline: none; border-color: var(--accent); }
.toolbar-go {
  padding: 10px 20px; border-radius: var(--radius-sm); border: 1px solid var(--accent);
  background: var(--accent); color: var(--surface);
  font-size: 0.9375rem; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: background 0.14s;
}
.toolbar-go:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

/* ── story reader ──────────────────────────────────────────────────── */
.reader-toggles { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toggle-btn {
  padding: 8px 18px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft);
  font-size: 0.9375rem; font-weight: 500; font-family: inherit; cursor: pointer;
  transition: all 0.12s;
}
.toggle-btn:hover:not(:disabled) { border-color: var(--line-strong); color: var(--ink); }
.toggle-btn.on { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.toggle-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.toggle-hint { font-size: 0.9375rem; color: var(--ink-faint); }

.rline { margin-bottom: 10px; }
.rline-newpara { margin-top: 28px; }

.rzh { font-size: 1.55rem; line-height: 1.95; font-weight: 400; }
.w, .p { display: inline-block; text-align: center; vertical-align: bottom; }
.w { cursor: pointer; border-radius: var(--radius-xs); transition: background 0.1s; }
.reader:not(.show-english) .w:hover { background: var(--accent-wash); }
.reader.show-english .w { cursor: default; }
/* Characters with no HSK vocab entry stay tappable (pinyin-only popup) but get
   a hairline dotted underline so they're told apart from real vocab words. */
.w-fallback .w-zh { border-bottom: 1px dotted var(--line-strong); }
.reader:not(.show-english) .w-fallback:hover .w-zh { border-color: var(--accent); }

.w-py {
  display: none;
  font-size: 0.8125rem; font-weight: 500; color: var(--accent);
  line-height: 1.4; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.reader.show-pinyin .w-py { display: block; }
.reader.show-pinyin .rzh { line-height: 1.55; }
.w-zh { display: block; }

.ren {
  display: none; font-family: var(--serif); font-size: 1.1rem; line-height: 1.6;
  color: var(--ink-soft); margin-top: 5px; max-width: 68ch;
}
.reader.show-english .ren { display: block; }
.ren-coarse { border-left: 2px solid var(--line-strong); padding-left: 12px; }

.wordpop {
  position: absolute; z-index: 50; max-width: 300px;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 13px 17px;
  box-shadow: 0 8px 26px rgba(34, 30, 26, 0.16);
}
.wordpop-hanzi { font-size: 1.875rem; font-weight: 500; line-height: 1.2; }
.wordpop-pinyin { font-size: 1.0625rem; font-weight: 600; color: var(--accent); margin-top: 2px; }
.wordpop-english { font-family: var(--serif); font-size: 1.05rem; margin-top: 7px; line-height: 1.45; }
.wordpop-english.muted { font-style: italic; }

/* ── audio player ──────────────────────────────────────────────────── */
.audio-player { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.speed-group { display: flex; align-items: center; gap: 6px; }
.speed-label { font-size: 0.875rem; font-weight: 500; color: var(--ink-soft); margin-right: 3px; }
.speed-btn {
  padding: 6px 11px; border-radius: var(--radius-xs); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft);
  font-size: 0.875rem; font-weight: 600; font-family: inherit; cursor: pointer;
  font-variant-numeric: tabular-nums; transition: all 0.12s;
}
.speed-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.speed-btn.on { background: var(--accent); border-color: var(--accent); color: var(--surface); }

/* The word being spoken warms to gold — a moving position marker, never a
   control, so it borrows the "achieved" colour rather than the interactive one. */
.w.speaking { background: var(--gold-wash); box-shadow: inset 0 -2px 0 var(--gold); }
.reader:not(.show-english) .w.speaking:hover { background: var(--gold-wash); }

/* ── flashcards ────────────────────────────────────────────────────── */
.flashcard-stage { max-width: 640px; margin: 8px auto 32px; }
.flashcard {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 52px 32px; min-height: 260px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; transition: border-color 0.14s;
}
.flashcard:hover { border-color: var(--line-strong); }
/* Word audio, tucked in the card's top-right corner in a deeper red so it
   reads as its own thing next to the outline controls below. */
.say-corner {
  position: absolute; top: 14px; right: 14px;
  width: 42px; height: 42px; border-radius: 999px; border: none;
  background: var(--gold); color: #fff; font-size: 1.2rem; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 3px 10px rgba(142, 16, 35, 0.3);
  transition: transform 0.1s, background 0.14s;
}
.say-corner:hover { background: var(--gold-strong); transform: scale(1.07); }
.say-corner:active { transform: scale(0.95); }
.flashcard-hanzi { font-size: 4.75rem; font-weight: 500; line-height: 1.15; letter-spacing: 0.02em; }
.flashcard-hint { margin-top: 20px; font-size: 0.875rem; font-weight: 500; color: var(--ink-faint); }
.flashcard-back { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); width: 100%; }
.flashcard-pinyin { font-size: 1.75rem; font-weight: 600; color: var(--accent); }
.flashcard-english { font-family: var(--serif); font-size: 1.3rem; margin-top: 8px; line-height: 1.45; }
.flashcard-controls {
  display: flex; gap: 12px; align-items: center; justify-content: center;
  margin-top: 20px; flex-wrap: wrap;
}
.flashcard-btn {
  padding: 9px 18px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-size: 0.9375rem; font-weight: 500; font-family: inherit; cursor: pointer;
  transition: all 0.12s;
}
.flashcard-btn:hover { border-color: var(--line-strong); background: var(--bg); }
.flashcard-btn.danger { color: var(--danger); border-color: var(--line); }
.flashcard-btn.danger:hover { border-color: var(--danger); background: var(--danger-wash); }
.filters-link { text-decoration: none; font-weight: 600; color: var(--accent-strong); white-space: nowrap; }
.filters-link:hover { color: var(--accent); }

/* ── collapsible level groups (flashcards: story sets) ─────────────── */
.level-group {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin: 12px 0 20px; padding: 2px 22px;
}
.level-group table { box-shadow: none; border: none; margin: 2px 0 14px; }
.level-group summary {
  cursor: pointer; list-style: none; padding: 16px 0;
  font-family: var(--serif); font-size: 1.15rem; font-weight: 500; color: var(--ink);
}
.level-group summary::-webkit-details-marker { display: none; }
.level-group summary::before {
  content: '\203A'; display: inline-block; width: 1em; margin-right: 8px;
  color: var(--accent); font-family: var(--sans); transition: transform 0.15s;
}
.level-group[open] summary::before { transform: rotate(90deg); }

/* ── pagination ────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 8px 0 32px; }
.pagination a {
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft);
  text-decoration: none; font-size: 0.9375rem; font-weight: 500;
}
.pagination a:hover { border-color: var(--line-strong); color: var(--ink); }
.page-indicator { font-size: 0.9375rem; font-weight: 500; color: var(--ink-soft); padding: 0 10px; font-variant-numeric: tabular-nums; }

/* ── vocabulary ────────────────────────────────────────────────────── */
.hanzi-cell { padding-right: 8px; }
.hanzi { font-size: 2.25rem; font-weight: 500; line-height: 1.25; letter-spacing: 0.02em; color: var(--ink); }
.hanzi .trad { font-size: 1.375rem; font-weight: 400; color: var(--ink-faint); }
.pinyin { font-size: 1rem; font-weight: 500; color: var(--accent); margin-top: 2px; }
.definition { font-family: var(--serif); font-size: 1.1rem; line-height: 1.5; }

.check-label { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.check-label input[type=checkbox] {
  width: 22px; height: 22px; cursor: pointer;
  accent-color: var(--gold); flex-shrink: 0;
}
.check-text { font-size: 0.9375rem; font-weight: 500; color: var(--ink-soft); white-space: nowrap; }

/* ── frequency ─────────────────────────────────────────────────────── */
.freq-rank { font-size: 1.1rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.freq-detail { font-size: 0.875rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.freq-none { font-size: 0.9375rem; color: var(--ink-faint); }

/* ── disclosure blocks (examples, occurrences, answers) ────────────── */
details.answer { margin-top: 10px; font-size: 1rem; }
details.answer summary {
  cursor: pointer; color: var(--accent-strong); font-weight: 500;
  padding: 6px 13px; border-radius: var(--radius-xs);
  border: 1px solid var(--accent-wash); background: var(--accent-wash);
  display: inline-block; list-style: none; font-size: 0.9375rem;
}
details.answer summary::-webkit-details-marker { display: none; }
details.answer summary:hover { border-color: var(--accent); }
details.answer[open] summary { margin-bottom: 10px; }

.examples { font-family: var(--serif); font-size: 1.02rem; color: var(--ink-soft); line-height: 1.65; }
.examples > div {
  margin-bottom: 8px; padding: 10px 14px;
  background: var(--bg); border-left: 2px solid var(--line-strong);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}
.examples mark { background: var(--gold-wash); color: var(--ink); font-weight: 600; border-radius: 2px; padding: 0 3px; }

/* ── stories ───────────────────────────────────────────────────────── */
.story-text { white-space: pre-line; font-size: 1.5rem; line-height: 2.05; }
.story-translation {
  font-family: var(--serif); font-size: 1.15rem; line-height: 1.65; color: var(--ink-soft);
  padding: 16px 20px; background: var(--surface);
  border-radius: var(--radius-sm); border-left: 2px solid var(--accent);
}
.story-preview { font-size: 1.05rem; }
.story-title { font-family: var(--serif); font-size: 1.2rem; font-weight: 500; text-decoration: none; color: var(--ink); }
.story-title:hover { color: var(--accent); }
.story-subtitle { font-size: 0.9375rem; color: var(--ink-soft); margin-top: 3px; }
.story-subtitle-large {
  font-family: var(--cjk), sans-serif; font-size: 1.4rem; color: var(--ink-soft);
  font-weight: 500; margin: -14px 0 22px;
}

/* ── questions ─────────────────────────────────────────────────────── */
.question {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 26px; margin-bottom: 16px;
  background: var(--surface); box-shadow: var(--shadow);
  transition: border-color 0.14s, background 0.14s;
}
.question.answered { border-color: var(--gold-line); background: var(--gold-wash); }
.question-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.question-prompt { font-family: var(--serif); font-size: 1.2rem; line-height: 1.55; margin: 4px 0 10px; white-space: pre-line; }
.question-meta { font-size: 0.8125rem; font-weight: 600; color: var(--ink-faint); }
.options { list-style: none; padding: 0; margin: 12px 0 0; }
.options li {
  padding: 10px 16px; margin-bottom: 6px; font-size: 1.0625rem;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--radius-xs);
}
.options li.correct { font-weight: 600; color: var(--gold-strong); border-color: var(--gold-line); background: var(--gold-wash); }

/* ── summary stats ─────────────────────────────────────────────────── */
.summary-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px; margin-bottom: 30px;
}
.summary-grid .stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 20px;
  box-shadow: var(--shadow);
}
.summary-grid .stat .num {
  font-family: var(--serif); font-size: 2.4rem; font-weight: 500;
  letter-spacing: -0.02em; line-height: 1.05; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.summary-grid .stat .label { color: var(--ink-soft); font-size: 0.9375rem; font-weight: 500; margin-top: 8px; }

/* ── misc ──────────────────────────────────────────────────────────── */
.muted { color: var(--ink-soft); }
.note {
  font-size: 0.9375rem; color: var(--ink-soft); line-height: 1.6;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 2px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px; margin: 0 0 22px; max-width: 74ch;
}
.result-count { font-size: 0.9375rem; font-weight: 500; color: var(--ink-soft); margin: 4px 0 16px; }
.nav-links { display: flex; justify-content: space-between; margin: 32px 0; gap: 16px; }
.nav-links a {
  text-decoration: none; color: var(--ink); font-size: 1rem; font-weight: 500;
  padding: 10px 20px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); transition: all 0.12s;
}
.nav-links a:hover { border-color: var(--line-strong); color: var(--accent); }
.back-link { display: inline-block; font-weight: 500; text-decoration: none; margin-bottom: 12px; color: var(--ink-soft); }
.back-link:hover { color: var(--accent); }

/* ── forms (sign in, register, sharing) ────────────────────────────── */
.auth-card { max-width: 460px; }
.auth-form { display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; border: none; padding: 0; margin: 0; }
.field-label { font-size: 0.9375rem; font-weight: 600; color: var(--ink); padding: 0; }
.field-input {
  padding: 11px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
  font-size: 1rem; font-family: inherit;
}
.field-input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.field-hint { font-size: 0.875rem; color: var(--ink-soft); line-height: 1.5; }
.role-choice { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.role-option {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 18px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  font-weight: 500;
}
.role-option input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.role-option:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); color: var(--accent-strong); }
.form-error {
  background: var(--danger-wash); border: 1px solid #e4b6ac; border-left: 2px solid var(--danger);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 12px 16px; font-weight: 500; color: #7e2b20;
}
.form-note {
  background: var(--gold-wash); border-left: 2px solid var(--gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 12px 16px; font-weight: 500; color: var(--gold-strong);
}

/* ── library: sets shelf + story/set rows ──────────────────────────── */
.shelf {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px; margin: 8px 0 16px;
}
.deck-card {
  display: flex; flex-direction: column; gap: 5px;
  padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink); transition: border-color 0.14s;
}
.deck-card:hover { border-color: var(--line-strong); }
/* The most-used set leads and reads as the recommended start. */
.deck-card.deck-lead { border-color: var(--accent); background: var(--accent-wash); }
.deck-card.deck-lead:hover { border-color: var(--accent-strong); }
.deck-name { font-family: var(--serif); font-size: 1.1rem; font-weight: 500; line-height: 1.25; }
.deck-meta { font-size: 0.875rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.deck-from { font-size: 0.8125rem; color: var(--ink-faint); }
/* New set is a single (+) tile that opens the name/description dialog. */
.deck-add {
  align-items: center; justify-content: center; min-height: 88px;
  border-style: dashed; border-color: var(--line-strong);
  background: var(--surface); cursor: pointer; font: inherit;
}
.deck-add:hover { border-color: var(--accent); background: var(--accent-wash); }
.deck-plus { font-size: 2rem; font-weight: 300; color: var(--accent); line-height: 1; }

.set-dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 26px; max-width: 400px; width: calc(100% - 32px);
  box-shadow: 0 16px 46px rgba(28, 20, 22, 0.22); color: var(--ink);
}
.set-dialog::backdrop { background: rgba(28, 20, 22, 0.38); }
.set-dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ── progress strip (top of stories) ───────────────────────────────── */
.progress-strip {
  display: flex; gap: 40px; flex-wrap: wrap; align-items: flex-start;
  padding-bottom: 22px; margin-bottom: 26px; border-bottom: 1px solid var(--line);
}
.prog { display: flex; flex-direction: column; gap: 3px; }
.prog-num {
  font-size: 1.9rem; font-weight: 800; letter-spacing: -0.03em;
  color: var(--ink); line-height: 1; font-variant-numeric: tabular-nums;
}
.prog-of { font-size: 1rem; font-weight: 500; color: var(--ink-faint); letter-spacing: 0; }
.prog-label { font-size: 0.85rem; color: var(--ink-soft); }
.prog-bar {
  margin-top: 7px; width: 150px; height: 6px; border-radius: 999px;
  background: var(--line-soft); overflow: hidden;
}
.prog-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

.lib-row {
  display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; margin-bottom: 14px;
}
.lib-story {
  display: flex; flex-direction: column; gap: 8px; padding: 18px 20px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink); transition: border-color 0.14s;
}
.lib-story:hover { border-color: var(--line-strong); }
.lib-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lib-title { font-family: var(--serif); font-size: 1.2rem; font-weight: 500; line-height: 1.3; margin: 0; }
.lib-title-zh { font-family: var(--cjk), sans-serif; font-size: 1.15rem; }
.lib-zh {
  font-family: var(--cjk), sans-serif; font-size: 0.98rem; color: var(--ink-soft);
  line-height: 1.5; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-set {
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
  padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-alt);
}
.lib-set-count { font-family: var(--serif); font-size: 1.05rem; color: var(--ink); }
.lib-set-sample {
  font-family: var(--cjk), sans-serif; font-size: 1.35rem; color: var(--ink);
  letter-spacing: 0.12em; line-height: 1.3;
}
.lib-set.empty { justify-content: center; }
.lib-set.empty p { margin: 0; font-size: 0.9375rem; }
a.toolbar-go { display: inline-block; text-decoration: none; align-self: flex-start; }

/* ── responsive ────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .lib-row { grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; }
  body { font-size: 16px; }
  main { padding: 28px 16px 80px; }
  .topbar { gap: 18px 24px; padding: 16px 18px; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  table { background: transparent; border: none; box-shadow: none; }
  tbody tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); margin-bottom: 14px; padding: 16px;
    box-shadow: var(--shadow);
  }
  tbody tr:hover td { background: transparent; }
  tr.is-done { border-color: var(--gold-line); background: var(--gold-wash); }
  tr.is-done td { background: transparent; }
  tr.is-done td:first-child { box-shadow: none; }
  td { border: none; padding: 5px 0; }
  td::before {
    content: attr(data-label); display: block;
    font-size: 0.75rem; font-weight: 600; color: var(--ink-faint); margin-bottom: 2px;
  }
  td.hanzi-cell::before, td.no-label::before { content: none; }
  .filter-label { min-width: 100%; }
  .filters input[type=text] { min-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
