:root {
  --bg: #15171c;
  --panel: #1c1f26;
  --panel-2: #242832;
  --line: #333845;
  --text: #e8e4da;
  --muted: #9a9688;
  --accent: #e0a64a;
  --ocean: #b8d4e3;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 13px/1.4 var(--sans);
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- header bar ---------- */
#top { position: relative; flex: none; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1000; }
/* Two rows: playback controls with About at the right; then views, focus and the ticker. */
.bar { display: flex; flex-direction: column; gap: 6px; padding: 8px 14px; }
.bar-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { font: 700 20px var(--serif); letter-spacing: 0.02em; color: var(--accent); white-space: nowrap; }
.year-display { display: flex; align-items: baseline; gap: 6px; min-width: 130px; font-family: var(--serif); }
#yearNum { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
#yearEra { font-size: 16px; color: var(--muted); font-weight: 700; }

.controls, .jump, .tl-zoom { display: flex; gap: 4px; align-items: center; }
.controls button, .jump button, .tl-zoom button, select, .jump input {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 9px; cursor: pointer; min-height: 30px;
}
.controls button:hover, .jump button:hover, .tl-zoom button:hover { border-color: var(--accent); }
.controls button.primary { background: var(--accent); color: #1a1408; border-color: var(--accent); min-width: 42px; font-weight: 600; }
.jump input { width: 76px; cursor: text; }
/* Major events "as they happen", right-aligned under the About button. The height is
   fixed (one line, overflow clipped) so the layout below never shifts. */
.ticker {
  flex: 1 1 260px; min-width: 260px; height: 28px; overflow: hidden;
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  white-space: nowrap;
}
.ticker-item {
  display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; flex: 0 1 auto;
  padding: 3px 9px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2);
  color: var(--text); font-size: 12px; cursor: pointer; overflow: hidden;
}
.ticker-item:hover { border-color: var(--accent); }
.ticker-item b { flex: none; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.ticker-item span { overflow: hidden; text-overflow: ellipsis; }
.ticker-item.major { border-color: rgba(224, 166, 74, 0.55); }
.ticker-item.fresh { animation: ticker-in 0.5s ease-out; }
@keyframes ticker-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .ticker-item.fresh { animation: none; } }

.about-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; min-height: 30px; color: var(--text); cursor: pointer;
}
.about-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- About dialog ---------- */
.about {
  width: min(320px, calc(100vw - 32px)); padding: 28px 24px 22px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.about::backdrop { background: rgba(0, 0, 0, 0.55); }
.about .close {
  position: absolute; top: 10px; right: 10px; padding: 2px 8px;
  background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--muted); cursor: pointer;
}
.about .close:hover { border-color: var(--line); color: var(--text); }
.about img { display: block; margin: 0 auto 14px; border-radius: 50%; border: 1px solid var(--line); }
.about h2 { margin: 0 0 6px; font: 700 22px var(--serif); }
.about h2 span { color: var(--accent); }
.about p { margin: 0; font-size: 14px; }
.about nav { display: flex; justify-content: center; gap: 8px; margin: 16px 0; }
.about nav a {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel-2); color: var(--text); font-weight: 600; text-decoration: none;
}
.about nav a:hover { border-color: var(--accent); color: var(--accent); }
.about .dim { color: var(--muted); font-size: 13px; }

/* ---------- search & people ---------- */
.search { position: relative; flex: 1 1 220px; max-width: 340px; }
.search input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; min-height: 32px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.search-results {
  position: absolute; z-index: 2000; top: calc(100% + 4px); left: 0; right: 0; min-width: 300px;
  max-height: 60vh; overflow-y: auto; list-style: none; margin: 0; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.search-results li { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-results li.active, .search-results li:hover { background: #3a3122; }
.search-results li.empty { color: var(--muted); cursor: default; }
.search-results .ico { width: 22px; text-align: center; flex: none; }
.search-results .txt { display: flex; flex-direction: column; min-width: 0; }
.search-results .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results small { color: var(--muted); font-size: 11px; }
.pp-hint { font-size: 12px; margin: 4px 0 6px; }
.pp-list { list-style: none; margin: 0; padding: 0; }
.pp-list li { display: flex; flex-direction: column; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.pp-list li:hover { background: var(--panel-2); }
.pp-name { font-weight: 600; }
.pp-what { font-size: 12px; color: #cfcabd; }
.pp-list small { color: var(--muted); font-size: 11px; }

/* ---------- country focus ---------- */
.focus-select { display: flex; align-items: center; gap: 6px; }
.focus-select span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.focus-select select { min-height: 30px; }
.focus-banner { margin: -2px 0 8px; padding: 4px 8px; border-radius: 6px; background: #22304a; color: #cfe0ff; font-size: 12px; }

/* ---------- timeline view toggle ---------- */
.tl-mode { display: flex; align-items: center; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.tl-mode span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 6px; }
.tl-mode button { background: none; border: 0; border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 12px; color: var(--muted); }
.tl-mode button:hover { color: var(--text); }
.tl-mode button.on { background: var(--accent); color: #1a1408; font-weight: 600; }

/* focus lanes: labelled lifespans / inventions */
.fitem { position: absolute; cursor: pointer; }
.fitem .fbar { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 3px; opacity: 0.5; }
.fitem.span .fbar { opacity: 0.45; }
.fitem.active .fbar { opacity: 1; box-shadow: 0 0 0 1px rgba(255,255,255,0.7); }
.fitem .flabel { position: absolute; top: 0; white-space: nowrap; font-size: 11px; line-height: 13px; padding: 0 4px; color: #f3efe6; text-shadow: 0 1px 2px rgba(0,0,0,0.8); cursor: pointer; }
.fitem.point .fbar { opacity: 0.95; }
.fitem.point .flabel { color: #f0d98a; }
.fitem.compact .flabel { font-size: 10px; line-height: 11px; }
.fitem.age .fbar { opacity: 0.6; }
.fitem .flabel.clipped { overflow: hidden; text-overflow: ellipsis; }
.fitem.age.active .fbar { opacity: 1; }
.fitem.war.active .fbar { box-shadow: 0 0 0 1px #f2b3a8; }
.fitem.point.battle .flabel { color: #f2b3a8; }
.fitem:hover .fbar { opacity: 1; }
.fitem:hover .flabel { color: #fff; }

/* ---------- timeline ---------- */
#timeline { display: grid; grid-template-columns: 64px 1fr 34px; border-top: 1px solid var(--line); user-select: none; }
.tl-labels { padding-top: 4px; border-right: 1px solid var(--line); }
.tl-lane-label { display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tl-track { position: relative; overflow: hidden; padding-top: 4px; cursor: ew-resize; touch-action: none; }
.tl-grid { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.tl-grid div { position: absolute; top: 0; bottom: 0; width: 0; }
.tl-grid .g500 { border-left: 1px dashed rgba(255,255,255,0.08); }
.tl-grid .g1000 { border-left: 1px solid rgba(255,255,255,0.2); }
.tl-grid .g0 { border-left: 2px solid rgba(224,166,74,0.85); box-shadow: 0 0 6px rgba(224,166,74,0.45); }
.tl-grid .g0 span { position: absolute; top: 0; left: 3px; font-size: 9px; font-weight: 600; letter-spacing: 0.05em; color: var(--accent); background: rgba(28,31,38,0.85); padding: 0 3px; border-radius: 3px; white-space: nowrap; }
.tl-lanes, .tl-axis { position: relative; z-index: 1; }
.tl-lane { position: relative; border-bottom: 1px dashed rgba(255,255,255,0.05); }
.band {
  position: absolute; border-radius: 3px; color: #fff; font-size: 10px; line-height: 14px;
  padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0.55; cursor: pointer;
}
.band.active { opacity: 1; box-shadow: 0 0 0 1px rgba(255,255,255,0.7); }
.band.person { border-radius: 2px; padding: 0; opacity: 0.45; }
.band.person.active { box-shadow: none; opacity: 1; }
.band.war { padding: 0; }
.band.empire { font-size: 10px; line-height: 13px; }
.tick { position: absolute; width: 3px; border-radius: 1px; cursor: pointer; opacity: 0.85; }
.tick:hover { transform: scaleX(1.8); opacity: 1; }
.tl-axis { position: relative; height: 18px; border-top: 1px solid var(--line); }
.tl-tick { position: absolute; top: 0; transform: translateX(-50%); font-size: 10px; color: var(--muted); padding-top: 3px; white-space: nowrap; }
.tl-tick::before { content: ''; position: absolute; top: 0; left: 50%; height: 3px; border-left: 1px solid var(--muted); }
.tl-cursor { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px solid var(--accent); pointer-events: none; z-index: 3; }
/* The current year, in a bubble on the year bar. */
.tl-cursor-year {
  position: absolute; top: 7px; left: -1px; transform: translateX(-50%);
  background: var(--accent); color: #1a1408; font-size: 11px; font-weight: 700; line-height: 16px;
  padding: 0 6px; border-radius: 4px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* The year bar: a prominent strip at the top of the timeline; click or drag it to set the year. */
.tl-ruler {
  position: relative; z-index: 2; height: 26px; margin-bottom: 3px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; cursor: pointer;
}
.tl-ruler:hover { border-color: rgba(224,166,74,0.6); background: #2a2f3a; }
.tl-ruler-ticks .tl-tick { color: #cfcabd; font-size: 11px; padding-top: 6px; }
.tl-ruler-ticks .tl-tick::before { height: 4px; border-left-color: #8a8577; }
.tl-ruler-hover { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid rgba(255,255,255,0.75); pointer-events: none; }
.tl-ruler-hover span {
  position: absolute; top: 4px; left: 5px; background: #0f1115; color: var(--text); border: 1px solid var(--line);
  font-size: 11px; line-height: 16px; padding: 0 5px; border-radius: 4px; white-space: nowrap;
}
.tl-ruler-label {
  height: 26px; margin-bottom: 3px; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent);
}
.tl-zoom { flex-direction: column; justify-content: center; padding: 4px; border-left: 1px solid var(--line); }
.tl-zoom button { padding: 0; width: 24px; min-height: 22px; font-size: 13px; }

.tooltip {
  position: fixed; z-index: 3000; max-width: 300px; pointer-events: none;
  background: #0f1115; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.tooltip strong { display: block; font-size: 13px; }
.tooltip .tt-range { color: var(--accent); font-size: 11px; }
.tooltip p { margin: 4px 0 0; color: #c8c4b8; font-size: 12px; }

/* ---------- resizable layout ---------- */
.splitter { flex: none; background: var(--panel); position: relative; z-index: 1001; touch-action: none; }
.splitter::after { content: ''; position: absolute; background: var(--line); border-radius: 2px; transition: background 0.15s; }
.splitter:hover::after, .splitter.dragging::after { background: var(--accent); }
.splitter-h { height: 7px; cursor: row-resize; border-bottom: 1px solid var(--line); }
.splitter-h::after { left: 50%; top: 2px; width: 44px; height: 3px; margin-left: -22px; }
.splitter-v { width: 7px; cursor: col-resize; border-left: 1px solid var(--line); }
.splitter-v::after { top: 50%; left: 2px; height: 44px; width: 3px; margin-top: -22px; }
#timeline { overflow: hidden; }
body.resizing, body.resizing * { cursor: inherit !important; user-select: none !important; }
#panel.collapsed { width: 0; border-left: 0; overflow: hidden; }

/* ---------- main ---------- */
main { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; position: relative; background: var(--ocean); }
.leaflet-container { background: var(--ocean); font-family: var(--sans); }
.loading {
  position: absolute; z-index: 1000; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(21,23,28,0.85); color: var(--text); padding: 6px 14px; border-radius: 16px; font-size: 12px;
}

#panel { width: var(--panel-w, 330px); flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); }
#panel section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
#panel h2 { margin: 0 0 8px; font: 700 26px var(--serif); }
#panel h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.now-row { display: grid; grid-template-columns: 52px 1fr; gap: 6px; margin: 5px 0; align-items: start; }
.now-label { font-size: 11px; color: var(--muted); padding-top: 3px; }
.chip { display: inline-block; margin: 0 4px 4px 0; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--panel-2); border-left: 3px solid var(--c, var(--accent)); }
.chip.war { --c: #c0392b; cursor: pointer; }
.chip.war:hover { background: #33262a; }

.filters { display: flex; flex-wrap: wrap; gap: 5px; }
.filter { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--c); font-size: 12px; cursor: pointer; }
.filter input { display: none; }
.filter.off { opacity: 0.4; border-color: var(--line); text-decoration: line-through; }

.event-list { list-style: none; margin: 0; padding: 0; }
.event-list li { display: flex; gap: 8px; padding: 6px 6px; border-radius: 6px; cursor: pointer; align-items: flex-start; }
.event-list li:hover { background: var(--panel-2); }
.event-list li.selected { background: #3a3122; outline: 1px solid var(--accent); }
.event-list li.empty { color: var(--muted); cursor: default; }
.event-list .ico { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--c) 30%, transparent); font-size: 13px; }
.event-list .txt { display: flex; flex-direction: column; }
.event-list .t { font-weight: 500; }
.event-list .w { color: var(--muted); font-size: 11px; }
.geo-item p { margin: 3px 0 10px; color: #c8c4b8; font-size: 12px; }
.credits { color: var(--muted); font-size: 11px; }
.credits a { color: var(--accent); }

/* ---------- map elements ---------- */
.polity-label { pointer-events: none; }
.polity-label span {
  display: block; transform: translate(-50%, -50%); width: max-content; text-align: center;
  font-family: var(--serif); font-weight: 700; color: #2c261c; line-height: 1.05;
  text-shadow: 0 0 3px rgba(255,255,255,0.85), 0 0 2px rgba(255,255,255,0.85);
  letter-spacing: 0.02em; white-space: normal;
}
.polity-label.non-state span { font-style: italic; font-weight: 500; color: #5b5242; }
.polity-tip { font-family: var(--sans); font-size: 12px; }
.polity-tip .muted { color: #6b665b; }
.geo-tip { max-width: 260px; white-space: normal; }

.ev-marker {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: #fffaf0; border: 2px solid var(--c); font-size: 13px; line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.35); cursor: pointer; transition: transform 0.12s;
}
.ev-marker:hover { transform: scale(1.2); }
.ev-marker.portrait { width: 32px; height: 32px; border-width: 2.5px; background-color: #fffaf0; background-size: cover; background-position: center 20%; font-size: 0; }
.ev-label {
  position: absolute; left: calc(100% + 3px); top: 50%; transform: translateY(-50%);
  display: none; white-space: nowrap; pointer-events: auto; cursor: pointer;
  font: 600 11px/16px var(--sans); color: #2c261c; background: rgba(255, 250, 240, 0.92);
  border-left: 3px solid var(--c); border-radius: 3px; padding: 0 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.ev-marker-wrap.show-label .ev-label { display: block; }
.ev-marker-wrap.label-left .ev-label { left: auto; right: calc(100% + 3px); border-left: 0; border-right: 3px solid var(--c); }
.ev-marker-wrap.selected .ev-label { background: #fff3d6; }
.ev-marker-wrap.selected .ev-marker { transform: scale(1.35); box-shadow: 0 0 0 3px var(--accent), 0 2px 8px rgba(0,0,0,0.5); }
.ev-popup h4 { margin: 2px 0; font: 700 17px var(--serif); }
.ev-popup .ev-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.ev-popup .ev-range { color: #8a6a2c; font-size: 12px; font-weight: 600; }
.ev-popup p { margin: 6px 0 0; }

/* ---------- country dialog ---------- */
main { position: relative; }
.polity-dialog {
  position: absolute; z-index: 1100; top: 12px; left: 56px; width: 340px; max-height: calc(100% - 24px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
.polity-dialog h3 { margin: 0 24px 2px 0; font: 700 24px/1.1 var(--serif); color: var(--accent); }
.polity-dialog h4 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.polity-dialog .close { position: absolute; top: 8px; right: 10px; background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.polity-dialog .close:hover { color: var(--text); }
.pd-sub { color: var(--muted); font-size: 12px; }
.pd-about { margin-top: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pd-desc { margin: 6px 0 10px; color: #cfcabd; }
.pd-fact { display: flex; gap: 8px; font-size: 12px; margin-bottom: 10px; }
.pd-fact span { color: var(--muted); min-width: 52px; }
.leader { background: var(--panel-2); border-left: 3px solid var(--accent); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.leader.none { border-left-color: var(--line); }
.leader-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.leader-name { font: 700 19px/1.2 var(--serif); margin-top: 2px; }
.leader-title { font-size: 12px; color: var(--accent); }
.leader p { margin: 6px 0 0; font-size: 12px; color: #cfcabd; }
.polity-dialog button.link { margin-top: 6px; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; }
.polity-dialog button.link:hover { text-decoration: underline; }
.pd-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 4px 0 6px; }
.pd-nav button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; cursor: pointer; font-size: 12px; text-align: left; }
.pd-nav button:last-child { text-align: right; }
.pd-nav button:hover { border-color: var(--accent); }
.pd-nav small, .pd-rulers small, .pd-events small { display: block; color: var(--muted); font-size: 10px; }
.pd-rulers summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 4px 0; }
.pd-rulers ol { list-style: none; margin: 4px 0 0; padding: 0; max-height: 220px; overflow-y: auto; }
.pd-rulers li { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; padding: 3px 6px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.pd-rulers li small { display: inline; white-space: nowrap; }
.pd-rulers li:hover { background: var(--panel-2); }
.pd-rulers li.current { background: #3a3122; color: var(--accent); }
.pd-events { list-style: none; margin: 0; padding: 0; }
.pd-events li { padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.pd-events li:hover { background: var(--panel-2); }
.pd-events li small { display: inline; margin-left: 4px; }

.name-link { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; text-decoration: underline; text-decoration-color: rgba(224,166,74,0.5); text-underline-offset: 3px; }
.name-link:hover { color: var(--accent); text-decoration-color: var(--accent); }
.name-hint { font-size: 0.75em; opacity: 0.7; }
.pd-succession { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.pd-succession button { flex: 1 1 140px; background: #2b2a33; border: 1px dashed var(--muted); border-radius: 6px; padding: 5px 8px; cursor: pointer; font-size: 12px; text-align: left; }
.pd-succession button:hover { border-color: var(--accent); border-style: solid; }
.pd-succession small { display: block; color: var(--muted); font-size: 10px; }

/* ---------- person & voyage dialog ---------- */
.detail-dialog { left: auto; right: calc(var(--panel-w, 330px) + 18px); width: 360px; }
.dd-back { display: block; margin-bottom: 6px; }
.dd-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.dd-portrait { width: 84px; height: 104px; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.dd-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; margin-bottom: 2px; }
.dd-epithet { color: #cfcabd; font-size: 13px; }
.dd-life { color: var(--accent); font-size: 12px; margin-top: 4px; }
.dd-now { font: 700 16px/1.25 var(--serif); margin-top: 2px; }
.dd-quote { margin: 10px 0; padding: 6px 10px; border-left: 3px solid var(--line); font: italic 500 16px/1.3 var(--serif); color: #e8e4da; }
.dd-quote cite { display: block; margin-top: 4px; font: normal 11px var(--sans); color: var(--muted); }
.dd-roles, .dd-legacy { margin: 0; padding-left: 18px; font-size: 12px; color: #cfcabd; }
.dd-roles li, .dd-legacy li { margin-bottom: 3px; }
.dd-roles small { color: var(--muted); }
.dd-voyages { display: flex; flex-direction: column; gap: 4px; }
.dd-voyages button, .dd-replay { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; cursor: pointer; text-align: left; font-size: 12px; }
.dd-voyages button:hover, .dd-replay:hover { border-color: var(--accent); }
.dd-voyages small { color: var(--muted); margin-left: 4px; }
.dd-replay { margin: 4px 0 2px; color: var(--accent); }
.dd-stops { list-style: none; margin: 0; padding: 0 0 0 10px; border-left: 2px solid var(--line); }
.dd-stops li { position: relative; display: flex; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 12px; color: var(--muted); }
.dd-stops li::before { content: ''; position: absolute; left: -15px; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dd-stops li.reached { color: var(--text); }
.dd-stops li.reached::before { background: var(--muted); }
.dd-stops li.current { background: #3a3122; color: var(--accent); }
.dd-stops li.current::before { background: var(--accent); }
.dd-stops li:hover { background: var(--panel-2); }
.dd-stops small { flex: none; width: 58px; color: var(--muted); }
.dd-chips { display: flex; flex-wrap: wrap; }
.chip.clickable { cursor: pointer; }
.chip.clickable:hover { background: #3a3122; }
.dd-wiki { display: inline-block; margin-top: 12px; color: var(--accent); font-size: 12px; }
.band.voyage { padding: 0; }
.ship-icon { font-size: 22px; line-height: 26px; text-align: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }

/* ---------- cities ---------- */
.city-marker { display: flex; align-items: center; gap: 4px; white-space: nowrap; width: auto !important; height: auto !important; }
.city-marker .dot { flex: none; width: 10px; height: 10px; background: #fffaf0; border: 2px solid #2c261c; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,0.4); }
.city-marker .nm { font: 700 12px var(--serif); color: #2c261c; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff; }
.city-marker:hover .dot { background: var(--accent); }
.dd-names { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-bottom: 10px; }
.dd-names .chip { border-left-color: #4a6a9f; font-size: 12px; }
.dd-names .chip.cur { background: #3a3122; color: var(--accent); }
.dd-names .chip small { color: var(--muted); }
.dd-names .arrow { color: var(--muted); margin: 0 2px 4px 0; }

/* ---------- subregions ---------- */
.subregion-label { pointer-events: none; }
.subregion-label span {
  display: block; transform: translate(-50%, -50%); width: max-content; white-space: nowrap;
  font: italic 500 11px/1 var(--serif); letter-spacing: 0.04em; color: rgba(44,38,28,0.75);
  text-shadow: 0 0 2px rgba(255,255,255,0.9), 0 0 2px rgba(255,255,255,0.9);
}
/* U.S. states, colonies and territories: darker and larger than other subregions. */
.subregion-label.state span, .subregion-label.district span, .subregion-label.territory span, .subregion-label.colony span {
  font-size: 13px; font-weight: 600; color: rgba(25, 20, 12, 0.95);
  text-shadow: 0 0 2px #fff, 0 0 3px #fff, 0 0 4px rgba(255,255,255,0.9);
}
.subregion-label.colony span { color: rgba(110, 40, 20, 0.95); }
/* A historic land outlined inside a larger state (Egypt in the caliphates). */
.subregion-label.region-outline-label span { font-size: 15px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(44,38,28,0.7); }
.polity-label.sub span { font-style: italic; font-weight: 500; opacity: 0.8; }
.pd-country { margin: 0 0 10px; padding: 6px 10px; background: #22304a; border-radius: 6px; font-size: 12px; color: #cfe0ff; }
.pd-country strong { font: 700 17px var(--serif); color: #fff; }
.pd-country-k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #9fb4d8; }
.pd-country-note { margin-top: 2px; color: #b9c8e4; }
.pd-region { margin: 0 0 10px; padding: 6px 10px; border: 1px dashed var(--line); border-radius: 6px; font-size: 12px; }
.pd-region strong { font: 700 15px var(--serif); margin-left: 4px; }
.pd-region-kind { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.pd-region p { margin: 3px 0 0; color: #cfcabd; }

/* ---------- trade routes ---------- */
/* Clicking an SVG shape gave it a browser focus ring drawn around its whole bounding box. */
.leaflet-container path:focus, .leaflet-container .leaflet-interactive:focus { outline: none; }
.trade-hit { cursor: pointer; }
/* Moving dashes show the direction goods flowed. */
.trade-line { stroke-dasharray: 10 8; animation: trade-flow 25.6s linear infinite; }
.trade-line.land { stroke-dasharray: 3 7; }
.trade-line.strong { stroke-dasharray: 14 6; }
@keyframes trade-flow { to { stroke-dashoffset: -36; } }
@media (prefers-reduced-motion: reduce) { .trade-line { animation: none; } }
.dd-legs { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.dd-legs li { display: flex; gap: 8px; align-items: center; padding: 3px 0; color: #cfcabd; }
.dd-legs .swatch { flex: none; width: 22px; height: 0; border-top: 3px dashed var(--c); }
.dd-legs li.strong .swatch { border-top-width: 5px; border-top-style: solid; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  main { flex-direction: column; }
  #map { min-height: 60vh; }
  #panel { width: auto; border-left: 0; }
  .bar { padding: 8px 12px; }
  .bar-row { gap: 10px; }
  #timeline { grid-template-columns: 48px 1fr 30px; }
  .splitter { display: none; }
  .polity-dialog { left: 8px; right: 8px; width: auto; max-height: 55vh; }
  .detail-dialog { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; }
}
