/* ---------- Tokens: the Round City palette, by day and by night ---------- */
:root {
  --stone: #E7E4DC;   /* limestone: the ground */
  --sheet: #F1EFEA;
  --ink: #0B2A30;     /* night river: text */
  --muted: #4E6468;
  --rule: #C8C5BC;
  --tigris: #0F5C63;  /* the river: links, buttons, the U-Net */
  --on-tigris: #FFFFFF;
  --brick: #C9A66B;   /* Abbasid brick: small marks only */
  --night: #0B2A30;   /* frames behind images */
  --water: #6FBFC6;   /* water drawn on the satellite image */

  --step--1: .875rem;
  --step-0: 1.0625rem;
  --step-1: 1.3125rem;
  --step-2: 1.75rem;
  --step-hero: clamp(2.5rem, 7vw, 5.25rem);

  --gutter: clamp(16px, 4vw, 48px);
  --max: 1180px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --stone: #0A2226; --sheet: #0F2E33; --ink: #E7E4DC; --muted: #9DB3B1; --rule: #20454B;
    --tigris: #6FBFC6; --on-tigris: #0A2226; --brick: #D2B27A; --night: #051518;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --stone: #0A2226; --sheet: #0F2E33; --ink: #E7E4DC; --muted: #9DB3B1; --rule: #20454B;
  --tigris: #6FBFC6; --on-tigris: #0A2226; --brick: #D2B27A; --night: #051518;
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--stone);
  color: var(--ink);
  font-family: "Readex Pro", system-ui, sans-serif;
  font-size: var(--step-0);
  font-weight: 300;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}
a { color: var(--tigris); text-underline-offset: 3px; }
:focus-visible { outline: 2.5px solid var(--tigris); outline-offset: 3px; border-radius: 4px; }
.skip { position: absolute; inset-inline-start: 12px; top: -60px; background: var(--ink); color: var(--stone); padding: 8px 14px; border-radius: 6px; z-index: 2000; }
.skip:focus { top: 12px; }
h1, h2, h3 { font-weight: 500; }
strong { font-weight: 500; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px max(var(--gutter), calc((100% - var(--max)) / 2 + var(--gutter)));
  background: var(--stone);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 500; }
.mark { width: 36px; height: 36px; color: var(--tigris); flex: none; }
.bar-nav { display: flex; align-items: center; gap: clamp(12px, 2.6vw, 26px); font-size: var(--step--1); font-weight: 400; }
.bar-nav a { color: var(--ink); text-decoration: none; border-bottom: 1px solid transparent; }
.bar-nav a:hover { border-color: var(--ink); }
.theme {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--rule); border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer;
}
.theme svg { width: 18px; height: 18px; }
.theme:hover { border-color: var(--ink); }
@media (max-width: 640px) { .bar-nav a { display: none; } }

/* ---------- Hero ---------- */
.hero { max-width: var(--max); margin: 0 auto; padding: clamp(36px, 7vw, 88px) var(--gutter) clamp(28px, 4vw, 48px); }
.eyebrow { margin: 0 0 14px; color: var(--muted); font-size: var(--step--1); font-weight: 400; letter-spacing: .04em; }
.hero h1 { margin: 0; max-width: 12em; font-size: var(--step-hero); line-height: 1.04; letter-spacing: -.025em; font-weight: 500; }
.lede { margin: 20px 0 0; max-width: 36em; font-size: var(--step-1); line-height: 1.65; }
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1px;
  margin: clamp(28px, 4vw, 44px) 0 0; background: var(--rule); border: 1px solid var(--rule);
}
.stats > div { background: var(--stone); padding: 18px 20px 20px; }
.stats dt { color: var(--muted); font-size: var(--step--1); font-weight: 400; line-height: 1.4; }
.stats dd { margin: 6px 0 0; font-size: clamp(2rem, 4.2vw, 2.9rem); font-weight: 500; line-height: 1.05; letter-spacing: -.02em; }
.stats dd small { display: block; margin-top: 6px; color: var(--muted); font-size: var(--step--1); font-weight: 300; letter-spacing: 0; }
.stats > div:nth-child(2) dd { color: var(--tigris); }

/* ---------- Sections ---------- */
.block { max-width: var(--max); margin: 0 auto; padding: clamp(40px, 6vw, 72px) var(--gutter) 0; }
.block-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px;
  padding-bottom: 16px; margin-bottom: 20px; border-bottom: 1.5px solid var(--ink);
}
.block h2 { margin: 0; font-size: var(--step-2); line-height: 1.2; }
.block h3 { margin: 32px 0 10px; font-size: var(--step-1); }
.body-text { max-width: 44em; margin: 0 0 20px; }
.note { margin: 12px 0 0; max-width: 52em; color: var(--muted); font-size: var(--step--1); line-height: 1.6; }

/* Chips and pickers: pill controls that fill with ink */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--rule); background: transparent; color: var(--ink); border-radius: 999px;
  padding: 5px 14px; font: inherit; font-size: var(--step--1); font-weight: 400; cursor: pointer;
  transition: background .15s ease-out, color .15s ease-out, border-color .15s ease-out;
}
.chips button:hover { border-color: var(--ink); }
.chips button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--stone); }
.toggles button[aria-pressed="true"] { background: transparent; border-color: var(--ink); color: var(--ink); }
.toggles button[aria-pressed="false"] { color: var(--muted); }
.toggles button[aria-pressed="false"] .swatch { opacity: .35; }
.chips .swatch { width: 18px; height: 0; border-top: 2.5px solid currentColor; }
.pick { display: inline-flex; align-items: center; gap: 8px; font-size: var(--step--1); font-weight: 400; color: var(--muted); }
.pick select {
  appearance: none; border: 1px solid var(--rule); border-radius: 999px; background: var(--sheet); color: var(--ink);
  padding: 5px 30px 5px 14px; font: inherit; font-weight: 500; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238A9A98' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-position: right 12px center; background-size: 10px 6px; background-repeat: no-repeat;
}
.pick select:hover { border-color: var(--ink); }

/* ---------- Map ---------- */
.map-frame { position: relative; border-radius: 6px; overflow: hidden; background: var(--night); }
#map { height: min(78vh, 720px); min-height: 420px; background: var(--night); font-family: inherit; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 11px; }
.leaflet-bar a { color: #0B2A30; }
.divider {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 0; z-index: 800;
  border-left: 2px solid #E7E4DC; pointer-events: none;
}
.grip {
  position: absolute; top: 50%; left: -21px; width: 40px; height: 40px; margin-top: -20px; padding: 0;
  display: grid; place-items: center; border-radius: 50%; border: 2px solid #E7E4DC;
  background: #0B2A30; color: #E7E4DC; cursor: ew-resize; pointer-events: auto; touch-action: none;
}
.grip svg { width: 22px; height: 22px; }
.tag {
  position: absolute; top: 12px; z-index: 800; padding: 3px 12px; border-radius: 999px;
  background: #0B2A30; color: #E7E4DC; font-size: var(--step--1); font-weight: 500; pointer-events: none;
}
.tag-a { left: 12px; }
.tag-b { right: 12px; }
.tag:empty { display: none; }
.map-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; margin-top: 12px; }
.map-foot .note { margin: 0; }
.key { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none; font-size: var(--step--1); font-weight: 400; }
.key:empty { display: none; }
.key li { display: inline-flex; align-items: center; gap: 8px; }
.key i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--rule); }

/* ---------- Chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--rule); stroke-width: 1; }
.chart .axis text, .chart .end text { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .end text { fill: var(--ink); font-weight: 400; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--stone); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .picked { fill: var(--sheet); }
.tip {
  position: absolute; z-index: 5; min-width: 168px; padding: 10px 12px; pointer-events: none;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; font-size: var(--step--1); line-height: 1.5;
}
.tip b { display: block; font-weight: 500; margin-bottom: 4px; }
.tip div { display: flex; align-items: center; gap: 8px; }
.tip span { flex: 1; color: var(--muted); }
.tip i { width: 14px; border-top: 2.5px solid; }
.tip[hidden] { display: none; }

/* ---------- Tables ---------- */
.numbers { margin-top: 16px; }
.numbers summary { cursor: pointer; font-size: var(--step--1); font-weight: 400; color: var(--tigris); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 400; }
tbody th { font-weight: 500; }
.scores tr.lead th, .scores tr.lead td { color: var(--tigris); font-weight: 500; }
.ci { display: inline-block; position: relative; width: 120px; height: 10px; margin-left: 10px; vertical-align: middle; }
.ci::before { content: ""; position: absolute; left: 0; right: 0; top: 4.5px; border-top: 1px solid var(--rule); }
.ci span { position: absolute; top: 3px; height: 4px; border-radius: 2px; background: currentColor; }
.ci b { position: absolute; top: 0; width: 2px; height: 10px; margin-left: -1px; background: currentColor; }
.muted { color: var(--muted); }

.examples { margin: 32px 0 0; }
.examples img { display: block; width: 100%; max-width: 860px; height: auto; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); }
.examples figcaption { margin-top: 10px; max-width: 52em; color: var(--muted); font-size: var(--step--1); }

/* ---------- Method and limits ---------- */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1px; margin: 0; padding: 0; list-style: none; counter-reset: step; background: var(--rule); border: 1px solid var(--rule); }
.steps li { counter-increment: step; background: var(--stone); padding: 20px 22px 24px; }
.steps li::before { content: counter(step, decimal-leading-zero); color: var(--brick); font-weight: 500; font-size: var(--step--1); }
.steps h3 { margin: 6px 0 8px; font-size: var(--step-0); font-weight: 500; }
.steps p { margin: 0; font-size: var(--step--1); line-height: 1.65; }
.limits { margin: 0; padding: 0; list-style: none; max-width: 52em; }
.limits li { position: relative; padding: 10px 0 10px 24px; border-bottom: 1px solid var(--rule); }
.limits li::before { content: ""; position: absolute; left: 4px; top: 21px; width: 7px; height: 7px; background: var(--brick); transform: rotate(45deg); }

.foot { max-width: var(--max); margin: clamp(56px, 8vw, 96px) auto 0; padding: 24px var(--gutter) 40px; border-top: 1px solid var(--rule); color: var(--muted); font-size: var(--step--1); }
.foot p { margin: 0; max-width: 60em; }
@media (max-width: 640px) { #map { height: 62vh; min-height: 380px; } }
