:root {
  --bg: #f6f5fb; --ink: #16183a; --muted: #5d6185; --faint: #666a8c;
  --line: rgba(40,44,110,.14); --accent: #4452d6; --code: #eaeaf6; --hl: #eceefe; --surface: #fff;
  --pre-bg: #12163a; --pre-ink: #e8f0ff; --pre-line: rgba(255,255,255,.12);
  --note-bg: #eceefe; --note-bar: #4452d6; --warn-bg: #fff1e8; --warn-bar: #b3400f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0e24; --ink: #eef0ff; --muted: #b4b9dc; --faint: #8a90bd;
    --line: rgba(255,255,255,.12); --accent: #8b96ff; --code: rgba(255,255,255,.09); --hl: #1a1f4a; --surface: #141838;
    --pre-bg: #0f1230; --note-bg: #161b44; --note-bar: #8b96ff; --warn-bg: #2b1a22; --warn-bar: #ff9a73;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0e24; --ink: #eef0ff; --muted: #b4b9dc; --faint: #8a90bd;
  --line: rgba(255,255,255,.12); --accent: #8b96ff; --code: rgba(255,255,255,.09); --hl: #1a1f4a; --surface: #141838;
  --pre-bg: #0f1230; --note-bg: #161b44; --note-bar: #8b96ff; --warn-bg: #2b1a22; --warn-bar: #ff9a73;
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); scroll-padding-top: 80px; }
body { background: var(--bg); color: var(--ink); font: 400 16px/1.7 Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--accent); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 16px; top: -60px; z-index: 50; background: var(--surface); color: var(--ink); padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; }
.skip:focus { top: 8px; }
[hidden] { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; gap: 16px; max-width: 1320px; margin: 0 auto; padding: 0 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 500 17px/1 "Inter Tight", sans-serif; letter-spacing: -.01em; white-space: nowrap; min-height: 32px; }
.brand svg { width: 26px; height: 18px; }
.label { font: 500 12px/1 "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; }
.top-links { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; }
.top-links a { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 10px; color: var(--muted); text-decoration: none; border-radius: 8px; }
.top-links a:hover { color: var(--ink); }
.gh-n { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; font-variant-numeric: tabular-nums; }
.theme { background: none; border: 0; color: var(--muted); width: 36px; height: 36px; border-radius: 999px; display: inline-grid; place-items: center; cursor: pointer; }
.theme:hover { color: var(--ink); }
.menu-btn { display: none; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; font: 500 14px/1 Inter, sans-serif; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }

/* layout */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr) 220px; gap: 48px; max-width: 1320px; margin: 0 auto; padding: 0 24px; }
.side, .toc { position: sticky; top: 60px; align-self: start; max-height: calc(100vh - 60px); overflow-y: auto; padding: 32px 0; }
.side-h, .toc-h { font: 500 11px/1 "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 12px; }
.side ul, .toc ul { list-style: none; display: grid; gap: 2px; }
.side a { display: flex; align-items: center; min-height: 36px; padding: 0 12px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; border-radius: 8px; }
.side a:hover { color: var(--ink); background: var(--hl); }
.side a[aria-current="page"] { color: var(--accent); background: var(--hl); }
.toc a { display: flex; align-items: center; min-height: 28px; padding: 2px 0 2px 12px; color: var(--muted); text-decoration: none; font-size: 13px; line-height: 1.4; border-left: 2px solid var(--line); }
.toc a.l3 { padding-left: 24px; }
.toc a:hover { color: var(--ink); }
.toc a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
main { min-width: 0; padding: 40px 0 24px; }
article { max-width: 70ch; min-width: 0; }

/* article */
article h1 { font: 500 clamp(32px, 4.2vw, 44px)/1.1 "Inter Tight", sans-serif; letter-spacing: -.035em; }
.lede { margin-top: 16px; font-size: 19px; line-height: 1.6; color: var(--muted); }
article h2 { font: 500 26px/1.25 "Inter Tight", sans-serif; letter-spacing: -.02em; margin: 56px 0 14px; padding-top: 32px; border-top: 1px solid var(--line); }
article h3 { font: 500 19px/1.35 "Inter Tight", sans-serif; letter-spacing: -.01em; margin: 32px 0 10px; }
.lede + h2 { margin-top: 40px; }
article h2, article h3 { position: relative; }
.anchor { position: absolute; left: -26px; top: 0; bottom: 0; display: inline-flex; align-items: center; justify-content: center; width: 24px; color: var(--faint); text-decoration: none; font: 400 16px/1 "JetBrains Mono", monospace; opacity: 0; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus-visible { opacity: 1; }
.anchor:hover { color: var(--accent); }
article p { margin: 14px 0; }
article .lede { margin: 16px 0 0; }
article ul, article ol { margin: 14px 0; padding-left: 24px; }
article li { margin: 6px 0; padding-left: 4px; }
article li::marker { color: var(--faint); }
article li > ul, article li > ol { margin: 6px 0; }
article strong { font-weight: 600; }
code { font: 400 .875em/1.5 "JetBrains Mono", ui-monospace, monospace; background: var(--code); padding: 2px 6px; border-radius: 5px; overflow-wrap: anywhere; }
.pre-wrap { position: relative; margin: 20px 0; }
pre { background: var(--pre-bg); color: var(--pre-ink); border: 1px solid var(--pre-line); border-radius: 12px; padding: 16px 56px 16px 18px; overflow-x: auto; font-size: 13.5px; line-height: 1.7; tab-size: 2; }
pre code { background: none; padding: 0; border-radius: 0; font-size: inherit; overflow-wrap: normal; white-space: pre; color: inherit; }
.copy { position: absolute; top: 8px; right: 8px; min-width: 40px; height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--pre-line); background: rgba(255,255,255,.08); color: #d4d9f5; font: 500 12px/1 Inter, sans-serif; cursor: pointer; }
.copy:hover { background: rgba(255,255,255,.18); color: #fff; }
.copy:focus-visible { outline-color: #fff; }
.tw { margin: 22px 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 560px; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); line-height: 1.5; }
td { color: var(--muted); }
thead th { font-weight: 600; background: var(--hl); white-space: nowrap; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
td code { white-space: nowrap; }
.note, .warn { margin: 22px 0; padding: 4px 18px; border-radius: 10px; border-left: 4px solid var(--note-bar); background: var(--note-bg); }
.warn { border-left-color: var(--warn-bar); background: var(--warn-bg); }
.note::before, .warn::before { content: "Note"; display: block; margin-top: 12px; font: 500 11px/1 "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--note-bar); }
.warn::before { content: "Warning"; color: var(--warn-bar); }
.note p, .warn p { margin: 8px 0 12px; font-size: 15px; }

/* prev/next + footer */
.pn { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 70ch; margin-top: 64px; }
.pn a { display: block; padding: 14px 18px; min-height: 64px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); background: var(--surface); }
.pn a:hover { border-color: var(--accent); }
.pn a.next { grid-column: 2; text-align: right; }
.pn small { display: block; font: 500 11px/1 "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; }
.pn span { font: 500 16px/1.3 "Inter Tight", sans-serif; color: var(--accent); }
.foot { max-width: 1320px; margin: 40px auto 0; padding: 24px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; color: var(--faint); font-size: 13px; }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr); gap: 40px; }
  .toc { display: none; }
}
@media (max-width: 800px) {
  .top-in { padding: 0 16px; gap: 10px; }
  .shell { display: block; padding: 0 16px; }
  .menu-btn { display: inline-flex; }
  .top-links .hide-s { display: none; }
  .side { display: none; position: static; max-height: none; padding: 16px 0 0; border-bottom: 1px solid var(--line); }
  .side.open { display: block; padding-bottom: 16px; }
  main { padding-top: 24px; }
  .anchor { display: none; }
  .foot { padding: 24px 16px; flex-direction: column; }
}
@media (max-width: 480px) { .label { display: none; } .pn { grid-template-columns: 1fr; } .pn a.next { grid-column: 1; } }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
