:root {
  --bg: oklch(99% 0.004 250); --panel: oklch(97% 0.006 250); --fg: oklch(23% 0.02 260);
  --muted: oklch(52% 0.02 260); --line: oklch(90% 0.01 260); --accent: oklch(52% 0.16 258);
  --accent-soft: oklch(95% 0.03 258); --code-bg: oklch(96% 0.008 250);
  --sidebar-w: 19rem; --topbar-h: 3.25rem;
}
[data-theme="dark"] {
  --bg: oklch(17% 0.012 260); --panel: oklch(21% 0.014 260); --fg: oklch(91% 0.012 260);
  --muted: oklch(66% 0.02 260); --line: oklch(30% 0.016 260); --accent: oklch(76% 0.12 250);
  --accent-soft: oklch(28% 0.04 255); --code-bg: oklch(24% 0.014 260);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 1rem); }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 400 16px/1.65 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "kern", "liga"; text-rendering: optimizeLegibility;
}

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem; padding: 0 .875rem;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar button {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  border-radius: .5rem; width: 2.25rem; height: 2.25rem; font-size: 1rem; cursor: pointer; line-height: 1;
}
.topbar button:hover { border-color: var(--accent); }
.topbar button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.brand { flex: 1; font-weight: 640; letter-spacing: -.011em; text-decoration: none; color: var(--fg); font-size: .975rem; }
.brand span { color: var(--muted); font-weight: 400; }
@media (max-width: 34rem) { .brand span { display: none; } }

.shell { display: flex; align-items: flex-start; }

aside {
  position: fixed; inset: var(--topbar-h) auto 0 0; z-index: 20;
  width: var(--sidebar-w); max-width: 86vw; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 1rem .75rem 3rem; transform: translateX(-101%); transition: transform .18s ease;
}
aside.open { transform: none; box-shadow: 0 0 0 100vmax color-mix(in oklab, black 38%, transparent); }
.navgroup { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 1rem .5rem .375rem; font-weight: 640; }
aside ul { list-style: none; margin: 0; padding: 0; }
aside li a {
  display: block; padding: .45rem .55rem; border-radius: .45rem; text-decoration: none;
  color: var(--fg); font-size: .875rem; line-height: 1.35;
}
aside li a:hover { background: var(--accent-soft); }
aside li.active > a { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.num { display: inline-block; min-width: 2.1rem; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .78rem; }
aside li.active .num { color: var(--accent); }

main { flex: 1; min-width: 0; padding: 1.5rem 1.125rem 5rem; }
article { max-width: 74ch; }
footer { max-width: 74ch; margin-top: 3.5rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }

.onthis { display: none; }

@media (min-width: 64rem) {
  #menu { display: none; }
  aside { transform: none; box-shadow: none; }
  main { margin-left: var(--sidebar-w); padding: 2rem 2.5rem 6rem; max-width: 76rem; }
  article { max-width: 76ch; }
  .onthis {
    display: block; float: right; width: 15rem; margin: .25rem 0 1.5rem 2rem;
    border-left: 2px solid var(--line); padding-left: .875rem;
  }
  .onthis ul { list-style: none; margin: 0; padding: 0; }
  .onthis li a { display: block; padding: .18rem 0; font-size: .8rem; color: var(--muted); text-decoration: none; }
  .onthis li a:hover { color: var(--accent); }
}

/* ---------- content ---------- */
h1 { font-size: clamp(1.55rem, 1.15rem + 1.7vw, 2.1rem); line-height: 1.18; letter-spacing: -.021em; margin: .25rem 0 1.25rem; font-weight: 700; text-wrap: balance; }
h2 { font-size: clamp(1.18rem, 1.02rem + .7vw, 1.4rem); line-height: 1.25; letter-spacing: -.014em; margin: 2.75rem 0 .875rem; padding-top: .75rem; border-top: 1px solid var(--line); font-weight: 660; text-wrap: balance; }
h3 { font-size: 1.06rem; margin: 1.85rem 0 .6rem; font-weight: 640; letter-spacing: -.008em; }
h4 { font-size: .95rem; margin: 1.4rem 0 .5rem; font-weight: 640; color: var(--muted); }
p, li { overflow-wrap: break-word; }
p { margin: 0 0 1rem; }
ul, ol { padding-left: 1.35rem; margin: 0 0 1rem; }
li { margin: .3rem 0; }
li > ul, li > ol { margin: .3rem 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.anchor { float: left; margin-left: -1.1rem; width: 1.1rem; color: var(--line); text-decoration: none; opacity: 0; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor { opacity: 1; }
@media (max-width: 64rem) { .anchor { display: none; } }
strong { font-weight: 660; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
blockquote { margin: 1rem 0; padding: .25rem 0 .25rem 1rem; border-left: 3px solid var(--accent); color: var(--muted); }

code { font: 400 .855em/1.5 ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace; background: var(--code-bg); padding: .12em .36em; border-radius: .3rem; }
pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: .6rem; padding: .875rem 1rem; overflow-x: auto; margin: 0 0 1.25rem; }
pre code { background: none; padding: 0; font-size: .82rem; line-height: 1.55; }

.tablewrap { overflow-x: auto; margin: 0 0 1.5rem; border: 1px solid var(--line); border-radius: .6rem; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .855rem; line-height: 1.5; }
th, td { padding: .5rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { background: var(--panel); font-weight: 640; white-space: nowrap; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in oklab, var(--accent-soft) 55%, transparent); }
td[align="right"], th[align="right"] { text-align: right; font-variant-numeric: tabular-nums; }

.mermaid { margin: 0 0 1.5rem; padding: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: .6rem; overflow-x: auto; text-align: center; }
.mermaid svg { max-width: 100%; height: auto; }

@media print {
  .topbar, aside, .onthis { display: none; }
  main { margin: 0; padding: 0; } article { max-width: none; }
}
