/* Tokens: the dataviz reference palette. Aid types take categorical slots 1, 3
   and 2 (blue, aqua, orange — validated all-pairs in both modes); the economy
   charts are single-series and take violet so no hue means two things on the
   page. Dark values are their own validated steps, not a flip. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --link: #1c5cab;
  --military: #2a78d6;
  --financial: #1baf7a;
  --humanitarian: #eb6834;
  --econ: #4a3aa7;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --link: #86b6ef;
    --military: #3987e5;
    --financial: #199e70;
    --humanitarian: #d95926;
    --econ: #9085e9;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a988f;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --link: #86b6ef;
  --military: #3987e5;
  --financial: #199e70;
  --humanitarian: #d95926;
  --econ: #9085e9;
  --shadow: none;
}

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

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a {
  color: var(--link);
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 16px 56px;
}

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

.masthead {
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4.2vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.lede {
  max-width: 62ch;
  margin: 10px 0 6px;
  color: var(--ink-2);
  font-size: 17px;
}

.asof {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.load-error {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

/* ------------------------------------------------------------ hero + tiles */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr);
  gap: 16px;
  margin-bottom: 16px;
}

.hero-figure,
.tile,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.hero-figure {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 22px 24px;
}

.hero-label,
.tile-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
}

.hero-value {
  margin: 4px 0;
  font-size: clamp(44px, 6vw, 56px);
  font-weight: 650;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.hero-sub {
  color: var(--ink-2);
  font-size: 14px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.tile {
  padding: 16px 18px;
}

.tile-value {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
}

.tile-note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

/* ------------------------------------------------------------ cards */

.card {
  min-width: 0;
  margin-bottom: 16px;
  padding: 20px 22px 16px;
}

h2,
h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

h3 {
  font-size: 16px;
}

.section-title {
  margin: 28px 0 12px;
  font-size: 22px;
}

.card-sub {
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.pair .card {
  margin-bottom: 0;
}

.trio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.trio .card {
  margin-bottom: 0;
}

/* ------------------------------------------------------------ legend */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  min-height: 20px;
  margin-bottom: 10px;
  color: var(--ink-2);
  font-size: 13px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-swatch {
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.fill-bg-military { background: var(--military); }
.fill-bg-financial { background: var(--financial); }
.fill-bg-humanitarian { background: var(--humanitarian); }

/* ------------------------------------------------------------ charts */

.chart {
  position: relative;
}

.chart-stage {
  width: 100%;
  border-radius: 6px;
  outline: none;
}

.chart-stage:focus-visible {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--link);
}

.chart svg {
  display: block;
  overflow: visible;
}

.fill-military { fill: var(--military); }
.fill-financial { fill: var(--financial); }
.fill-humanitarian { fill: var(--humanitarian); }
.fill-econ { fill: var(--econ); }
.stroke-econ { stroke: var(--econ); }

.grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.axis-base {
  stroke: var(--baseline);
  stroke-width: 1;
}

.axis-tick {
  stroke: var(--baseline);
}

.tick {
  fill: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.row-label {
  fill: var(--ink-2);
  font-size: 12px;
}

.value-label {
  fill: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
}

.annotation {
  stroke: var(--baseline);
  stroke-width: 1;
}

.annotation-label {
  fill: var(--muted);
  font-size: 12px;
}

.line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.dot {
  stroke: var(--surface);
  stroke-width: 2;
  paint-order: stroke;
}

.crosshair {
  stroke: var(--ink-2);
  stroke-width: 1;
}

.hit {
  fill: transparent;
  pointer-events: all;
}

.col {
  transition: opacity 120ms ease;
}

.has-active .col:not(.is-active) {
  opacity: 0.4;
}

@media (prefers-reduced-motion: reduce) {
  .col { transition: none; }
}

.tooltip {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  min-width: 150px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 80ms ease;
}

.tooltip.is-visible {
  opacity: 1;
}

.tooltip-title {
  margin-bottom: 4px;
  color: var(--ink-2);
  font-weight: 600;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.tooltip-key {
  flex: none;
  width: 12px;
  height: 2px;
  border-radius: 1px;
}

.stroke-key-military { background: var(--military); }
.stroke-key-financial { background: var(--financial); }
.stroke-key-humanitarian { background: var(--humanitarian); }
.stroke-key-econ { background: var(--econ); }

.tooltip-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.tooltip-value.is-strong {
  font-weight: 650;
}

.tooltip-label {
  color: var(--muted);
}

/* ------------------------------------------------------------ table views */

.table-view {
  margin-top: 12px;
  font-size: 13px;
}

.table-view-wide {
  margin: 12px 0 0;
  padding: 0 4px;
}

.table-view summary {
  width: fit-content;
  color: var(--link);
  cursor: pointer;
}

.table-wrap {
  max-height: 360px;
  margin-top: 8px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--grid);
  text-align: left;
  white-space: nowrap;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 600;
}

.data-table tbody th {
  font-weight: 500;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ sources */

.sources {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--grid);
  font-size: 13px;
}

.sources h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

.sources dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 4px 20px;
  margin: 0;
}

.sources dt {
  color: var(--ink-2);
  font-weight: 600;
}

.sources dd {
  margin: 0 0 12px;
}

.sources p {
  margin: 0 0 4px;
}

.muted {
  color: var(--muted);
}

.disclaimer {
  margin-top: 16px !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .hero,
  .pair,
  .trio {
    grid-template-columns: minmax(0, 1fr);
  }

  .pair .card,
  .trio .card {
    margin-bottom: 0;
  }
}

@media (max-width: 560px) {
  .page {
    padding-top: 28px;
  }

  .tiles {
    grid-template-columns: minmax(0, 1fr);
  }

  .card {
    padding: 16px 14px 12px;
  }

  .sources dl {
    grid-template-columns: minmax(0, 1fr);
  }
}
