/* One type scale, one card, one marker grammar. Tokens are in site.css. */
#date-display { position: absolute; z-index: 1000; top: 16px; left: 50%; transform: translateX(-50%); padding: 6px 20px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: var(--ink); font-family: var(--font-display); font-size: var(--text-heading); font-weight: 600; }
#legend-panel, #layer-panel, #details, .ancestry-popup-wrap .leaflet-popup-content-wrapper, .leaflet-tooltip {
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--card-radius); box-shadow: var(--card-shadow); color: var(--ink); padding: 16px;
}
#legend-panel, #layer-panel, #details { position: absolute; z-index: 1001; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
#legend-panel { bottom: 112px; left: 16px; width: 324px; max-height: calc(100dvh - 192px); }
#layer-panel { display: none; right: 16px; top: 70px; width: 340px; max-height: calc(100dvh - 182px); }
#layer-panel.open { display: block; }
#details { top: 80px; left: 16px; width: 360px; max-height: calc(100dvh - 192px); }
body:has(#details:not([hidden])) #legend-panel { max-height: 210px; }
#details-close { float: right; min-height: 44px; margin: -4px -4px 8px 8px; }
#details h3, .noah-popup > strong { display: block; font: 600 var(--text-title)/1.15 var(--font-display); color: var(--ink); margin-bottom: 12px; }
#details h4, .legend-title, .layer-panel-title { font: 600 var(--text-heading)/1.15 var(--font-display); color: var(--ink); margin: 16px 0 8px; }
#legend-colour .legend-title, .layer-panel-title { margin-top: 0; }
#details p, #details li, .noah-popup, .howto-body, .noah-explain { font-size: var(--text-body); line-height: 1.4; }
#details p, .howto-body p { margin-bottom: 10px; }
#details ul { margin-left: 18px; }
#details .big { font: 600 var(--text-title)/1.2 var(--font-display); }
#details .note, .rank-unit, .history-data { font-size: var(--text-xs); color: var(--ink-muted); }
#details .note { margin-top: 8px; }
#howto, #map-key, .noah-ranked-section, #named-key, .noah-nav { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 4px; }
#map-key p, .legend-item { font-size: var(--text-sm); line-height: 1.35; }
#grade-key { display: grid; gap: 10px; margin: 12px 0 4px; }
.legend-item { display: flex; align-items: center; gap: 10px; }
#place-ranking > summary { font: 600 var(--text-heading)/1.2 var(--font-display); }
.noah-ramp-wrap { position: relative; height: 46px !important; margin-top: 12px; }
.noah-ramp { display: flex; height: 12px; border-radius: 2px; overflow: hidden; }
.noah-ramp .grad { flex: 1; }
.noah-tick { position: absolute; font-size: var(--text-xs); transform: translateX(-50%); color: var(--ink-muted); white-space: nowrap; }
.noah-sw { display: inline-block; width: 16px; height: 16px; flex: 0 0 16px; border-radius: 50%; border: 1.5px solid var(--ink); }
.sw-solid, .sw-outline, .sw-faint { background: var(--accent-wash); }
.sw-outline { border-style: dashed; }
.sw-faint { border-style: dotted; }
.sw-zone { border: 0; border-radius: 2px; background: var(--accent); opacity: .2; }
.sw-empty { background: transparent; }
.sw-man { width: 7px; height: 7px; flex-basis: 7px; margin: 0 4.5px; background: var(--gold); border: 0; }
.sw-name { width: 7px; height: 7px; flex-basis: 7px; margin: 0 4.5px; background: var(--ink); border: 0; }
.grade-line { display: flex; gap: 10px; align-items: flex-start; }
.grade-line .noah-sw { margin-top: 4px; }
.noah-rank-row { display: flex; gap: 10px; align-items: center; width: 100%; min-height: 44px; text-align: left; padding: 8px 0; background: transparent; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-size: var(--text-sm); }
.noah-rank-row:last-child { border-bottom: 0; }
.noah-rank-row:hover, .noah-rank-row[aria-current="true"] { background: var(--accent-wash); }
.noah-rank-row .noah-sw { width: 10px; height: 10px; flex-basis: 10px; border: 0; border-radius: 2px; background: var(--rank-colour); }
.rank-name { flex: 1; min-width: 0; }
.rank-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-empty { font-size: var(--text-sm); color: var(--ink-muted); padding: 8px 0; }
.key-group-title { color: var(--ink-muted); font-size: var(--text-xs); margin: 8px 0; }
.hidden-title { display: none; }
.key-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.key-row { display: flex; gap: 6px; align-items: center; font-size: var(--text-sm); min-width: 0; }
.key-name { font-style: italic; overflow-wrap: anywhere; }
.key-place { color: var(--ink-muted); font-style: normal; }
.key-age { margin-left: auto; font-size: var(--text-xs); color: var(--ink-muted); }
.key-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; }
.noah-nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.return-home-btn { display: inline-flex; min-height: 36px; align-items: center; font-size: var(--text-sm); text-decoration: none; }
.layer-toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: var(--text-body); }
.layer-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
#layers-toggle { position: absolute; top: 16px; right: 16px; z-index: 1001; min-height: 44px; }
.mobile-map-controls { display: none; }
.noah-camera-follow { position: absolute; top: 62px; left: 50%; transform: translateX(-50%); z-index: 1001; min-height: 44px; border-radius: 24px; }
/* Stable typography during every fractional camera frame. */
.nation-label span { color: var(--ink) !important; font-size: var(--text-sm) !important; font-weight: 500 !important; text-shadow: var(--label-shadow) !important; }
.travel-dot-label span, .babel-scatter-label span { font-family: var(--font-body) !important; font-size: var(--text-sm) !important; font-weight: 400 !important; color: var(--ink) !important; text-shadow: var(--label-shadow) !important; }
.noah-walk-tooltip { font-family: var(--font-body); }
.leaflet-tooltip { font: 400 var(--text-sm)/1.35 var(--font-body); padding: 10px 12px; white-space: normal; width: max-content; max-width: 280px; }
.leaflet-tooltip-top::before { border-top-color: var(--line-strong); }
.leaflet-tooltip.name-label { background: transparent; border: 0; box-shadow: none; text-shadow: var(--label-shadow); padding: 0; font-family: var(--font-display); font-size: var(--text-sm); }
.leaflet-tooltip.name-label::before { display: none; }
.ancestry-popup-wrap .leaflet-popup-content { width: 290px !important; max-width: calc(100vw - 64px); margin: 0; max-height: 42vh; overflow-y: auto; overscroll-behavior: contain; font-family: var(--font-body); }
.ancestry-popup-wrap .leaflet-popup-content-wrapper { padding-top: 24px; }
.ancestry-popup-wrap .leaflet-popup-tip { background: var(--surface); box-shadow: none; }
.leaflet-container a.leaflet-popup-close-button { font: 400 var(--text-heading)/40px var(--font-body); width: 44px; height: 44px; color: var(--ink-muted); }
.noah-popup .pm { margin-top: 10px; }
.noah-popup .pm strong { font-weight: 500; }
.name-links { display: flex; flex-wrap: wrap; gap: 8px; }
.name-links button { min-height: 44px; }
/* Charts share the type and colour system. The scale and samples are unchanged. */
.history-figure { margin: 20px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.concentration-history { display: block; width: 100%; height: auto; overflow: visible; }
.concentration-history text { fill: var(--ink-muted); font-family: var(--font-body); font-size: var(--text-xs); }
.history-grid { stroke: var(--line); stroke-width: 1; }
.history-band { fill: var(--accent); fill-opacity: .18; }
.history-median { fill: none; stroke: var(--accent); stroke-width: 2; }
.history-arrival { stroke: var(--gold-bright); stroke-width: 1.5; stroke-dasharray: 4 3; }
.history-current { stroke: var(--ink); stroke-width: 1; }
.history-point { fill: var(--accent); stroke: var(--bg); stroke-width: 1; }
.history-figure figcaption { font-size: var(--text-sm); line-height: 1.4; margin: 10px 0; }
.history-data { margin-top: 8px; }
.history-arrival-swatch, .history-current-swatch { display: inline-block; width: 16px; margin-right: 5px; vertical-align: middle; border-top: 2px solid var(--ink); }
.history-arrival-swatch { border-top: 2px dashed var(--gold-bright); }
/* Navigation stays visible while paused. Period labels have their own reading timer. */
#timeline-container { position: absolute; z-index: 1001; bottom: 0; width: 100%; height: 96px; background: var(--surface); border-top: 1px solid var(--line); padding: 8px 16px; }
#timeline-markers { position: relative; height: 32px; margin: 0 170px 0 64px; }
.timeline-marker { position: absolute; line-height: 1.1; transform: translateX(-50%); font-size: var(--text-xs); color: var(--ink-muted); background: transparent; border: 0; padding: 0; white-space: nowrap; }
.timeline-marker.lower { top: 16px; }
.timeline-marker::before { content: ''; position: absolute; top: -5px; left: 50%; height: 4px; border-left: 1px solid var(--ink-muted); }
#timeline-slider-row { display: flex; align-items: center; gap: 12px; }
#play-btn { flex: 0 0 44px; height: 44px; border-radius: 50%; font-size: var(--text-heading); color: var(--accent-strong); padding: 0; }
#slider-wrap { flex: 1; min-width: 0; }
#timeline-slider { width: 100%; appearance: none; height: 4px; background: var(--line-strong); border-radius: 2px; cursor: pointer; }
#timeline-slider::-webkit-slider-thumb { appearance: none; width: 18px; height: 18px; background: var(--accent); border: 2px solid var(--ink); border-radius: 50%; }
#timeline-slider::-moz-range-thumb { width: 16px; height: 16px; background: var(--accent); border: 2px solid var(--ink); border-radius: 50%; }
#speed-control { display: flex; gap: 4px; }
.speed-btn { min-height: 36px; padding: 4px 8px; }
.leaflet-bottom { bottom: 100px; }
.leaflet-control-zoom a { background: var(--surface); color: var(--ink); font-family: var(--font-body); font-size: var(--text-heading); font-weight: 400; }
.leaflet-control-zoom a:hover { background: var(--surface); color: var(--accent); }
.leaflet-control-attribution { background: var(--surface) !important; color: var(--ink-muted); font: 400 var(--text-xs)/1.2 var(--font-body); }
.leaflet-control-attribution a { color: var(--accent); }
.noah-edge-markers { position: absolute; inset: 0; z-index: 1000; pointer-events: none; }
.noah-edge-marker { position: absolute; width: 28px; height: 28px; padding: 0; border-radius: 50%; color: var(--accent); font-size: var(--text-sm); line-height: 26px; pointer-events: auto; transform: translate(-50%, -50%) rotate(var(--direction)); transition: none; }
body:has(.leaflet-popup) .noah-edge-markers { visibility: hidden; }
@media (max-width: 768px) {
    #date-display { top: 10px; padding: 4px 16px; }
    .mobile-map-controls { display: flex; gap: 8px; position: absolute; top: 54px; left: 12px; z-index: 1002; }
    .mobile-map-btn { min-height: 44px; min-width: 72px; }
    #layers-toggle { display: none; }
    .noah-camera-follow { top: 54px; right: 12px; left: auto; transform: none; font-size: var(--text-sm); padding: 6px 10px; }
    #legend-panel, #layer-panel, #details { left: 12px; right: 12px; width: auto; bottom: 108px; top: auto; max-height: 44dvh; }
    #legend-panel, #layer-panel { display: none; }
    #legend-panel.mobile-open, #layer-panel.mobile-open { display: block; }
    body:has(#details:not([hidden])) #legend-panel { max-height: 44dvh; }
    .key-rows { grid-template-columns: 1fr; }
    #timeline-container { height: 96px; padding: 8px 12px; }
    #timeline-markers { height: 24px; margin: 0 10px; }
    .timeline-marker { min-height: 24px; min-width: 24px; }
    .timeline-marker .yr { display: none; }
    #timeline-slider-row { gap: 10px; }
    #speed-control .speed-btn { min-height: 44px; min-width: 36px; padding: 4px; }
    .leaflet-control-zoom, .leaflet-control-attribution { display: none; }
    .noah-edge-marker { width: 44px; height: 44px; line-height: 42px; }
    .ancestry-popup-wrap .leaflet-popup-content { max-height: 30dvh; }
    body:has(.leaflet-popup) #details { max-height: 30dvh; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 768px) {
    .leaflet-popup-pane { transform: none !important; }
    .ancestry-popup-wrap { position: fixed !important; left: 12px !important; right: 12px; top: 110px !important; bottom: auto !important; width: auto; margin: 0; transform: none !important; }
    .ancestry-popup-wrap .leaflet-popup-content { width: auto !important; max-width: none; }
    .ancestry-popup-wrap .leaflet-popup-tip-container { display: none; }
}
@media (max-width: 768px) { #main-map > .ancestry-popup-wrap { z-index: 1002; } }
@media (min-width: 769px) {
    body:has(#details:not([hidden])) #legend-panel { max-height: 350px; }
    body:has(#details:not([hidden])) #legend-colour,
    body:has(#details:not([hidden])) #map-key,
    body:has(#details:not([hidden])) #named-key,
    body:has(#details:not([hidden])) .noah-nav { display: none; }
    body:has(#details:not([hidden])) #place-ranking { border: 0; margin: 0; padding: 0; }
}
#legend-panel, #layer-panel, #details, .ancestry-popup-wrap .leaflet-popup-content-wrapper { backdrop-filter: blur(8px); }
#details-close { position: sticky; top: 0; z-index: 1; }
.travel-dot-label span, .babel-scatter-label span { max-width: 220px; white-space: normal !important; width: max-content; }
@media (max-width: 768px) { .travel-dot-label span, .babel-scatter-label span { max-width: 170px; } }
.leaflet-control-zoom span { font-size: inherit; }
.leaflet-fade-anim .leaflet-popup { opacity: 1 !important; transition: none; }
.leaflet-touch .leaflet-control-zoom a { font-size: var(--text-heading); }
@media (max-width: 768px) {
    body:has(#details:not([hidden])) .noah-edge-markers,
    body:has(.mobile-open) .noah-edge-markers { visibility: hidden; }
}

/* Labels share the map projection. Event labels disappear without a fade. */
.nation-label, .travel-dot-label, .babel-scatter-label, .people-group-label, .name-label { transition: none !important; }
.noah-period-label > span { opacity: var(--period-opacity, 1); transition: none !important; }
.noah-playing .noah-moving-tooltip { opacity: 0 !important; }
