:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #64717d;
  --line: #d8dee4;
  --paper: #f7f8fa;
  --panel: #ffffff;
  --accent: #75132f;
  --accent-dark: #4f0d20;
  --accent-soft: #f3e8ec;
  --focus: #176c88;
  --shadow: 0 18px 50px rgba(20, 31, 43, 0.16);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
  outline-offset: 2px;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
  z-index: 1100;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.45rem, 2.3vw, 2rem); font-weight: 600; }
h2 { margin-bottom: .45rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.3rem; line-height: 1.2; }
h3 { margin-bottom: .35rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.08rem; }
.eyebrow { margin-bottom: .12rem; color: var(--accent); font-size: .75rem; font-weight: 750; letter-spacing: .095em; text-transform: uppercase; }

.workspace { height: calc(100vh - 76px); display: grid; grid-template-columns: minmax(320px, 400px) 1fr; grid-template-rows: minmax(0, 1fr); }
.controls { min-width: 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); z-index: 700; }
.controls > .time-panel, .controls > .filter-panel, .controls > .result-summary { flex-shrink: 0; }
.time-panel, .filter-panel { padding: 1rem 1.15rem; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.year-slider { appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 20px; margin: 0; background: transparent; cursor: pointer; }
.year-slider::-webkit-slider-runnable-track { height: 4px; background: #c7cbd0; border-radius: 2px; }
.year-slider::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 0; border-radius: 50%; background: var(--accent); }
.year-slider::-moz-range-track { height: 4px; background: #c7cbd0; border-radius: 2px; }
.year-slider::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--accent); }
.year-slider:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.year-scale { position: relative; height: 1.2rem; margin: 0 8px; color: var(--muted); font-size: .65rem; font-variant-numeric: tabular-nums; }
.year-scale span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.method-note { margin: .6rem 0 0; color: var(--muted); font-size: .78rem; line-height: 1.35; }

.quiet-button, .text-button, .icon-button, .popup-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.quiet-button { padding: .55rem .8rem; border: 1px solid var(--line); border-radius: .35rem; background: var(--paper); font-weight: 650; }
.quiet-button:hover { border-color: var(--accent); color: var(--accent); }
.text-button { padding: .2rem 0; color: var(--accent); font-size: .82rem; font-weight: 700; }
.text-button:hover { color: var(--accent-dark); text-decoration: underline; }
.icon-button { width: 2.4rem; height: 2.4rem; font-size: 1.7rem; line-height: 1; border-radius: 50%; }
.icon-button:hover { background: var(--paper); }

.search-label { display: block; margin-bottom: .35rem; font-size: .85rem; font-weight: 700; }
.search-input, select {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid #b9c3cc;
  border-radius: .35rem;
  color: var(--ink);
  background: #fff;
}
.search-input { padding: .55rem .7rem; }
select { padding: .45rem 2rem .45rem .55rem; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: .7rem; }
.filter-grid label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.filter-grid select { display: block; margin-top: .25rem; color: var(--ink); font-size: .9rem; font-weight: 500; }
.selection-actions { display: flex; gap: 1rem; margin-top: .65rem; }
.result-summary { padding: .65rem 1.15rem; border-bottom: 1px solid var(--line); background: var(--paper); color: var(--muted); font-size: .82rem; }

.print-list { flex: 1 1 0; min-height: 8rem; overflow-y: auto; scrollbar-gutter: stable; }
.print-list:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.print-card { position: relative; display: grid; grid-template-columns: 1.25rem 1fr; gap: .65rem; padding: .82rem 1.1rem; border-bottom: 1px solid #e7ebef; }
.print-card:hover { background: #faf7f8; }
.print-card.is-unselected { opacity: .58; }
.print-card input { margin-top: .18rem; accent-color: var(--accent); }
.print-card-body { display: block; padding: 0; border: 0; color: inherit; background: transparent; text-align: left; cursor: pointer; }
.print-card-body:hover .print-title { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .16em; }
.print-title { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: .95rem; font-weight: 700; line-height: 1.25; }
.print-meta { margin: .28rem 0 0; color: var(--muted); font-size: .76rem; }
.print-id { font-variant-numeric: tabular-nums; }

.map-shell { position: relative; min-width: 0; min-height: 0; background: #e8ecef; }
.map { width: 100%; height: 100%; }
.map-legend { position: absolute; z-index: 600; left: 1rem; bottom: 1rem; display: flex; flex-wrap: wrap; gap: .45rem .9rem; max-width: calc(100% - 2rem); padding: .55rem .7rem; border: 1px solid rgba(80, 94, 107, .22); border-radius: .35rem; background: rgba(255,255,255,.94); box-shadow: 0 5px 20px rgba(20,31,43,.12); font-size: .75rem; }
.map-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend-dot { width: .72rem; height: .72rem; display: inline-block; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--accent); }
.legend-dot.inferred { background: #fff; }
.legend-line { width: 1.35rem; height: 0; border-top: 3px dashed var(--accent); opacity: .7; }
.map-message { position: absolute; z-index: 650; top: 1rem; left: 50%; transform: translateX(-50%); max-width: 28rem; padding: .7rem .9rem; border-radius: .35rem; background: rgba(23,33,43,.9); color: #fff; text-align: center; }

.detail-panel, .about-panel {
  position: fixed;
  z-index: 1200;
  top: 76px;
  right: 0;
  width: min(440px, 100vw);
  height: calc(100vh - 76px);
  overflow-y: auto;
  padding: 1.2rem;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform .22s ease;
}
.detail-panel.is-open, .about-panel.is-open { transform: translateX(0); }
.detail-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.detail-toolbar .eyebrow { margin-bottom: 0; }
.detail-panel > .detail-toolbar {
  position: sticky;
  top: -1.2rem;
  z-index: 2;
  margin: -1.2rem -1.2rem .8rem;
  padding: .8rem 1.2rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.detail-lead { color: var(--muted); }
.detail-facts { display: grid; grid-template-columns: 7.5rem 1fr; gap: .4rem .8rem; margin: 1rem 0; font-size: .88rem; }
.detail-facts dt { color: var(--muted); }
.detail-facts dd { margin: 0; overflow-wrap: anywhere; }
.detail-facts a, .station-source { color: var(--accent); }
.station-list { position: relative; list-style: none; margin: 1.1rem 0 0; padding: 0; }
.station-list::before { content: ""; position: absolute; left: .55rem; top: .4rem; bottom: .7rem; border-left: 1px solid #b7c0c8; }
.station-item { position: relative; padding: 0 0 1.15rem 2rem; }
.station-item::before { content: ""; position: absolute; left: .25rem; top: .22rem; width: .65rem; height: .65rem; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }
.station-type { display: block; color: var(--accent); font-size: .72rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.station-place { font-weight: 720; }
.station-time, .station-note { display: block; color: var(--muted); font-size: .8rem; }
.uncertain-badge { display: inline-block; margin-top: .25rem; padding: .12rem .35rem; border-radius: .2rem; background: #fff0c8; color: #624600; font-size: .72rem; font-weight: 700; }
.about-panel p { max-width: 42rem; }

.leaflet-popup-content { margin: .8rem 1rem; min-width: 230px; color: var(--ink); }
.leaflet-popup-content h3 { margin-bottom: .25rem; }
.leaflet-popup-content p { margin: .3rem 0; }
.popup-meta { color: var(--muted); font-size: .78rem; }
.popup-route { max-height: 5.5rem; overflow: hidden; color: var(--muted); font-size: .78rem; }
.popup-button { margin-top: .55rem; padding: .42rem .58rem; border-radius: .3rem; background: var(--accent); color: #fff; font-weight: 720; }
.popup-button:hover { background: var(--accent-dark); }
.bundle-list { max-height: 300px; max-height: min(300px, 45vh); overflow-y: auto; scrollbar-gutter: stable; }
.bundle-copy { padding: .65rem 0; border-top: 1px solid var(--line); }
.bundle-copy .popup-route { display: none; }
.bundle-list:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

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

@media (max-width: 820px) {
  .topbar { height: 68px; padding: 0 .8rem; }
  .topbar .eyebrow { display: none; }
  .quiet-button { font-size: .82rem; }
  .workspace { height: calc(100vh - 68px); grid-template-columns: 1fr; grid-template-rows: minmax(290px, 44%) 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .time-panel, .filter-panel { padding: .7rem .85rem; }
  .method-note { display: none; }
  .print-list { min-height: 10rem; }
  .result-summary { border-bottom: 0; }
  .detail-panel, .about-panel { top: 68px; height: calc(100vh - 68px); }
  .map-legend { left: .6rem; right: .6rem; bottom: .6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .detail-panel, .about-panel { transition: none; }
}

.view-switch { display: flex; gap: .3rem; margin-bottom: .8rem; }
.view-switch button { flex: 1; padding: .5rem .3rem; border: 1px solid var(--line); border-radius: .35rem; background: #fff; color: var(--ink); }
.view-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.legend-items { display: flex; flex-wrap: wrap; gap: .4rem .85rem; }
.legend-items[hidden] { display: none; }

.bundle-controls { flex-shrink: 0; padding: .6rem 1rem; border-bottom: 1px solid var(--line); }
.bundle-controls summary { cursor: pointer; font-weight: 650; }
.bundle-controls label { display: block; margin-top: .5rem; font-size: .85rem; }
.bundle-controls input { width: 100%; }
.bundle-controls p { font-size: .78rem; color: var(--muted); }
.bundle-panel { position: fixed; z-index: 1000; top: 88px; right: 12px; width: min(350px, calc(100vw - 32px)); max-height: calc(100dvh - 110px); overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: .5rem; padding: 1rem; box-shadow: var(--shadow); }
.bundle-panel[hidden], .bundle-controls[hidden] { display: none; }
.bundle-panel .detail-toolbar { position: sticky; top: -1rem; background: #fff; padding: .5rem 0; z-index: 1; }
.bundle-panel .bundle-list { max-height: none; overflow: visible; }
.bundle-panel .method-note { display: block; }
@media (max-width: 820px) { .bundle-panel { top: auto; bottom: 12px; max-height: 48dvh; } }

.collection-choices { margin: 0 0 .8rem; padding: 0 0 .7rem; border: 0; border-bottom: 1px solid var(--line); }
.collection-choices legend { font-weight: 650; margin-bottom: .35rem; }
.collection-choices label { display: flex; align-items: flex-start; gap: .45rem; margin: .35rem 0; font-size: .84rem; line-height: 1.35; cursor: pointer; }
.collection-choices input { flex: 0 0 auto; width: auto; margin: .18rem 0 0; accent-color: var(--accent, #75132f); }
.collection-choices small { color: var(--muted); white-space: nowrap; }
.collection-choices small:not(:empty)::before { content: " · "; }

.location-style-controls[hidden], #heatmap-legend[hidden], #circle-legend[hidden] { display: none; }
.location-style-controls { margin-top: .5rem; }
.density-canvas { position: absolute; top: 0; left: 0; pointer-events: none; }
.density-canvas[hidden] { display: none; }
.heat-gradient { display: inline-block; width: 70px; height: 10px; background: linear-gradient(to right,#ffe082,#f69340,#d54036,#75132f); border-radius: 3px; }

#heat-controls { margin-top: .7rem; }
#heat-controls[hidden] { display: none; }
#heat-radius { width: 100%; }

.digital-links { margin: .7rem 0; }
.digital-links summary { cursor: pointer; font-weight: 600; }
.digital-links li { margin: .65rem 0; overflow-wrap: anywhere; }
.digital-links small { display: block; margin-top: .2rem; }

/* Compact, vertically centred tools in the existing header. */
.topbar {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
}
.topbar > div { min-width: 0; }
.topbar h1 { white-space: nowrap; font-size: clamp(1.35rem, 2.1vw, 1.85rem); line-height: 1.15; }
.topbar .eyebrow { font-size: .65rem; }
.topbar > * { align-self: center; }
.map-tools {
  display: flex; align-items: center; justify-content: flex-start;
  justify-self: center; width: max-content; max-width: 100%; min-width: 0;
  gap: 1rem; overflow-x: auto; padding: .25rem 0;
}
.map-tools .view-switch { flex: 0 0 auto; margin: 0; gap: .25rem; }
.map-tools .view-switch button { flex: 0 0 auto; padding: .45rem .55rem; font-size: .85rem; }
.map-tools .bundle-controls {
  display: flex; align-items: center; gap: 1rem; flex: 0 0 auto;
  padding: 0 0 0 1rem; border: 0; border-left: 1px solid var(--line);
}
.map-tools .bundle-controls[hidden], .map-tools .location-style-controls[hidden] { display: none; }
.map-tools .bundle-controls label { flex: 0 0 125px; width: 125px; margin: 0; font-size: .75rem; white-space: nowrap; }
.map-tools .bundle-controls input { display: block; width: 125px; margin: .2rem 0 0; }
.map-tools .location-style-controls { padding-left: 1rem; border-left: 1px solid var(--line); }
#about-button { white-space: nowrap; }
@media (max-width: 1100px) and (min-width: 821px) {
  .topbar { padding: 0 .7rem; gap: .7rem; }
  .topbar h1 { font-size: 1.35rem; }
  .topbar .eyebrow { font-size: .55rem; }
  .map-tools { gap: .6rem; }
  .map-tools .bundle-controls { gap: .6rem; padding-left: .6rem; }
  .map-tools .bundle-controls label { flex-basis: 95px; width: 95px; }
  .map-tools .bundle-controls input { width: 95px; }
  #about-button { font-size: .75rem; padding: .4rem; }
}
@media (max-width: 820px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 28px 40px; height: 76px; gap: 0 .5rem; }
  .topbar h1 { font-size: 1.15rem; }
  .map-tools { grid-row: 2; grid-column: 1 / -1; }
  #about-button { grid-row: 1; grid-column: 2; }
  .workspace { height: calc(100vh - 76px); }
  .detail-panel, .about-panel { top: 76px; height: calc(100vh - 76px); }
}

/* Multi-select filters retain a compact closed state. */
.multi-filter { min-width: 0; color: var(--muted); font-size: .78rem; font-weight: 700; }
.multi-filter details { position: relative; margin-top: .25rem; }
.multi-filter summary { padding: .5rem; border: 1px solid var(--line); border-radius: .35rem; background: #fff; color: var(--ink); font-size: .9rem; font-weight: 500; cursor: pointer; overflow-wrap: anywhere; }
.multi-menu { position: absolute; left: 0; top: 100%; z-index: 1200; width: 265px; max-width: calc(100vw - 40px); max-height: min(320px, 45vh); overflow-y: auto; padding: .65rem; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: .35rem; box-shadow: var(--shadow); }
#language-dropdown .multi-menu { left: auto; right: 0; }
.multi-menu p { margin: 0 0 .4rem; font-weight: 400; }
.multi-menu label { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; cursor: pointer; }
.multi-menu input[type="checkbox"] { width: auto; margin: 0; flex-shrink: 0; }

.filter-unavailable { opacity: .45; cursor: default !important; }
.filter-count { font-weight: 400; white-space: nowrap; }

/* Session selection stays separate from the search filters. */
.saved-selection { border-top: 1px solid #e7ebef; margin-top: .65rem; padding-top: .5rem; }
.saved-selection p { font-size: .75rem; line-height: 1.35; margin: 0 0 .35rem; }
.saved-selection-actions { display: flex; flex-wrap: wrap; gap: .35rem .8rem; }
.saved-selection-actions button:disabled { opacity: .45; cursor: default; }
#search-controls[hidden], #save-matches[hidden] { display: none; }
