/* ============================================================
   Title:  Stylesheet for the Traditional Chinese web edition
   File:   lda_book_zh.css
   Author: HTYu (built with Claude)
   Date:   2026-08-25
   ============================================================
   A screen adaptation of the printed Chinese edition's identity, not a
   facsimile of it. What carries over: the book's six-colour palette
   (LDA_style_zh.sty's \definecolor lines, unchanged), Noto Serif TC for
   body text (the print edition's 思源宋體), Noto Sans TC for box titles and
   UI furniture, the six pedagogical box types, booktabs-style rules, and
   the 2em first-line indent Chinese prose expects. What does not: A4 page
   geometry, the 1.38 print leading (screen wants more), and the print
   edition's rotated 橫置 figure -- a scrolling page has no reason to turn
   anything sideways.
   ============================================================ */

/* ---------- tokens ---------- */
:root {
  --lda-blue:   #0072B2;
  --lda-green:  #1B7F5C;
  --lda-orange: #C15A00;
  --lda-purple: #7A4FA3;
  --lda-red:    #B23A48;
  --lda-gray:   #4D4D4D;

  --tint-blue:   #EAF2F8;
  --tint-green:  #EAF4EF;
  --tint-orange: #FBF0E6;
  --tint-purple: #F3EEF8;
  --tint-red:    #FAEDEF;
  --tint-gray:   #F2F2F2;

  --ink:        #1A1A1A;
  --ink-soft:   #4A4A4A;
  --ink-faint:  #767676;
  --page:       #FFFFFF;
  --surface:    #F8F9FA;
  --surface-2:  #F1F3F5;
  --rule:       #E1E4E8;
  --rule-strong:#B8BDC4;

  --serif: "Noto Serif TC", "Noto Serif CJK TC", "Palatino Linotype",
           "Book Antiqua", Palatino, "Songti TC", "PMingLiU", "新細明體", serif;
  --sans:  "Noto Sans TC", "Noto Sans CJK TC", "Helvetica Neue", Helvetica,
           Arial, "PingFang TC", "Microsoft JhengHei", "微軟正黑體", sans-serif;
  --mono:  "SFMono-Regular", Menlo, Consolas, "DejaVu Sans Mono",
           "Noto Sans Mono CJK TC", monospace;

  --measure: 44rem;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, .07);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .10);
}

/* The 339 figures are vector/raster art authored against white paper, so a
   dark page cannot simply invert. Dark mode therefore darkens the page
   furniture and keeps every figure, table and code block on its own light
   card -- the same relationship the printed page has between paper and ink,
   scaled down to the figure. */
@media (prefers-color-scheme: dark) {
  :root {
    --ink:        #E8EAED;
    --ink-soft:   #B8BDC4;
    --ink-faint:  #8A9099;
    --page:       #14171A;
    --surface:    #1B1F23;
    --surface-2:  #22262B;
    --rule:       #2E343A;
    --rule-strong:#454C54;

    --lda-blue:   #4BA6E0;
    --lda-green:  #46B78C;
    --lda-orange: #E08A3C;
    --lda-purple: #A98BD0;
    --lda-red:    #DF7280;
    --lda-gray:   #9BA1A8;

    --tint-blue:   #15242E;
    --tint-green:  #14251F;
    --tint-orange: #2A1F14;
    --tint-purple: #211C2B;
    --tint-red:    #2A1A1D;
    --tint-gray:   #1F2226;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.95;
  font-feature-settings: "kern" 1;
  text-rendering: optimizeLegibility;
}

.site-shell { max-width: 100%; }

a { color: var(--lda-blue); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: .18em; }

/* ---------- site header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: baseline;
  gap: .9rem;
  flex-wrap: wrap;
  padding: .7rem clamp(1rem, 4vw, 2.4rem);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  -webkit-backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.site-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.06rem;
  letter-spacing: .04em;
  color: var(--ink);
}
.site-title:hover { color: var(--lda-blue); text-decoration: none; }
.site-subtitle {
  margin: 0;
  font-family: var(--sans);
  font-size: .78rem;
  line-height: 1.5;
  color: var(--ink-faint);
  letter-spacing: .02em;
}

/* ---------- chapter navigation ---------- */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  max-width: 72rem;
  margin: 1.1rem auto;
  padding: 0 clamp(1rem, 4vw, 2.4rem);
  font-family: var(--sans);
  font-size: .82rem;
}
.chapter-nav a, .chapter-nav span {
  padding: .42rem .78rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chapter-nav .nav-prev { justify-self: start; }
.chapter-nav .nav-next { justify-self: end; }
.chapter-nav .nav-toc {
  justify-self: center;
  border-color: transparent;
  background: transparent;
  color: var(--ink-faint);
  letter-spacing: .03em;
}
.chapter-nav a:hover {
  border-color: var(--lda-blue);
  color: var(--lda-blue);
  text-decoration: none;
}
.chapter-nav .nav-disabled { color: var(--ink-faint); opacity: .55; }
.chapter-nav.bottom { margin-top: 2.6rem; margin-bottom: 2.6rem; }

/* ---------- chapter body ---------- */
main { padding: 0 clamp(1rem, 4vw, 2.4rem); }

.chapter {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.4rem 0 2rem;
}

.chapter-header { margin-bottom: 2.4rem; }
.chapter-kicker {
  margin: 0 0 .5rem;
  font-family: var(--sans);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--lda-blue);
}
.chapter h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4.4vw, 2.5rem);
  line-height: 1.42;
  font-weight: 700;
  letter-spacing: .01em;
}
.epigraph {
  margin: 1.5rem 0 0;
  padding-left: 1.1rem;
  border-left: 3px solid var(--rule-strong);
  color: var(--ink-soft);
  font-size: .95rem;
  line-height: 1.9;
  text-indent: 0;
}

h2, h3 {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.5;
  scroll-margin-top: 4.5rem;
}
h2 {
  margin: 3rem 0 1rem;
  padding-bottom: .4rem;
  font-size: 1.42rem;
  border-bottom: 1px solid var(--rule);
}
h2.unnum { border-bottom-color: var(--rule-strong); }
h3 { margin: 2.1rem 0 .7rem; font-size: 1.13rem; color: var(--ink-soft); }

p { margin: 0 0 1.05em; text-indent: 2em; text-align: justify; text-justify: inter-ideograph; }
/* Furniture is never indented prose. */
p.epigraph, p.box-title, p.fig-note, p.tab-note, p.table-caption,
p.ref-entry, p.page-toc-title, p.missing-figure, .site-footer p, li p { text-indent: 0; }

/* ---------- inline ---------- */
strong.keyterm { font-weight: 700; color: var(--ink); }
.en-gloss { font-family: var(--sans); font-size: .86em; color: var(--ink-faint); margin: 0 .1em; }
.boxname, .sans { font-family: var(--sans); }
.smallcaps { font-variant: small-caps; letter-spacing: .04em; }
.pkg { font-family: var(--mono); font-size: .9em; color: var(--lda-purple); }
code, code.dataset {
  font-family: var(--mono);
  font-size: .87em;
  padding: .1em .34em;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink);
  word-break: break-word;
}
/* xeCJK inserts glue between a Latin run and an adjacent CJK glyph; the
   source relies on it, writing 表~\ref{tab:families}以及 with no space after
   the number. HTML has no such glue, so the number gets its own small
   margins (70 refs across the book sit directly against a CJK character). */
a.xref { font-variant-numeric: tabular-nums; margin: 0 .1em; }
a.cite { color: var(--ink); border-bottom: 1px dotted var(--rule-strong); }
a.cite:hover { color: var(--lda-blue); border-bottom-color: var(--lda-blue); text-decoration: none; }

.tnote {
  display: block;
  margin: .6em 0;
  padding: .7em 1em;
  border-left: 3px solid var(--lda-gray);
  background: var(--tint-gray);
  border-radius: 0 6px 6px 0;
  font-size: .88em;
  line-height: 1.85;
  text-indent: 0;
}
.tnote-label { font-weight: 700; }

/* ---------- on-this-page ---------- */
.page-toc {
  margin: 0 0 2.4rem;
  padding: 1.05rem 1.3rem .95rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-family: var(--sans);
}
.page-toc-title {
  margin: 0 0 .55rem;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--ink-faint);
}
.page-toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  columns: 2;
  column-gap: 1.8rem;
  font-size: .87rem;
  line-height: 1.85;
}
.page-toc li { break-inside: avoid; }
.page-toc a { color: var(--ink-soft); }
.page-toc a:hover { color: var(--lda-blue); }
@media (max-width: 640px) { .page-toc ol { columns: 1; } }

/* ---------- pedagogical boxes ---------- */
.box {
  margin: 1.9rem 0;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--lda-gray);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--tint-gray);
  overflow: hidden;
}
.box-title {
  margin: 0;
  padding: .68rem 1.15rem;
  font-family: var(--sans);
  font-size: .88rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--lda-gray);
  border-bottom: 1px solid color-mix(in srgb, var(--rule) 70%, transparent);
}
.box-bullet { opacity: .5; margin: 0 .15em; }
.box-body { padding: .95rem 1.15rem .4rem; font-size: .95rem; }
.box-body > :last-child { margin-bottom: .8rem; }

.box-foundations { border-left-color: var(--lda-blue);   background: var(--tint-blue); }
.box-foundations .box-title { color: var(--lda-blue); }
.box-practice    { border-left-color: var(--lda-green);  background: var(--tint-green); }
.box-practice .box-title { color: var(--lda-green); }
.box-pitfall     { border-left-color: var(--lda-red);    background: var(--tint-red); }
.box-pitfall .box-title { color: var(--lda-red); }
.box-software    { border-left-color: var(--lda-purple); background: var(--tint-purple); }
.box-software .box-title { color: var(--lda-purple); }
.box-objectives  { border-left-color: var(--lda-orange); background: var(--tint-orange); }
.box-objectives .box-title { color: var(--lda-orange); }
.box-summary     { border-left-color: var(--lda-gray);   background: var(--surface); }
.box-summary .box-title { color: var(--ink-soft); }

/* A hand-written \begin{tcolorbox} rather than one of the six macros -- in
   this edition only Ch2's 倫理提示 box. The converter passes the palette entry
   it named in colframe as --box-accent (a var(), not a frozen hex), so the
   tint is derived here against the current page colour and the whole thing
   flips correctly in dark mode like every other box. */
.box-custom { border-left-color: var(--box-accent, var(--lda-gray));
              background: color-mix(in srgb, var(--box-accent, var(--lda-gray)) 9%, var(--page)); }
.box-custom .box-title { color: var(--box-accent, var(--lda-gray)); }

/* ---------- figures ---------- */
.lda-figure { margin: 2.2rem 0; }
.lda-figure img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;                 /* keeps line art readable in dark mode */
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: .5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s ease;
}
.lda-figure a:hover img { box-shadow: var(--shadow-md); }
figcaption {
  margin-top: .8rem;
  font-family: var(--sans);
  font-size: .85rem;
  line-height: 1.8;
  color: var(--ink-soft);
}
figcaption strong { color: var(--ink); }
.fig-note, .tab-note {
  margin: .5rem 0 0;
  font-family: var(--sans);
  font-size: .79rem;
  line-height: 1.8;
  color: var(--ink-faint);
}
.missing-figure {
  padding: 2rem; text-align: center; color: var(--lda-red);
  border: 1px dashed var(--lda-red); border-radius: var(--radius);
}

/* ---------- tables ---------- */
.table-wrap { margin: 2.2rem 0; scroll-margin-top: 4.5rem; }
.table-caption {
  margin: 0 0 .7rem;
  font-family: var(--sans);
  font-size: .85rem;
  line-height: 1.8;
  color: var(--ink-soft);
}
.table-caption strong { color: var(--ink); }
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--page);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: .82rem;
  line-height: 1.75;
}
thead th {
  padding: .7rem .85rem;
  text-align: left;
  vertical-align: bottom;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 2px solid var(--rule-strong);
  background: var(--surface);
}
tbody td {
  padding: .6rem .85rem;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }

/* ---------- glossary ---------- */
.glossary { margin-top: 3rem; }
.glossary-table tbody td:nth-child(2) {
  font-family: var(--sans);
  color: var(--ink-soft);
}

/* ---------- equations ---------- */
.equation {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1rem;
  margin: 1.6rem 0;
  scroll-margin-top: 4.5rem;
}
.equation-math { overflow-x: auto; }
.equation-num { font-family: var(--sans); font-size: .85rem; color: var(--ink-faint); }
mjx-container { max-width: 100%; }
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; }

/* ---------- code ---------- */
pre.r-code {
  margin: 1.7rem 0;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--lda-purple);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: var(--mono);
  font-size: .8rem;
  line-height: 1.75;
  color: var(--ink);
  tab-size: 2;
}
pre.r-code code { background: none; padding: 0; font-size: inherit; }
.c-com { color: var(--ink-faint); font-style: italic; }
.c-str { color: var(--lda-green); }
.c-kw  { color: var(--lda-purple); font-weight: 600; }

/* ---------- lists ---------- */
ol, ul { padding-left: 1.6em; }
li { margin-bottom: .5em; }
ol.exercise-list { list-style: none; padding-left: 0; counter-reset: none; }
ol.exercise-list > li {
  margin-bottom: 1.05em;
  padding-left: 3.1em;
  text-indent: 0;
}
.ex-num {
  display: inline-block;
  width: 3.1em;
  margin-left: -3.1em;
  font-family: var(--sans);
  font-weight: 700;
  font-size: .85em;
  color: var(--lda-blue);
}

/* ---------- references ---------- */
.chapter-refs { margin-top: 3rem; }
.references { font-size: .84rem; line-height: 1.85; }
.ref-entry {
  margin: 0 0 .7em;
  padding-left: 2em;
  text-indent: -2em;                /* APA hanging indent */
  text-align: left;
  color: var(--ink-soft);
  word-break: break-word;
}
.ref-entry:target { background: var(--tint-blue); border-radius: 4px; }
.ref-entry em { color: var(--ink); }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 3rem;
  padding: 1.8rem clamp(1rem, 4vw, 2.4rem) 3rem;
  border-top: 1px solid var(--rule);
  background: var(--surface);
  font-family: var(--sans);
  font-size: .78rem;
  line-height: 1.9;
  color: var(--ink-faint);
  text-align: center;
}

/* ============================================================
   Home page
   ============================================================ */
.home-hero {
  position: relative;
  overflow: hidden;
  padding: clamp(3rem, 9vw, 6.5rem) clamp(1rem, 4vw, 2.4rem) clamp(2.6rem, 6vw, 4.5rem);
  background:
    radial-gradient(120% 130% at 12% -10%, var(--tint-blue) 0%, transparent 58%),
    radial-gradient(110% 120% at 92% 8%, var(--tint-purple) 0%, transparent 52%),
    var(--page);
  border-bottom: 1px solid var(--rule);
}
/* The fan of individual trajectories sits behind the hero text. It is
   masked to fade out over its top half so no line ever crosses the title --
   at narrow viewports the hero shrinks and an unmasked fan struck straight
   through 變化的分析. */
.hero-art {
  position: absolute;
  inset: auto 0 -1px 0;
  height: 58%;
  width: 100%;
  opacity: .62;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 46%, #000 100%);
          mask-image: linear-gradient(to bottom, transparent 0%, #000 46%, #000 100%);
}
/* Cross-edition link to the already-published English site. Pinned to the
   hero's top-right so it reads as a language switch rather than as part of
   the book's own navigation. */
.edition-link {
  position: absolute;
  top: 1rem;
  right: clamp(1rem, 4vw, 2.4rem);
  z-index: 2;
  padding: .38rem .9rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-family: var(--sans);
  font-size: .78rem;
  color: var(--ink-soft);
}
.edition-link:hover {
  border-color: var(--lda-blue);
  color: var(--lda-blue);
  text-decoration: none;
}

.hero-inner { position: relative; max-width: 62rem; margin: 0 auto; }
.hero-eyebrow {
  margin: 0 0 1rem;
  font-family: var(--sans);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .22em;
  color: var(--lda-blue);
  text-indent: 0;
}
.hero-title {
  margin: 0;
  font-size: clamp(2.4rem, 7.5vw, 4.4rem);
  line-height: 1.24;
  font-weight: 700;
  letter-spacing: .02em;
}
.hero-sub {
  margin: 1rem 0 0;
  max-width: 34em;
  font-size: clamp(1rem, 2.4vw, 1.24rem);
  line-height: 1.75;
  color: var(--ink-soft);
  text-indent: 0;
}
.hero-byline {
  margin: 1.5rem 0 0;
  font-family: var(--sans);
  font-size: .88rem;
  line-height: 1.85;
  color: var(--ink-faint);
  text-indent: 0;
}
.hero-byline strong { color: var(--ink); font-weight: 500; }

.hero-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 2rem; }
.btn {
  display: inline-block;
  padding: .62rem 1.25rem;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: .88rem;
  font-weight: 500;
  border: 1px solid var(--rule-strong);
  background: var(--page);
  color: var(--ink);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary { background: var(--lda-blue); border-color: var(--lda-blue); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--lda-blue) 88%, #000); }

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(1.4rem, 5vw, 3.2rem);
  margin-top: 2.6rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
}
.stat-n {
  display: block;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--lda-blue);
  font-variant-numeric: tabular-nums;
}
.stat-l { display: block; font-size: .76rem; letter-spacing: .1em; color: var(--ink-faint); }

.home-main { max-width: 62rem; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.4rem); }

.home-section { margin: clamp(3rem, 7vw, 5rem) 0; }
.home-section > h2 {
  margin: 0 0 .5rem;
  padding: 0;
  border: none;
  font-size: clamp(1.4rem, 3.4vw, 1.85rem);
}
.home-lede { margin: 0 0 2rem; color: var(--ink-soft); font-size: .96rem; text-indent: 0; max-width: 44em; }

/* reading paths */
/* Both of these hold exactly four cards; a 2x2 block reads as one group,
   whereas auto-fit lands on 3+1 at the page's own 62rem measure. */
.path-grid, .note-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 760px) {
  .path-grid, .note-grid { grid-template-columns: 1fr; }
}
.path-card {
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--rule);
  border-top: 3px solid var(--lda-blue);
  border-radius: var(--radius);
  background: var(--surface);
}
.path-card h3 { margin: 0 0 .35rem; font-size: 1rem; color: var(--ink); }
.path-who { margin: 0 0 .7rem; font-family: var(--sans); font-size: .78rem; color: var(--ink-faint); text-indent: 0; }
.path-chs { margin: 0; font-family: var(--sans); font-size: .82rem; line-height: 1.8; color: var(--ink-soft); text-indent: 0; }
.path-card:nth-child(2) { border-top-color: var(--lda-green); }
.path-card:nth-child(3) { border-top-color: var(--lda-orange); }
.path-card:nth-child(4) { border-top-color: var(--lda-purple); }

.fivechapters {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  margin-top: 1rem;
}
.chip {
  display: inline-block;
  padding: .34rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--ink);
  background: var(--page);
}
.chip:hover { border-color: var(--lda-blue); color: var(--lda-blue); text-decoration: none; }

/* parts + chapter cards */
.part-block { margin: 2.6rem 0; }
.part-head {
  display: flex;
  align-items: baseline;
  gap: .85rem;
  flex-wrap: wrap;
  padding-bottom: .6rem;
  margin-bottom: 1.1rem;
  border-bottom: 2px solid var(--part, var(--lda-blue));
}
.part-tag {
  font-family: var(--sans);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .18em;
  padding: .22rem .7rem;
  border-radius: 999px;
  color: #fff;
  background: var(--part, var(--lda-blue));
}
.part-title { margin: 0; font-size: 1.16rem; font-weight: 700; }
.part-range { font-family: var(--sans); font-size: .78rem; color: var(--ink-faint); margin-left: auto; }

.ch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: .8rem;
}
.ch-card {
  display: block;
  padding: 1.05rem 1.15rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--ink);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.ch-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: var(--part, var(--lda-blue));
  box-shadow: var(--shadow-md);
}
.ch-num {
  display: inline-block;
  margin-bottom: .35rem;
  font-family: var(--sans);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--part, var(--lda-blue));
}
.ch-title { margin: 0 0 .4rem; font-size: .99rem; font-weight: 700; line-height: 1.55; text-indent: 0; }
.ch-blurb { margin: 0; font-family: var(--sans); font-size: .79rem; line-height: 1.75; color: var(--ink-faint); text-indent: 0; }

/* about / conventions */
.note-card {
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .88rem;
  line-height: 1.85;
}
.note-card h3 { margin: 0 0 .4rem; font-size: .95rem; }
.note-card p { margin: 0; text-indent: 0; color: var(--ink-soft); font-size: .85rem; }

@media (max-width: 620px) {
  body { font-size: 17px; }
  p { text-align: left; }
  .chapter-nav { grid-template-columns: 1fr 1fr; row-gap: .6rem; }
  .chapter-nav .nav-toc { grid-column: 1 / -1; order: -1; }
}

@media print {
  .site-header, .chapter-nav, .page-toc { display: none; }
  body { font-size: 11pt; }
  .chapter { max-width: none; }
}

/* ============================================================
   2026 reading interface: persistent book TOC + new home identity
   ============================================================ */
:root {
  --book-sidebar-width: 19.5rem;
  --book-deep: #113b43;
  --book-deep-2: #0b2d34;
  --book-paper: #f5f0e7;
  --book-paper-2: #ece3d5;
  --book-rust: #a53d2c;
  --book-gold: #c99752;
  --shadow-soft: 0 18px 50px rgba(42, 35, 27, .10);
}

body.has-book-sidebar {
  background: var(--page);
  overflow-x: clip;
}

.book-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  width: var(--book-sidebar-width);
  color: #f5f0e7;
  background:
    radial-gradient(circle at 15% 8%, rgba(201, 151, 82, .14), transparent 26%),
    linear-gradient(165deg, var(--book-deep), var(--book-deep-2));
  box-shadow: 10px 0 30px rgba(11, 45, 52, .10);
}

.book-brand {
  flex: none;
  padding: 1.25rem 1.15rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .13);
}

.book-brand > a {
  display: flex;
  align-items: center;
  gap: .8rem;
  color: inherit;
}

.book-brand > a:hover { text-decoration: none; }

.book-brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.85rem;
  height: 2.85rem;
  color: #fffaf1;
  background: var(--book-rust);
  border: 1px solid rgba(255, 255, 255, .28);
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}

.book-brand-copy { min-width: 0; }
.book-brand-copy strong,
.book-brand-copy small { display: block; }
.book-brand-copy strong {
  font-family: var(--serif);
  font-size: 1.02rem;
  letter-spacing: .08em;
}
.book-brand-copy small {
  margin-top: .18rem;
  overflow: hidden;
  color: rgba(245, 240, 231, .66);
  font-family: var(--sans);
  font-size: .64rem;
  letter-spacing: .04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-sidebar-close { display: none; }

.book-toc {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: .8rem .72rem 2rem;
  scrollbar-color: rgba(255, 255, 255, .24) transparent;
  scrollbar-width: thin;
}

.book-toc-home,
.book-toc-link {
  display: flex;
  align-items: baseline;
  color: rgba(245, 240, 231, .74);
  font-family: var(--sans);
  text-decoration: none;
}

.book-toc-home {
  margin-bottom: .7rem;
  padding: .62rem .72rem;
  border: 1px solid rgba(255, 255, 255, .14);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .12em;
}

.book-toc-part { margin-top: .8rem; }
.book-toc-part-title {
  margin: 0 0 .28rem;
  padding: 0 .68rem;
  color: rgba(245, 240, 231, .48);
  font-family: var(--sans);
  font-size: .65rem;
  font-weight: 500;
  line-height: 1.55;
  text-indent: 0;
}
.book-toc-part-title span {
  margin-right: .5rem;
  color: var(--book-gold);
  font-weight: 700;
  letter-spacing: .08em;
}

.book-toc-link {
  gap: .62rem;
  margin: 1px 0;
  padding: .4rem .68rem;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  font-size: .71rem;
  line-height: 1.45;
}

.book-toc-number {
  flex: 0 0 1.8rem;
  color: rgba(245, 240, 231, .42);
  font-size: .62rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
}

.book-toc-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.book-toc-link:hover,
.book-toc-home:hover {
  color: #fff;
  background: rgba(255, 255, 255, .075);
  text-decoration: none;
}

.book-toc-link.is-current,
.book-toc-home.is-current {
  color: #fff;
  background: rgba(165, 61, 44, .45);
  border-color: var(--book-rust);
}
.book-toc-link.is-current .book-toc-number { color: #f0c48c; }

.book-sidebar-foot {
  flex: none;
  padding: .7rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, .11);
  color: rgba(245, 240, 231, .42);
  font-family: var(--sans);
  font-size: .62rem;
  letter-spacing: .06em;
}

.book-menu-toggle,
.book-sidebar-backdrop { display: none; }

@media (min-width: 1081px) {
  body.has-book-sidebar { padding-left: var(--book-sidebar-width); }
  body.has-book-sidebar .site-header { padding-left: 1.5rem; }
  body.has-book-sidebar .chapter-nav { max-width: 57rem; }
  body.has-book-sidebar .site-footer { padding-left: 2.4rem; padding-right: 2.4rem; }
}

/* Home: deliberately warmer and more editorial than the companion book. */
.book-home-page {
  --ink: #1d292b;
  --ink-soft: #4f5c5e;
  --ink-faint: #707b7d;
  --page: #fffdf9;
  --surface: #f3ede4;
  --surface-2: #e9e0d3;
  --rule: #ddd3c5;
  --rule-strong: #b9aa97;
  background: var(--book-paper);
}

.book-home-page .site-shell {
  background: var(--book-paper);
}

.book-home-page .home-hero {
  display: grid;
  min-height: min(82vh, 54rem);
  align-items: center;
  padding: clamp(4.6rem, 10vw, 8.5rem) clamp(1.4rem, 7vw, 6.5rem);
  background:
    radial-gradient(circle at 82% 23%, rgba(165, 61, 44, .11), transparent 36%),
    linear-gradient(120deg, var(--book-paper), #fbf8f2 55%, var(--book-paper-2));
  border-bottom: 1px solid rgba(79, 60, 42, .16);
  isolation: isolate;
}

.book-home-page .home-hero::before {
  content: "變";
  position: absolute;
  z-index: -1;
  right: clamp(-3.5rem, -2vw, -1rem);
  top: 50%;
  color: rgba(165, 61, 44, .105);
  font-family: var(--serif);
  font-size: clamp(20rem, 48vw, 47rem);
  font-weight: 700;
  line-height: .72;
  transform: translateY(-50%);
  white-space: nowrap;
}

.book-home-page .home-hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: clamp(1.4rem, 7vw, 6.5rem);
  bottom: 2.2rem;
  width: min(13rem, 38vw);
  height: 1px;
  background: var(--book-rust);
}

.book-home-page .hero-art { display: none; }
.book-home-page .hero-inner { width: 100%; max-width: 68rem; }
.book-home-page .hero-eyebrow {
  display: flex;
  align-items: center;
  gap: .8rem;
  color: var(--book-rust);
  font-size: .72rem;
  letter-spacing: .24em;
}
.book-home-page .hero-eyebrow::before {
  content: "";
  width: 2.6rem;
  height: 2px;
  background: currentColor;
}
.book-home-page .hero-title {
  max-width: 8em;
  color: #182b2e;
  font-size: clamp(3.5rem, 8.5vw, 7.2rem);
  line-height: 1.02;
  letter-spacing: .055em;
}
.book-home-page .hero-sub {
  max-width: 31em;
  margin-top: 1.5rem;
  color: #45575a;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  letter-spacing: .045em;
}
.book-home-page .hero-byline { color: #6d6b64; }
.book-home-page .hero-byline strong { color: #2f3e40; }
.book-home-page .btn {
  border-radius: 3px;
  border-color: rgba(24, 43, 46, .32);
  background: rgba(255, 255, 255, .44);
  color: #182b2e;
}
.book-home-page .btn-primary {
  border-color: var(--book-rust);
  background: var(--book-rust);
  color: #fff;
}
.book-home-page .hero-stats {
  max-width: 44rem;
  border-color: rgba(79, 60, 42, .18);
}
.book-home-page .stat-n { color: var(--book-rust); }
.book-home-page .edition-link {
  border-radius: 3px;
  border-color: rgba(24, 43, 46, .25);
  background: rgba(255, 255, 255, .4);
}

.book-home-page .home-main {
  max-width: 72rem;
  padding: 0 clamp(1.4rem, 6vw, 5rem);
}
.book-home-page .home-section { position: relative; }
.book-home-page .home-section > h2 { color: #18383d; }
.book-home-page .home-lede { max-width: 50rem; }
.book-home-page .note-card,
.book-home-page .path-card,
.book-home-page .ch-card {
  border-radius: 3px;
  background: rgba(255, 255, 255, .64);
  box-shadow: 0 1px 0 rgba(79, 60, 42, .04);
}
.book-home-page .part-tag { border-radius: 3px; }
.book-home-page .site-footer { background: #e9e1d5; border-color: rgba(79, 60, 42, .14); }

/* Chapter refinements */
body.has-book-sidebar:not(.book-home-page) .site-header {
  background: color-mix(in srgb, var(--page) 94%, transparent);
}
body.has-book-sidebar:not(.book-home-page) .chapter-header {
  position: relative;
  padding: 2rem 0 1.2rem;
}
body.has-book-sidebar:not(.book-home-page) .chapter-header::after {
  content: "變";
  position: absolute;
  z-index: -1;
  top: -.45rem;
  right: -2.1rem;
  color: color-mix(in srgb, var(--book-rust) 7%, transparent);
  font-size: clamp(7rem, 16vw, 11rem);
  font-weight: 700;
  line-height: 1;
}
body.has-book-sidebar:not(.book-home-page) .chapter-kicker { color: var(--book-rust); }
body.has-book-sidebar:not(.book-home-page) .page-toc {
  border-radius: 4px;
  border-left: 3px solid var(--book-rust);
}

@media (max-width: 1080px) {
  .book-sidebar {
    width: min(21rem, 88vw);
    transform: translateX(-105%);
    transition: transform .24s ease;
  }
  .book-menu-open .book-sidebar { transform: translateX(0); }
  .book-sidebar-close {
    position: absolute;
    top: 1.2rem;
    right: .8rem;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 0;
    color: rgba(255, 255, 255, .78);
    background: transparent;
    font-size: 1.65rem;
    cursor: pointer;
  }
  .book-brand { padding-right: 3.3rem; }
  .book-menu-toggle {
    position: fixed;
    z-index: 90;
    top: .72rem;
    left: .72rem;
    display: grid;
    grid-template-columns: 1rem auto;
    align-items: center;
    gap: .1rem .42rem;
    padding: .48rem .7rem;
    border: 1px solid rgba(17, 59, 67, .18);
    border-radius: 4px;
    color: var(--book-deep);
    background: color-mix(in srgb, var(--page) 92%, transparent);
    box-shadow: 0 5px 18px rgba(11, 45, 52, .12);
    backdrop-filter: blur(10px);
    cursor: pointer;
  }
  .book-menu-toggle span {
    grid-column: 1;
    display: block;
    width: 1rem;
    height: 1px;
    background: currentColor;
  }
  .book-menu-toggle span:nth-child(1) { grid-row: 1; }
  .book-menu-toggle span:nth-child(2) { grid-row: 2; }
  .book-menu-toggle span:nth-child(3) { grid-row: 3; }
  .book-menu-toggle b {
    grid-column: 2;
    grid-row: 1 / 4;
    font-family: var(--sans);
    font-size: .68rem;
    letter-spacing: .08em;
  }
  .book-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 95;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(3, 17, 20, .52);
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s ease;
  }
  .book-menu-open .book-sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .book-menu-open { overflow: hidden; }
  body.has-book-sidebar .site-header { padding-left: 5.5rem; }
  .book-home-page .home-hero { padding-top: 6.2rem; }
}

@media (max-width: 620px) {
  .book-home-page .home-hero {
    min-height: 45rem;
    padding-left: 1.35rem;
    padding-right: 1.35rem;
  }
  .book-home-page .home-hero::before {
    right: -4.5rem;
    top: 38%;
    font-size: 23rem;
  }
  .book-home-page .hero-title { font-size: clamp(3.3rem, 18vw, 5.2rem); }
  .book-home-page .hero-actions { align-items: stretch; flex-direction: column; max-width: 17rem; }
  .book-home-page .btn { text-align: center; }
  .book-home-page .hero-stats { gap: 1.35rem 2rem; }
  body.has-book-sidebar:not(.book-home-page) .site-header { padding-left: 6rem; }
  body.has-book-sidebar:not(.book-home-page) .site-subtitle { display: none; }
  body.has-book-sidebar:not(.book-home-page) main { padding-left: 1.2rem; padding-right: 1.2rem; }
  body.has-book-sidebar:not(.book-home-page) .chapter-header::after { right: -.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .book-sidebar,
  .book-sidebar-backdrop { transition: none; }
}

@media print {
  .book-sidebar, .book-menu-toggle, .book-sidebar-backdrop { display: none !important; }
  body.has-book-sidebar { padding-left: 0; }
}
