/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;
  --page: #ffffff;
  --raised: #ffffff;
  --code-bg: #f4f6f9;
  --ink: #16233a;            /* headings */
  --text: #2c3548;           /* body copy */
  --text-secondary: #4c566a;
  --muted: #646d7f;
  --hairline: #e2e6ec;
  --grid: #e8ebf0;
  --baseline: #c3c9d3;
  --accent: #2a78d6;         /* the bar where the risk is */
  --accent-hover: #1c5cab;
  --context: #b3b9c4;        /* every other bar */
  --context-hover: #9aa2b0;
  --link: #1c5cab;

  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #11151c;
    --raised: #1a2029;
    --code-bg: #171c24;
    --ink: #eef1f6;
    --text: #d5dae2;
    --text-secondary: #b9c0cc;
    --muted: #8b94a4;
    --hairline: #262d39;
    --grid: #222936;
    --baseline: #3a4352;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --context: #4b5566;
    --context-hover: #5d6879;
    --link: #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #11151c;
  --raised: #1a2029;
  --code-bg: #171c24;
  --ink: #eef1f6;
  --text: #d5dae2;
  --text-secondary: #b9c0cc;
  --muted: #8b94a4;
  --hairline: #262d39;
  --grid: #222936;
  --baseline: #3a4352;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --context: #4b5566;
  --context-hover: #5d6879;
  --link: #6da7ec;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

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

h1, h2, h3 { color: var(--ink); margin: 0; font-weight: 600; }
p { margin: 0 0 1em; }
a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
strong { font-weight: 600; color: var(--ink); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 56px; }
.brand { color: var(--ink); font-weight: 600; text-decoration: none; font-size: 15px; }
nav { display: flex; align-items: center; gap: 20px; font-size: 15px; }
nav a { color: var(--text-secondary); text-decoration: none; }
nav a:hover { color: var(--ink); }

.lang-switch { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--hairline); border-radius: 6px; }
.lang-switch button {
  font: inherit; font-size: 13px; font-weight: 500; line-height: 1.4;
  color: var(--text-secondary); background: none; border: 0; border-radius: 4px;
  padding: 3px 8px; cursor: pointer;
}
.lang-switch button:hover { color: var(--ink); }
.lang-switch button[aria-pressed="true"] { background: var(--ink); color: var(--page); }

/* ---------- Hero ---------- */
.hero { padding-top: 80px; padding-bottom: 56px; }
.hero h1 {
  font-size: clamp(34px, 5.4vw, 56px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  max-width: 19ch;
}
.lede { font-size: 20px; line-height: 1.5; color: var(--text-secondary); max-width: 46ch; margin-top: 24px; }
.hero-links { display: flex; flex-wrap: wrap; gap: 24px; font-size: 16px; margin-bottom: 48px; }

.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr);
  margin: 0; border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline);
}
.kpi { padding: 20px 20px 20px 0; }
.kpi + .kpi { padding-left: 20px; border-left: 1px solid var(--hairline); }
.kpi dt { font-size: 14px; color: var(--muted); }
.kpi dd { margin: 0; }
.kpi .kpi-value { font-size: 32px; font-weight: 600; color: var(--ink); line-height: 1.25; margin-top: 4px; }
.kpi-note { font-size: 14px; color: var(--text-secondary); }

/* ---------- Finding sections ---------- */
.finding {
  display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 32px;
  padding-top: 64px; padding-bottom: 64px;
  border-top: 1px solid var(--hairline);
}
#findings > .finding:first-child { border-top: 0; }
.finding-tag { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.finding-tag span { display: block; }
.finding-tag span + span { color: var(--text-secondary); font-weight: 500; }
.finding-body > p { max-width: 64ch; }
.finding h2 {
  font-size: clamp(24px, 3vw, 31px);
  line-height: 1.2;
  letter-spacing: -0.01em;
  max-width: 28ch;
  margin-bottom: 16px;
}

/* ---------- Figures ---------- */
figure { margin: 0; min-width: 0; }
figcaption { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 12px; }
.figure-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 32px; align-items: start; }
.figure-wide { margin-top: 32px; max-width: 720px; }
.chart { position: relative; width: 100%; }

/* ---------- View SQL panels ---------- */
.query { margin-top: 16px; font-size: 14px; }
.query summary {
  cursor: pointer; color: var(--link); width: fit-content;
  list-style-position: inside; padding: 4px 0;
}
.query[open] summary { margin-bottom: 8px; }
.query-file { color: var(--muted); margin: 0 0 8px; }
.query pre {
  margin: 0 0 12px; padding: 14px 16px; overflow-x: auto;
  background: var(--code-bg); border: 1px solid var(--hairline); border-radius: 6px;
  font-family: var(--mono); font-size: 13px; line-height: 1.55; color: var(--text);
  tab-size: 4;
}
.query-table { overflow-x: auto; }
.query table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.query th, .query td { padding: 6px 12px 6px 0; text-align: left; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
.query th { color: var(--muted); font-weight: 500; }

/* ---------- High-risk segment ---------- */
.finding .segment-headline { font-size: clamp(30px, 4.4vw, 46px); max-width: 20ch; letter-spacing: -0.02em; }
.shares { margin-top: 32px; max-width: 760px; display: grid; gap: 18px; }
.share-row { display: grid; grid-template-columns: 220px 1fr 56px; align-items: center; gap: 16px; }
.share-label { font-size: 15px; color: var(--text-secondary); }
.share-track { position: relative; height: 24px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.share-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); border-radius: 0 4px 4px 0; }
.share-value { font-size: 20px; font-weight: 600; color: var(--ink); text-align: right; }

/* ---------- Actions table ---------- */
.table-wrap { margin-top: 28px; }
.actions-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.actions-table th {
  font-size: 13px; font-weight: 500; color: var(--muted); text-align: left;
  padding: 0 12px 10px 0; border-bottom: 1px solid var(--baseline); vertical-align: bottom;
}
.actions-table td { padding: 16px 12px 16px 0; border-bottom: 1px solid var(--hairline); vertical-align: top; }
.actions-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions-table th.num { white-space: normal; }
.actions-table td:last-child { font-weight: 600; color: var(--ink); }
.actions-table td:first-child { min-width: 260px; }
.action-name { font-weight: 600; color: var(--ink); display: block; }
.action-target { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }
.note { margin-top: 28px; max-width: 64ch; font-size: 15px; color: var(--text-secondary); }

/* ---------- Method ---------- */
.steps { padding-left: 1.3em; margin: 24px 0 8px; max-width: 64ch; }
.steps li { margin-bottom: 10px; padding-left: 4px; }
.method-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; }
.method-grid h3 { font-size: 16px; margin-bottom: 8px; }
.method-grid ul { margin: 0; padding-left: 1.2em; font-size: 16px; }
.method-grid li { margin-bottom: 6px; }
.source { margin-top: 32px; font-size: 15px; color: var(--text-secondary); }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--hairline); padding: 28px 0 40px; font-size: 15px; color: var(--muted); }
.footer p { margin: 0; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px; }
.footer-links { display: flex; gap: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .finding { grid-template-columns: 1fr; gap: 12px; padding-top: 48px; padding-bottom: 48px; }
  .finding-tag span { display: inline; }
  .finding-tag span + span { margin-left: 8px; }
  .figure-pair, .method-grid { grid-template-columns: 1fr; gap: 36px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(3) { padding-left: 0; border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--hairline); }
}

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .hero { padding-top: 48px; }
  .kpi .kpi-value { font-size: 26px; }
  nav .nav-section { display: none; }
  nav { gap: 14px; }
  .share-row { grid-template-columns: 1fr 56px; gap: 6px 12px; }
  .share-label { grid-column: 1 / -1; }

  /* The actions table turns into stacked rows on phones. */
  .actions-table thead { display: none; }
  .actions-table, .actions-table tbody, .actions-table tr, .actions-table td { display: block; width: 100%; }
  .actions-table tr { border-bottom: 1px solid var(--hairline); padding: 12px 0; }
  .actions-table td { border: 0; padding: 4px 0; }
  .actions-table td.num { display: flex; justify-content: space-between; text-align: right; }
  .actions-table td.num::before { content: attr(data-label); color: var(--muted); font-weight: 400; }
}
