:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f2f1ec;
  --ink: #17201f;
  --muted: #5d6764;
  --line: #dedcd3;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --accent-soft: #e4effb;
  --ok: #1d7a46;
  --warn: #a15c07;
  --bad: #b3261e;
  --code-bg: #14201f;
  --code-ink: #dce8e4;
  --code-key: #8cc8ff;
  --code-str: #f2c879;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111716; --surface: #182120; --surface-2: #1f2a29; --ink: #e8eeec; --muted: #9baba6;
    --line: #2d3b39; --accent: #6db3ff; --accent-ink: #0a1a2b; --accent-soft: #14283d;
    --ok: #5fd390; --warn: #f0b35a; --bad: #ff8a80; --code-bg: #0b1110;
  }
}
:root[data-theme="dark"] {
  --bg: #111716; --surface: #182120; --surface-2: #1f2a29; --ink: #e8eeec; --muted: #9baba6;
  --line: #2d3b39; --accent: #6db3ff; --accent-ink: #0a1a2b; --accent-soft: #14283d;
  --ok: #5fd390; --warn: #f0b35a; --bad: #ff8a80; --code-bg: #0b1110;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--sans); }
a { color: var(--accent); }
code, pre, kbd { font-family: var(--mono); }
:not(pre) > code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: .88em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* header */
.site-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; height: 60px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 15px; }
.brand small { color: var(--muted); font-weight: 500; }
.header-spacer { flex: 1; }
.header-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.header-link:hover { color: var(--ink); }
.menu-toggle { display: none; border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 6px 10px; }

/* layout */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); max-width: 1240px; margin: 0 auto; }
.sidebar { position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px); overflow-y: auto; padding: 24px 12px 40px 20px; border-right: 1px solid var(--line); }
.sidebar h2 { margin: 20px 0 6px; padding: 0 10px; font: 600 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sidebar h2:first-child { margin-top: 0; }
.sidebar a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 14px; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { min-width: 0; padding: 40px clamp(20px, 4vw, 56px) 80px; max-width: 900px; }
.site-footer { border-top: 1px solid var(--line); padding: 24px 20px; text-align: center; color: var(--muted); font-size: 13px; }

/* content */
.eyebrow { margin: 0 0 8px; font: 600 12px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0 0 12px; font-size: clamp(30px, 4.5vw, 42px); line-height: 1.12; letter-spacing: -.02em; }
h2.section { margin: 44px 0 10px; font-size: 22px; letter-spacing: -.01em; }
h3 { margin: 0 0 6px; font-size: 16px; }
.lead { font-size: 18px; color: var(--muted); max-width: 62ch; margin: 0 0 20px; }
p, li { max-width: 68ch; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 18px 0 0; }

.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 5px 10px; font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.card + .card { margin-top: 14px; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-top: 16px; }
.feature { display: flex; flex-direction: column; gap: 6px; color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s; }
.feature:hover { border-color: var(--accent); transform: translateY(-2px); }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }
.feature .tag { font: 600 11px/1 var(--mono); color: var(--accent); letter-spacing: .06em; text-transform: uppercase; }

.status { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state="live"]::before { background: var(--ok); }
.status[data-state="off"]::before { background: var(--muted); }

.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 12px 16px; border-radius: 0 8px 8px 0; margin: 16px 0; font-size: 15px; }
.callout > :first-child { margin-top: 0; } .callout > :last-child { margin-bottom: 0; }

/* code */
.code-wrap { position: relative; margin: 12px 0; }
pre.code { margin: 0; padding: 16px 18px; overflow-x: auto; background: var(--code-bg); color: var(--code-ink); border-radius: 10px; font-size: 13px; line-height: 1.6; }
.code-label { display: block; margin: 14px 0 -4px; font: 600 12px var(--mono); color: var(--muted); }
.copy { position: absolute; top: 8px; right: 8px; padding: 3px 9px; font-size: 12px; border: 1px solid #3a4a48; background: #1f2d2b; color: #cfe0db; border-radius: 6px; }
output.out { display: block; min-height: 3em; }

/* demo */
.demo { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.demo-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); font: 600 12px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.demo-body { padding: 18px; display: grid; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 14px; width: 100%; }
.field textarea { font-family: var(--mono); font-size: 13px; min-height: 90px; }
.fields-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.log { margin: 0; padding: 0; list-style: none; font: 13px/1.5 var(--mono); max-height: 220px; overflow-y: auto; }
.log li { padding: 5px 0; border-bottom: 1px dashed var(--line); max-width: none; }
.log li:first-child { color: var(--ink); }
.log .yes { color: var(--ok); } .log .no { color: var(--muted); } .log .bad { color: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--mono); font-size: 13px; word-break: break-word; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 600 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.yes-mark { color: var(--ok); font-weight: 700; } .no-mark { color: var(--bad); font-weight: 700; }

/* dialog */
dialog { width: min(720px, calc(100% - 24px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 90px #0006; }
dialog::backdrop { background: #0a1210aa; }
.dialog-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 19px; }
.dialog-close { border: 0; background: transparent; font-size: 26px; line-height: 1; padding: 0 6px; color: var(--muted); }
.dialog-body { padding: 8px 22px 24px; }
.dialog-body ol { padding-left: 22px; }
.dialog-body li { margin-bottom: 8px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-block; }
  .sidebar { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar.open { display: block; }
  main { padding-top: 28px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
