/* ============================================================
   Design tokens — single source of truth (spacing/type/radius/color)
   ============================================================ */
:root {
  /* spacing scale */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  /* type scale */
  --fs-xs: 12px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px;
  /* radius */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 999px;
  /* color */
  --accent: #0f766e;
  --accent-soft: #14b8a6;
  --ox: #0f766e; /* v91: was Oxford-crimson #b91c1c — slot 1 is WordNet now and a red panel head read as an error state (field report 2026-09-30) */
  --lm: #1d4ed8;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2937;
  --text-2: #646b78;
  --border: #e5e7eb;
  --shadow-1: 0 1px 3px rgba(0,0,0,.08);
  --shadow-2: 0 8px 24px rgba(0,0,0,.14);
  /* U8: ONE highlight convention. The exact word (reader tap / saved-context
     <mark>) is --hl-bg; the surrounding sentence is the softer --hl-soft. Before
     this, the same word was teal in the reader and amber in the context card. */
  --hl-bg: #fde68a;
  --hl-fg: #513c06;
  --hl-soft: #fef3c7;
  /* U3: a slot with no dictionary is a NEUTRAL state, never an error colour */
  --panel-muted: #475569;
  /* layout */
  --topbar-h: 52px;
  --touch: 44px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101317;
    --surface: #1a1e26;
    --text: #e7eaee;
    --text-2: #9aa3af;
    --border: #2b313c;
    --accent: #2dd4bf;
    --accent-soft: #0f766e;
    --shadow-1: 0 1px 3px rgba(0,0,0,.4);
    --shadow-2: 0 8px 24px rgba(0,0,0,.5);
    --hl-bg: #a16207;
    --hl-fg: #fffbeb;
    --hl-soft: #3f2d06;
    --panel-muted: #3f4a5a;
  }
}

/* ============================================================ base */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* R-E: ONE definition of the device's bottom inset. Anything that has to clear the
   fixed bottom nav reads --safe-b, so the nav's own height and the space reserved
   for it can never drift apart on a phone with a home indicator. Declared as a
   custom property (not env() inline) so the geometry stays testable: the ui-check
   pass overrides --safe-b to 34px and re-measures the clearance. */
:root { --safe-b: env(safe-area-inset-bottom, 0px); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: var(--fs-md);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================ topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sp-2) + env(safe-area-inset-top)) var(--sp-4) var(--sp-2);
  min-height: var(--topbar-h);
  background: var(--accent-soft);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: var(--sp-2); }
.brand img { border-radius: var(--r-sm); }
.brand h1 { font-size: var(--fs-lg); margin: 0; font-weight: 700; letter-spacing: -.01em; }
.brand .plus { opacity: .75; font-weight: 500; }
.topbar-actions { display: flex; gap: var(--sp-2); }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-full);
  border: 1px solid rgba(255,255,255,.45); background: rgba(255,255,255,.08);
  color: #fff; font-size: var(--fs-md); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.22); }

/* --- U11: header affordances --- */
/* The inline mark is a link (go to search): it must read as part of the bar, not
   as body text — the UA link colour/underline would otherwise leak through. */
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; text-decoration: none; border-radius: var(--r-sm);
}
.brand { min-width: 0; }
/* U11: the app title is one line on a phone. The two least-used controls (⚙/?)
   move into the ⋯ overflow menu (see .topbar-optional below) — the theme toggle
   stays in the bar — and the title itself truncates instead of wrapping if a
   translation is ever longer. */
.brand h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { flex: 0 0 auto; position: relative; }
/* Hover/focus tooltip for the icon-only controls: the text also exists as
   title (native tooltip + accessible name comes from aria-label). */
.icon-btn[data-tip] { position: relative; }
.icon-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 45;
  background: var(--text); color: var(--surface);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.3;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .12s ease;
}
.icon-btn[data-tip]:hover::after,
.icon-btn[data-tip]:focus-visible::after { opacity: 1; visibility: visible; }
@media (prefers-reduced-motion: reduce) { .icon-btn[data-tip]::after { transition: none; } }
/* the overflow menu itself (mobile) — a real dropdown, anchored under ⋯ */
.more-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 45;
  display: flex; flex-direction: column; gap: 2px; min-width: 186px;
  padding: var(--sp-1);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2);
}
.more-menu button {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: var(--touch); padding: 8px var(--sp-3);
  border: none; border-radius: var(--r-sm); background: transparent;
  color: var(--text); font-size: var(--fs-sm); font-weight: 600;
  text-align: left; cursor: pointer;
}
.more-menu button:hover,
.more-menu button:focus-visible { background: var(--bg); }

main { max-width: 1400px; margin: 0 auto; padding: 0 var(--sp-3) var(--sp-6); }

/* ============================================================ search */
.search-wrap {
  position: sticky; top: var(--topbar-h); z-index: 20;
  padding: var(--sp-3) 0 var(--sp-1);
  background: var(--bg);
}
.search-box {
  display: flex; align-items: center; gap: var(--sp-1);
  background: var(--surface);
  border: 1.5px solid var(--border); border-radius: var(--r-md);
  padding: 0 var(--sp-1) 0 var(--sp-3);
  box-shadow: var(--shadow-1);
  transition: border-color .15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-icon { color: var(--text-2); flex: 0 0 auto; }
#search-input {
  flex: 1; min-width: 0;
  font-size: var(--fs-md); padding: var(--sp-3) var(--sp-1);
  border: none; background: transparent; color: var(--text);
  outline: none;
}
#search-input::placeholder { color: var(--text-2); }
#search-input::-webkit-search-cancel-button { display: none; }
.btn-clear {
  width: 32px; height: 32px; border: none; border-radius: var(--r-full);
  background: var(--bg); color: var(--text-2); font-size: var(--fs-md);
  cursor: pointer; flex: 0 0 auto;
}
.btn-search {
  height: 40px; padding: 0 var(--sp-4);
  border: none; border-radius: var(--r-sm);
  background: var(--accent); color: #fff; cursor: pointer;
  font-weight: 600;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-search { color: #06251f; } }

.icon-inline {
  width: 32px; height: 32px; flex: 0 0 auto;
  border: none; border-radius: var(--r-full);
  background: transparent; color: var(--text-2);
  font-size: var(--fs-md); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-inline:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.icon-inline:disabled { opacity: .4; cursor: default; }
.icon-inline.is-saved { color: #d97706; }

/* ============================================================ topbar vocab badge */
.badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: var(--r-full); background: #dc2626; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
#btn-vocab { position: relative; }

/* ============================================================ storage banner */
.storage-banner {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-top: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: #fef3c7; color: #78350f;
  border: 1px solid #fcd34d; border-radius: var(--r-md);
  font-size: var(--fs-sm); line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .storage-banner { background: #451a03; color: #fde68a; border-color: #92400e; }
}
.storage-banner span:first-child { flex: 1; }
.storage-banner button {
  flex: 0 0 auto; border: none; background: transparent; color: inherit;
  font-size: var(--fs-lg); line-height: 1; cursor: pointer; padding: var(--sp-1);
}

/* ============================================================ saved words / SRS list */
#vocab-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-3); }
.vocab-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.vocab-word {
  border: none; background: transparent; color: var(--accent);
  font-weight: 700; font-size: var(--fs-sm); cursor: pointer; padding: 0;
}
.vocab-meta { font-size: var(--fs-xs); color: var(--text-2); flex: 0 0 auto; }
.vocab-gloss {
  flex: 1; min-width: 140px;
  font-size: var(--fs-xs); color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#vocab-export { margin-top: var(--sp-3); }
#sentences-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-2); }
.sentence-row {
  display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); align-items: baseline;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.sentence-text { margin: 0; flex: 1; min-width: 200px; font-size: var(--fs-sm); }
.sentence-word { border: none; background: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; }
.sentence-meta { font-size: var(--fs-xs); color: var(--text-2); }

/* ---------------- reader ---------------- */
.reader { margin-top: var(--sp-4); }
.reader-toolbar { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-2); }
.reader-input-wrap { display: flex; flex-direction: column; gap: var(--sp-2); }
#reader-input {
  width: 100%; resize: vertical; font: inherit;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
}
.reader-url-row { display: flex; gap: var(--sp-2); }
.reader-url-row input {
  flex: 1; padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
}
.reader-msg { font-size: var(--fs-xs); color: var(--text-2); margin: 0; }
/* v74: live reading pace — elapsed / words / wpm, driven by the reader timer */
.reader-timer { white-space: nowrap; font-variant-numeric: tabular-nums; align-self: center; margin-left: auto; }
/* v75: writing journal — editor + count + Task 2 countdown + saved entries */
.journal-panel textarea {
  width: 100%; box-sizing: border-box; resize: vertical; font: inherit;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
}
.journal-bar { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-2); }
.journal-bar .journal-actions { margin-left: auto; display: inline-flex; gap: var(--sp-2); }
#journal-count.journal-ok { color: var(--accent); font-weight: 600; }
.journal-timer { font-variant-numeric: tabular-nums; }
.journal-list { margin-top: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.journal-entry { position: relative; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.journal-entry .journal-meta { margin: 0 0 var(--sp-1); }
.journal-entry .journal-text { margin: 0; white-space: pre-wrap; }
.journal-entry .journal-del { position: absolute; top: var(--sp-2); right: var(--sp-2); min-width: 44px; min-height: 44px; }
/* v76: cue card in Practice */
.cue-card { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); padding: var(--sp-3); margin: var(--sp-3) 0; }
.cue-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.cue-prompt { font-size: var(--fs-md); margin: var(--sp-2) 0; }
.cue-bar { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.cue-bar .cue-actions { margin-left: auto; display: inline-flex; gap: var(--sp-2); }
#cue-clock { font-variant-numeric: tabular-nums; }
/* v78: the quiet EN–VI suggestion above the panels (slot 3 empty, not dismissed) */
.envi-hint {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  margin: var(--sp-3) 0 0; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text-2);
  font-size: var(--fs-sm);
}
.envi-hint .icon-inline { margin-left: auto; }
/* v77: listening — synced cue lines; the playing line follows along */
#listen-dialog textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; padding: var(--sp-2) var(--sp-3); margin: var(--sp-2) 0 0; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text); }
#listen-dialog .btn-primary { margin-top: var(--sp-3); }
#listen-audio { margin-bottom: var(--sp-3); }
.listen-cue { cursor: pointer; }
.listen-cue.listen-active { color: var(--accent); font-weight: 600; }
/* v73: the Advanced dialog's three tabs — same segmented-control pattern as the
   mobile view-switch (accent fill on the active tab; the dark-mode repainted
   accents need the near-black label, see the .btn-search note above). */
.adv-tabs {
  display: flex; gap: 3px; margin-top: var(--sp-3);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 3px;
}
.adv-tab {
  flex: 1; min-height: 44px; border: none; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2);
  font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}
.adv-tab[aria-selected="true"] { background: var(--accent); color: #fff; }
.adv-panel { margin-top: var(--sp-3); }
.adv-panel[hidden] { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .adv-tab[aria-selected="true"] { color: #06251f; } }
:root[data-theme="dark"] .adv-tab[aria-selected="true"] { color: #06251f; }
/* Phase 7 P1: the YouTube transcript dialog reuses the Reader's field styling */
#yt-dialog input[type="url"], #yt-dialog textarea {
  width: 100%; box-sizing: border-box; font: inherit;
  padding: var(--sp-2) var(--sp-3); margin: var(--sp-2) 0 0;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  resize: vertical;
}
#yt-dialog .btn-primary { margin-top: var(--sp-3); }
.reader-text {
  max-width: 44rem; margin: 0 auto;
  font-size: 1.05rem; line-height: 1.85; color: var(--text);
}
.reader-text p { margin: 0 0 1em; }
/* U8: the reader tap and the saved-context mark use the same highlight pair —
   exact word = --hl-bg, its sentence = --hl-soft. */
.rw { cursor: pointer; border-radius: 3px; }
.rw:hover { background: var(--hl-soft); }
.rw.sel { background: var(--hl-bg); color: var(--hl-fg); }
.reader-text p.sel-para { background: var(--hl-soft); box-shadow: 0 0 0 10px var(--hl-soft); border-radius: 8px; }

/* ---------------- toast feedback ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  z-index: 60; display: flex; align-items: center; gap: 12px;
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: var(--fs-sm); box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: min(92vw, 480px);
  /* U16: a toast that happens to sit over content must never swallow a tap
     aimed at the page beneath it — only its own Undo button stays clickable. */
  pointer-events: none;
}
.toast-undo { pointer-events: auto; }
.toast-undo { border: none; background: transparent; color: #5eead4; font-weight: 700; cursor: pointer; padding: 0; font-size: var(--fs-sm); }

/* BMC: fade while scrolling — never sits over content being read */
.bmc-btn-container { transition: opacity .25s ease; }
.bmc-btn-container.bmc-fade { opacity: .06; pointer-events: none; }
.envi-row { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.envi-row .hint { margin: var(--sp-1) 0 0; }
.hist-clear {
  margin-left: auto; border: none; background: none; cursor: pointer;
  color: var(--text-2); font-size: var(--fs-xs); padding: 4px 8px; border-radius: 6px;
}
.hist-clear:hover { color: #dc2626; }
.vocab-actions { display: flex; gap: var(--sp-1); flex: 0 0 auto; }
.vocab-actions button {
  min-height: 30px; padding: 0 var(--sp-2); border-radius: var(--r-sm);
  font-size: var(--fs-xs); cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.vocab-actions button:disabled { opacity: .4; cursor: default; }
.btn-vocab-ok:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-vocab-bad:not(:disabled) { border-color: #dc2626; color: #dc2626; }
.btn-vocab-del { color: var(--text-2); }

.suggestions {
  position: absolute; left: 0; right: 0; margin-top: var(--sp-1);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden;
  box-shadow: var(--shadow-2);
}
.suggestions div {
  padding: var(--sp-3) var(--sp-4); cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.suggestions div:last-child { border-bottom: none; }
.suggestions div:hover, .suggestions div.active { background: var(--bg); }
.suggestions .sug-more {
  color: var(--accent); font-weight: 600; font-size: var(--fs-sm);
  text-align: center;
}

/* ============================================================ history */
.history { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) 0 0; flex-wrap: wrap; }
.hist-label { font-size: var(--fs-xs); color: var(--text-2); }
#history-chips { display: flex; gap: var(--sp-1); flex-wrap: wrap; }
#history-chips button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--r-full); padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-xs); cursor: pointer; min-height: 28px;
}
#history-chips button:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================ dictionary tab switch */
/* v97: the tabs pick the ONE dictionary to show, on every screen size — the
   stacked "Both" view (and the desktop side-by-side grid) is gone. One flex
   row of equal segments, centered and reading-width on desktop, full-width on
   mobile (media query below). */
.view-switch {
  display: flex; gap: 3px; padding: 3px;
  margin: var(--sp-3) auto 0; max-width: 480px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.view-switch button {
  flex: 1 1 0; min-width: 0;
  padding: var(--sp-2) var(--sp-1); min-height: 38px;
  border: none; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2);
  cursor: pointer; font-size: var(--fs-sm); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.view-switch button.active { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .view-switch button.active { color: #06251f; } }

/* ============================================================ dict panels */
.dict-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-3); margin-top: var(--sp-3); }
.dict-panel.collapsed { display: none; }
@media (min-width: 900px) {
  /* a single active panel in a reading-width column (matches .reader-text) */
  .dict-grid { max-width: 44rem; margin-left: auto; margin-right: auto; align-items: start; }
}
@media (max-width: 899.5px) {
  .view-switch { margin-left: 0; margin-right: 0; max-width: none; }

  .dict-panel { max-height: 78vh; display: flex; flex-direction: column; }
  .dict-panel .entry-frame { overflow-y: auto; }

  /* Touch targets: minimum 44×44px on touch/mobile layouts */
  .icon-btn { width: 44px; height: 44px; }
  .icon-inline, .btn-clear { width: 44px; height: 44px; }
  .btn-search { height: 44px; }
  #search-input { padding: var(--sp-2) var(--sp-1); }
  .view-switch button { min-height: 44px; }
  /* v67 R2: due-banner controls + the onboarding reminders link ride the same floor */
  .due-banner button, .due-banner-cta { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .linklike { min-height: 44px; display: inline-flex; align-items: center; }
  .reminders-row { min-height: 44px; }

  /* U5/U11: name + licence chip + status + toggle do not fit one 390px row, and
     squeezing them wrapped a two-word name ("WordNet / 3.1"). The name takes the
     first row, the attribution and the status share the second. */
  .panel-head { flex-wrap: wrap; row-gap: 2px; }
  .dict-name { flex: 1 1 auto; -webkit-line-clamp: 1; }
  .dict-status { flex: 1 1 auto; text-align: left; }
}

.dict-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden;
  box-shadow: var(--shadow-1);
}
.panel-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3);
  color: #fff; font-weight: 600; font-size: var(--fs-sm);
}
.oxford-head { background: var(--ox); }
.longman-head { background: var(--lm); }
/* U3: a slot with no dictionary is a NEUTRAL state, not an error — one grey
   treatment for both panels (the per-slot accent returns the moment a dictionary
   is really in the slot, i.e. .has-dict). */
.dict-panel:not(.has-dict) .panel-head { background: var(--panel-muted); }
/* U5: the licence chip. One short line per source — the dictionary NAME stays in
   .dict-name (never licence text), the full wording lives in the chip's tooltip
   and NOTICE.md. */
.dict-lic {
  flex: 0 0 auto;
  /* ITEM B: WCAG 2.5.8 "Target Size (Minimum)" is AA at 24×24 and applies to this
     attribution link at EVERY width, so the floor lives on the chip itself instead
     of in the mobile-only touch block. Measured before: 108.2×20.5 (11px × 1.5
     line-height + 2px padding + 2px border). inline-flex only centres the label in
     the taller box — as a flex item of .panel-head the chip keeps its layout role
     (flex: 0 0 auto, nowrap), and the head is already ≥44px tall so nothing reflows. */
  display: inline-flex; align-items: center;
  min-height: 24px; min-width: 24px;
  font-size: 11px; font-weight: 600; line-height: 1.5;
  color: #fff; text-decoration: none; white-space: nowrap;
  padding: 1px 8px; border-radius: var(--r-full);
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.32);
}
.dict-lic:hover, .dict-lic:focus-visible { background: rgba(255,255,255,.32); color: #fff; }
.dict-lic[hidden] { display: none; }
.dict-name {
  flex: 0 1 auto; min-width: 0;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  white-space: normal; overflow: hidden;
  cursor: help; /* full name + source file shown in tooltip; never collapsed to one unreadable word */
}
.dict-status {
  flex: 1 0 auto; font-size: var(--fs-sm); font-weight: 500; opacity: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: right;
  text-shadow: 0 1px 2px rgba(0,0,0,.4); /* legibility on the red/blue headers */
}
.dict-status.loading::after {
  content: ""; display: inline-block; width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; margin-left: 6px; vertical-align: -2px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.panel-toggle, .panel-remove {
  background: transparent; border: none; color: #fff;
  font-size: var(--fs-md); cursor: pointer; padding: var(--sp-1) var(--sp-2);
}
.panel-remove { font-size: var(--fs-sm); opacity: .85; }
.panel-remove:hover { opacity: 1; }

.panel-loader { padding: var(--sp-3); }
.file-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.file-btn {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3); min-height: var(--touch);
  border: 1.5px dashed var(--text-2); border-radius: var(--r-md);
  cursor: pointer; font-size: var(--fs-sm); color: var(--text);
  transition: border-color .15s;
}
.file-btn:hover { border-color: var(--accent); color: var(--accent); }
.file-btn small { color: var(--text-2); }
.hint { font-size: var(--fs-xs); color: var(--text-2); margin: var(--sp-2) 0 0; line-height: 1.5; }

/* Entry content always renders as "paper" (light background, dark text) —
   MDX entries are authored for light backgrounds, so readability is guaranteed
   in both light and dark app themes. */
.entry-frame iframe {
  width: 100%; border: none; display: block;
  min-height: 280px; height: 55vh;
  background: #fff;
  transition: height .12s ease-out;
}

/* ============================================================ full-screen reading view */
body.reading-mode .about,
body.reading-mode .foot,
body.reading-mode .history,
body.reading-mode .storage-banner { display: none; }
body.reading-mode .dict-grid { grid-template-columns: 1fr; }
body.reading-mode .dict-panel { display: none; }
/* Must stay a vertical stack: the panel was block-level in desktop view, and a
   bare `display:flex` here laid head and frame out side-by-side (the "narrow
   strip" bug). */
body.reading-mode .dict-panel.reading {
  display: flex;
  flex-direction: column;
  max-height: none;
  width: 100%;
}
body.reading-mode .dict-panel.reading .entry-frame { overflow-y: visible; width: 100%; }
body.reading-mode .dict-panel.reading .entry-frame iframe { height: calc(100vh - 140px); }

/* ============================================================ empty state */
.empty-state {
  margin-top: var(--sp-5); text-align: center;
  color: var(--text-2); font-size: var(--fs-sm); line-height: 1.7;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
}
/* U3: with the panel grid hidden while nothing is loaded, this card is the page —
   it no longer needs 80vh of reserved space below it. (v70: the old
   `min-height: 0` override here lost to the 24rem rule and re-won after boot,
   flipping the card's height twice per visit — the reserve is gone entirely,
   see the note by #first-load-sizes.) */
/* U3: the lookup surface's own "not ready yet" line. The field stays editable
   (typing while a download runs is legitimate) but the surface is presented as
   inactive and the button announces itself as not-enabled. */
.gate-note {
  margin: var(--sp-2) 0 0; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text-2);
  font-size: var(--fs-sm); line-height: 1.5;
  /* CLS: two lines of text; border-box means the 8px paddings and 1px borders
     eat into min-height, so they must be added back or the two-line gate text
     still grows the box. */
  min-height: calc(3em + 18px);
}
.search-box-idle { border-style: dashed; border-color: var(--text-2); background: transparent; }
.search-box-idle #search-input { color: var(--text-2); }
/* R-A: the not-ready Search button must not LOOK like a live primary action.
   It used to be the accent fill at .55 opacity — still a saturated button, and the
   wash dropped its white label to ~2.4:1 (under AA). It is now a muted ghost that
   matches the dormant field: no fill, the same dashed --text-2 rule the input
   uses, label in --text-2 (4.9:1 light / 7.3:1 dark — AA for small text).
   Deliberately NOT `disabled`: the code keeps Enter-to-submit and the "/" shortcut
   alive while no dictionary is loaded, and a real disabled attribute would kill
   both. `cursor: not-allowed` + aria-disabled carry the "not now" message.
   Scoped through #search-form on purpose. The dark-mode overrides that repaint
   accent fills with the near-black label (#06251f) are `:root[data-theme="dark"]
   .btn-search` — three class-level selectors, so a plain `.search-box-idle
   .btn-search` (two) loses and the muted label goes near-black on a near-black
   field, i.e. invisible. One ID settles it without !important and without
   duplicating the rule per theme. */
#search-form .search-box-idle .btn-search {
  background: transparent; color: var(--text-2);
  border: 1px dashed var(--text-2); opacity: 1; cursor: not-allowed;
}
/* U3: with no dictionary there is no lookup surface to show — the download card
   is the one coherent state (and no "results continue below" cue pointing at an
   empty grid on mobile). */
/* CLS (v70): everything below keys on "ready" (or an active download), NOT on
   non-idle — boot passes through "loading" on EVERY visit (idle → loading →
   idle on a first visit), and elements above the card that flashed on and off
   during that window moved the whole page twice. */
body:not([data-dict-state="ready"]):not([data-downloading]) .dict-grid { display: none; }
body:not([data-dict-state="ready"]) .view-switch { display: none; }
/* U7: whatever we bring into view after a reader tap must clear the sticky
   topbar + search box instead of hiding behind them. */
#dict-grid, #empty-state { scroll-margin-top: calc(var(--topbar-h) + 76px); }
.empty-state strong { color: var(--text); }
.load-error {
  color: #b91c1c; font-weight: 600; max-width: 46ch; margin: 0;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .load-error { color: #f87171; } }
.btn-secondary {
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  font-size: var(--fs-sm); cursor: pointer; min-height: var(--touch);
}
.btn-primary {
  padding: var(--sp-3) var(--sp-5); border-radius: var(--r-md); border: none;
  background: var(--accent); color: #fff; font-size: var(--fs-md);
  cursor: pointer; font-weight: 600; min-height: var(--touch);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #06251f; } }
/* A button-styled LINK needs the button box explicitly: `<a>` is display:inline,
   where `min-height` is ignored outright AND vertical padding does not grow the
   line box — so every `<a class="btn-secondary">` (the bookmarklet drag target,
   the empty-state CTAs) drew 35px tall and its 44px min-height never applied.
   Scoped to anchors, so the real <button class="btn-…"> boxes are untouched. */
a.btn-primary, a.btn-secondary { display: inline-flex; align-items: center; justify-content: center; }

.btn-primary:disabled { opacity: .6; cursor: wait; }

/* ============================================================ about (SEO copy) */
.about {
  margin-top: var(--sp-6);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-4);
  font-size: var(--fs-sm); color: var(--text-2); line-height: 1.7;
}
.about h2 { font-size: var(--fs-lg); margin: 0 0 var(--sp-2); color: var(--text); }
.about summary {
  cursor: pointer; color: var(--accent); font-weight: 600;
  padding: var(--sp-2) 0; min-height: var(--touch); display: flex; align-items: center;
}
.about p strong { color: var(--text); font-weight: 600; }
.about ul { padding-left: var(--sp-5); margin: var(--sp-2) 0 0; }
.about li { margin-bottom: var(--sp-1); }

/* ============================================================ footer */
.foot { text-align: center; margin-top: var(--sp-6); font-size: var(--fs-xs); color: var(--text-2); }
.foot p { margin: var(--sp-1) 0; }
.foot a { color: var(--text-2); }
.foot a:hover { color: var(--accent); }
.credits { line-height: 1.7; }
/* U5: attribution is condensed to short one-line-per-source text at a readable
   size (it used to be 12px low-contrast prose, with one panel-style long licence
   block next to a one-liner). The full wording is in each link's tooltip and in
   NOTICE.md, so nothing about the licences changes — only the presentation. */
.attr-line { font-size: var(--fs-sm); color: var(--text); line-height: 1.6; }
.attr-line a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.attr-line a:hover, .attr-line a:focus-visible { color: var(--accent); }
.foot-offline { font-size: var(--fs-xs); }

/* --- Buy Me a Coffee: a quiet text link, never a competing CTA (U17) --- */
.support { margin-top: var(--sp-2); font-size: var(--fs-xs); }

/* Floating: the widget injected in the footer is pinned bottom-right so it
   stays visible while studying. Native <dialog> renders in the top layer,
   so it always paints above this regardless of z-index.
   bottom offset sits ABOVE Netlify's attribution badge (#nl-badge-frame,
   202x64px, bottom-right, z-index 2147483645 — cannot be hidden or out-z-indexed). */
.bmc-btn-container {
  position: fixed;
  right: 16px;
  bottom: 80px; /* 16px margin + 64px badge height */
  z-index: 40; /* above the sticky topbar (30) */
  width: auto;
}
.foot { padding-bottom: 156px; } /* keep footer text clear of the stacked widgets */

/* Mobile: shrink the widget so it never dominates a 375px screen */
@media (max-width: 640px) {
  .bmc-btn-container { right: 12px; bottom: 76px; } /* 12px margin + 64px badge */
  .bmc-btn { padding: 9px 16px !important; }
  .bmc-btn-text { font-size: 15px !important; }
}

/* Inline support affordance — no longer rendered inside the first-load card
   (U17: nothing competes with the download CTA), kept as a reusable quiet style. */
.bmc-inline {
  margin-top: var(--sp-2);
  padding: 6px 4px; /* reach a comfortable tap target, not just a text underline */
  font-size: var(--fs-xs);
  color: var(--text-2);
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
}
.bmc-inline:hover { color: var(--accent); }

/* ============================================================ dialog */
dialog {
  border: none; border-radius: var(--r-lg);
  max-width: 560px; width: 92vw; max-height: 84vh; overflow-y: auto;
  padding: var(--sp-5); color: var(--text); background: var(--surface);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin: 0 0 var(--sp-3); font-size: var(--fs-xl); }
dialog h3 { font-size: var(--fs-md); margin: var(--sp-4) 0 var(--sp-1); }
dialog ol, dialog ul { padding-left: var(--sp-5); }
dialog li { margin-bottom: var(--sp-2); line-height: 1.6; font-size: var(--fs-sm); }
dialog a { color: var(--accent); }
dialog code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* Sticky close button — stays visible at the top-right even in a long modal,
   so the user never has to scroll to the bottom to dismiss. */
.dialog-close {
  position: sticky; top: 0; float: right; z-index: 5;
  width: 44px; height: 44px;
  margin: calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)) 0 var(--sp-2);
  border: none; border-radius: var(--r-full);
  background: transparent; color: var(--text-2);
  font-size: var(--fs-lg); line-height: 1; cursor: pointer;
}
.dialog-close:hover { background: var(--bg); color: var(--text); }

/* Help modal: short quickstart first, long content collapsed */
dialog .quickstart li { font-size: var(--fs-md); margin-bottom: var(--sp-3); }
.help-more { margin-top: var(--sp-3); border-top: 1px solid var(--border); padding-top: var(--sp-2); }
.help-more summary {
  cursor: pointer; color: var(--accent); font-weight: 600;
  min-height: var(--touch); display: flex; align-items: center;
}

/* First-load gate */
.first-load-sizes { margin: 0; color: var(--text-2); text-align: left; }
/* v91 chooser: the size list became selectable dictionary cards */
.dict-chooser { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); text-align: left; width: 100%; }
.dict-choice { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.dict-choice.is-loading { border-color: var(--accent); }
.dict-choice.is-done { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.dict-choice.is-failed { border-color: #b91c1c; }
.dict-choice label {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: var(--sp-3); padding: var(--sp-3); cursor: pointer; min-height: var(--touch);
}
.dict-choice input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.dict-choice .dc-name { font-weight: 700; color: var(--text); }
.dict-choice .dc-desc { grid-column: 2; font-size: var(--fs-xs); color: var(--text-2); }
.dict-choice .dc-size { grid-row: 1; grid-column: 3; font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }
.firstload-title { margin: 0 0 var(--sp-2); font-size: 1.15rem; }
.first-load-note { margin: 0; }
.license-note {
  font-size: var(--fs-xs); color: var(--text-2);
  background: var(--bg); border-radius: var(--r-sm);
  padding: var(--sp-3); line-height: 1.7;
}

/* ==================== Phase 3 Release B — IA: routes, Vault, Review ==================== */

/* top nav (desktop ≥900px only) */
.app-nav { display: flex; gap: var(--sp-1); margin-left: var(--sp-5); }
.app-nav a {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px var(--sp-3); border-radius: var(--r-full);
  color: rgba(255,255,255,.85); text-decoration: none;
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.2;
  min-height: var(--touch);
}
.app-nav a:hover { background: rgba(255,255,255,.16); }
/* R-C: the active pill was a translucent white wash (rgba(255,255,255,.22)) with
   white text — 2.1:1 over the light-theme topbar, the worst contrast in the app.
   It is now a solid --accent pill: white on #0f766e is 5.47:1 in light, and the
   dark theme flips the label to the same near-black the other accent fills use
   (#06251f on #2dd4bf = 8.73:1), so the pill passes AA in both themes. Same
   palette, just opaque. */
.app-nav a.active { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .app-nav a.active { color: #06251f; } }

/* bottom nav (mobile <900px only) */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0,0,0,.06);
  padding-bottom: var(--safe-b);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 54px; padding: 4px 0;
  color: var(--text-2); text-decoration: none; font-size: var(--fs-xs); font-weight: 600;
  position: relative;
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav .bn-icon { font-size: 18px; line-height: 1; }
.bottom-nav .badge { position: absolute; top: 4px; right: 18%; }

@media (max-width: 899.5px) {
  .app-nav { display: none; }
  .bottom-nav { display: flex; }
  /* R-E: the fixed bottom nav is 55px tall and grows by the device inset
     (.bottom-nav padding-bottom). This reserve used to be a flat 70px, so on a
     phone with a home indicator the nav grew but the space below the content did
     not, and the last line of a long entry ended up underneath it. The reserve now
     tracks the nav: 70px of nav + gap, plus whatever inset the device reports. */
  main { padding-bottom: calc(70px + var(--safe-b)); }
  /* U11: advanced / help are reachable through the ⋯ menu on a phone — keeping
     them in the bar wrapped the app title onto two lines. The theme toggle stays
     in the bar on every screen size (owner request). */
  .topbar-actions .topbar-optional { display: none; }
}

/* ===== Vault ===== */
.vault-view, .review-view { max-width: 760px; margin: 0 auto; }
.vault-head { display: flex; align-items: baseline; gap: var(--sp-3); margin: var(--sp-4) 0 var(--sp-2); }
.vault-head h2 { font-size: var(--fs-xl); margin: 0; }
.vault-search {
  width: 100%; padding: 10px var(--sp-3); border: 1px solid var(--border);
  border-radius: var(--r-md); font-size: var(--fs-md); background: var(--surface); color: var(--text);
  margin-bottom: var(--sp-3);
}
.vault-search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.tab-row { display: flex; gap: var(--sp-1); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.tab-row button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: var(--r-full); padding: 6px var(--sp-3); font-size: var(--fs-sm);
  font-weight: 600; cursor: pointer; min-height: 36px;
}
.tab-row button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.select-bar {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  padding: var(--sp-2) 0; margin-bottom: var(--sp-2);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.select-bar .btn-secondary { min-height: 34px; padding: 4px var(--sp-2); font-size: var(--fs-sm); }
.select-spacer { flex: 1; }

.item-card {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-3); margin-bottom: var(--sp-2); box-shadow: var(--shadow-1);
}
.item-card.is-selected { border-color: var(--accent); outline: 1px solid var(--accent-soft); }
.item-select { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
/* Wrapper that carries the tap target (see the v63 block at the end of the file):
   on desktop it is a no-op box around the input, so the row is pixel-identical. */
.item-select-hit { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.item-main { flex: 1; min-width: 0; }
.item-text {
  background: none; border: none; padding: 0; cursor: pointer;
  font-size: var(--fs-md); font-weight: 700; color: var(--text);
  text-align: left; font-family: inherit;
}
.item-text:hover { color: var(--accent); text-decoration: underline; }
.item-gloss { margin: 2px 0 0; color: var(--text-2); font-size: var(--fs-sm); }
.item-context {
  margin: var(--sp-1) 0 0; font-size: var(--fs-sm); color: var(--text);
  font-style: italic; border-left: 3px solid var(--border); padding-left: var(--sp-2);
}
.item-meta { display: block; margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--text-2); }
.item-tag {
  display: inline-block; background: var(--bg); border-radius: var(--r-full);
  padding: 1px 8px; margin-right: 4px; font-size: var(--fs-xs); color: var(--text-2);
}
.item-actions { display: flex; flex-direction: column; gap: var(--sp-1); }
.item-actions .icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-2);
  border-radius: var(--r-sm); min-width: 34px; min-height: 34px; font-size: var(--fs-sm);
  padding: 0 var(--sp-1);
}
.item-actions .icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Review ===== */
.review-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-4); margin-bottom: var(--sp-2); box-shadow: var(--shadow-1);
}
.review-card .item-text { font-size: var(--fs-lg); cursor: default; }
.review-card .item-text:hover { text-decoration: none; color: var(--text); }
.review-answer { margin: var(--sp-2) 0 0; }
.review-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }
.review-actions .btn-secondary { min-height: var(--touch); }

/* ===== item editor dialog ===== */
#item-editor { width: min(460px, 92vw); }
#item-editor .field { display: block; margin: var(--sp-3) 0; font-size: var(--fs-sm); font-weight: 600; }
#item-editor textarea, #item-editor input, #item-editor select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: var(--fs-md); font-family: inherit; background: var(--surface); color: var(--text);
  box-sizing: border-box;
}
.editor-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }
.app-nav a, .bottom-nav a { position: relative; }
/* compact nav links — keep the topbar at its original 52px height so the
 * Release B IA change does not shift every element below it (ui-check diff) */
.app-nav a { min-height: 0; padding: 4px var(--sp-3); }
@media (max-width: 899.5px) {
  /* keep toasts clear of the fixed bottom nav on mobile (incl. safe-area) */
  .toast { bottom: calc(70px + var(--safe-b)); }
}

/* ============================================================ context layer (P1) */
.context-bar {
  display: flex; gap: var(--sp-3); align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; margin: var(--sp-2) 0; padding: var(--sp-3) var(--sp-4);
  border: 1px solid #99f6e4; background: #f0fdfa; border-radius: 10px;
}
.context-main { flex: 1 1 320px; min-width: 0; }
.context-label {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: #0f766e; font-weight: 700; margin-bottom: 2px;
}
.context-sentence { margin: 0; line-height: 1.5; color: #134e4a; overflow-wrap: break-word; }
.context-sentence mark { background: var(--hl-bg); color: var(--hl-fg); padding: 0 1px; border-radius: 3px; }
.context-source { display: block; margin-top: 3px; }
.context-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
#example-dialog .field { display: block; margin: var(--sp-3) 0; font-size: var(--fs-sm); font-weight: 600; }
#example-dialog textarea { width: 100%; box-sizing: border-box; font: inherit; padding: var(--sp-2); margin-top: var(--sp-1); }
@media (max-width: 899.5px) { .context-actions { width: 100%; } }

/* ============================================================ Phase 3+ add-ons */
/* pronunciation strip */
/* v69 R4 — say-it-aloud: practice word display + pron-strip mic feedback */
.practice-word { font-size: 1.7em; font-weight: 600; margin: var(--sp-1) 0; letter-spacing: 0.01em; }
.pron-mic-result { flex: 1 1 100%; margin: 0; }
.pron-mic-result.bad { color: #92400e; }

.pron-strip { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin: var(--sp-2) 0; padding: 8px var(--sp-3); border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.pron-word { font-weight: 700; }
.pron-ipa { color: var(--text-2); display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: baseline; } /* v91: gap instead of inline margins — variants never glue together */
.pron-ipa .ipa { white-space: nowrap; }
.ipa-stress { color: var(--accent); font-weight: 700; }
#btn-pron-slow.active { background: var(--accent); color: #fff; border-color: var(--accent); }
/* head action buttons */
.head-actions { margin-left: auto; display: flex; gap: var(--sp-2); flex-wrap: wrap; }
/* practice */
.practice-card { border: 1px solid var(--border); border-radius: 12px; padding: var(--sp-4); background: var(--surface); max-width: 42rem; }
.practice-kind { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); font-weight: 700; margin: 0 0 8px; }
.practice-prompt { font-size: var(--fs-md); line-height: 1.6; margin: 0 0 var(--sp-2); overflow-wrap: break-word; }
.practice-input { width: 100%; box-sizing: border-box; font: inherit; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin: var(--sp-2) 0; }
.practice-feedback { min-height: 1.4em; margin: 0; font-weight: 600; }
.practice-feedback.ok { color: #0f766e; }
.practice-feedback.bad { color: #b91c1c; }
/* stats — U10/R-C: labelled groups (vocabulary / review / activity) instead of one
   grid whose 9th card sat alone on its own row. */
.stats-grid { display: block; }
.stat-group { margin: 0 0 var(--sp-4); }
/* R-C: the group label used to be --text-2 at 12px uppercase+letterspaced. That
   measured 4.92:1 — technically over the 4.5 threshold, but with almost no margin
   for the lightest rendering, so it read as "grey text". --text is the palette's
   body colour: 13.5:1 light / 15.4:1 dark, same weight and tracking. */
.stat-group-title {
  margin: 0 0 var(--sp-2); font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text);
}
/* R-C: auto-fill with no cap let a one-card group occupy a single track of an
   eight-track row (the dead space on the right). auto-fit collapses the empty
   tracks, and the group publishes its card count as data-cards so the row is sized
   to its contents — every group now holds the same ~240px card, and no row is left
   holding a lone card. */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-2); }
.stat-group[data-cards="2"] .stat-cards { max-width: 496px; }
.stat-group[data-cards="3"] .stat-cards { max-width: 744px; }
.stat-group[data-cards="4"] .stat-cards { max-width: 992px; }
.stat-card { border: 1px solid var(--border); border-radius: 12px; padding: var(--sp-3); background: var(--surface); display: flex; flex-direction: column; gap: 2px; }
.stat-metric { display: flex; align-items: baseline; gap: 3px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--accent); }
/* R-C: the unit is always a separate span, never glued into the number. */
.stat-unit { font-size: var(--fs-sm); font-weight: 700; color: var(--text-2); }
.stat-label { font-size: var(--fs-sm); font-weight: 600; }
.stat-note { font-size: var(--fs-xs); color: var(--text-2); }
/* export dialog */
#export-dialog .field { display: block; margin: var(--sp-3) 0; font-size: var(--fs-sm); font-weight: 600; }
#export-fields { display: flex; flex-wrap: wrap; gap: 8px 16px; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
#export-fields legend { padding: 0 6px; }
#export-fields label { font-weight: 400; display: inline-flex; align-items: center; gap: 4px; }
.practice-options { display: grid; gap: 8px; margin: var(--sp-2) 0; }
.practice-option { text-align: left; }
.practice-option.opt-ok { border-color: #0f766e; color: #0f766e; font-weight: 700; }
.practice-option.opt-bad { border-color: #b91c1c; color: #b91c1c; }

/* ============================================================ UX pack (v47) */
/* manual theme — 'auto' (no attribute) still follows prefers-color-scheme */
:root[data-theme="light"] {
  --bg: #f4f5f7; --surface: #ffffff; --text: #1f2937; --text-2: #646b78; --border: #e5e7eb;
  --accent: #0f766e; --accent-soft: #14b8a6;
  --shadow-1: 0 1px 3px rgba(0,0,0,.08); --shadow-2: 0 8px 24px rgba(0,0,0,.14);
}
:root[data-theme="dark"] {
  --bg: #101317; --surface: #1a1e26; --text: #e7eaee; --text-2: #9aa3af; --border: #2b313c;
  --accent: #2dd4bf; --accent-soft: #0f766e;
  --shadow-1: 0 1px 3px rgba(0,0,0,.4); --shadow-2: 0 8px 24px rgba(0,0,0,.5);
}
:root[data-theme="dark"] .btn-search,
:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .app-nav a.active,
:root[data-theme="dark"] .view-switch button.active { color: #06251f; }
:root[data-theme="dark"] .load-error { color: #f87171; }
:root[data-theme="dark"] .storage-banner { background: #451a03; color: #fde68a; border-color: #92400e; }

.net-banner { margin: var(--sp-2) 0; padding: 8px 12px; border-radius: 10px;
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; font-size: var(--fs-sm); }
/* v67 R2 — due banner (quiet in-app review nudge, max once a day) */
.due-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.due-banner span:first-child { flex: 1; min-width: 0; }
.due-banner-cta { color: #92400e; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.due-banner-cta:hover, .due-banner-cta:focus-visible { color: #78350f; }
.due-banner button { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; padding: 6px; line-height: 1; }
.reminders-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.reminders-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.linklike { background: none; border: 0; padding: 4px 2px; font: inherit; font-size: var(--fs-sm); color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.linklike:hover, .linklike:focus-visible { color: var(--accent-strong, var(--accent)); }
.onboarding-extra { margin: 4px 0 8px; }
.hist-all { margin-left: var(--sp-2); font-size: var(--fs-sm); color: var(--accent); }
.sort-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); }
#vault-sort { font: inherit; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }
.tag-row { display: flex; align-items: center; gap: var(--sp-2); padding: 6px 0; border-bottom: 1px solid var(--border); }
.tag-row .tag-name { flex: 1; }
.tag-edit { width: 9rem; font: inherit; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.hist-row { display: flex; align-items: center; gap: var(--sp-2); padding: 6px 0; border-bottom: 1px solid var(--border); }
.hist-row .vocab-word { flex: 1; text-align: left; }
.history-view { padding-bottom: var(--sp-5); }
.icon-btn.playing { animation: ux-pulse .7s ease-in-out infinite alternate; }
@keyframes ux-pulse { from { opacity: .45; } to { opacity: 1; } }
/* U11: accent-on-teal was ~1.9:1 on the install button — same white as the rest
   of the header controls (the .icon-btn colour), only the weight is special. */
#btn-install { font-weight: 700; }

/* ============================================================ Phase 4: a11y + advanced */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.adv-section { border: 1px solid var(--border); border-radius: 10px; padding: var(--sp-2) var(--sp-3); margin: var(--sp-3) 0; }
.adv-section > summary { cursor: pointer; font-weight: 700; }
.adv-slot { margin: var(--sp-2) 0; padding-top: var(--sp-2); border-top: 1px dashed var(--border); }
.adv-slot h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-md); }

.skip-link { position: absolute; left: -9999px; top: 0; z-index: 100; background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0; font-weight: 600; text-decoration: none; }
.skip-link:focus { left: 0; }
/* U17: support is a footer text link — same weight as the licence links next to
   it, no block-level button treatment. */
.support-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.support-link:hover { color: var(--accent); }

/* perf: reserve space to avoid layout shift. Units are em on the 14px (fs-sm)
   text at line-height 1.7 (≈23.8px/line): 2 lines = 3.4em, 3 lines = 5.1em.
   The older 3em values sat UNDER one line pair, so the first gate paint still
   shifted. #empty-state-msg is a <strong> (inline) — min-height only applies
   once it is display:block. */
#first-load-sizes { min-height: 3.4em; }
#empty-state-msg { display: block; min-height: 5.1em; }
/* CLS (v70): the card's reserved height used to flip 0 ↔ 24rem between the
   "idle" and "loading" states around boot — a whole-card shift on every visit.
   Content now defines the height (the reserves above absorb the gate's text
   swaps); the download progress lives in the panel grid below the card. */

/* keep the mobile bottom-nav clear of Netlify's free-plan attribution badge */
@media (max-width: 899.5px) {
  :root.has-netlify-badge .bottom-nav { padding-bottom: calc(var(--safe-b) + 58px); }
  :root.has-netlify-badge main { padding-bottom: 128px; }
}

.backup-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-top: var(--sp-2); }
.backup-row select { flex: 1 1 14rem; font: inherit; padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

#snapshots-list { max-height: 50vh; overflow-y: auto; }

/* U13: the frequency badge was 11px accent-on-surface (~4.4:1 at 11px, under AA
   for small text). 12px + full-strength text colour on a bordered chip clears AA
   in both themes; the band itself is explained in its title attribute. */
.pron-freq {
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px;
  font-size: var(--fs-xs); font-weight: 700; color: var(--text); background: var(--bg);
  cursor: help;
}

.third-head { border-bottom-color: #c4b5fd; }

.context-more { margin-top: 4px; }
.context-extra { margin: 2px 0; font-size: var(--fs-sm); color: var(--text-2); overflow-wrap: break-word; }

/* ============================================================ v63: touch targets
   A QA pass measured interactive controls below the 44×44 minimum at 390×844 (the
   app's own bar — see the `--touch` token and the "Touch targets" block above).
   These rules raise the ones that are real, standalone CONTROLS.

   They sit at the END of the file on purpose: every control below is declared
   further up with equal specificity (e.g. `.item-select { width:18px }`,
   `.tab-row button { min-height:36px }`), and only source order makes these win.

   Deliberately NOT raised — WCAG 2.5.8 "inline" exception: the target sits in a
   run of text whose line-height fixes its box, and growing it would re-flow the
   sentence. Judged exempt: the footer/attribution links (NOTICE.md, "Licences &
   sources", "buy me a coffee", CMUdict, MIT, "detailed loading guide").

   ITEM B: the per-panel licence chips (.dict-lic) used to sit on that list too, as
   the weakest call in the pass — they are chips in a header row, not words inside a
   sentence, and at 20.5px they were below the AA minimum. They are no longer
   exempted: the base `.dict-lic` rule carries the WCAG 2.5.8 AA floor (24×24) at
   every width, and ui-check/touch-target-audit.js MEASURES the chip against that
   floor instead of skipping it. */
@media (max-width: 899.5px) {
  /* the app mark is a LINK (go to search) — a control, so it gets a real box */
  .brand-mark { width: var(--touch); height: var(--touch); }

  /* #search-input was only 34px tall: the mobile rule above SHRANK its padding to
     --sp-2 while the desktop one used --sp-3. Reclaim the height, keep the padding. */
  #search-input, #vault-search { min-height: var(--touch); }

  /* panel header controls: the ⤢ / ⤡ full-screen toggle and the ✕ remove */
  .panel-toggle, .panel-remove { min-width: var(--touch); min-height: var(--touch); }

  /* vault row: the select box was an 18×18 hit area. The .item-select-hit LABEL
     (see its base rule next to .item-select) becomes the 44×44 target while the
     input keeps its drawn 18px size — padding the input itself just scales the
     glyph, because Chrome draws the control at the border box. The row's text
     button is 44 tall too, so both centres line up. */
  .item-select-hit { width: var(--touch); height: var(--touch); cursor: pointer; }
  .item-select { width: 18px; height: 18px; margin-top: 0; }
  /* min-WIDTH as well: "apple" is a short word, so a text-sized button measured
     42.9px wide. Growing a left-aligned label button to 44 costs nothing. */
  .item-text { min-height: var(--touch); min-width: var(--touch); }

  /* selects and text inputs used as controls (several had no height rule at all,
     so the ~19-38px UA default applied inside a 390px layout) */
  .select-bar select, #vault-deck, #vault-sort, #export-format, #backup-select,
  #item-status, #item-tags, #item-deck, .tag-edit { min-height: var(--touch); }

  /* vault filters + the batch action bar (min-width too: the "All" pill is a
     one-word label and measured 43.4px wide) */
  .tab-row button, .select-bar .btn-secondary { min-height: var(--touch); }
  .tab-row button { min-width: var(--touch); }

  /* collapsible sections in the Advanced dialog. Only padding, so the native
     disclosure triangle is untouched. */
  .adv-section > summary { padding: 10px 0; }

  /* the export dialog's per-field checkboxes: the LABEL is the hit area */
  #export-fields label { min-height: var(--touch); }
}

/* v111: "did you mean" chips under a failed lookup — one row per panel, between
 * the status line and the entry frame. Buttons clear the 44px touch floor. */
.didyoumean {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) 0;
}
.didyoumean-label { color: var(--text-2); font-size: var(--fs-sm); }
.didyoumean button {
  min-height: var(--touch); padding: 0 var(--sp-4); border-radius: 999px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  font-size: var(--fs-sm); cursor: pointer;
}

/* v112: curriculum practice — deck picker chips + the wrong-answer save CTA */
.practice-decks { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
.practice-save { border-color: var(--accent); }

/* v117 A2 — known-words baseline (Vault empty-state CTA + Advanced section).
 * Passive, non-blocking: a quiet card in the empty vault, chips for the four
 * frequency milestones, everything else stays out of the way. */
.known-empty-box {
  margin: 14px auto 0;
  max-width: 460px;
  padding: 14px 16px;
  border: 1px solid #c9c9c9;
  border-radius: 12px;
  text-align: left;
}
.known-empty-box .hint { margin: 6px 0 0; }
.known-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.known-chips .known-chip { flex: 0 0 auto; }
#known-adv-status { margin: 8px 0 10px; }

/* v118 A1 — reading coverage card + 3-way word highlight (plan D5).
 * Passive: one card under the reader status line, colors that stay quiet. */
.cov-card { margin: 10px 0 0; padding: 10px 14px; border: 1px solid #c9c9c9; border-radius: 12px; max-width: 760px; }
.cov-card[data-tone="easy"] { border-color: #2e7d32; }
.cov-card[data-tone="mid"] { border-color: #b26a00; }
.cov-card[data-tone="hard"] { border-color: #c62828; }
.cov-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cov-pct { font-size: 1.4rem; font-weight: 700; }
.cov-word { color: var(--text-2); font-size: var(--fs-sm); }
.cov-tone { color: var(--text-2); font-size: var(--fs-sm); }
.cov-toggle { margin-left: auto; font-size: var(--fs-sm); }
.cov-toggle.is-off { opacity: .55; }
.cov-bars { display: grid; gap: 4px; margin-top: 8px; }
.cov-bar { display: grid; grid-template-columns: 70px 1fr 44px; align-items: center; gap: 8px; font-size: var(--fs-sm); }
.cov-bar-track { display: block; height: 8px; border-radius: 4px; background: rgba(128,128,128,.25); overflow: hidden; }
.cov-bar-fill { display: block; height: 100%; border-radius: 4px; }
.cov-bar[data-band="1k"] .cov-bar-fill { background: #2e7d32; }
.cov-bar[data-band="2k"] .cov-bar-fill { background: #7cb342; }
.cov-bar[data-band="5k"] .cov-bar-fill { background: #f9a825; }
.cov-bar[data-band="10k"] .cov-bar-fill { background: #ef6c00; }
.cov-warn { margin: 8px 0 0; color: #c62828; font-weight: 600; }
.cov-new { margin: 8px 0 0; }
.cov-note { margin: 6px 0 0; }
.cov-card[data-tone="unknown"] { border-color: var(--border,#526462); }
.cov-baseline-label { margin: 10px 0 6px; font-weight: 600; }
.cov-baseline-choices { display: flex; flex-wrap: wrap; gap: 8px; }
#reader-text.cov-hl .rw.cov-k { background: rgba(46,125,50,.22); border-radius: 3px; }
#reader-text.cov-hl .rw.cov-l { background: rgba(245,160,0,.30); border-radius: 3px; }
#reader-text.cov-hl .rw.cov-n { background: rgba(198,40,40,.16); border-radius: 3px; }

/* Reading-to-speaking tutor */
.tutor-dialog { max-width: 720px; padding: 0; overflow: hidden; }
.tutor-dialog[open] { display: flex; flex-direction: column; }
.tutor-dialog-header { display: flex; align-items: flex-start; gap: var(--sp-3); flex: 0 0 auto; padding: var(--sp-4); border-bottom: 1px solid var(--border); }
.tutor-dialog-header h2 { flex: 1; margin: 0; }
.tutor-dialog-header .dialog-close { position: static; float: none; flex: 0 0 44px; margin: 0; }
.tutor-dialog-body { min-height: 0; overflow-y: auto; padding: var(--sp-4); }
.sense-save-dialog { width: min(680px, calc(100vw - 24px)); max-width: 680px; }
.sense-save-form { display: grid; gap: 10px; }
.sense-save-form h2,.sense-save-form p { margin: 0; }
.sense-save-form label { font-weight: 600; }
.sense-save-form select,.sense-save-form textarea { width: 100%; min-height: 44px; padding: 10px; border: 1px solid var(--border,#526462); border-radius: 8px; background: var(--bg,#152321); color: var(--text,#f3faf8); color-scheme: dark light; }
.sense-save-form textarea { resize: vertical; }
.sense-save-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#tutor-stage { display: grid; gap: var(--sp-3); margin-top: var(--sp-3); }
#tutor-stage .adv-section { margin: 0; }
#tutor-stage textarea { width: 100%; min-height: 7rem; resize: vertical; }
#tutor-stage form { display: grid; gap: var(--sp-2); }
#tutor-stage blockquote { margin: 0; padding: var(--sp-2) var(--sp-3); border-left: 3px solid var(--accent); background: var(--bg); }
#tutor-stage button { min-height: var(--touch); }
#tutor-stage > div { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
#tutor-status { min-height: 1.5em; }

/* UX audit: progressive Reader actions and consistent form controls. */
.reader:not(:has(#reader-text:not(.hidden))) #btn-save-sentence,
.reader:not(:has(#reader-text:not(.hidden))) #btn-save-offline,
.reader:not(:has(#reader-text:not(.hidden))) #btn-cov-hl,
.reader:not(:has(#reader-text:not(.hidden))) #btn-tutor-start { display:none; }
.reader:has(#reader-text:not(.hidden)) .reader-source-options { display:none; }
.reader-source-options { margin:12px 0; padding:12px; border:1px solid var(--border,#526462); border-radius:12px; }
.reader-source-options summary { cursor:pointer; }
.reader-source-options .file-btn,.reader-source-options button { margin-top:10px; }
.ai-settings-form { display:grid; gap:10px; }
.ai-settings-form input,.ai-settings-form select,#vault-deck { width:100%; min-height:44px; padding:10px; border:1px solid var(--border,#526462); border-radius:8px; background:var(--bg,#152321); color:var(--text,#f3faf8); color-scheme:dark light; }
.ai-settings-form label { display:block; margin-top:6px; }
.ai-settings-form .envi-row { display:flex; flex-wrap:wrap; gap:8px; }
.ai-advanced-fields { border:1px solid var(--border,#526462); border-radius:8px; padding:10px 12px; }
.ai-advanced-fields > summary { cursor:pointer; font-weight:600; }
.ai-advanced-fields[open] { display:grid; gap:8px; }
.ai-settings-form #btn-tutor-clear-data { margin-top:16px; }
.vault-is-empty #vault-select-bar,.vault-is-empty #vault-search,.vault-is-empty #btn-vault-tags { display:none; }
.vault-is-empty #vault-tabs button:not([data-tab="journal"]) { display:none; }
.offline-study-panel,.offline-writing,.offline-speaking { margin:16px 0; padding:14px; border:1px solid var(--border); border-radius:12px; background:var(--surface); color:var(--text); }
.tutor-payload-preview { max-height: 42vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: 0.9rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.offline-study-panel > summary { cursor:pointer; display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.offline-writing > summary,.offline-speaking > summary,.offline-history > summary { cursor:pointer; padding:8px 0; }
.offline-history { margin-top:12px; }
.exam-picker,.exam-actions { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin:10px 0; }
.exam-picker select,.offline-study-panel textarea,.offline-study-panel select,#listen-dialog #listen-material-title { box-sizing:border-box; width:100%; min-height:44px; padding:10px; border:1px solid var(--border); border-radius:8px; background:var(--bg); color:var(--text); font:inherit; color-scheme:dark light; }
.exam-picker label { font-weight:600; }
.exam-passage { white-space:pre-wrap; margin:12px 0; padding:12px; border-left:3px solid var(--accent); border-radius:6px; background:var(--bg); line-height:1.65; }
.exam-options { display:grid; gap:8px; border:0; padding:0; margin:14px 0; }
.exam-options label,.self-check label { display:flex; gap:10px; align-items:flex-start; padding:10px; border:1px solid var(--border); border-radius:8px; cursor:pointer; }
.audio-choice-options label { display:grid; grid-template-columns:24px 1fr; align-items:center; }
.audio-choice-options audio { grid-column:2; width:min(100%,420px); }
.ai-review { margin:14px 0; padding:12px; border:1px solid var(--border); border-radius:10px; background:var(--bg); }
.ai-review > summary { cursor:pointer; font-weight:600; }
.ai-review > label { display:flex; align-items:flex-start; gap:8px; margin:10px 0; }
.ai-review-card { margin-top:10px; padding:12px; border-left:3px solid var(--accent); background:var(--surface); border-radius:8px; line-height:1.55; }
.ai-review-card h4 { margin:10px 0 4px; }
.ai-review-card ul { margin:4px 0; padding-left:22px; }
.exam-options input,.self-check input { margin-top:4px; }
.exam-feedback { padding:12px; border-radius:8px; line-height:1.5; }
.exam-feedback.is-correct { background:color-mix(in srgb,var(--accent) 16%,var(--surface)); }
.exam-feedback.is-wrong { background:color-mix(in srgb,#dc6b58 18%,var(--surface)); }
.self-check { display:grid; gap:7px; margin:12px 0; padding:10px; border:1px solid var(--border); border-radius:8px; }
.study-history { margin:10px 0; padding:12px; border:1px solid var(--border); border-radius:8px; overflow-wrap:anywhere; }
.study-history audio { display:block; width:100%; margin:8px 0; }
.exam-gaps,.exam-matches { display:grid; gap:10px; margin:14px 0; padding:12px; border:1px solid var(--border); border-radius:10px; }
.exam-gaps label,.exam-matches label,.exam-input-label { display:grid; gap:6px; font-weight:600; }
.exam-gaps input,.exam-matches select,.exam-text-answer { box-sizing:border-box; width:100%; min-height:44px; padding:10px; border:1px solid var(--border); border-radius:8px; background:var(--bg); color:var(--text); font:inherit; color-scheme:dark light; }
.exam-prompt-image { display:block; width:min(100%,640px); max-height:360px; object-fit:contain; margin:12px auto; border-radius:12px; background:var(--bg); }
.offline-study-stats { margin-top:12px; }
.offline-data-details { margin:14px 0; padding:12px; border:1px solid var(--border); border-radius:10px; background:var(--surface); }
.offline-data-details > summary { cursor:pointer; min-height:32px; display:flex; align-items:center; }
.offline-study-stats > summary { cursor:pointer; padding:8px 0; }
.offline-study-stats h4 { margin:12px 0 4px; }
.offline-study-stats ul { margin-top:6px; padding-left:22px; }
.exam-result { padding:14px; border:1px solid var(--border); border-radius:12px; background:var(--surface); }
.diagnostic-guidance { margin:12px 0; padding:12px; border:1px solid var(--border); border-left:3px solid var(--accent); border-radius:8px; background:var(--surface); }
.diagnostic-guidance h4 { margin:0 0 8px; }
.ielts-assignment { margin:14px 0; padding:14px; border:1px solid var(--border); border-left:4px solid var(--accent); border-radius:10px; background:var(--surface); }
.ielts-assignment h3 { margin:0 0 6px; }
.ielts-assignment p { margin:6px 0 10px; }
#exam-timer { font-variant-numeric:tabular-nums; }
#study-pack-status:not(:empty) { padding:8px 10px; border-left:3px solid var(--accent); background:var(--surface); }
.ielts-learning-scaffold,#ielts-stage-guidance { margin:10px 0; padding:10px 12px; border-left:3px solid var(--accent); border-radius:8px; background:var(--surface); line-height:1.6; }
.ielts-learning-scaffold p,#ielts-stage-guidance p { margin:6px 0; }
.ielts-learning-scaffold a,#ielts-stage-guidance a { display:inline-block; margin-top:3px; }
#listen-dialog #listen-library { max-height:45vh; overflow:auto; margin-top:16px; }
@media(max-width:600px) { .offline-study-panel,.offline-writing,.offline-speaking { padding:11px; } .exam-picker>* { flex:1 1 100%; } .exam-actions>* { flex:1 1 auto; min-height:44px; } }
@media(max-width:600px) { .reader-toolbar { gap:8px; } .reader-toolbar a,.reader-toolbar button { padding:10px 12px; } }

.reader:not(:has(#reader-text:not(.hidden))) .reader-tools { display:none; }
.reader-tools { position:relative; }
.reader-tools summary { cursor:pointer; padding:10px 12px; border:1px solid var(--border); border-radius:10px; }
.reader-tools[open] { flex-basis:100%; }
.reader-tools button { margin:8px 4px 0 0; }

.village-banner{border-left:4px solid var(--accent);background:var(--surface);color:var(--text);padding:12px 16px;border-radius:10px;margin:12px 0}.village-banner p{margin:6px 0}.village-actions{display:flex;gap:10px;flex-wrap:wrap}.village-banner .btn-secondary{text-decoration:none}
@media(prefers-reduced-motion:reduce){.village-banner{border-left-width:6px}}
.offline-badge{display:inline-block;background:#0f766e;color:#fff;font-size:12px;font-weight:700;padding:2px 8px;border-radius:10px;margin-left:8px;vertical-align:middle}.online-badge{display:inline-block;background:#fff;border:1px solid #b34524;color:#b34524;font-size:12px;font-weight:700;padding:2px 8px;border-radius:10px;margin-left:8px;vertical-align:middle}
.reader-loop-hint{margin-left:8px}

/* Reserve space even if Netlify inserts its badge after startup. */
@media (max-width: 768px) {
  :root:has(#nl-badge-frame) .bottom-nav { padding-bottom: calc(var(--safe-b) + 64px); }
  :root:has(#nl-badge-frame) main { padding-bottom: 134px; }
}

#practice-stage { scroll-margin-top: calc(var(--topbar-h) + 12px); }

.review-nav, .practice-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.review-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
}
.review-nav a.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
}
.mobile-word-actions { display: none; }

@media (max-width: 899.5px) {
  #due-banner, #wotd-card { display: none; }
  #search-form .search-box { margin-top: 8px; }
  body[data-app-view="search"]:has(#pron-strip:not(.hidden)) #history { display: none; }
  body[data-app-view="search"]:has(#pron-strip:not(.hidden)) #context-bar { margin-block: 4px; }
  body:is([data-app-view="search"], [data-app-view="reader"]):not([data-dict-state="idle"]) .mobile-word-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
  }
  .mobile-word-actions:has(+ #pron-strip:not(.hidden)) #btn-speak,
  .mobile-word-actions button:disabled { display: none; }
  .mobile-word-actions button { min-width: 44px; min-height: 44px; }
  .envi-hint { padding: 0; border: 0; background: transparent; }
  .envi-hint > span { display: none; }
  .bottom-nav .bn-label { font-size: 12px; }
}

#reader-lookup {
  width: min(100%, 560px);
  max-height: 80dvh;
  margin: auto auto 0;
  border-radius: 16px 16px 0 0;
  padding: 0 12px max(12px, env(safe-area-inset-bottom));
}
.reader-lookup-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  padding: 8px 0;
}
.reader-lookup-head h2 { margin: 0; }
body:not([data-app-view="search"]) #envi-hint { display: none; }

.topbar { background: #115e59; }
:root[data-theme="dark"] .context-bar {
  background: #172b2a;
  border-color: #315953;
}
:root[data-theme="dark"] .context-label { color: #5eead4; }
:root[data-theme="dark"] .context-sentence { color: #e7eaee; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .context-bar {
    background: #172b2a;
    border-color: #315953;
  }
  :root:not([data-theme="light"]) .context-label { color: #5eead4; }
  :root:not([data-theme="light"]) .context-sentence { color: #e7eaee; }
}

.exam-progress {
  position: sticky;
  top: var(--topbar-h);
  z-index: 2;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}
.exam-mistake {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.exam-mistake h4 { margin: 0 0 8px; }
.exam-mistake blockquote {
  margin: 10px 0;
  padding-inline-start: 10px;
  border-inline-start: 3px solid var(--accent);
}

.toeic-ai-dialog{width:min(34rem,calc(100% - 1.5rem));max-height:calc(100dvh - 1.5rem);padding:clamp(1rem,4vw,1.5rem);border:1px solid var(--border,#8994a0);border-radius:16px;background:var(--surface,var(--bg));color:var(--text);overflow:auto;overflow-wrap:anywhere}
.toeic-ai-dialog::backdrop{background:#0009}
.toeic-ai-dialog header{display:flex;align-items:center;justify-content:space-between;gap:.75rem;margin-bottom:1rem}
.toeic-ai-dialog h2{margin:0;font-size:1.25rem}
.toeic-ai-dialog textarea{display:block;width:100%;margin:.35rem 0 .75rem;padding:.65rem;font:inherit;color:inherit;background:var(--bg);border:1px solid var(--border,#8994a0);border-radius:8px;resize:vertical}
.toeic-ai-dialog summary{cursor:pointer;padding:.5rem 0}
.toeic-ai-dialog .toeic-ai-context,.toeic-ai-dialog .toeic-ai-answer{padding:.75rem;border:1px solid var(--border,#8994a0);border-radius:10px;margin:0 0 1rem}
.toeic-ai-dialog .toeic-ai-context p{margin:.3rem 0 0}
.toeic-ai-dialog .toeic-ai-answer{white-space:pre-wrap;line-height:1.6}
.toeic-ai-dialog :is(.toeic-ai-answer,[role=status]):empty,.toeic-ai-dialog [hidden]{display:none}
.toeic-ai-dialog .toeic-ai-consent{display:flex;align-items:flex-start;gap:.55rem;margin:.75rem 0}
.toeic-ai-dialog .toeic-ai-consent input{flex:none;width:1.15rem;height:1.15rem}
.toeic-ai-dialog button{min-height:44px}
.toeic-ai-actions button,.toeic-ai-dialog>button{width:100%}

.work-lesson-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.work-lesson-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.work-lesson-list .btn-secondary { min-height: 44px; }

/* Keep the first action above the optional package controls. */
#empty-state { align-items: stretch; text-align: start; gap: .65rem; }
#empty-state > p { margin: 0; }
#empty-state-msg { min-height: auto; }
#empty-state .firstload-title { margin: 0; }
#empty-state .empty-cta, .first-load-actions, .onboarding-actions {
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem;
}
.firstload-options { margin-block-start: .3rem; }
.firstload-options > summary { cursor: pointer; padding-block: .45rem; }
.firstload-options .dict-chooser { margin-block: .5rem; }
.firstload-options .dc-name { overflow-wrap: anywhere; }
#onboarding-dialog { max-inline-size: min(30rem, calc(100% - 1.5rem)); }
#onboarding-dialog .onboarding-actions form { margin: 0; }
