:root {
  --bg: #f5f1e8;
  --ink: #23211c;
  --muted: #6b665a;
  --line: #d9d2c2;
  --accent: #1f6f5c;
  --accent-ink: #fff;
  --sea: #b9d3de;
  --panel: #fffdf8;
  --recorded: #2e7d4f;
  --estimated: #2f62a8;
  --traditional: #b26b00;
  --mythical: #7a3fa0;
  --myth: #7a3fa0;
  --trad: #b26b00;
  --roman: #a3201c;
  --religion: #2a7f8f;
  --topbar-h: 48px;
  --timebar-h: 104px;
  --panel-w: 400px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
button { font: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: #24342f; color: #f3efe4; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-right: auto; white-space: nowrap; }
.brand-mark { color: #9fd6c2; font-size: 20px; }
.view-switch { display: flex; border: 1px solid #6c8a80; border-radius: 8px; overflow: hidden; }
.view-switch button { background: transparent; color: #e8e3d6; border: 0; padding: 6px 14px; }
.view-switch button.active { background: #9fd6c2; color: #14231e; font-weight: 600; }
.icon-btn { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; color: var(--ink); min-height: 34px; }
.topbar .icon-btn { background: transparent; color: #f3efe4; border-color: #6c8a80; }
.layers-menu {
  position: absolute; top: calc(var(--topbar-h) - 4px); right: 8px; width: min(340px, calc(100vw - 16px));
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: 10px 12px; z-index: 1100;
}
.layers-menu label { display: flex; align-items: center; gap: 8px; padding: 7px 0; }
.layers-menu small { color: var(--muted); }
.layers-menu hr { border: 0; border-top: 1px solid var(--line); }
.layers-note { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.swatch.myth { background: var(--myth); } .swatch.trad { background: var(--trad); }
.swatch.roman { background: var(--roman); } .swatch.religion { background: var(--religion); }

/* ---------- layout ---------- */
.layout {
  position: fixed; top: var(--topbar-h); bottom: var(--timebar-h); left: 0; right: 0;
  display: grid; grid-template-columns: 1fr var(--panel-w);
}
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--sea); }
.map-badge {
  position: absolute; left: 10px; bottom: 10px; z-index: 500; max-width: 70%;
  background: rgba(255,253,248,.92); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 8px; font-size: 12px; color: var(--muted); pointer-events: none;
}
.map-badge b { color: var(--ink); }
.legend {
  position: absolute; right: 10px; bottom: 10px; z-index: 500; max-width: 220px; max-height: 45%; overflow: auto;
  background: rgba(255,253,248,.94); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px;
}
.legend div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.legend i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; flex: none; border: 1px solid rgba(0,0,0,.2); }

/* ---------- panel ---------- */
.panel { background: var(--panel); border-left: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.panel-handle { display: none; }
.panel-body { overflow-y: auto; padding: 12px 14px 40px; flex: 1; -webkit-overflow-scrolling: touch; }
.panel h1 { font-size: 26px; margin: 0; line-height: 1.1; }
.panel h2 { font-size: 15px; margin: 0; }
.panel .sub { color: var(--muted); margin: 2px 0 8px; font-size: 14px; }
.panel p, .panel li { font-size: 14.5px; line-height: 1.45; }
.panel details { border-top: 1px solid var(--line); padding: 6px 0; }
.panel summary { cursor: pointer; font-weight: 600; padding: 6px 0; list-style: none; display: flex; align-items: center; gap: 6px; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.panel details[open] > summary::before { transform: rotate(90deg); }
.panel ul { padding-left: 0; list-style: none; margin: 4px 0; }
.panel li { margin: 0 0 9px; }
.fact { margin: 0 0 9px; }
.fact-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.tag {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  border-radius: 4px; padding: 1px 5px; color: #fff; vertical-align: 1px; margin-right: 4px;
}
.tag.recorded { background: var(--recorded); } .tag.estimated { background: var(--estimated); }
.tag.traditional { background: var(--traditional); } .tag.mythical { background: var(--mythical); }
.ev-year { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 4px; }
.ev.near { background: #fff4d6; border-radius: 6px; padding: 4px 6px; margin-left: -6px; margin-right: -6px; }
.ev.future { opacity: .55; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; background: #fff; }
.card h2 { font-size: 17px; }
.card .close { float: right; border: 0; background: none; font-size: 18px; color: var(--muted); }
.layer-section { border-left: 4px solid var(--line); padding-left: 10px; margin: 10px 0; }
.layer-section.myth { border-color: var(--myth); } .layer-section.trad { border-color: var(--trad); }
.layer-section.roman { border-color: var(--roman); } .layer-section.religion { border-color: var(--religion); }
.layer-banner { font-size: 12.5px; padding: 6px 8px; border-radius: 6px; margin: 4px 0 8px; }
.myth .layer-banner { background: #f2e9f7; color: #4d2466; }
.trad .layer-banner { background: #fbf0dc; color: #6b4100; }
.roman .layer-banner { background: #f8e4e2; color: #6d1512; }
.religion .layer-banner { background: #e0f1f3; color: #154b54; }
.pop-big { font-size: 22px; font-weight: 700; }
.ruler-list li { display: flex; gap: 6px; align-items: flex-start; }
.ruler-list .tag { flex: none; margin-top: 2px; }
.muted { color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; margin: 6px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sources-list li { font-size: 13px; }
.loading { color: var(--muted); }

/* ---------- timebar ---------- */
.timebar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--timebar-h);
  background: #fbf8f1; border-top: 1px solid var(--line); padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  z-index: 900; display: flex; flex-direction: column; gap: 4px;
}
.time-controls { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
.year-box input {
  width: 120px; font-size: 18px; font-weight: 700; text-align: center; padding: 4px 6px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; font-variant-numeric: tabular-nums;
}
.period-name { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slider-wrap { position: relative; padding-top: 8px; }
.period-band { position: absolute; top: 0; left: 8px; right: 8px; height: 8px; display: flex; border-radius: 4px; overflow: hidden; }
.period-band span { height: 100%; border-right: 1px solid rgba(255,255,255,.7); }
#year-slider { width: 100%; margin: 0; accent-color: var(--accent); height: 28px; }
.slider-ticks { position: relative; height: 16px; margin: 0 8px; font-size: 11px; color: var(--muted); }
.slider-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.slider-ticks span:first-child { transform: none; }
.slider-ticks span:last-child { transform: translateX(-100%); }

/* ---------- map bits ---------- */
.site-label, .region-label, .eu-label {
  background: transparent; border: 0; box-shadow: none; padding: 0;
  font-weight: 600; color: #2a2a2a; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
}
.region-label { font-size: 12px; text-align: center; }
.eu-label { font-size: 11px; }
.site-label { font-size: 11px; font-weight: 500; }
.leaflet-tooltip.site-label::before, .leaflet-tooltip.region-label::before, .leaflet-tooltip.eu-label::before { display: none; }
.layer-pin {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700;
}
.layer-pin.myth { background: var(--myth); } .layer-pin.trad { background: var(--trad); }
.layer-pin.roman { background: var(--roman); } .layer-pin.religion { background: var(--religion); }
.leaflet-popup-content { font-size: 13.5px; line-height: 1.4; }
.leaflet-container { font-family: inherit; }
.hide-labels .leaflet-tooltip.site-label, .hide-labels .leaflet-tooltip.region-label, .hide-labels .leaflet-tooltip.eu-label { display: none; }

/* ---------- phone ---------- */
@media (max-width: 820px) {
  :root { --timebar-h: 112px; }
  .brand-text { display: none; }
  .layout { grid-template-columns: 1fr; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: var(--timebar-h); height: 38vh; z-index: 800;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 18px rgba(0,0,0,.15); transition: height .2s;
  }
  .panel.expanded { height: calc(100vh - var(--topbar-h) - var(--timebar-h) - 10px); height: calc(100dvh - var(--topbar-h) - var(--timebar-h) - 10px); }
  .panel.collapsed { height: 64px; }
  .panel-handle { display: flex; justify-content: center; align-items: center; border: 0; background: none; padding: 8px 0 4px; flex: none; }
  .panel-handle span { width: 44px; height: 5px; border-radius: 3px; background: #c9c1ae; }
  .panel-body { padding-top: 0; }
  .panel h1 { font-size: 22px; }
  .map-badge { bottom: auto; top: 8px; }
  .legend { bottom: auto; top: 40px; max-height: 30%; }
  .period-name { display: none; }
  #btn-play { display: none; }
  .year-box input { width: 110px; }
  .time-controls { justify-content: center; }
  .leaflet-control-zoom { display: none; }
  .slider-ticks span.minor { display: none; }
}

.area-chart svg { width: 100%; height: auto; display: block; background: #f7f3ea; border-radius: 6px; }
.area-chart p { margin: 6px 0 2px; font-size: 12.5px; }
.event-marker { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { stroke-opacity: 1; } 50% { stroke-opacity: .35; } }

/* layer browse list */
.layer-section ul.browse { list-style: none; padding: 0; margin: 4px 0; font-size: 0.9em; }
.layer-section ul.browse li { padding: 2px 0; display: flex; gap: 6px; align-items: baseline; }
.layer-section ul.browse .chip { flex: none; min-width: 72px; }

/* search */
.search { position: relative; flex: 0 1 300px; min-width: 0; margin: 0 8px; }
.search input { width: 100%; box-sizing: border-box; padding: 6px 10px; border-radius: 8px; border: 1px solid #6c8a80; background: #2c3f39; color: #f3efe4; font: inherit; font-size: 14px; }
.search input::placeholder { color: #a9b8b1; }
.search input:focus { outline: 2px solid #9fd6c2; background: #fffdf7; color: #1b1b1b; }
.search-results { position: absolute; top: calc(100% + 4px); left: 0; width: min(420px, 92vw); max-height: 60vh; overflow-y: auto; background: #fffdf7; color: #1b1b1b; border: 1px solid #d8d2c2; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 2000; }
.search-hit { padding: 7px 10px; border-bottom: 1px solid #eee8da; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.search-hit .muted { font-size: 12px; }
.search-hit.active, .search-hit:hover { background: #e6f3ee; }
.search-empty { padding: 10px; color: #777; }
@media (max-width: 820px) {
  .search { flex: 1 1 auto; margin: 0 6px; }
  .search input { font-size: 16px; padding: 5px 8px; }
}
@media (max-width: 820px) {
  .topbar { gap: 6px; }
  .view-switch { flex: none; }
  .view-switch button { padding: 6px 9px; }
  #btn-layers { white-space: nowrap; padding: 6px 8px; flex: none; }
  .search { flex: 1 1 80px; margin: 0; }
  .search-results { position: fixed; left: 8px; right: 8px; top: 52px; width: auto; }
}

/* Guided tours */
.tour-card { border: 2px solid var(--accent); border-radius: 10px; padding: 8px 12px 10px; margin: 0 0 12px; background: #f3faf7; }
.tour-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); font-weight: 600; }
.tour-head .close { border: 0; background: none; font-size: 20px; color: var(--muted); padding: 0 2px; }
.tour-card h2 { margin: 4px 0 6px; font-size: 17px; }
.tour-card h2 .muted { font-size: 13px; font-weight: normal; }
.tour-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.tour-nav .btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font-size: 14px; min-height: 36px; }
.tour-nav .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tour-nav .btn:disabled { opacity: .4; }
.tour-dots { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.tour-dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--accent); background: #fff; padding: 0; }
.tour-dot.on { background: var(--accent); }
.tour-list { list-style: none; padding: 0; margin: 4px 0; }
.tour-list li { margin: 0 0 8px; }
.tour-list .chip { font-weight: 600; }
.roman-fort { width: 10px; height: 10px; background: #a3201c; border: 2px solid #fff; box-shadow: 0 0 0 1px #a3201c; box-sizing: border-box; }
.pop-chart { margin: 6px 0 8px; }
.pop-chart svg { width: 100%; height: auto; display: block; }
.pop-chart .ax { font-size: 10px; fill: var(--muted); }
.pop-chart figcaption { font-size: 12px; }

/* Population by county: one row per county, bar scaled to the largest. */
.county-bars { list-style: none; padding: 0; margin: 6px 0; }
.county-bars li { margin: 0; }
.county-bars button { display: grid; grid-template-columns: 7.5em minmax(0, 1fr) 5.6em 3.6em; gap: 6px; align-items: center; width: 100%; min-height: 26px; padding: 2px 4px; border: 0; background: none; font: inherit; font-size: 13px; text-align: left; cursor: pointer; border-radius: 4px; color: inherit; }
.county-bars button:hover, .county-bars button.on { background: rgba(0, 0, 0, .05); }
.county-bars button:focus-visible { outline: 2px solid var(--accent); }
.cb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-bar { height: 8px; background: transparent; }
.cb-bar i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.cb-bar i.ni { opacity: .55; }
.cb-val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cb-chg { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); white-space: nowrap; }
.cb-chg.down { color: #b23a2e; }
.cb-chg.up { color: #2d6a4f; }
.county-card .pop-chart { margin-bottom: 0; }
