/* ============================================================
   Jengo Reader — scoped under :is(#reader-overlay, #book-overlay)
   Full-viewport React overlay (dictionary.css precedent). All
   rules live under :is(#reader-overlay, #book-overlay) so the prototype's generic
   class names (.screen, .content, .btn, .field, .slot, .toast…)
   never collide with the rest of the app.

   One breakpoint at 768px:
     < 768px → mobile: page-turn reader, bottom sheets
     ≥ 768px → desktop: top bar, scroll/paged reader, word panel
   Forest design language (docs/DESIGN.md).

   Colors route through the local token block below, which derives
   from the global --brand + semantic tokens (auto-tracks theme).
   The warm-amber word states and a few one-off shades are named
   local tokens here — the sanctioned pattern (see dictionary.css);
   no loose hex lives in selectors.
   ============================================================ */

:is(#reader-overlay, #book-overlay) {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  background: var(--color-bg);
  overscroll-behavior: none;
  color: var(--text-primary);

  /* ---- local token block (theme-tracking) ---- */
  --brand-press:        color-mix(in oklab, var(--brand) 88%, black);
  --brand-tint:         color-mix(in oklab, var(--brand) 8%, white);
  --brand-tint-strong:  color-mix(in oklab, var(--brand) 18%, white);
  --brand-line:         color-mix(in oklab, var(--brand) 42%, white);

  --text-primary:   var(--color-text-primary);
  --text-secondary: var(--color-text-secondary);
  --text-muted:     var(--color-text-muted);
  --surface:        var(--color-surface);
  --surface-2:      color-mix(in oklab, var(--color-surface) 45%, white);
  --border:         var(--color-border);
  --border-light:   var(--color-border-light);

  /* warm-amber word marking (functional, like the SRS yellow) */
  --word-sel:    #ffe9a8;   /* staged in the live edge */
  --word-locked: #ffd45e;   /* committed / grade-locked */

  /* one-off accents */
  --warm-1: #f4ede0;        /* paused-story thumb gradient */
  --warm-2: #e8dcc4;
  --toast-bg:  #2f3a35;     /* dark "today done" toast */
  --toast-ico: #9fd9bf;

  --ui-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  /* reader SERIF (default reading face): Mincho. Hiragino = macOS/iOS, Yu Mincho =
     Windows, Songti SC = macOS Chinese w/ JP kanji, Noto Serif = Android/Linux. */
  --jp-font: 'Hiragino Mincho ProN', 'Yu Mincho', 'Songti SC', 'Noto Serif CJK JP', 'Noto Serif JP', serif;
  --jp-sans: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Roboto Mono', Menlo, monospace;

  --sat: env(safe-area-inset-top, 0px);

  /* reading surface — column width is FIXED; text size + font come from the
     in-reader gear settings (--read-size, --read-jp set inline on the overlay). */
  --read-measure: 40rem;
  --read-size: 1.18rem;
  --read-jp: var(--jp-font);

  font-family: var(--ui-font);
}
:is(#reader-overlay, #book-overlay).open {
  display: block;
  /* Opening a mode = the screen stepping forward (fade + slight rise). This is
     where the motion budget lives, now that the home cards render instantly. */
  animation: reader-open 0.26s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes reader-open {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  :is(#reader-overlay, #book-overlay).open { animation: none; }
}
:is(#reader-overlay, #book-overlay) * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:is(#reader-overlay, #book-overlay) button { margin: 0; font-family: var(--ui-font); }

:is(#reader-overlay, #book-overlay) #reader-mount { position: absolute; inset: 0; overflow: hidden; }

:is(#reader-overlay, #book-overlay) .reader-app {
  position: relative;
  width: 100%; height: 100%;
  background: var(--color-bg);
  overflow: hidden;
}

/* ---------- Screen system ---------- */
:is(#reader-overlay, #book-overlay) .screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  pointer-events: none;
  /* Screens stay fully opaque and slide horizontally (iOS push). The old
     opacity crossfade passed the green appbar through a pale midpoint over the
     white body — read as a white "flash" in the header. Constant opacity keeps
     the header solid throughout the transition. */
  transition: transform 0.3s cubic-bezier(.2, .7, .2, 1);
  z-index: 1;
}
:is(#reader-overlay, #book-overlay) .screen.active { pointer-events: auto; z-index: 2; }
/* Shelf is the root — it never moves; pushed screens slide over it. */
:is(#reader-overlay, #book-overlay) .screen-shelf { transform: none; z-index: 1; }
/* Pushed screens start off the right edge and slide in over the shelf. */
:is(#reader-overlay, #book-overlay) .screen-new,
:is(#reader-overlay, #book-overlay) .screen-reader {
  transform: translateX(100%);
  box-shadow: -10px 0 28px rgba(0, 0, 0, 0.12);
}
:is(#reader-overlay, #book-overlay) .screen-new.active,
:is(#reader-overlay, #book-overlay) .screen-reader.active { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  :is(#reader-overlay, #book-overlay) .screen { transition: none; }
}

/* ---------- App bar (Shelf / New) ---------- */
:is(#reader-overlay, #book-overlay) .appbar {
  flex: 0 0 auto;
  min-height: 52px;
  padding-top: var(--sat);
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 18px; padding-right: 10px;
}
:is(#reader-overlay, #book-overlay) .appbar .title { font-size: 1.05rem; font-weight: 700; }
:is(#reader-overlay, #book-overlay) .appbar .ico {
  width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
:is(#reader-overlay, #book-overlay) .appbar .ico:hover { background: rgba(255,255,255,0.14); }
:is(#reader-overlay, #book-overlay) .appbar .ico svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 1.8; }

:is(#reader-overlay, #book-overlay) .content {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 18px 18px calc(22px + var(--sab));
  display: flex; flex-direction: column; gap: 14px;
}

/* ---------- shelf loading state ---------- */
:is(#reader-overlay, #book-overlay) .shelf-loading {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--text-muted);
}
:is(#reader-overlay, #book-overlay) .shelf-spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
}
:is(#reader-overlay, #book-overlay) .shelf-loading p { font-size: 0.82rem; margin: 0; }

/* ---------- slot delete button (always visible, clearly tappable) ---------- */
:is(#reader-overlay, #book-overlay) .slot-del {
  margin-left: 2px; flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--color-bg);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-secondary); opacity: 1;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
:is(#reader-overlay, #book-overlay) .slot-del:hover { color: var(--color-danger); border-color: var(--color-danger); background: var(--color-danger-bg, #fff5f5); }
:is(#reader-overlay, #book-overlay) .slot-del:active { transform: scale(0.93); }
:is(#reader-overlay, #book-overlay) .slot-del svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ============================================================ SHELF */
:is(#reader-overlay, #book-overlay) .kicker {
  font-family: var(--mono);
  font-size: 0.64rem; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--text-muted); margin: 0;
}
:is(#reader-overlay, #book-overlay) .continue-card {
  border: 1px solid var(--border); border-radius: 16px;
  background: linear-gradient(160deg, var(--brand-tint), var(--color-bg) 70%);
  padding: 16px; cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
:is(#reader-overlay, #book-overlay) .continue-card:hover { box-shadow: 0 8px 28px rgba(0,0,0,0.08); }
:is(#reader-overlay, #book-overlay) .continue-card:active { transform: scale(0.99); }
:is(#reader-overlay, #book-overlay) .continue-card .ck { color: var(--brand); }
:is(#reader-overlay, #book-overlay) .continue-card .story-title {
  font-family: var(--jp-sans); font-size: 1.3rem; font-weight: 700;
  color: var(--text-primary); margin: 6px 0 8px; line-height: 1.3;
}
:is(#reader-overlay, #book-overlay) .continue-card .snip {
  font-family: var(--jp-font); font-size: 0.92rem; line-height: 1.75;
  color: var(--text-secondary); margin: 0 0 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
:is(#reader-overlay, #book-overlay) .resume-bar { display: flex; align-items: center; gap: 10px; }
:is(#reader-overlay, #book-overlay) .resume-bar .mini { flex: 1; height: 6px; border-radius: 999px; background: var(--brand-tint-strong); overflow: hidden; }
:is(#reader-overlay, #book-overlay) .resume-bar .mini i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
:is(#reader-overlay, #book-overlay) .resume-bar .pct { font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; gap: 4px; }
:is(#reader-overlay, #book-overlay) .resume-bar .pct-rv { color: var(--orange); }
:is(#reader-overlay, #book-overlay) .resume-bar .pct-sep { color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .resume-bar .pct-nw { color: var(--color-accent-new); }

:is(#reader-overlay, #book-overlay) .btn {
  appearance: none; border: none; cursor: pointer;
  font-family: var(--ui-font); font-weight: 600;
  border-radius: 12px; padding: 15px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 1.02rem;
}
:is(#reader-overlay, #book-overlay) .btn-primary { background: var(--brand); color: #fff; }
:is(#reader-overlay, #book-overlay) .btn-primary:hover { background: var(--brand-press); }
:is(#reader-overlay, #book-overlay) .btn-primary svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2.2; }

:is(#reader-overlay, #book-overlay) .section-label {
  font-family: var(--ui-font); font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted); margin: 4px 0 0;
}
:is(#reader-overlay, #book-overlay) .slot {
  border: 1px solid var(--border); border-radius: 13px; background: var(--color-bg);
  padding: 11px 12px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
:is(#reader-overlay, #book-overlay) .slot:hover { border-color: var(--brand-tint-strong); box-shadow: 0 4px 16px rgba(0,0,0,0.05); }
:is(#reader-overlay, #book-overlay) .slot:active { transform: scale(0.995); }
:is(#reader-overlay, #book-overlay) .slot .thumb {
  width: 40px; height: 52px; border-radius: 7px; flex: 0 0 auto;
  background: linear-gradient(160deg, var(--brand-tint), var(--brand-tint-strong));
  border: 1px solid var(--brand-tint-strong);
  display: flex; align-items: center; justify-content: center;
}
:is(#reader-overlay, #book-overlay) .slot .thumb.warm { background: linear-gradient(160deg, var(--warm-1), var(--warm-2)); border-color: var(--warm-2); }
:is(#reader-overlay, #book-overlay) .slot .thumb svg { width: 18px; height: 18px; stroke: var(--brand); fill: none; stroke-width: 1.6; opacity: 0.7; }
:is(#reader-overlay, #book-overlay) .slot .s-title { display: block; font-family: var(--jp-sans); font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
:is(#reader-overlay, #book-overlay) .slot .s-meta { display: block; font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }
:is(#reader-overlay, #book-overlay) .slot.add {
  border-style: dashed; justify-content: center; color: var(--text-secondary);
  font-weight: 600; font-size: 0.95rem; gap: 7px;
}
:is(#reader-overlay, #book-overlay) .slot.add svg { width: 18px; height: 18px; stroke: var(--text-secondary); fill: none; stroke-width: 2; }

/* Bottom-of-mode link into the Words hub (Reading words). */
:is(#reader-overlay, #book-overlay) .shelf-words-link {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  width: 100%; margin: 6px 0 2px; padding: 9px;
  background: none; border: none; cursor: pointer;
  font-family: var(--ui-font); font-size: 0.85rem; font-weight: 600;
  color: var(--text-secondary);
}
:is(#reader-overlay, #book-overlay) .shelf-words-link:hover { color: var(--brand); }
:is(#reader-overlay, #book-overlay) .shelf-words-link svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================ NEW STORY */
:is(#reader-overlay, #book-overlay) .field { display: flex; flex-direction: column; gap: 9px; }
:is(#reader-overlay, #book-overlay) .field-label {
  font-family: var(--ui-font); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted); margin: 0;
}
:is(#reader-overlay, #book-overlay) .mode-seg { display: flex; background: var(--surface); border-radius: 13px; padding: 4px; gap: 3px; }
:is(#reader-overlay, #book-overlay) .mode-seg .ms {
  flex: 1; border: none; background: none; cursor: pointer;
  font-family: var(--ui-font); font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
  padding: 10px 4px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 5px; position: relative;
}
:is(#reader-overlay, #book-overlay) .mode-seg .ms svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.7; }
:is(#reader-overlay, #book-overlay) .mode-seg .ms.on { background: var(--color-bg); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
:is(#reader-overlay, #book-overlay) .mode-seg .ms .soon { position: absolute; top: 4px; right: 9px; font-family: var(--mono); font-size: 0.5rem; color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .mode-seg .ms:disabled { cursor: default; opacity: 0.78; }

:is(#reader-overlay, #book-overlay) .ladder { display: flex; gap: 7px; }
:is(#reader-overlay, #book-overlay) .ladder .lv {
  flex: 1; border: 1px solid var(--border); border-radius: 10px; background: var(--color-bg);
  padding: 11px 0; text-align: center; cursor: pointer;
  font-size: 0.95rem; font-weight: 700; color: var(--text-secondary);
}
:is(#reader-overlay, #book-overlay) .ladder .lv:hover { border-color: var(--brand-tint-strong); }
:is(#reader-overlay, #book-overlay) .ladder .lv small { display: block; font-size: 0.55rem; font-weight: 500; color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .ladder .lv.on { background: var(--brand-tint); color: var(--brand); border-color: var(--brand-line); }
:is(#reader-overlay, #book-overlay) .preview-card { border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); padding: 12px 13px; }
:is(#reader-overlay, #book-overlay) .preview-card .pk { color: var(--brand); }
:is(#reader-overlay, #book-overlay) .preview-card .pv-head { display: flex; align-items: baseline; gap: 8px; }
:is(#reader-overlay, #book-overlay) .preview-card .pv-lv { font-family: var(--ui-font); font-weight: 800; font-size: 0.95rem; letter-spacing: 0.01em; }
:is(#reader-overlay, #book-overlay) .preview-card .pv-tag { font-family: var(--ui-font); font-size: 0.72rem; font-weight: 600; color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .preview-card .pv-caps { list-style: none; margin: 9px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
:is(#reader-overlay, #book-overlay) .preview-card .pv-caps li { position: relative; padding-left: 15px; font-family: var(--ui-font); font-size: 0.74rem; line-height: 1.4; color: var(--text-secondary); }
:is(#reader-overlay, #book-overlay) .preview-card .pv-caps li::before { content: ""; position: absolute; left: 3px; top: 0.5em; width: 4px; height: 4px; border-radius: 50%; background: var(--brand-tint-strong); }
:is(#reader-overlay, #book-overlay) .preview-card .pv-ex { margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border); }
:is(#reader-overlay, #book-overlay) .preview-card .pv-ex .pk-ex { font-family: var(--ui-font); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin: 0; }
:is(#reader-overlay, #book-overlay) .preview-card .pl { font-family: var(--jp-font); font-size: 0.9rem; line-height: 1.7; color: var(--text-secondary); margin: 4px 0 0; }
:is(#reader-overlay, #book-overlay) .topic-input {
  width: 100%; border: 1px solid var(--border); border-radius: 11px;
  padding: 13px; font-family: var(--jp-sans); font-size: 1rem; color: var(--text-primary);
  background: var(--color-bg); outline: none;
}
:is(#reader-overlay, #book-overlay) .topic-input:focus { border-color: var(--brand); }
:is(#reader-overlay, #book-overlay) .topic-input::placeholder { color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .suggest { display: flex; flex-wrap: wrap; gap: 7px; }
:is(#reader-overlay, #book-overlay) .suggest .s {
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 13px;
  font-family: var(--jp-sans); font-size: 0.82rem; color: var(--text-secondary); background: var(--color-bg); cursor: pointer;
}
:is(#reader-overlay, #book-overlay) .suggest .s:hover { border-color: var(--brand-tint-strong); }
:is(#reader-overlay, #book-overlay) .suggest .s.on { background: var(--brand-tint); color: var(--brand); border-color: var(--brand-line); }
:is(#reader-overlay, #book-overlay) .list-note { font-size: 0.74rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
:is(#reader-overlay, #book-overlay) .list-note b { color: var(--brand); font-weight: 600; }

/* ============================================================ READER — shared */
:is(#reader-overlay, #book-overlay) .rtop {
  flex: 0 0 auto;
  padding: calc(var(--sat) + 11px) 16px 11px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--border-light);
  z-index: 20;
}
:is(#reader-overlay, #book-overlay) .rtop-inner { display: flex; align-items: center; gap: 14px; max-width: 1180px; margin: 0 auto; width: 100%; }

:is(#reader-overlay, #book-overlay) .meters { display: flex; align-items: center; gap: 13px; flex: 1; min-width: 0; }
:is(#reader-overlay, #book-overlay) .meter { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
:is(#reader-overlay, #book-overlay) .meter .ml { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
:is(#reader-overlay, #book-overlay) .meter .mbar { flex: 1; height: 6px; min-width: 22px; border-radius: 999px; background: var(--border); overflow: hidden; }
:is(#reader-overlay, #book-overlay) .meter .mbar i { display: block; height: 100%; border-radius: 999px; background: var(--brand); transition: width 0.7s cubic-bezier(0.4,0,0.2,1); }
:is(#reader-overlay, #book-overlay) .meter .mv { font-size: 0.74rem; font-weight: 700; color: var(--text-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; }
:is(#reader-overlay, #book-overlay) .meter .mv b { color: var(--brand); }
:is(#reader-overlay, #book-overlay) .meter.newm .mbar i { background: var(--color-accent-new); }
:is(#reader-overlay, #book-overlay) .meter.newm .mv b { color: var(--color-accent-new); }
:is(#reader-overlay, #book-overlay) .meter.done .mv b { color: var(--green); }
:is(#reader-overlay, #book-overlay) .meter.done .mbar i { background: var(--green); }
/* soft-target overage: amber "+N" chip (amber = words you chose to mark). The
   bar stays full + green (target met); the chip carries the "and then some". */
:is(#reader-overlay, #book-overlay) .meter .over-chip {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 800;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--word-locked);
  font-variant-numeric: tabular-nums;
  transform-origin: left center;
  animation: reader-over-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes reader-over-pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
:is(#reader-overlay, #book-overlay) .mdiv { width: 1px; height: 24px; background: var(--border-light); flex: 0 0 auto; }

:is(#reader-overlay, #book-overlay) .rtop-actions { display: none; align-items: center; gap: 8px; flex: 0 0 auto; }
:is(#reader-overlay, #book-overlay) .rtop-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px 8px 9px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--color-bg); font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); cursor: pointer;
}
:is(#reader-overlay, #book-overlay) .rtop-back:hover { border-color: var(--brand-tint-strong); color: var(--brand); }
:is(#reader-overlay, #book-overlay) .rtop-back svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; }
:is(#reader-overlay, #book-overlay) .rtop-title { font-family: var(--jp-sans); font-size: 0.95rem; font-weight: 700; color: var(--text-primary); white-space: nowrap; }
:is(#reader-overlay, #book-overlay) .rtop-chip { font-size: 0.62rem; font-weight: 700; color: var(--brand); background: var(--brand-tint); border-radius: 999px; padding: 3px 9px; }

:is(#reader-overlay, #book-overlay) .modetoggle { display: inline-flex; background: var(--surface); border-radius: 9px; padding: 3px; gap: 2px; }
:is(#reader-overlay, #book-overlay) .modetoggle button {
  border: none; background: none; cursor: pointer; border-radius: 7px;
  padding: 6px 11px; font-family: var(--ui-font); font-size: 0.78rem; font-weight: 600; color: var(--text-secondary);
  display: inline-flex; align-items: center; gap: 5px;
}
:is(#reader-overlay, #book-overlay) .modetoggle button svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.9; }
:is(#reader-overlay, #book-overlay) .modetoggle button.on { background: var(--color-bg); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
:is(#reader-overlay, #book-overlay) .icon-btn {
  width: 38px; height: 38px; border-radius: 999px; border: 1px solid var(--border); background: var(--color-bg);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto;
}
:is(#reader-overlay, #book-overlay) .icon-btn:hover { border-color: var(--brand-tint-strong); }
:is(#reader-overlay, #book-overlay) .icon-btn svg { width: 19px; height: 19px; stroke: var(--text-secondary); fill: none; stroke-width: 1.9; }

:is(#reader-overlay, #book-overlay) .reader-body { flex: 1 1 auto; min-height: 0; display: flex; }
:is(#reader-overlay, #book-overlay) .reading-main { flex: 1 1 auto; min-width: 0; }

/* ---------- reading typography (shared) ---------- */
:is(#reader-overlay, #book-overlay) .ptext { font-family: var(--read-jp); font-size: var(--read-size); line-height: 2.05; color: var(--text-primary); letter-spacing: 0.015em; }
:is(#reader-overlay, #book-overlay) .ptext p { margin: 0 0 1.1rem; text-wrap: pretty; }
:is(#reader-overlay, #book-overlay) .ptext.streaming::after {
  content: ''; display: inline-block; width: 2px; height: 1.1em;
  background: var(--brand); margin-left: 2px; vertical-align: -3px; animation: rdr-caret 0.7s steps(1) infinite;
}
@keyframes rdr-caret { 50% { opacity: 0; } }

/* word states — warm amber */
/* padding gives the tap-target/highlight breathing room; the matching negative
   margin cancels its LAYOUT width so a tokenized word occupies the same inline
   space as the raw streamed text — no reflow jump when the stream tokenizes. */
:is(#reader-overlay, #book-overlay) .w { cursor: pointer; border-radius: 4px; padding: 0 2px; margin: 0 -2px; transition: background 0.18s ease; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
:is(#reader-overlay, #book-overlay) .w:hover { background: var(--brand-tint); }
:is(#reader-overlay, #book-overlay) .w.sel, :is(#reader-overlay, #book-overlay) .w.sel:hover { background: var(--word-sel); }
:is(#reader-overlay, #book-overlay) .w.locked, :is(#reader-overlay, #book-overlay) .w.locked:hover { background: var(--word-locked); }
:is(#reader-overlay, #book-overlay) .w.active-word { outline: 2px solid var(--brand); outline-offset: 1px; }
:is(#reader-overlay, #book-overlay) .w ruby { ruby-position: over; -webkit-ruby-position: before; }
:is(#reader-overlay, #book-overlay) .w rt { font-size: 0.5em; color: var(--brand); font-weight: 600; line-height: 1; letter-spacing: 0; }

/* word tinting — review words (green = in this batch's queue), new words (blue, requires body.new-word-color-on) */
:is(#reader-overlay, #book-overlay) .w.known-word { color: #1a7a1a; opacity: 0.85; }
:is(#reader-overlay, #book-overlay) .w.known-word:hover { opacity: 1; }
body.new-word-color-on :is(#reader-overlay, #book-overlay) .w.known-word.new-word { color: var(--color-accent-new); opacity: 0.85; }
body.new-word-color-on :is(#reader-overlay, #book-overlay) .w.known-word.new-word:hover { opacity: 1; }
/* sel/locked states always override tint color */
:is(#reader-overlay, #book-overlay) .w.known-word.sel,
:is(#reader-overlay, #book-overlay) .w.known-word.locked { color: inherit; opacity: 1; }
/* words that are selectable but NOT in the review queue: no special color */
:is(#reader-overlay, #book-overlay) .w.library-word { color: inherit; opacity: 1; }

/* ============================================================ READER — MOBILE (page-turn) */
:is(#reader-overlay, #book-overlay) .reading-main { position: relative; overflow: hidden; }
:is(#reader-overlay, #book-overlay) .turnstage { position: absolute; inset: 0; overflow: hidden; }

/* ---- measured CSS-column page surface (§3.1) — shared mobile + desktop-paged ---- */
/* The viewport clips to one page; the flow lays the whole batch into columns
   sized to the viewport and is translated horizontally to turn pages. No
   vertical scroll — overflow flows to the next column/page; resize + font-size
   changes re-measure (no char heuristic). */
:is(#reader-overlay, #book-overlay) .colview { position: absolute; inset: 0; overflow: hidden; padding: 28px 22px 22px; background: var(--color-bg); }
:is(#reader-overlay, #book-overlay) .colflow {
  height: 100%;
  column-gap: 0; column-fill: auto;
  transition: transform 0.34s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
/* keep whole words (and their ruby) from splitting across a column break */
:is(#reader-overlay, #book-overlay) .colflow .w { break-inside: avoid; }
:is(#reader-overlay, #book-overlay) .colflow p { break-inside: auto; }
:is(#reader-overlay, #book-overlay) .colflow p:first-child { margin-top: 0; }

/* live-edge margin tab (mobile) */
:is(#reader-overlay, #book-overlay) .edge-tab {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  z-index: 6; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity 0.35s ease;
}
:is(#reader-overlay, #book-overlay) .edge-tab.show { opacity: 1; pointer-events: auto; }
:is(#reader-overlay, #book-overlay) .edge-tab .bar { width: 6px; height: 64px; border-radius: 5px; background: var(--brand); box-shadow: 0 1px 4px color-mix(in oklab, var(--brand) 40%, transparent); }
:is(#reader-overlay, #book-overlay) .edge-tab .arw { width: 26px; height: 26px; border-radius: 999px; background: var(--brand); display: flex; align-items: center; justify-content: center; animation: rdr-tabnudge 2.4s ease-in-out infinite; }
:is(#reader-overlay, #book-overlay) .edge-tab .arw svg { width: 15px; height: 15px; stroke: #fff; fill: none; stroke-width: 2.4; }
@keyframes rdr-tabnudge { 0%,100% { transform: translateX(0); } 50% { transform: translateX(-3px); } }

/* quiet bar (mobile bottom) */
:is(#reader-overlay, #book-overlay) .quietbar {
  flex: 0 0 auto; border-top: 1px solid var(--border-light);
  padding: 9px 12px calc(9px + var(--sab));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; background: var(--color-bg); z-index: 20;
}
:is(#reader-overlay, #book-overlay) .qb-back { justify-self: start; display: inline-flex; align-items: center; gap: 5px; padding: 7px 13px 7px 9px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); cursor: pointer; }
:is(#reader-overlay, #book-overlay) .qb-back:active { background: var(--surface); }
:is(#reader-overlay, #book-overlay) .qb-back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }
:is(#reader-overlay, #book-overlay) .dict-btn {
  justify-self: center; display: inline-flex; align-items: center; gap: 7px;
  background: var(--brand-tint); border: 1px solid var(--brand-line);
  color: var(--brand); border-radius: 999px; padding: 7px 13px;
  font-family: var(--ui-font); font-size: 0.82rem; font-weight: 700; cursor: pointer;
}
:is(#reader-overlay, #book-overlay) .dict-btn:active { background: var(--brand-tint-strong); }
:is(#reader-overlay, #book-overlay) .dict-btn .ico svg { width: 17px; height: 17px; stroke: var(--brand); fill: none; stroke-width: 1.9; }
:is(#reader-overlay, #book-overlay) .dict-btn .ct { font-variant-numeric: tabular-nums; }
:is(#reader-overlay, #book-overlay) .dict-btn .up { width: 13px; height: 13px; stroke: var(--brand); fill: none; stroke-width: 2.4; opacity: 0.7; }
:is(#reader-overlay, #book-overlay) .qb-btn { justify-self: end; width: 36px; height: 36px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
:is(#reader-overlay, #book-overlay) .qb-btn:active { background: var(--surface); }
:is(#reader-overlay, #book-overlay) .qb-btn svg { width: 20px; height: 20px; stroke: var(--text-secondary); fill: none; stroke-width: 1.8; }

/* ---------- word panel (desktop sidebar) ---------- */
:is(#reader-overlay, #book-overlay) .word-panel { display: none; }
:is(#reader-overlay, #book-overlay) .wp-inner { display: flex; flex-direction: column; gap: 14px; }
:is(#reader-overlay, #book-overlay) .wp-def { border: 1px solid var(--border); border-radius: 14px; background: var(--color-bg); padding: 16px; }
:is(#reader-overlay, #book-overlay) .wp-def .dterm { font-family: var(--jp-sans); font-size: 1.7rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
:is(#reader-overlay, #book-overlay) .wp-def .dread { font-family: var(--jp-font); font-size: 0.92rem; color: var(--brand); margin-top: 4px; }
:is(#reader-overlay, #book-overlay) .wp-def .dpos { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin: 13px 0 4px; }
:is(#reader-overlay, #book-overlay) .wp-def .ddef { font-size: 0.98rem; line-height: 1.55; color: var(--text-primary); margin: 0; }
:is(#reader-overlay, #book-overlay) .wp-def .dmark {
  margin-top: 15px; width: 100%; border: 1px solid var(--brand);
  background: var(--brand-tint); color: var(--brand); border-radius: 10px; padding: 11px;
  font-family: var(--ui-font); font-weight: 600; font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
:is(#reader-overlay, #book-overlay) .wp-def .dmark:hover { background: var(--brand-tint-strong); }
:is(#reader-overlay, #book-overlay) .wp-def .dmark.is-marked { background: var(--brand); color: #fff; }
:is(#reader-overlay, #book-overlay) .wp-def .dmark.is-marked:hover { background: var(--brand-press); }
:is(#reader-overlay, #book-overlay) .wp-def .dmark svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.2; }
:is(#reader-overlay, #book-overlay) .wp-def-empty { text-align: center; color: var(--text-muted); padding: 22px 8px; }
:is(#reader-overlay, #book-overlay) .wp-def-empty svg { width: 30px; height: 30px; stroke: var(--text-muted); fill: none; stroke-width: 1.5; opacity: 0.6; margin-bottom: 8px; }
:is(#reader-overlay, #book-overlay) .wp-def-empty p { margin: 0; font-size: 0.85rem; line-height: 1.5; }

:is(#reader-overlay, #book-overlay) .wp-list { border: 1px solid var(--border); border-radius: 14px; background: var(--color-bg); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
:is(#reader-overlay, #book-overlay) .wp-list .lh { display: flex; align-items: baseline; gap: 8px; padding: 13px 15px; border-bottom: 1px solid var(--border-light); }
:is(#reader-overlay, #book-overlay) .wp-list .lh .lt { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); }
:is(#reader-overlay, #book-overlay) .wp-list .lh .lc { font-size: 0.74rem; color: var(--text-muted); margin-left: auto; }
:is(#reader-overlay, #book-overlay) .wp-list .lh .done-tag { font-size: 0.62rem; font-weight: 700; color: var(--brand); }
:is(#reader-overlay, #book-overlay) .list-rows { overflow-y: auto; }
:is(#reader-overlay, #book-overlay) .list-row { display: flex; align-items: center; gap: 10px; padding: 11px 15px; cursor: pointer; border-bottom: 1px solid var(--border-light); }
:is(#reader-overlay, #book-overlay) .list-row:last-child { border-bottom: none; }
:is(#reader-overlay, #book-overlay) .list-row:hover { background: var(--surface-2); }
:is(#reader-overlay, #book-overlay) .list-row.active-row { background: var(--brand-tint); }
:is(#reader-overlay, #book-overlay) .list-row .swatch { width: 7px; height: 28px; border-radius: 4px; flex: 0 0 auto; background: var(--word-locked); }
:is(#reader-overlay, #book-overlay) .list-row .swatch.sess { background: var(--word-sel); }
:is(#reader-overlay, #book-overlay) .list-row .rmid { min-width: 0; }
:is(#reader-overlay, #book-overlay) .list-row .jp { font-family: var(--jp-sans); font-size: 1rem; font-weight: 700; color: var(--text-primary); display: block; }
:is(#reader-overlay, #book-overlay) .list-row .rd { font-family: var(--jp-font); font-size: 0.72rem; color: var(--text-secondary); margin-top: 1px; display: block; }
:is(#reader-overlay, #book-overlay) .list-row .en { margin-left: auto; font-size: 0.74rem; color: var(--text-secondary); max-width: 45%; text-align: right; }
:is(#reader-overlay, #book-overlay) .list-empty { padding: 22px 16px; text-align: center; color: var(--text-muted); font-size: 0.84rem; line-height: 1.5; }

/* ============================================================ DESKTOP SCROLL / PAGES */
:is(#reader-overlay, #book-overlay) .scrollcol { max-width: var(--read-measure); margin: 0 auto; padding: 40px 8px 10px; }
:is(#reader-overlay, #book-overlay) .page-sec { position: relative; }
:is(#reader-overlay, #book-overlay) .page-sec + .page-sec { margin-top: 8px; padding-top: 28px; }
:is(#reader-overlay, #book-overlay) .page-sec + .page-sec::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 46px; height: 2px; border-radius: 2px; background: var(--border);
}
:is(#reader-overlay, #book-overlay) .page-sec.committed .ptext { color: color-mix(in srgb, var(--text-primary) 92%, #fff); }

/* frontier (scroll mode) — repeated high-frequency action, so just a divider
   + the button; the lock-in concept is taught once by the coachmark. */
:is(#reader-overlay, #book-overlay) .frontier { max-width: var(--read-measure); margin: 24px auto 0; padding: 24px 8px 56px; border-top: 1px solid var(--border); }
:is(#reader-overlay, #book-overlay) .write-next {
  width: 100%; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 13px; padding: 16px; cursor: pointer;
  font-family: var(--ui-font); font-size: 1rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  transition: background 0.15s ease;
}
:is(#reader-overlay, #book-overlay) .write-next:hover { background: var(--brand-press); }
:is(#reader-overlay, #book-overlay) .write-next:disabled { opacity: 0.6; cursor: default; }
:is(#reader-overlay, #book-overlay) .write-next svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2.2; }

/* paged mode (desktop) */
:is(#reader-overlay, #book-overlay) .pagestage { height: 100%; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 28px 18px; }
:is(#reader-overlay, #book-overlay) .page-card {
  position: relative; width: 100%; max-width: var(--read-measure); height: 100%;
  background: var(--color-bg); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.05); overflow: hidden;
}
:is(#reader-overlay, #book-overlay) .page-card .colview { padding: 48px 44px 40px; }
:is(#reader-overlay, #book-overlay) .page-card .pageno { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 2; font-family: var(--mono); font-size: 0.66rem; color: var(--text-muted); letter-spacing: 0.1em; }
:is(#reader-overlay, #book-overlay) .pg-nav {
  width: 52px; height: 52px; border-radius: 999px; flex: 0 0 auto;
  border: 1px solid var(--border); background: var(--color-bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
:is(#reader-overlay, #book-overlay) .pg-nav:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-tint); }
:is(#reader-overlay, #book-overlay) .pg-nav:disabled { opacity: 0.3; cursor: default; }
:is(#reader-overlay, #book-overlay) .pg-nav svg { width: 22px; height: 22px; stroke: var(--text-secondary); fill: none; stroke-width: 2; }
:is(#reader-overlay, #book-overlay) .pg-nav:hover:not(:disabled) svg { stroke: var(--brand); }
:is(#reader-overlay, #book-overlay) .pg-nav.is-frontier { border-color: var(--brand); background: var(--brand); animation: rdr-tabnudge 2.4s ease-in-out infinite; }
:is(#reader-overlay, #book-overlay) .pg-nav.is-frontier svg { stroke: #fff; }

/* ============================================================ MOBILE SHEETS + scrim */
:is(#reader-overlay, #book-overlay) .scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.28); opacity: 0; pointer-events: none; transition: opacity 0.34s ease; z-index: 35; }
:is(#reader-overlay, #book-overlay) .scrim.show { opacity: 1; pointer-events: auto; }

:is(#reader-overlay, #book-overlay) .sheet {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--color-bg);
  border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,0.18);
  padding: 10px 20px calc(20px + var(--sab));
  transform: translateY(110%); transition: transform 0.34s cubic-bezier(0.4,0,0.2,1);
  z-index: 40; max-height: 76%; display: flex; flex-direction: column;
}
:is(#reader-overlay, #book-overlay) .sheet.show { transform: translateY(0); }
:is(#reader-overlay, #book-overlay) .sheet .grab { width: 38px; height: 4px; border-radius: 999px; background: var(--border); margin: 0 auto 14px; flex: 0 0 auto; cursor: pointer; }
:is(#reader-overlay, #book-overlay) .sheet-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); margin: 2px 0 6px; }

:is(#reader-overlay, #book-overlay) .sheet .dterm { font-family: var(--jp-sans); font-size: 1.7rem; font-weight: 700; color: var(--text-primary); }
:is(#reader-overlay, #book-overlay) .sheet .dread { font-family: var(--jp-font); font-size: 0.95rem; color: var(--brand); margin-top: 2px; }
:is(#reader-overlay, #book-overlay) .sheet .dpos { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin: 12px 0 4px; }
:is(#reader-overlay, #book-overlay) .sheet .ddef { font-size: 1rem; line-height: 1.55; color: var(--text-primary); margin: 0; }
:is(#reader-overlay, #book-overlay) .sheet .dmark { margin-top: 16px; width: 100%; border: 1px solid var(--brand); background: var(--brand-tint); color: var(--brand); border-radius: 11px; padding: 12px; font-family: var(--ui-font); font-weight: 600; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
:is(#reader-overlay, #book-overlay) .sheet .dmark.is-marked { background: var(--brand); color: #fff; }
:is(#reader-overlay, #book-overlay) .sheet .dmark svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2.2; }

:is(#reader-overlay, #book-overlay) .sheet .lh { display: flex; align-items: baseline; gap: 8px; padding: 0 0 12px; border-bottom: 1px solid var(--border-light); flex: 0 0 auto; }
:is(#reader-overlay, #book-overlay) .sheet .lh .lt { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
:is(#reader-overlay, #book-overlay) .sheet .lh .lc { font-size: 0.8rem; color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .sheet .lh .done-tag { margin-left: auto; font-size: 0.7rem; font-weight: 700; color: var(--brand); }
:is(#reader-overlay, #book-overlay) .sheet .list-rows { padding: 4px 0; margin: 0 -20px; }
:is(#reader-overlay, #book-overlay) .sheet .list-row { padding: 12px 20px; }
:is(#reader-overlay, #book-overlay) .sheet .list-row .jp { font-size: 1.08rem; }

/* settings rows */
:is(#reader-overlay, #book-overlay) .set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--border-light); }
:is(#reader-overlay, #book-overlay) .set-row:last-child { border-bottom: none; }
:is(#reader-overlay, #book-overlay) .set-row .st { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
:is(#reader-overlay, #book-overlay) .set-row .sd { display: block; font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; max-width: 320px; line-height: 1.4; }
:is(#reader-overlay, #book-overlay) .set-row .sval { font-size: 0.86rem; color: var(--text-secondary); font-weight: 600; }
:is(#reader-overlay, #book-overlay) .switch { width: 46px; height: 27px; border-radius: 999px; background: var(--border); position: relative; flex: 0 0 auto; cursor: pointer; transition: background 0.2s ease; }
:is(#reader-overlay, #book-overlay) .switch.on { background: var(--brand); }
:is(#reader-overlay, #book-overlay) .switch i { position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 999px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: left 0.2s ease; }
:is(#reader-overlay, #book-overlay) .switch.on i { left: 22px; }

/* desktop settings modal */
:is(#reader-overlay, #book-overlay) .modal-scrim { position: absolute; inset: 0; background: rgba(20,22,20,0.4); opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 48; display: flex; align-items: center; justify-content: center; }
:is(#reader-overlay, #book-overlay) .modal-scrim.show { opacity: 1; pointer-events: auto; }
:is(#reader-overlay, #book-overlay) .modal {
  width: min(540px, 92vw); background: var(--color-bg); border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.32); padding: 24px;
  transform: translateY(10px) scale(0.98); transition: transform 0.25s ease;
}
:is(#reader-overlay, #book-overlay) .modal-scrim.show .modal { transform: none; }
:is(#reader-overlay, #book-overlay) .modal .sheet-title { font-size: 1.2rem; margin-bottom: 14px; }

/* ---------- first-frontier coachmark ---------- */
:is(#reader-overlay, #book-overlay) .coach-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.34); opacity: 0; pointer-events: none; transition: opacity 0.34s ease; z-index: 45; }
:is(#reader-overlay, #book-overlay) .coach-scrim.show { opacity: 1; pointer-events: auto; }
:is(#reader-overlay, #book-overlay) .coach-card {
  position: absolute; z-index: 46; left: 50%; bottom: calc(100px + var(--sab));
  transform: translateX(-50%) translateY(8px) scale(0.96);
  width: 280px; background: var(--color-bg); border-radius: 16px; box-shadow: 0 20px 54px rgba(0,0,0,0.3);
  padding: 16px 16px 14px; opacity: 0; pointer-events: none; transition: opacity 0.3s ease, transform 0.3s ease;
}
:is(#reader-overlay, #book-overlay) .coach-card.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0) scale(1); }
:is(#reader-overlay, #book-overlay) .coach-card .ct { font-size: 0.92rem; font-weight: 700; color: var(--text-primary); display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
:is(#reader-overlay, #book-overlay) .coach-card .ct svg { width: 18px; height: 18px; stroke: var(--brand); fill: none; stroke-width: 2; }
:is(#reader-overlay, #book-overlay) .coach-card p { margin: 0 0 12px; font-size: 0.84rem; line-height: 1.55; color: var(--text-secondary); }
:is(#reader-overlay, #book-overlay) .coach-card .got { background: var(--brand); color: #fff; border: none; border-radius: 9px; padding: 9px 16px; font-size: 0.85rem; font-weight: 600; cursor: pointer; float: right; }

/* toast */
:is(#reader-overlay, #book-overlay) .toast {
  position: absolute; left: 16px; right: 16px; bottom: calc(80px + var(--sab));
  background: var(--toast-bg); color: #fff; border-radius: 13px; padding: 13px 15px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 14px 40px rgba(0,0,0,0.3); z-index: 30;
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: all 0.34s ease; max-width: 460px; margin: 0 auto;
}
:is(#reader-overlay, #book-overlay) .toast.show { transform: none; opacity: 1; }
:is(#reader-overlay, #book-overlay) .toast svg { width: 20px; height: 20px; stroke: var(--toast-ico); fill: none; stroke-width: 2; flex: 0 0 auto; }
:is(#reader-overlay, #book-overlay) .toast p { margin: 0; font-size: 0.82rem; line-height: 1.45; }
:is(#reader-overlay, #book-overlay) .toast b { color: #fff; }

/* ============================================================ DESKTOP (≥ 768px) */
@media (min-width: 768px) {
  :is(#reader-overlay, #book-overlay) .screen-shelf, :is(#reader-overlay, #book-overlay) .screen-new { background: var(--surface); }
  /* Keep the brand-green bar + white text/icons (matching mobile); only widen
     the horizontal padding to center content at the desktop measure. */
  :is(#reader-overlay, #book-overlay) .screen-shelf .appbar, :is(#reader-overlay, #book-overlay) .screen-new .appbar {
    padding-left: max(24px, calc((100vw - 760px) / 2));
    padding-right: max(24px, calc((100vw - 760px) / 2));
  }
  :is(#reader-overlay, #book-overlay) .screen-shelf .appbar .title, :is(#reader-overlay, #book-overlay) .screen-new .appbar .title { font-size: 1.15rem; }
  :is(#reader-overlay, #book-overlay) .content { padding: 32px max(24px, calc((100vw - 760px) / 2)) 60px; gap: 16px; }

  :is(#reader-overlay, #book-overlay) .screen-shelf .content { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; align-content: start; }
  :is(#reader-overlay, #book-overlay) .screen-shelf .kicker { grid-column: 1 / -1; }
  :is(#reader-overlay, #book-overlay) .continue-card { grid-column: 1 / -1; padding: 22px; }
  :is(#reader-overlay, #book-overlay) .continue-card .story-title { font-size: 1.55rem; }
  :is(#reader-overlay, #book-overlay) .continue-btn { grid-column: 1 / -1; max-width: 280px; }
  :is(#reader-overlay, #book-overlay) .screen-shelf .section-label { grid-column: 1 / -1; }
  :is(#reader-overlay, #book-overlay) .shelf-words-link { grid-column: 1 / -1; }

  :is(#reader-overlay, #book-overlay) .screen-new .content { max-width: 620px; margin: 0 auto; width: 100%; padding: 32px 24px 60px; scrollbar-width: none; }
  :is(#reader-overlay, #book-overlay) .screen-new .content::-webkit-scrollbar { display: none; }
  :is(#reader-overlay, #book-overlay) .begin-btn { max-width: 320px; }

  :is(#reader-overlay, #book-overlay) .quietbar { display: none; }
  :is(#reader-overlay, #book-overlay) .rtop-actions { display: flex; }
  :is(#reader-overlay, #book-overlay) .reading-main { position: static; overflow: visible; }

  :is(#reader-overlay, #book-overlay) .screen-reader .reader-body { overflow-y: auto; }
  :is(#reader-overlay, #book-overlay) .screen-reader .reader-body.is-paged { overflow: hidden; }
  :is(#reader-overlay, #book-overlay) .reader-body { padding: 0 max(24px, calc((100vw - 1180px) / 2)); gap: 32px; align-items: flex-start; }

  :is(#reader-overlay, #book-overlay) .word-panel { display: block; flex: 0 0 300px; width: 300px; position: sticky; top: 24px; align-self: flex-start; padding: 24px 0 32px; }
  :is(#reader-overlay, #book-overlay) .word-panel .wp-list { max-height: 48vh; }

  /* Docked word detail (shared DetailContent) — a self-scrolling card above the
     marked-words list. Empty when no word is selected (no .has-detail). */
  :is(#reader-overlay, #book-overlay) .reader-dict-slot.has-detail {
    display: flex; flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
    max-height: 60vh;
  }

  :is(#reader-overlay, #book-overlay) .reader-body.is-paged .reading-main { height: calc(100dvh - 64px - var(--sat)); }
}

/* mobile top bar: the dual meter is the centerpiece — the story title is
   already shown on the shelf/continue card, so drop it (and the chip) here
   to give the meter full width instead of clipping it off-screen. */
@media (max-width: 767px) {
  :is(#reader-overlay, #book-overlay) .rtop-title, :is(#reader-overlay, #book-overlay) .rtop-chip { display: none; }
  :is(#reader-overlay, #book-overlay) .rtop-inner { gap: 0; }
  :is(#reader-overlay, #book-overlay) .rtop-back { display: none; }
  :is(#reader-overlay, #book-overlay) .qb-back {
    border: 1px solid var(--border); background: var(--color-bg);
    padding: 7px 13px 7px 9px; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
  }
  :is(#reader-overlay, #book-overlay) .qb-back:active { border-color: var(--brand-tint-strong); color: var(--brand); background: var(--color-bg); }

  /* scroll mode on mobile: the default mobile surface is the fixed paged
     turnstage, so let the body scroll vertically and stop clipping the flow. */
  :is(#reader-overlay, #book-overlay) .screen-reader .reader-body.is-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  :is(#reader-overlay, #book-overlay) .reader-body.is-scroll .reading-main { position: static; overflow: visible; }
}

/* ============================================================ READING SETTINGS — segmented controls (gear sheet + modal) */
:is(#reader-overlay, #book-overlay) .set-row-col { flex-direction: column; align-items: stretch; gap: 9px; }
:is(#reader-overlay, #book-overlay) .set-row-col .st { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
:is(#reader-overlay, #book-overlay) .set-seg { display: flex; background: var(--surface); border-radius: 11px; padding: 3px; gap: 3px; }
:is(#reader-overlay, #book-overlay) .set-segbtn {
  flex: 1; border: none; background: none; cursor: pointer; border-radius: 8px; padding: 9px 6px;
  font-family: var(--ui-font); font-size: 0.85rem; font-weight: 600; color: var(--text-secondary);
}
:is(#reader-overlay, #book-overlay) .set-segbtn.on { background: var(--color-bg); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* ============================================================ SHELF — soft-confirm selection */
:is(#reader-overlay, #book-overlay) .continue-card .card-meta { font-size: 0.78rem; color: var(--text-muted); margin: 0 0 12px; }
/* the card no longer activates on tap — only its Continue button does */
:is(#reader-overlay, #book-overlay) .continue-card { cursor: default; }
:is(#reader-overlay, #book-overlay) .continue-card:hover { box-shadow: none; }
:is(#reader-overlay, #book-overlay) .continue-card:active { transform: none; }
:is(#reader-overlay, #book-overlay) .continue-btn { margin-top: 16px; }
/* selected story slot */
:is(#reader-overlay, #book-overlay) .slot.on { border-color: var(--brand-line); background: var(--brand-tint); }
:is(#reader-overlay, #book-overlay) .slot.on .thumb { border-color: var(--brand-line); }
:is(#reader-overlay, #book-overlay) .slot-sel { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 999px; background: var(--brand); display: inline-flex; align-items: center; justify-content: center; }
:is(#reader-overlay, #book-overlay) .slot-sel svg { width: 15px; height: 15px; stroke: #fff; fill: none; stroke-width: 2.6; }
@media (min-width: 768px) {
  :is(#reader-overlay, #book-overlay) .continue-btn { max-width: 280px; }
}

/* ── Word detail bottom sheet (mobile) ───────────────────────────────
   Host spans the viewport so the dict's absolute .detail-backdrop/.detail-sheet
   (styled under .wd-scope) anchor to it. pointer-events:none lets reader taps
   through when closed; the sheet re-enables them so it stays interactive. */
:is(#reader-overlay, #book-overlay) .reader-detail-host {
  position: fixed; inset: 0;
  z-index: 1003;
  pointer-events: none;
}
:is(#reader-overlay, #book-overlay) .reader-detail-host .detail-sheet { pointer-events: auto; }
@media (min-width: 768px) {
  :is(#reader-overlay, #book-overlay) .reader-detail-host { display: none; }
}
