/* =============================================================
   Falakus — geospatial dashboard stylesheet
   Pure CSS. No remote fonts, images or imports.

   Markup contract
   ---------------
   header.app-header
     #brand-icon · .brand · .brand-subtitle · .header-meta
   main.workspace
     aside.panel
       .eyebrow · .section-title · .tabs > .tab · .controls
       .field > label · .grid-two · .metric-grid > .metric
       .status · .legend · .exports
     .map-stage
       #map                         (absolute fill)
       .map-top    > .map-badge, .map-counter
       .map-bottom > .map-key, .timeline > .timeline-tools
       .chart · #map-status · .year-stamp   (direct children of .map-stage)

   Design tokens are exposed as custom properties so the map layer
   can reuse them, e.g. getComputedStyle(root).getPropertyValue('--loss-fill').
   ============================================================= */

/* ---------- 1. Tokens ---------------------------------------- */
:root {
  color-scheme: light;

  /* Juniper — primary, very dark green */
  --juniper-950: #0b1a14;
  --juniper-900: #11261e;
  --juniper-800: #1a3830;
  --juniper-600: #3c5f51;
  --juniper-500: #557a6a;

  /* Ivory — off-white surfaces */
  --ivory-50: #fdfbf4;
  --ivory-100: #f8f5ea;
  --ivory-200: #f1ecdc;
  --ivory-300: #e4dcc6;

  /* Forest-loss coral */
  --loss-fill: #e4674d;
  --coral-deep: #b03f2a;          /* text / strong accents on ivory (≈7:1) */
  --coral-wash: #f7dcd3;

  /* Ink and lines */
  --ink: var(--juniper-950);
  --ink-soft: #3d4e46;
  --ink-muted: #5b6b63;           /* ≈5.3:1 on ivory */
  --line: #d8d1bb;
  --line-soft: #e8e2d0;
  --paper: #fffdf7;

  /* Elevation — quiet */
  --shadow-sm: 0 1px 2px rgb(11 26 20 / 0.06);
  --shadow-md: 0 1px 2px rgb(11 26 20 / 0.05), 0 12px 28px -18px rgb(11 26 20 / 0.32);
  --glass: rgb(253 251 244 / 0.94);

  /* Type */
  --font-ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
             "Helvetica Neue", Arial, sans-serif;
  --font-serif: ui-serif, "Iowan Old Style", "Charter", "Georgia",
                "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Geometry */
  --header-h: 56px;
  --panel-w: clamp(360px, 25vw, 400px);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --focus-ring: 0 0 0 2px var(--ivory-50), 0 0 0 4px var(--juniper-900);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ---------- 2. Base ------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--ivory-100);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

output {
  font-variant-numeric: tabular-nums;
}

/* Focus: visible everywhere, double ring so it survives dark and light surfaces */
:where(a, button, input, select, textarea, [tabindex]):focus {
  outline: none;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--juniper-900);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* The skip target is a container, not a control: no ring around the whole panel */
#controls:focus-visible {
  outline: none;
  box-shadow: none;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--juniper-900);
  color: var(--ivory-50);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus-visible {
  top: 12px;
}

/* ---------- 3. Header ---------------------------------------- */
.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--header-h);
  padding: 0 18px;
  background: var(--ivory-50);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

#brand-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--juniper-900);
  color: var(--ivory-50);
}

#brand-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1;
  color: var(--juniper-900);
  white-space: nowrap;
}

.brand-subtitle {
  min-width: 0;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  white-space: nowrap;
}

.header-meta > * + * {
  padding-left: 16px;
  border-left: 1px solid var(--line-soft);
}

/* ---------- 4. Workspace shell ------------------------------- */
.workspace {
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
}

/* ---------- 5. Side panel ------------------------------------ */
.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  min-height: 0;
  padding: 20px 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--ivory-50);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--ivory-300) transparent;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--coral-deep);
}

.section-title {
  margin-top: 4px;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--juniper-950);
}

/* Sections separated by hairlines when the markup uses <section> */
.panel > section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.panel > section:first-child {
  padding-top: 0;
  border-top: 0;
}

.panel h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* Tabs — segmented control */
.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
  grid-auto-flow: row;
  gap: 2px;
  padding: 3px;
  background: var(--ivory-200);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tab {
  min-height: 34px;
  padding: 7px 9px;
  white-space: nowrap;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}

.tab:hover {
  color: var(--juniper-900);
  background: rgb(255 253 247 / 0.7);
}

.tab[aria-selected="true"],
.tab[aria-pressed="true"],
.tab.is-active,
.tab[aria-current="true"] {
  background: var(--juniper-900);
  color: var(--ivory-50);
  box-shadow: var(--shadow-sm);
}

.tab[aria-selected="true"]:focus-visible,
.tab.is-active:focus-visible {
  outline-color: var(--juniper-900);
}

/* Controls and fields */
.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* Control grouping: choose-data block, then results block */
#comparison-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#comparison-controls > label:not(.field) {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

#metrics {
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

#metrics:empty {
  display: none;
}

.field > label,
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea,
.controls input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
.controls select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--ink);
  transition: border-color 160ms var(--ease);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--ink-muted);
  opacity: 0.8;
}

.field input:hover,
.field select:hover,
.controls input:hover,
.controls select:hover {
  border-color: var(--juniper-500);
}

.field input:focus,
.field select:focus,
.controls input:focus,
.controls select:focus {
  border-color: var(--juniper-900);
  outline: none;
}

/* Native range/checkbox tinted to the primary without custom markup */
input[type="range"] {
  accent-color: var(--juniper-900);
  width: 100%;
  margin: 6px 0;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--juniper-900);
  width: 16px;
  height: 16px;
  margin: 0;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Metrics */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 12px 12px 11px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.metric > span,
.metric-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric > strong,
.metric-value {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--juniper-950);
  font-variant-numeric: lining-nums tabular-nums;
  overflow-wrap: anywhere;
}

.metric > small,
.metric-delta {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.metric[data-tone="loss"] {
  border-left: 3px solid var(--loss-fill);
}

.metric[data-tone="loss"] .metric-value {
  color: var(--coral-deep);
}

/* Status line */
.status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 9px 12px;
  background: var(--ivory-100);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--ink-soft);
}

.status::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--juniper-500);
}

.status[data-state="loading"]::before {
  background: var(--loss-fill);
  animation: status-pulse 1.1s ease-in-out infinite;
}

.status[data-state="error"] {
  color: var(--coral-deep);
  background: var(--coral-wash);
  border-color: transparent;
}

.status[data-state="error"]::before {
  background: var(--coral-deep);
}

/* Evidence sentence: larger and airier so it reads at a glance */
#evidence {
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.5;
}

#evidence::before {
  margin-top: 0.42em;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}

/* Legend */
.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li,
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.swatch,
.legend-swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--ivory-300);
  box-shadow: inset 0 0 0 1px rgb(11 26 20 / 0.12);
}

.swatch--loss,
.legend [data-class="loss"] .swatch,
.map-key [data-class="loss"] .swatch {
  background: var(--loss-fill);
  box-shadow: none;
}

.swatch--stable,
.legend [data-class="stable"] .swatch,
.map-key [data-class="stable"] .swatch {
  background: var(--juniper-600);
  box-shadow: none;
}

.swatch--gain,
.legend [data-class="gain"] .swatch,
.map-key [data-class="gain"] .swatch {
  background: var(--ivory-200);
  box-shadow: inset 0 0 0 1px var(--juniper-500);
}

/* Buttons and exports */
.exports {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.exports a,
.exports button,
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  line-height: 1.25;
  min-height: 40px;
  padding: 9px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--juniper-900);
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}

.exports a:hover,
.exports button:hover,
.btn:hover {
  background: var(--ivory-200);
  border-color: var(--juniper-500);
}

.exports a:active,
.exports button:active,
.btn:active {
  transform: translateY(1px);
}

.exports :is(a, button):first-child,
.btn--primary {
  background: var(--juniper-900);
  border-color: var(--juniper-900);
  color: var(--ivory-50);
}

.exports :is(a, button):first-child:hover,
.btn--primary:hover {
  background: var(--juniper-800);
  border-color: var(--juniper-800);
}

.exports :is(a, button):first-child:focus-visible,
.btn--primary:focus-visible {
  outline-color: var(--juniper-900);
}

/* ---------- 6. Map stage ------------------------------------- */
.map-stage {
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--ivory-300);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  background: var(--ivory-200);
}

/* Overlay base: every overlay floats above the map */
.map-top,
.map-bottom,
.map-badge,
.map-key,
.timeline,
.timeline-tools,
.chart,
#map-status,
.map-counter,
.year-stamp {
  position: absolute;
  z-index: 2;
}

/* Frosted-glass card shared by overlays */
.map-badge,
.map-counter,
.map-key,
.timeline,
.chart,
#map-status {
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}

@supports (backdrop-filter: blur(1px)) {
  .map-badge,
  .map-counter,
  .map-key,
  .timeline,
  .chart,
  #map-status {
    -webkit-backdrop-filter: blur(10px) saturate(1.1);
    backdrop-filter: blur(10px) saturate(1.1);
  }
}

/* Top band: badge on the left, counter on the right */
.map-top {
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}

.map-top > * {
  pointer-events: auto;
}

.map-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border-color: var(--juniper-900);
  background: var(--juniper-900);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ivory-50);
}

.map-counter {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin-left: auto;
  padding: 7px 11px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* Editorial year stamp, decorative */
.year-stamp {
  left: 16px;
  top: 64px;
  font-family: var(--font-serif);
  font-size: 52px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--juniper-950);
  font-variant-numeric: lining-nums tabular-nums;
  padding: 4px 10px 6px;
  background: var(--glass);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

.year-stamp:empty {
  display: none;
}

/* Live status pill (filled by JS) */
#map-status {
  right: 14px;
  top: 66px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}

#map-status:empty {
  display: none;
}

/* Chart card, top-right beneath the status pill */
.map-stage > .chart {
  top: 104px;
  right: 14px;
  width: min(300px, 34%);
  padding: 12px 12px 10px;
  border-radius: var(--radius);
}

.chart figcaption,
.chart h3 {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart text {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--ink-muted);
}

.chart .axis,
.chart .grid-line {
  stroke: var(--line-soft);
  stroke-width: 1;
}

.chart .series-loss,
.chart .bar-loss {
  fill: var(--loss-fill);
  stroke: var(--loss-fill);
}

.chart .series-base {
  fill: none;
  stroke: var(--juniper-600);
  stroke-width: 1.5;
}

/* Bottom band: key and timeline stacked */
.map-bottom {
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  pointer-events: none;
}

.map-bottom > * {
  pointer-events: auto;
}

.map-key {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding: 7px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--ink-soft);
}

.map-key .legend-item,
.map-key > span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

/* Timeline */
.timeline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
}

.timeline input[type="range"] {
  flex: 1 1 240px;
  min-width: 0;
  margin: 0;
}

.timeline output {
  min-width: 4ch;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
  text-align: right;
  color: var(--juniper-950);
}

.timeline-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.timeline-tools button {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--juniper-900);
  border-radius: 999px;
  background: var(--juniper-900);
  color: var(--ivory-50);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 160ms var(--ease);
}

.timeline-tools button:hover {
  background: var(--juniper-800);
}

.timeline-tools button[aria-pressed="true"] {
  background: var(--loss-fill);
  border-color: var(--loss-fill);
  color: var(--juniper-950);
}

.timeline-tools button:focus-visible {
  outline-color: var(--juniper-900);
}

/* Overlay children are laid out by their parent band, not absolutely */
.map-top .map-badge,
.map-top .map-counter,
.map-bottom .map-key,
.map-bottom .timeline,
.map-bottom .chart,
.timeline .timeline-tools {
  position: static;
}

/* Map canvas controls (Leaflet/MapLibre) sit above the overlays' glass
   but below the header; keep them legible on ivory */
.map-stage .leaflet-control-zoom a,
.map-stage .maplibregl-ctrl-group button {
  color: var(--juniper-900);
}

/* ---------- 7. Responsive: tablet and mobile ----------------- */
@media (max-width: 1100px) {
  :root {
    --panel-w: 330px;
  }

  .brand-subtitle {
    display: none;
  }

  .header-meta > :nth-child(n + 3) {
    display: none;
  }
}

/* Short desktop viewports (e.g. 1366x768 browser chrome) */
@media (min-width: 901px) and (max-height: 820px) {
  .panel {
    gap: 14px;
    padding: 16px 20px 18px;
  }

  .panel > section {
    gap: 10px;
    padding-top: 14px;
  }

  .section-title {
    font-size: 20px;
  }

  .metric {
    padding: 10px 11px 9px;
  }

  .metric > strong,
  .metric-value {
    font-size: 21px;
  }

  .map-stage > .chart {
    top: 98px;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
    height: auto;
  }

  .app-header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    row-gap: 6px;
    padding: 10px 14px;
  }

  .brand-subtitle {
    display: block;
    order: 3;
    width: 100%;
    padding-left: 0;
    border-left: 0;
    white-space: normal;
  }

  .header-meta {
    order: 4;
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
    gap: 8px;
    font-size: 10.5px;
  }

  .header-meta > * + * {
    padding-left: 0;
    border-left: 0;
  }

  .header-meta > :nth-child(n + 3) {
    display: inline;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    height: auto;
    min-height: calc(100dvh - var(--header-h));
  }

  /* Map leads on small screens; panel follows as a scrollable sheet */
  .map-stage {
    order: -1;
    height: 64vh;
    height: 64dvh;
    min-height: 430px;
    max-height: 640px;
  }

  .panel {
    overflow: visible;
    padding: 18px 16px 32px;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .year-stamp {
    top: 58px;
    font-size: 38px;
  }

  .map-stage > .chart {
    top: 104px;
    width: 150px;
    padding: 8px 9px;
  }

  .chart figcaption,
  .chart h3 {
    font-size: 10px;
    margin-bottom: 4px;
  }

  #map-status {
    top: 60px;
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .timeline {
    padding: 8px 10px;
  }

  .timeline-tools button {
    min-width: 40px;
    height: 40px;
  }

  .map-key {
    gap: 4px 12px;
  }
}

@media (max-width: 560px) {
  .map-top {
    gap: 8px;
  }

  .map-badge {
    font-size: 11.5px;
    padding: 6px 10px;
  }

  .map-counter {
    min-height: 40px;
    font-size: 10.5px;
    padding: 6px 9px;
  }

  .map-stage > .chart {
    width: 132px;
  }

  .map-key {
    font-size: 11.5px;
  }

  .timeline {
    gap: 8px 10px;
  }

  .timeline input[type="range"] {
    flex-basis: 100%;
    order: -1;
    height: 32px;
  }

  .timeline output {
    margin-left: auto;
  }

  .grid-two {
    grid-template-columns: minmax(0, 1fr);
  }

  .exports {
    grid-template-columns: minmax(0, 1fr);
  }

  .exports a,
  .exports button,
  .btn {
    min-height: 44px;
  }

  .tab {
    min-height: 44px;
  }

  /* Disclosure summaries and checkbox rows as full-width touch targets */
  .panel summary,
  #comparison-controls > label:not(.field) {
    min-height: 44px;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--ivory-200);
  }

  .field input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
  .field select,
  .controls input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
  .controls select {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
}

/* ---------- 8. Preferences and system modes ------------------ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: #8f8770;
    --line-soft: #b9b29a;
    --ink-muted: #3f4c45;
  }
}

@media (forced-colors: active) {
  .swatch,
  .legend-swatch,
  .metric,
  .status,
  .map-badge,
  .map-counter,
  .map-key,
  .timeline,
  .chart,
  #map-status,
  .tabs,
  .panel,
  .exports button,
  .btn {
    border: 1px solid CanvasText;
    box-shadow: none;
  }

  .tab[aria-selected="true"],
  .tab[aria-pressed="true"],
  .exports button:first-child,
  .timeline-tools button {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }

  :where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid Highlight;
    box-shadow: none;
  }
}

@media print {
  body {
    overflow: visible;
    background: #fff;
  }

  .workspace {
    height: auto;
    display: block;
  }

  .map-stage {
    height: 90vh;
  }

  .panel,
  .app-header {
    box-shadow: none;
  }
}
