:root {
  --paper: #f3ead7;
  --paper-2: #fbf7ec;
  --ink: #2a2318;
  --muted: #6e624f;
  --line: #ddcfb3;
  --accent: #8c2f1f;
  --sea: #d6ddd3;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ───────── Header ───────── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}
.brand h1 {
  margin: 0;
  font: 700 28px/1.05 var(--serif);
  letter-spacing: .01em;
}
.brand h1 span { color: var(--accent); }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

/* Search: suggestions drop down under the box as you type. */
.search { position: relative; flex: 0 1 300px; min-width: 200px; }
.search-ico { position: absolute; left: 10px; top: 50%; width: 15px; height: 15px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf6;
  padding: 7px 30px 7px 32px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
}
.search input::placeholder { color: #a39579; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 31, .12); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 5px;
  font: 11px/16px var(--sans); color: var(--muted); background: var(--paper-2);
  pointer-events: none;
}
.search input:focus ~ kbd { display: none; }

/* Settings: a gear beside search opening a small menu of viewer preferences. */
.settings { position: relative; margin-left: -16px; }
.settings-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fffdf6; color: var(--muted);
}
.settings-btn svg { width: 18px; height: 18px; }
.settings-btn:hover, .settings-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.settings-menu {
  position: absolute; z-index: 1200; top: calc(100% + 6px); right: 0;
  width: min(320px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper-2);
  box-shadow: 0 10px 30px rgba(40, 20, 0, .22);
  padding: 12px 14px;
}
.settings-menu h3 {
  margin: 0 0 8px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.set-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.set-row input { margin: 3px 0 0; accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }
.set-row b { display: block; font-weight: 600; font-size: 13.5px; }
.set-row small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 2px; }
.set-note { margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.search-results {
  position: absolute; z-index: 1200; top: calc(100% + 6px); left: 0;
  width: max(100%, 420px); max-width: calc(100vw - 32px); max-height: min(70vh, 520px);
  overflow-y: auto;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper-2);
  box-shadow: 0 10px 30px rgba(40, 20, 0, .22);
  padding: 4px 0 6px;
}
.sr-head {
  padding: 8px 14px 4px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}
.sr { display: flex; align-items: center; gap: 10px; padding: 6px 14px; cursor: pointer; }
.sr.on { background: #f0e3c8; }
.sr .ico { width: 14px; height: 14px; color: var(--accent); }
.sr-dot { width: 10px; height: 10px; flex-shrink: 0; border-radius: 50%; background: var(--c); margin: 0 2px; }
.sr-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sr-main b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-ent .sr-main b { font: 700 16px/1.2 var(--serif); }
.sr-main small { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr mark { background: none; color: var(--accent); font-weight: 700; }
.sr-count { flex-shrink: 0; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.sr-more, .sr-none { padding: 8px 14px 4px; font-size: 12px; color: var(--muted); }
.sr-more { border-top: 1px solid var(--line); margin-top: 4px; }

.eras { display: inline-flex; border: 1px solid var(--accent); border-radius: 7px; overflow: hidden; }
.eras button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 5px 12px;
  font: 700 15px/1.1 var(--serif);
  font-variant-numeric: lining-nums;
}
.eras button + button { border-left: 1px solid var(--accent); }
.eras button.on { background: var(--accent); color: #fff8ec; }

.jump, .filters { display: flex; flex-wrap: wrap; gap: 6px; }
.jump { margin-left: auto; }
.jump button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
}
.jump button:hover { background: var(--paper); border-color: var(--muted); }

.filters { flex-basis: 100%; }
.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  opacity: .45;
  transition: opacity .15s;
}
.filter.on { opacity: 1; }
.filter i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

/* ───────── Layout ───────── */
.layout {
  display: grid;
  grid-template-columns: 1fr 390px;
  min-height: 0;
}
#map { height: 100%; background: var(--sea); }
#map.no-land { background: var(--paper); }

.country-label span {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font: italic 500 13px/1 var(--serif);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #9a8a6c;
}

/* ───────── Panel ───────── */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid var(--line);
  background: var(--paper-2);
}
/* A tall header (a followed person with a portrait) scrolls rather than pushing the list out of the panel. */
.panel-head { padding: 14px 18px 12px; border-bottom: 1px solid var(--line); flex-shrink: 0; max-height: 62%; overflow-y: auto; }
.crumb { color: var(--muted); font-size: 12px; margin-top: 10px; }
.crumb a { color: var(--accent); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.panel-head h2 { margin: 2px 0 6px; font: 700 26px/1.1 var(--serif); }
.context { margin: 0 0 8px; color: #4a4030; font-size: 13px; }
.view-meta { font-size: 12px; color: var(--muted); }
.view-meta .more { color: var(--accent); }

.lod-steps { display: flex; gap: 3px; }
.lod-steps .step {
  flex: 1;
  text-align: center;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 0 3px;
  border-bottom: 3px solid var(--line);
  color: #a99c84;
}
.lod-steps .step.on { border-color: #c79a6b; color: var(--muted); }
.lod-steps .step.cur { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.lod-hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.lod-hint b { color: var(--accent); font-weight: 500; }

.panel-list { flex: 1; overflow-y: auto; padding: 10px 12px 16px; }
.card {
  position: relative;
  padding: 10px 12px 10px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.card::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--c, var(--accent));
}
.card:hover, .card:focus-visible { border-color: var(--muted); outline: none; transform: translateX(2px); }
.card h4 { margin: 3px 0 1px; font: 600 15px/1.25 var(--sans); }
.card.lvl1 h4 { font: 700 19px/1.15 var(--serif); }
.card .place { font-size: 12px; color: var(--muted); }
.card p { margin: 6px 0 0; font-size: 13px; color: #3d3427; }
.card p.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); }
.card .count { color: var(--accent); font-weight: 600; }
.region-card h4 { font: 700 20px/1.15 var(--serif); }
.region-card ul { margin: 6px 0 0; padding-left: 16px; font-size: 12.5px; }
.region-card li span { color: var(--muted); font-size: 11px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--c);
  font-weight: 600;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }

.empty { color: var(--muted); text-align: center; padding: 30px 12px; }

.sources {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin-top: 8px;
  font-size: 11.5px;
}
.sources span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.sources a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted currentColor; }
.sources a:hover, .sources a:focus-visible { border-bottom-style: solid; }

.panel-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: center;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
}
.panel-foot span { display: inline-flex; align-items: center; gap: 5px; }
.panel-foot .note { margin-left: auto; font-style: italic; }
.key { display: inline-block; border-radius: 50%; background: var(--muted); border: 1.5px solid #fff; }
.k1 { width: 14px; height: 14px; }
.k2 { width: 10px; height: 10px; }
.k3 { width: 7px; height: 7px; }

/* ───────── Markers ───────── */
.region-icon { display: flex; flex-direction: column; align-items: center; }
.bubble {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b9563f, var(--accent));
  border: 2px solid rgba(255, 250, 238, .9);
  box-shadow: 0 0 0 6px rgba(140, 47, 31, .15), 0 3px 10px rgba(60, 30, 10, .3);
  color: #fff8ec;
  transition: transform .15s;
}
.region-icon:hover .bubble { transform: scale(1.08); }
.b-count { font: 700 18px/1 var(--serif); }
.b-name {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 6px;
  white-space: nowrap;
  font: 700 14px/1 var(--serif);
  color: var(--ink);
  text-shadow: 0 0 3px #fbf7ec, 0 0 3px #fbf7ec, 0 0 6px #fbf7ec;
}

.dot {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid #fffaf0;
  box-shadow: 0 1px 4px rgba(40, 20, 0, .45);
  transition: transform .12s;
}
.dot.lvl3 { border-width: 1.5px; }
.dot.lvl1::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--c);
  opacity: .6;
  animation: pulse 2.4s ease-out infinite;
}
.ev-icon:hover .dot { transform: scale(1.3); }
@keyframes pulse {
  from { transform: scale(.6); opacity: .7; }
  to { transform: scale(1.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .dot.lvl1::after { animation: none; } }

.mlabel {
  position: absolute;
  left: calc(100% + 5px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(251, 247, 236, .93);
  border: 1px solid var(--line);
  font: 600 11.5px/1.2 var(--sans);
  color: var(--ink);
  pointer-events: none;
}
.mlabel small { display: block; font-weight: 400; color: var(--muted); font-size: 10.5px; }

/* ───────── Leaflet overrides ───────── */
.leaflet-container { font-family: var(--sans); }
.tip.leaflet-tooltip {
  background: var(--paper-2);
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(40, 20, 0, .2);
  font-size: 12px;
  max-width: 280px;
  white-space: normal;
}
.tip ul { margin: 4px 0; padding-left: 16px; }
.tip em { color: var(--accent); font-size: 11px; }
.ev-popup .leaflet-popup-content-wrapper,
.ev-popup .leaflet-popup-tip { background: var(--paper-2); color: var(--ink); }
.ev-popup .leaflet-popup-content { margin: 14px 16px; }
.pop h3 { margin: 4px 0 2px; font: 700 21px/1.15 var(--serif); }
.pop .place { font-size: 12px; color: var(--muted); }
.pop p { margin: 8px 0 0; font-size: 13px; line-height: 1.5; }
.pop-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--muted); }

/* ───────── People and topics ───────── */
.ico { width: 12px; height: 12px; flex-shrink: 0; fill: currentColor; }

.ents { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.ent {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  border: 1px solid #d9c49e;
  background: #fff8e8;
  color: var(--ink);
  border-radius: 999px;
  padding: 2px 9px 2px 7px;
  font-size: 11.5px;
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
.ent .ico { color: var(--accent); }
.ent span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ent em {
  font-style: normal;
  font-size: 10.5px;
  color: var(--muted);
  padding-left: 5px;
  border-left: 1px solid #e3d3b4;
}
.ent:hover, .ent:focus-visible { background: var(--accent); border-color: var(--accent); color: #fff8ec; outline: none; }
.ent:hover .ico, .ent:hover em, .ent:focus-visible .ico, .ent:focus-visible em { color: #fff8ec; border-color: rgba(255, 248, 236, .4); }

.ent-link {
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(140, 47, 31, .45);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.ent-link:hover, .ent-link:focus-visible { color: var(--accent); text-decoration-color: var(--accent); outline: none; }

.focus-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--paper-2);
  box-shadow: 0 3px 12px rgba(40, 20, 0, .2);
  font-size: 13px;
}
.focus-pill[hidden] { display: none; }
.focus-pill .ico { color: var(--accent); width: 14px; height: 14px; }
.focus-pill b { font: 700 16px/1 var(--serif); }
.focus-pill button {
  width: 24px; height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff8ec;
  font-size: 12px;
  line-height: 1;
}

.focus-bar { display: flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 600; }
.focus-bar button {
  margin-left: auto;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11.5px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--ink);
}
.focus-bar button:hover { border-color: var(--muted); background: var(--paper); }
/* Back to the route you were following before this one. */
.back {
  display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 60%;
  border: 1px solid var(--accent) !important; border-radius: 999px;
  background: var(--accent) !important; color: #fff8ec !important;
  padding: 3px 10px 3px 8px;
  font-size: 11.5px; font-weight: 600; text-transform: none; letter-spacing: 0;
}
.focus-bar .back { margin-left: 0; }
.back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back:hover { filter: brightness(1.12); }
.focus-pill .back { width: auto; height: auto; margin-right: 4px; font-size: 12px; }
.context a { color: var(--accent); }

.view-meta:has(.scope) { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.scope { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.scope button { border: 0; background: transparent; padding: 4px 9px; font-size: 11.5px; }
.scope button + button { border-left: 1px solid var(--line); }
.scope button.on { background: var(--accent); color: #fff8ec; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button {
  width: 26px; height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fffdf7;
  font-size: 16px;
  line-height: 1;
}
.stepper button:hover { border-color: var(--accent); color: var(--accent); }
.stepper b { color: var(--accent); }

.era-div {
  margin: 14px 2px 4px;
  font: 700 20px/1 var(--serif);
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 10px;
}
.era-div::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.era-div:first-child { margin-top: 2px; }
.decade {
  margin: 10px 2px 6px;
  font: 600 11px/1 var(--sans);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.decade span { text-transform: none; letter-spacing: 0; font-weight: 400; }

.step-card { padding-left: 44px; }
.step-card .num, .stop {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font: 700 11px/1 var(--sans);
  border: 2px solid #fffaf0;
  box-shadow: 0 1px 4px rgba(40, 20, 0, .4);
}
.step-card .num { position: absolute; left: 12px; top: 11px; width: 24px; height: 24px; }
.step-card::before { display: none; }
.step-card.cur { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(140, 47, 31, .18); }
.step-card time b { color: var(--ink); font-weight: 600; }
.stop { width: 100%; height: 100%; transition: transform .15s; }
.stop.cur { transform: scale(1.35); box-shadow: 0 0 0 4px rgba(140, 47, 31, .35), 0 2px 8px rgba(40, 20, 0, .5); }
.ev-icon:hover .stop { transform: scale(1.2); }
.ghost { opacity: .22; pointer-events: none; }
.ghost .dot { border-width: 1px; box-shadow: none; }
.route { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 2 6; stroke-linecap: round; fill: none; opacity: .3; }
.route-leg { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 6; stroke-linecap: round; fill: none; opacity: .9; }

/* ───────── Timeline ───────── */
.timeline {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr);
  gap: 10px 24px;
  align-items: center;
  padding: 10px 20px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
}
.tl-now { display: flex; align-items: center; gap: 14px; min-width: 0; }
.tl-year { font: 700 40px/1 var(--serif); color: var(--accent); white-space: nowrap; }
.tl-headline {
  margin: 0;
  font-size: 12.5px;
  color: #4a4030;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tl-controls { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; flex-shrink: 0; }
.mode button { border: 0; background: transparent; padding: 6px 10px; font-size: 12px; }
.mode button.active { background: var(--accent); color: #fff8ec; }
.play {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
}
.play:hover { background: var(--accent); color: #fff8ec; }

.years { display: flex; gap: 3px; flex: 1; min-width: 0; }
.yr {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: 0;
  background: transparent;
  padding: 2px 0;
  border-radius: 5px;
}
.yr .n { font-size: 10px; line-height: 1; height: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.yr.cur .n { color: var(--accent); font-weight: 700; }
.yr.zero .y { opacity: .45; }
.focusing .yr .bar i { background: #e3d3b4; }
.focusing .yr:not(.zero) .bar i { background: #c48a62; }
.focusing .yr.cur .bar i { background: var(--accent); }
.yr .bar { display: flex; align-items: flex-end; width: 60%; max-width: 26px; height: 24px; }
.yr .bar i { display: block; width: 100%; border-radius: 3px 3px 0 0; background: #d6c3a0; }
.yr .y { font-size: 11.5px; color: var(--muted); }
.yr.on .bar i { background: #c48a62; }
.yr.cur .bar i { background: var(--accent); }
.yr.cur .y { color: var(--accent); font-weight: 700; }
.yr:hover { background: var(--paper); }

/* ───────── Small screens ───────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(260px, 1fr) minmax(0, 42%); }
  .topbar > * { min-width: 0; max-width: 100%; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .timeline { grid-template-columns: minmax(0, 1fr); padding: 8px 16px 10px; }
  .mode button { padding: 6px 8px; }
  .tl-now { display: none; }
  .tl-controls { flex-wrap: wrap; }
  .years { flex-basis: 100%; }
  .tl-year { font-size: 30px; }
  .jump { margin-left: 0; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .jump button { flex-shrink: 0; }
  .topbar { padding: 10px 16px; }
  .search { flex: 1 1 calc(100% - 50px); }
  .settings { margin-left: -14px; }
  .search kbd { display: none; }
  .search-results { width: 100%; }
  .brand h1 { font-size: 22px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; }
  .filter { flex-shrink: 0; }
  .yr .y { font-size: 10px; }
}

/* ───────── Phones ─────────
   The map fills the screen under the header (title, search, eras). The panel is a bottom sheet over it,
   like Google Maps: it peeks with the timeline, and its grip drags or taps it to
   half or full height, where the region and category buttons, description and list follow.
   app.js moves the timeline, regions and categories into the sheet. */
.panel-grip, .sheet-filters { display: none; }
@media (max-width: 600px) {
  .topbar { position: relative; gap: 8px; padding: 8px 12px; }
  .brand p { display: none; }
  .brand h1 { font-size: 21px; }
  .search { flex: 1 1 calc(100% - 50px); min-width: 0; }
  .search input { padding-block: 9px; font-size: 16px; } /* 16px stops iOS zooming in on focus */
  .settings { position: static; margin-left: 0; }
  .settings-menu { right: 12px; }
  .settings-btn { width: 42px; height: 42px; } /* as tall as the search box */
  .settings-btn svg { width: 20px; height: 20px; }
  .eras { display: flex; flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; }
  .eras::-webkit-scrollbar { display: none; }
  .eras button { flex-shrink: 0; white-space: nowrap; padding: 7px 11px; font-size: 15px; }

  .layout { position: relative; grid-template-rows: minmax(0, 1fr); }
  /* Map controls at the bottom stay above the peeking sheet. */
  #map .leaflet-bottom { bottom: var(--peek, 0px); }
  .panel {
    position: absolute; z-index: 1100; left: 0; right: 0; bottom: 0;
    height: 150px;
    overflow-y: auto; overscroll-behavior: contain;
    border: 0; border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 22px rgba(40, 20, 0, .22);
    transition: height .25s ease;
  }
  .panel.dragging { transition: none; }
  .panel-grip {
    display: grid; place-items: center; flex-shrink: 0;
    position: sticky; top: 0; z-index: 2;
    height: 26px; width: 100%; border: 0; padding: 0;
    background: var(--paper-2); border-radius: 16px 16px 0 0;
    touch-action: none; cursor: grab;
  }
  .panel-grip span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); transition: background .15s; }
  .panel-grip:hover span, .panel-grip:focus-visible span { background: var(--muted); }
  .panel-head { padding: 8px 14px 10px; max-height: none; overflow: visible; }
  .panel-head h2 { font-size: 22px; }
  .panel-list { flex: none; overflow: visible; }
  .panel-foot { display: none; }
  .sheet-filters { display: grid; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .sheet-filters .jump, .sheet-filters .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0; }
  .jump button, .filter { padding: 6px 11px; }

  .timeline { flex-shrink: 0; gap: 6px; padding: 0 12px 8px; border-top: 0; border-bottom: 1px solid var(--line); }
  .mode button { padding: 8px 10px; }
  .play { width: 38px; height: 38px; }
  .yr .bar { height: 16px; }

  /* Popups stay inside the shorter map: the gallery is lower and long text scrolls. */
  .ev-popup .leaflet-popup-content { margin: 12px 14px; max-height: 40vh; overflow-y: auto; }
  .pop .g-frame { height: 120px; }
}
/* Touch phones zoom with a pinch, so the +/− buttons only cover the map. */
@media (max-width: 600px) and (pointer: coarse) {
  .leaflet-control-zoom { display: none; }
}

/* ───────── Images (Wikimedia Commons, always credited) ───────── */
.gallery { margin: 0 0 10px; }
.pop .gallery { width: min(288px, 70vw); }
.g-frame {
  position: relative;
  height: 172px;
  border-radius: 6px;
  overflow: hidden;
  background: #2b241b;
}
.g-frame img { display: block; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; }
.g-nav, .g-full {
  position: absolute;
  border: 0;
  background: rgba(20, 14, 6, .55);
  color: #fff8ec;
  line-height: 1;
  transition: background .12s;
}
.g-nav:hover, .g-full:hover, .g-nav:focus-visible, .g-full:focus-visible { background: rgba(140, 47, 31, .9); outline: none; }
.g-nav { top: 50%; transform: translateY(-50%); width: 28px; height: 40px; font-size: 22px; }
.g-prev { left: 0; border-radius: 0 6px 6px 0; }
.g-next { right: 0; border-radius: 6px 0 0 6px; }
.g-full { top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 5px; font-size: 15px; }
.g-count {
  position: absolute; left: 8px; bottom: 6px;
  padding: 1px 7px; border-radius: 999px;
  background: rgba(20, 14, 6, .6); color: #fff8ec; font-size: 10.5px;
}
.g-credit { margin-top: 4px; font-size: 10.5px; line-height: 1.35; color: var(--muted); overflow-wrap: anywhere; }
.g-credit a { color: var(--muted); text-decoration: underline; text-decoration-color: rgba(110, 98, 79, .4); }
.g-credit a:hover { color: var(--accent); }

.portrait { margin-top: 10px; }
.portrait .g-frame { height: 190px; }
@media (max-width: 900px) { .portrait .g-frame { height: 130px; } }

.has-img { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; color: var(--muted); font-size: 11px; }
.has-img svg { width: 12px; height: 12px; fill: currentColor; }
.g-show {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 0 10px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: #fffdf6; color: var(--muted); font-size: 12px;
}
.g-show svg { width: 13px; height: 13px; fill: currentColor; }
.g-show:hover { color: var(--accent); border-color: var(--accent); }
.portrait .g-show { margin: 0; }

/* Full-screen viewer */
.lightbox {
  position: fixed; inset: 0; z-index: 3000;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(18, 13, 7, .94);
  color: #f3ead7;
}
.lightbox[hidden] { display: none; }
.lb-top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.lb-title { flex: 1; min-width: 0; font: 700 20px/1.2 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-count { font-size: 12px; color: #c9bb9f; }
.lb-top button, .lb-nav {
  border: 0; border-radius: 6px;
  background: rgba(255, 248, 236, .1); color: #fff8ec;
  width: 36px; height: 36px; font-size: 16px; line-height: 1;
}
.lb-top button:hover, .lb-nav:hover, .lb-top button:focus-visible, .lb-nav:focus-visible { background: var(--accent); outline: none; }
.lb-stage { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 0; padding: 0 16px; }
.lb-stage img { max-width: calc(100% - 120px); max-height: 100%; object-fit: contain; box-shadow: 0 8px 40px rgba(0, 0, 0, .5); }
.lb-nav { flex-shrink: 0; width: 44px; height: 64px; font-size: 30px; }
.lb-nav[hidden] { display: none; }
.lb-cap { padding: 10px 16px 14px; text-align: center; }
.lb-desc { margin: 0 auto 4px; max-width: 80ch; font-size: 13.5px; color: #e9dfc8; }
.lb-credit { margin: 0; font-size: 12px; color: #c9bb9f; }
.lb-credit a { color: #f0c9a0; }
@media (max-width: 600px) {
  .lb-stage { padding: 0 6px; gap: 4px; }
  .lb-stage img { max-width: calc(100% - 72px); }
  .lb-nav { width: 32px; height: 52px; font-size: 24px; }
}
