/* Cool slate neutrals, one accent that follows the map color choice (set from app.js). */
:root {
  color-scheme: dark;
  --surface-0: #0e1014;   /* page + map stage */
  --surface-1: #14171c;   /* header, side panels */
  --surface-2: #1a1e24;   /* inputs, hover */
  --surface-3: #232830;   /* pressed / selected */
  --float: rgba(20, 23, 28, 0.86); /* panels floating over the map */
  --line: #232830;
  --line-strong: #313742;
  --text-primary: #e6e8eb;
  --text-secondary: #a9b0ba;
  --text-muted: #737b86;
  --text-faint: #4a515b;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.14);
  --accent-ring: rgba(57, 135, 229, 0.35);
  --bar: #3987e5;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --left-w: 236px;
  --right-w: 324px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  grid-template-rows: 54px 1fr;
  grid-template-areas: "top top top" "left stage right";
  background: var(--surface-0);
  color: var(--text-primary);
  font: 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.muted { color: var(--text-muted); }
code { font: 11px ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--text-muted); }

/* thin, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- header ---- */
.top {
  grid-area: top;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}
.top h1 {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 8px 0 0; font: 600 18px/1 var(--serif); letter-spacing: 0.01em; white-space: nowrap;
}
.top h1::before {
  content: ""; align-self: center; width: 10px; height: 10px; border-radius: 3px;
  background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.top h1 span {
  font: 600 10.5px/1 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted);
}

.search { position: relative; flex: 0 1 300px; }
.search input, .table-bar input[type=search], select {
  width: 100%; height: 32px; padding: 0 10px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
.search input { padding-left: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23737b86' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 11px center; }
.search input::placeholder, .table-bar input::placeholder { color: var(--text-muted); }
.search input:hover, .table-bar input:hover, select:hover:not(:disabled) { border-color: #3d4451; }
.search input:focus, .table-bar input:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23a9b0ba' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
select option { background: var(--surface-2); color: var(--text-primary); }
select:disabled { cursor: default; color: var(--text-secondary); background-image: none; padding-right: 10px; }

#search-results {
  position: absolute; z-index: 30; top: 38px; left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#search-results li { padding: 7px 9px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#search-results li small { color: var(--text-muted); }
#search-results li[aria-selected=true], #search-results li:hover { background: var(--surface-3); }

.field {
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  font: 600 10.5px/1 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted);
}
.field select { width: 170px; font: 13px var(--sans); letter-spacing: 0; text-transform: none; color: var(--text-primary); }
.field select.version { width: 180px; }

.tabs { margin-left: auto; display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 3px; }
.tabs button { border: 0; background: none; padding: 4px 14px; border-radius: 5px; cursor: pointer; color: var(--text-secondary); font-weight: 500; }
.tabs button:hover { color: var(--text-primary); }
.tabs button[aria-selected=true] { background: var(--surface-3); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 0 0 1px var(--line-strong); }

/* ---- side panels ---- */
.side { background: var(--surface-1); overflow-y: auto; overflow-x: hidden; }
.side.left { grid-area: left; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side.right { grid-area: right; border-left: 1px solid var(--line); padding: 18px 18px 24px; }

#resource-list { padding: 8px 10px 4px; }
.group + .group { margin-top: 6px; }
.group h3, .options h3 {
  margin: 14px 8px 6px; font: 600 10.5px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted);
}
.res {
  position: relative; display: flex; justify-content: space-between; align-items: baseline; width: 100%;
  border: 0; background: none; text-align: left; padding: 6px 10px; border-radius: 6px; cursor: pointer;
  color: var(--text-secondary); transition: background .1s, color .1s;
}
.res:hover { background: var(--surface-2); color: var(--text-primary); }
.res[aria-pressed=true] { background: var(--accent-soft); color: var(--text-primary); font-weight: 500; }
.res[aria-pressed=true]::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.res .n { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 12px; font-weight: 400; }
.res[aria-pressed=true] .n { color: var(--text-secondary); }

.options { margin: 10px 10px 12px; padding: 4px 2px 8px; border-top: 1px solid var(--line); }
.opt { padding: 4px 8px 10px; }
.opt > span { display: block; color: var(--text-secondary); margin-bottom: 6px; font-size: 12px; }
.opt.disabled { opacity: .4; }
.seg { display: flex; gap: 2px; background: var(--surface-0); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 3px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 4px 4px; border-radius: 5px; cursor: pointer;
  font-size: 12px; color: var(--text-muted); white-space: nowrap; transition: color .1s, background .1s;
}
.seg button:hover { color: var(--text-primary); }
.seg button[aria-pressed=true] { background: var(--surface-3); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 0 0 1px var(--line-strong); }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 8px; color: var(--text-secondary); cursor: pointer; white-space: nowrap; font-size: 12px; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.credits { margin-top: auto; padding: 12px 18px 14px; font-size: 11px; line-height: 1.5; color: var(--text-muted); border-top: 1px solid var(--line); }

/* ---- stage ---- */
.stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; }
.view { position: absolute; inset: 0; }
#map { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#map.dragging { cursor: grabbing; }
.loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--text-muted); font: 13px var(--sans); letter-spacing: .04em; background: var(--surface-0);
}
.loading.error { color: #e66767; padding: 40px; text-align: center; }

.tooltip, .legend, .zoom button {
  background: var(--float); border: 1px solid var(--line-strong);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.tooltip { position: fixed; z-index: 40; pointer-events: none; max-width: 280px; padding: 9px 11px; border-radius: var(--radius); }
.tooltip b { display: block; font: 600 14px/1.25 var(--serif); }
.tooltip .sub { color: var(--text-muted); font-size: 12px; }
.tooltip .val { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line-strong); display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .val span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-primary); }
.tooltip .hint { margin-top: 5px; color: var(--text-muted); font-size: 11px; }

.legend { position: absolute; left: 14px; bottom: 14px; padding: 11px 13px 9px; min-width: 260px; border-radius: var(--radius); }
.legend .title { font-weight: 600; margin-bottom: 8px; }
.legend .title small { color: var(--text-muted); font-weight: 400; }
.legend .ramp { height: 8px; border-radius: 4px; }
.legend .ticks { position: relative; height: 17px; font-size: 11px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.legend .ticks span { position: absolute; top: 3px; transform: translateX(-50%); }
.legend .ticks span:first-child { transform: none; }
.legend .ticks span:last-child { transform: translateX(-100%); }
.legend .keys { display: flex; gap: 14px; margin-top: 5px; padding-top: 7px; border-top: 1px solid var(--line-strong); font-size: 11px; color: var(--text-secondary); }
.legend .keys i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }

.zoom { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.zoom button {
  width: 34px; height: 34px; border-radius: var(--radius); cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--text-secondary); transition: color .1s, border-color .1s;
}
.zoom button:hover { color: var(--text-primary); border-color: #3d4451; }

/* ---- right panel ---- */
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-head h2 { margin: 0; font: 600 22px/1.15 var(--serif); }
.panel-head .sub { color: var(--text-muted); margin-top: 4px; font-size: 12px; }
.close {
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text-secondary);
  border-radius: 6px; width: 28px; height: 28px; cursor: pointer; flex: none; font-size: 15px; line-height: 1;
}
.close:hover { background: var(--surface-3); color: var(--text-primary); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.chip {
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--text-secondary); font-size: 12px;
}
button.chip { cursor: pointer; }
button.chip:hover { color: var(--text-primary); border-color: #3d4451; }
.chip.on { border-color: var(--accent); color: var(--text-primary); background: var(--accent-soft); }
#panel h4 {
  margin: 22px 0 8px; font: 600 10.5px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted);
}
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 6px 4px; border-bottom: 1px solid var(--line); color: var(--text-secondary); }
.kv td:first-child { padding-left: 6px; }
.kv td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.kv td.rank { text-align: right; color: var(--text-muted); font-size: 11px; width: 78px; padding-right: 6px; }
.kv tr.on td { color: var(--text-primary); font-weight: 600; background: var(--accent-soft); }
.kv tr.on td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.kv tr.click { cursor: pointer; }
.kv tr.click:hover td { background: var(--surface-2); }
.kv tr.on.click:hover td { background: var(--accent-soft); }
.big { margin-top: 16px; font: 600 30px/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.big small { font: 400 13px var(--sans); color: var(--text-muted); margin-left: 6px; }
.stat-row {
  display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-0);
}
.stat-row div { display: flex; flex-direction: column; gap: 2px; padding: 9px 12px; }
.stat-row div + div { border-left: 1px solid var(--line); }
.stat-row span { color: var(--text-muted); font-size: 11px; }
.stat-row b { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; }

.toplist { list-style: none; margin: 0 -6px; padding: 0; }
.toplist li { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 6px; border-radius: 6px; cursor: pointer; }
.toplist li:hover { background: var(--surface-2); }
.toplist .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toplist .v { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 500; }
.toplist .bar { grid-column: 1 / -1; height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.toplist .bar i { display: block; height: 100%; background: var(--bar); border-radius: 0 2px 2px 0; }
.note { color: var(--text-muted); font-size: 12px; line-height: 1.5; margin: 12px 0 0; }

/* ---- table ---- */
.table-bar { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-1); }
.table-bar input[type=search] { width: 240px; }
.table-bar .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; font-size: 12px; }
.btn {
  white-space: nowrap; flex: none; margin-left: auto; height: 32px; padding: 0 14px; border-radius: var(--radius); cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line-strong); font-weight: 500;
}
.btn:hover { background: var(--surface-3); border-color: #3d4451; }
.table-wrap { position: absolute; top: 53px; left: 0; right: 0; bottom: 0; overflow: auto; }
#table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-variant-numeric: tabular-nums; }
#table th, #table td { padding: 6px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-1); text-align: right; cursor: pointer; user-select: none;
  font: 600 11px/1.4 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted);
  border-bottom-color: var(--line-strong);
}
#table thead th:hover { color: var(--text-primary); }
#table thead th.txt, #table td.txt { text-align: left; }
#table td { text-align: right; color: var(--text-secondary); }
#table td.zero { color: var(--text-faint); }
#table th.sorted { color: var(--text-primary); }
#table th.sorted::after { content: " ↓"; color: var(--accent); }
#table th.sorted.asc::after { content: " ↑"; }
#table th.cur, #table td.cur { background: var(--accent-soft); color: var(--text-primary); }
#table tbody tr { cursor: pointer; }
#table tbody tr:hover td { background: var(--surface-2); }
#table tr.total td { position: sticky; top: 31px; z-index: 1; background: var(--surface-1); font-weight: 600; color: var(--text-primary); border-bottom-color: var(--line-strong); }
#table td.name { color: var(--text-primary); position: sticky; left: 0; background: var(--surface-0); }
#table thead th.name { position: sticky; left: 0; z-index: 3; }
#table tr.total td.name { z-index: 2; background: var(--surface-1); }
#table td.crops { color: var(--text-muted); max-width: 360px; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1280px) {
  :root { --left-w: 212px; --right-w: 292px; }
  .field select { width: 140px; }
  .field select.version { width: 160px; }
}
