:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #0f172a;
  --muted: #5b6475;
  --border: #e2e7ef;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --accent-text: #1d4ed8;
  --good: #15803d;
  --warn: #b45309;
  --bad: #dc2626;
  --code-bg: #0d1424;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 24px rgba(15, 23, 42, .06);
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1c;
    --surface: #111827;
    --surface-2: #172033;
    --text: #e7ebf3;
    --muted: #97a1b5;
    --border: #243049;
    --accent: #5b8def;
    --accent-soft: #1a2a4d;
    --accent-text: #9dbcff;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --code-bg: #0b1120;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0f1c; --surface: #111827; --surface-2: #172033; --text: #e7ebf3; --muted: #97a1b5;
  --border: #243049; --accent: #5b8def; --accent-soft: #1a2a4d; --accent-text: #9dbcff;
  --good: #4ade80; --warn: #fbbf24; --bad: #f87171; --code-bg: #0b1120; color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd { font-family: var(--mono); font-size: .88em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 .35em; background: var(--surface); }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 600 14px var(--sans); cursor: pointer; text-decoration: none !important; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-small { padding: 5px 12px; font-size: 13px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; font-weight: 500; font-size: 13px; }
.btn-ghost:hover { color: var(--accent-text); border-color: transparent; }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 20; backdrop-filter: saturate(1.4) blur(10px);
  background: color-mix(in srgb, var(--bg) 82%, transparent); border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 12px; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 12px; }
.nav-links { display: flex; align-items: center; gap: 18px; }
.nav-links a:not(.btn) { color: var(--muted); font-weight: 500; font-size: 14px; }
.nav-links a:not(.btn):hover { color: var(--text); text-decoration: none; }

/* ---------- hero ---------- */
.hero { padding: 64px 0 48px; background:
  radial-gradient(800px 380px at 85% -10%, var(--accent-soft), transparent 70%); }
.hero-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 40px; align-items: center; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 700; color: var(--accent-text); margin: 0 0 12px; }
h1 { font-size: clamp(30px, 4.4vw, 46px); line-height: 1.12; letter-spacing: -.02em; margin: 0 0 16px; font-weight: 800; }
.hl { background: linear-gradient(90deg, var(--accent), #0ea5e9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { font-size: 18px; color: var(--muted); margin: 0 0 8px; max-width: 560px; }
.author { margin: 0 0 24px; color: var(--muted); }
.author strong { color: var(--text); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.hero-card-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.dot.live.ok { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 20%, transparent); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat span { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.hero-note { font-size: 13px; color: var(--muted); margin: 14px 0 0; }

/* ---------- sections ---------- */
.section { padding: 56px 0; }
.section.alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.section-title { font-size: 26px; letter-spacing: -.01em; margin: 0 0 6px; }
.section-sub { color: var(--muted); margin: 0 0 24px; }

.findings { margin: 16px 0 0; padding: 0; list-style: none; counter-reset: f; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.findings li { counter-increment: f; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 16px 16px 52px; position: relative; box-shadow: var(--shadow); }
.findings li::before { content: counter(f); position: absolute; left: 16px; top: 14px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; }

.brief-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 32px; align-items: start; }
.prose p { margin: 0 0 14px; }
.stakeholders { display: grid; gap: 10px; }
.stakeholder { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stakeholder .ico { font-size: 20px; line-height: 1.2; }
.stakeholder b { display: block; font-size: 14px; }
.stakeholder span { font-size: 13px; color: var(--muted); }

.data-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 20px; align-items: start; }
.erd-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow-x: auto; min-height: 200px; }
.erd-card svg { max-width: 100%; height: auto; }
.table-list { display: grid; gap: 8px; }
.tbl { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; background: var(--bg); }
.tbl-head { display: flex; justify-content: space-between; gap: 8px; }
.tbl-head code { background: none; padding: 0; font-weight: 600; color: var(--text); }
.tbl-head span { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.tbl p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- filters + cards ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px;
  padding: 6px 14px; font: 500 13px var(--sans); cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 4px; }

.cards { display: grid; gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.featured { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.card-head { padding: 20px 22px 0; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.qid { font-family: var(--mono); font-weight: 600; color: var(--accent-text); background: var(--accent-soft); padding: 1px 8px; border-radius: 6px; }
.lvl { letter-spacing: 1px; color: var(--accent); }
.lvl i { color: var(--border); font-style: normal; }
.badge-feat { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); padding: 1px 8px; border-radius: 6px; font-weight: 600; }
.card h3 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.card .ask { margin: 8px 0 2px; font-weight: 500; }
.card .why { margin: 0; color: var(--muted); font-size: 14px; }
.concepts { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.concepts span { font-family: var(--mono); font-size: 11.5px; border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; color: var(--muted); }
.rules { margin: 10px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.rules li { margin: 1px 0; }
details.rules-box { margin-top: 10px; }
details.rules-box summary { cursor: pointer; font-size: 13px; color: var(--muted); }

.card-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0; margin-top: 18px; border-top: 1px solid var(--border); }
.card-body.stack { grid-template-columns: minmax(0, 1fr); }
.pane { min-width: 0; padding: 16px 22px 20px; }
.pane + .pane { border-left: 1px solid var(--border); }
.card-body.stack .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
.pane-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }

.code {
  position: relative; background: var(--code-bg); border-radius: 10px; overflow: hidden;
}
.code pre { margin: 0; padding: 14px 16px; overflow: auto; font: 12.5px/1.6 var(--mono); max-height: 360px; }
.code.collapsed pre { max-height: 230px; overflow: hidden; }
.code.collapsed::after { content: ""; position: absolute; inset: auto 0 0 0; height: 60px; background: linear-gradient(transparent, var(--code-bg)); pointer-events: none; }
.code pre code.hljs { background: none; padding: 0; }
.code-actions { display: flex; gap: 4px; }

.chart-box { position: relative; height: 260px; margin-bottom: 14px; }
.insight {
  margin: 0 22px 20px; padding: 12px 16px; border-radius: 10px; background: var(--accent-soft);
  border-left: 3px solid var(--accent); font-size: 14px;
}
.insight b { color: var(--accent-text); }
.draft-note { margin: 16px 22px 20px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); font-size: 14px; }

/* ---------- result tables ---------- */
.result { min-width: 0; }
.table-scroll { overflow: auto; max-height: 330px; border: 1px solid var(--border); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-family: var(--mono); font-size: 11.5px; color: var(--muted); z-index: 1; }
table.data td.num { text-align: right; font-family: var(--mono); font-size: 12px; }
table.data th.num { text-align: right; }
table.data td.null { color: var(--muted); font-style: italic; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
.result-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error { color: var(--bad); font-family: var(--mono); font-size: 13px; background: color-mix(in srgb, var(--bad) 10%, transparent); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; }

/* heatmap */
table.heat { border-collapse: separate; border-spacing: 2px; font-size: 11.5px; font-variant-numeric: tabular-nums; width: 100%; }
table.heat th { font-weight: 600; color: var(--muted); font-family: var(--mono); font-size: 11px; padding: 2px 4px; white-space: nowrap; }
table.heat td { text-align: center; padding: 5px 2px; border-radius: 4px; font-family: var(--mono); min-width: 34px; }
.heat-scroll { overflow-x: auto; margin-bottom: 14px; }

/* ---------- playground ---------- */
.pg-grid { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; }
.pg-schema { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; max-height: 620px; overflow: auto; }
.pg-schema h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pg-schema details { margin-bottom: 4px; }
.pg-schema summary { cursor: pointer; font-family: var(--mono); font-size: 13px; font-weight: 600; padding: 3px 0; }
.pg-schema ul { list-style: none; margin: 2px 0 8px; padding-left: 14px; }
.pg-schema li { font-family: var(--mono); font-size: 12px; color: var(--muted); cursor: pointer; padding: 1px 0; display: flex; justify-content: space-between; gap: 6px; }
.pg-schema li:hover { color: var(--accent-text); }
.pg-schema li em { font-style: normal; opacity: .6; font-size: 10.5px; }
.pg-main { min-width: 0; display: grid; gap: 10px; }
.pg-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pg-toolbar select { font: 500 13px var(--sans); padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); max-width: 100%; }
#pg-editor {
  width: 100%; min-height: 220px; resize: vertical; padding: 14px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--code-bg); color: #e6edf3; font: 13px/1.6 var(--mono); tab-size: 4;
}
#pg-editor:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- footer ---------- */
.footer { padding: 32px 0 40px; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.foot-links { display: flex; gap: 8px; flex-wrap: wrap; }
.foot-note { margin-top: 18px; }

.fatal { position: fixed; inset: auto 16px 16px 16px; max-width: 640px; margin: 0 auto; background: var(--surface); border: 1px solid var(--bad); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); z-index: 50; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .hero-grid, .brief-grid, .data-grid { grid-template-columns: 1fr; }
  .card-body { grid-template-columns: minmax(0, 1fr); }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .pg-grid { grid-template-columns: minmax(0, 1fr); }
  .pg-schema { max-height: 220px; }
}
@media (max-width: 640px) {
  .nav-links a:not(.btn) { display: none; }
  .hero { padding: 40px 0 32px; }
  .section { padding: 40px 0; }
  .card-head, .pane { padding-left: 16px; padding-right: 16px; }
  .insight, .draft-note { margin-left: 16px; margin-right: 16px; }
}
