:root {
  --paper: #efe4c8;
  --paper-2: #e6d7b3;
  --paper-3: #d9c597;
  --ink: #33261a;
  --ink-2: #5e4a32;
  --ink-3: #8a7556;
  --wall: #7c2020;
  --water: #9db7b0;
  --water-ink: #4c6d69;
  --urban: #c98d6a;
  --accent: #a3301f;
  --person: #2d4a6b;
  --place: #33261a;
  --tl-h: 150px;
  --panel-w: 360px;
  --serif: "EB Garamond", Garamond, Georgia, serif;
  --fell: "IM Fell English", "EB Garamond", Georgia, serif;
  --fell-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #2a2119; color: var(--ink); font-family: var(--serif); }
#app { display: grid; grid-template-rows: auto 1fr var(--tl-h); height: 100%; }

/* ── masthead ── */
#masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 18px; background: #2a2119; color: #efe4c8; border-bottom: 1px solid #4a3a28;
}
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand-main { font-family: var(--fell-sc); font-size: 24px; letter-spacing: .04em; }
.brand-main .dot { color: #c9a35c; }
.brand-sub { font-family: var(--fell); font-style: italic; color: #bba987; font-size: 15px; }
.search { position: relative; }
#masthead { flex-wrap: wrap; }
#langs { display: flex; gap: 2px; margin-left: auto; }
#langs a { color: #bba987; text-decoration: none; font-family: var(--fell-sc); font-size: 14px; letter-spacing: .06em; padding: 4px 7px; border: 1px solid transparent; border-radius: 2px; }
#langs a:hover { color: #efe4c8; border-color: #5a4630; }
#langs a[aria-current] { color: #2a2119; background: #d8b878; }
.names-note { font-style: italic; }
#search {
  width: 280px; padding: 6px 10px; border-radius: 3px; border: 1px solid #5a4630;
  background: #3a2e22; color: #efe4c8; font-family: var(--serif); font-size: 15px;
}
#search::placeholder { color: #9b8a6c; }
#search-results {
  position: absolute; right: 0; top: 36px; z-index: 50; width: 340px; max-height: 60vh; overflow: auto;
  list-style: none; margin: 0; padding: 4px 0; background: var(--paper); border: 1px solid var(--ink-3);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
#search-results li { padding: 6px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
#search-results li:hover, #search-results li.active { background: var(--paper-2); }
#search-results .sr-year { color: var(--ink-3); font-variant-numeric: oldstyle-nums; }

/* ── stage ── */
#stage { display: grid; grid-template-columns: 1fr var(--panel-w); min-height: 0; }
#map-wrap { position: relative; overflow: hidden; background: var(--paper); min-height: 0; }
#map, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#overlay { pointer-events: none; }
#overlay .mk { pointer-events: all; cursor: pointer; }
.mk.cluster .c-bg { fill: rgba(51,38,26,.88); stroke: #efe4c8; stroke-width: 1.5; }
.mk.cluster .c-n { fill: #efe4c8; font-family: var(--fell); font-size: 12.5px; stroke: none; }
.mk.cluster .c-ev { fill: var(--accent); stroke: #f6ecd4; stroke-width: 1; }
.mk.cluster:hover .c-bg { fill: rgba(124,32,32,.92); }
#map-wrap::after { /* vignette */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 120px rgba(80, 55, 20, .35), inset 0 0 18px rgba(60, 40, 10, .35);
}

#cartouche {
  position: absolute; top: 16px; left: 16px; z-index: 3; min-width: 168px;
  padding: 10px 18px 12px; text-align: center; background: rgba(239, 228, 200, .94);
  border: 1px solid var(--ink-2); outline: 3px double var(--ink-2); outline-offset: 3px;
  box-shadow: 0 2px 10px rgba(50,30,10,.25);
}
.c-anno { font-family: var(--fell); font-style: italic; font-size: 14px; color: var(--ink-2); }
.c-roman { font-family: var(--fell-sc); font-size: 26px; letter-spacing: .06em; line-height: 1.1; }
.c-year { font-family: var(--fell); font-size: 15px; color: var(--ink-2); }
.c-era { font-family: var(--fell); font-style: italic; font-size: 13px; color: var(--accent); margin-top: 3px; max-width: 200px; }

#compass { position: absolute; right: 18px; top: 16px; width: 74px; height: 74px; z-index: 3; opacity: .85; }
#scalebar { position: absolute; left: 20px; bottom: 16px; z-index: 3; font-family: var(--fell); font-size: 13px; color: var(--ink); }
#scalebar .bar { height: 6px; border: 1px solid var(--ink); background: repeating-linear-gradient(90deg, var(--ink) 0 25%, transparent 25% 50%); margin-bottom: 2px; }
#map-controls { position: absolute; right: 18px; bottom: 16px; display: flex; flex-direction: column; gap: 4px; z-index: 3; }
#map-controls button {
  width: 32px; height: 32px; border: 1px solid var(--ink-2); background: rgba(239,228,200,.92); color: var(--ink);
  font-size: 18px; font-family: var(--serif); cursor: pointer; border-radius: 2px;
}
#map-controls button:hover { background: var(--paper-2); }

#tooltip {
  position: absolute; z-index: 10; pointer-events: none; max-width: 260px; padding: 6px 10px;
  background: rgba(36, 27, 18, .94); color: #f3e9d2; font-size: 14px; line-height: 1.3; border-radius: 2px;
  box-shadow: 0 3px 10px rgba(0,0,0,.3);
}
#tooltip .tt-y { color: #d8b878; font-style: italic; font-size: 13px; }

/* markers */
.mk .halo { fill: rgba(239,228,200,.85); }
.mk.event .sym { fill: var(--accent); stroke: #f6ecd4; stroke-width: 1.2; }
.mk.place .sym { fill: var(--place); stroke: #f6ecd4; stroke-width: 1; }
.mk.person .sym { fill: var(--person); stroke: #f6ecd4; stroke-width: 1.1; }
.mk.fresh .ring { stroke: var(--accent); fill: none; stroke-width: 1.5; animation: pulse 1.8s ease-out infinite; }
.mk.selected .sym { stroke: #ffd36b; stroke-width: 2.2; }
.mk text { font-family: var(--fell); font-size: 12.5px; fill: var(--ink); paint-order: stroke; stroke: rgba(239,228,200,.92); stroke-width: 3.5px; stroke-linejoin: round; pointer-events: none; }
.mk.person text { fill: var(--person); font-style: italic; }
.mk.event text { fill: #7b1d12; }
@keyframes pulse { 0% { r: 7; opacity: 1; } 100% { r: 20; opacity: 0; } }

/* ── panel ── */
#panel {
  overflow-y: auto; background: var(--paper); border-left: 1px solid var(--ink-3);
  padding: 16px 18px 24px; font-size: 15.5px; line-height: 1.45;
  background-image: linear-gradient(90deg, rgba(120,90,40,.08), transparent 18px);
}
#era-block { border-bottom: 1px solid var(--paper-3); padding-bottom: 10px; }
.era-years { font-family: var(--fell); font-style: italic; color: var(--ink-3); font-size: 14px; }
#era-name { font-family: var(--fell); font-weight: normal; font-size: 23px; line-height: 1.15; margin: 2px 0 6px; }
#era-text { margin: 0; color: var(--ink-2); }
.pblock h3 {
  font-family: var(--fell-sc); font-weight: normal; font-size: 16px; letter-spacing: .05em; color: var(--ink-2);
  margin: 16px 0 6px; border-bottom: 1px solid var(--paper-3); padding-bottom: 3px;
}
.itemlist { list-style: none; margin: 0; padding: 0; }
.itemlist li { display: grid; grid-template-columns: 54px 1fr; gap: 8px; padding: 3px 4px; cursor: pointer; border-radius: 2px; }
.itemlist li:hover { background: var(--paper-2); }
.itemlist li .y { color: var(--ink-3); font-variant-numeric: oldstyle-nums tabular-nums; text-align: right; font-size: 14px; padding-top: 1px; }
.itemlist li.now .y { color: var(--accent); font-weight: 600; }
.itemlist li .n { color: var(--ink); }
.itemlist .empty { color: var(--ink-3); font-style: italic; grid-template-columns: 1fr; cursor: default; }
.itemlist .empty:hover { background: none; }

.maps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mapcard { cursor: pointer; background: var(--paper-2); border: 1px solid var(--paper-3); padding: 4px; }
.mapcard:hover { border-color: var(--ink-3); }
.mapcard img { width: 100%; height: 96px; object-fit: cover; display: block; filter: sepia(.25); }
.mapcard .mt { font-size: 13px; line-height: 1.2; margin-top: 4px; }
.mapcard .my { font-size: 12px; color: var(--ink-3); font-style: italic; }

.layers { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 14.5px; }
.layers label { cursor: pointer; display: flex; gap: 6px; align-items: center; }
.layers input { accent-color: var(--ink-2); }

#legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 14px; }
#legend .lg { display: flex; align-items: center; gap: 8px; }
#legend svg { flex: none; }

.credits { font-size: 12.5px; color: var(--ink-3); margin-top: 18px; line-height: 1.4; }
.credits a { color: var(--ink-2); }

/* detail card */
#detail {
  position: relative; margin: -4px -6px 12px; padding: 12px 14px 12px; background: #f7efdc;
  border: 1px solid var(--ink-3); box-shadow: 0 2px 8px rgba(60,40,10,.15);
}
#detail .d-kind { font-family: var(--fell-sc); font-size: 13px; letter-spacing: .08em; color: var(--accent); }
#detail.person .d-kind { color: var(--person); }
#detail.place .d-kind { color: var(--ink-2); }
#detail h2 { font-family: var(--fell); font-weight: normal; font-size: 22px; margin: 2px 0 2px; line-height: 1.15; }
#detail .d-when { font-style: italic; color: var(--ink-3); margin-bottom: 6px; }
#detail p { margin: 0 0 6px; }
#detail .d-approx { font-size: 13px; color: var(--ink-3); font-style: italic; }
#detail .d-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
#detail button {
  font-family: var(--serif); font-size: 14px; padding: 3px 9px; border: 1px solid var(--ink-3); background: var(--paper);
  color: var(--ink); cursor: pointer; border-radius: 2px;
}
#detail button:hover { background: var(--paper-2); }
#detail .d-close { position: absolute; right: 6px; top: 4px; border: none; background: none; font-size: 20px; padding: 0 6px; }

/* ── timeline ── */
#timeline-wrap {
  display: grid; grid-template-columns: auto 1fr; background: #2a2119; border-top: 1px solid #4a3a28; min-height: 0;
}
#tl-controls { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; padding: 0 10px 0 14px; }
#tl-controls button {
  width: 40px; height: 30px; background: #3a2e22; color: #efe4c8; border: 1px solid #5a4630; cursor: pointer;
  font-size: 15px; border-radius: 2px; font-family: var(--serif);
}
#tl-controls button:hover { background: #4a3a2a; }
#tl-play { height: 38px !important; font-size: 17px !important; }
#tl-controls > button:not(#tl-play) { display: inline-block; }
#tl-controls { flex-direction: row; flex-wrap: wrap; width: 112px; align-content: center; }
#tl-speed { width: 100%; background: #3a2e22; color: #efe4c8; border: 1px solid #5a4630; font-family: var(--serif); }
#timeline { width: 100%; height: 100%; display: block; cursor: ew-resize; user-select: none; }
#timeline .era-band { opacity: .55; }
#timeline .era-label { font-family: var(--fell); font-style: italic; font-size: 12.5px; fill: #f2e7cd; pointer-events: none; }
#timeline .tick line { stroke: #9a8662; }
#timeline .tick text { fill: #cdbb97; font-family: var(--fell); font-size: 12px; }
#timeline .ev { cursor: pointer; }
#timeline .ev path { fill: #d9a35a; stroke: #2a2119; stroke-width: .8; }
#timeline .ev.place path { fill: #cdbb97; }
#timeline .ev.person path { fill: #8fb0d6; }
#timeline .ev:hover path, #timeline .ev.sel path { fill: #fff2c9; }
#timeline .handle line { stroke: #ffd36b; stroke-width: 2; }
#timeline .handle rect { fill: #ffd36b; }
#timeline .handle text { fill: #2a2119; font-family: var(--fell); font-size: 14px; font-weight: bold; }
#timeline .track-label { fill: #8d7b5c; font-family: var(--fell-sc); font-size: 11px; letter-spacing: .06em; }
#timeline .lane { stroke: #3e3226; }

/* ── lightbox ── */
#lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(20,14,8,.85); display: flex; align-items: center; justify-content: center; }
#lightbox[hidden] { display: none; }
.lb-inner { position: relative; width: min(1100px, 94vw); max-height: 92vh; display: grid; grid-template-columns: 1fr 300px; background: var(--paper); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lb-img { overflow: auto; max-height: 92vh; background: #1d1610; display: flex; align-items: center; justify-content: center; }
.lb-img img { max-width: 100%; display: block; }
.lb-meta { padding: 18px; overflow: auto; font-size: 15px; line-height: 1.45; }
.lb-meta h2 { font-family: var(--fell); font-weight: normal; margin: 0 0 4px; font-size: 22px; }
.lb-meta .lb-y { font-style: italic; color: var(--ink-3); }
.lb-meta a { color: var(--accent); }
.lb-close { position: absolute; right: 6px; top: 2px; z-index: 2; font-size: 26px; background: none; border: none; cursor: pointer; color: var(--ink); }

@media (max-width: 900px) {
  :root { --panel-w: 100%; --tl-h: 130px; }
  #stage { grid-template-columns: 1fr; grid-template-rows: 1fr 40%; }
  #panel { border-left: none; border-top: 1px solid var(--ink-3); }
  .brand-sub { display: none; }
  #search { width: 160px; }
  .lb-inner { grid-template-columns: 1fr; }
}
