/* Layout: full-height night map on the right; a quiet left rail of filters and totals. One dark look by choice. */
:root {
  --ground: #0d1117;
  --panel: #12171f;
  --raised: #1a2130;
  --line: #232b37;
  --ink: #e6e9ee;
  --muted: #8a94a3;
  --accent: #ffb347;
  --font-ui: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-data: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ground); color: var(--ink); font: 14px/1.4 var(--font-ui); overflow: hidden; }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; }

/* Rail */
.rail { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; min-height: 0;
  padding: 20px 18px 28px max(18px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 26px; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 12px; }
h2 { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 10px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-head h2 { margin: 0; }

.totals { display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; gap: 8px; margin: 0; }
.stat dt { font-size: 11px; color: var(--muted); }
.stat dd { margin: 0; font: 500 17px var(--font-data); font-variant-numeric: tabular-nums; }
.stat dd.sub { font: 10px var(--font-data); color: var(--muted); }

.seg { display: inline-grid; grid-auto-flow: column; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--panel); }
.seg button { background: none; border: 0; color: var(--muted); font-weight: 500; font-size: 13px; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--ink); }
.seg.small button { font-size: 11px; padding: 3px 8px; }
.seg-label { align-self: center; padding: 0 4px 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* Time */
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.presets button { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); cursor: pointer; }
.presets button:hover { color: var(--ink); border-color: var(--muted); }
.timeline svg { display: block; width: 100%; cursor: crosshair; touch-action: none; }
.timeline .brush { fill: var(--ink); fill-opacity: 0.06; stroke: var(--ink); stroke-opacity: 0.35; stroke-width: 1; pointer-events: none; }
.timeline-years { position: relative; height: 18px; border-top: 1px solid var(--line); }
.timeline-years button { position: absolute; top: 0; height: 100%; background: none; border: 0; border-left: 1px solid var(--line);
  font: 10px var(--font-data); color: var(--muted); padding: 2px 0 0; cursor: pointer; }
.timeline-years button:first-child { border-left: 0; }
.timeline-years button:hover { color: var(--ink); background: var(--raised); }
.date-inputs { display: flex; gap: 10px; margin-top: 10px; }
.date-inputs label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); flex: 1; min-width: 0; }
.date-inputs input { background: var(--ground); border: 1px solid var(--line); border-radius: 5px; color: var(--ink); font: 12px var(--font-data); padding: 4px 6px; width: 100%; }

/* Type */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.chip .n { font: 12px var(--font-data); color: var(--muted); margin-left: 4px; }
.chip[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.chip:disabled { opacity: 0.4; cursor: default; }

/* Places */
.places { display: flex; flex-direction: column; }
.place { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: baseline; background: none; border: 0;
  text-align: left; padding: 4px 8px; margin: 0 -8px; border-radius: 5px; cursor: pointer; }
.place span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place:hover { background: var(--raised); }
.place[aria-pressed="true"] { background: var(--raised); box-shadow: inset 2px 0 0 var(--accent); }
.place .n { font: 12px var(--font-data); color: var(--muted); font-variant-numeric: tabular-nums; }
.place.main { font-size: 16px; font-weight: 600; }
.place.area { padding-left: 22px; font-size: 13px; color: var(--muted); }
.place.area[aria-pressed="true"], .place.area:hover { color: var(--ink); }
.place[data-empty] { opacity: 0.45; }
.country { font-size: 11px; color: var(--muted); margin: 12px 0 2px; letter-spacing: 0.04em; }

/* By year */
.year-table table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.year-table th { font-size: 11px; font-weight: 400; color: var(--muted); text-align: right; padding: 0 0 6px; }
.year-table th:first-child { text-align: left; }
.year-table td { font: 12px var(--font-data); text-align: right; padding: 3px 0; }
.year-table td:first-child { text-align: left; }
.year-table th + th, .year-table td + td { padding-left: 12px; }
.year-table .bar-cell { width: 38%; }
.year-table .bar-cell i { display: block; height: 8px; border-radius: 2px; margin-left: auto; min-width: 2px; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 7px; }
.empty { color: var(--muted); font-size: 13px; }

/* Stage */
.stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.toolbar { position: absolute; top: 12px; left: 12px; z-index: 3; display: flex; gap: 8px; flex-wrap: wrap; }
.map-pane { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
.walk-card { position: absolute; right: max(12px, env(safe-area-inset-right, 0px)); top: 12px; z-index: 3; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; pointer-events: none; max-width: 300px; }
.walk-card b { display: block; font-weight: 600; margin-bottom: 4px; }
.walk-card .meta { font: 12px var(--font-data); color: var(--muted); }

.legend { position: absolute; left: 12px; bottom: 24px; z-index: 3; background: rgba(13, 17, 23, 0.86); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; max-width: min(380px, calc(100% - 80px)); backdrop-filter: blur(4px); }
.legend-title { font-weight: 600; font-size: 15px; }
.legend-sub { font: 11px var(--font-data); color: var(--muted); margin: 2px 0 8px; }
.legend-years { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend-years span { display: flex; align-items: center; gap: 5px; font: 11px var(--font-data); }
.legend-years i { width: 16px; height: 3px; border-radius: 2px; }
.legend-ramp { display: flex; justify-content: space-between; flex-wrap: wrap; font: 11px var(--font-data); color: var(--muted); width: 240px; max-width: 100%; }
.legend-ramp i { flex-basis: 100%; height: 6px; border-radius: 3px; margin-bottom: 4px; }
.legend-ramp.positioned { position: relative; height: 26px; display: block; }
.legend-ramp.positioned i { display: block; }
.legend-ramp.positioned span { position: absolute; bottom: 0; }


.load-error { margin: auto; color: var(--accent); }

/* MapLibre controls, recoloured for the dark basemap */
.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
.maplibregl-ctrl-group button span { filter: invert(1); }
.maplibregl-ctrl-attrib { background: rgba(13, 17, 23, 0.7) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }

/* Phone bottom sheet: the rail collapses to a bar under the map; the toggle only exists at this width */
.sheet-toggle { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .stage { grid-row: 1; }
  .rail { grid-row: 2; height: min(60dvh, 560px); gap: 22px; border-right: 0; border-top: 1px solid var(--line);
    padding-top: 0; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: max(20px, env(safe-area-inset-bottom, 0px)); }
  .rail[data-collapsed] { height: auto; overflow: hidden; padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  .rail[data-collapsed] > :not(.sheet-toggle) { display: none; }
  .rail h1 { display: none; }
  .sheet-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; z-index: 2;
    width: 100%; padding: 18px 0 12px; border: 0; background: var(--panel); cursor: pointer; text-align: left; }
  .sheet-toggle::before { content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--line); }
  .sheet-title { font-size: 18px; font-weight: 600; }
  .sheet-action { font-size: 13px; color: var(--muted); }
  .sheet-action::after { content: " ▴"; }
  .sheet-toggle[aria-expanded="true"] .sheet-action::after { content: " ▾"; }
  .sheet-toggle[aria-expanded="true"] [data-when="collapsed"], .sheet-toggle[aria-expanded="false"] [data-when="expanded"] { display: none; }
  .legend { bottom: 12px; }
}
