:root {
  color-scheme: light;
  --paper: #ffffff;
  --paper-soft: #f5f7f8;
  --ink: #172126;
  --ink-soft: #536168;
  --line: #d8dfe2;
  --line-strong: #aebbc0;
  --teal: #087f79;
  --teal-soft: #e2f2f0;
  --coral: #dc654f;
  --gold: #c58b19;
  --green: #245f46;
  --blue: #2c5f8b;
  --code: #10181c;
  --sidebar: #f0f3f4;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --sidebar-width: 320px;
  --reading-width: 820px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #11171a;
  --paper-soft: #182125;
  --ink: #edf2f3;
  --ink-soft: #aab8bd;
  --line: #344248;
  --line-strong: #596970;
  --teal: #55c3bc;
  --teal-soft: #173d3b;
  --coral: #ef816d;
  --gold: #e1ad42;
  --green: #78b995;
  --blue: #76a8d1;
  --code: #080d0f;
  --sidebar: #151d20;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 28px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.82;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--teal); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 100;
  background: transparent;
}
.reading-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--coral);
  transform: scaleX(0);
  transform-origin: left;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-width);
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  font-family: var(--sans);
}
.sidebar-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.book-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ink) 55%, var(--line));
  border-radius: 3px;
  background: var(--ink);
  box-shadow: inset 0 0 0 3px var(--sidebar), 0 4px 12px rgba(6, 14, 18, 0.12);
  color: var(--paper);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 750;
  font-size: 20px;
  line-height: 1;
}
.book-mark::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid color-mix(in srgb, var(--paper) 34%, transparent);
}
.book-mark::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 5px;
  height: 5px;
  background: var(--coral);
}
.book-mark span { position: relative; z-index: 1; }
.book-mark:hover { color: var(--paper); transform: translateY(-1px); }
.sidebar-close { display: none; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 14px 8px;
  padding: 0 11px;
  min-height: 40px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-soft);
}
.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
}

.toc { overflow: auto; padding: 8px 10px 22px; }
.toc-part-group { margin: 2px 0 8px; }
.toc-part-group + .toc-part-group {
  padding-top: 7px;
  border-top: 1px solid var(--line);
}
.toc-part-group summary {
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 8px;
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.4;
}
.toc-part-group summary::-webkit-details-marker { display: none; }
.toc-part-group summary::before {
  content: "›";
  grid-column: 2;
  grid-row: 1;
  color: var(--ink-soft);
  font-size: 16px;
  transform: rotate(0deg);
  transition: transform 150ms ease;
}
.toc-part-group[open] summary::before { transform: rotate(90deg); }
.toc-part-group summary span { grid-column: 1; grid-row: 1; }
.toc-part-group summary:hover { background: var(--paper); color: var(--teal); }
.toc-chapters { margin: 1px 0 7px 9px; }
.toc-chapter {
  display: block;
  padding: 6px 9px 6px 12px;
  border-left: 2px solid transparent;
  border-radius: 3px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 11px;
  line-height: 1.45;
}
.toc a:hover { background: var(--paper); color: var(--ink); }
.toc a.active { border-left-color: var(--coral); background: var(--paper); color: var(--teal); }

.icon-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--teal); color: var(--teal); }
.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-family: var(--sans);
  line-height: 1;
}
.sidebar .sidebar-close { display: none; }

.theme-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 60;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  box-shadow: 0 3px 12px rgba(6, 14, 18, 0.09);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.theme-toggle:hover { border-color: var(--teal); color: var(--teal); }

.mobile-bar { display: none; }
.sidebar-scrim { display: none; }
.page-shell { margin-left: var(--sidebar-width); min-width: 0; }

.cover {
  position: relative;
  min-height: min(780px, 84vh);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  color: #fff;
  background: #101619;
}
.cover-media {
  position: absolute;
  inset: 0;
  display: block;
}
.cover-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.72) contrast(1.05);
}
.cover-overlay { position: absolute; inset: 0; background: rgba(8, 14, 17, 0.68); }
.cover-copy {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 80px));
  margin: 0 auto;
  padding: 80px 0 112px;
}
.cover-kicker {
  margin: 0 0 18px;
  color: #e2b54b;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 800;
}
.cover h1 {
  margin: 0;
  max-width: 760px;
  font-family: var(--serif);
  font-size: clamp(50px, 7vw, 94px);
  line-height: 1.06;
  letter-spacing: 0;
}
.cover-copy > p:not(.cover-kicker) {
  max-width: 700px;
  margin: 24px 0 28px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 18px;
}
.book-content { width: min(var(--reading-width), calc(100% - 64px)); margin: 0 auto; padding: 80px 0 140px; }
.book-section { padding: 0 0 70px; }
.book-section + .book-section { border-top: 1px solid var(--line); padding-top: 72px; }

.home-overview {
  width: min(980px, calc(100% - 64px));
  margin: 0 auto;
  padding: 84px 0 112px;
}
.home-kicker,
.chapter-part-label {
  margin: 0 0 14px;
  color: var(--coral);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 800;
}
.home-overview h2 {
  max-width: 820px;
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 34px;
  line-height: 1.3;
  letter-spacing: 0;
}
.home-lede {
  max-width: 780px;
  margin: 24px 0 48px;
  color: var(--ink-soft);
  font-size: 18px;
}
.part-index {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.part-entry {
  display: block;
  min-width: 0;
  padding: 18px 18px 18px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}
.part-entry:nth-child(odd) { border-right: 1px solid var(--line); }
.part-entry:nth-child(even) { padding-left: 18px; }
.part-entry span,
.part-entry strong { display: block; }
.part-entry span {
  color: var(--teal);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.45;
}
.part-entry strong {
  overflow: hidden;
  margin-top: 5px;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.part-entry:hover strong { color: var(--ink); }

.chapter-part-label { margin-bottom: 26px; }
.chapter-outline {
  margin: 0 0 54px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}
.chapter-outline summary {
  list-style: none;
  cursor: pointer;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}
.chapter-outline summary::-webkit-details-marker { display: none; }
.chapter-outline summary::after { content: "＋"; float: right; color: var(--teal); font-weight: 500; }
.chapter-outline[open] summary::after { content: "−"; }
.chapter-outline > div {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 24px;
  padding-top: 10px;
}
.chapter-outline a {
  display: block;
  padding: 4px 0;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12px;
  line-height: 1.5;
}
.chapter-outline a:hover,
.chapter-outline a.active { color: var(--teal); }

.chapter-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-top: 54px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
}
.chapter-nav a {
  display: block;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}
.chapter-nav span,
.chapter-nav strong { display: block; }
.chapter-nav span {
  margin-bottom: 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 750;
}
.chapter-nav strong {
  font-size: 13px;
  line-height: 1.5;
}
.chapter-next { text-align: right; }
.chapter-nav a:hover strong { color: var(--coral); }

.book-content h1,
.book-content h2,
.book-content h3 {
  position: relative;
  scroll-margin-top: 24px;
  font-family: var(--sans);
  color: var(--ink);
  letter-spacing: 0;
}
.book-content h1 {
  margin: 0 0 34px;
  font-size: 38px;
  line-height: 1.22;
}
.book-content h1 + h1 { margin-top: 54px; color: var(--teal); font-size: 32px; }
.book-content h2 { margin: 48px 0 16px; font-size: 24px; line-height: 1.35; }
.book-content h3 { margin: 34px 0 12px; font-size: 19px; line-height: 1.4; }
.heading-link {
  position: absolute;
  left: -1.2em;
  color: var(--line-strong);
  opacity: 0;
  text-decoration: none;
  font-weight: 400;
}
h1:hover .heading-link, h2:hover .heading-link, h3:hover .heading-link, .heading-link:focus { opacity: 1; }

.book-content p { margin: 0 0 1.15em; }
.book-content strong { color: var(--ink); font-weight: 750; }
.book-content blockquote {
  margin: 28px 0;
  padding: 18px 22px;
  border-left: 4px solid var(--coral);
  background: var(--paper-soft);
  color: var(--ink-soft);
}
.book-content hr { margin: 72px 0; border: 0; border-top: 1px solid var(--line); }
.book-content ul, .book-content ol { margin: 0 0 1.4em; padding-left: 1.4em; }
.book-content li { margin: 0.4em 0; padding-left: 0.25em; }

.book-content code {
  padding: 0.13em 0.36em;
  border-radius: 3px;
  background: var(--teal-soft);
  color: var(--green);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82em;
}
.book-content pre {
  position: relative;
  overflow: auto;
  margin: 25px 0 32px;
  padding: 22px 24px;
  border: 1px solid #28343a;
  border-radius: 6px;
  background: var(--code);
  color: #dce6e9;
  line-height: 1.58;
  tab-size: 2;
}
.book-content pre code { padding: 0; background: transparent; color: inherit; font-size: 13px; }
.copy-button {
  position: sticky;
  float: right;
  top: 8px;
  margin: -12px -12px 0 16px;
  padding: 5px 8px;
  border: 1px solid #47565d;
  border-radius: 4px;
  background: #1a252a;
  color: #bac7cc;
  font-family: var(--sans);
  font-size: 11px;
  cursor: pointer;
}

.book-content table {
  display: block;
  overflow-x: auto;
  width: 100%;
  margin: 26px 0 34px;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.55;
}
.book-content th, .book-content td { padding: 10px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.book-content th { background: var(--paper-soft); color: var(--ink); font-weight: 750; }

.book-content p:has(> img:only-child),
.book-content p:has(> picture:only-child) { margin: 38px calc((min(100vw - var(--sidebar-width) - 16px, 1180px) - var(--reading-width)) / -2) 10px; }
.book-content picture { display: block; }
.book-content img {
  display: block;
  width: 100%;
  max-height: 760px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: zoom-in;
}
.book-content p:has(> img:only-child) + p > em:only-child,
.book-content p:has(> picture:only-child) + p > em:only-child {
  display: block;
  max-width: var(--reading-width);
  margin: 0 auto 26px;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 12px;
  font-style: normal;
  line-height: 1.6;
}

.image-dialog {
  width: min(96vw, 1500px);
  max-width: none;
  max-height: 94vh;
  padding: 54px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}
.image-dialog::backdrop { background: rgba(4, 8, 10, 0.86); }
.image-dialog img { display: block; max-width: 100%; max-height: 76vh; margin: 0 auto; object-fit: contain; }
.image-dialog p { max-width: 900px; margin: 13px auto 0; color: var(--ink-soft); font-family: var(--sans); font-size: 13px; }
.dialog-close { position: absolute; top: 10px; right: 10px; }

.back-to-top {
  position: fixed;
  z-index: 25;
  right: 22px;
  bottom: 22px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 150ms ease;
  box-shadow: 0 4px 16px rgba(15, 25, 29, 0.14);
}
.back-to-top.visible { opacity: 1; pointer-events: auto; transform: none; }
.book-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  width: min(var(--reading-width), calc(100% - 64px));
  margin: 0 auto;
  padding: 32px 0 52px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 11px;
}
.book-footer nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px 18px; }
.book-footer a { color: var(--ink-soft); text-decoration: none; }
.book-footer a:hover { color: var(--teal); }

@media (max-width: 1240px) {
  .book-content p:has(> img:only-child), .book-content p:has(> picture:only-child) { margin-inline: -24px; }
}

@media (max-width: 980px) {
  :root { --sidebar-width: 300px; }
  body { font-size: 17px; }
  .mobile-bar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 30;
    display: grid;
    grid-template-columns: 42px 1fr 42px;
    align-items: center;
    gap: 8px;
    min-height: 58px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(12px);
    font-family: var(--sans);
  }
  .mobile-title { overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
  .sidebar { transform: translateX(-102%); transition: transform 180ms ease; }
  .sidebar .sidebar-close { display: grid; }
  .sidebar-open .sidebar { transform: none; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 35; background: rgba(5, 10, 12, 0.58); }
  .sidebar-open .sidebar-scrim { display: block; }
  .page-shell { margin-left: 0; padding-top: 58px; }
  .cover { min-height: calc(82vh - 58px); }
  .cover-copy { width: calc(100% - 40px); padding-bottom: 96px; }
  .cover h1 { font-size: clamp(44px, 12vw, 72px); }
  .book-content { width: min(var(--reading-width), calc(100% - 40px)); padding-top: 56px; }
  .home-overview { width: calc(100% - 40px); padding-top: 64px; }
  .book-content p:has(> img:only-child), .book-content p:has(> picture:only-child) { margin-inline: -10px; }
}

@media (max-width: 620px) {
  body { font-size: 16px; line-height: 1.76; }
  .cover-copy { padding-top: 48px; }
  .cover h1 { font-size: 43px; }
  .cover-copy > p:not(.cover-kicker) { font-size: 15px; }
  .book-content { width: calc(100% - 30px); padding-bottom: 100px; }
  .home-overview { width: calc(100% - 30px); padding: 54px 0 80px; }
  .home-overview h2 { font-size: 26px; }
  .home-lede { margin-bottom: 36px; font-size: 16px; }
  .part-index, .chapter-outline > div { grid-template-columns: 1fr; }
  .part-entry:nth-child(odd) { border-right: 0; }
  .part-entry:nth-child(even) { padding-left: 0; }
  .chapter-outline { margin-bottom: 42px; }
  .chapter-nav { gap: 14px; }
  .chapter-nav strong { font-size: 12px; }
  .book-section { padding-bottom: 48px; }
  .book-section + .book-section { padding-top: 50px; }
  .book-content h1 { font-size: 30px; }
  .book-content h1 + h1 { font-size: 27px; }
  .book-content h2 { margin-top: 38px; font-size: 21px; }
  .book-content h3 { font-size: 18px; }
  .book-content pre { margin-inline: -5px; padding: 18px 16px; }
  .book-content p:has(> img:only-child), .book-content p:has(> picture:only-child) { margin: 28px -15px 9px; }
  .book-content img { border-radius: 0; }
  .book-footer { width: calc(100% - 30px); flex-direction: column; }
  .book-footer nav { justify-content: flex-start; }
}

@media print {
  @page { size: A4; margin: 18mm 17mm 20mm; }
  :root { --paper: #fff; --ink: #111; --ink-soft: #444; --line: #bbb; }
  body { font-size: 10.5pt; line-height: 1.58; }
  .sidebar, .mobile-bar, .theme-toggle, .reading-progress, .back-to-top, .heading-link, .copy-button { display: none !important; }
  .page-shell { margin: 0; padding: 0; }
  .cover { min-height: 245mm; break-after: page; }
  .cover h1 { font-size: 44pt; }
  .book-content { width: auto; margin: 0; padding: 0; }
  .book-section { padding: 0; }
  .book-section + .book-section { border: 0; padding-top: 0; }
  .book-content h1 { break-before: page; margin-top: 0; font-size: 24pt; }
  .book-content h1 + h1 { break-before: auto; font-size: 20pt; }
  .book-content h2 { break-after: avoid; font-size: 15pt; }
  .book-content h3 { break-after: avoid; font-size: 12pt; }
  .book-content p:has(> img:only-child), .book-content p:has(> picture:only-child) { margin: 7mm 0 2mm; }
  .book-content img { max-height: 165mm; break-inside: avoid; }
  .book-content pre, .book-content table, .book-content blockquote { break-inside: avoid; }
  .book-content pre { white-space: pre-wrap; color: #111; background: #f3f3f3; border-color: #ccc; }
  .book-footer { display: none; }
}
