/* Palette: reference data-viz palette. Exports = categorical slot 1 (blue), imports = slot 2 (orange);
   direction is also carried by arrow direction and the legend, never by colour alone. */
:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --panel: #f3f2ef;
  --text: #0b0b0b;
  --text-2: #52514e;
  --line: #d9d8d3;
  --land: #e7e6e1;
  --land-hover: #dcdad3;
  --border: #b9b8b1;
  --exp: #2a78d6;
  --imp: #eb6834;
  --focus: #0b0b0b;
  /* GDP-sector categorical slots 3-7 of the reference 8-hue palette (skipping slots 1-2, already
     used for exports/imports elsewhere on this page, to avoid implying a connection that isn't there) */
  --sec1: #1baf7a;
  --sec2: #eda100;
  --sec3: #e87ba4;
  --sec4: #008300;
  --sec5: #4a3aa7;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface: #1a1a19;
    --panel: #232321;
    --text: #f2f1ec;
    --text-2: #c3c2b7;
    --line: #3a3936;
    --land: #2c2c2a;
    --land-hover: #363633;
    --border: #4d4c47;
    --exp: #3987e5;
    --imp: #d95926;
    --focus: #f2f1ec;
    --sec1: #199e70; --sec2: #c98500; --sec3: #d55181; --sec4: #008300; --sec5: #9085e9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19; --panel: #232321; --text: #f2f1ec; --text-2: #c3c2b7; --line: #3a3936;
  --land: #2c2c2a; --land-hover: #363633; --border: #4d4c47; --exp: #3987e5; --imp: #d95926; --focus: #f2f1ec;
  --sec1: #199e70; --sec2: #c98500; --sec3: #d55181; --sec4: #008300; --sec5: #9085e9;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--surface); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
.muted { color: var(--text-2); }

.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 18px; font-weight: 650; }
.sub { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; list-style: none; margin: 0; padding: 0; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 22px; height: 4px; border-radius: 2px; display: inline-block; }
.swatch.exp { background: var(--exp); }
.swatch.imp { background: var(--imp); }
.wkey { stroke: var(--text-2); stroke-linecap: butt; }

main { flex: 1; min-height: 0; padding: 0 16px 8px; }
.layout { height: 100%; display: flex; gap: 12px; min-height: 0; }
.mapcol { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 300px; }
#map { width: 100%; height: 100%; display: block; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--text-2); }

#tableWrap { position: absolute; inset: 0; overflow: auto; background: var(--surface); }
#flowTable { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
#flowTable caption { text-align: left; padding: 4px 4px 10px; color: var(--text-2); font-size: 12.5px; caption-side: top; }
#flowTable th, #flowTable td { padding: 5px 10px; text-align: left; border-bottom: 1px solid var(--line); }
#flowTable td:last-child, #flowTable th:last-child { text-align: right; }
#flowTable thead th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 650;
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--border); }
#flowTable tbody tr:hover { background: var(--panel); }
#flowTable td.dir-exp { color: var(--exp); }
#flowTable td.dir-imp { color: var(--imp); }

/* commodity panel */
.panel {
  flex: 0 0 190px; display: flex; flex-direction: column; gap: 8px; max-height: 100%; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; color: var(--text-2); }
.panel-actions { display: flex; gap: 4px; }
.panel-actions button { padding: 2px 7px; font-size: 12px; }
.comm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.comm-list label { display: flex; align-items: flex-start; gap: 7px; padding: 3px 4px; border-radius: 4px; cursor: pointer; font-size: 12.5px; line-height: 1.3; }
.comm-list label:hover { background: var(--land); }
.comm-list input { margin-top: 3px; accent-color: var(--exp); flex-shrink: 0; }

/* right sidebar: Indicators / Economy */
.sidebar { flex: 0 0 250px; transition: flex-basis .15s; }
.sidebar.collapsed { flex: 0 0 32px; padding: 10px 3px; overflow: hidden; }
.sidebar.collapsed .tabs, .sidebar.collapsed .sidebar-body { display: none; }
.sidebar.collapsed #sidebarToggle { transform: scaleX(-1); }
.tabs { display: flex; gap: 4px; }
.tab { padding: 3px 9px; font-size: 12px; }
.tab[aria-selected="true"] { background: var(--surface); border-color: var(--text-2); font-weight: 650; color: var(--text); }
.sidebar-body { overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; font-size: 13px; }
.ind-section h3 { margin: 0 0 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; color: var(--text-2); }
.ind-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.ind-row .k { color: var(--text-2); }
.ind-row .v { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wage-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.wage-table td { padding: 2px 3px; }
.wage-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.wage-table tr.sel { background: var(--land); font-weight: 650; border-radius: 4px; }
.hint { color: var(--text-2); font-style: italic; }

.stackbar { display: flex; width: 100%; height: 18px; border-radius: 4px; overflow: hidden; background: var(--line); }
.stackbar .seg { height: 100%; }
.stackbar .seg + .seg { border-left: 2px solid var(--panel); }
.sect-legend { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.sect-legend li { display: flex; align-items: center; gap: 6px; }
.sect-legend .sw { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.sect-legend .name { flex: 1; }
.sect-legend .pct { font-variant-numeric: tabular-nums; color: var(--text-2); }

.spark-wrap { position: relative; }
.spark text.val { font-size: 11px; fill: var(--text-2); }
.spark .line { fill: none; stroke: var(--exp); stroke-width: 1.6; }
.spark .now { fill: var(--exp); }

.sector-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.sector-row { display: grid; grid-template-columns: 1fr 72px 32px; align-items: center; gap: 6px; font-size: 11.5px; }
.sname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.sbar-track { background: var(--line); border-radius: 3px; height: 8px; overflow: hidden; }
.sbar-fill { height: 100%; background: var(--text-2); border-radius: 3px; }
.sval { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

.sec-0 { background: var(--sec1); }
.sec-1 { background: var(--sec2); }
.sec-2 { background: var(--sec3); }
.sec-3 { background: var(--sec4); }
.sec-4 { background: var(--sec5); }
.sec-other { background: var(--border); }

/* map */
.province { fill: var(--land); stroke: var(--border); stroke-width: 0.8; cursor: pointer; transition: fill .12s; }
.province:hover { fill: var(--land-hover); }
.province.selected { stroke: var(--text); stroke-width: 1.6; }
.province:focus { outline: none; }
.province:focus-visible { outline: none; stroke: var(--focus); stroke-width: 2.2; }
.anchor { fill: var(--text-2); pointer-events: none; }
.anchor-hit, .port-hit { fill: transparent; cursor: pointer; }
.plabel { fill: var(--text-2); font-size: 11px; font-weight: 600; text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--land); stroke-width: 3px; stroke-linejoin: round; }
.port circle { fill: var(--surface); stroke: var(--text-2); stroke-width: 1.5; }
.port text { fill: var(--text); font-size: 12px; text-anchor: middle; paint-order: stroke; stroke: var(--surface); stroke-width: 3.5px; stroke-linejoin: round; }
.port .small { fill: var(--text-2); font-size: 11px; }
.port { cursor: pointer; }
/* toggled off: spot fades to grey and (via JS filtering) its arrows stop being drawn */
.anchor-spot.off .anchor { fill: var(--border); }
.anchor-spot.off .plabel { opacity: .4; }
.port.off circle { fill: var(--land); stroke: var(--border); }
.port.off text { fill: var(--text-2); opacity: .55; }
.anchor-hit:focus-visible, .port:focus-visible { outline: none; }
.anchor-hit:focus-visible ~ .anchor, .port:focus-visible circle { stroke: var(--focus); stroke-width: 2px; }
.arrow.exp { --c: var(--exp); }
.arrow.imp { --c: var(--imp); }
.arrow .shaft { fill: none; stroke: var(--c); stroke-linecap: butt; opacity: .82; }
.arrow .head { fill: var(--c); opacity: .9; }
.arrow .hit { fill: none; stroke: transparent; pointer-events: stroke; }
.arrow:hover .shaft { opacity: 1; }
.arrow:hover .head { opacity: 1; }
.dim .arrow:not(:hover) { opacity: .45; }

#tip {
  position: absolute; pointer-events: none; z-index: 2; max-width: 260px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
#tip b { font-weight: 650; }
#tip .row { display: flex; justify-content: space-between; gap: 14px; }
#tip .k { color: var(--text-2); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 0; border-top: 1px solid var(--line); }
.controls input[type=range] { flex: 1 1 260px; min-width: 160px; accent-color: var(--exp); }
#monthLabel { min-width: 76px; font-weight: 650; font-variant-numeric: tabular-nums; border-radius: 4px; }
@keyframes monthJump { 0% { background: var(--exp); color: #fff; } 100% { background: transparent; color: inherit; } }
#monthLabel.flash { animation: monthJump 1.1s ease-out; }
.controls select {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 6px;
}
.range-label { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 13px; white-space: nowrap; }
#play { font-size: 14px; line-height: 1; padding: 5px 10px; }
#play[aria-pressed="true"] { border-color: var(--text-2); color: var(--text); }
#dollarMode[aria-pressed="true"] { border-color: var(--exp); color: var(--exp); }
#viewToggle[aria-pressed="true"] { border-color: var(--text-2); color: var(--text); }
.totals { color: var(--text-2); font-variant-numeric: tabular-nums; }
.totals b { color: var(--text); font-weight: 650; }
button {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--text-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.foot { margin: 0; padding: 4px 0 0; color: var(--text-2); font-size: 12px; }

@media (max-width: 640px) {
  .top { padding: 10px 12px; }
  main { padding: 0 8px 8px; }
  .layout { flex-direction: column; }
  .panel { flex: 0 0 auto; max-height: 160px; }
  /* the sidebar carries more content (stats, a 13-row table, charts) than the commodity checklist,
     so it gets more room on a phone; still capped well short of the full viewport height */
  .sidebar { max-height: 340px; }
  .sidebar.collapsed { flex: 0 0 auto; max-height: 34px; }
}
