/* Minigraf docs. System fonts only; light and dark themes via tokens. */

:root {
  --bg: #fbfbfa;
  --bg-raised: #ffffff;
  --bg-sunken: #f2f2ef;
  --text: #1d1f21;
  --text-muted: #5d6166;
  --border: #e3e3de;
  --accent: #2f5fd0;
  --accent-soft: #e8eefc;
  --code-bg: #f3f3f0;
  --added: #1f7a4a;
  --added-bg: #e7f5ec;
  --removed: #b4372f;
  --removed-bg: #fbeceb;
  --dev: #8a5a00;
  --dev-bg: #fff4dc;
  --tok-keyword: #7a3e9d;
  --tok-var: #b2502c;
  --tok-string: #2e7d32;
  --tok-comment: #8a8f95;
  --tok-number: #1565c0;
  --tok-head: #2f5fd0;
  --on-accent: #ffffff;
  --shadow: 0 8px 24px rgba(20, 22, 26, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --topbar: 56px;
  --sidebar: 264px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --bg-raised: #1c1f23;
    --bg-sunken: #111316;
    --text: #e4e6e9;
    --text-muted: #9aa0a7;
    --border: #2c3036;
    --accent: #7ea2ff;
    --accent-soft: #1f2a44;
    --code-bg: #1f2227;
    --added: #6fd39b;
    --added-bg: #16291f;
    --removed: #ff8a80;
    --removed-bg: #2f1b1a;
    --dev: #f2c063;
    --dev-bg: #2c2414;
    --tok-keyword: #d3a4f5;
    --tok-var: #ffab83;
    --tok-string: #9ad79c;
    --tok-comment: #7f868e;
    --tok-number: #8cc3ff;
    --tok-head: #7ea2ff;
    --on-accent: #10131a;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --bg-raised: #1c1f23;
  --bg-sunken: #111316;
  --text: #e4e6e9;
  --text-muted: #9aa0a7;
  --border: #2c3036;
  --accent: #7ea2ff;
  --accent-soft: #1f2a44;
  --code-bg: #1f2227;
  --added: #6fd39b;
  --added-bg: #16291f;
  --removed: #ff8a80;
  --removed-bg: #2f1b1a;
  --dev: #f2c063;
  --dev-bg: #2c2414;
  --tok-keyword: #d3a4f5;
  --tok-var: #ffab83;
  --tok-string: #9ad79c;
  --tok-comment: #7f868e;
  --tok-number: #8cc3ff;
  --tok-head: #7ea2ff;
  --on-accent: #10131a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--topbar) + 16px); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font);
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--bg-raised); padding: 8px 12px; border-radius: 6px;
}
.skip:focus { left: 8px; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; font-size: 17px; color: var(--text); text-decoration: none;
}

.toplinks { margin-left: auto; display: flex; align-items: center; gap: 18px; font-size: 14.5px; }
.toplinks a { color: var(--text-muted); text-decoration: none; white-space: nowrap; }
.toplinks a:hover { color: var(--text); }

.theme-toggle, .menu-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  background: none; border: 1px solid transparent; border-radius: 8px; color: var(--text-muted);
}
.theme-toggle:hover, .menu-toggle:hover { border-color: var(--border); color: var(--text); }
.menu-toggle { display: none; }

/* Version picker */
.picker { position: relative; }
.picker summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-raised); font-size: 14px; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.picker summary::-webkit-details-marker { display: none; }
.picker summary::after {
  content: ""; width: 6px; height: 6px; margin-left: 2px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg); opacity: 0.6;
}
.picker-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  min-width: 240px; max-height: 70vh; overflow: auto;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px;
}
.picker-group + .picker-group { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.picker-line {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding: 4px 10px;
}
.picker ul { list-style: none; margin: 0; padding: 0; }
.picker li { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.picker li a {
  flex: 1; display: block; padding: 5px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: 14.5px; font-variant-numeric: tabular-nums;
}
.picker li a:hover { background: var(--bg-sunken); }
.picker li a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.picker-note { font-size: 12px; color: var(--text-muted); padding-right: 8px; white-space: nowrap; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

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

.sidebar {
  position: sticky; top: var(--topbar);
  flex: 0 0 var(--sidebar); width: var(--sidebar);
  height: calc(100vh - var(--topbar)); overflow-y: auto;
  padding: 20px 12px 40px 16px;
  border-right: 1px solid var(--border);
  font-size: 14.5px;
}
.nav-section + .nav-section { margin-top: 18px; }
.nav-section h2 {
  margin: 0 0 4px; padding: 0 10px;
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block; padding: 4px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; line-height: 1.4;
}
.sidebar a:hover { background: var(--bg-sunken); }
.sidebar a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar code { font-size: 0.9em; background: none; padding: 0; }

main { flex: 1; min-width: 0; padding: 28px 40px 80px; }
main:focus { outline: none; }

.doc { max-width: 820px; margin: 0 auto; }

/* ── Banners and badges ──────────────────────────────────────────────────── */

.banner {
  max-width: 820px; margin: 0 auto 20px; padding: 10px 14px;
  border-radius: 8px; font-size: 14.5px;
}
.banner-dev { background: var(--dev-bg); color: var(--dev); }
.banner-old { background: var(--accent-soft); color: var(--text); }
.banner a { color: inherit; font-weight: 600; }

.badge-added {
  display: inline-block; margin: 18px 0 -6px;
  padding: 1px 8px; border-radius: 999px;
  background: var(--added-bg); color: var(--added);
  font-size: 12.5px; font-weight: 600;
}

.frag { border-radius: 8px; }
.frag-changed { animation: changed 2.4s ease-out; }
@keyframes changed {
  0%, 30% { box-shadow: 0 0 0 6px var(--accent-soft); background: var(--accent-soft); }
  100% { box-shadow: 0 0 0 6px transparent; background: transparent; }
}
@media (prefers-reduced-motion: reduce) { .frag-changed { animation: none; } }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Content ─────────────────────────────────────────────────────────────── */

.doc h1 { font-size: 2.1rem; line-height: 1.2; margin: 0.2em 0 0.6em; letter-spacing: -0.01em; }
.doc h2 { font-size: 1.5rem; line-height: 1.3; margin: 1.8em 0 0.6em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.doc h3 { font-size: 1.2rem; margin: 1.6em 0 0.5em; }
.doc h4 { font-size: 1.05rem; margin: 1.4em 0 0.4em; }
.doc h1 code, .doc h2 code, .doc h3 code { font-size: 0.88em; }

.anchor { margin-left: 8px; color: var(--text-muted); text-decoration: none; opacity: 0; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor, .anchor:focus { opacity: 1; }

.doc p, .doc ul, .doc ol { margin: 0.8em 0; }
.doc li + li { margin-top: 0.25em; }
.doc img { max-width: 100%; }
.doc blockquote {
  margin: 1em 0; padding: 0.4em 1em;
  border-left: 3px solid var(--accent); background: var(--bg-sunken); border-radius: 0 8px 8px 0;
}
.doc blockquote p { margin: 0.4em 0; }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

code {
  font-family: var(--mono); font-size: 0.88em;
  background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px;
}
pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; overflow-x: auto;
  font-size: 13.5px; line-height: 1.55;
}
pre code { background: none; padding: 0; font-size: inherit; }

.tok-keyword { color: var(--tok-keyword); }
.tok-var { color: var(--tok-var); }
.tok-string { color: var(--tok-string); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-number { color: var(--tok-number); }
.tok-head { color: var(--tok-head); font-weight: 600; }
.tok-slot { color: var(--tok-var); font-style: italic; }

table {
  border-collapse: collapse; margin: 1em 0; font-size: 14.5px;
  display: block; overflow-x: auto; max-width: 100%;
}
th, td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--bg-sunken); font-weight: 600; }
.results th { white-space: nowrap; }

.assembled {
  max-width: 820px; margin: 48px auto 0; padding: 12px 16px;
  border: 1px dashed var(--border); border-radius: 10px;
  font-size: 14px; color: var(--text-muted);
}
.assembled summary { cursor: pointer; }
.assembled pre { white-space: pre-wrap; word-break: break-word; }

/* ── Tools: diff and console ─────────────────────────────────────────────── */

.tool .lede { color: var(--text-muted); font-size: 1.05rem; }
.note { color: var(--text-muted); }
.status { min-height: 1.6em; color: var(--text-muted); font-size: 14.5px; margin: 10px 0; }

select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px;
}
select { padding: 6px 8px; max-width: 100%; }
form button[type="submit"] {
  padding: 7px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}

.diff-form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 20px 0; }
.diff-form label { display: flex; align-items: center; gap: 8px; }
.diff-form .arrow { color: var(--text-muted); }
.diff-lede { font-size: 1.05rem; }
.diff-index { columns: 2 260px; padding-left: 1.2em; }
.diff-page { margin-top: 32px; }
.diff-page h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; }
.diff-page h2 a { color: var(--text); text-decoration: none; }
.diff-counts { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.plus { color: var(--added); }
.minus { color: var(--removed); }
.diff-tag { font-size: 12.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.diff-tag-added { background: var(--added-bg); color: var(--added); }
.diff-tag-removed { background: var(--removed-bg); color: var(--removed); }
.diff-frag { margin: 14px 0; padding: 4px 16px 6px; border-radius: 8px; border-left: 4px solid; }
.diff-added { border-color: var(--added); background: color-mix(in srgb, var(--added-bg) 60%, transparent); }
.diff-removed { border-color: var(--removed); background: color-mix(in srgb, var(--removed-bg) 60%, transparent); }
.diff-label { font-size: 12.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 8px; }
.diff-added .diff-label { color: var(--added); }
.diff-removed .diff-label { color: var(--removed); }
.diff-frag h2 { border: none; }
.diff-same { margin: 10px 0; padding: 6px 12px; border-radius: 8px; background: var(--bg-sunken); font-size: 14px; color: var(--text-muted); }
.diff-same summary { cursor: pointer; }
.diff-headings { margin: 6px 0; columns: 2 220px; }

.console-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 20px 0; }
.console-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.console-row label { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.console-row select { min-width: 0; flex: 1; }
.console-form textarea { width: 100%; padding: 12px 14px; font: 13.5px/1.55 var(--mono); resize: vertical; }
.hint { color: var(--text-muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
.results { display: table; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.results td { font-family: var(--mono); font-size: 13px; }
.results .ver, .results .nil { font-family: var(--font); color: var(--text-muted); font-size: 12px; }
.result-error { border-color: var(--removed); color: var(--removed); white-space: pre-wrap; }
.result-raw { white-space: pre-wrap; }
.schema { margin: 12px 0; font-size: 14.5px; }
.schema summary { cursor: pointer; font-weight: 600; }

.notfound { max-width: 560px; margin: 15vh auto; padding: 0 16px; text-align: center; }

/* ── Narrow screens ──────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar); z-index: 25;
    background: var(--bg); box-shadow: var(--shadow);
    transform: translateX(-105%); transition: transform 0.2s;
  }
  body.nav-open .sidebar { transform: none; }
  main { padding: 20px 16px 64px; }
  .toplinks { gap: 12px; }
  .toplinks a:not(:first-child) { display: none; }
}

@media (max-width: 560px) {
  .brand span { display: none; }
  .toplinks a { display: none; }
  .picker-menu { position: fixed; left: 16px; right: 16px; top: calc(var(--topbar) + 4px); min-width: 0; }
  .doc h1 { font-size: 1.7rem; }
}
