/* Map page — loaded after site.css */

/* ---------- Base ---------- */
body.page-map { overflow: hidden; font-size: 15px; line-height: 1.5; }
.topbar .menu-btn { display: none; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.hand { font-family: var(--font-hand); font-weight: 700; color: var(--hand); font-size: 22px; line-height: 1.1; margin: 0; }
.hand.inline { font-size: 1.3em; }
.link { color: var(--accent); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

.app { position: fixed; inset: 0; overflow: hidden; }
.map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: var(--ocean); cursor: grab; touch-action: none; }
.map:active { cursor: grabbing; }

.card {
  position: absolute; z-index: 2;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--card-border);
  font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.pill:hover { border-color: var(--accent-fill); }
.pill svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.pill.small { height: 30px; padding: 0 10px; font-size: 13px; font-weight: 500; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: var(--card); border: 1px solid var(--card-border);
  cursor: pointer; font-size: 20px; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent-fill); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header ---------- */
.topbar {
  position: absolute; z-index: 4; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px;
  background: linear-gradient(to bottom, var(--bg) 0%, color-mix(in srgb, var(--bg) 70%, transparent) 70%, transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo { width: 40px; height: 40px; color: var(--accent-fill); flex: none; }
.wordmark { font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: 0.02em; text-transform: uppercase; white-space: nowrap; }
.age-picker { position: relative; }
.age-button { font-family: var(--font-body); }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 10;
  list-style: none; margin: 0; padding: 6px; min-width: 260px;
  background: var(--card-solid); border: 1px solid var(--card-border); border-radius: 14px; box-shadow: var(--shadow);
}
.menu li button {
  width: 100%; display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 10px 12px; border: 0; background: none; border-radius: 10px; cursor: pointer; text-align: left;
}
.menu li button:hover, .menu li button:focus-visible { background: var(--accent-wash); }
.menu li button[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.menu .m-span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nav-link { background: none; border: 0; padding: 8px 12px; border-radius: 10px; cursor: pointer; font-weight: 500; color: var(--text-2); }
.nav-link:hover { color: var(--text); background: var(--accent-wash); }
.i-moon { display: none; }
:root[data-theme="light"] .i-sun { display: none; }
:root[data-theme="light"] .i-moon { display: block; }

/* ---------- Search ---------- */
.search-wrap { position: absolute; z-index: 5; top: 72px; left: 50%; transform: translateX(-50%); width: min(520px, calc(100% - 32px)); }
.search {
  display: flex; align-items: center; gap: 10px;
  height: 46px; padding: 0 18px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--card-border); box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.search:focus-within { border-color: var(--accent-fill); }
.search svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; }
.search input::placeholder { color: var(--muted); }
.search-results {
  list-style: none; margin: 6px 0 0; padding: 6px; max-height: 50vh; overflow-y: auto;
  background: var(--card-solid); border: 1px solid var(--card-border); border-radius: 16px; box-shadow: var(--shadow);
}
.search-results button {
  width: 100%; text-align: left; border: 0; background: none; border-radius: 10px; padding: 10px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.search-results button:hover, .search-results button.active { background: var(--accent-wash); }
.search-results .r-title { font-weight: 600; }
.search-results .r-meta { font-size: 13px; color: var(--muted); }
.search-results .r-empty { padding: 12px; color: var(--muted); font-size: 14px; }

/* ---------- Map layers ---------- */
.sphere { fill: var(--ocean); }
.graticule { fill: none; stroke: var(--graticule); stroke-width: 0.5; vector-effect: non-scaling-stroke; }
.country { fill: var(--land); stroke: var(--land-stroke); stroke-width: 0.4; vector-effect: non-scaling-stroke; }
.polity { fill-opacity: var(--polity-opacity); stroke: var(--polity-stroke); stroke-width: 0.6; vector-effect: non-scaling-stroke; transition: fill-opacity 160ms ease-out; cursor: pointer; }
.polity.neutral { fill: transparent; stroke: none; cursor: default; }
.polity:not(.neutral):hover { fill-opacity: calc(var(--polity-opacity) + 0.2); }
.polities.focus .polity:not(.on) { fill-opacity: 0.12; }
.polities.focus .polity.on { fill-opacity: 0.85; }
.labels text {
  font-family: var(--font-body); font-weight: 600; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  fill: var(--label); paint-order: stroke; stroke: var(--label-halo); stroke-width: 3px; stroke-linejoin: round;
  text-anchor: middle; dominant-baseline: middle; pointer-events: none;
}
.labels text.big { font-size: 13px; }

.marker .dot { fill: var(--marker); stroke: var(--marker-ring); stroke-width: 2; }
.marker .hit { fill: transparent; cursor: pointer; }
.marker.selected .dot { fill: var(--ember); stroke: var(--paper); stroke-width: 2.5; }
.marker .pulse { fill: none; stroke: var(--ember); stroke-width: 2; opacity: 0; pointer-events: none; }
.marker.selected .pulse { animation: pulse 1.8s ease-out infinite; }
.marker.enter .dot { animation: pop 260ms cubic-bezier(.2,.9,.3,1.3); }
@keyframes pulse { 0% { opacity: .8; r: 9; } 100% { opacity: 0; r: 24; } }
@keyframes pop { from { r: 0; } }

/* ---------- Story card (left) ---------- */
.story {
  top: 136px; left: 20px; width: 360px;
  max-height: calc(100% - 136px - var(--tl-h) - 32px); overflow-y: auto;
  padding: 20px 22px;
}
.story h2 { font-family: var(--font-display); font-weight: 800; font-size: 26px; line-height: 1.15; margin: 4px 0 6px; letter-spacing: 0.005em; }
.story p { margin: 0; color: var(--text-2); }
.story .lede { color: var(--text); }
.story .meta { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.story .why { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--card-border); }
.story .why p { color: var(--text); margin-top: 4px; }
.story .tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 4px; }
.tag { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-wash); border-radius: 999px; padding: 3px 10px; }
.story-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.story .close { width: 32px; height: 32px; font-size: 18px; border-radius: 10px; }
.in-view { margin-top: 18px; }
.in-view h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; }
.event-list { list-style: none; margin: 0 -10px; padding: 0; }
.event-list button {
  width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 10px; cursor: pointer;
  display: grid; grid-template-columns: 10px 1fr; gap: 2px 10px; align-items: baseline;
}
.event-list button:hover, .event-list button.hover { background: var(--accent-wash); }
.event-list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--marker); transform: translateY(-1px); }
.event-list .e-title { font-weight: 600; font-size: 14px; color: var(--text); }
.event-list .e-meta { grid-column: 2; font-size: 12px; color: var(--muted); }
.empty-note { font-size: 14px; color: var(--muted); }
.hint { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--accent-wash); font-size: 13px; color: var(--text-2); }
.hint strong { color: var(--text); }
.pager { display: flex; gap: 8px; margin-top: 16px; }
.pager button {
  flex: 1; min-width: 0; text-align: left; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  background: transparent; border: 1px solid var(--card-border); font-size: 12px; color: var(--muted);
}
.pager button:hover:not(:disabled) { border-color: var(--accent-fill); }
.pager button:disabled { opacity: .35; cursor: default; }
.pager .next { text-align: right; }
.pager strong { display: block; font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Legend (right) ---------- */
.legend {
  top: 136px; right: 20px; width: 270px;
  max-height: calc(100% - 136px - var(--tl-h) - 32px);
  display: flex; flex-direction: column; padding: 14px 8px 8px 14px;
}
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-right: 6px; margin-bottom: 6px; }
.legend-title { display: flex; align-items: baseline; gap: 8px; background: none; border: 0; padding: 0; cursor: pointer; }
.legend-title .eyebrow { color: var(--accent); }
.legend-title .count { font-size: 12px; color: var(--muted); }
.legend-title .chev { width: 12px; height: 12px; fill: none; stroke: var(--muted); stroke-width: 1.6; display: none; }
.legend-list { list-style: none; margin: 0; padding: 0 6px 0 0; overflow-y: auto; }
.legend-list button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 0; background: none; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.legend-list button:hover, .legend-list button.hover { background: var(--accent-wash); }
.legend-list button[aria-pressed="true"] { background: var(--accent-wash); font-weight: 600; }
.legend-list .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.legend-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-empty { font-size: 13px; color: var(--muted); padding: 4px 8px 8px; }
.legend.collapsed .legend-list, .legend.collapsed #legend-sort, .legend.collapsed .borders-note { display: none; }
.legend.collapsed .chev { transform: rotate(-90deg); }

/* ---------- Map controls ---------- */
.map-controls { position: absolute; z-index: 2; right: 20px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; }

/* ---------- Timeline (bottom) ---------- */
.timeline {
  left: 50%; transform: translateX(-50%); bottom: 16px;
  width: min(880px, calc(100% - 180px));
  padding: 10px 24px 10px; text-align: center;
}
.viewing { display: flex; flex-direction: column; align-items: center; }
.year-row { display: flex; align-items: center; gap: 16px; width: 100%; justify-content: center; }
.year-row .rule { height: 1px; width: 90px; background: linear-gradient(to right, transparent, var(--accent-fill), transparent); opacity: .6; }
.year { font-family: var(--font-display); font-weight: 800; font-size: 34px; line-height: 1.1; letter-spacing: 0.01em; font-variant-numeric: lining-nums; min-width: 6ch; }
.shown { display: flex; gap: 8px; align-items: baseline; }
.window { font-weight: 600; color: var(--accent); font-size: 14px; }
.track-wrap { margin-top: 4px; }
.track-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.track { position: relative; height: 34px; }
.rail { position: absolute; left: 0; right: 0; top: 50%; height: 4px; transform: translateY(-50%); background: var(--rail); border-radius: 2px; }
.track-window { position: absolute; top: 50%; height: 6px; transform: translateY(-50%); background: var(--accent-fill); opacity: .55; border-radius: 3px; pointer-events: none; }
.track-events { position: absolute; inset: 0; pointer-events: none; }
.track-events i { position: absolute; top: 50%; width: 2px; height: 10px; margin-left: -1px; transform: translateY(-50%); background: var(--text-2); opacity: .45; border-radius: 1px; }
.slider { position: absolute; inset: 0; width: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.slider::-webkit-slider-runnable-track { height: 34px; background: transparent; }
.slider::-moz-range-track { height: 34px; background: transparent; }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; margin-top: 5px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F6CE7E, var(--gilt) 55%, #B7801F);
  border: 2px solid var(--card-solid); box-shadow: 0 0 0 1px rgba(17,17,17,.25), 0 2px 8px rgba(0,0,0,.35);
}
.slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F6CE7E, var(--gilt) 55%, #B7801F);
  border: 2px solid var(--card-solid); box-shadow: 0 0 0 1px rgba(17,17,17,.25), 0 2px 8px rgba(0,0,0,.35);
}
.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent-wash), 0 0 0 5px var(--accent-fill); }
.track-ticks { position: relative; height: 18px; }
.track-ticks span { position: absolute; transform: translateX(-50%); font-size: 11px; letter-spacing: .08em; color: var(--muted); white-space: nowrap; }
.track-ticks span::before { content: ""; position: absolute; left: 50%; top: -6px; width: 1px; height: 5px; background: var(--muted); opacity: .6; }
.timeline-actions { display: flex; justify-content: center; gap: 10px; margin-top: 2px; }
.timeline-actions .icon-btn { width: 48px; height: 40px; font-size: 24px; }
.timeline-actions .play { background: var(--gilt); color: #111111; border-color: transparent; }
.timeline-actions .play:hover { background: #EDB955; }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.play svg path { fill: currentColor; }
.play.playing svg path { fill: none; stroke-width: 2.4; }
.borders-note { margin: 8px 8px 2px; font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: absolute; z-index: 6; pointer-events: none; max-width: 260px;
  background: var(--card-solid); border: 1px solid var(--card-border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px 12px; font-size: 13px;
}
.tooltip .t-title { font-weight: 600; color: var(--text); }
.tooltip .t-meta { color: var(--muted); font-size: 12px; }
.tooltip .t-cta { color: var(--accent); font-size: 12px; font-weight: 600; margin-top: 2px; }

.attribution { position: absolute; z-index: 1; left: 20px; bottom: 4px; margin: 0; font-size: 11px; color: var(--muted); }
.attribution button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font-size: inherit; }

/* ---------- Modals ---------- */
.modal {
  width: min(520px, calc(100% - 32px)); padding: 28px; border-radius: 20px;
  background: var(--card-solid); color: var(--text); border: 1px solid var(--card-border); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); }
.modal h2 { font-family: var(--font-display); font-weight: 800; font-size: 26px; line-height: 1.15; margin: 4px 0 12px; }
.modal p { color: var(--text-2); margin: 0 0 12px; }
.modal .close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; }
.credits { padding-left: 18px; margin: 0; color: var(--text-2); font-size: 14px; }
.credits li { margin-bottom: 10px; }
.credits strong { color: var(--text); }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  .marker.selected .pulse, .marker.enter .dot { animation: none; }
  .polity { transition: none; }
}

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .story { width: 320px; }
  .legend { width: 230px; }
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  body { font-size: 14px; }
  .topbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .wordmark { display: none; }
  .logo { width: 36px; height: 36px; }
  .age-button { height: 38px; padding: 0 12px; font-size: 14px; }
  .nav-link { display: none; }
  .nav .icon-btn { width: 38px; height: 38px; }
  .search-wrap { top: 60px; width: calc(100% - 24px); }
  .search { height: 42px; }
  .menu { min-width: min(300px, calc(100vw - 24px)); }

  .legend {
    top: 112px; right: 12px; left: auto; width: auto; max-width: calc(100% - 24px);
    max-height: 40vh; padding: 8px 6px 6px 12px; border-radius: 14px; z-index: 3;
  }
  .legend-title .chev { display: block; }
  .legend-head { margin-bottom: 0; }

  .map-controls { display: none; }

  .timeline {
    left: 0; right: 0; bottom: 0; transform: none; width: 100%;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  }
  .viewing > .eyebrow, .track-ticks { display: none; }
  .year { font-size: 28px; }
  .year-row .rule { width: 32px; }
  .shown .eyebrow { font-size: 10px; }
  .track-wrap { margin-top: 2px; }
  .timeline-actions .icon-btn { height: 38px; }

  /* story becomes a sheet that sits above the timeline */
  .story {
    left: 8px; right: 8px; width: auto; top: auto; bottom: calc(var(--tl-h) + 8px);
    max-height: 34vh; padding: 16px 18px; border-radius: 16px;
  }
  .story.minimized { max-height: none; }
  .story.minimized .collapsible { display: none; }
  .story h2 { font-size: 21px; }
  .attribution { display: none; }
}

/* ---------- Site integration ---------- */
.topbar .nav { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar .site-nav { margin-left: 0; margin-right: 6px; }
.topbar .site-nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent-fill); }
.story-links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.hint { position: relative; padding-right: 34px; }
.hint-x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; border-radius: 8px; }
.hint-x:hover { color: var(--text); background: var(--accent-wash); }
.attribution a { color: inherit; }
@media (max-width: 1180px) { .topbar .site-nav { display: none; } .topbar .menu-btn { display: inline-grid; } }
@media (max-width: 760px) { .topbar .nav { margin-left: auto; } }

/* ---------- Story places & route ---------- */
.story-route .route { fill: none; stroke: var(--gilt); stroke-width: 2.5; stroke-dasharray: 7 7; stroke-linecap: round; opacity: .9; pointer-events: none; }
.story-route .place circle { fill: var(--ember); stroke: var(--paper); stroke-width: 2; cursor: help; }
.story-route .place text { fill: #fff; font: 700 11px var(--font-body); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.story-route .place:focus-visible circle { stroke: var(--gilt); stroke-width: 3; }
.mini-places { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--text-2); }
.mini-places li { display: flex; align-items: center; gap: 6px; }
.mini-places .pnum { width: 18px; height: 18px; border-radius: 50%; background: var(--ember); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }

/* ---------- Calmer layout ---------- */
.legend-title .chev { display: block; transition: transform 150ms; }
.legend-title { min-height: 32px; }
.legend.collapsed { width: auto; padding: 6px 10px 6px 14px; }
.legend.collapsed .legend-head { margin: 0; }
.legend:not(.collapsed) .chev { transform: rotate(180deg); }
.legend.collapsed .chev { transform: none; }
.age-about { margin-top: 8px; border-top: 1px solid var(--card-border); border-bottom: 1px solid var(--card-border); }
.age-about summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-weight: 600; font-size: 14px; color: var(--accent); }
.age-about summary::-webkit-details-marker { display: none; }
.age-about summary::after { content: "+"; font-size: 18px; color: var(--muted); }
.age-about[open] summary::after { content: "−"; }
.age-about .lede { margin-bottom: 4px; }
.age-about .why { margin: 12px 0 14px; }
.story { width: 340px; }
.story h2 { font-size: 24px; }
.in-view { margin-top: 14px; }
.viewing > .eyebrow { display: none; }
.year { font-size: 30px; }
.timeline { padding: 8px 24px 8px; }
.track-wrap { margin-top: 2px; }
.search-wrap { width: min(440px, calc(100% - 32px)); }
.labels text { opacity: 0.9; }
.legend.collapsed { padding-top: 4px; padding-bottom: 4px; }
@media (max-width: 760px) { .legend.collapsed { padding: 2px 8px 2px 12px; } }
