
/* === Theme variables === */
:root, [data-theme="light"] {
  --bg: #fafaf7; --surface: #f0ede6; --border: #d4d0c8;
  /* text gentled from #1a1a1a (17.5:1) to #262626 (13.2:1) — high-contrast
     near-black causes eye fatigue over long reads; ~13:1 is the comfort
     sweet spot for sustained reading (still AAA). */
  --text: #262626; --text-dim: #6e6e6e;
  --accent: #7c4d28; --accent-dim: #a0704a;
  --blockquote-border: #c4b998; --blockquote-bg: rgba(0,0,0,0.02);
  --font-serif: 'Literata', 'Source Serif 4', 'Source Serif Pro', Charter, Georgia, Cambria, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-body: var(--font-serif);
  --font-size: 1.125rem; --line-height: 1.6;
  --page-pad: clamp(20px, 4vw, 64px);
}
[data-theme="dark"] {
  /* Background lifted from #1a1a1e (cool near-black, 14.5:1 contrast — causes
     halation around serif strokes) to #1f1f23 (mid-dark, ~13:1 contrast).
     Eye-strain paradox: lower absolute contrast in this range = more
     comfortable for sustained reading. Matches Safari Reader dark palette. */
  --bg: #1f1f23; --surface: #2a2a2e; --border: #3f3f44;
  --text: #ececec; --text-dim: #a8aab0;
  --accent: #a78bfa; --accent-dim: #7c5cbf;
  --blockquote-border: #5a5a5e; --blockquote-bg: rgba(255,255,255,0.03);
}
[data-theme="sepia"] {
  --bg: #f4ecd8; --surface: #ebe3cc; --border: #c4b598;
  /* text-dim lifted from #7c6a56 (3.6:1, below AA for body) to #5e4d3a
     (~6:1, comfortably above AA). text body kept — the brown-ink-on-cream
     paper aesthetic is intentional. */
  --text: #3e2c1c; --text-dim: #5e4d3a;
  --accent: #7c4d28; --accent-dim: #a0704a;
  --blockquote-border: #c4a882; --blockquote-bg: rgba(0,0,0,0.03);
}
/* === Base === */
* { margin: 0; padding: 0; box-sizing: border-box; }
html {
  hyphens: auto;
  -webkit-hyphens: auto;
  /* Only hyphenate words ≥8 chars with ≥4 chars per side; never two
     consecutive hyphenated lines. Eliminates routine mid-word breaks
     ("be-/come") while keeping the safety valve for overlong loanwords. */
  -webkit-hyphenate-limit-chars: 8 4 4;
  hyphenate-limit-chars: 8 4 4;
  hyphenate-limit-lines: 2;
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  font-family: var(--font-body);
  font-size: var(--font-size);
  line-height: var(--line-height);
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.container { max-width: 100%; margin: 0 auto; padding: 0 var(--page-pad); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
/* === Nav === */
nav { padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem;
      display: flex; align-items: center; gap: 0; flex-wrap: wrap;
      font-family: var(--font-sans); }
nav a { color: var(--text-dim); }
nav a:hover { color: var(--accent); text-decoration: none; }
nav .sep { color: var(--border); margin: 0 8px; }
nav .site-name { font-weight: 600; color: var(--text); }
nav .nav-links { margin-left: auto; display: flex; gap: 16px; align-items: center; }
nav .nav-links a { font-size: 0.82rem; }
nav .breadcrumb { display: flex; align-items: center; gap: 0; }
@media (max-width: 640px) {
  nav { flex-direction: column; align-items: flex-start; gap: 6px; }
  nav .nav-links { margin-left: 0; }
}
/* === Typography === */
h1 { font-family: var(--font-sans); font-size: 1.8rem; font-weight: 700; margin: 32px 0 8px; letter-spacing: -0.02em; }
h2 { font-family: var(--font-sans); font-size: 1.3rem; font-weight: 600; margin: 24px 0 12px; color: var(--accent); }
h3 { font-family: var(--font-sans); font-size: 1.1rem; font-weight: 600; margin: 20px 0 8px; }
p, li { color: var(--text-dim); margin-bottom: 12px; }
.meta { font-family: var(--font-sans); font-size: 0.85rem; color: var(--text-dim); margin-bottom: 16px; }
.meta span { margin-right: 0; }
.meta span + span:before { content: "·"; margin: 0 10px; color: var(--border); }
/* === Tables === */
table { width: 100%; border-collapse: collapse; margin: 16px 0; }
th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border);
     color: var(--text-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
td a { font-weight: 500; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem;
         font-weight: 600; background: var(--surface); border: 1px solid var(--border); }
.badge.record-unknown { border-style: dashed; }
.record-line { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 1rem; }
.site-heading { color: var(--text-dim); font-size: 0.85rem; font-style: italic; margin: -0.25rem 0 1rem; }
.site-heading a { color: inherit; font-style: normal; }
/* === Document content (reading area) === */
.content { padding: 32px 0; max-width: 72ch; }
.content h1 { font-size: 1.5rem; margin: 2.5rem 0 0.75rem; }
.content h2 { font-size: 1.25rem; margin: 2rem 0 0.6rem; }
.content h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.content p { line-height: var(--line-height); margin-bottom: 1.75em; color: var(--text); }
.content h1 { margin-top: 0; }
.content h2 { margin-top: 3.2em; margin-bottom: 0.8em; line-height: 1.2; }
.content h3 { margin-top: 2.4em; margin-bottom: 0.6em; line-height: 1.25; }
.content blockquote { border-left: 3px solid var(--blockquote-border); background: var(--blockquote-bg);
                      padding: 1.2rem 1.5rem; margin: 1.75em 0; color: var(--text); font-style: normal; line-height: var(--line-height); }
.content blockquote + p > em:first-child { font-size: 0.85rem; color: var(--text-dim); }
.content figure.ga-figure { margin: 1.75em 0; text-align: center; }
.content figure.ga-figure img { max-width: 100%; height: auto; }
.content figure.ga-figure figcaption { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.5em; }
.content figure.ga-figure.blackboard a { border: none; }
.content figure.ga-figure.blackboard img { max-height: 32rem; width: auto; }
.content .blackboard-drawings { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.content .blackboard-drawings h2 { margin-top: 0; font-size: 1.2rem; }
.content .blackboard-drawings .bb-lede { font-size: 0.9rem; color: var(--text-dim); }
.content .bb-strip { display: flex; flex-wrap: wrap; gap: 1rem; }
.content .bb-item { width: 12rem; font-size: 0.8rem; color: var(--text-dim); }
.content .bb-item img { display: block; width: 100%; height: auto; border: 1px solid var(--border); }
.content .bb-item span { display: block; margin-top: 0.3rem; }
.content ul, .content ol { margin: 1rem 0 1rem 1.5rem; }
.content li { margin-bottom: 0.5em; color: var(--text); line-height: var(--line-height); }
.content sup { font-size: 0.75em; }
.content .footnote { font-size: 0.85rem; color: var(--text-dim); }
/* === Reading shell (Work page) === */
:root {
  --rail-w: 32px;
  --rail-gap: 40px;
  --content-max: 72rem;        /* shared with .library-index, .library-volume, and .reading-shell */
}
.reading-shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  gap: var(--rail-gap);
  max-width: var(--content-max);
  margin: 0 auto;
  position: relative;
}
/* Inside reading-shell, content fills the 1fr cell. Right edge aligns with
   the right edge of the index pages above; the rail eats from the left only,
   so only one edge moves between index→work — fixes the navigation-jarring
   complaint from 2026-05-14. CPL ≈ 73 in Literata at 18px — at the edge of
   Bringhurst's 75-CPL ceiling but acceptable for navigation consistency. */
.reading-shell .content { max-width: 100%; padding: 32px 0; }
.reading-rail {
  position: sticky;
  top: 64px;
  height: calc(100vh - 96px);
  width: var(--rail-w);
  align-self: start;
}
.rail-track {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  border-left: 1px solid var(--border);
}
.rail-segment {
  flex: var(--flex, 1);
  display: block;
  position: relative;
  text-decoration: none;
}
/* Section-start tick at the top of each segment — the only visible marker
   per segment. The progress fill (.rail-fill) is the primary "where am I"
   indicator. Active segment was previously rendered with a 3px brown
   left-border spanning the segment's full height, which made
   single-section documents (where one segment covers ~all the content)
   look like the rail was already filled on initial load. Now we mark the
   active segment with a small accent dot beside its tick instead. */
.rail-segment::before {
  content: '';
  position: absolute;
  left: -4px; top: 0;
  width: 7px; height: 1px;
  background: var(--border);
  transition: background 120ms ease, height 120ms ease, top 120ms ease;
}
.rail-segment:first-child::before { display: none; }
.rail-segment:hover::before { background: var(--accent-dim); height: 3px; top: -1px; }
.rail-segment[data-active="true"]::before { background: var(--accent); height: 3px; top: -1px; }
.rail-fill {
  position: absolute;
  left: -2px; top: 0;
  width: 4px;
  background: var(--accent);
  pointer-events: none;
  height: 0;                       /* JS sets height % on scroll */
  opacity: 0.7;
  border-radius: 2px;
  transition: height 80ms linear;
}
.rail-tooltip {
  position: absolute;
  left: calc(var(--rail-w) + 4px);
  top: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  white-space: nowrap;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 10;
}
.rail-segment:hover .rail-tooltip { opacity: 1; }
.reading-progress-top {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 50;
  pointer-events: none;
}
.reading-progress-top-fill {
  width: var(--top-progress, 0%);
  height: 100%;
  background: var(--accent);
  opacity: 0.7;
  transition: width 60ms linear;
}
@media (max-width: 767px) {
  .reading-shell { display: block; max-width: 100%; }
  .reading-shell .content { max-width: 100%; }
  .reading-rail { display: none; }
  .reading-progress-top { display: block; }
}
/* === Library index pages === */
.library-index {
  max-width: var(--content-max);
  margin: 0 auto;
}
.library-index table { table-layout: fixed; }
.library-index th:nth-child(1),
.library-index td:nth-child(1) { width: 8em; white-space: nowrap; padding-right: 20px; }
.library-index th:nth-child(3),
.library-index td:nth-child(3) {
  width: 4em;
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.library-index td { padding: 10px 12px; line-height: 1.4; }
.library-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 20px 0 24px;
  font-family: var(--font-sans);
}
.library-jump a {
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.library-jump a:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
}
@media (max-width: 767px) {
  .library-jump { gap: 4px; }
  .library-index td { padding: 8px 6px; font-size: 0.95rem; }
}
/* === Library volume (GA-N) index === */
.library-volume {
  max-width: var(--content-max);
  margin: 0 auto;
}
.library-volume .chapter-row {
  display: grid;
  grid-template-columns: 2.4em 1fr 7em;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.library-volume .chapter-row.subordinate {
  grid-template-columns: 2.4em 1fr 7em;
  padding: 6px 0 6px 28px;
  font-size: 0.92em;
}
.library-volume .chapter-num {
  text-align: right;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-sans);
}
.library-volume .chapter-title { font-weight: 500; }
.library-volume .chapter-title a { color: var(--accent); }
.library-volume .chapter-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
  font-family: var(--font-sans);
}
.library-volume .chapter-length {
  text-align: right;
  color: var(--text-dim);
  font-size: 0.78rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-sans);
  opacity: 0.7;
}
.library-volume .chapter-summary {
  grid-column: 2 / 3;
  margin-top: 6px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-dim);
  max-width: 60ch;
}
.library-volume .chapter-summary[hidden] { display: none; }
.library-volume .section-heading {
  font-size: 1rem;
  font-weight: 600;
  font-style: italic;
  color: var(--text);
  margin: 24px 0 6px;
  padding-left: calc(2.4em + 12px);
}
.library-volume .volume-alt-title {
  font-size: 1.05rem;
  color: var(--text-dim);
  margin-top: -8px;
  margin-bottom: 16px;
  font-style: italic;
}
.library-volume .volume-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 20px;
}
.library-volume .volume-topics a {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 14px;
  font-size: 0.78rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-sans);
}
.library-volume .volume-topics a:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
}
.library-volume .contents-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 24px 0 8px;
}
.library-volume .contents-head h2 { margin: 0; }
.library-volume .md-link {
  font-size: 0.72em;
  color: var(--text-dim);
  margin-left: 6px;
}
@media (max-width: 767px) {
  .library-volume .chapter-row {
    grid-template-columns: 2em 1fr;
    gap: 8px;
  }
  .library-volume .chapter-length {
    grid-column: 2 / 3;
    text-align: left;
    margin-top: 2px;
  }
  .library-volume .chapter-summary { font-size: 0.88rem; }
}
/* === Topic / Concept detail pages === */
.topic-detail {
  max-width: var(--content-max);
  margin: 0 auto;
}
.topic-detail .intro { margin: 24px 0 32px; }
.topic-detail .intro p {
  color: var(--text);
  line-height: var(--line-height);
  margin-bottom: 1.5em;
}
.topic-detail .intro p:last-child { margin-bottom: 0; }
.topic-detail h2 {
  font-family: var(--font-sans);
  font-size: 1.3rem; font-weight: 600;
  margin: 40px 0 12px; color: var(--accent);
}
.topic-detail .section-note {
  font-size: 0.85rem; color: var(--text-dim);
  margin-bottom: 12px; font-family: var(--font-sans);
}
.topic-detail .reading-order { margin: 16px 0 32px; }
.topic-detail .reading-order-row {
  display: grid;
  grid-template-columns: 2.4em 1fr;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.topic-detail .reading-order-row:last-child { border-bottom: none; }
.topic-detail .reading-order-num {
  text-align: right;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.topic-detail .reading-order-title { font-weight: 500; }
.topic-detail .reading-order-title a { color: var(--accent); }
.topic-detail .reading-order-note {
  font-size: 0.92rem;
  color: var(--text-dim);
  line-height: 1.55;
  margin-top: 4px;
  max-width: 60ch;
}
.topic-detail .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}
.topic-detail .concept-chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 0.82rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-decoration: none;
  font-family: var(--font-sans);
}
.topic-detail .concept-chip:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.topic-detail .concept-chip-count {
  margin-left: 6px; opacity: 0.5;
  font-variant-numeric: tabular-nums;
}
.topic-detail .related-chip {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  font-weight: 500;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--text);
}
.topic-detail .related-chip:hover { border-color: var(--accent); text-decoration: none; }
/* Topics index grid */
.topics-grid {
  max-width: var(--content-max);
  margin: 24px auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.topics-grid a {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-decoration: none;
  transition: border-color 0.15s;
}
.topics-grid a:hover { border-color: var(--accent); text-decoration: none; }
.topics-grid h3 { margin: 0 0 6px; color: var(--accent); }
.topics-grid p { margin: 0; font-size: 0.88rem; color: var(--text-dim); line-height: 1.5; }
.topics-intro {
  max-width: var(--content-max);
  margin: 0 auto;
}
@media (max-width: 640px) { .topics-grid { grid-template-columns: 1fr; } }
/* Encyclopedia: denser auto-fit grid — 3 cols at full width, fewer as it narrows. */
.encyclopedia-grid { grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
/* === TOC === */
.toc { margin: 1.5rem 0 2rem; padding: 1rem 1.5rem; border: 1px solid var(--border);
       border-radius: 6px; font-size: 0.9rem; }
.toc summary { font-weight: 600; cursor: pointer; color: var(--text); }
.toc ul { list-style: none; padding-left: 1rem; margin: 0.5rem 0 0; }
.toc li { margin: 0.3em 0; }
.toc a { color: var(--link); text-decoration: none; }
.toc a:hover { text-decoration: underline; }
/* === Footer === */
footer { padding: 32px 0; text-align: center; font-size: 0.82rem; color: var(--text-dim);
         border-top: 1px solid var(--border); margin-top: 48px; font-family: var(--font-sans); }
.section-group { margin: 32px 0; }
.section-header { font-size: 0.85rem; font-weight: 600; text-transform: uppercase;
                  letter-spacing: 0.06em; color: var(--text-dim); padding: 8px 0;
                  border-bottom: 1px solid var(--border); margin-bottom: 8px; }
/* === Reader controls === */
.reader-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
              border-radius: 6px; padding: 4px 10px; font-size: 0.82rem; cursor: pointer;
              font-family: var(--font-sans); }
.reader-btn:hover { border-color: var(--accent); color: var(--text); }
.reader-popup { display: none; position: absolute; right: 0; top: 100%; margin-top: 6px;
                background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
                padding: 16px; z-index: 100; min-width: 240px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.reader-popup.open { display: block; }
.reader-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.reader-row:last-child { margin-bottom: 0; }
.reader-label { font-size: 0.78rem; color: var(--text-dim); font-family: var(--font-sans); }
.reader-toggle { display: flex; gap: 4px; }
.reader-toggle button { background: var(--bg); border: 1px solid var(--border); color: var(--text-dim);
                        border-radius: 4px; padding: 3px 10px; font-size: 0.78rem; cursor: pointer;
                        font-family: var(--font-sans); }
.reader-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="light"] .reader-toggle button.active,
[data-theme="sepia"] .reader-toggle button.active { color: #fff; }
/* === Font size steps === */
/* Flat 1.6 line-height across all size steps. Size scales the absolute
   leading (lh × size); the ratio stays constant so paragraph rhythm is
   consistent regardless of which step the reader picks. */
[data-fontsize="1"] { --font-size: 0.95rem;  --line-height: 1.6; }
[data-fontsize="2"] { --font-size: 1.05rem;  --line-height: 1.6; }
[data-fontsize="3"] { --font-size: 1.125rem; --line-height: 1.6; }
[data-fontsize="4"] { --font-size: 1.25rem;  --line-height: 1.6; }
[data-fontsize="5"] { --font-size: 1.375rem; --line-height: 1.6; }
/* === Reading font toggle === */
[data-font="serif"] { --font-body: var(--font-serif); }
[data-font="sans"] { --font-body: var(--font-sans); }
@media (max-width: 640px) {
  h1 { font-size: 1.4rem; }
}
