:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f7;
  --bg-header: #ffffff;
  --border: #e2e2e3;
  --text: #213547;
  --text-2: #3c3c43c7;
  --text-3: #3c3c4380;
  --accent: #3451b2;
  --accent-soft: #3451b21a;
  --tip-bg: #f3e8fd;
  --tip-border: #a855f7;
  --tip-title: #7e22ce;
  --code-bg: #f1f1f3;
  --radius: 8px;
  --header-h: 68px;
  --sidebar-w: 300px;
  --toc-w: 280px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1b1f; --bg-soft: #202127; --bg-header: #202127; --border: #2e2e32;
    --text: #dfdfd6; --text-2: #98989f; --text-3: #6a6a71;
    --accent: #a8b1ff; --accent-soft: #a8b1ff29;
    --tip-bg: #3f1f52; --tip-border: #c86bfa; --tip-title: #e9b5ff; --code-bg: #161618;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1b1f; --bg-soft: #202127; --bg-header: #202127; --border: #2e2e32;
  --text: #dfdfd6; --text-2: #98989f; --text-3: #6a6a71;
  --accent: #a8b1ff; --accent-soft: #a8b1ff29;
  --tip-bg: #3f1f52; --tip-border: #c86bfa; --tip-title: #e9b5ff; --code-bg: #161618;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.75 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h); z-index: 30;
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  background: var(--bg-header); border-bottom: 1px solid var(--border);
}
.brand { font-size: 26px; font-weight: 500; color: var(--accent); text-decoration: none; white-space: nowrap; }
.brand { font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.brand b { color: var(--accent); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 6px;
  background: none; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }
.menu-btn { display: none; }
.theme select {
  appearance: none; min-width: 132px; height: 40px; padding: 0 36px 0 14px; border: 0; border-radius: 10px;
  background: var(--accent-soft) no-repeat right 12px center / 14px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398989f' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  color: var(--text); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; transition: background-color .15s;
}
.theme select:hover { background-color: color-mix(in srgb, var(--accent) 24%, transparent); }
.theme select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme option { background: var(--bg-soft); color: var(--text); }
.search { position: relative; margin-left: auto; display: flex; align-items: center; color: var(--text-2); }
.search > svg { position: absolute; left: 12px; pointer-events: none; }
.search input {
  width: 260px; height: 40px; padding: 0 12px 0 36px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-soft); color: var(--text); font: inherit; font-size: 14px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results {
  position: absolute; top: 46px; right: 0; width: 340px; max-height: 60vh; overflow: auto; margin: 0; padding: 6px;
  list-style: none; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px #0000003d;
}
.results a { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; line-height: 1.4; }
.results a:hover, .results li:first-child a { background: var(--accent-soft); }
.results small { color: var(--text-2); }
.results .empty { padding: 10px; color: var(--text-2); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w); padding-top: var(--header-h); min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto;
  padding: 24px 20px 48px 26px; background: var(--bg-soft); border-right: 1px solid var(--border);
}
.nav, .nav ul { list-style: none; margin: 0; padding: 0; }
.nav .sub {
  display: grid; grid-template-rows: 0fr; margin: 0; opacity: 0; visibility: hidden; /* hidden keeps collapsed links out of Tab order */
  transition: grid-template-rows .32s cubic-bezier(.2, .8, .2, 1), margin .32s, opacity .25s, visibility 0s .32s;
}
.nav li.open > .sub { grid-template-rows: 1fr; margin: 2px 0 6px; opacity: 1; visibility: visible; transition-delay: 0s; }
.nav .sub > ul { min-height: 0; overflow: hidden; padding-left: 14px; border-left: 1px solid var(--border); }
.nav li.open > .sub > ul > li { animation: nav-in .35s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i, 0) * 22ms); }
@keyframes nav-in { from { opacity: 0; transform: translateX(-8px); } }
@media (prefers-reduced-motion: reduce) {
  .nav .sub, .chev { transition: none; }
  .nav li.open > .sub > ul > li { animation: none; }
}
.nav-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.nav a {
  flex: 1; padding: 5px 0; color: var(--text-2); text-decoration: none; font-size: 14px; line-height: 1.5;
  transition: color .15s;
}
.nav > li > .nav-row > a { padding: 8px 0; color: var(--text); font-size: 17px; font-weight: 600; }
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--accent); font-weight: 600; }
.chev {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin-top: 4px;
  border: 0; border-radius: 6px; background: none; color: var(--text-2); cursor: pointer; transition: transform .3s cubic-bezier(.2, .8, .2, 1), background .15s;
}
.chev:hover { background: var(--accent-soft); color: var(--text); }
li.open > .nav-row > .chev { transform: rotate(90deg); }

/* ---------- content ---------- */
.content { padding: 48px 48px 96px; outline: none; }
.doc, .pager { max-width: 760px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--text-3); margin-bottom: 8px; }
.crumbs a { color: var(--text-2); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.doc h1 { font-size: 46px; line-height: 1.2; font-weight: 600; letter-spacing: -.02em; margin: 0 0 20px; }
.title-rule { margin: 0 -48px 24px; border: 0; border-top: 1px solid var(--border); }
.doc .title-rule + h2 { margin-top: 0; padding-top: 0; } /* no extra gap when a section starts right under the title */
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); margin-bottom: 24px; }
.meta:empty { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 12px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 13px; text-decoration: none; background: var(--bg-soft);
}
.pill:hover { border-color: var(--accent); }
.doc h2 { font-size: 30px; line-height: 1.3; font-weight: 600; margin: 48px 0 16px; padding-top: 8px; letter-spacing: -.01em; }
.doc h3 { font-size: 21px; font-weight: 600; margin: 32px 0 8px; }
.doc p, .doc li { color: var(--text-2); }
.doc strong { color: var(--text); }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }
.doc img { max-width: 100%; height: auto; border-radius: var(--radius); }
.doc code { font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: .875em; background: var(--code-bg); padding: 2px 6px; border-radius: 4px; }
.doc pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; overflow-x: auto; line-height: 1.6; }
.doc pre code { background: none; padding: 0; }
.table-wrap { overflow-x: auto; margin: 20px 0; }
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; }
.doc th, .doc td { border: 1px solid var(--border); padding: 8px 14px; text-align: left; vertical-align: top; }
.doc th { background: var(--bg-soft); color: var(--text); }
.doc tr:nth-child(2n) td { background: color-mix(in srgb, var(--bg-soft) 50%, transparent); }

.callout { margin: 24px 0; padding: 14px 22px; background: var(--tip-bg); border-left: 5px solid var(--tip-border); border-radius: 0 4px 4px 0; }
.callout p, .callout li { color: var(--text); }
.callout-title { display: flex; align-items: center; gap: 8px; color: var(--tip-title); font-weight: 500; font-size: 18px; }

/* section cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.card {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--bg-soft); text-decoration: none; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-num { font-size: 12px; color: var(--accent); font-weight: 600; }
.card-title { color: var(--text); font-weight: 600; line-height: 1.4; }
.card-meta { font-size: 12px; color: var(--text-3); }

/* svg gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.gallery figure { margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-soft); }
.gallery img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; border-radius: 6px; }
.gallery figcaption { margin-top: 8px; font-size: 14px; color: var(--text); text-transform: capitalize; text-align: center; }

/* full screen visuals */
.viz { position: relative; }
.fs-btn {
  position: absolute; top: 10px; right: 10px; display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid #ffffff33; border-radius: 8px; background: #000000a6; color: #fff; cursor: pointer;
  opacity: 0; transition: opacity .15s;
}
.viz:hover .fs-btn, .fs-btn:focus-visible, .viz.is-full .fs-btn { opacity: 1; }
@media (hover: none) { .fs-btn { opacity: 1; } }
.doc img { cursor: zoom-in; }
.viz.is-full {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; margin: 0;
  border: 0; border-radius: 0; background: var(--bg);
}
.viz.is-full .fs-btn { position: fixed; top: 16px; right: 16px; }
.viz.is-full img { width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 48px); aspect-ratio: auto; cursor: zoom-out; }
.viz.is-full a { display: contents; pointer-events: none; }
.viz.is-full figcaption { display: none; }
.viz-open { overflow: hidden; }

/* prev / next */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--border); }
.pager a { display: flex; flex-direction: column; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; font-weight: 500; }
.pager a:hover { border-color: var(--accent); }
.pager small { color: var(--text-2); font-weight: 400; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- on this page ---------- */
.toc { position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto; padding: 24px 24px 48px 16px; }
.toc-title { margin: 0 0 8px; font-weight: 600; font-size: 18px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: block; padding: 3px 8px; margin: 1px 0; border-radius: 4px; font-size: 14px; line-height: 1.45;
  color: var(--text-2); text-decoration: none; cursor: pointer;
}
.toc li:not(:first-child) a { padding-left: 26px; }
.toc li.sub a { padding-left: 42px; font-size: 13px; }
.toc a:hover { color: var(--text); }
.toc a.active { background: var(--accent); color: #1b1b1f; font-weight: 500; }

.loading { color: var(--text-2); }
.backdrop { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-grid; }
  .brand { font-size: 18px; }
  .search input { width: 140px; }
  .theme select { min-width: 0; padding: 0 30px 0 10px; background-position: right 10px center; }
  .topbar { gap: 8px; padding: 0 12px; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; z-index: 25; width: min(86vw, var(--sidebar-w));
    transform: translateX(-100%); transition: transform .25s;
  }
  .nav-open .sidebar { transform: none; }
  .nav-open .backdrop { display: block; position: fixed; inset: var(--header-h) 0 0 0; z-index: 20; background: #0008; }
  .content { padding: 28px 16px 64px; }
  .title-rule { margin: 0 -16px 24px; }
  .doc h1 { font-size: 32px; }
  .doc h2 { font-size: 24px; }
  .results { width: calc(100vw - 24px); right: -60px; }
}
@media (max-width: 480px) {
  .brand { font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .brand span { display: none; }
  .search { margin-left: 0; }
  .search input { width: 40px; padding: 0; color: transparent; }
  .search input:not(:focus)::placeholder { color: transparent; }
  .search input:focus { position: fixed; left: 12px; right: 12px; top: 14px; width: auto; padding: 0 12px; color: var(--text); z-index: 2; }
  .search > svg { left: 12px; }
  .results { position: fixed; top: var(--header-h); left: 12px; right: 12px; width: auto; }
  .theme { margin-left: auto; }
}
