:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --surface: #ffffff;
  --text: #171b26;
  --text-2: #3d4453;
  --muted: #6b7385;
  --border: #e6e8ee;
  --border-strong: #d3d8e2;
  --accent: #2f5fe0;
  --accent-soft: #eef3ff;
  --code-bg: #0f172a;
  --code-text: #e6edf7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
  --topbar: 60px;
  --sidebar-w: 276px;
  --toc-w: 232px;
}

html[data-theme="dark"] {
  --bg: #0e1116;
  --bg-soft: #141922;
  --surface: #141922;
  --text: #e8ebf2;
  --text-2: #c3c9d6;
  --muted: #8d97a8;
  --border: #232a36;
  --border-strong: #303948;
  --accent: #7ea2ff;
  --accent-soft: #1a2438;
  --code-bg: #0a0e14;
  --code-text: #dfe7f4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.78;
  font-size: 15.5px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; border-radius: 8px; }

/* ---------- 顶栏 ---------- */
#progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 60; transition: width .08s linear;
}
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar); padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.5) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 15px; color: var(--text); white-space: nowrap; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; color: var(--accent); }
.menu-btn, .icon-btn {
  display: none; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 15px;
}
.icon-btn { display: inline-flex; }
.menu-btn:hover, .icon-btn:hover { border-color: var(--border-strong); color: var(--text); }
.top-link { font-size: 13px; color: var(--muted); margin-left: 4px; }

.search-box { position: relative; margin-left: auto; }
.search-box input {
  width: 320px; max-width: 38vw;
  padding: 8px 12px 8px 32px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-soft); color: var(--text); outline: none;
  transition: border-color .15s, background .15s;
}
.search-box input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box::before {
  content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 15px; pointer-events: none; z-index: 1;
}
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 420px; max-width: 80vw; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 50;
}
.search-results[hidden] { display: none; }
.sr-item { display: block; padding: 9px 11px; border-radius: 8px; color: var(--text); }
.sr-item:hover, .sr-item.active { background: var(--accent-soft); text-decoration: none; }
.sr-title { font-size: 13.5px; font-weight: 600; }
.sr-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.sr-empty { padding: 14px; color: var(--muted); font-size: 13px; }

/* ---------- 三栏 ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w); align-items: start; }

.sidebar {
  position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 12px 48px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.nav-home {
  display: block; margin: 0 8px 14px; padding: 8px 10px;
  font-weight: 650; font-size: 14px; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.nav-home:hover { text-decoration: none; color: var(--accent); }
.nav-group { margin-bottom: 16px; }
.nav-group-title {
  padding: 4px 10px 6px; font-size: 11.5px; font-weight: 650;
  letter-spacing: .04em; color: var(--muted);
}
.nav-group-title a { color: var(--muted); }
.nav-group-title a:hover { color: var(--accent); text-decoration: none; }
.nav-item {
  display: block; padding: 5px 10px; margin: 1px 0;
  color: var(--text-2); font-size: 13px; line-height: 1.5;
  border-radius: 7px; border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav-item.active {
  color: var(--accent); background: var(--accent-soft);
  border-left-color: var(--accent); font-weight: 600;
}
.side-foot { margin-top: 26px; padding: 14px 10px 0; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--muted); line-height: 1.7; }

.main { min-width: 0; padding: 44px 56px 96px; }
.doc { max-width: 780px; margin: 0 auto; }
.doc-home { max-width: 1080px; }
.doc-home .hero { max-width: none; }

/* ---------- 正文 ---------- */
.doc h1 { font-size: 32px; line-height: 1.32; margin: 0 0 20px; letter-spacing: -.02em; }
.doc h2 { font-size: 22px; margin: 44px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); letter-spacing: -.01em; }
.doc h3 { font-size: 17.5px; margin: 30px 0 10px; }
.doc h4 { font-size: 15.5px; margin: 22px 0 8px; color: var(--text-2); }
.doc p { margin: 13px 0; }
.doc strong { font-weight: 650; }
.doc ul, .doc ol { margin: 13px 0; padding-left: 24px; }
.doc li { margin: 6px 0; }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 36px 0; }
.doc blockquote {
  margin: 18px 0; padding: 12px 18px;
  background: var(--bg-soft); border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0; color: var(--text-2);
}
.doc blockquote p { margin: 6px 0; }
.doc .anchor {
  margin-left: 8px; color: var(--muted); opacity: 0; font-weight: 400; font-size: .8em;
}
.doc h1:hover .anchor, .doc h2:hover .anchor, .doc h3:hover .anchor, .doc h4:hover .anchor { opacity: .7; }
.doc .anchor:hover { text-decoration: none; opacity: 1; }

.doc :not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .89em; background: var(--bg-soft);
  border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px;
  color: #b42318;
}
html[data-theme="dark"] .doc :not(pre) > code { color: #ffb4a9; }

.code-block {
  margin: 18px 0; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); background: var(--code-bg);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; font-size: 11.5px; letter-spacing: .04em;
  color: #8fa3bf; background: rgba(255, 255, 255, .04);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.copy-btn {
  border: 1px solid rgba(255, 255, 255, .14); background: transparent;
  color: #b9c7da; font-size: 11.5px; padding: 2px 9px;
  border-radius: 6px; cursor: pointer;
}
.copy-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.doc pre {
  margin: 0; padding: 16px 18px; overflow-x: auto;
  background: var(--code-bg); color: var(--code-text);
  line-height: 1.62; font-size: 13px;
}
.doc pre code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  background: none; padding: 0; border: none; color: inherit; font-size: 13px;
}

.table-wrap { overflow-x: auto; margin: 18px 0; border: 1px solid var(--border); border-radius: var(--radius); }
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; }
.doc th, .doc td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc th { background: var(--bg-soft); font-weight: 650; white-space: nowrap; }
.doc tr:last-child td { border-bottom: none; }

/* ---------- 页内目录 ---------- */
.toc {
  position: sticky; top: var(--topbar);
  max-height: calc(100vh - var(--topbar));
  overflow-y: auto; padding: 36px 18px 40px 8px;
  font-size: 12.5px;
}
.toc-title { font-size: 11.5px; font-weight: 650; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }
.toc nav { border-left: 1px solid var(--border); }
.toc-item {
  display: block; padding: 4px 0 4px 12px; margin-left: -1px;
  color: var(--muted); border-left: 2px solid transparent;
  line-height: 1.5;
}
.toc-item:hover { color: var(--text); text-decoration: none; }
.toc-item.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc-item.lv3 { padding-left: 24px; font-size: 12px; }

/* ---------- 上下页 ---------- */
.pager {
  display: flex; justify-content: space-between; gap: 16px;
  max-width: 780px; margin: 64px auto 0; padding-top: 24px;
  border-top: 1px solid var(--border); font-size: 13.5px;
}
.pager a { max-width: 46%; }
.pager .pg-next { text-align: right; margin-left: auto; }

/* ---------- 首页 ---------- */
.hero { max-width: 860px; margin: 0 auto; padding: 64px 0 24px; }
.hero-kicker { font-size: 12.5px; font-weight: 650; letter-spacing: .06em; color: var(--accent); }
.hero h1 { font-size: 52px; line-height: 1.15; margin: 12px 0 16px; letter-spacing: -.035em; }
.hero-lead { font-size: 17px; color: var(--text-2); max-width: 640px; margin: 0 0 28px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; padding: 10px 20px;
  border-radius: 10px; font-size: 14px; font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { text-decoration: none; filter: brightness(1.06); }
.btn-ghost { border: 1px solid var(--border-strong); color: var(--text); }
.btn-ghost:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.hero-stats { display: flex; gap: 36px; margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border); }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats b { font-size: 24px; letter-spacing: -.02em; }
.hero-stats span { font-size: 12px; color: var(--muted); }

.chapters, .howto { max-width: 1080px; margin: 56px auto 0; }
.chapters h2, .howto h2 { font-size: 20px; margin: 0 0 20px; }
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.ch-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.ch-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.ch-no { font-size: 11.5px; font-weight: 650; letter-spacing: .06em; color: var(--accent); }
.ch-title { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.ch-desc { font-size: 12.5px; color: var(--muted); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ch-meta { margin-top: auto; padding-top: 10px; font-size: 12px; color: var(--muted); }
.howto { padding-bottom: 80px; }
.howto p { color: var(--text-2); font-size: 14px; }

/* ---------- 章导览 ---------- */
.chapter-head { margin-bottom: 8px; }
.chapter-head .ch-no { margin-bottom: 6px; }
.chapter-head h1 { margin-top: 0; }
.doc .lead { font-size: 16.5px; color: var(--text-2); }
.sec-heading { margin-top: 48px; }
.sec-list { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.sec-row {
  display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 4px 12px;
  padding: 14px 4px; border-bottom: 1px solid var(--border); color: var(--text);
}
.sec-row:hover { text-decoration: none; background: var(--bg-soft); }
.sec-no { font-size: 12px; font-weight: 650; color: var(--accent); padding-top: 3px; }
.sec-title { font-weight: 600; font-size: 15px; }
.sec-desc { grid-column: 2; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* ---------- 响应式 ---------- */
@media (max-width: 1240px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .search-box input { width: 190px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar); z-index: 30;
    width: 300px; transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 28px 20px 64px; }
  .hero { padding: 36px 0 8px; }
  .hero h1 { font-size: 36px; }
  .hero-stats { gap: 24px; flex-wrap: wrap; }
  .doc h1 { font-size: 26px; }
  .doc h2 { font-size: 19px; }
}
@media (max-width: 560px) {
  .brand { font-size: 13.5px; }
  .search-box input { width: 140px; }
  .hero h1 { font-size: 31px; }
  .hero-lead { font-size: 15px; }
  .search-results { width: 88vw; }
}
@media print {
  .topbar, .sidebar, .toc, .pager, #progress { display: none; }
  .layout { display: block; }
  .main { padding: 0; }
  .doc { max-width: none; }
  .doc pre { white-space: pre-wrap; }
}