:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface-1: #fcfcfb;
  --surface-2: #efeee9;
  --border: #e2e0d8;
  --grid: #e7e5de;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --accent: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --neutral: #a9a79f;
  --seq-0: #cde2fb;
  --seq-1: #104281;
  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --neutral: #6d6c66;
    --seq-0: #1d2a3a;
    --seq-1: #86b6ef;
    --good: #4ac26b;
    --warn: #d29922;
    --bad: #f47067;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --grid: #2a2a28;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --neutral: #6d6c66;
  --seq-0: #1d2a3a;
  --seq-1: #86b6ef;
  --good: #4ac26b;
  --warn: #d29922;
  --bad: #f47067;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.55 Inter, system-ui, -apple-system, sans-serif;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 6px; }
h3 { font-size: 15px; font-weight: 600; }
h3.group { margin: 28px 0 12px; font-size: 17px; }
code { font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.hero { padding: 48px 0 32px; border-bottom: 1px solid var(--border); background: var(--surface-1); }
.eyebrow { color: var(--accent); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 10px; }
.lede { color: var(--text-secondary); max-width: 760px; font-size: 17px; margin: 12px 0 28px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.tile .num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.tile .lbl { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.toc { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--surface-1) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.toc .wrap { display: flex; gap: 4px; overflow-x: auto; padding-top: 8px; padding-bottom: 8px; scrollbar-width: none; }
.toc a { color: var(--text-secondary); text-decoration: none; font-size: 13px; font-weight: 500; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.toc a:hover { background: var(--surface-2); color: var(--text-primary); }

section { padding: 44px 0 8px; scroll-margin-top: 50px; }
.note { color: var(--text-secondary); font-size: 14px; max-width: 820px; margin: 4px 0 18px; }
.sub { color: var(--text-muted); font-size: 13px; margin: 2px 0 12px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 16px; min-width: 0; }
.grid .card { margin-bottom: 0; }
.grid + .card, .card + .grid { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.chart { position: relative; height: 260px; }
.chart.sm { height: 200px; }
.chart.lg { height: 340px; }
.chart.tall { height: 380px; }

details.datatable { margin-top: 10px; }
details.datatable summary { cursor: pointer; color: var(--text-muted); font-size: 12px; }
details.datatable .table-scroll { max-height: 260px; overflow: auto; margin-top: 8px; }

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface-1); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.inv td:first-child { font-weight: 600; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.have { color: var(--good); }
.status.partial { color: var(--warn); }
.status.missing { color: var(--text-muted); }
.status.missing::before { background: transparent; border: 1.5px solid currentColor; }

.map-wrap { position: relative; }
#elev-map { width: 100%; display: block; border-radius: 8px; image-rendering: pixelated; }
.tip { position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12px; display: none; box-shadow: 0 4px 12px rgba(0,0,0,.12); white-space: nowrap; }
.ramp-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.ramp-legend .bar { flex: 1; height: 8px; border-radius: 4px; max-width: 260px; }
.field { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.field h4 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.field .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.field p { margin: 0; color: var(--text-secondary); font-size: 13px; }
.field .coords { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.select { font-size: 13px; color: var(--text-secondary); display: flex; gap: 8px; align-items: center; }
select { font: inherit; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg button { font: inherit; font-size: 13px; font-weight: 500; border: 0; background: transparent; color: var(--text-secondary); padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font: inherit; font-size: 12px; font-weight: 500; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary); border-radius: 999px; padding: 4px 10px 4px 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip .sw { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid currentColor; }
.chip.on { color: var(--text-primary); border-color: var(--text-muted); }

.strip { display: grid; gap: 2px; font-size: 11px; color: var(--text-muted); min-width: 560px; }
.strip .row { display: grid; grid-template-columns: 40px repeat(23, 1fr); gap: 2px; align-items: center; }
.strip .cell { height: 14px; border-radius: 2px; }
.strip .axis { display: grid; grid-template-columns: 40px repeat(12, 1fr); margin-top: 4px; }

.gaps { padding-left: 18px; color: var(--text-secondary); max-width: 860px; }
.gaps li { margin-bottom: 8px; }
.gaps b { color: var(--text-primary); }
.disclaimer { border-left: 3px solid var(--accent); padding: 8px 14px; background: var(--surface-1); border-radius: 0 8px 8px 0; color: var(--text-secondary); max-width: 820px; }
footer { border-top: 1px solid var(--border); margin-top: 40px; padding: 24px 0 40px; color: var(--text-muted); font-size: 12px; }
footer a { color: var(--text-secondary); }

@media (max-width: 860px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .wrap { padding: 0 16px; }
  .chart { height: 230px; }
  .chart.lg, .chart.tall { height: 300px; }
  .hero { padding-top: 32px; }
}

/* region picker, country map */
.region-pick { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-primary); padding-right: 8px; margin-right: 4px; border-right: 1px solid var(--border); white-space: nowrap; }
.metric-pick { margin-bottom: 14px; flex-wrap: wrap; }
.metric-pick select { max-width: 100%; }
#uz-map { width: 100%; height: auto; display: block; }
#uz-map .rg { stroke: var(--surface-1); stroke-width: 6; stroke-linejoin: round; }
#uz-map .rg.click { cursor: pointer; }
#uz-map .rg.click:hover { stroke: var(--text-muted); }
#uz-map .rg.sel { stroke: var(--text-primary); stroke-width: 9; }
#uz-map .pt { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 4; cursor: pointer; }
#uz-map .pt.sel { fill: var(--series-2); }
.region-banner { margin-top: 36px; padding: 18px 20px; border-radius: 14px; background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--series-2); position: relative; }
.region-banner h2 { margin-bottom: 2px; }
.region-banner .note { margin-bottom: 0; }

/* SMAP map images */
.smap-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.smap-grid figure { margin: 0; }
.smap-grid svg { width: 100%; height: auto; display: block; border-radius: 8px; background: var(--surface-2); }
.smap-grid figcaption { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.smap-outline { fill: none; stroke: #111; stroke-opacity: 0.55; stroke-width: 4; stroke-linejoin: round; }
.smap-pt { fill: var(--series-2); stroke: #fff; stroke-width: 4; }
.smap-legend img { max-width: 100%; height: auto; margin-top: 10px; background: #fff; border-radius: 6px; }
@media (max-width: 520px) { .smap-grid { grid-template-columns: 1fr; } }

/* salinity and water */
.region-summary { font-size: 15px; max-width: 860px; margin: 0 0 18px; padding: 12px 16px; border-radius: 10px; background: var(--surface-1); border: 1px solid var(--border); }
#ss-map { width: 100%; display: block; border-radius: 8px; }

/* What to plant next (advisor.js) */
.field-map { height: 280px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 10px; z-index: 0; }
.adv-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.btn { font: inherit; font-size: 13px; font-weight: 500; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--text-muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 14px; margin-top: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; }
.rec { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.rec h4 { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 0 0 2px; font-size: 16px; }
.rec .score { font-size: 12px; font-weight: 600; color: var(--text-secondary); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.rec .when { font-size: 13px; color: var(--text-secondary); margin: 0 0 6px; }
.rec ul { margin: 6px 0 8px 18px; padding: 0; font-size: 13px; color: var(--text-secondary); }
.rec li.risk { color: var(--warn); }
.rec .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rec .meta b { color: var(--text-primary); font-weight: 600; }
.excluded { color: var(--text-muted); }
