:root {
  --bg: #e9eeec;
  --panel: #fbfcfb;
  --panel-2: #f1f4f3;
  --ink: #16232a;
  --muted: #5a6a70;
  --line: #d2dbda;
  --now: #1f6f78;       /* sea teal: the present */
  --then: #8f6118;      /* brass: the past */
  --then-soft: #f3e7cf;
  --shadow: 0 6px 24px rgba(22, 35, 42, .14), 0 1px 3px rgba(22, 35, 42, .12);
  --font-body: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --font-sc: "Alegreya Sans SC", "Alegreya Sans", "Segoe UI", sans-serif;
  --font-display: "Alegreya", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e161a;
    --panel: #142026;
    --panel-2: #1a2930;
    --ink: #e2eaea;
    --muted: #93a4a8;
    --line: #27373e;
    --now: #5cb4ba;
    --then: #d8ab57;
    --then-soft: #3a2f1c;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--now); }

#app {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 370px;
  grid-template-rows: 1fr auto;
  grid-template-areas: "stage panel" "timeline panel";
}
#stage { grid-area: stage; position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--bg); }
#panel { grid-area: panel; }
#timeline { grid-area: timeline; }

/* ---------- shared bits ---------- */
.eyebrow {
  font-family: var(--font-sc);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: lowercase;
  color: var(--muted);
}
.mono { font-family: var(--font-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 500;
  line-height: 1.1;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible, select:focus-visible, input:focus-visible, li[tabindex]:focus-visible, #divider-knob:focus-visible {
  outline: 2px solid var(--now); outline-offset: 2px;
}
.btn-primary { background: var(--now); border-color: var(--now); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--now); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0e161a; } }
.btn.icon { width: 38px; height: 38px; justify-content: center; padding: 0; font-size: 22px; }

.float-card {
  position: absolute; z-index: 800;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* ---------- location card ---------- */
#loc { top: 14px; left: 14px; width: 300px; padding: 14px; display: grid; gap: 6px; }
.loc-name { font-family: var(--font-display); font-weight: 700; font-size: 22px; line-height: 1.1; text-wrap: balance; }
.loc-note { font-size: 13px; color: var(--muted); }
.loc-note.warn { color: var(--then); }
.search { display: flex; gap: 6px; margin-top: 4px; }
.search input {
  flex: 1; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2);
  padding: 7px 10px;
}
.search-results { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 200px; overflow: auto; }
.search-results li { padding: 7px 10px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.search-results li:last-child { border-bottom: 0; }
.search-results li:hover, .search-results li:focus-visible { background: var(--panel-2); }
.loc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
body.picking #map, body.picking #map .leaflet-interactive { cursor: crosshair; }
body.picking #btn-pick { background: var(--then); border-color: var(--then); color: #fff; }

/* ---------- controls ---------- */
.controls { top: 14px; right: 14px; padding: 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 340px); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; background: var(--panel-2); }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.base-pick { display: inline-flex; align-items: center; gap: 6px; }
.base-pick select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--panel-2); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--then); }
.panel-toggle { display: none; }

/* ---------- divider ---------- */
#divider { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; z-index: 700; pointer-events: none; }
#divider[hidden] { display: none; }
.divider-line { position: absolute; top: 0; bottom: 0; left: -1.5px; width: 3px; background: var(--panel); box-shadow: 0 0 0 1px rgba(0,0,0,.18); }
#divider-knob {
  position: absolute; top: 72%; left: -21px; width: 42px; height: 42px; margin-top: -21px;
  border-radius: 50%; border: 2px solid var(--panel); background: var(--then); color: #fff;
  display: grid; place-items: center; cursor: ew-resize; pointer-events: auto;
  box-shadow: var(--shadow); touch-action: none;
}
.side-tag {
  position: absolute; bottom: 16px; white-space: nowrap;
  font-family: var(--font-sc); font-weight: 700; font-size: 13px; letter-spacing: .08em;
  padding: 4px 10px; border-radius: 6px; color: #fff; box-shadow: var(--shadow);
}
.side-then { right: 12px; background: var(--then); }
.side-now { left: 12px; background: var(--now); }
@media (prefers-color-scheme: dark) { .side-tag, #divider-knob, body.picking #btn-pick { color: #0e161a; } }

/* ---------- panel ---------- */
#panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); align-items: flex-end; }
.tablist { display: flex; gap: 4px; align-items: flex-end; }
.tabs button[role="tab"] {
  border: 0; background: transparent; cursor: pointer;
  padding: 8px 10px 9px; font-weight: 700; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[role="tab"].on { color: var(--ink); border-bottom-color: var(--then); }
.panel-close { display: none; margin-left: auto; border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.tab-body { overflow: auto; padding: 14px 16px 20px; flex: 1; min-height: 0; }
.lede { margin: 0 0 12px; color: var(--muted); font-size: 14px; max-width: 60ch; }
.source { font-size: 12.5px; color: var(--muted); margin-top: 16px; }

.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.progress > div { height: 100%; width: 0; background: var(--then); transition: width .2s; }
.progress.done { visibility: hidden; }

.hist-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 7px; font-size: 13px; cursor: pointer; background: var(--panel-2); }
.chip input { accent-color: var(--then); margin: 0; }
.hist-list li .dot.ev { border-radius: 3px; background: var(--ev, #7a5c8e); }
.hist-list li.kind-occupation, .hist-list li.kind-repression, .hist-list li.kind-war { --ev: #a0432f; }
.hist-list li.kind-state { --ev: var(--now); }
.hist-list li.kind-peace { --ev: #3d8a5f; }
.hist-list li.kind-disaster { --ev: #6b6f73; }
.hist-list li.event .what { font-weight: 500; }
.hist-list li .ev-d { margin-top: 5px; font-size: 14px; line-height: 1.4; max-width: 60ch; }
.hist-list li .ev-d a { white-space: nowrap; }
.here-ev { font-weight: 400; font-size: 13.5px; margin-top: 3px; color: var(--ink); }
.here-ev b { font-weight: 600; }
.online-status { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.more-maps { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.hist-list li .dot.sheet { border-radius: 2px; background: var(--then); opacity: .55; width: 10px; height: 10px; margin-left: 3px; }
.hist-list li.sheet .what { font-weight: 500; }
.hist-list li .orig a { white-space: nowrap; }
.hist-list { list-style: none; margin: 0; padding: 0; position: relative; }
.hist-list::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.hist-list li {
  position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 8px;
  padding: 7px 8px 7px 0; border-radius: 8px; cursor: pointer;
}
.hist-list li:hover { background: var(--panel-2); }
.hist-list li .dot { width: 12px; height: 12px; border-radius: 50%; margin: 5px 0 0 2px; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); position: relative; z-index: 1; }
.hist-list li .when { font-family: var(--font-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-list li .what { font-weight: 700; line-height: 1.25; }
.hist-list li .orig { font-size: 12.5px; color: var(--muted); }
.hist-list li.none .what { font-weight: 400; color: var(--muted); font-style: italic; }
.hist-list li.cur { background: var(--then-soft); }
.hist-list li.map .what { color: var(--then); }

.famous-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.famous-list li { display: grid; grid-template-columns: 124px 1fr; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.famous-list li:hover, .famous-list li.cur { background: var(--panel-2); }
.famous-list li.cur { box-shadow: inset 3px 0 0 var(--then); }
.famous-list .when { font-family: var(--font-mono); font-size: 12px; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; }
.famous-list .t { font-weight: 700; line-height: 1.25; }

.famous-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; background: var(--panel-2); }
.famous-card .img { background: var(--line); aspect-ratio: 4 / 3; max-width: 100%; display: grid; place-items: center; overflow: hidden; }
.famous-card .img img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; }
.famous-card .img .noimg { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
.famous-card .credit { padding: 6px 14px 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.famous-card .body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.famous-card h3 { margin: 0; font-family: var(--font-display); font-size: 20px; line-height: 1.15; text-wrap: balance; }
.famous-card p { margin: 0; font-size: 14.5px; }
.famous-card .links { display: flex; gap: 12px; font-size: 13.5px; flex-wrap: wrap; }

/* ---------- timeline ---------- */
#timeline {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 18px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: grid; gap: 6px;
}
.tl-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tl-year { min-width: 190px; text-align: center; }
.year { font-family: var(--font-display); font-weight: 700; font-size: 30px; line-height: 1.05; color: var(--then); font-variant-numeric: lining-nums tabular-nums; }
.year.sat { color: var(--now); }
.tl-here { margin-left: 12px; padding-left: 14px; border-left: 1px solid var(--line); flex: 1; min-width: 200px; }
.here { font-weight: 700; font-size: 18px; line-height: 1.2; }
.here .orig { font-weight: 400; font-size: 13px; color: var(--muted); }
.tl-track { position: relative; padding-top: 2px; }
#tl-range { width: 100%; accent-color: var(--then); margin: 0; height: 22px; cursor: pointer; }
.tl-ticks { position: relative; height: 16px; margin: 0 8px; }
.tl-ticks span {
  position: absolute; top: 0; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); white-space: nowrap;
}
.tl-ticks span.sat { color: var(--now); }
.tl-ticks .map-tick { position: absolute; top: -9px; width: 7px; height: 7px; margin-left: -3.5px; border-radius: 50%; background: var(--then); border: 1px solid var(--panel); }

/* ---------- map details ---------- */
.leaflet-container { font-family: var(--font-body); background: var(--bg); }
.leaflet-tooltip.poly-tip {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-weight: 700; font-size: 13px; padding: 4px 8px;
}
.leaflet-tooltip.poly-tip .orig { font-weight: 400; color: var(--muted); }
.leaflet-tooltip.poly-tip::before { border-top-color: var(--panel); }
.leaflet-tooltip.here-tip {
  background: var(--then); color: #fff; border: 0; font-weight: 700; font-size: 13px;
  padding: 5px 9px; box-shadow: var(--shadow);
}
.leaflet-tooltip.here-tip::before { border-top-color: var(--then); }
@media (prefers-color-scheme: dark) { .leaflet-tooltip.here-tip { color: #0e161a; } }
/* NLS county sheets: blank paper outside a county must not hide the neighbouring county. */
.county-sheet { mix-blend-mode: darken; }
.me-pin { width: 22px; height: 22px; border-radius: 50%; background: var(--now); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(31,111,120,.25), 0 2px 6px rgba(0,0,0,.35); }
.leaflet-control-attribution { font-size: 10.5px; }

/* ---------- small screens ---------- */
@media (max-width: 1040px), (max-height: 520px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "stage" "timeline"; }
  #panel {
    position: fixed; z-index: 1200; left: 0; right: 0; bottom: 0; height: 72%;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow); transform: translateY(105%);
    visibility: hidden; transition: transform .25s ease, visibility 0s linear .25s;
  }
  body.panel-open #panel { transform: none; visibility: visible; transition: transform .25s ease; }
  .panel-close { display: block; }
  .panel-toggle { display: inline-flex; position: absolute; z-index: 800; right: 14px; bottom: 40px; box-shadow: var(--shadow); }
  .leaflet-control-zoom, .leaflet-control-scale { display: none; }
  #divider-knob { top: 62%; }
  #loc { width: auto; right: 14px; padding: 10px 12px; }
  #loc .loc-note:not(.warn):not(.busy) { display: none; }
  .controls { top: auto; bottom: 40px; left: 14px; right: auto; max-width: calc(100% - 118px); justify-content: flex-start; }
  .seg button { padding: 6px 9px; }
  .controls .base-pick .eyebrow, .controls .check { display: none; }
  .side-tag { top: auto; bottom: var(--tag-bottom, 150px); }
  .tl-here { margin-left: 0; padding-left: 0; border-left: 0; flex-basis: 100%; }
  .tl-year { min-width: 0; flex: 1; }
  .year { font-size: 24px; }
  .loc-name { font-size: 18px; }
}
/* Landscape phones: location card on the left, controls on the right, both at the top. */
@media (max-height: 520px) {
  #loc { right: auto; width: calc(50% - 40px); padding: 8px 10px; }
  #loc .mono, #loc .eyebrow { display: none; }
  #search-results { max-height: 96px; }
  .controls { top: 14px; bottom: auto; left: auto; right: 14px; max-width: calc(50% - 40px); }
  .side-tag { top: auto; bottom: 12px; }
  #divider { z-index: auto; }
  .divider-line, .side-tag { z-index: 700; }
  #divider-knob { z-index: 850; }
  #timeline { padding-block: 6px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  #panel, body.panel-open #panel, .progress > div { transition: none; }
}
