:root {
  --sea: #d3dee3;
  --land: #e7e9e4;
  --border: #f7f8f6;
  --ink: #18303d;
  --ink-2: #4d6470;
  --rule: #c3ced3;
  --low: #b7791f;      /* ochre: below the midpoint */
  --mid: #eceee6;
  --high: #1d6a80;     /* chart teal: above the midpoint */
  --paper: #fbfcfb;
  --focus: #1d6a80;
  --shadow: 0 1px 2px rgba(24, 48, 61, .12), 0 8px 28px rgba(24, 48, 61, .14);
  --wide: 125;
  --narrow: 75;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sea: #0f1c23; --land: #24343c; --border: #0f1c23; --ink: #e6eef1; --ink-2: #9db1ba;
    --rule: #33454e; --low: #d39a3c; --mid: #3a4a50; --high: #5bb5cc; --paper: #16252d; --focus: #5bb5cc;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --sea: #0f1c23; --land: #24343c; --border: #0f1c23; --ink: #e6eef1; --ink-2: #9db1ba;
  --rule: #33454e; --low: #d39a3c; --mid: #3a4a50; --high: #5bb5cc; --paper: #16252d; --focus: #5bb5cc;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Archivo', system-ui, sans-serif;
  font-variation-settings: 'wdth' 100;
  font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--sea);
  overflow: hidden;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: inherit; }

/* ---------- map */
#map { position: fixed; inset: 0; }
#map svg { width: 100%; height: 100%; display: block; cursor: grab; }
#map svg:active { cursor: grabbing; }
.country { stroke: var(--border); stroke-width: .5; vector-effect: non-scaling-stroke; cursor: pointer; transition: opacity .12s; }
.country:hover { opacity: .78; }
.country.selected { stroke: var(--ink); stroke-width: 2; }
.core-dot { fill: var(--ink); stroke: var(--paper); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }

#tooltip {
  position: fixed; pointer-events: none; z-index: 30; background: var(--paper); color: var(--ink);
  padding: 6px 10px; border-radius: 4px; box-shadow: var(--shadow); font-size: 13px;
  font-variation-settings: 'wdth' var(--narrow); white-space: nowrap;
}
#tooltip b { font-weight: 650; }

/* ---------- top bar */
.bar {
  position: fixed; top: 16px; left: 16px; z-index: 20; display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; max-width: calc(100vw - 32px);
}
.brand {
  margin: 0 6px 0 0; font-size: 19px; font-weight: 780; letter-spacing: -.01em;
  font-variation-settings: 'wdth' var(--wide);
}
.search { position: relative; }
.search input, .metric select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid var(--rule);
  border-radius: 6px; padding: 7px 10px; height: 36px;
}
.search input { width: 220px; }
#search-results {
  position: absolute; top: 40px; left: 0; width: 260px; max-height: 320px; overflow: auto; margin: 0; padding: 4px;
  list-style: none; background: var(--paper); border-radius: 6px; box-shadow: var(--shadow);
}
#search-results li { padding: 6px 8px; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--mid); }
#search-results li small { color: var(--ink-2); }
.metric { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }

/* ---------- legend */
.legend {
  position: fixed; left: 16px; bottom: 40px; z-index: 10; width: 240px; padding: 12px 14px;
  background: var(--paper); border-radius: 6px; box-shadow: var(--shadow); font-size: 12.5px;
}
.legend-title { font-weight: 650; margin-bottom: 6px; }
.legend-bar { height: 8px; border-radius: 2px; }
.legend-scale { display: flex; justify-content: space-between; color: var(--ink-2); margin: 3px 0 8px; font-variant-numeric: tabular-nums; }
.legend-key { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.legend-key + .legend-key { margin-top: 3px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); margin: 0 3px; }
.swatch { width: 13px; height: 9px; border-radius: 2px; }
.swatch.none { background: var(--land); outline: 1px solid var(--rule); }

.site-foot {
  position: fixed; left: 16px; bottom: 12px; z-index: 10; font-size: 11.5px; color: var(--ink-2);
}

/* ---------- panel */
.panel {
  position: fixed; z-index: 25; top: 0; right: 0; bottom: 0; width: min(440px, 100vw);
  background: var(--paper); box-shadow: var(--shadow); display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .28s cubic-bezier(.2, .7, .2, 1);
}
.panel.entering { transform: translateX(100%); }
.panel-head { padding: 22px 24px 0; border-bottom: 1px solid var(--rule); }
.close {
  position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border: 0; background: none;
  font-size: 26px; line-height: 1; color: var(--ink-2); cursor: pointer; border-radius: 6px;
}
.close:hover { background: var(--mid); color: var(--ink); }
.panel-kicker { margin: 0 44px 2px 0; font-size: 13px; color: var(--ink-2); }
#panel-name {
  margin: 0 40px 14px 0; font-weight: 800; line-height: .95; letter-spacing: -.02em;
  font-variation-settings: 'wdth' var(--wide); font-size: clamp(30px, 7vw, 44px);
  overflow-wrap: anywhere;
}
#panel-name.long { font-size: clamp(24px, 5.5vw, 32px); }
.tabs { display: flex; gap: 4px; }
.tabs button {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink-2); background: none; border: 0;
  padding: 9px 10px 11px; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--high); }
.tabs button:hover { color: var(--ink); }

.pane { flex: 1; overflow-y: auto; padding: 6px 24px 24px; }
.pane h3 {
  font-size: 13px; font-weight: 700; margin: 22px 0 2px; color: var(--high);
  font-variation-settings: 'wdth' var(--wide); letter-spacing: .01em;
}
.rows { margin: 0; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 11px 0; border-bottom: 1px solid var(--rule); }
.row dt { font-weight: 550; }
.row dd { margin: 0; text-align: right; font-weight: 650; font-size: 17px; font-variant-numeric: tabular-nums; font-variation-settings: 'wdth' var(--narrow); }
.row dd.muted { font-weight: 450; font-size: 14px; color: var(--ink-2); }
.row .meta { grid-column: 1 / -1; font-size: 12px; color: var(--ink-2); font-variation-settings: 'wdth' var(--narrow); }
.row .unit { font-size: 12px; font-weight: 450; color: var(--ink-2); margin-left: 3px; }
.row.block { grid-template-columns: 1fr; }
.row.block dd { text-align: left; font-size: 15px; font-weight: 450; font-variation-settings: 'wdth' 100; }
.neg { color: var(--low); }

.hist { display: inline-flex; gap: 10px; }
.hist span { white-space: nowrap; }

ol.companies { margin: 4px 0 0; padding-left: 22px; columns: 2; column-gap: 18px; }
ol.companies li { break-inside: avoid; padding: 1px 0; }
ul.plain { margin: 4px 0 0; padding: 0; list-style: none; }
ul.plain li { padding: 3px 0; }

.weights { display: grid; grid-template-columns: max-content 1fr 34px; gap: 5px 10px; align-items: center; margin-top: 6px; }
.weights .wbar { height: 8px; background: var(--mid); border-radius: 2px; overflow: hidden; }
.weights .wbar i { display: block; height: 100%; background: var(--high); }
.weights .pct { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

.product { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.ticker {
  font-size: 12px; font-weight: 650; padding: 1px 6px; border-radius: 3px; background: var(--mid);
  font-variation-settings: 'wdth' var(--narrow); white-space: nowrap; align-self: flex-start;
}
.product small { display: block; color: var(--ink-2); font-size: 12px; }

.notice { margin: 18px 0 0; padding: 12px 14px; border-left: 3px solid var(--low); background: var(--mid); font-size: 13.5px; }
.panel-foot { padding: 10px 24px 14px; font-size: 11.5px; color: var(--ink-2); border-top: 1px solid var(--rule); }

/* ---------- small screens: the panel becomes a bottom sheet */
@media (max-width: 720px) {
  .bar { top: 10px; left: 10px; gap: 8px; }
  .brand { font-size: 16px; width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .metric label { display: none; }
  .metric select { width: 128px; }
  .legend { left: 10px; bottom: 34px; width: 200px; padding: 10px; }
  .site-foot { left: 10px; right: 10px; bottom: 8px; font-size: 10.5px; }
  .panel { top: auto; height: 72vh; width: 100vw; border-radius: 12px 12px 0 0; }
  .panel.entering { transform: translateY(100%); }
  .panel-head { padding: 16px 18px 0; }
  .pane { padding: 4px 18px 20px; }
  ol.companies { columns: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .panel, .country { transition: none; }
}
