:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-sunken: #f3f1ed;
  --border: #e2ded7;
  --border-strong: #cdc7bd;
  --text: #1c1a17;
  --text-muted: #5f5a52;
  --text-faint: #8b847a;
  --accent: #0f5f55;
  --accent-soft: #e4efec;
  --danger: #9a2f24;
  --danger-soft: #f8e9e7;
  --warn: #8a5a09;
  --warn-soft: #fbf0db;
  --ok: #1f6038;
  --ok-soft: #e6f1e9;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --radius: 10px;
  --maxw: 54rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1c1b19;
    --surface-sunken: #232120;
    --border: #322f2c;
    --border-strong: #474340;
    --text: #ece8e2;
    --text-muted: #a8a29a;
    --text-faint: #807a72;
    --accent: #5fc4b0;
    --accent-soft: #16302c;
    --danger: #e8837a;
    --danger-soft: #341f1d;
    --warn: #d9a84a;
    --warn-soft: #302512;
    --ok: #71c48d;
    --ok-soft: #17301f;
  }
}

:root[data-theme="dark"] {
  --bg: #141312;
  --surface: #1c1b19;
  --surface-sunken: #232120;
  --border: #322f2c;
  --border-strong: #474340;
  --text: #ece8e2;
  --text-muted: #a8a29a;
  --text-faint: #807a72;
  --accent: #5fc4b0;
  --accent-soft: #16302c;
  --danger: #e8837a;
  --danger-soft: #341f1d;
  --warn: #d9a84a;
  --warn-soft: #302512;
  --ok: #71c48d;
  --ok-soft: #17301f;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ---------- masthead ---------- */

.masthead {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 2.5rem 0 2rem;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 0.9rem;
}

.masthead h1 {
  font-family: var(--serif);
  font-size: clamp(1.85rem, 5vw, 2.7rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.standfirst {
  font-size: 1.08rem;
  color: var(--text-muted);
  margin: 0;
  max-width: 44rem;
}

.masthead-meta {
  margin-top: 1.5rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
}

.crumbs {
  font-family: var(--mono);
  font-size: 0.78rem;
  margin-bottom: 1.4rem;
}
.crumbs a { color: var(--text-faint); }

/* ---------- typography ---------- */

main { padding: 3rem 0 4rem; }

h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 3.5rem 0 1rem;
  font-weight: 600;
  scroll-margin-top: 1.5rem;
}

h3 {
  font-size: 1.07rem;
  margin: 2.2rem 0 0.6rem;
  font-weight: 650;
  letter-spacing: -0.005em;
}

h4 {
  font-size: 0.8rem;
  font-family: var(--mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 1.5rem 0 0.5rem;
  font-weight: 500;
}

p { margin: 0 0 1.05rem; }

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

strong { font-weight: 650; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

pre {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 0 0 1.2rem;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }

ul, ol { margin: 0 0 1.1rem; padding-left: 1.3rem; }
li { margin-bottom: 0.45rem; }

hr { border: 0; border-top: 1px solid var(--border); margin: 3rem 0; }

.lede { font-size: 1.05rem; color: var(--text-muted); }

/* ---------- finding blocks ---------- */

.finding {
  border-top: 1px solid var(--border);
  padding-top: 1.6rem;
  margin-top: 2.6rem;
}

.finding-num {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--accent);
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 0.4rem;
}

.finding > h2 { margin-top: 0.1rem; }

.gap {
  background: var(--surface-sunken);
  border-left: 2px solid var(--border-strong);
  border-radius: 0 6px 6px 0;
  padding: 0.85rem 1.1rem;
  margin: 1.2rem 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.gap b {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

/* ---------- tool panels ---------- */

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.6rem 0 1.4rem;
}

.tool-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tool-title {
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.85rem 1rem;
  margin-bottom: 1.1rem;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }

.field label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.field input[type="number"], .field input[type="text"], .field select {
  font: inherit;
  font-size: 0.92rem;
  font-family: var(--mono);
  padding: 0.42rem 0.55rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  width: 100%;
  min-width: 0;
}
.field input:focus-visible, .field select:focus-visible, .toggle input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toggles { display: flex; flex-direction: column; gap: 0.55rem; margin-bottom: 1.1rem; }

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.45;
}
.toggle input { margin: 0.25rem 0 0; flex: none; accent-color: var(--accent); }
.toggle span small { display: block; color: var(--text-faint); font-size: 0.8rem; }

/* readout */

.readout {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.metric { min-width: 0; }
.metric .k {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: block;
  margin-bottom: 0.15rem;
}
.metric .v {
  font-family: var(--mono);
  font-size: 1.32rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.metric .v.big { font-size: 1.6rem; }
.metric .n { font-size: 0.76rem; color: var(--text-faint); display: block; }

.verdict {
  font-size: 0.93rem;
  border-radius: 7px;
  padding: 0.7rem 0.9rem;
  border: 1px solid;
}
.verdict.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--text); }
.verdict.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.verdict.bad { background: var(--danger-soft); border-color: var(--danger); color: var(--text); }
.verdict b { display: block; margin-bottom: 0.15rem; }
.verdict ul { margin: 0.5rem 0 0; padding-left: 1.2rem; }
.verdict li { margin-bottom: 0.3rem; font-size: 0.9rem; }

.chart-wrap { margin: 0.4rem 0 0.2rem; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-caption { font-size: 0.8rem; color: var(--text-faint); margin: 0.5rem 0 0; }

/* ---------- misc ---------- */

.pill-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0 0 1.3rem; }
.pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  color: var(--text-muted);
  background: var(--surface);
  text-decoration: none;
}
a.pill:hover { border-color: var(--accent); color: var(--accent); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0.9rem; margin: 1.5rem 0 1rem; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: inherit;
}
.card:hover { border-color: var(--accent); }
.card .t { font-weight: 650; font-size: 0.97rem; margin-bottom: 0.25rem; display: block; }
.card .d { font-size: 0.85rem; color: var(--text-muted); }

.note {
  font-size: 0.88rem;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 0.9rem 1.05rem;
  margin: 1.5rem 0;
  background: var(--surface);
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 0 0 1.3rem; display: block; overflow-x: auto; }
th, td { text-align: left; padding: 0.5rem 0.7rem 0.5rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); font-weight: 500; }
td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

.toc { font-size: 0.93rem; margin: 1.8rem 0 0; padding-left: 1.2rem; }
.toc li { margin-bottom: 0.3rem; }

footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0 3rem;
  font-size: 0.86rem;
  color: var(--text-faint);
  background: var(--surface);
}
footer a { color: var(--text-muted); }
footer p { margin: 0 0 0.6rem; }

.skip {
  position: absolute; left: -9999px;
}
.skip:focus { left: 1rem; top: 1rem; position: fixed; background: var(--surface); padding: 0.6rem 1rem; border: 1px solid var(--accent); border-radius: 6px; z-index: 10; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .tool { padding: 1rem; }
  .metric .v { font-size: 1.15rem; }
  .metric .v.big { font-size: 1.35rem; }
}
