:root {
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-line: #c7d2fe;
  --text: #1f2937;
  --text-strong: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --bg: #ffffff;
  --bg-page: #f8f9fb;
  --bg-sidebar: #fbfbfd;
  --border: #e5e7eb;
  --border-light: #eef0f3;
  --code-bg: #0f172a;
  --inline-code-bg: #f1f3f9;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05);
  --shadow-md: 0 4px 16px rgba(17, 24, 39, .08);
  --radius: 10px;
  --topbar-h: 60px;
  --sidebar-w: 268px;
  --toc-w: 210px;
  --content-max: 820px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.78;
  color: var(--text);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-line); color: var(--text-strong); }

/* ---------------------------------------------------------- topbar */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  height: var(--topbar-h);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(1.5) blur(10px);
  border-bottom: 1px solid var(--border-light);
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
}
.menu-btn {
  display: none; border: 0; background: none; color: var(--text-strong);
  padding: 6px; margin-left: -6px; cursor: pointer; border-radius: 8px;
}
.menu-btn:hover { background: var(--inline-code-bg); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-strong); min-width: 0; }
.brand-mark {
  flex: none; width: 32px; height: 32px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-weight: 700; font-size: 17px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, .35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; font-weight: 650; font-size: 15px; white-space: nowrap; }
.brand-text em { font-style: normal; font-size: 11.5px; font-weight: 500; color: var(--text-muted); }

/* ---------------------------------------------------------- search */
.search { position: relative; margin-left: auto; width: min(320px, 42vw); }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); display: flex; }
.search input {
  width: 100%; height: 36px;
  padding: 0 40px 0 32px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-page); color: var(--text);
  font-size: 13.5px; font-family: inherit;
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.search input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font-family: inherit; font-size: 11px; color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 0 6px; line-height: 18px; background: #fff;
  pointer-events: none;
}
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: min(440px, 86vw); max-height: min(480px, 70vh); overflow-y: auto;
  background: #fff; border: 1px solid var(--border-light); border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 6px;
}
.search-result {
  display: block; padding: 9px 12px; border-radius: 8px;
  text-decoration: none; color: var(--text);
}
.search-result:hover, .search-result.cursored { background: var(--accent-soft); }
.search-result .sr-title { font-weight: 600; font-size: 13.5px; color: var(--text-strong); }
.search-result mark, .search-result .sr-snippet mark { background: #fde68a; color: inherit; border-radius: 3px; padding: 0 1px; }
.search-result .sr-snippet { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-empty { padding: 14px 12px; font-size: 13px; color: var(--text-muted); text-align: center; }

/* ---------------------------------------------------------- layout */
.layout {
  max-width: 1440px; margin: 0 auto;
  padding-top: var(--topbar-h);
  display: flex; align-items: flex-start;
}
.sidebar {
  position: sticky; top: var(--topbar-h);
  flex: none; width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  overscroll-behavior: contain;
}
.sidebar-scroll { padding: 18px 14px 40px; }
.nav-group { margin-bottom: 20px; }
.nav-group-title {
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  color: var(--text-strong);
  margin: 0 10px 6px;
}
.nav-link {
  display: block; padding: 6px 10px; margin: 1px 0;
  border-radius: 8px;
  color: var(--text-muted); text-decoration: none;
  font-size: 13.8px; line-height: 1.5;
  transition: background .12s, color .12s;
}
.nav-link:hover { color: var(--text-strong); background: var(--inline-code-bg); }
.nav-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.main {
  flex: 1; min-width: 0;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 36px 36px 48px;
  background: var(--bg);
}
.doc { word-wrap: break-word; }

/* ---------------------------------------------------------- toc */
.toc {
  position: sticky; top: var(--topbar-h);
  flex: none; width: var(--toc-w);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 40px 18px 40px 8px;
  font-size: 12.8px;
}
.toc-title { font-weight: 700; color: var(--text-strong); margin: 0 0 8px 12px; font-size: 12px; letter-spacing: .04em; }
.toc nav { border-left: 1px solid var(--border); }
.toc-link {
  display: block; padding: 4px 12px;
  color: var(--text-muted); text-decoration: none;
  border-left: 2px solid transparent; margin-left: -1.5px;
  line-height: 1.5;
}
.toc-link.lvl3 { padding-left: 24px; font-size: 12.3px; }
.toc-link:hover { color: var(--text-strong); }
.toc-link.current { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------- typography */
.doc h1, .doc h2, .doc h3, .doc h4 {
  color: var(--text-strong); font-weight: 700; line-height: 1.4;
  margin: 1.8em 0 .7em;
}
.doc > h1:first-child { margin-top: .2em; }
.doc h1 { font-size: 27px; margin: .3em 0 1em; padding-bottom: .55em; border-bottom: 1px solid var(--border-light); position: relative; }
.doc h1::after {
  content: ""; position: absolute; left: 0; bottom: -1px;
  width: 64px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
}
.doc h2 { font-size: 21px; margin-top: 2.2em; padding-left: 12px; position: relative; }
.doc h2::before {
  content: ""; position: absolute; left: 0; top: .28em;
  width: 4px; height: 1em; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), #8b5cf6);
}
.doc h3 { font-size: 17px; }
.doc h4 { font-size: 15px; }
.doc p { margin: .85em 0; }
.doc a { color: var(--accent); text-decoration: none; }
.doc a:hover { text-decoration: underline; text-underline-offset: 3px; }
.doc strong { color: var(--text-strong); font-weight: 650; }
.doc hr { border: 0; border-top: 1px solid var(--border-light); margin: 2.2em 0; }
.doc ul, .doc ol { padding-left: 1.5em; margin: .8em 0; }
.doc li { margin: .35em 0; }
.doc li::marker { color: var(--accent); }
.doc li > ul, .doc li > ol { margin: .3em 0; }

/* 行内代码 */
.doc code {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .875em;
  background: var(--inline-code-bg);
  border: 1px solid var(--border-light);
  border-radius: 5px;
  padding: .12em .38em;
  color: #4338ca;
  word-break: break-all;
}

/* ---------------------------------------------------------- 代码块 */
.doc pre {
  position: relative;
  margin: 1.1em 0;
  padding: 14px 16px;
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.doc pre code {
  display: block;
  background: none; border: 0; padding: 0;
  color: #e2e8f0;
  font-size: 13px; line-height: 1.65;
  white-space: pre; word-break: normal;
}
.copy-btn {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.08); color: #cbd5e1;
  font-size: 11.5px; font-family: inherit;
  padding: 2px 9px; border-radius: 6px; cursor: pointer;
  opacity: 0; transition: opacity .15s, background .15s;
}
.doc pre:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,.18); }
.copy-btn.copied { color: #86efac; }

/* highlight.js 配色 */
.hljs-comment, .hljs-quote { color: #64748b; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section { color: #c4b5fd; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #86efac; }
.hljs-number, .hljs-symbol, .hljs-bullet { color: #fbbf24; }
.hljs-title, .hljs-title.function_, .hljs-name { color: #7dd3fc; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: #f9a8d4; }
.hljs-type, .hljs-built_in, .hljs-builtin-name, .hljs-class .hljs-title { color: #67e8f9; }
.hljs-meta, .hljs-doctag { color: #94a3b8; }
.hljs-deletion { color: #fca5a5; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------------------------------------------------------- 表格 */
.table-wrap { overflow-x: auto; margin: 1.2em 0; border: 1px solid var(--border-light); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.table-wrap table { margin: 0; width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.8px; }
.doc thead { background: var(--accent-soft); }
.doc th {
  text-align: left; font-weight: 650; color: #3730a3;
  padding: 9px 14px; white-space: nowrap;
  border-bottom: 1px solid var(--accent-line);
}
.doc td { padding: 8px 14px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
.doc tbody tr:last-child td { border-bottom: 0; }
.doc tbody tr:nth-child(even) { background: #fafbfc; }
.doc tbody tr:hover { background: var(--accent-soft); }

/* ---------------------------------------------------------- 引用块 */
.doc blockquote {
  margin: 1.1em 0; padding: 12px 18px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #4b5563;
}
.doc blockquote p { margin: .4em 0; }
.doc blockquote > :first-child { margin-top: 0; }
.doc blockquote > :last-child { margin-bottom: 0; }

/* ---------------------------------------------------------- 图片 */
.img-frame { display: block; margin: 1.3em auto; text-align: center; }
.img-frame img {
  max-width: 100%; height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  cursor: zoom-in;
  transition: transform .18s ease, box-shadow .18s ease;
}
.img-frame img:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(17, 24, 39, .14); }

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .78);
  display: flex; align-items: center; justify-content: center;
  padding: 32px; cursor: zoom-out;
  backdrop-filter: blur(4px);
}
.lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 10px; box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
  background: #fff;
}

/* ---------------------------------------------------------- 上一篇/下一篇 */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-top: 48px; padding-top: 26px;
  border-top: 1px solid var(--border-light);
}
.pager-card {
  display: flex; flex-direction: column; gap: 3px;
  padding: 13px 16px;
  border: 1px solid var(--border-light); border-radius: var(--radius);
  background: var(--bg-page);
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.pager-card:hover { border-color: var(--accent-line); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.pager-card.next { text-align: right; }
.pager-dir { font-size: 12px; color: var(--text-faint); }
.pager-title { font-size: 14px; font-weight: 600; color: var(--accent); }

.site-footer {
  margin-top: 40px; padding-top: 18px;
  border-top: 1px solid var(--border-light);
  font-size: 12.5px; color: var(--text-faint); text-align: center;
}

/* ---------------------------------------------------------- 滚动条 */
.sidebar::-webkit-scrollbar, .toc::-webkit-scrollbar, .search-results::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .toc::-webkit-scrollbar-thumb, .search-results::-webkit-scrollbar-thumb {
  background: #d7dae2; border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover, .toc::-webkit-scrollbar-thumb:hover { background: #c1c6d1; }

/* ---------------------------------------------------------- 响应式 */
@media (max-width: 1180px) { .toc { display: none; } }
@media (max-width: 860px) {
  .menu-btn { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-md); }
  .sidebar-mask {
    display: none;
    position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 55;
    background: rgba(15, 23, 42, .4);
  }
  body.sidebar-open .sidebar-mask { display: block; }
  .main { padding: 24px 20px 40px; }
  .brand-text em { display: none; }
  .pager { grid-template-columns: 1fr; }
  .pager-card.next { text-align: left; }
  .search kbd { display: none; }
}
@media (max-width: 520px) {
  .brand-text { display: none; }
  .search { width: 100%; }
  .topbar-inner { gap: 8px; }
}

@media print {
  .topbar, .sidebar, .toc, .pager, .site-footer, .copy-btn, .lightbox { display: none !important; }
  .layout { padding-top: 0; }
  .main { max-width: none; padding: 0; }
  body { background: #fff; }
}
