/* --- tokens --------------------------------------------------------------- */
:root {
  --bg: #f7f4ee;
  --bg-elevated: #fffdf9;
  --bg-sunk: #efe9de;
  --ink: #1d2033;
  --ink-soft: #4c5068;
  --ink-faint: #7c8098;
  --line: #e2dad0;
  --line-strong: #cec3b4;
  --accent: #8a6d2f;
  --accent-soft: #f0e4c8;
  --accent-ink: #6d5522;
  --sky-1: #dfe9f5;
  --sky-2: #f6efe2;
  --chart-alt: #6f88b4;
  --good: #3f7d5a;
  --warn: #a2662b;
  --bad: #a04141;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(29, 32, 51, .06), 0 8px 24px -12px rgba(29, 32, 51, .18);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --measure: 68ch;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141f;
    --bg-elevated: #1a1d2c;
    --bg-sunk: #0d0f18;
    --ink: #eceaf3;
    --ink-soft: #b3b1c4;
    --ink-faint: #83819a;
    --line: #2b2f42;
    --line-strong: #3d4256;
    --accent: #d9bd77;
    --accent-soft: #33302a;
    --accent-ink: #eed9a2;
    --sky-1: #1b2436;
    --sky-2: #221f2c;
    --chart-alt: #7c93c4;
    --good: #6fbc92;
    --warn: #d59a5b;
    --bad: #d97b7b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  --bg: #12141f;
  --bg-elevated: #1a1d2c;
  --bg-sunk: #0d0f18;
  --ink: #eceaf3;
  --ink-soft: #b3b1c4;
  --ink-faint: #83819a;
  --line: #2b2f42;
  --line-strong: #3d4256;
  --accent: #d9bd77;
  --accent-soft: #33302a;
  --accent-ink: #eed9a2;
  --sky-1: #1b2436;
  --sky-2: #221f2c;
  --chart-alt: #7c93c4;
  --good: #6fbc92;
  --warn: #d59a5b;
  --bad: #d97b7b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

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

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

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 .4em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.85rem); margin: 0 0 .5em; }
h3 { font-size: 1.15rem; margin: 0 0 .4em; }
p { margin: 0 0 1em; }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--ink); }

.wrap { width: min(100% - 2.5rem, 1080px); margin-inline: auto; }
.narrow { max-width: var(--measure); }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: .875rem; }
.center { text-align: center; }

/* --- chrome --------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 0; flex-wrap: wrap;
}
.brand {
  font-family: var(--serif); font-size: 1.05rem; font-weight: 600;
  color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: .5rem;
}
.brand .mark { font-size: 1.2rem; }
.nav { display: flex; gap: 1.25rem; align-items: center; }
.nav a { color: var(--ink-soft); text-decoration: none; font-size: .95rem; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.nav a[aria-current="page"] { font-weight: 600; }

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 5rem; padding: 2rem 0 3rem;
  color: var(--ink-faint); font-size: .875rem;
}
.site-footer .wrap { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* --- hero ----------------------------------------------------------------- */
.hero {
  background: linear-gradient(170deg, var(--sky-1), var(--sky-2) 70%, var(--bg));
  border-bottom: 1px solid var(--line);
  padding: clamp(3rem, 9vw, 6rem) 0 clamp(2.5rem, 7vw, 4.5rem);
}
.hero .eyebrow {
  text-transform: uppercase; letter-spacing: .14em; font-size: .74rem;
  color: var(--accent-ink); font-weight: 700; margin-bottom: 1rem;
}
.hero p.lead { font-size: 1.15rem; color: var(--ink-soft); max-width: 56ch; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .75rem 1.4rem; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .98rem;
  cursor: pointer; text-decoration: none; transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--bg-elevated); }
.btn-primary:hover { background: var(--accent-ink); color: #fff; }
.btn-ghost { border-color: var(--line-strong); color: var(--ink); background: transparent; }
.btn-ghost:hover { background: var(--bg-elevated); color: var(--ink); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.75rem; }

/* --- cards / grid --------------------------------------------------------- */
main { padding-bottom: 2rem; }
section.block { padding: clamp(2rem, 5vw, 3.25rem) 0; }

.card {
  background: var(--bg-elevated); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1.25rem; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
/* Six headline stats sit better as 3x2 than 4+2. */
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(min(290px, 100%), 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(430px, 100%), 1fr)); }

.stat { text-align: left; }
.stat .value { font-family: var(--serif); font-size: clamp(2.1rem, 5vw, 2.9rem); line-height: 1; }
.stat .value small { font-size: .42em; color: var(--ink-faint); font-family: var(--sans); margin-left: .2em; }
.stat .label { font-size: .82rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); margin-top: .6rem; font-weight: 600; }
.stat .sub { font-size: .85rem; color: var(--ink-soft); margin-top: .35rem; }

/* --- form ----------------------------------------------------------------- */
.progress-rail { position: sticky; top: 57px; z-index: 15; background: var(--bg); border-bottom: 1px solid var(--line); }
.progress-rail .wrap { padding: .6rem 0; display: flex; align-items: center; gap: 1rem; }
.progress-track { flex: 1; height: 6px; background: var(--bg-sunk); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.progress-label { font-size: .82rem; color: var(--ink-soft); white-space: nowrap; }

fieldset.section {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-elevated); padding: clamp(1.25rem, 3vw, 2rem);
  margin: 0 0 1.75rem; box-shadow: var(--shadow);
}
fieldset.section > legend {
  font-family: var(--serif); font-size: 1.45rem; font-weight: 600;
  padding: 0 .5rem; margin-left: -.5rem;
}
.section-blurb { color: var(--ink-soft); margin: .25rem 0 1.75rem; font-size: .95rem; }

.question { padding: 1.25rem 0; border-top: 1px solid var(--line); }
.question:first-of-type { border-top: none; padding-top: .25rem; }
.question .prompt { font-weight: 600; display: block; margin-bottom: .2rem; }
.question .help { color: var(--ink-soft); font-size: .9rem; margin-bottom: .75rem; }
.required-dot { color: var(--bad); margin-left: .25rem; }

.scale { margin-top: .9rem; }
.scale-options { display: flex; gap: .4rem; flex-wrap: wrap; }
.scale-options label {
  flex: 1 1 0; min-width: 44px; text-align: center; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: .6rem .25rem; background: var(--bg); font-variant-numeric: tabular-nums;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.scale-options label:hover { border-color: var(--accent); }
.scale-options input { position: absolute; opacity: 0; width: 0; height: 0; }
.scale-options input:checked + span { color: var(--bg-elevated); }
.scale-options label:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--bg-elevated); font-weight: 600; }
.scale-options label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.scale-ends { display: flex; justify-content: space-between; font-size: .8rem; color: var(--ink-faint); margin-top: .45rem; }

.choices { display: grid; gap: .5rem; margin-top: .75rem; }
.choices label {
  display: flex; align-items: flex-start; gap: .65rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .65rem .85rem; background: var(--bg);
  transition: border-color .12s ease, background .12s ease;
}
.choices label:hover { border-color: var(--line-strong); }
.choices label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choices label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choices input { margin-top: .35rem; accent-color: var(--accent-ink); }

textarea {
  width: 100%; min-height: 100px; resize: vertical; margin-top: .6rem;
  font: inherit; font-size: .97rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: .7rem .85rem;
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.char-count { font-size: .78rem; color: var(--ink-faint); text-align: right; margin-top: .25rem; }

.matrix { margin-top: .5rem; }
.matrix-row {
  display: grid; grid-template-columns: minmax(150px, 1fr) auto;
  gap: .5rem 1rem; align-items: center; padding: .55rem 0;
  border-top: 1px solid var(--line);
}
.matrix-row:first-child { border-top: none; }
.matrix-row .matrix-label { font-size: .97rem; }
.matrix-row .scale-options { gap: .35rem; }
.matrix-row .scale-options label { min-width: 40px; padding: .4rem .2rem; font-size: .88rem; }
@media (max-width: 620px) {
  .matrix-row { grid-template-columns: 1fr; }
  .matrix-row .scale-options label { flex: 1 1 0; }
}

.optional-flag {
  display: inline-block; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-ink); background: var(--accent-soft);
  border-radius: 99px; padding: .15rem .55rem; margin-left: .5rem; font-weight: 700; vertical-align: middle;
}

.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.form-error {
  border: 1px solid var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--bg-elevated));
  color: var(--ink); border-radius: var(--radius-sm); padding: .85rem 1rem; margin-bottom: 1rem;
}
.form-error ul { margin: .5rem 0 0; padding-left: 1.2rem; }

/* --- dashboard ------------------------------------------------------------ */
.chart-card h3 { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.chart-card h3 .n { font-family: var(--sans); font-size: .78rem; font-weight: 500; color: var(--ink-faint); white-space: nowrap; }
.chart-scroll { overflow-x: auto; }
.chart-scroll svg { display: block; }

.controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.25rem; }
.control { display: flex; flex-direction: column; gap: .3rem; }
.control label { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-faint); font-weight: 700; }
select {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--bg-elevated);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: .55rem .8rem; min-width: 220px;
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--ink-soft); margin-top: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.note {
  border-left: 3px solid var(--accent); background: var(--bg-sunk);
  padding: .85rem 1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .9rem; color: var(--ink-soft);
}

.empty-state { text-align: center; padding: 3.5rem 1rem; color: var(--ink-soft); }
.empty-state .mark { font-size: 2.5rem; display: block; margin-bottom: .75rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
table.data th { font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

.skip-link {
  position: absolute; left: -9999px; background: var(--ink); color: var(--bg);
  padding: .6rem 1rem; border-radius: 0 0 var(--radius-sm) 0; z-index: 50;
}
.skip-link:focus { left: 0; top: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* --- utilities that exist so no element needs a style attribute ----------- */
.stack-lg { margin: 2rem 0; }
.mb-card { margin-bottom: 1.25rem; }
.mt-card { margin-top: 1.25rem; }
.mt-lg { margin-top: 2rem; }
.tight { margin-bottom: .25rem; }
.small { font-size: .95rem; }
.lead-center { margin-inline: auto; }
.btn-row.center-row { justify-content: center; }

.q-group { border: 0; margin: 0; padding: 0; min-width: 0; }
.q-group > legend { padding: 0; }
.matrix-group { display: contents; }

/* Charts are drawn at a width the script measured from the container, so they
   only need to stay inside it. */
.chart-svg { max-width: 100%; height: auto; }

td.delta-pos { color: var(--good); }
td.delta-neg { color: var(--bad); }

/* The progress bar is driven by a custom property set on the rail, so the
   fill needs no style attribute of its own. */
.progress-fill { width: calc(var(--progress, 0) * 1%); }

#crosstab-table { overflow-x: auto; }

/* Long option lists (countries) render as a dropdown rather than 237 radios. */
.q-select {
  width: 100%;
  max-width: 30rem;
  margin-top: .75rem;
  font: inherit;
  font-size: .97rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .65rem .8rem;
}
.q-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
