/* Map page layout: panel, map, time bar. Loaded after style.css and Leaflet's CSS. */
body.is-app { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.is-app .site-header { position: static; flex: 0 0 auto; }
.app-main { flex: 1 1 auto; min-height: 0; display: flex; }
.map-app { flex: 1; display: grid; grid-template-columns: 20rem 1fr; grid-template-rows: 1fr auto; grid-template-areas: "panel map" "panel time"; min-height: 0; width: 100%; position: relative; }
.panel { grid-area: panel; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 0.4rem 1rem 1rem; font-size: 0.9rem; }
.map-wrap { grid-area: map; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--water); font-family: var(--font-body); }
.loading { position: absolute; z-index: 500; left: 50%; top: 1rem; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); padding: 0.4rem 0.9rem; border-radius: 6px; margin: 0; }
.loading[hidden] { display: none; }
.timebar { grid-area: time; background: var(--surface); border-top: 1px solid var(--line); padding: 0.5rem 1rem 0.7rem; }
.panel-toggle { display: none; }

.panel-sec { padding: 0.5rem 0 0.7rem; border-bottom: 1px solid var(--line); }
.panel-sec h2 { font-size: 1.15rem; margin: 0.3rem 0 0.4rem; }
.panel input[type=search] { width: 100%; }
.opt { display: flex; align-items: center; gap: 0.45rem; padding: 0.12rem 0; cursor: pointer; }
.opt-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.2rem 0; }
.opt-row select { max-width: 11rem; min-width: 8.5rem; text-overflow: ellipsis; }
.more summary { cursor: pointer; color: var(--muted); margin-top: 0.3rem; }
.s-out { list-style: none; padding: 0; margin: 0.3rem 0 0; max-height: 11rem; overflow-y: auto; }
.s-out li { padding: 0.15rem 0; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 0.15em; cursor: pointer; text-align: left; }
.now-counts { margin: 0.2rem 0 0.4rem; font-variant-numeric: tabular-nums; }
.panel-foot { margin-top: 0.8rem; }
.key { display: inline-block; width: 12px; height: 12px; flex: 0 0 auto; }
.key-place { background: var(--republic); border-radius: 50%; } .key-prov { border: 2px solid var(--republic); transform: rotate(30deg); border-radius: 3px; }
.key-road { height: 0; border-top: 3px dashed #f2a900; width: 16px; filter: drop-shadow(0 0 1px #2b1b0a) drop-shadow(0 0 1px #2b1b0a); } .key-road2 { height: 0; border-top: 2px solid #7b2d26; width: 16px; }
.key-event { background: var(--empire); transform: rotate(45deg) scale(0.8); } .key-people { background: #1f6f6b; border-radius: 2px; }
.key-river { height: 0; border-top: 2px solid #2f7f9e; width: 16px; } .key-sea { height: 0; border-top: 2px dotted #3c9fd0; width: 16px; }
.key-venue { background: #2b6a9b; border-radius: 50% / 38%; }
.key-theatre { background: #c8691a; width: 12px; height: 7px; border-radius: 12px 12px 0 0; display: inline-block; vertical-align: middle; }
.key-custom { background: #5b6b2f; clip-path: polygon(50% 0, 100% 100%, 0 100%); }

/* time bar */
.time-read { display: flex; align-items: baseline; gap: 0.3rem; flex-wrap: wrap; }
.year-out { font-family: var(--font-display); font-size: 2rem; font-weight: 600; min-width: 7.5rem; font-variant-numeric: tabular-nums; }
.era-out { font-weight: 600; } .era-out.era-kingdom { color: var(--kingdom); } .era-out.era-republic { color: var(--republic); } .era-out.era-empire { color: var(--empire); }
.period-out, .sep { color: var(--muted); }
.time-controls { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin: 0.2rem 0 0.5rem; }
.time-controls button, .time-controls select { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
#play { min-width: 4.5rem; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.jumps { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-left: auto; }
.slider-wrap { position: relative; }
.band { position: relative; height: 2.3rem; border-radius: 4px; overflow: hidden; background: var(--line); cursor: pointer; }
.band-seg { position: absolute; top: 0; bottom: 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 0.2rem; box-sizing: border-box; font-size: 0.72rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; }
.band-seg.era-kingdom { background: var(--kingdom); } .band-seg.era-republic { background: var(--republic); } .band-seg.era-empire { background: var(--empire); }
@media (prefers-color-scheme: dark) { .band-seg { color: #14170f; } }
.band-tick { position: absolute; bottom: 0; transform: translateX(-50%); font-size: 0.66rem; font-weight: 600; color: #fff; opacity: 1; padding-bottom: 1px; pointer-events: none; }
@media (prefers-color-scheme: dark) { .band-tick { color: #14170f; } }
.marker { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--ink); box-shadow: 0 0 0 1px var(--surface); pointer-events: none; }
#year { width: 100%; margin: 0.25rem 0 0; accent-color: var(--accent); }

/* markers */
.mk { background: none; border: 0; }
.mk svg { display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35)); overflow: visible; }
.mk.is-ended svg { opacity: 0.38; }
.mk.is-recent svg { filter: drop-shadow(0 0 4px rgba(255, 200, 80, 0.95)) drop-shadow(0 1px 1px rgba(0,0,0,0.4)); }
.mk-prov svg { filter: none; opacity: 0.85; }
.badge-n { position: absolute; right: -6px; top: -6px; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px; background: var(--ink); color: var(--surface); font: 600 9px/14px var(--font-body); text-align: center; pointer-events: none; }
.mk:focus-visible svg { outline: 2px solid var(--accent); outline-offset: 2px; }

/* popups */
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--ink); border-radius: 8px; }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-container a { color: var(--accent); }
.pop { font-family: var(--font-body); font-size: 0.88rem; line-height: 1.45; }
.pop h3 { margin: 0 0 0.15rem; font-size: 1.15rem; } .pop p { margin: 0.3rem 0; } .pop-meta { color: var(--muted); font-size: 0.78rem; }
.pop-list { margin: 0.3rem 0; padding-left: 1.1rem; max-height: 14rem; overflow-y: auto; } .pop-when { color: var(--muted); font-size: 0.78rem; }

@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) {
  .map-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "map" "time"; }
  .panel { position: absolute; z-index: 800; left: 0; right: 0; top: 0; bottom: auto; max-height: 70%; transform: translateY(-110%); transition: transform 0.2s; box-shadow: 0 6px 16px rgba(0,0,0,0.25); }
  .panel.is-open { transform: none; }
  .panel-toggle { display: block; position: absolute; z-index: 850; top: 0.5rem; right: 0.5rem; background: var(--surface); }
  .year-out { font-size: 1.5rem; min-width: 6rem; } .jumps { margin-left: 0; }
  .band-seg { font-size: 0.6rem; }

  /* Phones: give the map most of the screen. A one-line scrolling menu, and a compact time bar. */
  body.is-app .site-header { position: relative; z-index: 1300; }
  body.is-app .site-header .parent { display: none; }
  .timebar { padding: 0.3rem 0.6rem 0.45rem; min-width: 0; }
  .time-controls, .time-read, .slider-wrap { min-width: 0; }
  .time-read { gap: 0.1rem 0.4rem; }
  .year-out { font-size: 1.3rem; min-width: 0; }
  .era-out, .period-out, .sep { font-size: 0.85rem; }
  .time-controls { gap: 0.3rem; margin: 0.1rem 0 0.3rem; }
  .time-controls button, .time-controls select { padding: 0.35rem 0.5rem; font-size: 0.82rem; }
  #play { min-width: 3.4rem; }
  .jumps { flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .jumps::-webkit-scrollbar { display: none; }
  .jumps button { flex: 0 0 auto; white-space: nowrap; }
  .band { height: 1.1rem; } .band-seg { font-size: 0.55rem; align-items: center; padding-top: 0; } .band-tick { display: none; }
  #year { margin: 0.15rem 0 0; }
  .leaflet-control-attribution { font-size: 9px; max-width: 78vw; line-height: 1.25; }
}

/* Phones held sideways (short screens): one compact row of time controls, a slim header, so the map keeps most of the height */
@media (max-height: 500px) and (pointer: coarse) {
  body.is-app .site-header { padding: 0.15rem 0.6rem; }
  .js body.is-app .site-header { padding: 0.15rem 0.6rem; }
  .js .site-header .brand { font-size: 1.05rem; }
  .js .nav-toggle { padding: 0.2rem 0.7rem; font-size: 0.82rem; }
  .timebar { display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.6rem; padding: 0.2rem 0.6rem 0.25rem; }
  .time-read { flex: 0 0 auto; }
  .year-out { font-size: 1.1rem; }
  .sep, .period-out { display: none; }
  .time-controls { flex: 1 1 0; flex-wrap: nowrap; overflow-x: auto; margin: 0; scrollbar-width: none; align-items: center; }
  .time-controls::-webkit-scrollbar { display: none; }
  .time-controls > * { flex: 0 0 auto; }
  .jumps { flex: 0 0 auto; margin-left: 0.2rem; }
  .time-controls button, .time-controls select { padding: 0.2rem 0.5rem; font-size: 0.78rem; }
  .slider-wrap { flex: 1 0 100%; }
  .band { height: 0.8rem; }
  #year { margin: 0; height: 1.2rem; }
  .panel { max-height: 100%; padding-left: 3.4rem; padding-right: 10rem; }
}

/* Marker name tooltip (above the marker) */
.leaflet-tooltip.mk-tip { font-family: inherit; font-size: 0.85rem; padding: 2px 7px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,0.18); }
.leaflet-tooltip-top.mk-tip::before { border-top-color: var(--line); }
.layer-link { display: block; margin: -0.15rem 0 0.5rem 1.65rem; font-size: 0.85rem; }

/* Modern country names (borders layer): quiet background labels */
.sea-label { pointer-events: none; }
.sea-label span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font-family: var(--font-body); font-style: italic; font-size: 0.85rem; letter-spacing: 0.18em; text-transform: uppercase; color: #3d6478; opacity: 0.9; text-shadow: 0 0 3px #e6eff3, 0 0 5px #e6eff3; }
@media (prefers-color-scheme: dark) { .sea-label span { color: #9cc0d2; text-shadow: 0 0 3px #1a252b, 0 0 5px #1a252b; } }
.cn-label { pointer-events: none; }
.cn-label span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font-family: var(--font-body); font-style: italic; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: #6b2f2f; opacity: 0.8; text-shadow: 0 0 3px #fffaf0, 0 0 3px #fffaf0, 0 0 5px #fffaf0; }

/* Layer boxes can be swept with the mouse, so the rows must not select text */
.panel-sec .opt { user-select: none; -webkit-user-select: none; }

/* Limes: the nested checkboxes in the Layers panel, and the page list */
.key-limes { background: #d6178a; width: 14px; height: 3px; border-radius: 2px; display: inline-block; vertical-align: middle; }
.limes-tree { margin: 2px 0 6px 4px; font-size: 0.92em; }
.limes-tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.limes-tree ul.lm-root { padding-left: 0; }
.limes-tree .lm-row { display: flex; align-items: baseline; gap: 2px; }
.limes-tree .lm-tg { width: 1.2em; flex: none; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: center; }
.limes-tree .lm-none { cursor: default; }
.limes-tree .lm-tag { color: #777; font-size: 0.85em; }
.limes-tree .opt { margin: 1px 0; }

/* Layers: All on / All off */
.layer-all { margin: 0 0 0.45rem; }
.btn-sm { font: inherit; font-size: 0.85rem; padding: 0.15rem 0.6rem; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }
.btn-sm:hover, .btn-sm:focus-visible { background: rgba(128,128,128,0.15); }

/* Clusters of overlapping markers */
.mk-cluster-wrap { background: none; border: 0; }
.mk-cluster { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; background: #3a2e22; color: #f6efe0; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.4); font: 600 12px/1 var(--font-body); cursor: pointer; box-sizing: border-box; }
.mk-cluster.is-limes { background: #d6178a; }
.mk-cluster.is-limes:hover { background: #e23fa3; }
/* Clusters of a single layer take that layer's colour (same colours as the Layers panel keys); mixed clusters stay brown. */
.mk-cluster.is-places, .mk-cluster.is-places:hover { background: #8c2f2f; }
.mk-cluster.is-events, .mk-cluster.is-events:hover { background: #4b3f72; }
.mk-cluster.is-people, .mk-cluster.is-people:hover { background: #1f6f6b; }
.mk-cluster.is-customs, .mk-cluster.is-customs:hover { background: #5b6b2f; }
.mk-cluster.is-amph, .mk-cluster.is-amph:hover { background: #2b6a9b; }
.mk-cluster.is-theatre, .mk-cluster.is-theatre:hover { background: #c8691a; }
.mk-cluster[class*=" is-"]:hover { filter: brightness(1.2); }
.mk-cluster:hover { background: #5a4430; }
.mk-cluster-wrap:focus-visible .mk-cluster { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Modern cities (base map) */
.mc-wrap { background: none; border: 0; }
.mc-dot { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid #444; background: #fff; box-sizing: content-box; margin: -2px 0 0 -2px; }
.mc-name { position: absolute; left: 12px; top: -8.5px; white-space: nowrap; font-family: var(--font-body); font-size: 0.816rem; font-weight: 600; -webkit-text-stroke: 0.4px #292929; color: #292929; text-shadow: 0 0 3px #fffaf0, 0 0 3px #fffaf0, 0 0 4px #fffaf0; }

/* Compass rose (top right of the map) */
.leaflet-top .leaflet-control.compass-rose { pointer-events: none; margin: 10px 10px 0 0; line-height: 0; opacity: 0.92; }
.compass-rose svg { display: block; filter: drop-shadow(0 0 2px var(--surface)); }
.compass-rose .cr-ring { fill: var(--surface); fill-opacity: 0.55; stroke: #6b2f2f; stroke-width: 0.8; }
.compass-rose .cr-a { fill: #6b2f2f; }
.compass-rose .cr-b { fill: #c9a98f; stroke: #6b2f2f; stroke-width: 0.5; }
.compass-rose .cr-hub { fill: var(--surface); stroke: #6b2f2f; stroke-width: 0.8; }
.compass-rose .cr-t { font: 600 11px var(--font-body); fill: var(--ink); }
.compass-rose .cr-t.cr-n { font-size: 13px; fill: #b3392b; }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) { .compass-rose svg { width: 58px; height: 58px; } .leaflet-top .leaflet-control.compass-rose { margin: 62px 6px 0 0; } }

/* Scale bar */
.leaflet-control-scale-line { background: var(--surface); color: var(--ink); border-color: var(--ink); font-family: var(--font-body); font-size: 0.72rem; opacity: 0.92; }
/* Keep the attribution clear of the scale bar at the bottom left: it wraps onto more lines instead of running under it */
/* The credits list sits on the bottom row, between the scale bar (left) and the Credits button (right) */
#map .leaflet-bottom.leaflet-right { left: 0; }
#map .leaflet-control-attribution { display: none; position: absolute; right: 96px; bottom: 0; margin: 0; max-width: calc(100% - 300px); box-sizing: border-box; background: var(--surface); color: var(--ink); font-size: 0.68rem; line-height: 1.35; padding: 3px 8px; border-radius: 4px 4px 0 0; }
#map.credits-open .leaflet-control-attribution { display: block; }
.credits-btn { margin: 0 !important; clear: both; }
.credits-btn button { font: inherit; font-size: 0.74rem; padding: 2px 9px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-right: 0; border-bottom: 0; border-radius: 4px 0 0 0; cursor: pointer; opacity: 0.92; }
.credits-btn button:hover, .credits-btn button:focus-visible { border-color: var(--accent); }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) { #map .leaflet-control-attribution { font-size: 0.6rem; max-width: calc(100% - 225px); right: 90px; } }

/* Famous roads: dark edge round the amber line */
.road-famous { filter: drop-shadow(0 0 1px #2b1b0a) drop-shadow(0 0 1px #2b1b0a); }

/* "The end" button: Jerome's words, centred over the map for a while */
.end-quote { position: absolute; z-index: 1100; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, 86%); max-height: 86%; overflow: hidden; box-sizing: border-box; padding: 1.1rem 1.4rem; border-radius: 6px; background: rgba(28, 22, 18, 0.86); color: #f3ead8; text-align: center; font-family: var(--font-body); pointer-events: none; opacity: 0; visibility: hidden; transition: opacity 1.5s ease, visibility 0s linear 1.5s; }
.end-quote.show { opacity: 1; visibility: visible; transition: opacity 1.5s ease; }
.end-quote blockquote { margin: 0 0 0.9rem; }
.end-quote p { margin: 0; font-style: italic; font-size: 1.05rem; line-height: 1.45; }
.end-quote footer { margin-top: 0.35rem; font-size: 0.78rem; letter-spacing: 0.03em; opacity: 0.8; }
.end-quote .eq-credit { font-style: normal; font-size: 0.68rem; opacity: 0.6; }
@media (max-width: 800px) { .end-quote { padding: 0.8rem 1rem; } .end-quote p { font-size: 0.86rem; } .end-quote blockquote { margin-bottom: 0.6rem; } }
@media (prefers-reduced-motion: reduce) { .end-quote, .end-quote.show { transition: none; } }
