:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #5b6774;
  --line: #dde3ea;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --ok: #1d7a46;
  --warn: #9a6a00;
  --bad: #a3332e;
  --chip: #eef3f8;
  --code: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --panel: #161c23;
  --ink: #e8edf2;
  --muted: #9aa7b4;
  --line: #273039;
  --accent: #6fb3e0;
  --accent-ink: #0f1419;
  --ok: #58c389;
  --warn: #e3b341;
  --bad: #f08a84;
  --chip: #1f2932;
  --code: #1b232b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --panel: #161c23;
    --ink: #e8edf2;
    --muted: #9aa7b4;
    --line: #273039;
    --accent: #6fb3e0;
    --accent-ink: #0f1419;
    --ok: #58c389;
    --warn: #e3b341;
    --bad: #f08a84;
    --chip: #1f2932;
    --code: #1b232b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
code { background: var(--code); padding: 0.1em 0.35em; border-radius: 4px; }
pre { background: var(--code); padding: 12px; border-radius: 8px; overflow: auto; max-height: 420px; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--panel); padding: 8px; }
.skip:focus { left: 8px; z-index: 10; }
.muted { color: var(--muted); }

.topbar { border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar__row { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); text-decoration: none; }
.brand__mark { width: 26px; height: 26px; }
.brand__mark .bg { fill: var(--accent); }
.brand__mark .ln { stroke: var(--accent-ink); stroke-width: 2; stroke-linecap: round; fill: none; }
.brand__mark .dot { fill: #ffb347; }
.topbar__nav { display: flex; gap: 14px; margin-left: auto; }
.topbar__nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.topbar__nav a:hover { color: var(--ink); }
.topbar__nav a { white-space: nowrap; }
.iconbtn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 36px; height: 36px; display: inline-grid; place-items: center; color: var(--ink); cursor: pointer; flex: none; }
@media (max-width: 860px) { .topbar__nav { display: none; } .iconbtn { margin-left: auto; } }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.theme-icon--dark { display: none; }
:root[data-theme="dark"] .theme-icon--light { display: none; }
:root[data-theme="dark"] .theme-icon--dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon--light { display: none; }
  :root:not([data-theme="light"]) .theme-icon--dark { display: block; }
}

.hero { padding: 40px 0 8px; }
.kicker { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; color: var(--muted); margin: 0 0 8px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); line-height: 1.15; margin: 0 0 12px; }
.hero h1 span { color: var(--accent); }
.lede { max-width: 72ch; margin: 0 0 10px; }
.stack { color: var(--muted); font-size: 0.9rem; margin: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin: 24px 0; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 12px; font-size: 1.25rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chip { background: var(--chip); border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 0.9rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.askform textarea { width: 100%; resize: vertical; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; }
.askform__row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-top: 10px; }
.select { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); flex: 1 1 260px; min-width: 0; }
/* width 100%: a select is otherwise as wide as its longest document title */
.select select { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; }
.btn { border: 1px solid var(--line); border-radius: 10px; padding: 10px 18px; font: inherit; cursor: pointer; background: var(--panel); color: var(--ink); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn[disabled] { opacity: 0.6; cursor: wait; }
.status { min-height: 1.4em; margin: 10px 0 0; color: var(--muted); }
.status[data-kind="error"] { color: var(--bad); }

.result { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
.result__head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; border: 1px solid currentColor; }
.badge[data-status="answered"] { color: var(--ok); }
.badge[data-status="insufficient_context"] { color: var(--warn); }
.badge[data-status="refused"] { color: var(--bad); }
.result__meta { color: var(--muted); font-size: 0.88rem; }
.result__answer { font-size: 1.08rem; margin: 12px 0; }
.citations h3 { font-size: 0.95rem; margin: 12px 0 6px; color: var(--muted); }
.citations ol { margin: 0; padding-left: 20px; }
.citations li { margin: 8px 0; }
.citations blockquote { margin: 4px 0 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--chip); border-radius: 0 8px 8px 0; }
.citations .where { color: var(--muted); font-size: 0.88rem; }
.raw { margin-top: 16px; }
#rules { margin-top: 10px; }
.raw summary { cursor: pointer; color: var(--muted); }

.docs { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.docs li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.docs .doc__title { font-weight: 600; }
.docs .doc__meta { color: var(--muted); font-size: 0.88rem; white-space: nowrap; }
.steps { padding-left: 20px; }
.steps li { margin: 8px 0; }
.foot { border-top: 1px solid var(--line); margin-top: 32px; padding: 18px 0 40px; color: var(--muted); font-size: 0.9rem; }
.foot__row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.trace h3 { font-size: 0.95rem; margin: 16px 0 6px; color: var(--muted); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.preview { color: var(--muted); font-size: 0.86rem; margin-top: 2px; }
.small { font-size: 0.85rem; }
