/* ============================================================
   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;
  }
}


/* ============================================================
   V02 shell: chrome palettes
   ============================================================
   The six data colours above are the printed edition's and do not move --
   they carry the figures, the six box types and the eight Part accents, so
   changing them would desynchronise screen from paper. What the palettes
   below control is the *furniture*: the fixed top bar, the left sidebar,
   the current-chapter highlight, buttons and body links, plus the paper
   tint the text sits on. Three are provided; the reader can switch with the
   swatches in the top bar and the choice is remembered per browser.
   ------------------------------------------------------------ */
:root,
:root[data-theme="ink"] {
  --chrome:       #16283F;   /* 深墨藍 */
  --chrome-2:     #1F3654;
  --chrome-3:     #2B4668;
  --chrome-ink:   #EDF1F6;
  --chrome-soft:  #A9B8CC;
  --chrome-rule:  #2C4159;
  --accent:       #C98A46;   /* 銅褐 */
  --accent-ink:   #1B2A41;
  --link:         #15618F;
  --page:         #FBF9F5;   /* 暖米白 */
  --surface:      #F4F1EA;
  --surface-2:    #EBE7DE;
  --rule:         #E2DDD2;
  --rule-strong:  #BEB6A6;
}
:root[data-theme="moss"] {
  --chrome:       #1E3A32;   /* 墨綠 */
  --chrome-2:     #27493F;
  --chrome-3:     #345D51;
  --chrome-ink:   #EDF3F0;
  --chrome-soft:  #A6BDB4;
  --chrome-rule:  #2F5449;
  --accent:       #4FA98C;
  --accent-ink:   #12271F;
  --link:         #1C6B55;
  --page:         #FAF9F4;   /* 象牙白 */
  --surface:      #F2F2EA;
  --surface-2:    #E8E9DF;
  --rule:         #DFE1D5;
  --rule-strong:  #B9BDAC;
}
:root[data-theme="claret"] {
  --chrome:       #4E2233;   /* 赭紅 */
  --chrome-2:     #632D41;
  --chrome-3:     #7A3A52;
  --chrome-ink:   #F6EDF0;
  --chrome-soft:  #CDAFB9;
  --chrome-rule:  #663145;
  --accent:       #C9955A;
  --accent-ink:   #33141F;
  --link:         #8C3A20;
  --page:         #FCFBFA;   /* 紙白 */
  --surface:      #F5F1F2;
  --surface-2:    #ECE5E7;
  --rule:         #E4DCDF;
  --rule-strong:  #C0B2B6;
}

/* ============================================================
   V02 shell: fixed top bar + left book sidebar
   ============================================================ */
:root { --topbar-h: 3.5rem; --toc-w: 17.5rem; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--chrome); color: var(--chrome-ink);
  padding: .6rem 1rem; font-family: var(--sans); font-size: .9rem;
}
.skip-link:focus { left: 0; }

/* ---- top bar ---- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 120;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .9rem;
  padding: 0 clamp(.7rem, 2.2vw, 1.3rem);
  background: var(--chrome);
  color: var(--chrome-ink);
  border-bottom: 1px solid var(--chrome-rule);
}
.brand { display: flex; flex-direction: column; line-height: 1.2; gap: .1rem; }
.brand:hover { text-decoration: none; }
.brand-title {
  font-family: var(--serif); font-weight: 700; font-size: 1.08rem;
  letter-spacing: .06em; color: var(--chrome-ink);
}
.brand-author {
  font-family: var(--sans); font-size: .72rem; letter-spacing: .04em;
  color: var(--chrome-soft);
}
.brand-sub {
  font-family: var(--sans); font-size: .76rem; color: var(--chrome-soft);
  border-left: 1px solid var(--chrome-rule); padding-left: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.theme-picker { margin-left: auto; display: flex; gap: .35rem; }
.swatch {
  width: 1.35rem; height: 1.35rem; padding: 0; cursor: pointer;
  border-radius: 50%; border: 1px solid var(--chrome-rule);
  background: transparent; display: grid; place-items: center;
}
.swatch span { width: .95rem; height: .95rem; border-radius: 50%; display: block; }
.swatch[data-set-theme="ink"] span    { background: #16283F; box-shadow: inset 0 0 0 2px #C98A46; }
.swatch[data-set-theme="moss"] span   { background: #1E3A32; box-shadow: inset 0 0 0 2px #4FA98C; }
.swatch[data-set-theme="claret"] span { background: #4E2233; box-shadow: inset 0 0 0 2px #C9955A; }
.swatch:hover { border-color: var(--accent); }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toc-toggle {
  display: none; width: 2.1rem; height: 2.1rem; padding: 0; cursor: pointer;
  background: transparent; border: 1px solid var(--chrome-rule); border-radius: 6px;
  place-items: center;
}
.toc-toggle-bars, .toc-toggle-bars::before, .toc-toggle-bars::after {
  display: block; width: 1.05rem; height: 2px; background: var(--chrome-ink);
  border-radius: 2px; content: '';
}
.toc-toggle-bars { position: relative; }
.toc-toggle-bars::before { position: absolute; top: -6px; }
.toc-toggle-bars::after  { position: absolute; top:  6px; }

/* ---- layout ---- */
.layout { display: block; }
.content-col {
  margin-left: var(--toc-w);
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

/* ---- left sidebar ---- */
.book-toc {
  position: fixed; z-index: 110;
  top: var(--topbar-h); bottom: 0; left: 0; width: var(--toc-w);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--chrome); color: var(--chrome-soft);
  border-right: 1px solid var(--chrome-rule);
  font-family: var(--sans); font-size: .82rem; line-height: 1.55;
  padding: .9rem 0 3rem;
  scrollbar-width: thin;
  scrollbar-color: var(--chrome-3) transparent;
}
.book-toc::-webkit-scrollbar { width: 9px; }
.book-toc::-webkit-scrollbar-thumb { background: var(--chrome-3); border-radius: 6px; }
.book-toc a { color: var(--chrome-soft); display: block; }
.book-toc a:hover { color: var(--chrome-ink); background: var(--chrome-2); text-decoration: none; }
.toc-home {
  margin: 0 .8rem .7rem; padding: .45rem .7rem; border-radius: 6px;
  border: 1px solid var(--chrome-rule); text-align: center;
  letter-spacing: .05em; font-size: .8rem;
}
.toc-parts, .toc-chapters, .toc-sections { list-style: none; margin: 0; padding: 0; }
.toc-part { margin-bottom: .35rem; }
.toc-part-head {
  margin: .85rem 0 .3rem; padding: 0 1rem 0 .8rem;
  border-left: 3px solid var(--part, var(--accent));
  display: flex; flex-direction: column; gap: .05rem;
}
.toc-part-tag {
  font-size: .68rem; letter-spacing: .16em; text-transform: none;
  color: var(--part, var(--accent)); font-weight: 700;
}
.toc-part-title { font-size: .76rem; color: var(--chrome-soft); opacity: .85; }
.toc-ch > a {
  padding: .3rem 1rem .3rem 1.1rem;
  border-left: 3px solid transparent;
  display: grid; grid-template-columns: 4.2rem 1fr; gap: .35rem; align-items: baseline;
}
.toc-ch-num { color: var(--chrome-soft); opacity: .7; font-size: .74rem; white-space: nowrap; }
.toc-ch-title { overflow-wrap: anywhere; }
.toc-ch.is-current > a {
  background: var(--chrome-3);
  border-left-color: var(--accent);
  color: var(--chrome-ink);
  font-weight: 700;
}
.toc-ch.is-current .toc-ch-num { color: var(--accent); opacity: 1; }
.toc-sections {
  background: color-mix(in srgb, var(--chrome-2) 70%, transparent);
  padding: .3rem 0 .45rem;
  border-left: 3px solid var(--accent);
}
.toc-sections a {
  padding: .18rem 1rem .18rem 1.9rem; font-size: .76rem; opacity: .9;
}
.toc-sections a:hover { opacity: 1; }

/* ---- content column ---- */
main { padding: 0 clamp(1rem, 4vw, 2.4rem); }
.site-footer { border-top: 1px solid var(--rule); }

/* The old sticky header is superseded by .topbar on chapter pages; the home
   page keeps its own hero, so the rule only has to stop the two stacking. */
.site-header { display: none; }

/* ---- narrow screens: the sidebar becomes a drawer ---- */
@media (max-width: 1080px) {
  .toc-toggle { display: grid; }
  .brand-sub { display: none; }
  .content-col { margin-left: 0; }
  .book-toc {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: none;
  }
  body.toc-open .book-toc { transform: none; box-shadow: var(--shadow-lg); }
}
@media (max-width: 560px) {
  .brand-title { font-size: .98rem; }
  :root { --topbar-h: 3.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  .book-toc { transition: none; }
  html { scroll-behavior: auto; }
}

/* Anchors have to clear the fixed bar. */
:target { scroll-margin-top: calc(var(--topbar-h) + .8rem); }
h2, h3, .table-wrap, .lda-figure, .box { scroll-margin-top: calc(var(--topbar-h) + .8rem); }

/* ---- home page keeps the shell too ---- */
body.home .content-col { margin-left: var(--toc-w); }

/* Chrome in dark mode: the bar and sidebar are already dark, so they only
   need their rules and text softened; the paper tint gives way to the dark
   page defined above. */
@media (prefers-color-scheme: dark) {
  :root, :root[data-theme="ink"] {
    --page: #14171A; --surface: #1B1F23; --surface-2: #22262B;
    --rule: #2E343A; --rule-strong: #454C54;
    --chrome: #101820; --chrome-2: #182430; --chrome-3: #23323F;
    --chrome-rule: #24313C; --link: #6FB6E4;
  }
  :root[data-theme="moss"] {
    --page: #141816; --surface: #1B211E; --surface-2: #222A26;
    --rule: #2C3833; --rule-strong: #44544C;
    --chrome: #12211C; --chrome-2: #1B302A; --chrome-3: #264035;
    --chrome-rule: #22382F; --link: #63C0A2;
  }
  :root[data-theme="claret"] {
    --page: #171315; --surface: #1F191B; --surface-2: #272022;
    --rule: #362C2F; --rule-strong: #524448;
    --chrome: #2A1220; --chrome-2: #3A1B2B; --chrome-3: #4A2537;
    --chrome-rule: #3B2030; --link: #E09B7E;
  }
}


/* ---------- 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(--link, 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(--link); }
@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; }
}

/* ============================================================
   V02 shell: overrides that must win over the rules above
   ============================================================ */
/* ---- home page ---- */
.topbar-links { display: flex; gap: .9rem; margin-left: 1.2rem; font-family: var(--sans); font-size: .82rem; }
.topbar-links a { color: var(--chrome-soft); }
.topbar-links a:hover { color: var(--chrome-ink); text-decoration: none; border-bottom: 1px solid var(--accent); }
@media (max-width: 720px) { .topbar-links { display: none; } }

/* The hero's own colours follow the chrome so the home page and the chapter
   pages read as one site rather than two. */
.home-hero { background: var(--surface); border-bottom: 1px solid var(--rule); }
.hero-eyebrow { color: var(--accent); }
.btn-primary { background: var(--chrome); color: var(--chrome-ink); border-color: var(--chrome); }
.btn-primary:hover { background: var(--chrome-2); border-color: var(--chrome-2); color: var(--chrome-ink); }
.stat-n { color: var(--accent); }
.part-tag { color: var(--part, var(--accent)); }
.chip:hover, .ch-card:hover { border-color: var(--accent); }

/* ---- 「變」：the book's own first character, used as a watermark ---- */
/* Carried over from the V01 site. It sits behind everything (z-index -1 on a
   positioned ancestor), is pointer-transparent and aria-hidden, and takes its
   colour from the active palette so it reads the same in all three and in
   dark mode. */
.mark-bian {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  font-family: var(--serif);
  font-weight: 700;
  line-height: .78;
  color: color-mix(in srgb, var(--accent) 16%, transparent);
}
.home-hero { position: relative; overflow: hidden; }
.mark-bian-hero {
  right: clamp(-5rem, -3vw, -1.5rem);
  top: 50%;
  transform: translateY(-50%);
  font-size: clamp(15rem, 34vw, 32rem);
  color: color-mix(in srgb, var(--accent) 10%, transparent);
}
.chapter-header { position: relative; }
.chapter-header .mark-bian {
  top: -.6rem;
  right: -2.4rem;
  font-size: clamp(6rem, 15vw, 10rem);
  color: color-mix(in srgb, var(--accent) 11%, transparent);
}
.chapter-header > :not(.mark-bian) { position: relative; z-index: 1; }
@media (max-width: 640px) {
  .chapter-header .mark-bian { right: -1rem; font-size: 6rem; }
}
/* Browsers without color-mix() get a plain low-alpha ink instead of nothing. */
@supports not (color: color-mix(in srgb, red 10%, transparent)) {
  .mark-bian { color: rgba(140, 100, 55, .13); }
}

/* ---- home page now carries the sidebar as well ---- */
body.home .content-col { margin-left: var(--toc-w); }
body.home .home-shell { padding-top: var(--topbar-h); }
@media (max-width: 1080px) { body.home .content-col { margin-left: 0; } }
.toc-home.is-current {
  background: var(--chrome-3);
  border-color: var(--accent);
  color: var(--chrome-ink);
  font-weight: 700;
}

/* In dark mode the chrome colour is nearly the page colour, so a primary
   button painted with it loses its shape. Give it the accent ground there. */
@media (prefers-color-scheme: dark) {
  .btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
  }
  .btn-primary:hover {
    background: color-mix(in srgb, var(--accent) 84%, #fff);
    border-color: color-mix(in srgb, var(--accent) 84%, #fff);
    color: var(--accent-ink);
  }
}

/* ============================================================
   引用區塊
   ============================================================ */
.cite-block { margin-top: 3.2rem; }
.chapter .cite-block {
  border-top: 2px solid var(--rule-strong);
  padding-top: 1.6rem;
}
.cite-block h2 { margin-bottom: .4rem; }
.cite-h {
  font-family: var(--sans);
  font-size: .92rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 1.5rem 0 .5rem;
  letter-spacing: .02em;
}
.cite-note {
  font-family: var(--sans);
  font-size: .84rem;
  line-height: 1.75;
  color: var(--ink-faint);
  margin: .3rem 0 .8rem;
  text-indent: 0;
}
.cite-rows { display: grid; gap: .5rem; }
.cite-row {
  display: grid;
  grid-template-columns: 5.2rem 1fr auto;
  gap: .7rem;
  align-items: start;
  padding: .7rem .85rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.cite-label {
  font-family: var(--sans);
  font-size: .76rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .04em;
  padding-top: .15rem;
  white-space: nowrap;
}
.cite-text {
  font-family: var(--serif);
  font-size: .92rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
  text-indent: 0;
}
.cite-copy {
  font-family: var(--sans);
  font-size: .76rem;
  padding: .28rem .7rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--page);
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.cite-copy:hover { border-color: var(--accent); color: var(--ink); }
.cite-copy.is-done { border-color: var(--accent); color: var(--accent); }
@media (max-width: 720px) {
  .cite-row { grid-template-columns: 1fr auto; }
  .cite-label { grid-column: 1 / -1; }
}

/* Defensive: an older cached index.html wrapped the home page in
   .site-shell rather than .content-col. Without this the text would sit
   under the fixed sidebar until the cache cleared. */
body.home .site-shell.home-shell { margin-left: var(--toc-w); padding-top: var(--topbar-h); }
@media (max-width: 1080px) {
  body.home .site-shell.home-shell { margin-left: 0; }
}
