:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --fg: #1c1b19;
  --muted: #615e56;
  --border: #e4e0d5;
  --line: #efece4;
  --link: #7a5a06;
  --gold: #e5c261;
  --gold-soft: #faf1d6;
  --code-bg: #f4f2ec;
  --code-fg: #26241f;
  --verb-bg: #e3f1e6;
  --verb-fg: #1d6b34;
  --focus: #b08410;
  --shadow: 0 1px 2px rgb(28 27 25 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --surface: #232322;
    --fg: #e6e3da;
    --muted: #a9a59a;
    --border: #3a3936;
    --line: #2e2e2c;
    --link: #e5c261;
    --gold: #e5c261;
    --gold-soft: #3a3322;
    --code-bg: #151514;
    --code-fg: #e6e3da;
    --verb-bg: #1f3a27;
    --verb-fg: #8fd6a2;
    --focus: #e5c261;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-padding-top: 76px; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 0.875em; }
pre code { font-size: inherit; }
:not(pre) > code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 4px; padding: 0.05em 0.35em; white-space: nowrap; }

.skip { position: absolute; left: 16px; top: -48px; z-index: 20; background: var(--surface); color: var(--fg); padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; }
.skip:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 60px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; font-weight: 650; letter-spacing: -0.01em; min-height: 44px; }
.brand img { display: block; }
@media (prefers-color-scheme: dark) { .brand img { filter: invert(1); } }
.brand-sub { color: var(--muted); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px;
  padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--gold); color: #171717; font-weight: 600; font-size: 0.9375rem; text-decoration: none;
}
.btn:hover { background: #d9b24c; text-decoration: none; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface); }

/* Layout */
.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 48px; max-width: 1120px; margin: 0 auto; padding: 0 24px; }
.toc { position: sticky; top: 60px; align-self: start; max-height: calc(100vh - 60px); overflow-y: auto; padding: 32px 0; }
.toc-title { margin: 0 0 8px; padding: 0 12px; font-size: 0.75rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a { display: block; padding: 6px 12px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: 0.9375rem; line-height: 1.4; }
.toc-list a:hover { color: var(--fg); }
.toc-list a[aria-current="true"] { color: var(--fg); border-left-color: var(--gold); font-weight: 600; }
.toc-mobile { display: none; }

main { min-width: 0; max-width: 760px; padding: 40px 0 64px; outline: none; }
section { padding-top: 8px; margin-bottom: 48px; }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.015em; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2vw, 2.5rem); margin: 0 0 16px; font-weight: 720; text-wrap: balance; }
h2 { font-size: 1.5rem; margin: 0 0 16px; padding-top: 8px; font-weight: 680; }
h3 { font-size: 1.0625rem; margin: 28px 0 8px; font-weight: 650; }
h2 .anchor { color: inherit; text-decoration: none; }
h2 .anchor:hover::after { content: " #"; color: var(--muted); font-weight: 400; }
p, ul, ol, dl { margin: 0 0 16px; }
ul, ol { padding-left: 1.4em; }
li + li { margin-top: 6px; }

/* Hero */
.hero { padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 40px; }
.eyebrow { display: inline-block; margin: 0 0 12px; padding: 2px 10px; border-radius: 999px; background: var(--gold-soft); color: var(--link); font-size: 0.8125rem; font-weight: 650; }
.lead { font-size: 1.125rem; color: var(--muted); max-width: 64ch; }
.facts { list-style: none; padding: 0; margin: 24px 0 32px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.facts li { margin: 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.facts span { display: block; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.facts b { display: block; margin-top: 2px; font-size: 0.9375rem; font-weight: 600; }

/* Steps */
.steps { list-style: none; padding: 0; counter-reset: step; }
.steps > li { position: relative; padding-left: 44px; counter-increment: step; margin: 0 0 24px; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--gold); color: #171717; font-weight: 700; font-size: 0.875rem;
}
.steps h3 { margin: 2px 0 6px; }

/* Endpoint line */
.endpoint { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.endpoint code { background: none; border: 0; padding: 0; font-size: 0.9375rem; white-space: normal; overflow-wrap: anywhere; }
.verb { padding: 2px 8px; border-radius: 6px; background: var(--verb-bg); color: var(--verb-fg); font: 700 0.75rem/1.6 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.04em; }
.label { margin: 20px 0 8px; font-weight: 600; font-size: 0.9375rem; }

/* Code blocks */
.code { margin: 0 0 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--code-bg); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; padding: 0 6px 0 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.code pre { margin: 0; padding: 14px; overflow-x: auto; color: var(--code-fg); line-height: 1.55; tab-size: 2; }
.copy {
  min-height: 32px; min-width: 64px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  font-family: inherit; font-weight: 600; font-size: 0.8125rem; line-height: 1; cursor: pointer;
}
.copy:hover { border-color: var(--muted); }
.copy[data-state="done"] { color: var(--verb-fg); border-color: currentColor; }
.copy[hidden] { display: none; }

/* Tabs: without JS every panel shows, each with its own label */
.tabs { margin: 16px 0; }
.tab-list { display: none; }
.js .tab-list { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: -1px; }
.js .tab-list [role="tab"] {
  min-height: 40px; padding: 0 14px; border: 1px solid transparent; border-bottom: 0;
  border-radius: 8px 8px 0 0; background: none; color: var(--muted);
  font-family: inherit; font-weight: 600; font-size: 0.875rem; line-height: 1; cursor: pointer;
}
.js .tab-list [role="tab"]:hover { color: var(--fg); }
.js .tab-list [role="tab"][aria-selected="true"] { color: var(--fg); background: var(--code-bg); border-color: var(--border); }
.js .tabs:has([role="tab"]:first-child[aria-selected="true"]) .tab-panel { border-top-left-radius: 0; }
.js .tab-panel[hidden] { display: none; }

/* Tables */
.table-wrap { margin: 0 0 16px; overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.table-wrap.narrow { max-width: 420px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: left; vertical-align: top; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 0.8125rem; font-weight: 650; color: var(--muted); background: var(--bg); }
tr:last-child td { border-bottom: 0; }
td:first-child, th:first-child { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Definition lists */
.defs { display: grid; gap: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.defs > div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.defs > div:last-child { border-bottom: 0; }
.defs dt { font-weight: 650; }
.defs dd { margin: 0; color: var(--fg); }

/* Callouts */
.callout { margin: 0 0 16px; padding: 14px 16px; border: 1px solid var(--border); border-left: 4px solid var(--gold); border-radius: 10px; background: var(--gold-soft); }
.callout p { margin: 0; }
.callout .callout-title { font-weight: 650; margin-bottom: 4px; }

.foot { margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.875rem; }

/* Phones: stack wide tables as one card per row */
@media (max-width: 640px) {
  .stack { overflow: visible; border: 0; background: none; }
  .stack table, .stack tbody, .stack tr, .stack td { display: block; width: 100%; }
  .stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stack tr { margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
  .stack td { position: relative; padding: 8px 14px 8px 114px; border-bottom: 1px solid var(--line); white-space: normal; }
  .stack td:first-child { white-space: normal; }
  .stack td::before { content: attr(data-label); position: absolute; left: 14px; top: 8px; width: 88px; font-size: 0.8125rem; font-weight: 650; color: var(--muted); }
  .stack tr td:last-child { border-bottom: 0; }
}

/* 404 page */
.notfound { max-width: 560px; margin: 0 auto; padding: 96px 24px; text-align: center; }
.notfound h1 { margin-bottom: 12px; }
.notfound p { color: var(--muted); }

/* Narrow screens */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0 16px; }
  .toc { position: static; max-height: none; overflow: visible; padding: 16px 0 0; max-width: 760px; }
  .toc-desktop { display: none; }
  .toc-mobile { display: block; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
  .toc-mobile summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; font-weight: 600; cursor: pointer; list-style: none; }
  .toc-mobile summary::-webkit-details-marker { display: none; }
  .toc-mobile summary::after { content: ""; width: 8px; height: 8px; margin-right: 4px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-2px) rotate(45deg); }
  .toc-mobile[open] summary::after { transform: translateY(2px) rotate(-135deg); }
  .copy, .js .tab-list [role="tab"], .btn { min-height: 44px; }
  .code-head { min-height: 52px; }
  .toc-mobile .toc-list { padding: 0 0 8px; }
  .toc-mobile .toc-list a { min-height: 44px; display: flex; align-items: center; }
  main { padding-top: 24px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 0 16px; }
}
@media (max-width: 520px) {
  .brand-sub { display: none; }
  .defs > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}
