/* Noah map: page-specific additions. Everything here uses the site's own tokens
   (--surface, --ink, --line, --accent, --gold, --font-body, --font-display from
   css/site.css) and the site's panel, button and label chrome. The site is dark
   only, and so is this page. */


/* Layer panel additions (the panel itself is the site's #layer-panel). Collapsed until the Layers toggle is clicked. */
#layer-panel { display: none; top: 60px; width: 256px; padding: 8px 12px; max-height: calc(100vh - 32px - 90px); overflow-y: auto; font-size: 12px; }
#layer-panel .layer-toggle, #layer-panel .noah-field, #layer-panel .noah-explain { font-size: 12px; }
#layer-panel .layer-panel-title { font-size: 12px; margin-bottom: 4px; }
#layer-panel .layer-toggle { min-height: 26px; }
#layer-panel .noah-select { min-height: 30px; font-size: 12px; }
.layer-panel-title { display: block; }
.noah-explain { font-size: 12px; color: var(--ink-faint); margin: 4px 0 4px; line-height: 1.35; }
.noah-field { display: block; font-size: 13px; color: var(--ink-muted); margin: 8px 0 4px; line-height: 1.3; }
.noah-select {
    width: 100%; min-height: 36px; padding: 4px 8px; font-family: var(--font-body); font-size: 13px;
    background: var(--accent-wash); color: var(--ink-muted); border: 1px solid var(--line); border-radius: 4px; cursor: pointer;
}
.noah-select:disabled { opacity: 0.7; cursor: default; }
.noah-select option { background: #0e1322; color: var(--ink); }
.layer-toggle { min-height: 32px; }
.noah-keep-ends { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-faint); }

/* Range slider: the same look as the site's timeline slider (#timeline-slider) */
.noah-range {
    width: 100%; -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px;
    background: linear-gradient(to right, #2a2a5a, #4a4a8a, #6a6aaa); outline: none; cursor: pointer; margin: 10px 0 6px;
}
.noah-range::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
    background: var(--ink-faint); border: 2px solid var(--ink-muted); cursor: pointer; box-shadow: 0 0 8px rgba(100, 100, 200, 0.5);
}
.noah-range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--ink-faint); border: 2px solid var(--ink-muted); cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#howto { padding-top: 8px; margin-top: 8px; border-top: 1px solid var(--line); }
#howto summary { cursor: pointer; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-faint); min-height: 32px; display: flex; align-items: center; }
.howto-body p { font-size: 13px; color: var(--ink-muted); margin-bottom: 8px; line-height: 1.4; }
#caveats { margin: 0 0 8px 18px; font-size: 13px; color: var(--ink-muted); }
.design-note { font-family: ui-monospace, Menlo, monospace; color: var(--accent) !important; }

/* Legend additions (built from .legend-title and .legend-item) */
#legend-panel { width: 240px; max-width: 240px; padding: 8px 10px; }
#legend-panel .legend-item { font-size: 11.5px; gap: 6px; padding: 1px 0; }
#legend-panel .legend-title { font-size: 11px; }
.noah-legend-block { margin-top: 6px; }
.noah-legend-block .legend-title { margin-bottom: 4px; letter-spacing: 1px; font-size: 12px; }
.noah-ramp-wrap { position: relative; height: 34px; }
.noah-ramp { display: flex; height: 12px; border: 1px solid var(--line); overflow: hidden; }
.noah-ramp .grad { flex: 1; }
.noah-ramp .top { border-left: 2px solid var(--surface); }
.noah-tick { position: absolute; top: 15px; transform: translateX(-50%); font-size: 11px; white-space: nowrap; color: var(--ink-muted); font-family: var(--font-body); }
.noah-tick::before { content: ""; position: absolute; left: 50%; top: -4px; height: 4px; border-left: 1px solid var(--ink-faint); }
.noah-sw-ring-dashed { width: 14px; height: 14px; border-radius: 50%; border: 2px dashed var(--ink-muted); flex-shrink: 0; }
.noah-size-row { display: flex; align-items: flex-end; gap: 12px; margin: 2px 0; }
.noah-size-row svg { overflow: visible; font-family: var(--font-body); }
.noah-sw-solid { background: var(--ink); width: 9px; height: 9px; }
.noah-sw-man { background: var(--gold); border: 1.5px solid #05070f; width: 12px; height: 12px; }
.noah-sw-line { background: conic-gradient(#4a90d9 0 33%, #d94a4a 0 66%, #4ad97a 0); width: 8px; height: 8px; }
.noah-sw-ring { background: transparent; border: 2px solid var(--ink); width: 10px; height: 10px; }

/* Map labels: the site's .nation-label and .babel-scatter-label do the layout; the colour and
   shadow are inline in the label HTML, as on the site. */
.leaflet-tooltip { background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: none; padding: 3px 8px;
    font-family: var(--font-display); font-size: 13px; font-weight: 500; font-style: normal; white-space: nowrap; width: max-content; max-width: none; }
.leaflet-tooltip-top::before { border-top-color: var(--line); }
.leaflet-tooltip.name-label { background: transparent; border: 0; padding: 0 2px; text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.7); }
.leaflet-tooltip.name-label::before { display: none; }
.noah-popup .pm { margin-top: 4px; color: var(--ink-muted); }
.leaflet-container { font-family: var(--font-body); }
.leaflet-control-attribution { background: var(--surface) !important; color: var(--ink-muted) !important; font-family: var(--font-body); }
.leaflet-control-attribution a { color: var(--accent); }

/* Details panel: same chrome as #legend-panel; sits top left and never covers the map centre */
#details {
    position: absolute; z-index: 1001; top: 16px; left: 16px; width: 280px;
    max-height: calc(100vh - 32px - 90px);
    background: var(--surface); backdrop-filter: blur(8px); padding: 10px 14px; border-radius: 0;
    border: 1px solid var(--line); overflow-y: auto; font-family: var(--font-body);
}
#details[hidden] { display: none; }
#details-close { float: right; min-height: 32px; min-width: 52px; }
#details h3 { font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--ink-strong); margin-bottom: 2px; }
#details h4 { font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-faint); margin: 10px 0 2px; font-weight: 400; }
#details p, #details li { font-size: 14px; color: var(--ink-muted); line-height: 1.35; }
#details ul { margin-left: 18px; }
#details .big { font-size: 20px; font-weight: 600; color: var(--ink); }
#details .note { font-size: 12px; color: var(--ink-faint); }

/* Event ticks: the site's .timeline-marker row, with short names */
.timeline-marker { font-size: 9px; min-width: 40px; text-align: center; background: none; border: 0; font-family: var(--font-body); padding: 0; }
.timeline-marker.lower { top: 12px; }
#timeline-markers { height: 28px; }
#timeline-slider { flex: 1; }
#play-btn, #timeline-slider { min-height: 0; }

/* Phones: the site's own rules (css/site.css, max-width 768px) hide the layer and legend panels behind
   the Layers and Legend buttons. Differences from the site: the speed control and the event ticks stay. */
@media (min-width: 769px) { .mobile-map-controls { display: none; } }
@media (max-width: 768px) {
    .mobile-map-btn { min-height: 40px; min-width: 76px; }
    #layer-panel { max-height: min(50vh, 380px); width: auto; }
    #legend-panel { max-width: none; width: auto; }
    #speed-control { display: flex; }
    #speed-control .speed-btn { min-height: 40px; min-width: 36px; padding: 3px 4px; }
    #play-btn { width: 44px; height: 44px; }
    #timeline-markers { display: block; height: 30px; margin: 0 12px; }
    .timeline-marker .yr { display: none; }
    #details { top: auto; left: 0; right: 0; bottom: 96px; width: auto; max-height: 44vh; }
    .leaflet-control-zoom { display: none; }
    .leaflet-bottom.leaflet-right { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Layers toggle (desktop): a small button at the top right; the panel opens below it */
#layers-toggle { display: block; position: absolute; top: 16px; right: 16px; z-index: 1001; min-height: 34px; min-width: 76px; padding: 4px 12px; background: var(--surface); }
#layer-panel.open { display: block; }

/* Compact legend: one row of ramp and one sentence */
@media (min-width: 769px) { #legend-panel { width: 260px; max-width: 260px; padding: 6px 10px 8px; bottom: 96px; } }
#legend-panel .legend-title { font-size: 10px; letter-spacing: 0.6px; margin-bottom: 2px; white-space: nowrap; }
.noah-legend-note { font-size: 12px; color: var(--ink-muted); margin: 2px 0 0; line-height: 1.3; }
.noah-tick { font-size: 10px; }

/* Idle fade: after a few seconds without input the chrome steps back (the site's chrome-idle), with a 300 ms fade, even when paused */
#layer-panel, #legend-panel, #timeline-container, .mobile-map-controls, .leaflet-control-zoom, #layers-toggle, .leaflet-control-attribution,
.chrome-fade, .people-group-label { transition: opacity 0.3s ease; }
body.chrome-idle #layers-toggle, body.chrome-idle .leaflet-control-attribution, body.chrome-idle .chrome-fade, body.chrome-idle .people-group-label { opacity: 0 !important; pointer-events: none; }
@media (max-width: 768px) { #layers-toggle { display: none; } #layer-panel { top: auto; } }

/* Key of named people alive: the site's inset roster (css/style.css, #inset-roster, .inset-roster-row), adapted */
#named-key { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--line); }
.key-heading { font-size: 10px; letter-spacing: 0.6px; margin-bottom: 2px; white-space: nowrap; }
.key-group-title { font-family: var(--font-body); font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--ink-faint); margin: 3px 0 1px; }
.key-group-title.hidden-title { display: none; }
.key-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 12px; }
.key-row { display: flex; align-items: center; gap: 6px; font-family: var(--font-display); font-size: 12px; font-weight: 500; line-height: 1.5; color: var(--ink-muted); min-width: 0; }
.key-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 5px rgba(0, 0, 0, 0.6); }
.key-dot.ring { box-shadow: 0 0 0 1.5px #ffffff; }
.key-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.key-place { color: var(--ink-faint); }
.key-age { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink-faint); font-size: 11px; }
@media (min-width: 769px) { #legend-panel { width: 316px; max-width: 316px; } }
@media (max-width: 768px) { .key-rows { grid-template-columns: 1fr; } }

/* The legend panel (ramp and key of named people) stays visible at all times: it is not part of the idle fade */
body.chrome-idle #legend-panel { opacity: 1 !important; pointer-events: auto !important; }

/* The notice occupies a strip below the date. Desktop side panels start below that strip. */
.draft-notice {
    position: absolute; z-index: 1002; top: 58px; left: 16px; right: 16px;
    width: auto; max-width: 680px; margin: 0 auto; padding: 4px 10px;
    background: var(--surface); border: 1px solid var(--line); color: var(--ink-muted);
    font-family: var(--font-body); font-size: 11px; line-height: 1.3; text-align: center;
}
.draft-notice a { color: var(--accent); white-space: nowrap; }
body.chrome-idle .draft-notice { opacity: 1 !important; pointer-events: auto !important; }
@media (min-width: 769px) {
    #layer-panel, #details { top: 110px; max-height: calc(100vh - 216px); }
    #legend-panel { max-height: calc(100vh - 216px); }
}
@media (max-width: 768px) {
    .draft-notice { top: 98px; left: 10px; right: 10px; max-width: none; }
    #layer-panel, #legend-panel, #details { max-height: min(44vh, calc(100vh - 270px)); }
}

/* People | Sheep switch */
.view-switch { display: flex; gap: 4px; }
.view-switch .autozoom-btn { flex: 1; min-height: 32px; display: flex; align-items: center; justify-content: center; font-family: var(--font-body); font-size: 13px; }
.legend-switch { margin-bottom: 6px; }
#sheep-settings[hidden], #measure-block[hidden] { display: none; }
