:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --plane: #f3f2ef;
  --map-bg: #f6f5f2;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.12);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --a: #2a78d6;
  --b: #d95926;
  --focus: #2a78d6;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #1a1a19;
    --plane: #0f0f0e;
    --map-bg: #141413;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9c9b94;
    --line: #2c2c2a;
    --axis: #45453f;
    --ring: rgba(255, 255, 255, 0.12);
    --accent: #3987e5;
    --a: #3987e5;
    --b: #e0703f;
    --focus: #86b6ef;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19;
  --plane: #0f0f0e;
  --map-bg: #141413;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9c9b94;
  --line: #2c2c2a;
  --axis: #45453f;
  --ring: rgba(255, 255, 255, 0.12);
  --accent: #3987e5;
  --a: #3987e5;
  --b: #e0703f;
  --focus: #86b6ef;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--plane); color: var(--ink); font-size: 14px; line-height: 1.4; display: flex; flex-direction: column; overflow: hidden; }
abbr[title] { text-decoration: underline dotted; cursor: help; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.title { font-size: 16px; margin: 0; font-weight: 650; margin-right: auto; }
.subtitle { font-weight: 400; color: var(--ink-2); }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: var(--radius); overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 5px 10px; color: var(--ink-2); white-space: nowrap; }
.seg label + label span { border-left: 1px solid var(--axis); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -3px; }
.icon-btn, .btn { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: var(--radius); padding: 5px 10px; cursor: pointer; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.link-btn { font: inherit; background: none; border: 0; color: var(--accent); padding: 4px 0; cursor: pointer; text-decoration: underline; }
.only-narrow { display: none; }

.banner { background: #fff4d6; color: #4a3500; padding: 6px 14px; border-bottom: 1px solid #ecd9a0; font-size: 13px; }
:root[data-theme="dark"] .banner { background: #3a2f12; color: #f6e2a6; border-color: #5a4a1d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3a2f12; color: #f6e2a6; border-color: #5a4a1d; } }

/* ---------------------------------------------------------------- layout */
.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
.panel { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; background: var(--plane); border-right: 1px solid var(--line); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card h2 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; color: var(--ink-2); font-size: 13px; }
.field select, .stepper select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: 6px; padding: 4px 6px; width: 100%; }
.stepper { display: flex; gap: 4px; }
.step { font: inherit; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); border-radius: 6px; padding: 0 8px; cursor: pointer; }
.step:disabled { opacity: 0.4; cursor: default; }
.check { display: flex; gap: 6px; align-items: flex-start; margin: 6px 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.badge { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 4px; color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 0; }
.badge-a { background: var(--a); }
.badge-b { background: var(--b); }

/* legend */
.legend-bar { height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--ring); }
.legend-ticks { position: relative; height: 18px; font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend-ticks span { position: absolute; transform: translateX(-50%); top: 2px; white-space: nowrap; }
.legend-ticks span:first-child { transform: none; }
.legend-ticks span:last-child { transform: translateX(-100%); }
.legend-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); }
.legend-title { font-size: 13px; margin-bottom: 4px; }
.legend-unit { color: var(--muted); }
.swatch-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.swatch { width: 22px; height: 0; border-top: 3px solid var(--sw); }
.swatch.dashed { border-top-style: dashed; }

/* details */
.details-title { font-weight: 600; margin: 0 0 2px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 56px; display: block; }
.spark-caption { font-size: 11px; color: var(--muted); }

/* ---------------------------------------------------------------- maps */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.maps { position: relative; flex: 1; min-height: 200px; background: var(--map-bg); }
.map { position: absolute; inset: 0; }
.maps.mode-side .map#mapA { right: 50%; border-right: 1px solid var(--line); }
.maps.mode-side .map#mapB { left: 50%; }
.swipe { position: absolute; top: 0; bottom: 0; width: 0; z-index: 5; cursor: ew-resize; touch-action: none; }
.swipe::before { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: var(--ink); opacity: 0.7; }
.swipe .grip { position: absolute; top: 50%; left: -14px; width: 28px; height: 40px; margin-top: -20px; border-radius: 6px; background: var(--surface); border: 1px solid var(--axis); box-shadow: var(--shadow); }
.swipe .grip::before { content: "\2039\00a0\203A"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); font-size: 16px; }
.map-tag { position: absolute; top: 8px; z-index: 4; padding: 2px 8px; border-radius: 4px; color: #fff; font-weight: 700; font-size: 12px; pointer-events: none; }
.tag-a { left: 8px; background: var(--a); }
.tag-b { right: 8px; background: var(--b); }
.maps.mode-side .tag-b { left: calc(50% + 8px); right: auto; }
.maps.mode-swipe .tag-b { right: 52px; }
.tooltip { position: absolute; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px; padding: 4px 8px; font-size: 12px; box-shadow: var(--shadow); max-width: 260px; }
.status { position: absolute; left: 8px; bottom: 8px; z-index: 4; font-size: 12px; color: var(--ink-2); background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 2px 6px; border-radius: 4px; }
.status:empty { display: none; }
/* what changed, on the difference map (top left, under the B − A tag) */
.diff-summary { position: absolute; left: 8px; top: 36px; z-index: 6; width: min(340px, calc(100% - 64px)); max-height: calc(100% - 90px); overflow: auto;
  background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--axis); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 10px; font-size: 13px; }
.diff-summary summary { cursor: pointer; font-weight: 700; }
.diff-summary p { margin: 6px 0 0; }
.diff-summary h3 { font-size: 12px; margin: 10px 0 2px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.diff-summary h3 .hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.diff-summary ul { list-style: none; margin: 0; padding: 0; }
.diff-summary li { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.diff-summary li .link-btn { padding: 2px 0; text-align: left; }
.diff-summary .chg { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.diff-summary .chg.up { color: #b8461f; }
.diff-summary .chg.down { color: #2f6db5; }
.maplibregl-ctrl-attrib { font-size: 11px; }
.target-marker { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--ink); }
.origin-marker { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--ink); }

/* ---------------------------------------------------------------- timeline */
.timeline { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 14px 10px; }
.tl-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-time { font-size: 18px; font-weight: 650; min-width: 9.5em; font-variant-numeric: tabular-nums; }
.tl-chart { position: relative; margin-top: 6px; height: 74px; }
.tl-chart svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.tl-range { position: absolute; left: 0; right: 0; bottom: -4px; width: 100%; margin: 0; accent-color: var(--accent); }
.tl-marker { position: absolute; top: 0; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; border: 2px solid var(--surface); cursor: pointer; padding: 0; z-index: 2; box-shadow: 0 0 0 1px var(--ink-2); }
.tl-marker.auto { background: var(--ink-2); }
.tl-marker.scenario { background: var(--b); border-radius: 2px; }
.tl-marker.compare { background: var(--a); transform: rotate(45deg); border-radius: 2px; }
.tl-caption { font-size: 11px; color: var(--muted); }
.tl-bookmarks { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 0; scrollbar-width: thin; }
.chip { font: inherit; font-size: 12px; white-space: nowrap; border: 1px solid var(--axis); border-radius: 999px; padding: 2px 10px; background: var(--surface); color: var(--ink); cursor: pointer; }
.chip[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .k { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: var(--ink-2); }
.chip .k.scenario { background: var(--b); border-radius: 1px; }
.chip .k.compare { background: var(--a); border-radius: 1px; transform: rotate(45deg); }
.tl-legend { display: flex; gap: 12px; font-size: 11px; color: var(--ink-2); }
.tl-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--a); vertical-align: middle; margin-right: 4px; }
.tl-legend i.b { border-top: 2px dashed var(--b); }

/* about */
dialog { border: 1px solid var(--axis); border-radius: 10px; background: var(--surface); color: var(--ink); max-width: min(720px, 92vw); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.about { padding: 16px 20px; max-height: 80vh; overflow-y: auto; }
.about h2 { margin-top: 0; }
.about h3 { font-size: 14px; margin: 14px 0 4px; }
.about p, .about li { font-size: 13px; color: var(--ink-2); }

/* ---------------------------------------------------------------- narrow screens */
@media (max-width: 760px) {
  .only-narrow { display: inline-block; }
  .title { font-size: 14px; flex-basis: calc(100% - 180px); }
  .subtitle { display: none; }
  .topbar { padding: 6px 10px; gap: 6px; }
  .seg span { padding: 4px 7px; font-size: 13px; }
  .layout { grid-template-columns: 1fr; position: relative; }
  .panel { position: absolute; z-index: 20; inset: 0 auto 0 0; width: min(330px, 88vw); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform 0.2s; }
  .panel.open { transform: none; }
  .maps.mode-side .map#mapA { right: 0; bottom: 50%; border-right: 0; border-bottom: 1px solid var(--line); }
  .maps.mode-side .map#mapB { left: 0; top: 50%; }
  .maps.mode-side .tag-b { left: 8px; top: calc(50% + 8px); }
  .tl-time { font-size: 15px; min-width: 0; }
  .tl-chart { height: 56px; }
  .timeline { padding: 6px 10px 8px; }
}
@media (prefers-reduced-motion: reduce) { .panel { transition: none; } }
