/* ============ ReadWord v2 ============ */
/* Visual language: Readlang-like minimalism — flat, white, airy.
 * Content is the hero; chrome stays quiet. Every color flows through
 * the CSS variables below. `html[data-theme="warm"]` and
 * `html[data-theme="dark"]` override the default values; custom user
 * colors are applied as inline styles on <html> (inline always wins). */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --input-bg: #ffffff;
  --text: #1c2330;
  --muted: #6b7484;
  --border: #e8ebf0;
  --accent: #2f6fed;
  --accent-soft: #e8effe;
  --accent-hover: #265fd4;
  --on-accent: #ffffff;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --danger-border: #f3c2c2;
  --danger-hover: #bd3a3a;
  --on-danger: #ffffff;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --ok-border: #bfe6cd;
  --badge-bg: #f2f4f8;
  --badge-text: #5b6474;
  --auto-bg: #fff4d6;
  --auto-text: #8a6d00;
  --invert-bg: #1c2330;
  --invert-text: #ffffff;
  --radius: 10px;
  --shadow: none;
  --maxw: 780px;
  --hl1: #fff3c4;
  --hl2: #ffe08a;
  --hl3: #ffc94d;
}

/* Warm eye-care theme (Readlang-like cozy feel, matches gejoylab.com) */
html[data-theme="warm"] {
  --bg: #faf6ec;
  --surface: #fffdf6;
  --input-bg: #fffdf6;
  --text: #2b2b2b;
  --muted: #6b6257;
  --border: #e9e0cc;
  --accent: #2d6a4f;
  --accent-soft: #e3efe7;
  --accent-hover: #245c43;
  --on-accent: #ffffff;
  --danger: #c0504a;
  --danger-soft: #f9e9e4;
  --danger-border: #ecc9bd;
  --danger-hover: #a8433d;
  --on-danger: #ffffff;
  --ok: #4a8f5d;
  --ok-soft: #e9f3e4;
  --ok-border: #c4ddb6;
  --badge-bg: #f0e8d2;
  --badge-text: #6d6046;
  --auto-bg: #f7ecc8;
  --auto-text: #7c6410;
  --invert-bg: #3d3627;
  --invert-text: #fffdf6;
  --shadow: 0 1px 3px rgba(90, 70, 30, 0.10);
  --hl1: #fdf0c0;
  --hl2: #fbe08a;
  --hl3: #f7c948;
}

/* Dark theme (true dark, low contrast) */
html[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1e2126;
  --input-bg: #262a31;
  --text: #e2e6eb;
  --muted: #9aa2ad;
  --border: #33383f;
  --accent: #6ea8ff;
  --accent-soft: #22344f;
  --accent-hover: #5a94f0;
  --on-accent: #0f1420;
  --danger: #e0706a;
  --danger-soft: #3a2226;
  --danger-border: #5c3236;
  --danger-hover: #c85d57;
  --on-danger: #141014;
  --ok: #5fc98a;
  --ok-soft: #1d3327;
  --ok-border: #2f5240;
  --badge-bg: #2a2f36;
  --badge-text: #b9c0ca;
  --auto-bg: #3d3418;
  --auto-text: #e3c76a;
  --invert-bg: #e2e6eb;
  --invert-text: #14161a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  /* word highlights stay readable with light text on dark amber */
  --hl1: #57481c;
  --hl2: #6a5718;
  --hl3: #7d651a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Jost", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.screen { min-height: 100vh; }

/* hidden attribute must always win over display rules above/below */
[hidden] { display: none !important; }

/* ---------- login ---------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.5px; }
.login-card input { margin: 8px 0; }
.cefr-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}

/* ---------- layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 20px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.3px; white-space: nowrap; }
.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0;
  background: transparent;
  padding: 10px 4px;
  margin: 0 10px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { background: transparent; color: var(--text); }
.tabs button.active { background: transparent; color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }

.main { padding: 28px 20px 80px; }
.tab { display: none; }
.tab.active { display: block; }
.narrow { max-width: var(--maxw); margin: 0 auto; }

/* Readlang-style: sections are separated by whitespace, not boxes */
.card {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 4px 0;
  margin-bottom: 32px;
}
.card h2 { margin: 0 0 14px; font-size: 22px; font-weight: 700; letter-spacing: -0.2px; }
.card h3 { margin: 22px 0 10px; font-size: 16px; }
.card h3:first-child { margin-top: 0; }
.card h4 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); }

/* ---------- controls ---------- */
input[type="text"], input[type="password"], input:not([type]), textarea, select {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
textarea { min-height: 180px; resize: vertical; }
textarea.short { min-height: 90px; }
.block-input { display: block; margin-bottom: 10px; }
.grow { flex: 1; min-width: 0; }

.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--text); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; margin-top: 4px; }
.btn:disabled { opacity: 0.55; cursor: default; }

.row { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 14px;
}
.ok {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid var(--ok-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 14px;
}

.toggle { display: flex; gap: 10px; align-items: center; margin: 12px 0; cursor: pointer; }
.toggle input { width: auto; accent-color: var(--accent); }

/* ---------- reader ---------- */
.article {
  font-size: var(--reader-fs, 18px);
  line-height: 2;
  padding: 28px;
}
.article .w {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 2px;
  margin: 0 -2px;
}
.article .w:hover { background: var(--accent-soft); }
.article .w.hl1 { background: var(--hl1); }
.article .w.hl2 { background: var(--hl2); }
.article .w.hl3 { background: var(--hl3); font-weight: 600; }
.reader-toolbar { justify-content: space-between; }

/* ---------- audio reader (listen + follow-along transcript) ---------- */
.audio-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  margin-bottom: 12px;
}
.audio-bar audio { width: 100%; display: block; }
.seg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 7px 10px;
  border-radius: 8px;
  border-left: 3px solid transparent;
}
.seg.active { background: var(--accent-soft); border-left-color: var(--accent); }
.seg-time {
  flex: none;
  border: 0;
  background: none;
  padding: 5px 2px;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.seg-time:hover { text-decoration: underline; }
.seg-text { margin: 0; flex: 1; min-width: 0; }

/* import progress line under the YouTube row */
#import-yt-status { margin: 8px 0 0; }

/* ---------- lookup panel (desktop side panel / mobile bottom sheet) ---------- */
#panel-scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 40, 0.4);
  z-index: 60;
}
.lookup-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(440px, 100vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(20, 30, 60, 0.12);
  z-index: 70;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.panel-body { overflow-y: auto; padding: 16px; flex: 1; }
.lookup-word { font-size: 24px; font-weight: 700; margin: 0; }
.lookup-sub { color: var(--muted); font-size: 14px; margin: 2px 0 8px; }

.dict-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.dict-panel > .dp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}
/* chevron collapse toggle on the right of every dictionary panel header */
.dp-chevron {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.dp-chevron:hover { color: var(--text); background: var(--badge-bg); }
.source-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 2px 7px;
}
.dict-panel > .dp-body { padding: 12px 14px; font-size: 15px; }
.dp-body.collapsed { display: none; }
.dp-toggle { margin-left: auto; }

.sense { margin-bottom: 12px; }
.sense:last-child { margin-bottom: 0; }
.pos-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--badge-text);
  background: var(--badge-bg);
  border-radius: 4px;
  padding: 1px 8px;
  margin-right: 6px;
}
.example { color: var(--muted); font-style: italic; margin: 4px 0 4px 12px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip {
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
}
.chip.syn { background: var(--ok-soft); border-color: var(--ok-border); }
.chip.ant { background: var(--danger-soft); border-color: var(--danger-border); }

.trans-line { margin: 4px 0; }
.tag-chip {
  display: inline-block;
  font-size: 12px;
  background: var(--badge-bg);
  border-radius: 4px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  color: var(--badge-text);
}
.audio-badge {
  display: inline-block;
  font-size: 14px;
  margin-left: 6px;
  vertical-align: middle;
  cursor: default;
}
.forms-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
.forms-table td { border-bottom: 1px solid var(--border); padding: 4px 6px; }
.forms-table td:first-child { color: var(--muted); width: 45%; }

.audio-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  vertical-align: middle;
  margin-left: 6px;
}
.audio-btn:hover { background: var(--accent-soft); }

/* ---------- pronunciation ---------- */
.pron-block {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 8px 0 2px;
}
.ipa-chip {
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 9px;
  font-family: "Charis SIL", "Doulos SIL", "Segoe UI", sans-serif;
}
.hyphen {
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 1px;
}

/* clickable words inside lookup results */
[data-lookup-word] { cursor: pointer; }
[data-lookup-word]:hover { color: var(--accent); text-decoration: underline; }

/* ---------- screenshot-style dictionary view ---------- */
.dict-word { font-size: 30px; font-weight: 800; margin: 0; letter-spacing: 0.5px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* speaker after the word: plays the US pronunciation */
.word-audio {
  background: none; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; padding: 6px; border-radius: 8px; flex-shrink: 0;
}
.word-audio:hover { background: var(--accent-soft); }
/* ONE actions row: icon buttons + tips/forms mini-toggles, always one line */
.dh-actions-row {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: nowrap; overflow-x: auto;
  scrollbar-width: none; -ms-overflow-style: none;
  margin: 10px 0 2px; padding-bottom: 2px;
}
.dh-actions-row::-webkit-scrollbar { display: none; }
.dh-actions-row > * { flex-shrink: 0; }
.dh-actions-row .mini-toggle { margin-left: 2px; }
/* inflect note shown at the top of the expanded 时态/词形 section */
.dh-inflect-note { color: var(--muted); font-size: 13.5px; margin-bottom: 6px; }
.icon-btn {
  width: 34px; height: 34px; font-size: 16px; line-height: 1;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.icon-btn.done { color: #1a7a4c; border-color: #1a7a4c; background: #e8f7ef; }
.icon-btn.off { opacity: 0.4; }
html[data-theme="dark"] .icon-btn.done { background: #14301f; }
.dh-freq { font-size: 12.5px; color: var(--muted); margin-left: 2px; }
/* small inline toggle buttons (pron tips / word forms) */
.mini-toggle {
  display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
  font-size: 13px; color: var(--accent); white-space: nowrap;
  background: var(--accent-soft); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; cursor: pointer;
}
.mini-toggle:hover { border-color: var(--accent); }
.mini-toggle .chev { font-size: 10px; transition: transform 0.15s; }
.mini-toggle.open .chev { transform: rotate(90deg); }
.dh-inflect { font-size: 13.5px; color: var(--muted); margin: 4px 0; }
.dh-forms[hidden] { display: none; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 13px; padding: 2px 6px; border-radius: 6px; white-space: nowrap;
}
.link-btn:hover { background: var(--accent-soft); }
.dh-ipa-extra { margin-top: 2px; }
.dh-tips { margin: 6px 0 0; display: flex; flex-direction: column; gap: 4px; }
.dh-tips[hidden] { display: none; }
.dh-meta {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: nowrap; overflow-x: auto;
  scrollbar-width: none; -ms-overflow-style: none;
  margin: 6px 0 2px; padding-bottom: 2px; font-size: 14px;
}
.dh-meta::-webkit-scrollbar { display: none; }
.dh-meta > * { flex-shrink: 0; }
.dh-meta .pos-badge { font-size: 13px; }
.collins-stars { color: #e6a817; letter-spacing: 2px; font-size: 15px; }
.oxford-badge {
  font-size: 12px; font-weight: 700; color: #b45309;
  border: 1.5px solid #e6a817; border-radius: 4px; padding: 0 6px;
}
.cefr-badge { /* reused in reader stats too */
  font-size: 12px; font-weight: 700; color: #0f766e;
  border: 1.5px solid #0f766e; border-radius: 4px; padding: 0 6px;
}
.dh-ipa { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; margin: 8px 0 2px; }
.dh-ipa .ipa-text { min-width: 0; }
.ipa-tag { font-size: 12px; font-weight: 800; color: #c0392b; }
.ipa-text { font-size: 17px; color: #1d4ed8; }
html[data-theme="dark"] .ipa-text { color: #93c5fd; }
.pron-tip {
  font-size: 13px; line-height: 1.5; color: #6b4e12;
  background: #fef9e7; border: 1px solid #f0d878; border-radius: 6px;
  padding: 5px 9px;
}
html[data-theme="dark"] .pron-tip { background: #3a2f14; color: #fcd34d; border-color: #8a6d1f; }
.dh-inflect { font-size: 13.5px; color: var(--muted); margin: 4px 0; }
.dh-forms { font-size: 14px; margin: 6px 0; line-height: 1.9; }
.dh-forms .flabel { color: var(--muted); font-size: 13px; }
.dh-forms .fval { font-weight: 700; color: var(--text); }

/* numbered definitions grouped by part of speech */
.dict-pos-block { margin: 12px 0 4px; }
.dict-pos-head { font-size: 16px; font-weight: 700; margin: 10px 0 6px; }
.dict-def { display: flex; gap: 8px; margin: 7px 0; font-size: 15px; line-height: 1.55; }
.dict-def-num { font-weight: 800; flex-shrink: 0; min-width: 18px; }
.dict-def-body { flex: 1; }
.dict-zh { color: #2f6b4f; font-size: 14px; margin-top: 2px; }
html[data-theme="dark"] .dict-zh { color: #7fd6a4; }
.dict-ex { margin: 5px 0 5px 26px; font-size: 14px; }
.dict-ex::before { content: "• "; color: var(--muted); }
.dict-ex .ex-en { color: var(--text); }
.dict-group-zh {
  margin: 6px 0 4px 26px; font-size: 14.5px; color: #2f6b4f; font-weight: 600;
}
html[data-theme="dark"] .dict-group-zh { color: #7fd6a4; }
.dict-src-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* lookup head tag toggles */
.tag-toggle {
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 20px;
  padding: 3px 11px;
  cursor: pointer;
  color: var(--muted);
}
.tag-toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
/* icon-style tag toggles in the lookup head */
.icon-btn.tag-toggle { border-radius: 8px; padding: 0; font-size: 16px; color: var(--text); }
.icon-btn.tag-toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* desktop: the lookup drawer is a fixed overlay on the right — it never
 * pushes or re-scales the article, so line wraps / page counts stay put */
/* reader: always reserve the right-side word-panel space (desktop), from
 * article open to close, so the lookup drawer never shifts the text */
@media (min-width: 721px) {
  body.reader-open .main { margin-right: 440px; }
}

/* lookup count badges in reader */
.article .w sup.cnt {
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 2px;
  line-height: 1;
}

/* wordbook: word as button + notes */
.wb-word {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  font-family: inherit;
}
.wb-word:hover { color: var(--accent); text-decoration: underline; }
.wb-notes-snippet { font-size: 13px; color: var(--muted); font-style: italic; margin: 4px 0; }
.notes-editor { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.notes-editor textarea { min-height: 70px; margin-bottom: 8px; }

.panel-error { padding: 12px 14px; font-size: 14px; color: var(--muted); }
.inline-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- history (dictionary tab: recent lookups) ---------- */
.history { display: flex; flex-direction: column; margin-top: 12px; }
.history:empty { display: none; }
.hist-item {
  display: flex; align-items: center; gap: 16px;
  width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--border);
  padding: 14px 4px; cursor: pointer;
}
.hist-item:last-child { border-bottom: none; }
.hist-item:hover { background: var(--accent-soft); }
.hist-clock { font-size: 22px; color: var(--muted); flex-shrink: 0; }
.hist-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.hist-word { font-size: 20px; font-weight: 700; color: var(--text); }
.hist-snippet {
  font-size: 15px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-count {
  flex-shrink: 0; font-size: 13px; color: var(--muted);
  background: var(--surface); border-radius: 6px; padding: 5px 10px;
  white-space: nowrap;
}
/* new-word + sweet-spot badges on article rows */
.newwords-badge {
  font-size: 12px; color: var(--muted); background: var(--badge-bg);
  border-radius: 4px; padding: 2px 8px; white-space: nowrap;
}
.sweetspot-badge {
  font-size: 12px; color: var(--ok); background: var(--ok-soft);
  border-radius: 4px; padding: 2px 8px; font-weight: 700; white-space: nowrap;
}
/* streak banner */
#streak-banner { margin-bottom: 20px; }
.streak-line {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; padding: 4px 0;
}
.streak-fire { font-size: 18px; }
.streak-count { font-weight: 700; }
.streak-bar {
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--badge-bg); overflow: hidden; min-width: 60px;
}
.streak-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.streak-goal { color: var(--muted); font-size: 14px; white-space: nowrap; }
/* quiz overlay */
#quiz-overlay {
  position: fixed; inset: 0; z-index: 120;
  background: var(--bg); display: flex; justify-content: center;
  padding: 24px 16px; overflow-y: auto;
}
#quiz-overlay[hidden] { display: none; }
.quiz-box { width: 100%; max-width: 640px; }
.quiz-sentence {
  font-size: 19px; line-height: 1.7; margin: 24px 0;
  padding: 18px; background: var(--surface); border-radius: 10px;
}
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quiz-opt { padding: 12px; font-size: 16px; }
.quiz-opt.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.quiz-opt.wrong { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.quiz-opt:disabled { cursor: default; opacity: 1; }
.quiz-feedback { margin-top: 14px; font-size: 16px; }
.ok-text { color: var(--ok); font-weight: 700; }
.err-text { color: var(--danger); font-weight: 700; }
.quiz-result { text-align: center; margin-top: 40px; }
.quiz-score { font-size: 48px; font-weight: 800; margin-bottom: 8px; }
/* floating phrase-lookup button on text selection */
.sel-lookup-btn {
  position: fixed; z-index: 200; box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: sel-pop 0.15s ease-out;
}
@keyframes sel-pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.phrase-save { padding: 2px 8px; font-size: 14px; }
.phrase-save.saved { color: var(--ok); }
/* per-word personal notes at the bottom of the lookup panel */
#word-note-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.note-head { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.note-preview {
  white-space: pre-wrap; font-size: 15px; line-height: 1.6;
  background: var(--surface); border-radius: 8px; padding: 10px 12px;
}
#word-note-input {
  width: 100%; box-sizing: border-box; font-size: 15px; line-height: 1.6;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--bg); color: var(--text); resize: vertical;
}
#word-note-input:focus { outline: none; border-color: var(--accent); }

/* ---------- wordbook ---------- */
.filter-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-btns button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
}
.filter-btns button.active { background: var(--invert-bg); color: var(--invert-text); border-color: var(--invert-bg); }

/* settings accordion groups */
.settings-group { border: 1px solid var(--border); border-radius: var(--radius);
  margin: 8px 0; background: var(--surface); }
.settings-group > summary { cursor: pointer; padding: 12px 14px; font-weight: 600;
  font-size: 15px; list-style: none; display: flex; align-items: center; gap: 8px; }
.settings-group > summary::-webkit-details-marker { display: none; }
.settings-group > summary::before { content: '▸'; color: var(--muted); font-size: 12px;
  transition: transform 0.15s; }
.settings-group[open] > summary::before { transform: rotate(90deg); }
.settings-group > summary:hover { background: rgba(0,0,0,0.03); }
.settings-body { padding: 4px 14px 14px; border-top: 1px solid var(--border); }
.settings-body > :first-child { margin-top: 10px; }

/* fsrs review */
.fsrs-btns { gap: 6px; flex-wrap: wrap; }
.fsrs-btns .btn { min-width: 70px; }
.quiz-cloze { margin: 12px 0; padding: 12px; background: var(--surface);
  border: 1px dashed var(--border); border-radius: 8px; font-style: italic;
  line-height: 1.6; }
.cloze-blank { font-weight: 700; color: var(--accent); letter-spacing: 2px; }

/* stats */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat-box { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
#vocab-chart { margin: 12px 0; }
#vocab-chart svg { width: 100%; height: auto; display: block; }
#vocab-range { margin-bottom: 8px; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: none; }
.user-row .grow { flex: 1; }
.user-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--invert-bg); color: var(--invert-text); }
.import-subtab { margin-top: 12px; }
#news-ranges { margin-top: 8px; margin-bottom: 4px; }
#news-ranges button { font-size: 13px; padding: 5px 12px; }
#news-fallback-notice { margin: 8px 0; padding: 8px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; }

.wb-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.wb-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wb-word { font-size: 18px; font-weight: 700; margin: 0; }
.wb-preview { color: var(--muted); font-size: 14px; margin: 4px 0; }
.wb-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.src-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; border-radius: 4px; padding: 2px 7px; }
.src-badge.auto { background: var(--auto-bg); color: var(--auto-text); }
.src-badge.manual { background: var(--accent-soft); color: var(--accent); }
.src-badge.reader { background: var(--ok-soft); color: var(--ok); }
.wb-article { color: var(--muted); font-size: 13px; margin: 4px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count-badge { color: var(--muted); }
.wb-actions { margin-left: auto; display: flex; gap: 6px; }
.tag-editor { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.tag-editor label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.tag-editor input { width: auto; accent-color: var(--accent); }
.mastered-btn.on { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); font-weight: 600; }

/* ---------- review ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { font-size: 13px; color: var(--muted); }

.quiz-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  margin-top: 16px;
  background: var(--bg);
}
.quiz-word { font-size: 32px; font-weight: 700; margin: 8px 0; }
.quiz-answer { font-size: 16px; color: var(--muted); margin: 12px 0; min-height: 24px; }
.quiz-progress { font-size: 13px; color: var(--muted); }

/* ---------- library ---------- */
.lib-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--surface);
}
.lib-title { font-weight: 600; margin: 0 0 2px; }
.lib-meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.lib-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* reading progress: slim bar + percent */
.progress-wrap { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-pct { font-size: 12px; color: var(--muted); min-width: 38px; text-align: right; }

/* article is its own scroll container so reading progress can be tracked */
#article-body { max-height: calc(100vh - 260px); max-height: calc(100dvh - 260px); min-height: 300px; overflow-y: auto; }
/* Readlang-style fullscreen reader: the article spans the viewport width */
#reader-view.reader-full { max-width: none; }
/* reader is a full-height column; the pagebar pins to the viewport bottom */
#reader-view {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 90px);
  min-height: calc(100dvh - 90px);
}
#reader-view .pagebar {
  margin-top: auto;
  padding: 14px 0 18px;
}
/* paged (Readlang-style) mode: fixed-height viewport, pages slide via transform */
#article-body.paged {
  height: calc(100vh - 330px);
  height: calc(100dvh - 330px);
  min-height: 340px;
  max-height: none;
  overflow: hidden;
}
#article-pages { will-change: transform; }
.pagebar { justify-content: center; align-items: center; gap: 10px; margin-top: 10px; }
#page-indicator { min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }

/* document editor modal */
.editor-modal { max-width: 680px; }
.editor-modal h3 { margin: 0 0 12px; }
#editor-content { min-height: 280px; }
.import-block { border-top: 1px solid var(--border); padding-top: 6px; margin-top: 10px; }
.import-block:first-of-type { border-top: 0; margin-top: 0; }

/* ---------- settings ---------- */
.panel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--surface);
}
.panel-row .lbl { flex: 1; font-weight: 600; }
.panel-row input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.order-btns { display: flex; gap: 2px; }
.order-btns button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 14px;
}
.order-btns button:hover:not(:disabled) { background: var(--bg); }
.order-btns button:disabled { opacity: 0.35; cursor: default; }

/* uploaded-dictionary health warning (dict manager list) */
.dict-warning {
  margin: 6px 0;
  padding: 8px 10px;
  border: 1px solid #d97706;
  border-left: 4px solid #d97706;
  border-radius: 6px;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
  line-height: 1.45;
}
html[data-theme="dark"] .dict-warning,
html[data-theme="warm"] .dict-warning {
  background: #3a2b12;
  color: #fcd34d;
  border-color: #b45309;
}

/* ---------- home ---------- */
.spot-chip { cursor: pointer; font-size: 14px; padding: 5px 14px; font: inherit; color: var(--text); background: var(--bg); }
.spot-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- review (SRS) ---------- */
#srs-area { margin-top: 12px; }

/* ---------- import / collect ---------- */
#collect-results .lib-entry:last-child { margin-bottom: 0; }
#collect-results { margin-top: 12px; }

/* ---------- import / hot news ---------- */
#news-list { margin-top: 12px; }
#news-list .lib-entry:last-child { margin-bottom: 0; }
#news-topics { margin: 10px 0 4px; flex-wrap: wrap; }
.lib-title a { color: var(--text); text-decoration: none; }
.lib-title a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- settings: appearance ---------- */
.color-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
input[type="color"] {
  width: 44px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  cursor: pointer;
}
/* library group tabs sit above the search box */
#library-group-tabs { margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- toast & modal ---------- */
#toast-wrap {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--invert-bg);
  color: var(--invert-text);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: fadeup 0.2s ease-out;
}
.toast.err { background: var(--danger); }
@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } }

.modal-wrap {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 40, 0.45);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(20, 30, 60, 0.2);
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .main { padding: 14px 10px 90px; }
  .card { padding: 16px; }
  .article { padding: 18px 16px; font-size: 17px; }
  .topbar { padding: 8px 10px; }
  .brand { display: none; }

  /* lookup becomes a bottom sheet */
  .lookup-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 86vh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    animation: slideup 0.25s ease-out;
  }
  @keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } }

  #article-body { max-height: calc(100vh - 210px); max-height: calc(100dvh - 210px); min-height: 240px; }
  #editor-content { min-height: 40vh; }
}
