/* Layout: sticky top bar; sidebar | article (~70ch) | on-this-page rail. Same palette and faces as theonlygrid.com,
   dark first, with a light reading mode for viewers who ask for it. */
:root {
  --bg: #0d0f13;
  --bg2: #12151b;
  --card: #171a21;
  --code-bg: #10131a;
  --line: #262a33;
  --text: #eef0f3;
  --muted: #a3a8b3;
  --dim: #6d7380;
  --accent: #3987e5;
  --accent2: #5aa2ff;
  --teal: #2cc3b0;
  --amber: #f0b44c;
  --red: #ef6b6b;
  --sel: rgba(57, 135, 229, .28);
  --top-bg: rgba(13, 15, 19, .82);
  --f-body: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side-w: 264px;
  --toc-w: 220px;
  --top-h: 60px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fbfbfc; --bg2: #f3f5f8; --card: #ffffff; --code-bg: #f2f4f8; --line: #e1e5ec;
    --text: #141821; --muted: #4f5664; --dim: #7a8190; --accent: #1f6fd1; --accent2: #1f6fd1;
    --teal: #128a7c; --amber: #a86a06; --red: #c33a3a; --sel: rgba(31, 111, 209, .18);
    --top-bg: rgba(251, 251, 252, .86); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #fbfbfc; --bg2: #f3f5f8; --card: #ffffff; --code-bg: #f2f4f8; --line: #e1e5ec;
  --text: #141821; --muted: #4f5664; --dim: #7a8190; --accent: #1f6fd1; --accent2: #1f6fd1;
  --teal: #128a7c; --amber: #a86a06; --red: #c33a3a; --sel: rgba(31, 111, 209, .18);
  --top-bg: rgba(251, 251, 252, .86); color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top-h) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--f-body); font-size: 16px; line-height: 1.65; -webkit-font-smoothing: antialiased;
}
::selection { background: var(--sel); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; border-radius: 4px; }
code, kbd, pre { font-family: var(--f-mono); }
.skip { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--card); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 16px; }

/* top bar */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30; height: var(--top-h);
  background: var(--top-bg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  height: 100%; display: flex; align-items: center; gap: 18px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); white-space: nowrap; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand .mark { width: 26px; height: 26px; color: var(--muted); flex: none; }
.tag {
  font-family: var(--f-mono); font-size: 11.5px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase;
  color: var(--teal); border: 1px solid color-mix(in srgb, var(--teal) 45%, transparent);
  background: color-mix(in srgb, var(--teal) 10%, transparent); padding: 2px 8px; border-radius: 999px;
}
.menu { display: none; background: none; border: 0; padding: 6px; margin-left: -6px; color: var(--text); cursor: pointer; }
.menu svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search > svg { position: absolute; left: 11px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; fill: none; stroke: var(--dim); stroke-width: 1.8; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 38px 0 34px; border-radius: 10px; font: inherit; font-size: 14.5px;
  color: var(--text); background: var(--bg2); border: 1px solid var(--line);
}
.search input::placeholder { color: var(--dim); }
.search input:focus { outline: none; border-color: var(--accent); }
.search kbd {
  position: absolute; right: 9px; top: 50%; translate: 0 -50%; font-size: 11px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; line-height: 18px;
}
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: min(70vh, 480px); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .55);
}
.results a { display: block; padding: 9px 11px; border-radius: 8px; color: var(--text); }
.results a:hover, .results a.on { background: var(--bg2); text-decoration: none; }
.results b { display: block; font-weight: 600; font-size: 14.5px; }
.results small { display: block; color: var(--muted); font-size: 13px; line-height: 1.45; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results mark { background: none; color: var(--accent2); font-weight: 600; }
.results .none { padding: 12px; color: var(--muted); font-size: 14px; }
.top-links { display: flex; gap: 18px; font-size: 14.5px; }
.top-links a { color: var(--muted); }
.top-links a:hover { color: var(--text); }

/* shell */
.shell {
  display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr) var(--toc-w); gap: 48px;
  max-width: 1440px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.side, .toc {
  position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top, 0px)); align-self: start;
  max-height: calc(100vh - var(--top-h)); overflow-y: auto; padding-block: 28px 40px;
}
.side { border-right: 1px solid var(--line); padding-right: 20px; }
.nav-group + .nav-group { margin-top: 22px; }
.nav-h { margin: 0 0 8px; font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.side ul, .toc ul { list-style: none; margin: 0; padding: 0; }
.side li a {
  display: block; padding: 5px 10px; margin-left: -10px; border-radius: 7px; color: var(--muted); font-size: 14.5px;
}
.side li a:hover { color: var(--text); background: var(--bg2); text-decoration: none; }
.side li a[aria-current="page"] { color: var(--text); background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 500; }
.side-note { margin: 26px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--dim); }
.side-note code { font-size: 11.5px; }
.toc li a { display: block; padding: 3px 0 3px 12px; border-left: 1px solid var(--line); color: var(--dim); font-size: 13.5px; line-height: 1.45; }
.toc li.sub a { padding-left: 24px; }
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.on { color: var(--text); border-left-color: var(--accent); }
.scrim { display: none; }

/* article */
.doc { min-width: 0; padding-block: 34px 40px; }
.crumb { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--teal); letter-spacing: .02em; }
.prose { max-width: 74ch; }
.prose h1 { font-size: clamp(30px, 4vw, 40px); font-weight: 800; letter-spacing: -.025em; line-height: 1.15; margin: 0 0 14px; text-wrap: balance; }
.prose h2 { font-size: 24px; font-weight: 700; letter-spacing: -.015em; line-height: 1.25; margin: 48px 0 12px; padding-top: 22px; border-top: 1px solid var(--line); text-wrap: balance; }
.prose h3 { font-size: 18px; font-weight: 650; margin: 32px 0 8px; line-height: 1.35; }
.prose h4 { font-size: 15.5px; font-weight: 650; margin: 24px 0 6px; }
.prose p, .prose ul, .prose ol { margin: 0 0 16px; }
.prose > p:first-of-type { font-size: 18px; color: var(--muted); }
.prose li { margin: 4px 0; }
.prose li > p { margin: 0 0 6px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose strong { font-weight: 650; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 36px 0; }
.anchor { margin-left: 8px; color: var(--dim); opacity: 0; font-weight: 400; transition: opacity .15s; }
.prose h2:hover .anchor, .prose h3:hover .anchor, .anchor:focus { opacity: 1; text-decoration: none; }

.prose :not(pre) > code {
  font-size: .86em; padding: .12em .38em; border-radius: 5px; background: var(--code-bg); border: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.prose pre {
  position: relative; margin: 0 0 18px; padding: 14px 16px; border-radius: 10px; overflow-x: auto;
  background: var(--code-bg); border: 1px solid var(--line); font-size: 13.5px; line-height: 1.6;
}
.prose pre code { white-space: pre; }
.copy {
  position: absolute; top: 8px; right: 8px; font: 500 12px var(--f-body); color: var(--muted); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; opacity: 0; transition: opacity .15s;
}
.prose pre:hover .copy, .copy:focus-visible { opacity: 1; }
.copy.done { color: var(--teal); }
@media (hover: none) { .copy { opacity: 1; } }
.c-comment { color: var(--dim); }

.table { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--line); border-radius: 10px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 14.5px; line-height: 1.5; }
.prose th, .prose td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { font-weight: 600; font-size: 13px; color: var(--muted); background: var(--bg2); white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.prose td code { white-space: nowrap; }

/* callouts: !!! note / tip / warning / danger */
.admonition { margin: 0 0 20px; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); }
.admonition > p:last-child { margin-bottom: 0; }
.admonition-title { margin: 0 0 4px !important; font-weight: 650; font-size: 14px; color: var(--accent2); }
.admonition.tip { border-color: color-mix(in srgb, var(--teal) 40%, var(--line)); }
.admonition.tip .admonition-title { color: var(--teal); }
.admonition.warning { border-color: color-mix(in srgb, var(--amber) 45%, var(--line)); }
.admonition.warning .admonition-title { color: var(--amber); }
.admonition.danger { border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }
.admonition.danger .admonition-title { color: var(--red); }

/* landing cards (index) */
.paths { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin: 8px 0 28px; }
.paths a {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 16px 15px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); transition: border-color .15s, transform .15s;
}
.paths a:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.paths .k { font-family: var(--f-mono); font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--teal); }
.paths b { font-size: 16px; font-weight: 650; }
.paths span:last-child { font-size: 14px; color: var(--muted); line-height: 1.5; }

/* steps: an ordered list that is a real sequence */
.steps { counter-reset: s; list-style: none; padding-left: 0 !important; }
.steps > li { counter-increment: s; position: relative; padding-left: 40px; margin: 0 0 16px; }
.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 1px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font: 600 13px var(--f-mono); color: var(--accent2);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--line));
}

.prevnext { display: flex; justify-content: space-between; gap: 12px; margin: 48px 0 0; max-width: 74ch; }
.pn { display: flex; flex-direction: column; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-weight: 600; min-width: 0; }
.pn span { font-size: 12.5px; font-weight: 500; color: var(--dim); }
.pn.next { text-align: right; margin-left: auto; }
.pn:hover { border-color: var(--accent); text-decoration: none; }
.foot { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--line); max-width: 74ch; font-size: 13px; color: var(--dim); }
.foot p { margin: 0 0 8px; }
.foot a { color: var(--muted); }

/* responsive */
@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--side-w) minmax(0, 1fr); gap: 40px; }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .menu { display: inline-flex; }
  .top-links { display: none; }
  .brand > span:not(.tag) { display: none; }
  .search { max-width: none; }
  .search kbd { display: none; }
  .side {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); max-height: none;
    background: var(--bg); border-right: 1px solid var(--line);
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(28px + env(safe-area-inset-bottom, 0px)) max(20px, calc(env(safe-area-inset-left, 0px) + 16px));
    transform: translateX(-105%); transition: transform .22s ease;
  }
  .side.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .5); }
  .scrim[hidden] { display: none; }
  .doc { padding-top: 24px; }
  .prose h2 { margin-top: 38px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
