:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #7559d9;
  --accent-soft: #f0ecff;
  --code-bg: #111827;
  --code-text: #dbeafe;
  --shadow: 0 10px 35px rgba(16, 24, 40, 0.08);
}

[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #11182a;
  --surface-soft: #161f34;
  --text: #e7ecf5;
  --muted: #9aa7bd;
  --line: #27324a;
  --accent: #a78bfa;
  --accent-soft: #292246;
  --code-bg: #090e1a;
  --code-text: #dbeafe;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.75 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(14px);
}
.site-brand { color: var(--text); font-weight: 750; }
.site-brand:hover { text-decoration: none; }
.header-links { margin-left: auto; display: flex; gap: 8px; overflow-x: auto; }
.header-links a { flex: 0 0 auto; padding: 7px 11px; border-radius: 9px; color: var(--muted); white-space: nowrap; }
.header-links a:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }

.page-layout {
  max-width: 1500px;
  margin: auto;
  display: grid;
  grid-template-columns: 290px minmax(0, 900px);
  gap: 48px;
  justify-content: center;
  padding: 38px 32px 80px;
}
.chapter-sidebar {
  position: sticky;
  top: 92px;
  align-self: start;
  max-height: calc(100vh - 116px);
  overflow: auto;
  scrollbar-width: thin;
}
.chapter-sidebar h2 { margin: 0 0 12px; color: var(--muted); font-size: 12px; letter-spacing: .11em; text-transform: uppercase; }
.chapter-sidebar nav, .mobile-nav nav { display: grid; gap: 3px; }
.chapter-sidebar a, .mobile-nav a {
  display: block;
  padding: 5px 9px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}
.chapter-sidebar a:hover, .chapter-sidebar a.active, .mobile-nav a:hover, .mobile-nav a.active {
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}
.mobile-nav { display: none; margin-bottom: 18px; }
.mobile-nav summary { cursor: pointer; color: var(--accent); font-weight: 700; }

.page-main { min-width: 0; }
.breadcrumbs { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.breadcrumbs span { margin: 0 8px; color: var(--line); }
.chapter-content, .overview-section, .chapter {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.chapter-content { padding: 12px 32px 42px; }
.overview-section, .chapter { border: 0; box-shadow: none; }
.chapter-header { margin: 18px 0 28px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.chapter-number, .section-kicker {
  display: inline-flex;
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .08em;
}
h2 { margin: 34px 0 15px; font-size: 26px; line-height: 1.35; }
h3 { margin: 28px 0 10px; font-size: 20px; line-height: 1.4; }
h4 { margin: 22px 0 8px; font-size: 17px; }
.chapter-header h2, .overview-section > h2 { margin-top: 0; font-size: clamp(30px, 4vw, 44px); line-height: 1.18; }
.lead, .chapter-header p, .source-note, .note { color: var(--muted); }

.chapter-cards, .review-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0 24px;
}
.chapter-card, .review-card, .workflow-card {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-soft);
}
.chapter-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  color: var(--text);
}
.chapter-card:hover { border-color: var(--accent); text-decoration: none; }
.card-num { color: var(--accent); font: 750 14px/1.4 ui-monospace, monospace; }
.chapter-card strong { display: block; color: var(--text); }
.chapter-card small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.55; }

.source-details {
  margin: 20px 0;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-soft);
}
.source-details summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.source-content { margin-top: 12px; }
.table-wrap { margin: 20px 0; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 10px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-soft); color: var(--text); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); }

code { padding: .12em .35em; border-radius: 5px; color: #c2410c; background: #fff2e8; font: .91em/1.5 "JetBrains Mono", "SFMono-Regular", Consolas, monospace; }
[data-theme="dark"] code { color: #fdba74; background: #2b1c19; }
pre { overflow: auto; padding: 18px; border-radius: 12px; background: var(--code-bg); color: var(--code-text); }
pre code { padding: 0; color: inherit; background: transparent; }
.kw { color: #88aaff; font-weight: 600; }
.im { color: #73daca; }
.op { color: #93a4bd; }

.chapter-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 24px;
}
.chapter-pager a, .back-top {
  padding: 15px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.chapter-pager a:hover, .back-top:hover { border-color: var(--accent); text-decoration: none; }
.chapter-pager a:last-child { text-align: right; }
.placeholder { min-height: 1px; }
.back-top { display: inline-flex; margin-top: 20px; color: var(--accent); }

@media (max-width: 900px) {
  .site-header { padding: 0 14px; gap: 10px; }
  .page-layout { display: block; padding: 24px 18px 65px; }
  .chapter-sidebar { display: none; }
  .mobile-nav { display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
  .chapter-content { padding: 5px 18px 35px; }
  .chapter-cards, .review-grid { grid-template-columns: 1fr; }
  .chapter-pager { grid-template-columns: 1fr; }
  .site-brand { flex: 0 0 auto; }
  .header-links { min-width: 0; }
}

@media print {
  .site-header, .chapter-sidebar, .mobile-nav, .back-top { display: none !important; }
  body { background: white; color: black; }
  .page-layout, .chapter-content { display: block; padding: 0; border: 0; box-shadow: none; }
}
