/* Shared tokens, controls and lesson content blocks for both themes. */
:root {
  --rail-bg: #0C2530;
  --rail-line: #1E3C48;
  --rail-text: #E4EEF1;
  --rail-muted: #9DB6BE;
  --rail-hover: #133442;
  --rail-active: #17414F;
  --rail-accent: #6ED7C2;

  --page: #FFFFFF;
  --surface: #F3F6F8;
  --surface-strong: #E8EEF2;
  --line: #DCE3E8;
  --ink: #0D1B24;
  --muted: #4E5E69;
  --faint: #8C9AA4;

  --accent: #0A7363;
  --accent-ink: #075A4D;
  --accent-tint: #DCF1EC;
  --accent-soft: #9FD3C7;
  --key: #B4440E;
  --key-tint: #FBEADF;
  --skip: #C5CED5;
  --note: #B7791F;
  --note-ink: #7A4A06;
  --note-tint: #FFF5E3;
  --note-mark: #FCE3B4;
  --user-mark: rgba(110, 215, 194, 0.28);
  --user-line: rgba(110, 215, 194, 0.16);
  --user-note-bg: rgba(220, 241, 236, 0.42);
  --para-now-bg: rgba(10, 115, 99, 0.045);

  --code-bg: #0C2530;
  --code-ink: #E3F1EE;
  --float-bg: #0C2530;
  --float-ink: #E4EEF1;
  --float-hover: #17414F;
  --primary-bg: #6ED7C2;
  --primary-ink: #062019;
  --primary-hover: #8BE3D2;
  --key-hover: #F6D9C6;
  --shadow-rgb: 13, 27, 36;
  --backdrop: rgba(12, 37, 48, 0.48);

  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --font-scale: 1;
  --fs-xs: calc(12px * var(--font-scale));
  --fs-sm: calc(13px * var(--font-scale));
  --fs-body: calc(16px * var(--font-scale));
  --fs-h: calc(19px * var(--font-scale));
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p, ol, ul, dl, dd, figure { margin: 0; padding: 0; }
ol, ul { list-style: none; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.num, time { font-variant-numeric: tabular-nums; }
.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.i.is-fill { fill: currentColor; stroke: none; }

/* ---------- Controls ---------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-strong);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.segmented input:checked + span { background: var(--page); color: var(--ink); box-shadow: 0 1px 3px rgba(var(--shadow-rgb), 0.14); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}
.switch[hidden], .primary-btn[hidden], .segmented[hidden] { display: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--skip);
  transition: background-color 180ms var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 180ms var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  flex: none;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: background-color 140ms var(--ease);
}
.icon-btn:hover { background: var(--surface-strong); }
.icon-btn-light { color: var(--rail-text); }
.icon-btn-light:hover { background: rgba(255, 255, 255, 0.1); }

.text-btn {
  border: 0;
  padding: 0;
  background: none;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  transition: color 140ms var(--ease);
}
.text-btn:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
.primary-btn {
  border: 0;
  padding: 7px 14px;
  border-radius: 6px;
  background: var(--primary-bg);
  color: var(--primary-ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 140ms var(--ease);
}
.primary-btn:hover { background: var(--primary-hover); }
.copy-btn {
  border: 0;
  padding: 3px 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  color: #E3F1EE;
  font-size: var(--fs-sm);
  transition: background-color 140ms var(--ease);
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.22); }
.time-btn {
  border: 0;
  padding: 2px 0;
  background: none;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: left;
  line-height: 1.9;
  transition: color 140ms var(--ease);
}
.time-btn:hover { color: var(--accent); }

/* ---------- Search ---------- */
.search { position: relative; }
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search input {
  width: 100%;
  height: 38px;
  padding: 0 40px 0 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: var(--fs-sm);
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); background: var(--page); }
.search input::-webkit-search-cancel-button { display: none; }
.search-key {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  line-height: 20px;
  text-align: center;
  color: var(--muted);
  background: var(--page);
}
.search-panel {
  --fs-xs: calc(12px * var(--font-scale));
  --fs-sm: calc(13px * var(--font-scale));
  --fs-body: calc(16px * var(--font-scale));
  --fs-h: calc(19px * var(--font-scale));
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: max(100%, 600px);
  max-width: calc(100vw - 32px);
  max-height: min(70vh, 640px);
  overflow-y: auto;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(var(--shadow-rgb), 0.16);
  padding: 6px 0;
  z-index: 50;
}
.search-status { padding: 14px 18px; font-size: var(--fs-sm); color: var(--muted); }
.search-toolbar {
  position: sticky;
  top: -6px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--page);
  border-bottom: 1px solid var(--line);
}
.search-scope {
  display: inline-flex;
  padding: 2px;
  border-radius: 7px;
  background: var(--surface-strong);
}
.search-scope-btn {
  border: 0;
  padding: 3px 10px;
  border-radius: 5px;
  background: transparent;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
}
.search-scope-btn.is-on {
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(var(--shadow-rgb), 0.12);
}
.search-count { margin-left: auto; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.search-empty-actions { padding: 0 18px 14px; }
.search-course-group + .search-course-group { border-top: 2px solid var(--line); margin-top: 6px; }
.search-course-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 4px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: 0.01em;
}
.search-course-cur {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-tint);
  font-weight: 600;
}
.search-group + .search-group { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.search-group-title { padding: 8px 18px 4px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); white-space: pre-wrap; }
.search-item {
  display: block;
  width: 100%;
  padding: 8px 18px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: var(--fs-sm);
  line-height: 1.55;
  transition: background-color 120ms var(--ease);
}
.search-item:hover, .search-item[aria-selected="true"] { background: var(--surface); }
.search-item-head { display: flex; gap: 10px; align-items: baseline; }
.search-item-where { font-weight: 600; color: var(--ink); white-space: pre-wrap; }
.search-item-kind { margin-left: auto; color: var(--muted); white-space: nowrap; }
.search-item-snippet { color: var(--muted); overflow-wrap: anywhere; }
.search-item.is-pending .search-item-where { color: var(--muted); }
mark { background: var(--accent-tint); color: var(--accent-ink); border-radius: 2px; padding: 0 1px; }

/* ---------- Lesson list (rail / drawer) ---------- */
.lesson-group { padding: 16px 20px 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--rail-muted); }
.lesson-link {
  display: grid;
  grid-template-columns: calc(40px * var(--font-scale)) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  padding: 8px 20px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
  font-size: var(--fs-sm);
  line-height: 1.5;
  color: var(--rail-text);
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
}
.lesson-link:hover { background: var(--rail-hover); }
.lesson-link[aria-current="page"] { background: var(--rail-active); border-left-color: var(--rail-accent); }
.lesson-link:focus-visible { outline-color: var(--rail-accent); outline-offset: -2px; }
.lesson-prefix { color: var(--rail-muted); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.lesson-title { font-weight: 500; overflow-wrap: anywhere; }
.lesson-min {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--rail-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lesson-done-icon { width: 13px; height: 13px; color: var(--rail-accent); stroke-width: 2.2; }
.lesson-note-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--rail-accent);
  opacity: 0.85;
}
.lesson-link.is-done .lesson-title { color: var(--rail-muted); }
.lesson-link.is-done[aria-current="page"] .lesson-title { color: var(--rail-text); }
.lesson-link.is-pending .lesson-title { color: var(--rail-muted); font-weight: 400; }
.course-select {
  width: 100%;
  min-height: 40px;
  height: calc(40px * max(1, var(--font-scale)));
  padding: 0 12px;
  border: 1px solid var(--rail-line);
  border-radius: 8px;
  background-color: var(--rail-hover);
  color: var(--rail-text);
  font-size: var(--fs-body);
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.course-select:focus-visible { outline-color: var(--rail-accent); }

/* ---------- Document head ---------- */
.doc-loading { color: var(--muted); font-size: var(--fs-sm); padding: 40px 0; text-align: center; }
.doc-title {
  font-size: calc(34px * var(--font-scale));
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.doc-meta {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
  font-size: var(--fs-sm);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.doc-meta > span { white-space: nowrap; }
.doc-meta strong { color: var(--ink); font-weight: 600; }

.doc-actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
.action-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--page);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease), color 140ms var(--ease);
}
.action-pill .i { width: 14px; height: 14px; }
.action-pill:hover { border-color: var(--accent-soft); background: var(--surface); color: var(--ink); }
.action-pill.is-done {
  border-color: var(--accent-soft);
  background: var(--accent-tint);
  color: var(--accent-ink);
  font-weight: 600;
}
.action-pill-play.is-playing {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-ink);
  font-weight: 600;
}
.action-pill:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}
.action-pill:disabled:hover {
  border-color: var(--line);
  background: var(--page);
  color: var(--muted);
}
.media-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--note-tint);
  color: var(--note-ink);
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
}

.resume-bar {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: var(--fs-sm);
}
.resume-label { color: var(--ink); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.resume-ops { display: inline-flex; align-items: center; gap: 12px; margin-left: auto; }
.resume-dismiss { width: 24px; height: 24px; color: var(--muted); }

/* ---------- Overview ---------- */
.overview { margin-top: 36px; padding: 28px 0 8px; border-top: 1px solid var(--line); }
.overview-summary { max-width: 78ch; text-indent: 2em; }
.overview-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 32px;
}
.overview h2, .overview h3, .chapter-tools h3 {
  font-size: var(--fs-body);
  font-weight: 600;
  margin-bottom: 8px;
}
.prereq li { position: relative; padding-left: 18px; font-size: var(--fs-sm); color: var(--muted); line-height: 1.6; }
.prereq li + li { margin-top: 6px; }
.prereq li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
}
.keywords { font-size: var(--fs-sm); line-height: 1.9; color: var(--muted); }
.kw {
  border: 0;
  padding: 0;
  background: none;
  color: var(--ink);
  font-size: var(--fs-sm);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  transition: color 140ms var(--ease), text-decoration-color 140ms var(--ease);
}
.kw:hover { color: var(--accent); text-decoration-color: var(--accent); }
.kw-sep { margin: 0 6px; color: var(--faint); }

/* ---------- Chapter toggle (one per chapter) ---------- */
.chapter-title { font-size: var(--fs-h); line-height: 1.45; font-weight: 600; letter-spacing: -0.01em; }
.chapter-toggle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 26px;
  align-items: start;
  gap: 12px;
  width: 100%;
  border: 0;
  padding: 0;
  background: none;
  text-align: left;
  font: inherit;
  letter-spacing: inherit;
}
.chapter-toggle.no-advice { grid-template-columns: minmax(0, 1fr) 26px; }
.chapter-name { overflow-wrap: anywhere; transition: color 140ms var(--ease); }
.chapter-toggle:hover .chapter-name { color: var(--accent-ink); }
.advice { padding-top: 3px; font-size: var(--fs-sm); font-weight: 600; line-height: 1.6; white-space: nowrap; color: var(--faint); letter-spacing: 0; }
.chapter[data-advice="精读"] .advice { color: var(--accent); }
.chapter[data-advice="略读"] .advice { color: var(--muted); }
.chapter[data-advice="跳过"] .chapter-name { color: var(--muted); font-weight: 500; }
.chev {
  width: 26px;
  height: 26px;
  padding: 5px;
  border-radius: 6px;
  color: var(--muted);
  stroke-width: 1.8;
  transition: transform 200ms var(--ease), background-color 140ms var(--ease);
}
.chapter-toggle:hover .chev { background: var(--surface); }
.chapter.is-open .chev { transform: rotate(180deg); }
.chapter-reason { margin-top: 4px; font-size: var(--fs-sm); color: var(--muted); max-width: 78ch; }
.chapter-reason b { font-weight: 600; color: var(--ink); }

/* ---------- Chapter body ---------- */
.chapter-summary { max-width: 78ch; color: var(--ink); text-indent: 2em; }
.key-moment {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--key-tint);
  color: var(--key);
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: background-color 140ms var(--ease);
}
.key-moment:hover { background: var(--key-hover); }
.key-moment .i { width: 13px; height: 13px; }

.chapter-tools {
  margin-top: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  padding: 20px 22px;
  background: var(--surface);
  border-radius: 8px;
}
.actions li { font-size: var(--fs-sm); }
.actions li + li { margin-top: 6px; }
.actions label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; line-height: 1.6; }
.actions input {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0.28em 0 0;
  border: 1.5px solid var(--faint);
  border-radius: 4px;
  background: var(--page) no-repeat center / 12px;
  cursor: pointer;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
}
.actions input:checked {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-5' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
}
.actions input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }

.ref { margin: 6px 0 4px 26px; }
.ref summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}
.ref summary::-webkit-details-marker { display: none; }
.ref summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 160ms var(--ease);
}
.ref[open] summary::before { transform: rotate(45deg); }
.ref summary:hover { color: var(--accent-ink); }
.ref-body {
  margin-top: 8px;
  padding: 12px 16px;
  border-left: 2px solid var(--note);
  background: var(--page);
  font-size: var(--fs-sm);
  line-height: 1.7;
  display: grid;
  gap: 10px;
}
.ref-label { font-weight: 600; color: var(--note-ink); }

.snip-inline { font-size: var(--fs-sm); line-height: 2; color: var(--muted); overflow-wrap: anywhere; }
.snip-inline code, .snip-terms dt, code.ic {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--page);
  padding: 1px 6px;
  border-radius: 4px;
  overflow-wrap: anywhere;
}
.rich code.ic, .transcript code.ic { background: var(--surface-strong); }
.snip-inline .sep { margin: 0 4px; color: var(--faint); }
.snip-block { position: relative; margin-top: 10px; }
.snip-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.65;
  tab-size: 4;
}
.snip-block .copy-btn { position: absolute; top: 8px; right: 8px; }
.snip-terms { margin-top: 10px; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; font-size: var(--fs-sm); }
.snip-terms dt { align-self: start; max-width: 220px; }
.snip-terms dd { color: var(--muted); line-height: 1.6; }
.snip-notes { margin-top: 10px; }
.snip-notes li { font-size: var(--fs-sm); color: var(--muted); line-height: 1.6; padding-left: 14px; position: relative; }
.snip-notes li + li { margin-top: 6px; }
.snip-notes li::before { content: ""; position: absolute; left: 0; top: 0.7em; width: 6px; height: 1.5px; background: var(--faint); }

/* ---------- Remarks ---------- */
.rich p + p, .rich p + .snip-block, .rich .snip-block + p { margin-top: 8px; }
.rich p { max-width: 78ch; }
.rich-label { font-weight: 600; color: var(--note-ink); }
.companion {
  border-left: 3px solid var(--note);
  background: var(--note-tint);
  border-radius: 0 8px 8px 0;
  padding: 16px 20px 16px 18px;
}
.companion-review { margin-top: 22px; }
.companion-review h2 { color: var(--note-ink); }
.companion-lens { font-weight: 600; color: var(--note-ink); margin-bottom: 4px; }
.review-table { margin-top: 22px; overflow-x: auto; }
.review-table table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); line-height: 1.6; }
.review-table th, .review-table td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.review-table thead th { background: var(--note-tint); color: var(--note-ink); font-weight: 600; border-bottom-color: var(--note); white-space: nowrap; }
.review-table tbody th { font-weight: 600; }

.annot {
  margin: 12px 0 22px;
  max-width: 78ch;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--note);
  font-size: var(--fs-sm);
  line-height: 1.7;
}
.annot-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 4px; }
.annot-head strong { color: var(--note-ink); font-weight: 600; }
.annot-quote {
  border: 0;
  padding: 0;
  background: none;
  font-size: var(--fs-sm);
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--note-mark);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  transition: color 140ms var(--ease);
}
.annot-quote .num { margin-right: 6px; color: var(--note-ink); font-weight: 500; }
.annot-quote:hover { color: var(--ink); }

/* ---------- Transcript & document blocks ---------- */
.transcript { margin-top: 28px; }
.para {
  max-width: 78ch;
  line-height: 1.9;
  text-indent: 2em;
  border-radius: 4px;
  transition: background-color 200ms var(--ease), box-shadow 200ms var(--ease);
}
.para.is-now {
  background: var(--para-now-bg);
  box-shadow: 0 0 0 4px var(--para-now-bg);
}
.transcript > :not(:first-child) { margin-top: 16px; }
.transcript > .para + .para { margin-top: 8px; }
.doc-subh { max-width: 78ch; font-size: calc(17px * var(--font-scale)); font-weight: 600; line-height: 1.45; color: var(--ink); margin-top: 28px !important; }
.doc-subh4 { max-width: 78ch; font-size: var(--fs-body); font-weight: 600; line-height: 1.5; color: var(--muted); margin-top: 20px !important; }
.doc-list { max-width: 78ch; padding-left: 22px; line-height: 1.85; list-style: disc; }
.doc-list.is-ordered { list-style: decimal; }
.doc-list li + li { margin-top: 8px; }
.doc-quote {
  max-width: 78ch;
  margin: 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent-soft);
  background: var(--surface);
  border-radius: 0 6px 6px 0;
  color: var(--ink);
  line-height: 1.85;
}
.doc-quote p + p { margin-top: 8px; }
.doc-quote > :not(:first-child) { margin-top: 10px; }
.doc-quote .frame,
html .chapter-body-inner .doc-quote .frame { margin: 14px 0 4px; width: 100%; max-width: 100%; }
.doc-math {
  max-width: 78ch;
  margin: 18px 0;
  padding: 8px 4px;
  overflow-x: auto;
  overflow-y: hidden;
}
.doc-math .katex-display { margin: 0; }
.doc-imath .katex { font-size: 1.04em; }
.fn-ref { font-size: 0.74em; line-height: 0; vertical-align: super; margin: 0 1px; }
.fn-link {
  border: 0;
  padding: 0 2px;
  background: none;
  color: var(--accent-ink);
  font-weight: 500;
  border-radius: 3px;
}
.fn-link:hover { color: var(--accent); text-decoration: underline; }
.doc-footnotes {
  max-width: 78ch;
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font-size: var(--fs-sm);
  color: var(--muted);
  line-height: 1.75;
}
.doc-footnotes-list { list-style: none; display: grid; gap: 6px; }
.doc-footnote-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 2px 4px;
  border-radius: 4px;
}
.doc-footnote-item.is-flash { animation: flash 1800ms var(--ease); }
.doc-footnote-num {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.doc-footnote-num:hover { color: var(--accent); text-decoration: underline; }
.doc-footnote-body { min-width: 0; overflow-wrap: anywhere; }
.doc-link { color: var(--accent-ink); text-decoration: underline; text-decoration-color: var(--accent-soft); text-underline-offset: 3px; }
.doc-link:hover { color: var(--accent); text-decoration-color: var(--accent); }
.transcript em, .doc-subh em, .doc-subh4 em, .doc-table em { font-style: italic; }
.transcript .snip-block { margin: 18px 0; }
.doc-table { margin: 20px 0; }
.frame.is-tall .frame-img img { width: auto; max-width: 100%; max-height: 78vh; margin: 0 auto; }
.s { border-radius: 3px; transition: background-color 160ms var(--ease), color 160ms var(--ease); }
.s.is-noted { background: var(--note-tint); box-shadow: 0 0 0 1px var(--note-mark); }
.s.is-now { background: var(--accent-tint); color: var(--accent-ink); box-shadow: 0 0 0 2px var(--accent-tint); }
.s.is-noted.is-now { box-shadow: 0 0 0 2px var(--note); }
.s.is-flash { animation: flash 1800ms var(--ease); }
@media (hover: hover) and (pointer: fine) {
  body.is-listening .transcript .s[data-sid] { cursor: pointer; }
  body.is-listening .transcript .s[data-sid]:not(.is-now):not(.is-noted):hover { background: var(--surface); }
}
mark.hl { background: var(--note-mark); color: inherit; padding: 0 1px; border-radius: 2px; box-shadow: inset 0 -2px 0 var(--note); }
mark.uhl {
  background: var(--user-mark);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
  box-shadow: inset 0 -2px 0 var(--accent);
  cursor: pointer;
}
.s.is-user-marked {
  background: var(--user-line);
  box-shadow: inset 0 -2px 0 var(--accent-soft);
}
.user-note {
  margin: 10px 0 18px;
  max-width: 78ch;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--user-note-bg);
  border-radius: 0 6px 6px 0;
  font-size: var(--fs-sm);
  line-height: 1.65;
}
.user-note.is-frame-note { margin: 10px 0 0; max-width: none; }
.user-note-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-bottom: 4px;
}
.user-note-head strong { color: var(--accent-ink); font-weight: 600; }
.user-note-ops { margin-left: auto; display: inline-flex; gap: 10px; }
.user-note-quote { color: var(--muted); font-size: var(--fs-xs); margin-bottom: 4px; }
.text-btn.is-danger { color: var(--key); }
.frame-note-btn.is-saved,
.lightbox .lightbox-note.is-saved { color: #6ED7C2; }
.frame-note-btn.is-saved { color: var(--accent-ink); font-weight: 600; }

/* ---------- Selection bar & Note/Export dialogs ---------- */
.sel-bar {
  position: fixed;
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 8px;
  background: var(--float-bg);
  color: var(--float-ink);
  box-shadow: 0 10px 28px rgba(var(--shadow-rgb), 0.28);
}
.sel-bar[hidden] { display: none; }
.sel-btn {
  border: 0;
  padding: 5px 11px;
  border-radius: 6px;
  background: transparent;
  color: var(--float-ink);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
}
.sel-btn:hover { background: var(--float-hover); }
.sel-btn.is-danger { color: #FCA58B; }

.note-dialog,
.export-dialog {
  width: min(560px, calc(100vw - 28px));
  max-width: none;
  max-height: 90vh;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 20px 56px rgba(var(--shadow-rgb), 0.22);
}
.export-dialog { width: min(720px, calc(100vw - 28px)); }
.note-dialog::backdrop,
.export-dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.note-dialog-form { display: flex; flex-direction: column; gap: 12px; }
.note-dialog-title,
.export-title { font-size: var(--fs-h); font-weight: 600; }
.note-dialog-quote {
  margin: 0;
  padding: 8px 12px;
  border-left: 2px solid var(--accent-soft);
  background: var(--surface);
  border-radius: 0 6px 6px 0;
  font-size: var(--fs-sm);
  color: var(--muted);
  max-height: 110px;
  overflow-y: auto;
}
.note-preview-meta { display: block; margin-bottom: 6px; font-size: var(--fs-xs); color: var(--accent-ink); font-weight: 600; }
.note-dialog-input,
.export-preview {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: var(--fs-sm);
  line-height: 1.6;
  resize: vertical;
}
.note-dialog-input:focus,
.export-preview:focus { outline: none; border-color: var(--accent); background: var(--page); }
.note-dialog-actions,
.export-foot { display: flex; align-items: center; gap: 14px; }
.note-dialog-spacer,
.export-spacer { flex: 1; }
.export-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.export-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.export-tab {
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--surface);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
}
.export-tab.is-on {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-ink);
  font-weight: 600;
}
.export-preview {
  height: min(48vh, 380px);
  font-family: var(--font-mono);
  font-size: calc(12.5px * var(--font-scale));
  line-height: 1.55;
  margin-bottom: 14px;
}
.export-count { font-size: var(--fs-sm); color: var(--muted); }
@keyframes flash {
  0%, 40% { background-color: var(--key-tint); box-shadow: 0 0 0 3px var(--key-tint); }
  100% { background-color: transparent; box-shadow: 0 0 0 3px transparent; }
}

/* ---------- Frames ---------- */
.frame { margin: 28px 0; max-width: 100%; }
.frame.is-flash img { animation: frameflash 1800ms var(--ease); }
@keyframes frameflash {
  0%, 40% { box-shadow: 0 0 0 4px var(--key); }
  100% { box-shadow: 0 0 0 4px transparent; }
}
.frame-img {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: zoom-in;
}
.frame-img img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: opacity 160ms var(--ease);
}
.frame-img:hover img { opacity: 0.92; }
.frame-cap { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; font-size: var(--fs-sm); color: var(--muted); }
.frame-title { flex: 1 1 100%; color: var(--ink); font-weight: 500; line-height: 1.5; }
.ocr {
  margin: 10px 0 0;
  padding: 14px 16px;
  border-left: 2px solid var(--accent-soft);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
  max-height: 320px;
  overflow-y: auto;
}
.dup-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 14px 0 4px;
  padding: 3px 10px 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-sm);
  color: var(--muted);
  transition: color 140ms var(--ease), border-color 140ms var(--ease);
}
.dup-tag .i { width: 10px; height: 10px; }
.dup-tag:hover { color: var(--accent-ink); border-color: var(--accent-soft); }
.dup-time { color: var(--faint); }

/* ---------- References ---------- */
.doc-refs {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  max-width: 78ch;
}
.doc-refs-title {
  font-size: var(--fs-h);
  font-weight: 600;
  margin-bottom: 12px;
}
.doc-refs-group + .doc-refs-group { margin-top: 16px; }
.doc-refs-group-title {
  font-size: var(--fs-body);
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--ink);
}
.doc-refs-list {
  padding-left: 20px;
  list-style: disc;
  font-size: var(--fs-sm);
  line-height: 1.75;
  color: var(--muted);
}
.doc-refs-list li + li { margin-top: 6px; }
.doc-refs-list li { overflow-wrap: anywhere; }

/* ---------- Lesson pager ---------- */
.lesson-pager {
  margin-top: 36px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.pager-btn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--page);
  text-align: left;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.pager-btn:hover { border-color: var(--accent-soft); background: var(--surface); }
.pager-btn.is-next { align-items: flex-end; text-align: right; }
.pager-dir {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.pager-dir .i { width: 15px; height: 15px; }
.pager-title {
  font-size: calc(15px * var(--font-scale));
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
  overflow-wrap: anywhere;
  transition: color 140ms var(--ease);
}
.pager-btn:hover .pager-title { color: var(--accent-ink); }

/* ---------- Empty and pending ---------- */
.empty { padding-top: 12vh; max-width: 560px; }
.empty h1 { font-size: calc(30px * var(--font-scale)); line-height: 1.3; font-weight: 700; letter-spacing: -0.02em; }
.empty p { margin-top: 16px; color: var(--muted); }
.empty-list { margin-top: 28px; border-top: 1px solid var(--line); }
.empty-list button {
  display: grid;
  grid-template-columns: calc(48px * var(--font-scale)) minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  font-size: var(--fs-sm);
  transition: color 140ms var(--ease);
}
.empty-list button:hover { color: var(--accent); }
.empty-list .num { color: var(--muted); }
.catalog { margin-top: 36px; columns: 2; column-gap: 40px; }
.catalog section { break-inside: avoid; padding-bottom: 20px; }
.catalog h2 { font-size: var(--fs-body); font-weight: 600; margin-bottom: 6px; }
.catalog li { font-size: var(--fs-sm); color: var(--muted); line-height: 1.7; display: grid; grid-template-columns: calc(40px * var(--font-scale)) minmax(0, 1fr); }

/* ---------- Lightbox ---------- */
.lightbox {
  width: min(1400px, 94vw);
  max-width: none;
  max-height: 94vh;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #0A1A21;
  color: #E4EEF1;
}
.lightbox::backdrop { background: rgba(6, 16, 21, 0.78); }
.lightbox-inner { display: flex; flex-direction: column; max-height: 94vh; }
.lightbox img { display: block; width: 100%; height: auto; max-height: calc(94vh - 64px); object-fit: contain; background: #000; }
.lightbox-bar { display: flex; align-items: center; gap: 18px; padding: 14px 18px; font-size: var(--fs-sm); }
.lightbox-time { color: #6ED7C2; font-weight: 600; white-space: pre; }
.lightbox-spacer { flex: 1; }
.lightbox .text-btn { color: #E4EEF1; }

/* ---------- Auth dialog ---------- */
.auth-dialog {
  width: min(360px, calc(100vw - 32px));
  max-width: none;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 20px 56px rgba(var(--shadow-rgb), 0.22);
}
.auth-dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-title { font-size: var(--fs-h); font-weight: 600; }
.auth-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: max(16px, var(--fs-body));
}
.auth-input:focus { outline: none; border-color: var(--accent); background: var(--page); }
.auth-err { font-size: var(--fs-sm); color: var(--key); }
.auth-submit { height: 40px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  padding: 9px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--page);
  font-size: var(--fs-sm);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (hover: none), (pointer: coarse) {
  .search-key { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Appearance popover (both themes) ---------- */
.topbar {
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-body: 16px;
  --fs-h: 19px;
}
.crumb, .read-bar, .sonnet-aside { display: none; }
.appearance { position: relative; flex: none; }
.appearance-btn { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.appearance-btn[aria-expanded="true"] { background: var(--surface-strong); }
.appearance-pop {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 52;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(var(--shadow-rgb), 0.16);
}
.appearance-pop[hidden] { display: none; }
.appearance-row { display: grid; grid-template-columns: 30px auto; align-items: center; gap: 10px; }
.appearance-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.appearance-pop .segmented { justify-self: start; }
.appearance-pop .segmented span { padding: 5px 12px; }
.scale-control {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-strong);
}
.scale-btn,
.scale-value {
  border: 0;
  border-radius: 6px;
  font-size: var(--fs-sm);
  line-height: 1.5;
  white-space: nowrap;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.scale-btn {
  padding: 5px 12px;
  background: transparent;
  font-weight: 600;
  color: var(--muted);
}
.scale-btn:hover:not(:disabled) { color: var(--ink); background: rgba(var(--shadow-rgb), 0.06); }
.scale-btn:disabled { opacity: 0.36; cursor: not-allowed; }
.scale-value {
  min-width: 62px;
  padding: 5px 10px;
  background: var(--page);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
  box-shadow: 0 1px 3px rgba(var(--shadow-rgb), 0.14);
}
.scale-value.is-default { cursor: default; }
.scale-value:not(.is-default):hover { color: var(--accent-ink); }

/* ---------- Night scheme (Opus tokens; Sonnet overrides in its own sheet) ---------- */
html[data-scheme="dark"] {
  color-scheme: dark;
  --rail-bg: #0B1C23;
  --rail-line: #1C333D;
  --rail-text: #DCE7EA;
  --rail-muted: #8FA6AE;
  --rail-hover: #11272F;
  --rail-active: #163540;
  --rail-accent: #5FCDB7;

  --page: #10191E;
  --surface: #17232A;
  --surface-strong: #1F2E36;
  --line: #273841;
  --ink: #E2EBEE;
  --muted: #9DB0B8;
  --faint: #6C808A;

  --accent: #4CC2AA;
  --accent-ink: #84DBC9;
  --accent-tint: rgba(76, 194, 170, 0.15);
  --accent-soft: #2E7466;
  --key: #F0905F;
  --key-tint: rgba(240, 144, 95, 0.15);
  --key-hover: rgba(240, 144, 95, 0.25);
  --skip: #34464F;
  --note: #D3A04A;
  --note-ink: #E9C47F;
  --note-tint: rgba(211, 160, 74, 0.10);
  --note-mark: rgba(211, 160, 74, 0.34);
  --user-mark: rgba(76, 194, 170, 0.26);
  --user-line: rgba(76, 194, 170, 0.12);
  --user-note-bg: rgba(76, 194, 170, 0.08);
  --para-now-bg: rgba(76, 194, 170, 0.06);

  --code-bg: #0A1418;
  --code-ink: #D6E6E3;
  --float-bg: #22333C;
  --float-ink: #E2EBEE;
  --float-hover: #2D424C;
  --primary-bg: #4CC2AA;
  --primary-ink: #04201A;
  --primary-hover: #6ED7C2;
  --shadow-rgb: 0, 0, 0;
  --backdrop: rgba(0, 0, 0, 0.6);
}
html[data-scheme="dark"] .segmented input:checked + span,
html[data-scheme="dark"] .scale-value { background: var(--line); box-shadow: none; }
html[data-scheme="dark"] .scale-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
html[data-scheme="dark"] .search-scope-btn.is-on { background: var(--line); box-shadow: none; }
html[data-scheme="dark"] .snip-block pre { border: 1px solid var(--line); }
html[data-scheme="dark"] .sel-bar { border: 1px solid var(--line); }
html[data-scheme="dark"] .sel-btn.is-danger { color: #F7A487; }
html[data-scheme="dark"] .switch-track::after { background: #E8EEF0; }
html[data-scheme="dark"] .actions input:checked { border-color: var(--accent); }
html[data-scheme="dark"] .frame-img img {
  filter: brightness(0.92) contrast(0.98);
  transition: filter 160ms var(--ease), opacity 160ms var(--ease);
}
html[data-scheme="dark"] .frame-img:hover img,
html[data-scheme="dark"] .frame-img:focus-visible img { filter: none; opacity: 1; }
