:root {
  color-scheme: light dark;
  --paper: #f4f6f8;
  --paper-raised: #ffffff;
  --ink: #17202b;
  --muted: #5e6a78;
  --line: #d9e0e8;
  --soft: #edf2f7;
  --accent: #1479d1;
  --accent-ink: #075899;
  --accent-soft: #e7f2ff;
  --shadow: 0 18px 42px rgba(21, 38, 57, .10);
  --radius: 8px;
  --page: 72rem;
  --toc: 18rem;
}

:root[data-theme="dark"] {
  --paper: #111820;
  --paper-raised: #17212c;
  --ink: #edf3f8;
  --muted: #a9b5c1;
  --line: #2c3a47;
  --soft: #1e2a36;
  --accent: #5eb1ff;
  --accent-ink: #a6d4ff;
  --accent-soft: #102b46;
  --shadow: 0 18px 42px rgba(0, 0, 0, .26);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #111820;
    --paper-raised: #17212c;
    --ink: #edf3f8;
    --muted: #a9b5c1;
    --line: #2c3a47;
    --soft: #1e2a36;
    --accent: #5eb1ff;
    --accent-ink: #a6d4ff;
    --accent-soft: #102b46;
    --shadow: 0 18px 42px rgba(0, 0, 0, .26);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 5.5rem; }
body {
  margin: 0;
  min-width: 20rem;
  color: var(--ink);
  background: var(--paper);
  font-family: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  font-size: 17px;
  line-height: 1.82;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.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; left: 1rem; top: -4rem; z-index: 20; padding: .5rem .8rem; background: var(--accent); color: #fff; border-radius: var(--radius); }
.skip-link:focus { top: 1rem; }
.site-header { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(14px); }
.header-inner { max-width: calc(var(--page) + 2rem); min-height: 4.1rem; padding: .6rem 1rem; margin: auto; display: flex; align-items: center; gap: 1rem; }
.wordmark { color: var(--ink); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .83rem; font-weight: 800; letter-spacing: .08em; text-decoration: none; white-space: nowrap; }
.header-tools { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.search { position: relative; width: min(20rem, 38vw); }
.search input { width: 100%; min-height: 2.45rem; padding: .45rem .8rem .45rem 2.15rem; color: var(--ink); background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius); }
.search::before { content: "⌕"; position: absolute; top: .18rem; left: .75rem; color: var(--muted); pointer-events: none; }
.icon-button { min-width: 2.45rem; min-height: 2.45rem; padding: .35rem .55rem; color: var(--ink); background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.progress { height: 2px; background: var(--line); }
.progress > span { display: block; height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; animation: reading-progress linear both; animation-timeline: scroll(root); }

@keyframes reading-progress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.cover { max-width: var(--page); padding: clamp(3.5rem, 10vw, 8rem) 1.25rem clamp(2.5rem, 8vw, 6rem); margin: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(15rem, .72fr); align-items: center; gap: clamp(2rem, 6vw, 6rem); }
.cover-kicker, .eyebrow, .section-marker { margin: 0 0 1rem; color: var(--accent); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.cover h1 { max-width: 12ch; margin: 0; font-size: clamp(2.3rem, 5.2vw, 5rem); line-height: 1.16; letter-spacing: -.05em; }
.cover .subtitle { max-width: 34rem; margin: 1.35rem 0 0; color: var(--muted); font-size: clamp(1.03rem, 1.8vw, 1.25rem); line-height: 1.72; }
.meta-row { display: flex; flex-wrap: wrap; gap: .5rem 1.15rem; margin-top: 1.55rem; color: var(--muted); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .82rem; }
.cover-art { width: 100%; max-height: 29rem; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.notice { max-width: var(--page); margin: 0 auto 3rem; padding: 0 1.25rem; }
.notice-inner { padding: 1.15rem 1.3rem; color: var(--ink); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: var(--radius); }
.notice strong { font-family: ui-sans-serif, system-ui, sans-serif; font-size: .84rem; letter-spacing: .04em; }
.notice p { margin: .45rem 0 0; font-size: .95rem; line-height: 1.65; }

.reader-shell { max-width: calc(var(--page) + var(--toc) + 4rem); padding: 0 1.25rem 5rem; margin: auto; display: grid; grid-template-columns: var(--toc) minmax(0, var(--page)); gap: 2.5rem; align-items: start; }
.toc-panel { position: sticky; top: 5.5rem; max-height: calc(100vh - 7rem); padding: .2rem .1rem .75rem 0; overflow: auto; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .8rem; line-height: 1.45; }
.toc-panel h2 { margin: 0 0 .65rem; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; }
.toc-panel a { display: block; padding: .36rem .55rem; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; }
.toc-panel a:hover, .toc-panel a[aria-current="true"] { color: var(--accent-ink); background: var(--accent-soft); border-left-color: var(--accent); }
.toc-panel a.level-3 { padding-left: 1.2rem; font-size: .75rem; }
.toc-panel a.level-4 { padding-left: 1.8rem; font-size: .72rem; }
.mobile-toc { display: none; }

.book { min-width: 0; }
.book > * { max-width: 100%; }
.book h2, .book h3, .book h4, .book h5 { position: relative; scroll-margin-top: 5.7rem; }
.book h2 { margin: 5rem 0 1.45rem; padding-top: 1.35rem; font-size: clamp(1.65rem, 3vw, 2.3rem); line-height: 1.35; letter-spacing: -.035em; border-top: 1px solid var(--line); }
.book h3 { margin: 3rem 0 1rem; font-size: clamp(1.32rem, 2.1vw, 1.65rem); line-height: 1.45; letter-spacing: -.025em; }
.book h4 { margin: 2.25rem 0 .8rem; font-size: 1.15rem; line-height: 1.55; }
.book h5 { margin: 1.65rem 0 .65rem; font-size: 1rem; line-height: 1.6; }
.book p { margin: 0 0 1.15rem; overflow-wrap: anywhere; }
.book .doc-list { margin: 0 0 1.15rem; padding-left: 1.5rem; }
.book .doc-list li { padding-left: .25rem; margin: .25rem 0; }
.book pre { margin: 1.4rem 0; padding: 1rem 1.1rem; overflow: auto; color: #eaf4ff; background: #101a25; border: 1px solid #30475e; border-radius: var(--radius); font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .86rem; line-height: 1.65; tab-size: 2; }
.book code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .88em; }
.book :not(pre) > code { padding: .12em .3em; background: var(--soft); border-radius: 3px; }
.book figure { margin: 1.7rem 0; padding: .6rem; background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(21, 38, 57, .06); }
.book figure img { display: block; width: 100%; height: auto; max-height: 42rem; object-fit: contain; }
.book figcaption { padding: .55rem .25rem .1rem; color: var(--muted); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .75rem; line-height: 1.55; }
.table-wrap { margin: 1.4rem 0; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.book table { width: 100%; min-width: 37rem; border-collapse: collapse; background: var(--paper-raised); font-size: .9rem; line-height: 1.65; }
.book th, .book td { min-width: 8rem; padding: .65rem .75rem; vertical-align: top; text-align: left; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.book tr:last-child > * { border-bottom: 0; }
.book tr > *:last-child { border-right: 0; }
.book th, .book tr:first-child td { background: var(--soft); font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 700; }
.table-cell-block { margin: 0 0 .65rem; }
.table-cell-block:last-child { margin-bottom: 0; }
.empty { color: var(--muted); }
.search-hit { color: inherit; background: #ffe487; }
:root[data-theme="dark"] .search-hit { background: #8d6600; }
.book-footer { margin-top: 4rem; padding-top: 1.5rem; color: var(--muted); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .78rem; border-top: 1px solid var(--line); }

@media (max-width: 66rem) {
  .cover { grid-template-columns: 1fr; }
  .cover-art { max-width: 28rem; }
  .reader-shell { display: block; }
  .toc-panel { display: none; }
  .mobile-toc { display: block; margin-bottom: 2rem; }
  .mobile-toc summary { padding: .7rem .85rem; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .85rem; font-weight: 700; color: var(--ink); background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
  .mobile-toc nav { max-height: 20rem; padding: .65rem; overflow: auto; background: var(--paper-raised); border: 1px solid var(--line); border-top: 0; }
  .mobile-toc a { display: block; padding: .35rem .3rem; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .8rem; line-height: 1.45; }
}

@media (max-width: 40rem) {
  body { font-size: 16px; }
  .header-inner { gap: .5rem; }
  .wordmark { max-width: 6rem; overflow: hidden; text-overflow: ellipsis; }
  .search { width: auto; flex: 1; }
  .search input { min-width: 0; }
  .reader-shell, .cover { padding-left: 1rem; padding-right: 1rem; }
  .notice { padding-left: 1rem; padding-right: 1rem; }
  .book h2 { margin-top: 3.5rem; }
}

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