:root {
  --bg: #0b1017; --bg-subtle: #0f151e; --surface: #121923; --surface-2: #1a2330;
  --text: #e9eef4; --text-2: #c5ced8; --muted: #95a2b1; --faint: #6f7d8c; --border: #232e3c;
  --primary: #3390ec; --primary-soft: #132f4c; --primary-ink: #9fd0ff; --link: #5eb5f7;
  --code-bg: #121923;
  --info: #5eb5f7; --info-bg: #0f2433; --success: #4cc38a; --success-bg: #0f261a;
  --warning: #f1a10d; --warning-bg: #2c1e08; --danger: #ff6369; --danger-bg: #2f1214;
  --head-h: 60px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #ffffff; --bg-subtle: #f5f8fb; --surface: #ffffff; --surface-2: #f4f6f9;
  --text: #0f1924; --text-2: #39434e; --muted: #64707d; --faint: #8a95a1; --border: #e3e8ee;
  --primary: #3390ec; --primary-soft: #e4f1fd; --primary-ink: #1565b3; --link: #2481cc;
  --code-bg: #f5f7fa;
  --info: #2481cc; --info-bg: #eef6fd; --success: #218358; --success-bg: #ebf8f0;
  --warning: #ad5700; --warning-bg: #fff6e6; --danger: #cd2b31; --danger-bg: #fdf0f0;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--head-h) + 20px); }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.7 "Inter", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font: 500 11px "JetBrains Mono", monospace; padding: 1px 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); color: var(--faint); }

/* HEADER */
.dh { position: sticky; top: 0; z-index: 30; height: var(--head-h); display: flex; align-items: center; gap: 20px; padding: 0 24px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.dh-brand { display: flex; align-items: center; gap: 8px; flex: none; width: 236px; }
.wm { font: italic 900 18px/1 "Chivo", sans-serif; letter-spacing: -.3px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-ink); }
.dh-search { flex: 0 1 380px; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--faint); font-size: 14px; text-align: left; }
.dh-search span { flex: 1; }
.dh-search:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.dh-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.dh-theme { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); }
.dh-theme .i-sun { display: none; }
:root[data-theme="light"] .dh-theme .i-sun { display: block; }
:root[data-theme="light"] .dh-theme .i-moon { display: none; }
.dh-app { height: 38px; display: inline-flex; align-items: center; padding: 0 16px; border-radius: 10px; background: var(--primary); color: #fff; font-weight: 600; font-size: 14px; }
.dh-menu { display: none; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.dh-menu span { width: 16px; height: 2px; border-radius: 2px; background: currentColor; }

/* SHELL */
.shell { display: flex; max-width: 1440px; margin: 0 auto; }
.sb { position: sticky; top: var(--head-h); flex: none; width: 280px; height: calc(100vh - var(--head-h)); overflow-y: auto; padding: 24px 16px 40px 24px; border-right: 1px solid var(--border); }
.sb-group { margin-bottom: 22px; }
.sb-title { padding: 0 10px; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--text); }
.sb a { display: block; padding: 6px 10px; border-radius: 8px; font-size: 14px; line-height: 1.4; color: var(--muted); transition: background .12s, color .12s; }
.sb a:hover { background: var(--surface-2); color: var(--text); }
.sb a.on { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.scrim { display: none; }

.page { flex: 1; min-width: 0; display: flex; gap: 48px; padding: 40px 48px 80px; }
.doc { flex: 1; min-width: 0; max-width: 760px; }
.toc { position: sticky; top: calc(var(--head-h) + 40px); align-self: flex-start; flex: none; width: 220px; max-height: calc(100vh - var(--head-h) - 60px); overflow-y: auto; font-size: 13px; }
.toc-title { font-weight: 600; margin-bottom: 10px; }
.toc a { display: block; padding: 4px 0 4px 12px; border-left: 1px solid var(--border); color: var(--muted); line-height: 1.4; }
.toc a.d3 { padding-left: 24px; }
.toc a:hover { color: var(--text); }
.toc a.on { color: var(--primary-ink); border-left-color: var(--primary); font-weight: 500; }

/* CONTENT */
.crumb { font-size: 13px; font-weight: 600; color: var(--primary-ink); margin-bottom: 8px; }
.doc h1 { margin: 0 0 12px; font-size: 36px; line-height: 1.2; letter-spacing: -.6px; font-weight: 700; }
.lead { margin: 0 0 36px; font-size: 18px; color: var(--muted); line-height: 1.6; }
.doc h2 { margin: 48px 0 12px; font-size: 24px; line-height: 1.3; letter-spacing: -.3px; font-weight: 700; }
.doc h3 { margin: 32px 0 8px; font-size: 19px; line-height: 1.35; font-weight: 600; }
.doc h2, .doc h3 { position: relative; }
.anchor { position: absolute; left: -22px; opacity: 0; color: var(--faint); font-weight: 400; transition: opacity .12s; }
.doc h2:hover .anchor, .doc h3:hover .anchor { opacity: 1; }
.doc p, .doc li { color: var(--text-2); }
.doc p { margin: 0 0 16px; }
.doc ul, .doc ol { margin: 0 0 16px; padding-left: 24px; }
.doc li { margin: 4px 0; }
.doc li::marker { color: var(--faint); }
.doc strong { color: var(--text); font-weight: 600; }
.doc a:not(.pg):not(.anchor) { color: var(--link); font-weight: 500; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent); text-underline-offset: 3px; }
.doc a:not(.pg):not(.anchor):hover { text-decoration-color: var(--link); }
.ext { font-size: .75em; margin-left: 2px; text-decoration: none; display: inline-block; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 36px 0; }
.doc :not(pre) > code { font: 500 .86em "JetBrains Mono", monospace; padding: 2px 6px; border-radius: 6px; background: var(--code-bg); border: 1px solid var(--border); overflow-wrap: anywhere; }
.doc blockquote { margin: 0 0 16px; padding: 4px 16px; border-left: 3px solid var(--border); color: var(--muted); }

.code { margin: 0 0 20px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--border); font: 500 12px "JetBrains Mono", monospace; color: var(--faint); }
.copy { border: 0; background: none; padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.copy:hover { background: var(--surface-2); color: var(--text); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; font: 400 13.5px/1.65 "JetBrains Mono", monospace; color: var(--text); }

.hint { display: flex; gap: 12px; margin: 0 0 20px; padding: 14px 16px; border-radius: 12px; border: 1px solid transparent; }
.hint-icon { flex: none; margin-top: 3px; }
.hint > div > :last-child { margin-bottom: 0; }
.hint p { color: var(--text); }
.hint-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 20%, transparent); } .hint-info .hint-icon { color: var(--info); }
.hint-success { background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 20%, transparent); } .hint-success .hint-icon { color: var(--success); }
.hint-warning { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 22%, transparent); } .hint-warning .hint-icon { color: var(--warning); }
.hint-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 20%, transparent); } .hint-danger .hint-icon { color: var(--danger); }

.table-wrap { margin: 0 0 20px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.doc th { text-align: left; font-weight: 600; background: var(--bg-subtle); }
.doc th, .doc td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc tr:last-child td { border-bottom: 0; }
.doc td { color: var(--text-2); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 56px 0 24px; }
.pg { display: flex; flex-direction: column; gap: 2px; padding: 14px 18px; border: 1px solid var(--border); border-radius: 12px; transition: border-color .15s, box-shadow .15s; }
.pg:hover { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 10%, transparent); }
.pg small { font-size: 12px; color: var(--faint); }
.pg span { font-weight: 600; color: var(--text); }
.pg.next { text-align: right; }
.pg.prev span::before { content: "← "; color: var(--faint); }
.pg.next span::after { content: " →"; color: var(--faint); }
.doc-foot { display: flex; justify-content: space-between; gap: 16px; padding-top: 20px; border-top: 1px solid var(--border); font-size: 13px; color: var(--faint); }
.doc-foot a:hover { color: var(--text); }

/* SEARCH */
.sm { position: fixed; inset: 0; z-index: 60; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; background: rgba(10, 8, 25, .45); }
.sm[hidden] { display: none; }
.sm-card { width: 100%; max-width: 620px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.28); overflow: hidden; }
.sm-in { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 56px; border-bottom: 1px solid var(--border); color: var(--faint); }
.sm-in input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; color: var(--text); }
.sm-res { max-height: 56vh; overflow-y: auto; padding: 8px; }
.sm-res a { display: block; padding: 10px 12px; border-radius: 10px; }
.sm-res a.sel, .sm-res a:hover { background: var(--primary-soft); }
.sm-res b { display: block; font-size: 14px; font-weight: 600; }
.sm-res small { display: block; font-size: 12px; color: var(--primary-ink); margin-bottom: 2px; }
.sm-res p { margin: 2px 0 0; font-size: 13px; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sm-res mark { background: color-mix(in srgb, var(--primary) 22%, transparent); color: inherit; border-radius: 3px; }
.sm-empty { padding: 28px 12px; text-align: center; color: var(--faint); font-size: 14px; }

/* RESPONSIVE */
@media (max-width: 1200px) { .toc { display: none; } }
@media (max-width: 900px) {
  .dh { padding: 0 16px; gap: 10px; }
  .dh-menu { display: flex; }
  .dh-brand { width: auto; }
  .dh-search { flex: 1; }
  .dh-search span, .dh-search kbd { display: none; }
  .dh-search { flex: 0 0 38px; justify-content: center; padding: 0; }
  .dh-app { display: none; }
  .sb { position: fixed; top: var(--head-h); left: 0; bottom: 0; z-index: 40; height: auto; width: min(300px, 86vw); background: var(--bg); transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sb { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--head-h) 0 0 0; z-index: 35; background: rgba(10, 8, 25, .4); }
  .page { padding: 28px 16px 64px; }
  .doc h1 { font-size: 30px; }
  .lead { font-size: 17px; }
  .anchor { display: none; }
  .pager { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
