:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --ink: #1d1f22;
  --muted: #5d636b;
  --line: #e2ded5;
  --accent: #1f5c4a;
  --accent-soft: #e3efe9;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --code-bg: #f0ede6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --ink: #e8e6e1;
    --muted: #a0a6ad;
    --line: #2f3338;
    --accent: #7cc4a8;
    --accent-soft: #1f3330;
    --warn: #e8b85c;
    --warn-soft: #3a2f19;
    --code-bg: #23272c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --surface: #1d2024; --ink: #e8e6e1; --muted: #a0a6ad; --line: #2f3338;
  --accent: #7cc4a8; --accent-soft: #1f3330; --warn: #e8b85c; --warn-soft: #3a2f19; --code-bg: #23272c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 Inter, system-ui, sans-serif;
}
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
h1, h2, h3 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; line-height: 1.2; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: .3em 0 .4em; max-width: 18ch; }
h2 { font-size: 1.7rem; margin: 0 0 .5em; }
h3 { font-size: 1.2rem; margin: 2em 0 .6em; }
code, pre, textarea { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .85rem; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }

.hero { padding-top: 56px; padding-bottom: 24px; }
.eyebrow { color: var(--muted); font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; margin: 0; }
.lede { font-size: 1.15rem; max-width: 62ch; color: var(--ink); }
.toc { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 20px; font-size: .9rem; }
.toc a { text-decoration: none; border-bottom: 1px solid var(--line); }

section { padding: 40px 0; border-top: 1px solid var(--line); }
.note { color: var(--muted); max-width: 70ch; }
.loading { color: var(--muted); }
.error { color: #b3261e; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.card .num { font-family: "Source Serif 4", Georgia, serif; font-size: 2rem; font-weight: 600; color: var(--accent); line-height: 1.1; margin: 0 0 6px; }
.card p { margin: 0 0 8px; }
.card .src { font-size: .8rem; color: var(--muted); }
.card .kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.card h4 { margin: 0 0 6px; font-size: 1.05rem; }

.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters button, .presets button {
  font: inherit; font-size: .85rem; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.filters button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.presets button:hover, .filters button:hover { border-color: var(--accent); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.hyp { color: var(--muted); font-style: italic; min-width: 200px; }

.sqlpeek { margin-top: 8px; font-size: .85rem; }
.sqlpeek summary { cursor: pointer; color: var(--muted); }
pre { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; }

.calc { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.inputs { display: grid; gap: 12px; }
.inputs label { display: grid; gap: 4px; font-size: .9rem; font-weight: 500; }
.inputs input, .inputs select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); width: 100%;
}
.tag { font-size: .72rem; font-weight: 400; color: var(--muted); }
.tag.warn { color: var(--warn); background: var(--warn-soft); padding: 0 6px; border-radius: 4px; justify-self: start; }
.result { align-self: center; }
.result .big { font-family: "Source Serif 4", Georgia, serif; font-size: 2.6rem; font-weight: 600; color: var(--accent); margin: 0; }
.result .compare { background: var(--accent-soft); padding: 12px; border-radius: 8px; }

textarea { width: 100%; min-height: 150px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.row { display: flex; align-items: center; gap: 12px; margin: 10px 0 14px; }
button#run { font: inherit; font-weight: 600; padding: 8px 18px; border-radius: 8px; border: 0; background: var(--accent); color: var(--bg); cursor: pointer; }
.status { color: var(--muted); font-size: .85rem; }

.plan { padding-left: 1.2em; max-width: 72ch; }
.plan li { margin-bottom: 12px; }
.plan .wk { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.method { max-width: 72ch; }
.sources { font-size: .85rem; word-break: break-word; }
.foot { color: var(--muted); font-size: .85rem; padding-top: 24px; padding-bottom: 48px; border-top: 1px solid var(--line); }

@media (max-width: 720px) {
  .calc { grid-template-columns: 1fr; }
  .hero { padding-top: 32px; }
}
