:root {
  --serif: "Iowan Old Style", "Charter", "Source Serif Pro", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f6f4ef;
  --surface: #fffdf8;
  --surface-2: #efece4;
  --ink: #1d1c1a;
  --ink-2: #4d4a44;
  --ink-3: #7a766d;
  --rule: #dcd7cc;
  --rule-strong: #b9b2a3;
  --accent: #1f4e79;
  --focus: #1f6fc4;
  --ocean: #eef0ef;
  --border: #fffdf8;

  /* Diverging score scale: orange (weak) to blue (strong). Colour-blind safe;
     numbers and arrows always carry the same meaning. */
  --s1: #a8510a; --on-s1: #fff;
  --s2: #e3954b; --on-s2: #1d1c1a;
  --s3: #e4d7b4; --on-s3: #1d1c1a;
  --s4: #86acd6; --on-s4: #1d1c1a;
  --s5: #2a5a92; --on-s5: #fff;
  /* Trend has its own hues, so a declining 4 is never painted like a score of 1. */
  --t-up: #2f7d4f; --t-flat: #b3a878; --t-down: #9b3d8a;
  --none: #d6d3cc;
  --none-hatch: #c3bfb6;
  --dim: 0.22;
  --warn-bg: #fbeed2;
  --warn-ink: #7a4b00;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315;
    --surface: #1a1b1e;
    --surface-2: #232428;
    --ink: #ecebe7;
    --ink-2: #bdbab2;
    --ink-3: #8c8981;
    --rule: #2f3034;
    --rule-strong: #4a4b50;
    --accent: #8cb8e8;
    --focus: #6aa8ee;
    --ocean: #16171a;
    --border: #121315;
    --s1: #f0a35a; --on-s1: #121315;
    --s2: #9c6334; --on-s2: #ecebe7;
    --s3: #565042; --on-s3: #ecebe7;
    --s4: #3c6896; --on-s4: #ecebe7;
    --s5: #93c3f0; --on-s5: #121315;
    --t-up: #6fcf97; --t-flat: #7a7150; --t-down: #e08ad0;
    --none: #2b2d31;
    --none-hatch: #36383d;
    --dim: 0.25;
    --warn-bg: #3a2c12;
    --warn-ink: #f2c879;
  }
}
:root[data-theme="dark"] {
  --bg: #121315;
  --surface: #1a1b1e;
  --surface-2: #232428;
  --ink: #ecebe7;
  --ink-2: #bdbab2;
  --ink-3: #8c8981;
  --rule: #2f3034;
  --rule-strong: #4a4b50;
  --accent: #8cb8e8;
  --focus: #6aa8ee;
  --ocean: #16171a;
  --border: #121315;
  --s1: #f0a35a; --on-s1: #121315;
  --s2: #9c6334; --on-s2: #ecebe7;
  --s3: #565042; --on-s3: #ecebe7;
  --s4: #3c6896; --on-s4: #ecebe7;
  --s5: #93c3f0; --on-s5: #121315;
  --t-up: #6fcf97; --t-flat: #7a7150; --t-down: #e08ad0;
  --none: #2b2d31;
  --none-hatch: #36383d;
  --dim: 0.25;
  --warn-bg: #3a2c12;
  --warn-ink: #f2c879;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; outline: none; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.wordmark { font: 600 17px/1 var(--serif); color: var(--ink); text-decoration: none; white-space: nowrap; letter-spacing: -0.01em; }
.wordmark em { font-style: italic; font-weight: 400; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 4px; font-size: 14px; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); font-weight: 600; }
.search { position: relative; margin-left: auto; width: 240px; }
.search input {
  width: 100%; padding: 7px 28px 7px 10px; border: 1px solid var(--rule-strong);
  border-radius: 4px; background: var(--surface); font-size: 14px;
}
.search input::placeholder { color: var(--ink-3); }
.search-key { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px var(--mono); color: var(--ink-3); border: 1px solid var(--rule); border-radius: 3px; padding: 0 4px; pointer-events: none; }
.search input:focus + .search-key { display: none; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 4px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12); max-height: 340px; overflow: auto;
}
.search-results li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 3px; cursor: pointer; font-size: 14px; }
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--surface-2); }
.search-results .meta { color: var(--ink-3); font-size: 12px; white-space: nowrap; }
.search-results .empty { color: var(--ink-3); cursor: default; }
.theme-toggle { border: 1px solid var(--rule-strong); background: var(--surface); border-radius: 4px; width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); flex: none; }
.theme-toggle:hover { color: var(--ink); }
.demo-banner { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 16px; font-size: 13px; text-align: center; border-bottom: 1px solid var(--rule); }

/* ---------- Layout ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 32px 16px 64px; }
.page-narrow { max-width: 780px; }
.eyebrow { font: 600 11px/1.2 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.page-title { font: 600 32px/1.15 var(--serif); margin: 6px 0 8px; }
.lede { font: 18px/1.55 var(--serif); color: var(--ink-2); margin: 0 0 24px; max-width: 64ch; }
.section { margin-top: 40px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--ink); padding-bottom: 6px; margin-bottom: 16px; }
.section-head h2 { font: 600 13px/1.2 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; }
.section-head .kind { font-size: 12px; color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- Home / map ---------- */
.home-head { max-width: 1400px; margin: 0 auto; padding: 24px 16px 0; display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
.home-head h1 { font: 600 26px/1.15 var(--serif); }
.home-head p { margin: 4px 0 0; color: var(--ink-2); font: 16px/1.45 var(--serif); max-width: 60ch; }
.home-side { display: flex; align-items: center; gap: 12px 16px; }
.home-side .segmented button { padding: 6px 14px; }
.map-wrap[hidden], .list-view[hidden], .home-lists[hidden] { display: none; }
.coverage { font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.coverage strong { color: var(--ink); font-size: 15px; }
.controls { max-width: 1400px; margin: 16px auto 0; padding: 0 16px; display: grid; gap: 10px; }
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.control-label { font: 600 11px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); min-width: 52px; }
.select { appearance: none; padding: 6px 30px 6px 10px; border: 1px solid var(--rule-strong); border-radius: 4px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 10px center; font-size: 14px; cursor: pointer; }
.segmented { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 4px; overflow: hidden; }
.segmented button { border: 0; background: var(--surface); padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.segmented button + button { border-left: 1px solid var(--rule-strong); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--rule-strong); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; cursor: pointer; color: var(--ink-2); }
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.filters-toggle { display: none; align-items: center; gap: 6px; border: 1px solid var(--rule-strong); background: var(--surface); border-radius: 4px; padding: 6px 10px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.filters-toggle[aria-expanded="true"] { color: var(--ink); border-color: var(--ink-3); }
.filter-count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ink); color: var(--bg); font: 700 11px/1 var(--sans); }
.filter-count[hidden] { display: none; }
.clear-filters { border: 0; background: none; color: var(--accent); font-size: 13px; cursor: pointer; text-decoration: underline; padding: 4px; }

.map-wrap { position: relative; max-width: 1400px; margin: 14px auto 0; padding: 0 16px; }
.map-frame { position: relative; background: var(--ocean); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; touch-action: pan-y; }
.map-frame svg { display: block; width: 100%; height: auto; cursor: grab; }
.map-frame svg:active { cursor: grabbing; }
.country { stroke: var(--border); stroke-width: 0.5; vector-effect: non-scaling-stroke; transition: opacity 0.2s; }
.country.assessed { cursor: pointer; }
.country.unassessed { cursor: pointer; }
.country.dimmed { opacity: var(--dim); }
.country.hover { stroke: var(--ink); stroke-width: 1.5; }
.small-state { stroke: var(--ink-2); stroke-width: 0.75; vector-effect: non-scaling-stroke; cursor: pointer; }
.small-state.dimmed { opacity: var(--dim); }
.hit { fill: transparent; pointer-events: none; }
.touch-input .hit { pointer-events: all; cursor: pointer; }
@media (pointer: coarse) { .hit { pointer-events: all; } }
.map-label { font: 700 11px var(--sans); fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; text-anchor: middle; dominant-baseline: central; }
.map-zoom { position: absolute; right: 12px; top: 12px; display: grid; gap: 4px; }
.map-zoom button { width: 32px; height: 32px; border: 1px solid var(--rule-strong); background: var(--surface); border-radius: 4px; cursor: pointer; font-size: 16px; line-height: 1; color: var(--ink-2); }
.map-zoom button:hover { color: var(--ink); }
.map-zoom .zoom-text { display: none; }
@media (pointer: coarse), (max-width: 640px) {
  .map-zoom { right: 8px; top: 8px; justify-items: end; }
  .map-zoom button { width: 44px; height: 44px; font-size: 20px; }
}
@media (max-width: 640px) {
  .map-zoom .zoom-world { width: auto; min-width: 44px; padding: 0 10px; font-size: 13px; font-weight: 600; }
  .map-zoom .zoom-icon { display: none; }
  .map-zoom .zoom-text { display: inline; }
}
.map-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; pointer-events: none; max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 6px; background: color-mix(in srgb, var(--ink) 86%, transparent); color: var(--bg); font-size: 14px; font-weight: 600; text-align: center; }
.map-hint[hidden] { display: none; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 2px 0; font-size: 12px; color: var(--ink-2); }
.legend-title { font-weight: 600; color: var(--ink); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 2px; border: 1px solid color-mix(in srgb, var(--ink) 15%, transparent); flex: none; }
.swatch.none { background: repeating-linear-gradient(45deg, var(--none) 0 3px, var(--none-hatch) 3px 5px); }
.legend-mini { display: none; }
.map-note { font-size: 12px; color: var(--ink-3); margin: 6px 2px 0; }

.list-view { max-width: 1400px; margin: 14px auto 0; padding: 0 16px 40px; }
.list-caption { margin: 0 0 8px; font-size: 13px; color: var(--ink-3); }
.rank-list { max-width: 760px; margin: 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; }
.rank-list li + li { border-top: 1px solid var(--rule); }
.rank-item { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 14px; color: var(--ink); text-decoration: none; }
.rank-item:hover { background: var(--surface-2); }
.rank-n { width: 22px; flex: none; font-size: 13px; color: var(--ink-3); text-align: right; }
.rank-main { flex: 1; min-width: 0; display: grid; }
.rank-name { display: flex; align-items: center; gap: 8px; font: 600 16px/1.25 var(--serif); }
.rank-region { font-size: 12px; color: var(--ink-3); }
.rank-score { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.rank-label { font-size: 13px; color: var(--ink-2); min-width: 9.5em; }
.home-lists { max-width: 1400px; margin: 0 auto; padding: 8px 16px 56px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.country-card { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 14px 16px; }
.country-card:hover { border-color: var(--ink-3); }
.country-card h3 { font: 600 17px/1.2 var(--serif); display: flex; align-items: center; gap: 8px; }
.country-card p { margin: 8px 0 10px; font: 14px/1.45 var(--serif); color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.empty-state { background: var(--surface); border: 1px dashed var(--rule-strong); border-radius: 6px; padding: 20px; color: var(--ink-2); font-size: 14px; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 40; pointer-events: none; max-width: 300px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule-strong); border-radius: 5px;
  padding: 10px 12px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.16); font-size: 13px;
}
.tooltip .tt-name { font: 600 15px/1.2 var(--serif); display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.tooltip .tt-verdict { margin: 8px 0 0; font: 13px/1.4 var(--serif); color: var(--ink-2); }
.tooltip .tt-hint { margin-top: 6px; font-size: 11px; color: var(--ink-3); }

/* ---------- Touch summary card ---------- */
.sheet {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule-strong); border-bottom: 0; border-radius: 12px 12px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 28px rgb(0 0 0 / 0.18); font-size: 14px;
  touch-action: none; animation: sheet-in 0.18s ease-out;
}
.sheet[hidden] { display: none; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
.sheet-grab { width: 36px; height: 4px; border-radius: 2px; background: var(--rule-strong); margin: 0 auto 8px; }
.sheet-close { position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; border: 0; background: none; border-radius: 6px; font-size: 24px; line-height: 1; color: var(--ink-2); cursor: pointer; }
.sheet-close:hover { color: var(--ink); }
.sheet .tt-name { font: 600 19px/1.2 var(--serif); display: flex; align-items: center; gap: 8px; padding-right: 40px; }
.sheet .tt-name:focus { outline: none; }
.sheet .tt-name:focus-visible { outline: 2px solid var(--focus); }
.sheet .tt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
.sheet .tt-verdict { margin: 10px 0 0; font: 15px/1.45 var(--serif); color: var(--ink-2); }
.sheet .tt-hint { margin-top: 8px; font-size: 12px; color: var(--ink-3); }
.sheet-open { margin-top: 14px; width: 100%; justify-content: center; min-height: 44px; font-size: 15px; font-weight: 600; }
.country.selected { stroke: var(--ink); stroke-width: 2; }
.small-state.selected { stroke: var(--ink); stroke-width: 2; }

/* ---------- Score marks ---------- */
.score-badge { display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 3px; font: 700 13px/1 var(--sans); }
.score-badge.s1 { background: var(--s1); color: var(--on-s1); }
.score-badge.s2 { background: var(--s2); color: var(--on-s2); }
.score-badge.s3 { background: var(--s3); color: var(--on-s3); }
.score-badge.s4 { background: var(--s4); color: var(--on-s4); }
.score-badge.s5 { background: var(--s5); color: var(--on-s5); }
.score-badge.na { background: transparent; color: var(--ink-3); border: 1px dashed var(--rule-strong); font-weight: 400; }
.trend { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.trend-arrow { font: 700 14px/1 var(--sans); width: 1em; text-align: center; }
.trend.improving .trend-arrow { color: var(--t-up); }
.trend.declining .trend-arrow { color: var(--t-down); }
.conf { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.conf-dots { display: inline-flex; gap: 2px; }
.conf-dots i { width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--ink-3); }
.conf-dots i.on { background: var(--ink-2); border-color: var(--ink-2); }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 14px; height: 8px; border-radius: 1px; background: var(--surface-2); border: 1px solid var(--rule); }
.pips.s1 i.on { background: var(--s1); border-color: var(--s1); }
.pips.s2 i.on { background: var(--s2); border-color: var(--s2); }
.pips.s3 i.on { background: var(--s3); border-color: var(--rule-strong); }
.pips.s4 i.on { background: var(--s4); border-color: var(--s4); }
.pips.s5 i.on { background: var(--s5); border-color: var(--s5); }
.flag { font-size: 1.1em; line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.label-tag { display: inline-block; font: 600 10px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; padding: 3px 6px; border-radius: 2px; border: 1px solid currentColor; }
.label-tag.fact { color: var(--ink-3); }
.label-tag.judgement { color: var(--accent); }
.badge-stale { display: inline-flex; align-items: center; gap: 6px; background: var(--warn-bg); color: var(--warn-ink); font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 3px; }

/* ---------- Profile ---------- */
.profile-head { display: grid; gap: 10px; padding-bottom: 20px; border-bottom: 1px solid var(--rule); }
.profile-head h1 { font: 600 40px/1.05 var(--serif); display: flex; align-items: center; gap: 12px; }
.profile-head h1 .flag { font-size: 34px; }
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 14px; color: var(--ink-2); }
.meta-line .sep { color: var(--rule-strong); }
.bloc-list { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.bloc { font: 600 11px/1 var(--sans); letter-spacing: 0.04em; padding: 4px 6px; border-radius: 3px; background: var(--surface-2); color: var(--ink-2); }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--rule-strong); background: var(--surface); padding: 6px 12px; border-radius: 4px; font-size: 13px; color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); margin-top: 20px; }
.stat { position: relative; padding: 12px 14px; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); text-align: left; background: none; border-top: 0; border-left: 0; cursor: help; }
.stat:nth-child(4n) { border-right: 0; }
.stat:nth-last-child(-n+4):nth-child(4n+1), .stat:nth-last-child(-n+4):nth-child(4n+1) ~ .stat { border-bottom: 0; }
.stat-label { font-size: 12px; color: var(--ink-3); }
.stat-value { font: 600 22px/1.2 var(--sans); margin-top: 2px; letter-spacing: -0.01em; }
.stat-value .unit { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.stat-src { display: block; font-size: 11px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-pop { position: absolute; z-index: 5; left: 8px; right: 8px; top: calc(100% - 6px); background: var(--ink); color: var(--bg); font-size: 12px; padding: 8px 10px; border-radius: 4px; display: none; line-height: 1.4; }
.stat:hover .stat-pop, .stat:focus .stat-pop, .stat[aria-expanded="true"] .stat-pop { display: block; }

.verdict { margin-top: 28px; padding: 22px 24px; background: var(--surface); border-left: 3px solid var(--ink); border-radius: 0 6px 6px 0; }
.verdict-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.verdict p { font: 21px/1.5 var(--serif); margin: 0; }
.verdict .lens-limit { font: 15px/1.5 var(--serif); color: var(--ink-2); margin-top: 12px; }

.scorecard { width: 100%; border-collapse: collapse; }
.scorecard th, .scorecard td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.scorecard thead th { font: 600 11px/1.2 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); border-bottom-color: var(--rule-strong); }
.scorecard .layer-row th { font: 600 11px/1.2 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); padding-top: 16px; background: none; border-bottom: 0; }
.scorecard tbody tr.model-row { cursor: pointer; }
.scorecard tbody tr.model-row:hover td { background: var(--surface); }
.scorecard .model-name a { color: var(--ink); font-weight: 600; text-decoration: none; }
.scorecard .model-name a:hover { text-decoration: underline; }
.scorecard .model-q { display: block; font-size: 12px; color: var(--ink-3); font-weight: 400; }
.scorecard .score-cell { display: flex; align-items: center; gap: 10px; }

.layer { margin-top: 32px; }
.layer > h3 { font: 600 12px/1.2 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.model { padding: 18px 0; border-bottom: 1px solid var(--rule); scroll-margin-top: 80px; }
.model:target, .model.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 14%, transparent); } to { background: transparent; } }
.model-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.model-head h4 { font: 600 20px/1.2 var(--serif); margin: 0; margin-right: auto; }
.model .question { font-size: 13px; color: var(--ink-3); margin: 2px 0 10px; }
.model .prose { font: 17px/1.6 var(--serif); margin: 0; max-width: 68ch; }
.prose sup a, sup.cite a { font: 600 10px var(--sans); text-decoration: none; padding: 0 1px; }
.filters-note { margin-top: 18px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; font-size: 14px; color: var(--ink-2); }

.powermap-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: start; }
.powermap svg { width: 100%; height: auto; display: block; }
.pm-node rect { fill: var(--surface); stroke: var(--rule-strong); }
.pm-node text { font: 600 12px var(--sans); fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.pm-center rect { fill: var(--ink); stroke: var(--ink); }
.pm-center text { fill: var(--bg); font-size: 13px; }
.pm-link { stroke-width: 1.5; fill: none; }
.pm-link.patrons { stroke: var(--s5); }
.pm-link.partners { stroke: var(--s4); }
.pm-link.rivals { stroke: var(--s1); stroke-dasharray: 5 3; }
.pm-link.hedges { stroke: var(--ink-3); stroke-dasharray: 2 3; }
.pm-group-label { font: 600 10px var(--sans); letter-spacing: 0.08em; text-transform: uppercase; fill: var(--ink-3); text-anchor: middle; }
.pm-key { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.pm-key span { display: inline-flex; align-items: center; gap: 6px; }
.trade-list { margin: 0; padding: 0; list-style: none; counter-reset: t; }
.trade-list li { counter-increment: t; display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 15px; }
.trade-list li::before { content: counter(t); font: 600 12px var(--sans); color: var(--ink-3); width: 16px; }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: 15px; }
.timeline time { font-size: 13px; color: var(--ink-3); padding-top: 2px; }
.timeline li.past { color: var(--ink-3); }
.timeline li.next time { color: var(--ink); font-weight: 600; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }

.sources { margin: 0; padding-left: 28px; font-size: 14px; }
.sources li { padding: 4px 0; scroll-margin-top: 80px; }
.sources li:target { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.sources .acc { color: var(--ink-3); font-size: 12px; }

.unassessed { text-align: left; }
.unassessed .box { margin-top: 24px; padding: 24px; background: var(--surface); border: 1px dashed var(--rule-strong); border-radius: 6px; }

/* ---------- Tables ---------- */
.table-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 14px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); -webkit-overflow-scrolling: touch; }
.rank-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.rank-table th, .rank-table td { padding: 9px 10px; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; }
.rank-table thead th { font: 600 11px/1.2 var(--sans); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); background: var(--surface); position: sticky; top: 0; }
.rank-table th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.rank-table th button:focus-visible { outline: 2px solid var(--focus); }
.rank-table th[aria-sort] button { color: var(--ink); }
.rank-table th.active-col, .rank-table td.active-col { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.rank-table td.country-col, .rank-table th.country-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.rank-table thead th.country-col { z-index: 2; }
.rank-table td.country-col a { color: var(--ink); font-weight: 600; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; }
.rank-table td.country-col a:hover { text-decoration: underline; }
.rank-table tbody tr:last-child td { border-bottom: 0; }
.rank-table .cell { display: inline-flex; align-items: center; gap: 4px; }
.rank-table .num { color: var(--ink-3); font-size: 12px; width: 22px; }

/* ---------- Compare ---------- */
.compare-picker { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.compare-picker .slot { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--rule-strong); padding: 4px 4px 4px 10px; border-radius: 4px; font-size: 14px; }
.compare-picker .slot button { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 2px 6px; font-size: 16px; line-height: 1; }
.compare-picker .slot button:hover { color: var(--ink); }
.compare-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
.compare-table { border-collapse: collapse; min-width: 100%; }
.compare-table th, .compare-table td { padding: 10px 12px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.compare-table thead th { min-width: 210px; border-bottom: 1px solid var(--ink); }
.compare-table thead th:first-child, .compare-table td:first-child, .compare-table th[scope="row"] { min-width: 130px; width: 150px; position: sticky; left: 0; background: var(--bg); z-index: 1; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.compare-table .cmp-name { font: 600 19px/1.2 var(--serif); display: flex; align-items: center; gap: 8px; }
.compare-table .cmp-name a { color: var(--ink); text-decoration: none; }
.compare-table .cmp-name a:hover { text-decoration: underline; }
.compare-table .cmp-verdict { font: 15px/1.5 var(--serif); color: var(--ink); max-width: 36ch; }
.compare-table .group-row th { font: 600 11px/1.2 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); padding-top: 18px; border-bottom: 1px solid var(--rule-strong); }
.compare-table .cmp-score { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.compare-table .best { box-shadow: inset 2px 0 0 var(--s5); }

/* ---------- Framework ---------- */
.fw-layer { margin-top: 28px; }
.fw-layer h3 { font: 600 20px/1.2 var(--serif); margin-bottom: 4px; }
.fw-layer > p { margin: 0 0 10px; color: var(--ink-2); font: 16px/1.5 var(--serif); }
.fw-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.fw-table th, .fw-table td { text-align: left; padding: 10px 10px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.fw-table th { width: 22%; font-weight: 600; }
.fw-table td.q { width: 34%; font: 15px/1.45 var(--serif); }
.fw-table td.ind { color: var(--ink-2); }
.scale-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.scale-list li { display: flex; align-items: center; gap: 10px; }
.prose-block { font: 17px/1.6 var(--serif); }
.prose-block p { margin: 0 0 14px; }
.prose-block ul { margin: 0 0 14px; padding-left: 22px; }
.prose-block li { margin-bottom: 6px; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--rule); padding: 18px 16px 28px; font-size: 12px; color: var(--ink-3); text-align: center; }
.footer p { margin: 4px auto; max-width: 70ch; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding-top: 8px; padding-bottom: 8px; }
  .wordmark { order: 0; }
  .theme-toggle { order: 1; margin-left: auto; width: 32px; height: 32px; }
  .search { order: 2; width: 100%; margin-left: 0; }
  .search-key { display: none; }
  .nav { order: 3; width: 100%; overflow-x: auto; margin: 0 -8px -4px; }
  .nav a { padding: 6px 8px; font-size: 13px; white-space: nowrap; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(4n) { border-right: 1px solid var(--rule); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-last-child(-n+4):nth-child(4n+1), .stat:nth-last-child(-n+4):nth-child(4n+1) ~ .stat { border-bottom: 1px solid var(--rule); }
  .stat:nth-last-child(-n+2):nth-child(2n+1), .stat:nth-last-child(-n+2):nth-child(2n+1) ~ .stat { border-bottom: 0; }
  .powermap-grid, .two-col { grid-template-columns: 1fr; }
  .profile-head h1 { font-size: 32px; }
  .verdict { padding: 18px; }
  .verdict p { font-size: 19px; }
  .page { padding-top: 22px; }
}
@media (max-width: 560px) {
  body { font-size: 14px; }
  .scorecard thead { display: none; }
  .scorecard, .scorecard tbody { display: block; }
  .scorecard tr.model-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name score" "trend conf"; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
  .scorecard tr.layer-row { display: block; }
  .scorecard tr.layer-row th { display: block; padding: 14px 0 2px; }
  .scorecard td { border: 0; padding: 0; }
  .scorecard td.model-name { grid-area: name; }
  .scorecard td.c-score { grid-area: score; justify-self: end; }
  .scorecard td.c-trend { grid-area: trend; }
  .scorecard td.c-conf { grid-area: conf; justify-self: end; }
  .scorecard .pips { display: none; }
  .timeline li { grid-template-columns: 90px 1fr; }
  .fw-table th, .fw-table td { display: block; width: auto !important; padding: 2px 0; border: 0; }
  .fw-table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--rule); }
  .fw-table thead { display: none; }
  .control-label { min-width: 0; width: 100%; }
  /* One row of controls on phones: lens, score/trend and a Filters button that opens the rest. */
  .controls { margin-top: 12px; gap: 8px; grid-template-columns: minmax(0, 1fr); }
  .controls .control-row { flex-wrap: nowrap; }
  .controls .control-row:first-child .control-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #lens-select { flex: 1 1 auto; min-width: 0; text-overflow: ellipsis; }
  .controls .select, .controls .segmented button, .filters-toggle { min-height: 40px; }
  .controls .segmented, .filters-toggle { flex: none; }
  .filters-toggle { display: inline-flex; }
  .controls .filter-panel { display: none; flex-wrap: wrap; padding: 10px; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; }
  .controls.filters-open .filter-panel { display: flex; }
  .filter-panel .control-label { width: auto; }
  .filter-panel .select { flex: 1 1 auto; min-width: 0; }
  .filter-panel .chips { width: 100%; }
  .chip { min-height: 32px; padding: 4px 12px; }
  .clear-filters { min-height: 32px; }
  .home-head { padding-top: 16px; }
  .home-head h1 { font-size: 21px; }
  .home-head p { font-size: 15px; }
  .controls .control-row { gap: 6px 10px; }
  .map-frame svg { height: min(420px, 56vh); }
  .map-wrap { padding: 0 8px; }
  .home-head { gap: 8px; }
  .home-side { width: 100%; justify-content: space-between; }
  .home-side .segmented button { min-height: 36px; }
  .list-view { padding: 0 8px 32px; }
  .rank-item { padding: 8px 10px; gap: 10px; }
  .rank-label { min-width: 0; }
}
@media (max-width: 640px) {
  /* The legend becomes a compact key in the map's lower-left corner. */
  .legend { display: none; }
  .legend-mini {
    display: block; position: absolute; left: 8px; bottom: 8px; z-index: 2; max-width: calc(100% - 16px);
    background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--rule-strong); border-radius: 6px;
    font-size: 12px; color: var(--ink-2);
  }
  .legend-mini summary { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 10px; cursor: pointer; list-style: none; font-weight: 600; color: var(--ink); }
  .legend-mini summary::-webkit-details-marker { display: none; }
  .legend-mini summary::after { content: "▴"; font-size: 10px; color: var(--ink-3); }
  .legend-mini[open] summary::after { content: "▾"; }
  .legend-mini-swatches { display: inline-flex; gap: 2px; }
  .legend-mini-swatches .swatch { width: 12px; height: 12px; }
  .legend-mini[open] .legend-mini-swatches { display: none; }
  .legend-mini-body { display: grid; gap: 6px; padding: 2px 10px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Change log tiers ---------- */
.tier-tag { display: inline-block; font: 600 10px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); border: 1px solid var(--rule-strong); border-radius: 2px; padding: 3px 5px; margin-right: 4px; vertical-align: 1px; }
.timeline li > a { font-weight: 600; color: var(--ink); text-decoration: none; }
.timeline li > a:hover { text-decoration: underline; }

/* Small layout helpers, so the app needs no inline style attributes (the CSP forbids them). */
.swatch.sw-s1 { background: var(--s1); }
.swatch.sw-declining { background: var(--t-down); }
.swatch.sw-s2 { background: var(--s2); }
.swatch.sw-s3 { background: var(--s3); }
.swatch.sw-stable { background: var(--t-flat); }
.swatch.sw-s4 { background: var(--s4); }
.swatch.sw-s5 { background: var(--s5); }
.swatch.sw-improving { background: var(--t-up); }
.page.page-wide { max-width: 1300px; }
.page.page-xwide { max-width: 1400px; }
.fact-note { margin: 8px 0 0; }
.fw-normal { font-weight: 400; }
.mt-0 { margin-top: 0; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-6 { margin-bottom: 6px; }
.mb-8 { margin-bottom: 8px; }
