/* GraphChinese — /textbook renderer styles (docs/textbook/04-DESIGN.md).
   Mobile-first. Reuses tokens + fonts from assets/styles.css (no new palette);
   only introduces `--tb-*` custom properties for things that don't already
   have a house token (widget stage background, dialogue rail). Dark mode is
   ONE [data-theme="dark"] block at the bottom, per house convention — almost
   everything below already rides existing tokens and needs no override.

   .lesson-h / .md-table are already styled globally in styles.css (used by
   the in-app lesson renderer) — the PHP-ported md() in textbook/index.php
   emits the exact same classes, so prose/table styling is inherited free.
   .hz / ruby (.py-on .hz[data-py]::before) are also global. What's new here
   is textbook-specific layout: measure, dialogue, deep-read accordion,
   widgets, chapter-close, TOC. */

:root {
  --tb-measure: 700px;
  --tb-stage-bg: var(--paper-raised);
}

.tb-main { max-width: var(--tb-measure); margin: 0 auto; padding: 32px 20px 90px; }

/* ── header / kicker / title ─────────────────────────────────────────── */
.tb-head { margin: 0 0 28px; }
.tb-kicker { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-whisper); margin: 0 0 10px; }
.tb-kicker a { color: inherit; }
.tb-title {
  font-family: var(--serif-display); font-weight: 600; line-height: 1.2;
  font-size: clamp(28px, 6vw, 40px); margin: 0 0 10px;
}
.tb-title-zh { font-family: var(--han); color: var(--ink-faded); font-size: 0.72em; }
.tb-summary { font-size: 17px; line-height: 1.7; color: var(--ink-faded); margin: 0; }

/* ── scene header ─────────────────────────────────────────────────────── */
.tb-scene {
  margin: 22px 0 30px; padding: 16px 18px; border-radius: 12px;
  background: var(--paper-raised); border: 1px solid var(--hairline);
  display: grid; gap: 6px;
}
.tb-scene-row { display: flex; gap: 10px; font-size: 14.5px; line-height: 1.5; }
.tb-scene-label { flex: 0 0 auto; min-width: 68px; color: var(--ink-whisper); text-transform: uppercase; letter-spacing: .03em; font-size: 12px; padding-top: 2px; }
.tb-scene-val { color: var(--ink); }

/* ── body / block rhythm ──────────────────────────────────────────────── */
.tb-body { display: flex; flex-direction: column; gap: 26px; }
.tb-prose { font-size: 17px; line-height: 1.85; }
.tb-prose p { margin: 0 0 14px; }
.tb-prose p:last-child { margin-bottom: 0; }
.py-on .tb-prose p { line-height: 2.15; }

/* ── dialogue ─────────────────────────────────────────────────────────── */
.tb-dialogue {
  display: flex; flex-direction: column; gap: 16px;
  padding: 18px 18px 18px 20px; border-left: 3px solid var(--hairline);
  background: var(--paper-raised); border-radius: 0 14px 14px 0;
}
.tb-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.tb-speaker { flex: 0 0 100%; font-size: 12.5px; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-whisper); }
.tb-zh-row { display: inline-flex; align-items: baseline; gap: 8px; }
.tb-zh { font-family: var(--han); font-size: 21px; line-height: 2; color: var(--ink); }
.py-on .tb-zh { line-height: 2.3; }
.tb-en { flex: 0 0 100%; font-size: 14.5px; color: var(--ink-faded); }
.tb-audio-btn { padding: 4px 9px; font-size: 12px; line-height: 1; border-radius: 999px; }
.tb-gnote-wrap, .tb-note-wrap { flex: 0 0 100%; margin-top: 2px; }
.tb-gmark, .tb-nmark {
  display: inline-block; cursor: pointer; font-size: 12.5px; color: var(--azure);
  list-style: none; user-select: none;
}
.tb-gmark::-webkit-details-marker, .tb-nmark::-webkit-details-marker { display: none; }
.tb-nmark { color: var(--ink-faded); font-style: italic; }
.tb-nmark::before { content: '\2733\ '; opacity: .6; }
.tb-gnote, .tb-note { margin-top: 6px; padding: 10px 14px; border-radius: 10px; background: var(--paper); border: 1px solid var(--hairline); font-size: 14.5px; line-height: 1.6; }
.tb-gnote p, .tb-note p { margin: 0 0 8px; }
.tb-gnote p:last-child, .tb-note p:last-child { margin-bottom: 0; }

/* ── deep reads ───────────────────────────────────────────────────────── */
.tb-deep { border: 1px solid var(--hairline); border-radius: 12px; padding: 4px 18px; background: var(--paper); }
.tb-deep summary {
  cursor: pointer; padding: 12px 0; font-family: var(--serif-display); font-weight: 600;
  font-size: 16.5px; color: var(--ink); list-style: none;
}
.tb-deep summary::-webkit-details-marker { display: none; }
.tb-deep summary::before { content: '\25B8\ '; color: var(--azure); }
.tb-deep[open] summary::before { content: '\25BE\ '; }
.tb-deep-body { padding: 2px 0 16px; font-size: 15.5px; line-height: 1.75; }
.tb-deep-body p { margin: 0 0 12px; }
.tb-deep-body p:last-child { margin-bottom: 0; }

/* ── widgets (facade pattern: fixed-height reserve, hydrate on view/tap) ─ */
.tb-widget { margin: 0; border: 1px solid var(--hairline); border-radius: 14px; overflow: hidden; background: var(--tb-stage-bg); }
.tb-widget-stage {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  min-height: 220px; padding: 12px;
}
.tb-widget-strokes .tb-widget-stage { min-height: 264px; }
.tb-widget-egograph .tb-widget-stage { min-height: 360px; }
.tb-widget-sentences .tb-widget-stage { min-height: 160px; justify-content: flex-start; flex-direction: column; align-items: stretch; }
.tb-widget-static { font-family: var(--han); font-size: 84px; color: var(--ink); line-height: 1; }
.tb-widget-caption { padding: 10px 16px 14px; font-size: 13.5px; color: var(--ink-faded); border-top: 1px solid var(--hairline); }
.tb-widget-empty { color: var(--ink-whisper); font-size: 14px; padding: 10px 4px; margin: 0; }
.tb-widget-sent { padding: 8px 4px; border-bottom: 1px solid var(--hairline); }
.tb-widget-sent:last-child { border-bottom: 0; }
.tb-widget-sent-zh { font-family: var(--han); font-size: 17px; line-height: 1.9; }
.tb-widget-sent-en { font-size: 13px; color: var(--ink-faded); margin-top: 2px; }

/* ── checks (ungraded, place-your-bets) ──────────────────────────────── */
.tb-check { border: 1px dashed var(--hairline); border-radius: 12px; padding: 16px 18px; }
.tb-check-prompt { font-size: 16px; line-height: 1.6; margin-bottom: 10px; }
.tb-check-prompt p { margin: 0; }
.tb-check-reveal { font-size: 13.5px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; font-family: inherit; }
.tb-check-reveal:hover { background: rgba(var(--accent-rgb), 0.08); }
.tb-check-answer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--hairline); font-size: 15px; line-height: 1.6; }
.tb-check-answer p { margin: 0; }

/* ── chapter close ────────────────────────────────────────────────────── */
.tb-close { margin-top: 8px; padding: 24px 22px; border-radius: 14px; background: var(--paper-raised); border: 1px solid var(--hairline); }
.tb-close h2 { font-family: var(--serif-display); font-size: 20px; margin: 0 0 14px; }
.tb-newwords { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tb-word-chip { font-family: var(--han); font-size: 17px; padding: 7px 14px; border-radius: 999px; background: var(--paper); border: 1px solid var(--hairline); }
.py-on .tb-word-chip { padding-top: 16px; }
.tb-cta { display: inline-block; }

/* ── table of contents ───────────────────────────────────────────────── */
/* Whole chapter entry is ONE tap target: title, level, summary, and an
   explicit "Read chapter →" affordance all live inside the card link, so
   touch users (no hover cue) can tap anywhere on the entry. */
.tb-toc-empty { color: var(--ink-faded); font-size: 16px; }
.tb-unit { margin: 0 0 34px; }
.tb-unit-h { font-family: var(--serif-display); font-size: 18px; color: var(--ink-faded); margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--hairline); }
.tb-toc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.tb-toc-item { margin: 0; }
.tb-toc-link { display: block; padding: 16px 18px 14px; border: 1px solid var(--hairline); border-radius: 14px;
  background: var(--paper-raised); text-decoration: none; color: var(--ink); transition: border-color .12s ease; }
.tb-toc-link:hover { border-color: var(--azure); }
.tb-toc-link:hover .tb-toc-title { color: var(--azure); }
.tb-toc-link:active { background: var(--paper); }
.tb-toc-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.tb-toc-title { font-family: var(--serif-display); font-weight: 600; font-size: 18px; transition: color .12s ease; }
.tb-toc-zh { font-family: var(--han); color: var(--ink-faded); font-weight: 400; font-size: 0.75em; }
.tb-toc-level { flex: 0 0 auto; font-size: 12.5px; color: var(--ink-whisper); white-space: nowrap; }
.tb-toc-summary { display: block; margin: 6px 0 10px; font-size: 14.5px; color: var(--ink-faded); line-height: 1.55; }
.tb-toc-go { display: inline-block; font-size: 13.5px; font-weight: 600; color: var(--azure); }

/* ── prev/next chapter nav ───────────────────────────────────────────── */
.tb-pagenav { margin-top: 28px; display: flex; flex-direction: column; gap: 10px; }
.tb-pagenav-link { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border: 1px solid var(--hairline);
  border-radius: 12px; background: var(--paper-raised); text-decoration: none; color: var(--ink); transition: border-color .12s ease; }
.tb-pagenav-link:hover { border-color: var(--azure); }
.tb-pagenav-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-whisper); }
.tb-pagenav-title { font-family: var(--serif-display); font-weight: 600; font-size: 16.5px; }
.tb-pagenav-toc { align-self: center; order: 1; padding: 10px 14px; font-size: 14px; color: var(--ink-faded); }
.tb-pagenav-toc:hover { color: var(--ink); }
@media (min-width: 480px) {
  .tb-pagenav { flex-direction: row; align-items: stretch; justify-content: space-between; }
  .tb-pagenav-link { flex: 0 1 44%; }
  .tb-pagenav-toc { order: 0; align-self: center; }
  .tb-pagenav-prev { order: -1; }
  .tb-pagenav-next { margin-left: auto; text-align: right; }
}

/* ── header: compact CTA on phones so the nav stays two rows, not three ─ */
@media (max-width: 759px) {
  .tb-page .nav-actions .btn { padding: 8px 14px; font-size: 14px; }
}

/* ── 404 ──────────────────────────────────────────────────────────────── */
.tb-notfound { text-align: center; padding: 90px 20px; }
.tb-notfound h1 { font-family: var(--serif-display); font-size: 30px; margin: 0 0 12px; }

/* ── breakpoints (match styles.css cadence: 480 / 860) ───────────────── */
@media (min-width: 480px) {
  .tb-scene { display: flex; gap: 22px; }
  .tb-scene-row { flex: 1 1 auto; flex-direction: column; gap: 3px; }
  .tb-scene-label { min-width: 0; }
}
@media (min-width: 860px) {
  .tb-main { padding-top: 48px; }
  .tb-title { font-size: clamp(34px, 4.5vw, 44px); }
  .tb-widget-egograph .tb-widget-stage { min-height: 400px; }
}
@media (max-width: 480px) {
  .tb-main { padding-left: 16px; padding-right: 16px; }
  .tb-close { padding: 20px 16px; }
  .tb-widget-static { font-size: 64px; }
}

/* ══ dark mode — tokens only ═══════════════════════════════════════════ */
:root[data-theme="dark"] {
  --tb-stage-bg: var(--paper-sunken);
}
:root[data-theme="dark"] .tb-check { border-color: rgba(var(--accent-rgb), 0.35); }
:root[data-theme="dark"] .tb-scene,
:root[data-theme="dark"] .tb-dialogue,
:root[data-theme="dark"] .tb-close { box-shadow: none; }
