/* --- 00-tokens.css --- */
/* ==========================================================================
   Design Tokens — 《高性价比人生指南》 Editorial Print × Evidence Handbook
   Themes: paper (default), light, dark
   ========================================================================== */

:root,
[data-theme="paper"] {
  color-scheme: light;

  /* Surfaces */
  --bg-canvas: #f5f1e8;
  --bg-surface: #fcfaf5;
  --bg-elevated: #ffffff;
  --bg-subtle: #ece6d9;
  --bg-callout: #f2ecdf;
  --bg-hover: rgba(28, 25, 21, 0.045);

  /* Ink */
  --ink-primary: #1c1915;
  --ink-secondary: #4a443c;
  --ink-muted: #6e675c;
  --ink-faint: #8f877b;

  /* Borders */
  --border-subtle: rgba(28, 25, 21, 0.1);
  --border-default: rgba(28, 25, 21, 0.16);
  --border-strong: rgba(28, 25, 21, 0.28);

  /* Editorial Brand Accent (Cinnabar / Vermilion Stamp) */
  --accent: #a43728;
  --accent-hover: #8a2c1f;
  --accent-soft: rgba(164, 55, 40, 0.09);
  --accent-border: rgba(164, 55, 40, 0.28);
  --accent-ink: #ffffff;

  /* Semantic Evidence & ROI Badges (WCAG AA+ contrast) */
  --grade-a-bg: #e2f0e8;
  --grade-a-ink: #175c3e;
  --grade-a-border: rgba(23, 92, 62, 0.22);

  --grade-b-bg: #e3edf5;
  --grade-b-ink: #1e4d73;
  --grade-b-border: rgba(30, 77, 115, 0.22);

  --grade-c-bg: #f3ead4;
  --grade-c-ink: #725014;
  --grade-c-border: rgba(114, 80, 20, 0.24);

  --errata-bg: #f7e9e6;
  --errata-ink: #8e2d20;
  --errata-border: rgba(142, 45, 32, 0.26);

  --diff-del-bg: rgba(164, 55, 40, 0.1);
  --diff-del-ink: #7d2519;
  --diff-add-bg: rgba(23, 92, 62, 0.1);
  --diff-add-ink: #145036;

  --mark-bg: #f5df97;
  --mark-ink: #1c1915;

  --scrim: rgba(20, 18, 14, 0.45);
  --shadow-sm: 0 1px 2px rgba(28, 25, 21, 0.05);
  --shadow-md: 0 6px 20px rgba(28, 25, 21, 0.08), 0 1px 3px rgba(28, 25, 21, 0.05);
  --shadow-lg: 0 18px 46px rgba(20, 18, 14, 0.16), 0 4px 12px rgba(20, 18, 14, 0.08);

  /* Typography */
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Monaco, Consolas, monospace;

  /* Scale defaults (md / normal) */
  --text-base: 16.5px;
  --text-sm: 14px;
  --text-xs: 12.5px;
  --leading-body: 1.8;
  --measure: 68ch;

  /* Spacing & Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Layout Heights */
  --header-h: 56px;
  --dock-h: 60px;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 140ms;
  --dur-mid: 220ms;
}

[data-theme="light"] {
  color-scheme: light;

  --bg-canvas: #f7f8fa;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-subtle: #eff1f5;
  --bg-callout: #f4f6f9;
  --bg-hover: rgba(18, 24, 34, 0.045);

  --ink-primary: #14181f;
  --ink-secondary: #414956;
  --ink-muted: #626c7c;
  --ink-faint: #8791a1;

  --border-subtle: rgba(20, 24, 31, 0.09);
  --border-default: rgba(20, 24, 31, 0.15);
  --border-strong: rgba(20, 24, 31, 0.26);

  --accent: #1b5776;
  --accent-hover: #14445d;
  --accent-soft: rgba(27, 87, 118, 0.09);
  --accent-border: rgba(27, 87, 118, 0.28);
  --accent-ink: #ffffff;

  --grade-a-bg: #e1f2ea;
  --grade-a-ink: #145b3d;
  --grade-a-border: rgba(20, 91, 61, 0.22);

  --grade-b-bg: #e3eef8;
  --grade-b-ink: #1b4f78;
  --grade-b-border: rgba(27, 79, 120, 0.22);

  --grade-c-bg: #f6eed8;
  --grade-c-ink: #725013;
  --grade-c-border: rgba(114, 80, 19, 0.24);

  --errata-bg: #fbeae7;
  --errata-ink: #952e21;
  --errata-border: rgba(149, 46, 33, 0.25);

  --mark-bg: #fde68a;
  --mark-ink: #14181f;

  --scrim: rgba(15, 20, 28, 0.42);
  --shadow-sm: 0 1px 2px rgba(15, 20, 28, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 20, 28, 0.08), 0 1px 3px rgba(15, 20, 28, 0.04);
  --shadow-lg: 0 18px 44px rgba(15, 20, 28, 0.16), 0 4px 12px rgba(15, 20, 28, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg-canvas: #121417;
  --bg-surface: #1a1d21;
  --bg-elevated: #21252b;
  --bg-subtle: #24282f;
  --bg-callout: #1f2329;
  --bg-hover: rgba(235, 231, 224, 0.06);

  --ink-primary: #eae6de;
  --ink-secondary: #b7b2a8;
  --ink-muted: #8f8a80;
  --ink-faint: #6f6b63;

  --border-subtle: rgba(234, 230, 222, 0.09);
  --border-default: rgba(234, 230, 222, 0.15);
  --border-strong: rgba(234, 230, 222, 0.26);

  --accent: #e07862;
  --accent-hover: #ec8d79;
  --accent-soft: rgba(224, 120, 98, 0.15);
  --accent-border: rgba(224, 120, 98, 0.38);
  --accent-ink: #121417;

  --grade-a-bg: rgba(74, 186, 134, 0.16);
  --grade-a-ink: #7ae0b0;
  --grade-a-border: rgba(122, 224, 176, 0.28);

  --grade-b-bg: rgba(96, 168, 224, 0.16);
  --grade-b-ink: #8ac6f5;
  --grade-b-border: rgba(138, 198, 245, 0.28);

  --grade-c-bg: rgba(224, 178, 86, 0.16);
  --grade-c-ink: #ecc879;
  --grade-c-border: rgba(236, 200, 121, 0.28);

  --errata-bg: rgba(224, 120, 98, 0.14);
  --errata-ink: #f3a18f;
  --errata-border: rgba(243, 161, 143, 0.3);

  --diff-del-bg: rgba(224, 108, 90, 0.18);
  --diff-del-ink: #f4a497;
  --diff-add-bg: rgba(74, 186, 134, 0.18);
  --diff-add-ink: #8ae4b8;

  --mark-bg: rgba(238, 196, 86, 0.34);
  --mark-ink: #fff6dc;

  --scrim: rgba(0, 0, 0, 0.66);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 22px 54px rgba(0, 0, 0, 0.58);
}

/* Font size tiers */
[data-font-size="sm"] {
  --text-base: 15px;
  --leading-body: 1.75;
}
[data-font-size="md"] {
  --text-base: 16.5px;
  --leading-body: 1.8;
}
[data-font-size="lg"] {
  --text-base: 18.5px;
  --leading-body: 1.84;
}
[data-font-size="xl"] {
  --text-base: 20.5px;
  --leading-body: 1.86;
}

/* Reading measure tiers */
[data-measure="narrow"] {
  --measure: 58ch;
}
[data-measure="normal"] {
  --measure: 68ch;
}
[data-measure="wide"] {
  --measure: 78ch;
}


/* --- 01-base.css --- */
/* ==========================================================================
   Base Reset, Editorial Typography & Accessibility Foundations
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
  background: var(--bg-canvas);
  color: var(--ink-primary);
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  letter-spacing: 0.01em;
  background: var(--bg-canvas);
  color: var(--ink-primary);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

body.modal-open {
  overflow: hidden;
}

img,
svg {
  display: block;
  max-width: 100%;
}

.ic {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.2em;
  transition: color var(--dur-fast) var(--ease-out);
}

a:hover {
  color: var(--accent-hover);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.01em;
  color: var(--ink-primary);
}

p {
  margin: 0 0 0.9em;
}

p:last-child {
  margin-bottom: 0;
}

code,
.mono,
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

mark {
  background: var(--mark-bg);
  color: var(--mark-ink);
  border-radius: 3px;
  padding: 0.04em 0.2em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 9999;
  padding: 10px 16px;
  background: var(--ink-primary);
  color: var(--bg-canvas);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: top var(--dur-fast) var(--ease-out);
}

.skip-link:focus {
  top: 12px;
}

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


/* --- 02-layout.css --- */
/* ==========================================================================
   Global Layout Shell: Sticky Top Bar, 3-Column Reading Grid, Mobile Dock
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg-canvas) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: 1420px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-primary);
  min-width: 0;
  flex-shrink: 1;
}

.brand:hover {
  color: var(--ink-primary);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-crumb {
  display: none;
  align-items: center;
  gap: 6px;
  color: var(--ink-muted);
  font-size: 13.5px;
  min-width: 0;
  overflow: hidden;
}

.header-crumb span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-secondary);
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.nav-link[aria-current="page"] {
  font-weight: 600;
  color: var(--accent);
}

.nav-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.nav-count:empty,
.nav-count[data-count="0"] {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 11px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--ink-muted);
  font-size: 13.5px;
  transition: border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}

.search-trigger:hover {
  border-color: var(--border-strong);
  color: var(--ink-primary);
}

.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--ink-muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
  height: 36px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.icon-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Thin Reading Progress Bar pinned to header bottom */
.reading-progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: transparent;
  pointer-events: none;
}

.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 90ms linear;
}

/* ==========================================================================
   Main Containers
   ========================================================================== */

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

.container--narrow {
  max-width: 820px;
}

/* ==========================================================================
   Chapter 3-Column Editorial Reading Shell
   ========================================================================== */

.reader-shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 28px 20px 80px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 236px;
  gap: 32px;
  align-items: start;
}

.reader-sidebar {
  position: sticky;
  top: calc(var(--header-h) + 20px);
  max-height: calc(100dvh - var(--header-h) - 36px);
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
}

.reader-sidebar--right {
  padding-right: 0;
  padding-left: 4px;
}

.reader-main {
  min-width: 0;
  max-width: var(--measure);
  width: 100%;
  margin: 0 auto;
}

/* Focus Mode (Desktop): collapses sidebars seamlessly */
[data-focus="true"] .reader-shell {
  grid-template-columns: minmax(0, 1fr);
  max-width: 960px;
}

[data-focus="true"] .reader-sidebar {
  display: none;
}

/* Sidebar Book TOC */
.sidebar-section-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 10px;
  padding: 0 8px;
}

.toc-domain {
  margin-bottom: 14px;
}

.toc-domain-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
  padding: 4px 8px;
  margin-bottom: 2px;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ink-secondary);
  transition: background var(--dur-fast), color var(--dur-fast);
}

.toc-link:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.toc-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  flex-shrink: 0;
  width: 20px;
}

.toc-link[aria-current="page"] .toc-num {
  color: var(--accent);
}

/* Right Outline (In-Chapter Entries) */
.outline-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
  color: var(--ink-muted);
}

.outline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.outline-link {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  font-size: 12.5px;
  line-height: 1.42;
  color: var(--ink-muted);
  transition: color var(--dur-fast), background var(--dur-fast), border-color var(--dur-fast);
}

.outline-link:hover {
  color: var(--ink-primary);
  background: var(--bg-hover);
}

.outline-link.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.outline-idx {
  font-family: var(--font-mono);
  font-size: 11px;
  flex-shrink: 0;
  opacity: 0.72;
}

.outline-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ==========================================================================
   Site Footer (CC BY 4.0 Attribution & Upstream Provenance)
   ========================================================================== */

.site-footer {
  margin-top: 64px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 36px 0 44px;
  font-size: 13.5px;
  color: var(--ink-muted);
}

.footer-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.footer-col {
  max-width: 580px;
}

.footer-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-primary);
  margin-bottom: 8px;
}

.footer-meta {
  line-height: 1.7;
  margin-bottom: 6px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
}

.footer-links a {
  color: var(--ink-secondary);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}

.footer-links a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

/* ==========================================================================
   Mobile Fixed Bottom Dock (< 768px)
   ========================================================================== */

.mobile-dock {
  display: none;
}

@media (max-width: 1140px) {
  .reader-shell {
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 24px;
  }
  .reader-sidebar--right {
    display: none;
  }
}

@media (max-width: 900px) {
  .reader-shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 20px 18px 64px;
  }
  .reader-sidebar--left {
    display: none;
  }
  .header-nav {
    display: none;
  }
  .tablet-toc-btn {
    display: inline-flex;
  }
}

@media (min-width: 901px) {
  .tablet-toc-btn {
    display: none;
  }
}

@media (max-width: 767px) {
  :root {
    --header-h: 48px;
  }

  .header-inner {
    padding: 0 14px;
  }

  .brand-title {
    font-size: 15px;
  }

  .header-crumb {
    display: flex;
  }

  .brand-title--hide-mobile {
    display: none;
  }

  .header-actions .hide-mobile,
  .search-trigger kbd,
  .search-trigger .search-label,
  .tablet-toc-btn {
    display: none;
  }

  .search-trigger {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    border: none;
    background: transparent;
  }

  .container {
    padding: 0 16px;
  }

  .reader-shell {
    padding: 16px 16px 104px;
  }

  body {
    padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
  }

  .site-footer {
    margin-top: 40px;
    padding-bottom: 32px;
  }

  .mobile-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    height: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--bg-surface) 95%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-default);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  }

  .dock-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 100%;
    color: var(--ink-muted);
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    transition: color var(--dur-fast);
  }

  .dock-item:active {
    opacity: 0.7;
  }

  .dock-item[aria-current="page"],
  .dock-item.is-active {
    color: var(--accent);
    font-weight: 600;
  }

  .dock-badge {
    position: absolute;
    top: 7px;
    right: calc(50% - 19px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: var(--accent-ink);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
  }

  .dock-badge:empty,
  .dock-badge[data-count="0"] {
    display: none;
  }
}


/* --- 03-components.css --- */
/* ==========================================================================
   Editorial Components: Chapter Header, Topic Groups, Entries, Badges,
   Progressive Citations, Errata Diffs, Buttons, Chips, Toasts
   ========================================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 15px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

.btn--secondary {
  background: var(--bg-surface);
  color: var(--ink-primary);
  border-color: var(--border-default);
  box-shadow: var(--shadow-sm);
}

.btn--secondary:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--ink-primary);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-secondary);
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.btn--sm {
  min-height: 32px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

/* Badges & Evidence Seals */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge--grade-A {
  background: var(--grade-a-bg);
  color: var(--grade-a-ink);
  border-color: var(--grade-a-border);
}

.badge--grade-B {
  background: var(--grade-b-bg);
  color: var(--grade-b-ink);
  border-color: var(--grade-b-border);
}

.badge--grade-C {
  background: var(--grade-c-bg);
  color: var(--grade-c-ink);
  border-color: var(--grade-c-border);
}

.badge--neutral {
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  border-color: var(--border-subtle);
}

.badge--errata {
  background: var(--errata-bg);
  color: var(--errata-ink);
  border-color: var(--errata-border);
}

.badge--disputed {
  background: var(--grade-c-bg);
  color: var(--grade-c-ink);
  border-color: var(--grade-c-border);
}

.badge--audience {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--border-default);
}

/* Filter Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--ink-primary);
}

.chip[aria-pressed="true"],
.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.chip-count {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.78;
}

/* ==========================================================================
   Chapter Header, Organic Resume Banner & Topic Index
   ========================================================================== */

.chapter-resume-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 15px;
  margin-bottom: 20px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--accent-border);
  box-shadow: var(--shadow-sm);
  font-size: 13.5px;
}

.chapter-resume-banner[hidden] {
  display: none;
}

.chapter-resume-text {
  color: var(--ink-secondary);
  min-width: 0;
}

.chapter-resume-text strong {
  color: var(--ink-primary);
}

.chapter-resume-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chapter-header {
  padding-bottom: 24px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border-default);
}

.chapter-kicker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 10px;
}

.chapter-kicker-domain {
  color: var(--accent);
  font-weight: 600;
}

.chapter-title {
  font-size: clamp(1.65rem, 3.2vw, 2.25rem);
  line-height: 1.24;
  margin-bottom: 14px;
}

.chapter-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  font-size: 13px;
  color: var(--ink-muted);
}

.chapter-stat-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chapter-intro {
  margin-top: 20px;
  color: var(--ink-secondary);
  font-size: 0.98em;
}

/* Chapter Topic Groups (structured from intro "**组名**：条目（第 N 条）") */
.chapter-topics {
  margin-top: 22px;
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.chapter-topics-heading {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 12px;
}

.topic-group-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topic-group-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px 14px;
  align-items: baseline;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.topic-group-row:first-child {
  padding-top: 0;
  border-top: none;
}

.topic-group-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-primary);
}

.topic-group-items {
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ink-secondary);
}

@media (max-width: 600px) {
  .topic-group-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
  .chapter-topics {
    padding: 14px 15px;
  }
}

/* ==========================================================================
   Editorial Entry Article (772 Entries)
   ========================================================================== */

.entries-flow {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.entry-card {
  position: relative;
  padding: 26px 28px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-mid) var(--ease-out), box-shadow var(--dur-mid) var(--ease-out);
}

.entry-card.is-highlighted {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-md);
}

.entry-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.entry-id-wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.entry-ordinal {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.entry-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.entry-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 500;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.entry-action-btn:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.entry-action-btn.is-saved {
  color: var(--accent);
  background: var(--accent-soft);
}

.entry-action-btn.is-done {
  color: var(--grade-a-ink);
  background: var(--grade-a-bg);
}

.entry-title {
  font-size: clamp(1.16rem, 2.1vw, 1.36rem);
  line-height: 1.42;
  margin-bottom: 14px;
  overflow-wrap: break-word;
}

/* Compact Cost / ROI Metadata Ribbon */
.entry-meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.roi-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.roi-pill-k {
  color: var(--ink-muted);
}

.roi-pill-v {
  font-weight: 600;
  color: var(--ink-primary);
}

.roi-pill--good .roi-pill-v {
  color: var(--grade-a-ink);
}

.roi-pill--high .roi-pill-v {
  color: var(--accent);
}

/* Tier 1: 说人话 (3-Second Plain-Language Lead) */
.entry-plain {
  position: relative;
  padding: 14px 16px 14px 18px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-callout);
  border-left: 3px solid var(--accent);
}

.field-kicker {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 5px;
}

.entry-plain-body {
  font-size: 1em;
  line-height: 1.78;
  color: var(--ink-primary);
  font-weight: 450;
}

/* Tier 2: 成本 (Cost Breakdown) */
.entry-cost {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 14px;
  margin-bottom: 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  font-size: 0.93em;
  line-height: 1.7;
  color: var(--ink-secondary);
}

.entry-cost-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

/* Tier 3: 收益与实证 + 备注 */
.entry-section {
  margin-bottom: 16px;
}

.entry-section:last-child {
  margin-bottom: 0;
}

.entry-section-label {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.entry-prose {
  color: var(--ink-primary);
  overflow-wrap: break-word;
  word-break: break-word;
}

.entry-prose--muted {
  color: var(--ink-secondary);
  font-size: 0.95em;
}

/* Inline Cross-Reference Links */
.xref-link {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  border-radius: 3px;
  padding: 0 2px;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.xref-link:hover,
.xref-link:focus-visible {
  background: var(--accent-soft);
  text-decoration-style: solid;
}

/* Tier 4: Progressive Disclosure — 文献与信源 (<details>) */
.citation-disclosure {
  margin-top: 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
  overflow: hidden;
}

.citation-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
  user-select: none;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.citation-summary::-webkit-details-marker {
  display: none;
}

.citation-summary:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.citation-summary-left {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.citation-chevron {
  transition: transform var(--dur-fast) var(--ease-out);
  color: var(--ink-muted);
}

.citation-disclosure[open] .citation-chevron {
  transform: rotate(180deg);
}

.citation-body {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 13px;
  line-height: 1.68;
  color: var(--ink-secondary);
  overflow-wrap: anywhere;
}

.citation-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.citation-list li {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.citation-url {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 1px 7px;
  margin: 2px 2px 0;
  border-radius: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--ink-secondary);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  vertical-align: baseline;
  overflow-wrap: anywhere;
  word-break: break-all;
  transition: border-color var(--dur-fast), color var(--dur-fast);
}

.citation-url:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

/* Tier 5: 本站勘误说明 (108 Safety Notes) */
.errata-callout {
  margin-top: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--errata-border);
  background: var(--errata-bg);
  padding: 13px 15px;
  font-size: 13.5px;
  line-height: 1.68;
}

.errata-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: var(--errata-ink);
  margin-bottom: 6px;
}

.errata-note {
  color: var(--ink-primary);
  margin-bottom: 8px;
}

.errata-details {
  margin-top: 8px;
}

.errata-details summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  list-style: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--errata-ink);
  user-select: none;
}

.errata-details summary::-webkit-details-marker {
  display: none;
}

.errata-diff-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.errata-diff-item {
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
}

.errata-diff-field {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.errata-diff-del,
.errata-diff-add {
  padding: 5px 8px;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

.errata-diff-del {
  background: var(--diff-del-bg);
  color: var(--diff-del-ink);
  margin-bottom: 5px;
}

.errata-diff-add {
  background: var(--diff-add-bg);
  color: var(--diff-add-ink);
}

.errata-diff-tag {
  font-weight: 700;
  margin-right: 6px;
}

.errata-sources {
  margin: 10px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.errata-sources a {
  color: var(--errata-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

/* Chapter Bottom Prev/Next Navigation */
.chapter-pager {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-default);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.pager-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--ink-primary);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}

.pager-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-sm);
  color: var(--ink-primary);
}

.pager-card--next {
  text-align: right;
  align-items: flex-end;
}

.pager-dir {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
}

.pager-title {
  font-family: var(--font-serif);
  font-size: 15.5px;
  font-weight: 700;
}

@media (max-width: 767px) {
  .entry-card {
    padding: 18px 16px;
    border-radius: var(--radius-md);
  }
  .entries-flow {
    gap: 20px;
  }
  .entry-action-btn .action-label {
    display: none;
  }
  .chapter-pager {
    grid-template-columns: minmax(0, 1fr);
  }
  .pager-card--next {
    text-align: left;
    align-items: flex-start;
  }
}

/* Toast Notification */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 120;
  pointer-events: none;
  transition: bottom var(--dur-fast) var(--ease-out);
}

body.has-return-pill .toast-region {
  bottom: 72px;
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--ink-primary);
  color: var(--bg-canvas);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-fast), transform var(--dur-fast) var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 767px) {
  .toast-region {
    bottom: calc(var(--dock-h) + 16px + env(safe-area-inset-bottom, 0px));
  }
  body.has-return-pill .toast-region {
    bottom: calc(var(--dock-h) + 64px + env(safe-area-inset-bottom, 0px));
  }
}


/* --- 04-overlays.css --- */
/* ==========================================================================
   Overlays: Command Search Modal, Cross-Ref Popover, Return Stack Pill,
   Mobile Bottom Sheet & Reading Settings Panel
   ========================================================================== */

.overlay-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--scrim);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 68px 16px 24px;
}

.overlay-backdrop[hidden] {
  display: none;
}

/* ==========================================================================
   Command Search Dialog (Cmd/Ctrl + K)
   ========================================================================== */

.search-dialog {
  width: 100%;
  max-width: 680px;
  max-height: calc(100dvh - 110px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.search-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-head-icon {
  color: var(--ink-muted);
  display: inline-flex;
}

.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--ink-primary);
  outline: none;
}

.search-input::placeholder {
  color: var(--ink-faint);
}

.search-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 9px 16px;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
}

.search-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 500;
}

.search-filter-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.search-select {
  height: 26px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 12px;
  max-width: 170px;
}

.search-status {
  padding: 7px 16px;
  font-size: 12px;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-results {
  overflow-y: auto;
  padding: 8px;
  flex: 1;
  min-height: 180px;
}

.search-result-item {
  display: block;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  color: var(--ink-primary);
  border: 1px solid transparent;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}

.search-result-item:hover,
.search-result-item.is-selected {
  background: var(--bg-callout);
  border-color: var(--accent-border);
  color: var(--ink-primary);
}

.search-result-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.search-result-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 4px;
}

.search-result-snippet {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.search-empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
}

.search-hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.search-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
  font-size: 11.5px;
  color: var(--ink-muted);
}

.search-foot kbd {
  font-family: var(--font-mono);
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
}

@media (max-width: 767px) {
  .overlay-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .search-dialog {
    max-width: 100%;
    height: 88dvh;
    max-height: 88dvh;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  .search-foot {
    display: none;
  }
}

/* ==========================================================================
   Cross-Reference Inline Preview Popover
   ========================================================================== */

.xref-popover {
  position: fixed;
  z-index: 85;
  width: min(390px, calc(100vw - 24px));
  padding: 15px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  line-height: 1.62;
}

.xref-popover[hidden] {
  display: none;
}

.xref-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.xref-pop-kicker {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
}

.xref-pop-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink-primary);
  margin-bottom: 8px;
}

.xref-pop-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 9px;
}

.xref-pop-plain {
  color: var(--ink-secondary);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.xref-pop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Return Stack Floating Pill (Back to Previous Reading Position)
   ========================================================================== */

.return-pill {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 75;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 28px);
  padding: 6px 8px 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--ink-primary);
  color: var(--bg-canvas);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
}

.return-pill[hidden] {
  display: none;
}

.return-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  font-weight: 600;
  min-width: 0;
}

.return-pill-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.return-pill-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: inherit;
  opacity: 0.72;
}

.return-pill-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.14);
}

@media (max-width: 767px) {
  .return-pill {
    bottom: calc(var(--dock-h) + 12px + env(safe-area-inset-bottom, 0px));
  }
}

/* ==========================================================================
   Sheet / Drawer (Settings Aa Panel & Mobile/Tablet TOC Drawer)
   ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: var(--scrim);
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet-panel {
  width: min(380px, 100vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 100dvh;
}

.sheet-handle {
  display: none;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.sheet-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
}

.sheet-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
}

.sheet-tab {
  height: 34px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-muted);
}

.sheet-tab[aria-selected="true"] {
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 28px;
}

/* Settings controls */
.setting-group {
  margin-bottom: 22px;
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 10px;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  transition: background var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}

.segmented-btn[aria-pressed="true"] {
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.setting-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
}

.setting-toggle-desc {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.storage-notice {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--grade-c-bg);
  color: var(--grade-c-ink);
  font-size: 12.5px;
  line-height: 1.5;
}

@media (max-width: 767px) {
  .sheet-backdrop {
    align-items: flex-end;
    justify-content: center;
  }
  .sheet-panel {
    width: 100%;
    max-height: 82dvh;
    border-left: none;
    border-top: 1px solid var(--border-default);
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sheet-handle {
    display: block;
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: var(--border-strong);
    margin: 9px auto 0;
  }
  .sheet-head {
    padding: 10px 18px 12px;
  }
}


/* --- 05-pages.css --- */
/* ==========================================================================
   Page Layouts: Home (Frontispiece + ROI Explorer + 8 Domains),
   Action List (/list/), Errata Center (/errata/), and 404 Page
   ========================================================================== */

/* ---- Home Book Frontispiece (Editorial Masthead, Zero Marketing Fluff) ---- */
.frontispiece {
  padding: 40px 0 32px;
  border-bottom: 1px solid var(--border-default);
}

.frontispiece-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr);
  gap: 28px 40px;
  align-items: end;
}

.edition-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.frontispiece-title {
  font-size: clamp(2rem, 4.2vw, 2.95rem);
  line-height: 1.16;
  letter-spacing: 0.015em;
  margin-bottom: 14px;
}

.frontispiece-lead {
  font-size: clamp(1rem, 1.4vw, 1.1rem);
  line-height: 1.72;
  color: var(--ink-secondary);
  max-width: 56ch;
  margin-bottom: 22px;
}

.frontispiece-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* Right-side Ledger Card (Book Numbers + Resume Slot) */
.book-ledger {
  padding: 20px 22px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
}

.ledger-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.ledger-stat-num {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
}

.ledger-stat-label {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 4px;
}

.ledger-meta {
  padding-top: 14px;
  font-size: 12.5px;
  color: var(--ink-muted);
  line-height: 1.65;
}

.ledger-meta a {
  color: var(--ink-secondary);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
}

.ledger-meta a:hover {
  color: var(--accent);
}

/* Continue Reading Card (shown dynamically when user has reading progress) */
.resume-card {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--accent-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.resume-card[hidden] {
  display: none;
}

.resume-card-info {
  min-width: 0;
  flex: 1;
}

.resume-card-kicker {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.resume-card-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-card-sub {
  font-size: 12.5px;
  color: var(--ink-muted);
}

/* ==========================================================================
   Home Section: ROI Decision Explorer
   ========================================================================== */

.home-section {
  padding: 40px 0 12px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.section-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.section-title {
  font-size: clamp(1.35rem, 2.4vw, 1.7rem);
}

.section-sub {
  font-size: 14px;
  color: var(--ink-muted);
  margin-top: 4px;
}

.explorer-shell {
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.preset-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
}

.preset-bar .chip {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 767px) {
  .preset-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .preset-bar::-webkit-scrollbar {
    display: none;
  }
}

.explorer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.explorer-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.explorer-count {
  font-size: 13.5px;
  color: var(--ink-secondary);
}

.explorer-count strong {
  font-family: var(--font-mono);
  color: var(--ink-primary);
}

.explorer-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-input {
  height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-size: 13px;
  min-width: 215px;
}

.inline-select {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-size: 13px;
}

/* Advanced Multi-Facet Filter Grid */
.facet-panel {
  padding: 16px 18px;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 20px;
}

.facet-panel[hidden] {
  display: none;
}

.facet-group-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 7px;
}

.facet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.facet-chip {
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-weight: 500;
}

.facet-chip:hover {
  border-color: var(--border-strong);
  color: var(--ink-primary);
}

.facet-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* Decision Result Grid */
.explorer-results {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.decision-card {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}

.decision-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.decision-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.decision-card-loc {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.decision-card-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink-primary);
  margin-bottom: 8px;
  display: block;
}

.decision-card-title:hover {
  color: var(--accent);
}

.decision-card-plain {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-secondary);
  margin-bottom: 12px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.decision-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.decision-card-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.explorer-more {
  padding: 4px 18px 20px;
  text-align: center;
}

/* ==========================================================================
   Home Section: 8 Life Domains Book Catalog (34 Chapters)
   ========================================================================== */

.domains-stack {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.domain-block {
  padding-top: 22px;
  border-top: 1px solid var(--border-subtle);
}

.domain-block:first-child {
  padding-top: 0;
  border-top: none;
}

.domain-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.domain-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.domain-title {
  font-size: 1.2rem;
}

.domain-sub {
  font-size: 13.5px;
  color: var(--ink-muted);
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.chapter-card {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast), transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}

.chapter-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: var(--ink-primary);
}

.chapter-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.chapter-card-num {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.chapter-card-progress {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.chapter-card-progress:empty {
  display: none;
}

.chapter-card-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.38;
  margin-bottom: 6px;
}

.chapter-card-excerpt {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-muted);
  margin-bottom: 12px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chapter-card-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-faint);
}

/* ==========================================================================
   Action List Page (/list/) & Errata Page (/errata/)
   ========================================================================== */

.page-hero {
  padding: 34px 0 24px;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: 24px;
}

.page-hero h1 {
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  margin-bottom: 10px;
}

.page-hero p {
  color: var(--ink-secondary);
  max-width: 64ch;
}

.list-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.list-tabs {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.checklist-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.checklist-item.is-done {
  opacity: 0.78;
}

.checklist-item.is-done .checklist-title {
  text-decoration: line-through;
  color: var(--ink-muted);
}

.check-toggle {
  margin-top: 2px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1.5px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: transparent;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}

.check-toggle[aria-pressed="true"] {
  background: var(--grade-a-ink);
  border-color: var(--grade-a-ink);
  color: #ffffff;
}

.checklist-body {
  flex: 1;
  min-width: 0;
}

.checklist-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-primary);
  display: inline-block;
  margin-bottom: 5px;
}

.checklist-plain {
  font-size: 13.5px;
  color: var(--ink-secondary);
  line-height: 1.62;
  margin-bottom: 8px;
}

/* Errata Page */
.errata-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.errata-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.errata-page-card {
  padding: 18px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.errata-page-card[hidden] {
  display: none;
}

.errata-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.errata-card-title {
  font-family: var(--font-serif);
  font-size: 16.5px;
  font-weight: 700;
  color: var(--ink-primary);
  margin-bottom: 8px;
  display: block;
}

.provenance-card {
  margin-top: 40px;
  padding: 22px 24px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
}

.provenance-card h2 {
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.provenance-dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px 16px;
  margin: 14px 0 0;
  font-size: 13.5px;
}

.provenance-dl dt {
  color: var(--ink-muted);
  font-weight: 600;
}

.provenance-dl dd {
  margin: 0;
  color: var(--ink-primary);
  overflow-wrap: anywhere;
}

/* Empty States & 404 */
.empty-state {
  padding: 44px 20px;
  text-align: center;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  color: var(--ink-muted);
}

.empty-state h2,
.empty-state h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  max-width: 44ch;
  margin: 0 auto 18px;
}

.not-found-wrap {
  padding: 64px 0 80px;
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
}

.not-found-code {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 12px;
}

.not-found-wrap h1 {
  font-size: 1.65rem;
  margin-bottom: 10px;
}

.not-found-wrap p {
  color: var(--ink-secondary);
  margin-bottom: 24px;
}

.not-found-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}

@media (max-width: 960px) {
  .frontispiece-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .chapter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .explorer-results {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .frontispiece {
    padding: 24px 0 22px;
  }
  .chapter-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .explorer-results {
    padding: 12px;
  }
  .preset-bar {
    padding: 12px 14px;
  }
  .explorer-toolbar {
    padding: 10px 14px;
  }
  .provenance-dl {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .provenance-dl dd {
    margin-bottom: 10px;
  }
}
