/* Zìzì design system: warm paper neutrals, one deep Chinese red as the accent, Chinese text
   first. Spacing follows 4 / 8 / 12 / 16 / 24 / 32 / 48 px. */
:root {
  --bg: #f8f7f3;
  --surface: #ffffff;
  --surface-2: #f3f1ec;       /* quiet fills: segmented controls, rows, inputs */
  --text: #171717;
  --muted: #6b6b6b;           /* secondary text */
  --faint: #9a9a9a;           /* metadata */
  --border: #e7e3dc;
  --border-strong: #d8d3ca;
  --accent: #b3261e;
  --accent-hover: #971f18;
  --accent-soft: #fbeeec;
  --accent-text: #ffffff;
  --hover: #fbeeec;           /* hovered word */
  --pinned: #f5d7d2;          /* pinned word */
  --highlight: #b3261e;       /* highlighted HSK words */
  --success: #2f7d4f; --success-soft: #e8f3ec;
  --warning: #a8661a; --warning-soft: #fbf1e1;
  --info: #3b6aa8; --info-soft: #e9eff8;
  --tone1: #d7263d;
  --tone2: #e07a10;
  --tone3: #2e8b3e;
  --tone4: #2563c9;
  --tone5: #6b6b6b;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(23, 20, 15, 0.04);
  --shadow: 0 12px 32px rgba(40, 30, 20, 0.14), 0 2px 6px rgba(40, 30, 20, 0.06);
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --zh-font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --reader-size: 26px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151413;
    --surface: #1e1c1a;
    --surface-2: #272421;
    --text: #edeae4;
    --muted: #aaa49b;
    --faint: #7c766e;
    --border: #34302b;
    --border-strong: #45403a;
    --accent: #d9463e;
    --accent-hover: #e5564e;
    --accent-soft: #3a211e;
    --accent-text: #ffffff;
    --hover: #3a2522;
    --pinned: #5a2c27;
    --highlight: #f07a72;
    --success: #6cc38b; --success-soft: #1d3326;
    --warning: #e6a55a; --warning-soft: #372a19;
    --info: #86aee6; --info-soft: #1c2a3d;
    --tone1: #ff6b6b;
    --tone2: #f5a142;
    --tone3: #5cc26c;
    --tone4: #6aa3ff;
    --tone5: #aaa49b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--ui-font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 0 16px 24px; }
button, select, input, textarea { font: inherit; color: inherit; }
h2, h3 { letter-spacing: -0.01em; }
.icon { display: block; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.primary, .secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: background-color 120ms, border-color 120ms, color 120ms;
}
.primary { background: var(--accent); color: var(--accent-text); }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); font-weight: 500; }
.secondary:hover { background: var(--surface-2); }
.primary:disabled, .secondary:disabled { opacity: 0.45; cursor: default; }
.primary:disabled:hover { background: var(--accent); }
.secondary:disabled:hover { background: var(--surface); }
.primary.small, .secondary.small { min-height: 34px; padding: 5px 14px; font-size: 14px; border-radius: 9px; gap: 6px; }
.full { width: 100%; }
.link {
  background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 14px; font-weight: 500;
}
.link:hover { text-decoration: underline; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 34px; height: 34px; padding: 0; border-radius: 999px; cursor: pointer;
  background: none; border: 1px solid transparent; color: var(--muted);
  transition: background-color 120ms, color 120ms;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.playing, .icon-btn:active { color: var(--accent); }
/* Icon + label; the label is dropped on narrow screens. */
.icon-label { gap: 6px; padding-left: 12px; padding-right: 14px; }

/* ---------- Top bar ---------- */
.topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
  max-width: 880px; width: 100%; margin: 0 auto; padding: 20px 16px 16px;
}
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(20px + env(safe-area-inset-top)); }
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}
.brand { font-size: 24px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 12px; letter-spacing: -0.01em; }
.brand-icon { width: 40px; height: 40px; border-radius: 11px; display: block; box-shadow: var(--shadow-sm); }
.top-actions { grid-column: 3; display: flex; align-items: center; gap: 8px; }
.streak-btn {
  display: inline-flex; align-items: center; gap: 4px; min-height: 38px; padding: 6px 12px 6px 9px; border-radius: 999px;
  font-weight: 700; font-variant-numeric: tabular-nums; color: var(--faint);
}
.streak-btn.done { color: #e8590c; border-color: color-mix(in srgb, #e8590c 40%, var(--border)); background: color-mix(in srgb, #e8590c 8%, var(--surface)); }
.streak-btn.pending .icon { color: #e8590c; opacity: 0.55; }
.account-btn { min-height: 38px; padding: 6px 14px 6px 10px; border-radius: 999px; position: relative; }
.account-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.account-btn[data-status]:not([data-status=""])::after {
  content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--surface);
}
.account-btn[data-status="syncing"]::after { background: var(--warning); }
.account-btn[data-status="offline"]::after, .account-btn[data-status="error"]::after { background: var(--accent); }
.mainnav {
  grid-column: 2; grid-row: 1; justify-self: center;
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-sm);
}
.nav-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 6px 16px; border: none; border-radius: 10px; cursor: pointer;
  background: none; color: var(--muted); font-size: 15px; font-weight: 500; white-space: nowrap;
  transition: background-color 120ms, color 120ms;
}
.nav-btn:hover { color: var(--text); background: var(--surface-2); }
.nav-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.count { color: inherit; opacity: 0.75; font-weight: 400; }
.nav-btn .count:empty { display: none; }

/* ---------- Locked features (signed out) ---------- */
.locked::before {
  content: ""; width: 14px; height: 14px; flex-shrink: 0; background: currentColor; opacity: 0.8;
  -webkit-mask: var(--lock-icon) center / contain no-repeat; mask: var(--lock-icon) center / contain no-repeat;
}
:root {
  --lock-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E");
}
.nav-btn.locked { gap: 6px; }
.nav-btn.locked .count { display: none; }
.locked > .icon { display: none; }
.unlock-dialog, .words-dialog {
  padding: 0; border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.unlock-dialog { width: min(460px, calc(100vw - 32px)); }
.unlock-dialog::backdrop, .words-dialog::backdrop { background: rgba(20, 15, 10, 0.45); }
.unlock { padding: 24px 24px 20px; }
.unlock-icon {
  display: inline-flex; padding: 12px; border-radius: 14px; background: var(--accent-soft); color: var(--accent);
}
.unlock h2 { margin: 16px 0 6px; font-size: 21px; }
.unlock p { margin: 0 0 12px; color: var(--muted); }
.unlock-list { margin: 0; padding: 0; list-style: none; font-size: 14px; }
.unlock-list li { padding: 8px 12px; border-radius: var(--r-sm); color: var(--muted); }
.unlock-list li b { color: var(--text); }
.unlock-list li::before { content: "✓  "; color: var(--success); font-weight: 700; }
.unlock-list li.current { background: var(--accent-soft); }
.unlock .actions { align-items: center; flex-wrap: wrap; margin-top: 20px; }
.unlock .unlock-close { margin-right: auto; color: var(--muted); }

/* ---------- Panels and page headings ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 24px; box-shadow: var(--shadow-sm);
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-title { margin: 0; font-size: 26px; font-weight: 700; }
.page-sub { margin: 4px 0 0; color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; }
.status { color: var(--muted); font-size: 14px; min-height: 1.5em; margin: 12px 0 0; }
.status.error { color: var(--accent); }
.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.actions.left { justify-content: flex-start; flex-wrap: wrap; align-items: center; }
.actions.left .hint { margin: 0; }

/* Library: continue reading, the saved books and texts, and adding one (the reader opens from here).
   With nothing saved yet, adding comes first. */
.library { display: flex; flex-direction: column; gap: 16px; }
.library > .panel { margin: 0; }
.library.add-first #input-view { order: -1; }
.library.add-first #continue-reading { order: -2; }
.panel.continue { padding: 0; overflow: hidden; }
.continue-open {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px 20px; text-align: left;
  background: none; border: none; cursor: pointer; color: var(--text);
}
@media (hover: hover) { .continue-open:hover { background: var(--surface-2); } }
.continue-open:disabled { cursor: progress; opacity: 0.7; }
.continue-icon { display: inline-flex; padding: 12px; border-radius: 12px; background: var(--accent); color: var(--accent-text); flex-shrink: 0; }
.continue-body { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.continue-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }
.continue-title { font-weight: 700; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.continue-where { color: var(--muted); font-size: 14px; }
.continue-open.loading .continue-icon { animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.5; } }
.reader-meta .meta-back { display: inline-flex; align-items: center; gap: 1px; font-size: inherit; }

/* Segmented control (tabs) */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 16px;
  background: var(--surface-2); border-radius: 11px;
}
.segmented button {
  border: none; background: none; border-radius: 8px; padding: 6px 14px; min-height: 34px; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 15px; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

/* Inputs */
textarea, input[type="search"], input[type="text"], input[type="email"], input[type="password"], input:not([type]), select {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 8px 12px; min-height: 40px; color: var(--text);
  transition: border-color 120ms, box-shadow 120ms;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea {
  display: block; width: 100%; min-height: 280px; resize: vertical; padding: 16px;
  font-family: var(--zh-font); font-size: 19px; line-height: 1.8; background: var(--bg);
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 240px; padding: 24px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--r-md); background: var(--bg);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dz-icon { display: inline-flex; padding: 12px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); }
.dz-title { font-weight: 600; }
.dz-hint { color: var(--muted); font-size: 14px; max-width: 420px; }

/* Reading a file: spinner, file name, progress bar (filled, or sliding when the amount is unknown) */
.file-progress {
  display: flex; flex-direction: column; justify-content: center; gap: 14px; min-height: 240px; padding: 24px 28px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg);
}
.fp-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fp-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-msg { color: var(--muted); font-size: 14px; }
.fp-track { position: relative; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.fp-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: inherit; background: var(--accent); transition: width 200ms ease-out; }
.fp-track.indeterminate .fp-fill { width: 35%; animation: fp-slide 1.1s ease-in-out infinite; transition: none; }
@keyframes fp-slide { from { left: -35%; } to { left: 100%; } }
.spinner {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chapter.loading .ch-meta { font-size: 0; }
.chapter.loading .ch-meta::after {
  content: ""; display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: middle;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
.pager.loading .pager-fill { width: 35% !important; animation: fp-slide 1.1s ease-in-out infinite; position: relative; }
@media (prefers-reduced-motion: reduce) {
  .spinner, .chapter.loading .ch-meta::after { animation-duration: 2.4s; }
  .fp-track.indeterminate .fp-fill { animation: none; left: 0; width: 100%; opacity: 0.5; }
}

/* A book from an uploaded file: its chapters */
.book { margin-top: 20px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); padding: 16px; }
.book-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.book-head h3 { margin: 0; font-size: 18px; }
.book-head .hint { margin: 2px 0 0; }
.book-head > div { flex: 1; min-width: 0; }
.book-head .book-save, .book-head .book-saved { flex-shrink: 0; }
.book-head .book-saved { min-height: 36px; padding: 0 12px; }
@media (max-width: 600px) {
  .book-head { flex-wrap: wrap; row-gap: 10px; }
  .book-head > div { flex-basis: calc(100% - 56px); }
  .book-head .book-save, .book-head .book-saved { margin-left: 56px; }
}
.save-menu summary.is-saved { color: var(--success); }
.save-menu .menu-panel { width: 260px; }
.save-menu .menu-item:disabled { opacity: 0.6; cursor: default; background: none; }
.book-icon { display: inline-flex; padding: 10px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.chapter-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.chapter {
  display: flex; align-items: baseline; gap: 12px; width: 100%; padding: 10px 12px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text);
}
.chapter:hover { border-color: var(--border-strong); }
.chapter.current { border-color: var(--accent); background: var(--accent-soft); }
.ch-num { color: var(--faint); font-size: 13px; min-width: 2em; text-align: right; font-variant-numeric: tabular-nums; }
.ch-title { flex: 1; min-width: 0; font-family: var(--zh-font); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-meta { color: var(--faint); font-size: 13px; white-space: nowrap; }
.reader-meta .link { font-size: 14px; }

/* Empty states and promos */
.empty {
  list-style: none; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 36px 16px; border: 1px dashed var(--border-strong); border-radius: var(--r-md); background: var(--bg);
}
.empty h3 { margin: 8px 0 0; font-size: 18px; }
.empty p { margin: 0 0 10px; color: var(--muted); max-width: 380px; }
.empty-icon { display: inline-flex; padding: 12px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); }
.guest-note {
  display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; padding: 10px 12px; font-size: 14px;
  color: var(--muted); background: var(--surface-2); border-radius: var(--r-sm);
}
.guest-note .icon { flex-shrink: 0; margin-top: 2px; color: var(--faint); }
.guest-note .link { font-size: inherit; }
.promo {
  display: flex; align-items: center; gap: 16px; width: 100%; margin-top: 16px; padding: 16px 18px;
  text-align: left; cursor: pointer; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
}
.promo:hover { border-color: var(--border-strong); }
.promo > .icon { margin-left: auto; color: var(--faint); }
.promo-icon { display: inline-flex; padding: 12px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.promo-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.promo-text span { color: var(--muted); font-size: 14px; }

/* Badges and chips */
.badge {
  display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; line-height: 1.5;
  padding: 1px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip {
  flex-shrink: 0; font-size: 12px; font-weight: 500; line-height: 1.5; padding: 1px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--faint); background: var(--surface);
}
.chip.s-learning { color: var(--warning); background: var(--warning-soft); border-color: transparent; }
.chip.s-known { color: var(--success); background: var(--success-soft); border-color: transparent; font-weight: 600; }
/* A word's skills (字 characters, 意 meaning, 听 listen, 写 write), each new / learning / known */
.skills { display: inline-flex; gap: 3px; flex-shrink: 0; }
.skill {
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px;
  font-family: var(--zh-font); font-size: 13px; line-height: 1; color: var(--faint); border: 1px solid var(--border); background: var(--surface);
}
.skill.s-learning { color: var(--warning); background: var(--warning-soft); border-color: transparent; }
.skill.s-known { color: var(--success); background: var(--success-soft); border-color: transparent; font-weight: 700; }

/* Menus: ⋯ buttons and the Display panel */
details.menu, .display-menu { position: relative; }
details.menu > summary, .display-menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker, .display-menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { background: var(--surface-2); color: var(--text); }
.menu-panel {
  position: absolute; z-index: 20; top: calc(100% + 6px); right: 0; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow);
  padding: 6px; color: var(--text); font-size: 14px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; border-radius: var(--r-sm);
  background: none; cursor: pointer; text-align: left; font-size: 14px; color: var(--text);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item .icon { color: var(--muted); }
.menu-item.danger, .menu-item.danger .icon { color: var(--accent); }

/* ---------- Reader ---------- */
.reader-bar {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px;
}
.reader-bar .segmented { margin: 0; }
.reader-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.display-menu > summary { cursor: pointer; }
.display-menu[open] > summary { background: var(--surface-2); }
.display-menu .menu-panel { width: 300px; padding: 8px 14px 14px; }
.switch-row, .field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 15px;
}
.field-row select { min-height: 34px; padding: 4px 10px; }
.switch {
  appearance: none; -webkit-appearance: none; position: relative; width: 40px; height: 24px; margin: 0; flex-shrink: 0;
  border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background-color 150ms;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 150ms;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
.menu-section { padding-top: 12px; }
.menu-label { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 15px; }
.menu-value { color: var(--accent); font-weight: 500; font-size: 13px; text-align: right; }
.menu-hint { margin: 2px 0 10px; color: var(--muted); font-size: 13px; }
.level-checks { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip-check { cursor: pointer; }
.chip-check input { position: absolute; opacity: 0; pointer-events: none; }
.chip-check span {
  display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-strong); color: var(--muted); background: var(--surface);
}
.chip-check input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-check input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.save-text { display: flex; align-items: center; }
.save-text .inline-form { display: flex; align-items: center; gap: 6px; }
.save-text .inline-form input { width: 13em; min-height: 36px; padding: 5px 10px; }
.save-text .status { margin: 4px 0 0; }
.saved-as {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px;
  color: var(--success); background: var(--success-soft); font-size: 14px; font-weight: 600;
}
.reader-meta { margin: 0 0 4px; color: var(--faint); font-size: 14px; }
.reader-meta b { color: var(--muted); font-weight: 600; }
#reader-hint { margin: 0 0 12px; font-size: 13px; color: var(--faint); }

.reader {
  font-family: var(--zh-font);
  font-size: var(--reader-size);
  line-height: 1.9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  letter-spacing: 0.02em;
}
.reader.with-pinyin { line-height: 2.4; }
/* Blocks of a text: paragraphs, and the headings, list items, dividers and pictures of a book */
.reader p { margin: 0 0 0.45em; }
.reader .rd-h1, .reader .rd-h2, .reader .rd-h3 { margin: 0.7em 0 0.45em; line-height: 1.5; font-weight: 700; letter-spacing: 0.01em; }
.reader .rd-h1 { font-size: 1.35em; text-align: center; }
.reader .rd-h2 { font-size: 1.2em; }
.reader .rd-h3 { font-size: 1.1em; }
.reader > :first-child { margin-top: 0; }
.reader .rd-li { position: relative; padding-left: 1.1em; }
.reader .rd-li.rd-cont::before { content: none; }
.reader .rd-li::before { content: "•"; position: absolute; left: 0.2em; color: var(--faint); }
.reader .rd-center { text-align: center; }
.rd-hr { border: 0; border-top: 1px solid var(--border); margin: 1em 25%; }
.rd-figure { margin: 0.7em 0; text-align: center; }
.rd-figure img {
  display: inline-block; max-width: 100%; height: auto; max-height: calc(var(--page-h, 60vh) - 1.4em); object-fit: contain;
  border-radius: 8px; box-shadow: var(--shadow-sm);
}
.w { cursor: pointer; border-radius: 4px; transition: background-color 80ms; }
.w:hover, .w.active { background: var(--hover); }
.w.pinned { background: var(--pinned); }
.w.unknown { color: var(--faint); cursor: default; }
.w.unknown:hover { background: none; }
.reader.hsk-highlight .w.hl {
  color: var(--highlight); text-decoration: underline dotted; text-decoration-thickness: 1.5px; text-underline-offset: 0.22em;
}
rt { font-family: var(--ui-font); font-size: 0.42em; color: var(--muted); user-select: none; letter-spacing: 0; }

/* Swipes: the browser keeps vertical scrolling, the app handles sideways moves. */
.reader, .page-stack, .flashcard { touch-action: pan-y; }
.flashcard:not(.revealed) { user-select: none; -webkit-user-select: none; } /* double tap/click reveals */
.cards { overflow-x: clip; } /* a card swiped away flies off the side */
/* Page turns: the page flies off like a flashcard (set from app.js), uncovering the next page,
   which is already lying underneath. */
#reader-view { overflow-x: clip; } /* a page turned away flies off the side */
.page-stack { position: relative; }
.reader { position: relative; z-index: 1; transform-origin: 50% 100%; }
.reader.under { position: absolute; top: 0; left: 0; right: 0; z-index: 0; pointer-events: none; }
/* The whole text, laid out for a moment to find where pages end (see measurePages in app.js). */
.reader.measure { position: absolute; top: 0; left: 0; right: 0; z-index: -1; visibility: hidden; pointer-events: none; }
.reader.dragging {
  /* An opaque sheet of paper while it moves; the padding and margin cancel out. */
  background: var(--surface); border-radius: var(--r-md); padding: 0 12px; margin: 0 -12px;
  box-shadow: 0 12px 32px rgba(40, 30, 20, 0.16);
}

/* Page buttons: under the text, and stuck to the bottom of the window while reading. */
.pager {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 24px -24px -24px; padding: 14px 24px;
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.pager-btn { min-width: 128px; }
.pager-mid { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; }
.pager-info { color: var(--muted); font-size: 14px; }
.pager-chapter { color: var(--faint); font-size: 12px; margin-top: -6px; }
.pager-track { width: min(180px, 100%); height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.pager-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 200ms; }

/* ---------- Word popup ---------- */
.popup {
  position: absolute; z-index: 10;
  width: min(360px, calc(100vw - 24px)); max-height: min(60vh, 460px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 16px 18px; font-size: 15px;
}
.popup-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.popup-word { font-family: var(--zh-font); font-size: 34px; line-height: 1.2; color: var(--accent); font-weight: 500; }
.popup-trad { font-family: var(--zh-font); font-size: 20px; color: var(--faint); }
.popup-speak { margin-left: auto; background: var(--surface-2); color: var(--text); }
.popup-entry { margin-top: 12px; }
.popup-entry + .popup-entry { padding-top: 12px; border-top: 1px solid var(--border); }
.pinyin { font-size: 18px; font-weight: 600; }
.t1 { color: var(--tone1); } .t2 { color: var(--tone2); } .t3 { color: var(--tone3); }
.t4 { color: var(--tone4); } .t5, .t0 { color: var(--tone5); }
.no-tones .t1, .no-tones .t2, .no-tones .t3, .no-tones .t4 { color: inherit; }
.defs { list-style: none; margin: 4px 0 0; padding: 0; }
.defs li { margin: 3px 0; }
.defs .pm { display: flex; gap: 8px; align-items: baseline; cursor: pointer; }
.defs .pm input { margin: 0; flex-shrink: 0; transform: translateY(2px); }
.chars { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; }
.chars-title { color: var(--faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.char-row { display: flex; gap: 10px; align-items: baseline; margin-top: 4px; }
.char-row .zh { font-family: var(--zh-font); font-size: 20px; }
.char-row .def { color: var(--muted); }
.char-row .pinyin-sm { white-space: nowrap; }
.popup-save {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  margin-top: 12px; padding: 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 14px;
}
.popup-save select, .popup-save input { min-height: 34px; padding: 4px 10px; min-width: 0; }
.popup-save select { flex: 1 1 140px; max-width: 220px; }
.popup-save input { flex: 1 1 140px; }
.save-status { color: var(--muted); font-size: 13px; }

/* ---------- Grammar ---------- */
.grammar > .hint { margin: 0 0 12px; }
.gp-filter { padding: 8px 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg); }
.gp-filter .hint { font-size: 13px; }
.gp-level { font-size: 13px; margin: 20px 0 8px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; display: inline; }
.grammar > .gp-level { display: block; }
.gp { border: 1px solid var(--border); border-radius: var(--r-md); margin: 8px 0; background: var(--surface); }
.gp > summary { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; list-style: none; }
.gp > summary::-webkit-details-marker { display: none; }
.gp > summary::after { content: "›"; margin-left: auto; color: var(--faint); font-size: 20px; line-height: 1; transition: transform 120ms; }
.gp[open] > summary::after { transform: rotate(90deg); }
.gp:hover { border-color: var(--border-strong); }
.gp-count { color: var(--faint); font-size: 13px; white-space: nowrap; }
.gp > summary .badge { flex-shrink: 0; }
.gp-name { font-weight: 600; }
.gp-body { padding: 4px 16px 16px; border-top: 1px solid var(--border); }
.gp-body p { margin: 10px 0; }
.gp-structure { font-family: var(--zh-font); font-size: 17px; }
.gp-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin-top: 14px; }
.gp-examples, .gp-sentences { margin: 4px 0; padding-left: 20px; font-family: var(--zh-font); font-size: 17px; }
.gp-examples li, .gp-sentences li { margin: 6px 0; }
.gp-examples .py { font-family: var(--ui-font); font-size: 13px; color: var(--muted); display: block; }
.gp-examples .en { font-family: var(--ui-font); font-size: 14px; display: block; }
.gp-notes { margin: 6px 0 10px; padding-left: 20px; font-size: 15px; color: var(--muted); }
.gp-notes li { margin: 4px 0; }
.sentence { font-family: var(--zh-font); font-size: 17px; line-height: 1.7; }
.jump { font-size: 13px; margin-left: 6px; white-space: nowrap; }
mark { background: var(--hover); color: inherit; border-radius: 3px; padding: 0 1px; }
.gp-review { margin-top: 20px; }
.gp-review > summary { cursor: pointer; }
.w.flash { animation: flash 2s ease-out; }
@keyframes flash { 0%, 40% { background: var(--pinned); } 100% { background: transparent; } }
.gp-locked {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 16px; text-align: left;
  cursor: pointer; font: inherit; color: inherit;
}
.gp-locked .gp-name { color: var(--muted); }
.gp-locked .lock-icon { margin-left: auto; color: var(--faint); }
.unlock-cta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  margin: 16px 0 8px; padding: 14px 16px; border-radius: var(--r-md); background: var(--accent-soft);
}
.unlock-cta p { margin: 0; font-size: 14px; flex: 1 1 260px; }
.unlock-cta p .icon { display: inline-block; vertical-align: -2px; color: var(--accent); }
.badge.lv1, .badge.lv2 { background: #e8f3ec; border-color: #c9e3d2; color: #2c6e45; }
.badge.lv3, .badge.lv4 { background: #e9eff8; border-color: #cddbef; color: #2f5a93; }
.badge.lv5, .badge.lv6 { background: #fbf1e1; border-color: #efdab6; color: #8a5414; }
.badge.lv7 { background: #fbeeec; border-color: #f0cfca; color: #962323; }
@media (prefers-color-scheme: dark) {
  .badge.lv1, .badge.lv2 { background: #1d3326; border-color: #2d4d39; color: #9fd8b1; }
  .badge.lv3, .badge.lv4 { background: #1c2a3d; border-color: #2d4466; color: #a9c6f0; }
  .badge.lv5, .badge.lv6 { background: #372a19; border-color: #5a4323; color: #f0c68f; }
  .badge.lv7 { background: #3a211e; border-color: #5e302b; color: #f3aaa4; }
}

/* ---------- Word lists ---------- */
.new-list-form { display: flex; gap: 8px; align-items: center; margin: -4px 0 16px; }
.new-list-form input { flex: 1; min-width: 0; }
.list-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.list-card {
  --list-color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--list-color) 22%, var(--border));
  background: color-mix(in srgb, var(--list-color) 6%, var(--surface));
  border-radius: var(--r-md); overflow: hidden;
}
.list-head {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px 18px; border: none; background: none;
  cursor: pointer; text-align: left; color: var(--text);
}
.list-folder { color: var(--list-color); display: inline-flex; }
.list-folder .icon { fill: currentColor; fill-opacity: 0.9; }
.list-name { font-weight: 700; font-size: 18px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list-count { color: var(--muted); font-size: 14px; white-space: nowrap; }
.list-chevron { color: var(--faint); display: inline-flex; }
.list-body { padding: 0 12px 12px; }
.list-detail { background: var(--surface); border-radius: var(--r-sm); padding: 12px; }
.ld-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.ld-menu { margin-left: auto; }
.ld-search { position: relative; }
.ld-search .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.ld-search .ld-query { width: 100%; padding-left: 38px; }
.ld-results { list-style: none; margin: 8px 0 0; padding: 0; }
.ld-results:not(:empty) { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 12px; background: var(--bg); }
.ld-words { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ld-count { margin: 12px 4px 0; color: var(--faint); font-size: 13px; }
.lw { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.ld-results .lw + .lw { border-top: 1px solid var(--border); }
.ld-words .lw, .fc-summary .lw { padding: 12px 14px; border-radius: var(--r-sm); background: var(--surface-2); }
.lw-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lw-top { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.lw-word { font-family: var(--zh-font); font-size: 26px; line-height: 1.25; font-weight: 500; }
.lw-speak { width: 30px; height: 30px; }
.lw-sub { display: flex; align-items: baseline; gap: 4px 12px; min-width: 0; }
.lw-py { font-size: 15px; white-space: nowrap; }
.lw-py .t1, .lw-py .t2, .lw-py .t3, .lw-py .t4, .lw-py .t5 { font-weight: 500; }
.lw-def { color: var(--accent); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lw > details.menu { align-self: flex-start; }

/* ---------- My texts ---------- */
.texts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tx { display: flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: var(--r-md); padding-right: 8px; background: var(--surface); }
.tx:hover { border-color: var(--border-strong); }
.tx-open {
  display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; padding: 14px 16px; text-align: left;
  background: none; border: none; cursor: pointer; color: var(--text); border-radius: var(--r-md);
}
.tx-icon { display: inline-flex; padding: 10px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.tx-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tx-title { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.tx-preview { font-family: var(--zh-font); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 13px; color: var(--faint); }
.reads-tabs .count { margin-left: 4px; color: var(--faint); font-weight: 500; font-size: 13px; }
.bk-cover {
  flex-shrink: 0; width: 44px; height: 62px; border-radius: 6px; overflow: hidden; display: inline-flex;
  align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent);
  box-shadow: 0 0 0 1px var(--border);
}
.bk-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bk-error { margin: 4px 0 0; font-size: 13px; }
.tx-open.loading { cursor: progress; }
.tx-open.loading .tx-icon, .tx-open.loading .bk-cover { position: relative; }
.tx-open.loading .tx-icon::after, .tx-open.loading .bk-cover::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
  background: transparent;
}
.tx-open.loading .bk-cover img, .tx-open.loading .bk-cover .icon, .tx-open.loading .tx-icon .icon { opacity: 0.25; }

/* ---------- Shared lists ---------- */
.lists-tabs .count { margin-left: 4px; color: var(--faint); font-weight: 500; font-size: 13px; }
.shared-levels { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.level-chip {
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border-strong); color: var(--muted); background: var(--surface);
}
.level-chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.shared-count { margin: 0 0 4px; }
.shared-theme { margin: 20px 0 8px; font-size: 13px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.shared-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.shared-card { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.shared-card:hover, .shared-card.open { border-color: var(--border-strong); }
.shared-head {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 12px 14px; text-align: left;
  background: none; border: none; cursor: pointer; color: var(--text); border-radius: var(--r-md);
}
.shared-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.shared-name { font-weight: 700; font-size: 16px; }
.shared-mine { display: inline-flex; align-items: center; gap: 2px; margin-left: 6px; color: var(--success); font-size: 12px; font-weight: 600; vertical-align: 1px; }
.shared-desc { color: var(--muted); font-size: 14px; }
.shared-preview { font-family: var(--zh-font); color: var(--faint); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shared-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.shared-count-words { color: var(--faint); font-size: 13px; white-space: nowrap; }
.shared-detail { padding: 0 10px 10px; }
.shared-detail .ld-words { gap: 6px; }
.shared-detail .lw { padding: 8px 12px; }
.shared-detail .lw-word { font-size: 22px; }
.shared-none { padding: 12px 0; }

/* A short message at the bottom of the screen */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h, 0px) + 20px); transform: translateX(-50%); z-index: 30;
  width: max-content; max-width: min(460px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- Dictionary ---------- */
.dict-search {
  display: flex; align-items: center; gap: 10px; padding: 0 14px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
}
.dict-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dict-search .icon { color: var(--faint); flex-shrink: 0; }
.dict-search input { flex: 1; min-width: 0; border: none; background: none; box-shadow: none; outline: none; padding: 12px 0; font-size: 18px; }
.dict-search input:focus { box-shadow: none; }
.dict-results, .dict-recent { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dict-results { margin-bottom: 8px; }
.dict-row {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 14px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); color: var(--text);
}
.dict-row:hover { border-color: var(--border-strong); }
.dict-zh { font-family: var(--zh-font); font-size: 24px; line-height: 1.2; white-space: nowrap; }
.dict-body { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.dict-py { font-size: 14px; font-weight: 600; }
.dict-def { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dict-row .badge { flex-shrink: 0; }
.dict-entry {
  padding: 16px 18px; margin-bottom: 8px; font-size: 15px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.dict-entry .popup-word { font-size: 44px; }
.dict-back { display: inline-flex; align-items: center; gap: 2px; margin-bottom: 8px; font-size: 14px; }
.dict-entry .char-row .zh { cursor: pointer; color: var(--accent); }
.dict-entry .char-row .zh:hover { text-decoration: underline; }
.dict-recent-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 8px; }
.dict-recent-head h3 { margin: 0; font-size: 13px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.dict-recent .dict-zh { font-size: 20px; }
.dict-recent .dict-row { padding: 8px 14px; }
.dict-none { padding: 4px 0; }

/* ---------- Flashcards ---------- */
.cards-tabs { margin-bottom: 20px; }

/* Cards: one line with today's goal (opens Progress) */
.today-strip {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 16px; padding: 8px 14px 8px 8px; text-align: left;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: 14px;
}
.today-strip:hover { border-color: var(--border-strong); }
.today-strip > span { flex: 1; display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.today-strip b { color: var(--text); }
.today-strip .icon { color: #e8590c; }
.today-strip > .icon:last-child { color: var(--faint); }
.today-strip .ring circle { stroke-width: 9; }

/* Today: daily goal ring, streak and quests */
.today {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px 20px; margin-bottom: 20px; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
}
.today-goal { display: flex; align-items: center; gap: 14px; }
.today-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.today-text .hint { margin: 0; font-size: 13px; }
.today-streak { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 14px; }
.today-streak.done { color: #e8590c; }
.today-goal-pick { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.today-goal-pick select { min-height: 30px; padding: 2px 8px; font-size: 13px; }
.ring { flex-shrink: 0; }
.ring circle { fill: none; stroke-width: 7; }
.ring-track { stroke: var(--surface-2); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 300ms; }
.ring text { fill: var(--text); font-size: 15px; font-weight: 700; font-family: var(--ui-font); }
.quests { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; align-self: center; }
.quest { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.quest-check { display: inline-flex; color: var(--faint); }
.quest.complete .quest-check { color: var(--success); }
.quest-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.quest.complete .quest-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border-strong); }
.quest-bar, .mode-bar { display: block; height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.quest-bar span, .mode-bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.quest.complete .quest-bar span { background: var(--success); }
.quest-count { color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Progress: the month */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav h3 { margin: 0; font-size: 18px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; width: 100%; max-width: 420px; margin: 0 auto; }
.cal-head { text-align: center; font-size: 12px; color: var(--faint); font-weight: 600; }
.cal-day {
  aspect-ratio: 1; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px;
  font-size: 13px; color: var(--muted); background: var(--surface-2); font-variant-numeric: tabular-nums;
}
.cal-day.l1 { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); color: var(--text); }
.cal-day.l2 { background: color-mix(in srgb, var(--accent) 60%, var(--surface)); color: #fff; font-weight: 600; }
.cal-day.l3 { background: var(--accent); color: #fff; font-weight: 700; }
.cal-day.rest { background: var(--surface); outline: 1.5px dashed color-mix(in srgb, #e8590c 60%, var(--border)); outline-offset: -1.5px; }
.cal-day.is-today { box-shadow: 0 0 0 2px var(--text); }
.cal-day.future { opacity: 0.45; }
.cal-legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; margin: 10px 0 18px; font-size: 12px; }
.cal-legend .cal-day { width: 14px; height: 14px; border-radius: 4px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--border);
}
.stat-value { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat.small .stat-value { font-size: 20px; }
.stat-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 5px; }
.stat-change { color: var(--faint); font-size: 12px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--accent); }
.progress-h { margin: 22px 0 8px; font-size: 13px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.mode-stats, .hsk-cover { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mode-stats li, .hsk-level > summary, .hsk-skills li {
  display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 4px 10px; font-size: 14px;
}
.hsk-cover { gap: 6px; }
.hsk-note { margin: -2px 0 10px; font-size: 13px; }
.hsk-level { border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); }
.hsk-level[open] { border-color: var(--border-strong); }
.hsk-level > summary { padding: 10px 12px; cursor: pointer; list-style: none; }
.hsk-level > summary::-webkit-details-marker { display: none; }
.hsk-level > summary .mode-name::after { content: "›"; margin-left: 2px; color: var(--faint); transition: transform 120ms; }
.hsk-level[open] > summary .mode-name::after { transform: rotate(90deg); }
.hsk-upto, .hsk-what { grid-column: 2 / -1; color: var(--faint); font-size: 12px; margin-top: -2px; }
.hsk-skills { list-style: none; margin: 0; padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); }
.hsk-skills li { padding-top: 6px; }
.hsk-skills .mode-name { font-weight: 500; }
.hsk-skills .mode-bar span { background: var(--accent); }
.mode-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.mode-num { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.hsk-cover .mode-bar span { background: var(--success); }
.known-skills { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.recap .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 12px 0; text-align: left; }
@media (max-width: 600px) {
  .today { grid-template-columns: 1fr; padding: 14px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .known-skills { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode-stats li, .hsk-level > summary, .hsk-skills li { grid-template-columns: 112px 1fr auto; }
  .streak-btn { padding: 6px 10px 6px 8px; }
}
.cards-setup fieldset { border: none; margin: 0 0 20px; padding: 0; }
.cards-setup legend { font-weight: 700; font-size: 16px; margin-bottom: 8px; padding: 0; }
.check {
  display: flex; align-items: baseline; gap: 10px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface);
}
.check:hover { border-color: var(--border-strong); }
.check:has(input:checked) { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: var(--accent-soft); }
.check .count { margin-left: 2px; color: var(--muted); }
.cards-setup .actions { justify-content: flex-start; }
.fc-progress { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; color: var(--muted); font-size: 14px; }
.fc-progress .fc-end { margin-left: auto; }
.fc-ok { color: var(--success); font-weight: 600; }
.fc-bad { color: var(--accent); font-weight: 600; }
.fc-bar { height: 4px; background: var(--surface-2); border-radius: 999px; margin: 10px 0 20px; overflow: hidden; }
.fc-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 200ms; }
.flashcard {
  min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 32px 24px; text-align: center; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow-sm), 0 8px 24px rgba(40, 30, 20, 0.06); outline: none;
  transition: transform 180ms ease-out, border-color 120ms, box-shadow 120ms;
}
.flashcard.swipe-yes { border-color: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.flashcard.swipe-no { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fc-meta { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 8px; }
.fc-label { color: var(--faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.fc-front, .fc-back { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.fc-back { padding-top: 16px; border-top: 1px solid var(--border); width: min(100%, 460px); }
.fc-zh { font-family: var(--zh-font); font-size: 72px; line-height: 1.2; font-weight: 500; }
.fc-py { font-size: 24px; }
.fc-meanings { margin: 0; padding: 0; list-style: none; font-size: 19px; }
.fc-meanings li + li { margin-top: 2px; color: var(--muted); font-size: 16px; }
.fc-speak { background: var(--surface-2); color: var(--text); }
.fc-listen .fc-speak {
  display: inline-flex; padding: 20px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent-soft); color: var(--accent);
}
.fc-actions { display: flex; justify-content: center; gap: 16px; margin-top: 20px; }
/* Writing cards: a square with guide lines (米字格) where the characters are written */
.fc-writing { gap: 10px; }
.fc-write-sound { display: flex; align-items: center; gap: 10px; }
.fc-write-sound .fc-py { font-size: 20px; }
.fc-slots { display: flex; gap: 6px; }
.fc-slot {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px dashed var(--border-strong); border-radius: 8px; font-family: var(--zh-font); font-size: 28px;
}
.fc-slot.current { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.fc-slot.done { border-style: solid; border-color: var(--border); }
.fc-slot.fixed { border: none; width: auto; }
.fc-write {
  position: relative; width: var(--write-size); height: var(--write-size);
  border: 1.5px solid var(--border-strong); border-radius: 10px; background: var(--surface);
}
.fc-grid { position: absolute; inset: 0; width: 100%; height: 100%; }
.fc-grid path { fill: none; stroke: var(--border); stroke-width: 0.4; stroke-dasharray: 2 1.5; }
.fc-writer { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.fc-writer svg { display: block; }
.fc-write-status { margin: 0; min-height: 1.4em; color: var(--muted); font-size: 14px; }
.fc-result { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 8px 0; font-weight: 600; }
.fc-result.ok { color: var(--success); }
.fc-result.bad { color: var(--accent); }
.fc-actions .fc-reveal { min-width: 200px; min-height: 48px; font-size: 16px; }
.fc-answer {
  display: inline-flex; align-items: center; gap: 8px; min-width: 150px; min-height: 52px; padding: 10px 20px;
  justify-content: center; border-radius: 14px; cursor: pointer; font-weight: 600; font-size: 15px;
  background: var(--surface); border: 1.5px solid currentColor;
}
.fc-no { color: var(--accent); }
.fc-no:hover { background: var(--accent-soft); }
.fc-yes { color: var(--success); }
.fc-yes:hover { background: var(--success-soft); }
.fc-keys { text-align: center; color: var(--faint); font-size: 13px; }
.fc-summary h3 { margin: 0 0 4px; font-size: 22px; }
.fc-summary .ld-words { margin-bottom: 8px; }
.fc-summary .actions { flex-wrap: wrap; justify-content: flex-start; margin-top: 20px; }
.app-settings fieldset { border: none; border-top: 1px solid var(--border); margin: 0; padding: 16px 0; }
.app-settings fieldset:first-child { border-top: none; padding-top: 0; }
.app-settings legend { font-weight: 700; font-size: 17px; padding: 0; margin-bottom: 6px; }
.app-settings .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.app-settings select { min-height: 34px; padding: 4px 10px; }
.app-settings .hint { margin: 4px 0; }
.tone-colors { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 6px 0 4px 26px; font-size: 14px; }
.tone-colors label { display: flex; align-items: center; gap: 6px; }
.tone-colors input:disabled { opacity: 0.4; }
.tone-sample { font-family: var(--zh-font); font-size: 26px; margin: 6px 0 6px 26px; }
.tone-sample .pinyin { font-family: var(--ui-font); font-size: 16px; margin-left: 12px; }

/* ---------- Export / import dialog ---------- */
.words-dialog { width: min(640px, calc(100vw - 24px)); max-height: min(86vh, 760px); }
.wd-form { display: flex; flex-direction: column; gap: 12px; padding: 20px 24px; max-height: min(86vh, 760px); }
.wd-form h2 { margin: 0; font-size: 20px; }
.wd-form .hint { margin: 0; }
.wd-form .actions { margin-top: 4px; }
.wd-paste { min-height: 180px; font-size: 18px; }
.wd-bar { display: flex; gap: 14px; }
.wd-list { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; min-height: 80px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.wd-item label { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.wd-item:last-child label { border-bottom: none; }
.wd-item input { flex-shrink: 0; width: 17px; height: 17px; }
.wd-item.in-list { opacity: 0.6; }
.wd-word { font-family: var(--zh-font); font-size: 22px; flex-shrink: 0; min-width: 2.2em; }
.wd-info { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.wd-count { color: var(--muted); font-size: 13px; }
.wd-target { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.wd-target select, .wd-target input { max-width: 100%; }
.wd-target input { flex: 1; min-width: 180px; }

/* ---------- Account ---------- */
.account { max-width: 560px; }
.account h3 { margin: 0 0 6px; }
.account-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.account-form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.account-form input { font-size: 16px; }
.sync-status { color: var(--muted); font-size: 14px; }
a.account-admin { text-decoration: none; }
.sync-status[data-status="saved"]::before { content: "✓ "; color: var(--success); }
.sync-status[data-status="error"], .sync-status[data-status="offline"] { color: var(--warning); }

/* Your plan */
.plan { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.plan h4 { margin: 20px 0 10px; font-size: 15px; }
.plan-status {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2);
}
.plan-status > .icon { flex-shrink: 0; color: var(--muted); margin-top: 2px; }
.plan-status div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.plan-status span { color: var(--muted); font-size: 14px; }
.plan-status.is-plus { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: var(--accent-soft); }
.plan-status.is-plus > .icon { color: var(--accent); }
.passes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 340px) { .passes { grid-template-columns: 1fr; } }
.pass {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
}
.pass.best { border-color: var(--accent); }
.pass-flag {
  position: absolute; top: -9px; right: 10px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--accent); color: var(--accent-text);
}
.pass-name { font-weight: 600; }
.pass-price { font-size: 22px; font-weight: 700; }
.pass-sub { font-size: 13px; color: var(--muted); flex: 1; }
.pass-buy { margin-top: 10px; align-self: flex-start; }
.plan-compare { margin-top: 16px; }
.plan-compare > summary { cursor: pointer; font-weight: 600; font-size: 15px; }
.plan-table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 13px; }
.plan-table th, .plan-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.plan-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.plan-table tbody th { font-weight: 500; color: var(--muted); }
.plan-table .current { background: var(--accent-soft); }
.plan-table thead .current { color: var(--accent); }

/* Past a level's limit: locked items and notes */
.plus-icon { background: var(--accent-soft); color: var(--accent); }
.rd-limit {
  margin: 1.5em 0 0.5em; padding: 14px 16px; border-radius: var(--r-md); background: var(--accent-soft);
  font-family: var(--ui-font, inherit); font-size: 15px; line-height: 1.5;
}
.rd-limit p { margin: 0 0 10px; }
.rd-limit p .icon { display: inline-block; vertical-align: -2px; margin-right: 4px; color: var(--accent); }
.book-preview { display: flex; align-items: flex-start; gap: 6px; margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.book-preview .icon { flex-shrink: 0; margin-top: 3px; }
.chapter.locked-ch { color: var(--faint); background: var(--surface-2); }
.chapter.locked-ch .ch-title { color: var(--muted); }
.tx.locked .tx-title, .tx.locked .tx-preview { color: var(--muted); }
.tx.locked .tx-icon { background: var(--surface-2); color: var(--faint); }
.tx.locked .bk-cover { opacity: 0.45; }
.tx-title .icon { display: inline-block; vertical-align: -1px; color: var(--faint); }
.list-card.locked { --list-color: var(--faint); opacity: 0.8; }
.list-card.locked .list-folder .icon { fill: none; }
.library-note { list-style: none; align-items: center; flex-wrap: wrap; }
.library-note span { flex: 1 1 220px; }
.library-note.over .icon { color: var(--warning); }
.empty .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.about { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.about h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.about h4 { margin: 16px 0 6px; font-size: 12px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.about p { margin: 0; }
.about ul { margin: 0; padding-left: 18px; }
.about li { margin: 3px 0; }
.about a { color: inherit; }

/* ---------- Phones and tablets ---------- */
/* The sections are in a bar at the bottom of the screen, icon above the label, as in mobile
   apps: on phones, and on touch screens up to tablet size. */
@media (max-width: 600px), (pointer: coarse) and (max-width: 1366px) {
  :root { --nav-h: calc(60px + env(safe-area-inset-bottom)); }
  body { padding-bottom: var(--nav-h); }
  .pager { bottom: var(--nav-h); }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0; justify-self: stretch; justify-content: center;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border: none; border-radius: 0;
    border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(40, 30, 20, 0.06);
  }
  .nav-btn {
    flex: 1 1 0; min-width: 0; max-width: 160px; flex-direction: column; gap: 3px; min-height: 52px; padding: 4px 2px;
    font-size: 11px; font-weight: 500; border-radius: 12px;
  }
  .nav-btn span:not(.count) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .nav-btn .icon { width: 24px; height: 24px; transition: transform 120ms; }
  .nav-btn:hover { background: none; }
  .nav-btn[aria-pressed="true"] { background: none; color: var(--accent); font-weight: 700; }
  .nav-btn[aria-pressed="true"] .icon { transform: translateY(-1px); }
  .nav-btn[aria-pressed="true"]::after {
    content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
  }
  .nav-btn { position: relative; }
  .nav-btn.locked { gap: 3px; }
  .nav-btn.locked::before { width: 22px; height: 22px; opacity: 0.6; }
  .nav-btn .count { display: none; }
  /* While typing, the keyboard needs the room. */
  body:has(input:focus, textarea:focus) { --nav-h: 0px; }
  body:has(input:focus, textarea:focus) .mainnav { display: none; }
}

@media (pointer: coarse) and (min-width: 601px) and (max-width: 1366px) {
  .nav-btn { font-size: 12.5px; }
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  .topbar { grid-template-columns: auto 1fr; padding: calc(14px + env(safe-area-inset-top)) 16px 12px; gap: 12px; }
  .brand { font-size: 22px; }
  .brand-icon { width: 36px; height: 36px; border-radius: 10px; }
  .top-actions { grid-column: 2; justify-self: end; }
  .panel { padding: 16px; border-radius: 14px; }
  .page-title { font-size: 23px; }
  .page-head { margin-bottom: 16px; }
  .icon-label .label { display: none; }
  .icon-label { padding: 0; width: 40px; }
  .saved-as { padding: 0; width: 40px; justify-content: center; }
  .saved-as .label { display: none; }
  .reader-bar { flex-wrap: nowrap; gap: 8px; }
  .reader-bar .segmented button { padding: 5px 10px; font-size: 14px; }
  .reader-actions { flex-wrap: nowrap; gap: 6px; }
  .reader-actions .icon-label, .reader-actions .saved-as { width: 36px; min-height: 36px; }
  /* The title form for saving a text gets a row of its own. */
  .reader-bar:has(.save-text-form), .reader-actions:has(.save-text-form) { flex-wrap: wrap; }
  .reader-actions:has(.save-text-form) { flex: 1 1 100%; }
  .save-text:has(.save-text-form) { order: 5; flex: 1 1 100%; }
  .save-text .save-text-form { flex: 1; }
  .save-text .save-text-form input { flex: 1; width: auto; min-width: 0; }
  .display-menu .menu-panel { position: fixed; top: auto; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px); width: auto; z-index: 25; }
  :root { --reader-size: 22px; }
  /* On phones the page buttons are always on screen, at the bottom. */
  .pager {
    position: fixed; left: 0; right: 0; bottom: var(--nav-h); margin: 0; border-radius: 16px 16px 0 0;
    padding: 10px 12px;
    box-shadow: 0 -6px 20px rgba(40, 30, 20, 0.08);
  }
  .pager-btn { min-width: 0; flex: 0 1 120px; min-height: 52px; padding: 8px 10px; white-space: normal; line-height: 1.2; font-size: 14px; }
  .pager-mid { gap: 6px; }
  body.has-pager { padding-bottom: calc(var(--nav-h) + 76px); }
  .list-head { padding: 14px; gap: 12px; }
  .list-body { padding: 0 8px 8px; }
  .list-detail { padding: 10px; }
  .lw-sub { flex-direction: column; gap: 0; }
  .lw-def { white-space: normal; }
  .fc-zh { font-size: 56px; }
  .flashcard { min-height: 240px; padding: 24px 16px; }
  .fc-answer { min-width: 0; flex: 1; padding: 10px 12px; white-space: nowrap; }
  .tx-open { padding: 12px; gap: 12px; }
}
