
:root {
  color-scheme: light;
  --ink: #162232;
  --muted: #647182;
  --paper: #ffffff;
  --canvas: #edf2f7;
  --line: #d5dde7;
  --accent: #c83c32;
  --accent-strong: #9c281f;
  --nav: #10263f;
  --nav-ink: #f5f8fb;
  --nav-muted: #b9c5d2;
  --focus: #1d6fd6;
  --reader-font-size: 1.125rem;
  --content-width: 74ch;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8edf3;
  --muted: #a8b4c2;
  --paper: #111922;
  --canvas: #0a1119;
  --line: #2b3948;
  --accent: #ff7164;
  --accent-strong: #ff9187;
  --nav: #08131f;
  --nav-ink: #f4f7fa;
  --nav-muted: #9daab9;
  --focus: #78b5ff;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Noto Serif TC", "Source Han Serif TC", "Microsoft JhengHei", system-ui, sans-serif;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.75rem 1rem;
  color: #fff;
  background: #000;
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.reading-progress {
  position: fixed;
  z-index: 70;
  inset: 0 0 auto 0;
  height: 3px;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.site-layout {
  display: grid;
  grid-template-columns: 20rem minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  z-index: 40;
  inset: 0 auto 0 0;
  width: 20rem;
  overflow-y: auto;
  color: var(--nav-ink);
  background: var(--nav);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-head {
  display: grid;
  grid-template-columns: 3rem 1fr;
  gap: 0.9rem;
  align-items: center;
  padding: 1.5rem 1.25rem 1.2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.book-mark {
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  color: #fff;
  text-decoration: none;
  border: 2px solid var(--accent);
}

.book-mark span { font-size: 1.4rem; font-weight: 800; }

.book-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.45;
  text-decoration: none;
}

.sidebar-head p {
  margin: 0.22rem 0 0;
  color: var(--nav-muted);
  font-size: 0.78rem;
}

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

.toc-link {
  display: grid;
  grid-template-columns: 2.35rem 1fr;
  gap: 0.55rem;
  align-items: start;
  padding: 0.58rem 1.25rem;
  color: var(--nav-muted);
  font-size: 0.9rem;
  line-height: 1.45;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.toc-link:hover,
.toc-link.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.toc-link.is-active { border-left-color: var(--accent); }

.toc-number {
  color: #8191a4;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
}

.toc-appendix {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.content-column { grid-column: 2; min-width: 0; }

.reader-toolbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  min-height: 3.6rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem clamp(1rem, 4vw, 3rem);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.toolbar-home {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
}

.toolbar-home:hover { color: var(--accent); }

.toolbar-actions { display: flex; gap: 0.38rem; }

.toolbar-actions button,
.icon-button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.55rem 0.75rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.toolbar-actions button:hover,
.icon-button:hover { border-color: var(--accent); color: var(--accent); }

main {
  width: min(100%, calc(var(--content-width) + 6rem));
  min-height: calc(100vh - 11rem);
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 5rem) clamp(1.2rem, 5vw, 3rem) 5rem;
  background: var(--paper);
}

.index-intro { padding-bottom: 2rem; border-bottom: 1px solid var(--line); }

.eyebrow,
.chapter-kicker {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-family: "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1, h2, strong { text-wrap: balance; }

.index-intro h1,
.article-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.22;
  letter-spacing: -0.025em;
}

.index-subtitle {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.3rem);
}

.index-scope { margin: 0.6rem 0 0; color: var(--muted); line-height: 1.7; }

.chapter-index,
.editorial-notes { padding-top: 2.5rem; }

.section-heading-row {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  justify-content: space-between;
}

.section-heading-row h2,
.editorial-notes h2 {
  margin: 0;
  font-size: 1.45rem;
}

.section-heading-row > a {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 800;
  text-underline-offset: 0.25em;
}

.chapter-index ol {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 1.2rem 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.chapter-index li { border-bottom: 1px solid var(--line); }

.chapter-index li:nth-child(odd) { border-right: 1px solid var(--line); }

.chapter-index li a,
.appendix-link {
  display: grid;
  grid-template-columns: 2.6rem 1fr;
  gap: 0.8rem;
  align-items: start;
  min-height: 5.2rem;
  padding: 1rem;
  text-decoration: none;
}

.chapter-index li a:hover,
.appendix-link:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }

.chapter-index li span,
.appendix-link span {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.chapter-index li strong,
.appendix-link strong { font-size: 1rem; line-height: 1.55; }

.appendix-link { margin-top: 1rem; border: 1px solid var(--line); }

.editorial-notes ul { margin: 1rem 0 0; padding-left: 1.4rem; }

.editorial-notes li { margin: 0.72rem 0; line-height: 1.8; }

.article-header { padding-bottom: 1.8rem; border-bottom: 1px solid var(--line); }

.source-details { margin-top: 1.4rem; color: var(--muted); font-family: "Microsoft JhengHei", system-ui, sans-serif; }

.source-details summary { width: fit-content; cursor: pointer; font-size: 0.9rem; font-weight: 700; }

.source-details dl { margin: 1rem 0 0; font-size: 0.82rem; }

.source-details dl div { display: grid; grid-template-columns: 6rem 1fr; gap: 0.8rem; padding: 0.38rem 0; }

.source-details dt { font-weight: 800; }

.source-details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.source-details a,
.appendix-source a { color: var(--accent); text-underline-offset: 0.2em; }

.source-details code { color: inherit; font-size: 0.75rem; }

.safety-note {
  margin: 2rem 0 0;
  padding: 0.9rem 0 0.9rem 1rem;
  color: var(--muted);
  font-family: "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 0.88rem;
  line-height: 1.7;
  border-left: 3px solid var(--accent);
}

.safety-note strong { color: var(--ink); }

.article-body {
  padding-top: 2.2rem;
  font-size: var(--reader-font-size);
  line-height: 2;
  letter-spacing: 0.025em;
}

.article-paragraph { margin: 0 0 1.45em; text-align: justify; text-justify: inter-ideograph; }

.article-paragraph.byline { color: var(--muted); font-size: 0.92em; text-align: left; }

.article-paragraph.annotation {
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.9em;
  border-left: 2px solid var(--line);
}

.article-subheading { margin: 2.4em 0 0.9em; font-size: 1.22em; line-height: 1.5; }

.body-list-item { margin: 0.75em 0 0.75em 1.4em; }

.chapter-pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.pager-link { display: flex; flex-direction: column; min-height: 5rem; padding: 0.9rem; text-decoration: none; border: 1px solid var(--line); }

.pager-link:hover { color: var(--accent); border-color: var(--accent); }

.pager-link.next { text-align: right; }

.pager-link span { color: var(--muted); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.08em; }

.pager-link strong { margin-top: 0.35rem; line-height: 1.5; }

.site-footer {
  width: min(100%, calc(var(--content-width) + 6rem));
  margin: 0 auto;
  padding: 2rem clamp(1.2rem, 5vw, 3rem) 3rem;
  color: var(--muted);
  background: var(--paper);
  border-top: 1px solid var(--line);
  font-family: "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 0.78rem;
  line-height: 1.7;
}

.site-footer p { margin: 0.3rem 0; }

.mobile-header,
.sidebar-scrim { display: none; }

@media (max-width: 880px) {
  .site-layout { display: block; }
  .content-column { width: 100%; }
  .mobile-header {
    position: sticky;
    z-index: 50;
    top: 0;
    display: grid;
    grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
    gap: 0.65rem;
    align-items: center;
    min-height: 3.8rem;
    padding: 0.5rem 0.75rem;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
  }
  .mobile-brand { overflow: hidden; font-size: 0.9rem; font-weight: 800; text-align: center; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
  .icon-button { min-width: 2.75rem; padding: 0.4rem; }
  .sidebar { width: min(88vw, 21rem); transform: translateX(-105%); transition: transform 180ms ease; box-shadow: 1.2rem 0 3rem rgba(0, 0, 0, 0.28); }
  body.menu-open { overflow: hidden; }
  body.menu-open .sidebar { transform: translateX(0); }
  .sidebar-scrim { position: fixed; z-index: 35; inset: 0; width: 100%; height: 100%; padding: 0; background: rgba(2, 10, 18, 0.6); border: 0; opacity: 0; pointer-events: none; }
  body.menu-open .sidebar-scrim { display: block; opacity: 1; pointer-events: auto; }
  .reader-toolbar { top: 3.8rem; min-height: 3.3rem; padding: 0.45rem 0.8rem; }
  .toolbar-home { display: none; }
  .toolbar-actions { width: 100%; justify-content: center; }
  .desktop-theme { display: none; }
  main { min-height: calc(100vh - 12rem); padding-top: 2rem; }
  .chapter-index ol { grid-template-columns: 1fr; }
  .chapter-index li:nth-child(odd) { border-right: 0; }
}

@media (max-width: 560px) {
  :root { --reader-font-size: 1.08rem; }
  main { padding-right: 1.05rem; padding-left: 1.05rem; }
  .index-intro h1, .article-header h1 { font-size: clamp(1.8rem, 9vw, 2.5rem); }
  .section-heading-row { align-items: flex-start; flex-direction: column; }
  .source-details dl div { grid-template-columns: 1fr; gap: 0.12rem; }
  .chapter-pager { grid-template-columns: 1fr; }
  .pager-link.next { text-align: left; }
  .article-paragraph { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .sidebar { transition: none; }
}

@media print {
  .sidebar, .mobile-header, .reader-toolbar, .reading-progress, .chapter-pager, .site-footer { display: none !important; }
  .site-layout, .content-column { display: block; }
  main { width: auto; margin: 0; padding: 0; color: #000; background: #fff; }
  .article-body { font-size: 12pt; line-height: 1.8; }
  .source-details { break-inside: avoid; }
}
