:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fb;
  --bg-code: #0f1b2d;
  --ink: #0f1b2d;
  --dim: #4a5a72;
  --faint: #8a98ad;
  --line: #e5eaf1;
  --accent: #1f5eff;
  --accent-soft: #eaf0ff;
  --accent-ink: #1747c7;
  --warn-soft: #fff6e6;
  --shadow: 0 12px 32px rgba(15, 27, 45, 0.12);
  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1120; --bg-soft: #111a2e; --bg-code: #0a1222; --ink: #e6ecf5; --dim: #a9b6cb; --faint: #7486a3; --line: #1f2b44;
    --accent: #6b95ff; --accent-soft: #16244a; --accent-ink: #9db8ff; --warn-soft: #2a2213; --shadow: 0 12px 32px rgba(0, 0, 0, 0.45); color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0b1120; --bg-soft: #111a2e; --bg-code: #0a1222; --ink: #e6ecf5; --dim: #a9b6cb; --faint: #7486a3; --line: #1f2b44;
  --accent: #6b95ff; --accent-soft: #16244a; --accent-ink: #9db8ff; --warn-soft: #2a2213; --shadow: 0 12px 32px rgba(0, 0, 0, 0.45); color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15.5px/1.65 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 18px; height: 18px; flex: none; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; height: 60px; display: flex; align-items: center; gap: 18px; padding: 0 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16.5px; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 24px; height: 24px; }
.ver { font: 500 11px var(--mono); color: var(--faint); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
.top-links { display: flex; gap: 4px; }
.top-links a { color: var(--dim); font-weight: 500; font-size: 14.5px; padding: 6px 10px; border-radius: 8px; }
.top-links a:hover { background: var(--bg-soft); color: var(--ink); text-decoration: none; }
.top-links a.on { color: var(--accent); }
.search { position: relative; margin-left: auto; display: flex; align-items: center; gap: 8px; width: 280px; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-soft); color: var(--faint); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 14px; }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within { border-color: var(--accent); background: var(--bg); }
.search kbd { font: 500 11px var(--mono); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; color: var(--faint); background: var(--bg); }
.results { position: absolute; top: 42px; right: 0; width: min(460px, calc(100vw - 32px)); max-height: 70vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.results a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.results a:hover, .results a.sel { background: var(--accent-soft); text-decoration: none; }
.results .r-sec { font-size: 11.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.results .r-title { font-weight: 600; font-size: 14px; }
.results .r-snip { font-size: 13px; color: var(--dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.results mark { background: transparent; color: var(--accent); font-weight: 600; }
.results .empty { padding: 12px; color: var(--faint); font-size: 14px; }
.theme, .gh, .menu { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 0; background: transparent; color: var(--dim); cursor: pointer; }
.theme:hover, .gh:hover, .menu:hover { background: var(--bg-soft); color: var(--ink); }
.theme .moon { display: none; }
:root[data-theme='dark'] .theme .sun { display: none; }
:root[data-theme='dark'] .theme .moon { display: block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .theme .sun { display: none; } :root:not([data-theme='light']) .theme .moon { display: block; } }
.menu { display: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr) 240px; max-width: 1440px; margin: 0 auto; }
.sidebar { position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; padding: 20px 12px 40px 20px; border-right: 1px solid var(--line); }
.nav-section { margin-bottom: 4px; }
.nav-title { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 7px 10px; border: 0; background: transparent; color: var(--ink); font: 600 14.5px var(--sans); border-radius: 8px; cursor: pointer; text-align: left; }
.nav-title:hover { background: var(--bg-soft); }
.nav-title svg { width: 14px; height: 14px; color: var(--faint); transition: transform 0.15s; }
.nav-section.open .nav-title svg { transform: rotate(90deg); }
.nav-section ul { list-style: none; margin: 2px 0 8px; padding: 0 0 0 10px; display: none; border-left: 1px solid var(--line); margin-left: 12px; }
.nav-section.open ul { display: block; }
.nav-section li a { display: block; padding: 6px 10px; color: var(--dim); font-size: 14.5px; border-radius: 8px; line-height: 1.35; }
.nav-section li a:hover { background: var(--bg-soft); color: var(--ink); text-decoration: none; }
.nav-section li a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.content { min-width: 0; padding: 28px 48px 60px; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--faint); margin-bottom: 18px; }
.crumbs a { color: var(--faint); display: flex; }
.crumbs svg { width: 15px; height: 15px; }
.crumbs .here { color: var(--accent-ink); background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; font-weight: 500; }
.toc { position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; padding: 32px 20px 40px 8px; }
.toc-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin-bottom: 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc li a { display: block; padding: 4px 0 4px 12px; margin-left: -1px; border-left: 2px solid transparent; color: var(--dim); font-size: 13.5px; line-height: 1.4; }
.toc li.d3 a { padding-left: 24px; font-size: 13px; }
.toc li a:hover { color: var(--ink); text-decoration: none; }
.toc li a.on { color: var(--accent); border-left-color: var(--accent); }

/* ---------- article ---------- */
.doc { max-width: 820px; }
.doc h1 { font-size: 36px; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 18px; font-weight: 700; }
.doc h2 { font-size: 25px; letter-spacing: -0.01em; margin: 44px 0 12px; padding-top: 4px; font-weight: 650; }
.doc h3 { font-size: 19px; margin: 30px 0 10px; font-weight: 650; }
.doc h2, .doc h3 { position: relative; }
.doc .anchor { position: absolute; left: -22px; opacity: 0; color: var(--faint); font-weight: 400; padding-right: 6px; }
.doc h2:hover .anchor, .doc h3:hover .anchor { opacity: 1; text-decoration: none; }
.doc p, .doc ul, .doc ol { margin: 0 0 16px; }
.doc li { margin: 4px 0; }
.doc li > p { margin: 0 0 8px; }
.doc strong { font-weight: 650; }
.doc :not(pre) > code { font: 500 0.86em var(--mono); background: var(--bg-soft); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; overflow-wrap: anywhere; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.doc .shot { display: block; margin: 18px 0 24px; }
.doc img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(15, 27, 45, 0.08); }
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--line); border-radius: 10px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.doc th, .doc td { text-align: left; vertical-align: top; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.doc th { background: var(--bg-soft); font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }
.code { position: relative; margin: 0 0 20px; }
.code pre { margin: 0; padding: 16px 18px; background: var(--bg-code); border-radius: 12px; overflow-x: auto; border: 1px solid #1c2940; }
.code code { font: 400 13.5px/1.65 var(--mono); color: #dbe6ff; }
.code[data-lang]::before { content: attr(data-lang); position: absolute; top: 8px; right: 70px; font: 500 11px var(--mono); color: #6f86b3; text-transform: lowercase; }
.copy { position: absolute; top: 6px; right: 8px; font: 500 12px var(--sans); color: #cfd8ea; background: #16223a; border: 1px solid #2a3a55; border-radius: 7px; padding: 4px 9px; cursor: pointer; opacity: 0; transition: opacity 0.15s; }
.code:hover .copy, .copy:focus-visible { opacity: 1; }
.admonition { display: flex; gap: 12px; margin: 0 0 20px; padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); border-left: 4px solid var(--accent); }
.admonition > div:last-child > :last-child { margin-bottom: 0; }
.admonition-icon { flex: none; width: 20px; height: 20px; margin-top: 3px; border-radius: 50%; background: var(--accent); color: #fff; font: 700 12px/20px var(--sans); text-align: center; }

/* highlight.js, in the site palette */
.hljs-comment, .hljs-quote { color: #6f86b3; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-built_in { color: #8fb0ff; }
.hljs-string, .hljs-attr + .hljs-string, .hljs-regexp { color: #9fe0c1; }
.hljs-number, .hljs-symbol { color: #ffc98a; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-name { color: #c7b7ff; }
.hljs-title, .hljs-section, .hljs-function .hljs-title { color: #ffd7a8; }
.hljs-meta, .hljs-bullet { color: #7fd3ff; }

.edit { max-width: 820px; margin-top: 36px; }
.edit a { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.edit svg { width: 15px; height: 15px; }
.pager { max-width: 820px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; }
.pager a { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a span { font-size: 13px; color: var(--faint); }
.pager a b { font-weight: 600; color: var(--accent); }
.pager .next { text-align: right; grid-column: 2; }
.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 24px 32px; border-top: 1px solid var(--line); color: var(--faint); font-size: 14px; background: var(--bg-soft); }
.footer div { display: flex; align-items: center; gap: 18px; }
.footer img { width: 18px; height: 18px; margin-right: -8px; }
.footer a { color: var(--dim); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .menu { display: grid; }
  .top-links { display: none; }
  .search { width: auto; flex: 1; max-width: 320px; }
  .search kbd { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 60px; left: 0; bottom: 0; width: min(300px, 85vw); height: auto; z-index: 15; background: var(--bg); transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .content { padding: 20px 16px 48px; }
  .doc h1 { font-size: 29px; }
  .doc h2 { font-size: 22px; }
  .doc .anchor { display: none; }
  .ver, .brand-text { display: none; }
}
@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand { font-size: 0; gap: 0; }
  .brand img { width: 26px; height: 26px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .footer { padding: 20px 16px; }
}
