/* ===== Deep Histomap — dark cosmic ===== */
:root {
  --bg: #05060e;
  --ink: #e8ebf5;
  --ink-dim: #9aa3bf;
  --ink-faint: #7a83a0; /* >=4.5:1 on --bg for small secondary text (WCAG AA) */
  --line: rgba(140, 155, 200, 0.14);
  --panel-bg: rgba(13, 16, 30, 0.92);
  --card-bg: rgba(18, 22, 40, 0.97);
  --accent: #7fb4ff;
  --glow-tech: #46d4ff;
  --glow-rel: #b78aff;
  --glow-person: #ffd27a;
  --glow-event: #ff9d5c;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --topbar-h: 52px;
  --regionbar-h: 0px;
  --tabs-h: 54px;
  --scrubber-w: 96px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

/* keyboard focus: visible ring on buttons and on focusable SVG map entries */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
.stream:focus-visible, .stream-label:focus-visible, .marker:focus-visible,
.m-bar:focus-visible, .cluster:focus-visible, .thread-dot:focus-visible,
.thread-secondary-dot:focus-visible, .thread-label:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* inside the scrollable tab row an outset ring would be clipped — draw it inside */
#tab-group .tab:focus-visible { outline-offset: -2px; }
/* Pointer selection must not flash the browser's SVG focus rectangle.
   Keyboard navigation retains the focus ring; plain labels use an underline. */
#map [role="button"]:focus:not(:focus-visible),
#map .selection-label:focus { outline: none; }

@media (prefers-reduced-motion: reduce) {
  #panel, #coach-hole, #coach-pop, .tab, .stream, #intro-hint,
  .related-chip, #panel-image { transition: none !important; }
  #toast { animation: none; }
}
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

/* ---- layers ---- */
#stars {
  position: fixed; top: 0; left: 0; right: 0; bottom: var(--tabs-h);
  z-index: 0;
  width: 100vw;
  height: calc(100vh - var(--tabs-h));
  height: calc(100dvh - var(--tabs-h));
}
#map {
  position: fixed; top: 0; left: 0; right: 0; bottom: var(--tabs-h); z-index: 1;
  width: 100vw;
  height: calc(100vh - var(--tabs-h));
  height: calc(100dvh - var(--tabs-h));
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#scrubber { user-select: none; -webkit-user-select: none; }
#map.dragging { cursor: grabbing; }

/* ---- top bar ---- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: linear-gradient(to bottom, rgba(5,6,14,0.88), rgba(5,6,14,0.55) 75%, transparent);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#brand { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
#brand h1 {
  font-family: var(--serif);
  font-size: 19px; font-weight: 500; letter-spacing: 0.06em;
  background: linear-gradient(100deg, #cfe0ff, #8fb8ff 55%, #c9a6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  white-space: nowrap;
}
#progress-counter { font-size: 11px; color: var(--ink-faint); white-space: nowrap; }

#searchbox { position: relative; flex: 1; max-width: 380px; }
#search {
  width: 100%; padding: 7px 12px;
  background: rgba(20, 25, 48, 0.75);
  border: 1px solid rgba(130, 150, 210, 0.22);
  border-radius: 17px;
  color: var(--ink); font-size: 13px; outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#search:focus { border-color: rgba(140, 170, 255, 0.55); background: rgba(22, 28, 55, 0.92); }
#search::placeholder { color: var(--ink-faint); }
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--card-bg);
  border: 1px solid rgba(130, 150, 210, 0.25);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  max-height: 60vh; overflow-y: auto;
}
.search-item {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.search-item .si-date { margin-left: auto; color: var(--ink-faint); font-size: 11px; white-space: nowrap; }
.search-item .si-cat { font-size: 10px; padding: 1px 6px; border-radius: 8px; flex-shrink: 0; }
.search-item:hover, .search-item.active { background: rgba(110, 140, 230, 0.16); }
.search-empty { padding: 10px 12px; font-size: 13px; color: var(--ink-dim); }

#topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }
#year-pill {
  font-size: 13px; font-variant-numeric: tabular-nums;
  color: #cdd8f5;
  padding: 5px 13px;
  background: rgba(20, 25, 48, 0.75);
  border: 1px solid rgba(130, 150, 210, 0.22);
  border-radius: 15px;
  min-width: 124px; text-align: center; white-space: nowrap;
}
/* All ages / Kids segmented switch */
#mode-switch {
  display: flex;
  border: 1px solid rgba(130, 150, 210, 0.22);
  border-radius: 15px;
  overflow: hidden;
  background: rgba(20, 25, 48, 0.75);
  flex-shrink: 0;
}
#mode-switch button {
  border: none; background: none;
  color: var(--ink-dim); font-size: 12px;
  padding: 6px 11px; white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
#mode-switch button:hover { color: var(--ink); }
#mode-switch button.active { background: rgba(110, 140, 230, 0.28); color: #fff; }
html.kids #mode-switch button.active { background: rgba(127, 217, 168, 0.3); }
#mode-switch .ms-short { display: none; }
@media (max-width: 900px) {
  #mode-switch button { padding: 5px 8px; font-size: 11px; }
  #mode-switch .ms-full { display: none; }
  #mode-switch .ms-short { display: inline; }
}

#zoom-controls { display: flex; gap: 4px; }
#zoom-controls button, #about-btn {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(20, 25, 48, 0.75);
  border: 1px solid rgba(130, 150, 210, 0.22);
  color: var(--ink-dim); font-size: 16px; line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
#zoom-controls button:hover, #about-btn:hover { color: #fff; border-color: rgba(140,170,255,0.5); }

#mobile-region-nav { display: none; }

/* ---- scrubber ---- */
#scrubber {
  position: fixed; left: 0; top: var(--topbar-h);
  width: var(--scrubber-w);
  height: calc(100vh - var(--topbar-h) - var(--tabs-h));
  height: calc(100dvh - var(--topbar-h) - var(--tabs-h));
  z-index: 10;
  touch-action: none;
  cursor: pointer;
}

/* ---- tabs ----
   The Tours button stays in normal flow (inside the right tool cluster) so it
   can never cover the tab row; only at >=1360px — where there is provably
   clear space — is it lifted out and centered like the original design. */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--tabs-h);
  z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 12px;
  background: linear-gradient(to top, rgba(5,6,14,0.92), rgba(5,6,14,0.6) 75%, transparent);
}
#tab-group { display: flex; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#tab-group::-webkit-scrollbar { display: none; }
.tab {
  --tc: #9db8ff;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  background: rgba(20, 25, 48, 0.75);
  border: 1px solid rgba(130, 150, 210, 0.22);
  border-radius: 15px;
  color: var(--ink-dim); font-size: 13px;
  transition: color 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.tab::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--tc); opacity: 0.55; flex-shrink: 0;
  transition: opacity 0.2s, box-shadow 0.2s;
}
.tab[data-tab="civilizations"] { --tc: #e8b45c; }
.tab[data-tab="technology"] { --tc: #46d4ff; }
.tab[data-tab="religions"] { --tc: #b78aff; }
.tab[data-tab="people"] { --tc: #ffb36b; }
.tab:hover { color: var(--ink); border-color: rgba(140,170,255,0.5); }
.tab:hover::before { opacity: 0.9; }
.tab.active {
  color: #fff;
  background: color-mix(in srgb, var(--tc) 14%, rgba(20, 25, 48, 0.75));
  border-color: color-mix(in srgb, var(--tc) 45%, transparent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--tc) 22%, transparent);
}
.tab.active::before { opacity: 1; box-shadow: 0 0 8px var(--tc); }
#tab-tools { display: flex; gap: 6px; margin-left: auto; justify-content: flex-end; align-items: center; flex-shrink: 0; }
#discovery-tools { display: flex; gap: inherit; align-items: center; flex-shrink: 0; }
#tab-tools button {
  padding: 7px 13px;
  background: rgba(20, 25, 48, 0.75);
  border: 1px solid rgba(130, 150, 210, 0.22);
  border-radius: 15px;
  color: var(--ink-dim); font-size: 13px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#tab-tools button:hover { color: #fff; border-color: rgba(140,170,255,0.5); }
#tours-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 164px;
  padding: 9px 18px;
  color: #f0f5ff;
  background:
    linear-gradient(180deg, rgba(83, 119, 232, 0.42), rgba(31, 39, 88, 0.88)),
    rgba(20, 25, 48, 0.9);
  border-color: rgba(155, 184, 255, 0.62);
  box-shadow:
    0 0 0 1px rgba(130, 160, 255, 0.1) inset,
    0 0 26px rgba(78, 116, 232, 0.34),
    0 8px 26px rgba(0, 0, 0, 0.34);
}
#tours-btn:hover {
  color: #fff;
  border-color: rgba(190, 210, 255, 0.86);
  background:
    linear-gradient(180deg, rgba(102, 142, 255, 0.54), rgba(38, 48, 108, 0.92)),
    rgba(20, 25, 48, 0.94);
  box-shadow:
    0 0 0 1px rgba(170, 195, 255, 0.16) inset,
    0 0 34px rgba(92, 132, 255, 0.45),
    0 10px 30px rgba(0, 0, 0, 0.38);
}
.tour-icon { font-size: 14px; line-height: 1; opacity: 0.95; }
.tour-label-full { display: inline; }
.tour-label-short { display: none; }

/* Keep tours and the random discovery button together when centered. */
@media (min-width: 1360px) {
  #discovery-tools {
    position: absolute; left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
  }
}
/* narrow desktop: compact the tool cluster so everything fits in-flow */
@media (min-width: 721px) and (max-width: 1359px) {
  #tours-btn { min-width: 0; padding: 8px 12px; }
  #tours-btn .tour-label-full { display: none; }
  #tours-btn .tour-label-short { display: inline; }
  #help-btn .btn-txt { display: none; }
  #feedback-btn .feedback-label { display: none; }
}
@media (min-width: 721px) and (max-width: 1000px) {
  #tabs { padding: 0 8px; }
  .tab { padding: 7px 10px; font-size: 12.5px; }
}
/* just above the mobile breakpoint everything must still fit without clipping */
@media (min-width: 721px) and (max-width: 840px) {
  #tabs { gap: 6px; }
  .tab { padding: 6px 8px; font-size: 11.5px; gap: 5px; }
  #tab-tools { gap: 4px; }
  #tab-tools button { padding: 7px 9px; font-size: 12px; }
}

/* mobile layer picker (drop-up) — hidden on desktop where the tab row lives */
/* The open picker must sit above the story sheet's stacking context (30). */
#tabs.menu-open { z-index: 31; }
#tab-menu-btn { display: none; align-items: center; justify-content: center; gap: 7px; }
#search-toggle-btn { display: none; align-items: center; justify-content: center; }
#feedback-btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
#tab-menu-btn i { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 7px currentColor; }
#tab-menu-btn b { font-size: 9px; font-weight: 400; color: var(--ink-faint); }
#tab-menu {
  position: fixed; right: 10px; bottom: calc(var(--tabs-h) + 8px);
  z-index: 55;
  min-width: 220px;
  background: var(--card-bg);
  border: 1px solid rgba(130, 150, 210, 0.3);
  border-radius: 13px; padding: 6px;
  box-shadow: 0 -8px 44px rgba(0, 0, 0, 0.55);
}
.tab-menu-opt {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 12px 14px;
  background: none; border: none; border-radius: 9px;
  color: var(--ink); font-size: 14px; text-align: left;
}
.tab-menu-opt i { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.tab-menu-opt:hover { background: rgba(110, 140, 230, 0.12); }
.tab-menu-opt.active { background: rgba(110, 140, 230, 0.2); }
.tab-menu-sep { height: 1px; margin: 5px 8px; background: rgba(130, 150, 210, 0.2); }
.tab-menu-opt.about-opt { color: var(--ink-dim); font-size: 13px; }
.tab-menu-opt.about-opt i { background: none; box-shadow: none; }
.tab-menu-heading {
  padding: 7px 14px 3px;
  color: var(--ink-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.tab-menu-opt.edition-opt i {
  border: 1px solid rgba(157, 184, 255, 0.55);
  background: transparent;
}
.tab-menu-opt.edition-opt.active i {
  background: #9db8ff;
  box-shadow: 0 0 8px rgba(157, 184, 255, 0.65);
}

/* ---- map svg elements ---- */
.era-band { fill: rgba(255,255,255,0.012); }
.era-band.alt { fill: rgba(120,140,220,0.028); }
.era-line { stroke: rgba(150, 165, 220, 0.18); stroke-width: 1; stroke-dasharray: 2 6; }
.era-label {
  fill: rgba(160, 175, 225, 0.35);
  font-family: var(--serif);
  letter-spacing: 0.35em; text-transform: uppercase;
  text-anchor: middle;
  pointer-events: none;
}
.grid-line { stroke: var(--line); stroke-width: 1; }
.grid-label {
  fill: var(--ink-faint); font-size: 10px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.stream { opacity: 0.92; transition: opacity 0.4s, filter 0.25s; cursor: pointer; }
.stream-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 36;
  pointer-events: none;
}
.stream:hover { opacity: 1; filter: brightness(1.3) saturate(1.25); }
.stream.bg { opacity: 0.15; pointer-events: none; filter: none; }
.stream.dim { opacity: 0.42; }
.stream.dim:hover { opacity: 1; }
.stream-label.dim { opacity: 0.78; }
.stream.selected { opacity: 1; filter: brightness(1.35) saturate(1.3); }
.stream-label {
  fill: #b9f3df;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-anchor: middle; cursor: pointer;
  dominant-baseline: central;
  alignment-baseline: central;
  paint-order: stroke; stroke: rgba(0,0,0,0.7); stroke-width: 2.5px;
}
.stream-label.vertical {
  font-weight: 700;
  letter-spacing: 0.06em;
  stroke-width: 3px;
}
.stream-label.bg { opacity: 0.25; pointer-events: none; }

.region-label {
  fill: rgba(175, 190, 235, 0.62);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  paint-order: stroke;
  stroke: rgba(5, 6, 14, 0.82);
  stroke-width: 3px;
  pointer-events: none;
}

.m-bar { cursor: pointer; }
.m-hit, .m-bar-hit {
  fill: transparent;
  stroke: none;
  pointer-events: none;
}
.marker { cursor: pointer; }
.marker .m-label {
  font-size: 11px; fill: #ccd6f0;
  paint-order: stroke; stroke: rgba(5,6,14,0.8); stroke-width: 2.5px;
  cursor: pointer;
}
.marker.visited .m-label { fill: #8d97b8; }
.marker.visited .m-core { opacity: 0.75; }
.marker .m-ring { fill: none; stroke-width: 1.2; opacity: 0; }
.marker.selected .m-ring { opacity: 0.9; }
.marker .m-check { font-size: 8px; fill: #7fd9a8; opacity: 0.9; pointer-events: none; }

.cluster { cursor: pointer; }
.cluster .cluster-hit { fill: transparent; stroke: none; pointer-events: none; }
.cluster .cluster-core { fill: rgba(90, 105, 160, 0.25); stroke: rgba(140, 160, 230, 0.4); stroke-width: 1; }
.cluster text {
  fill: #aab6dd; font-size: 10px; text-anchor: middle;
  pointer-events: none;
}
.cluster:hover .cluster-core { fill: rgba(110, 130, 200, 0.4); }

.influence-thread {
  fill: none;
  stroke: rgba(157, 184, 255, 0.24);
  stroke-width: 1;
  stroke-dasharray: 2 7;
  stroke-linecap: round;
  pointer-events: none;
}
.thread { fill: none; stroke-width: 1.4; opacity: 0.75; pointer-events: none; }
.thread-dot { cursor: pointer; transition: fill 0.15s; }

/* wide invisible stroke along each arc so the thin lines are easy to hover/click */
.thread-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}
/* hovered arc: brighten the line, pop the endpoint dot (r via CSS, Chromium ok) */
.thread.hover:not(.glow) { opacity: 1; stroke-width: 2; }
.thread.glow.hover { opacity: 0.3; }
.thread-dot.hover { fill: #cfe0ff; r: 7.5px; }
.thread-label.hover { font-weight: 700; filter: brightness(1.35); }
/* 2nd-degree web: connections of the connected — deliberately faint + dotted */
.thread-secondary {
  fill: none;
  stroke: rgba(157, 184, 255, 0.28);
  stroke-width: 1.1;
  stroke-dasharray: 3 6;
  stroke-linecap: round;
  pointer-events: none;
}
.thread-secondary-dot {
  fill: rgba(157, 184, 255, 0.4);
  stroke: rgba(5, 6, 14, 0.8);
  stroke-width: 1;
  cursor: pointer;
  transition: fill 0.15s;
}
.thread-secondary-dot:hover, .thread-secondary-dot.hover { fill: rgba(190, 210, 255, 0.95); r: 5.5px; }
.thread-secondary.hover {
  stroke: rgba(157, 184, 255, 0.8);
  stroke-width: 1.6;
}
.thread-label-secondary { font-size: 10.5px; font-weight: 600; }
.thread-label {
  font-size: 11px; font-weight: 600; cursor: pointer;
  paint-order: stroke; stroke: rgba(5,6,14,0.85); stroke-width: 2.5px;
}
.thread-label:hover { fill: #fff !important; }

/* Persistent, readable names for the selected connection web. */
.selection-label { cursor: pointer; }
.selection-label text { fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; }
.selection-label[data-depth="0"] text,
.selection-label[data-depth="1"] text { fill: var(--connection-color); }
.selection-label:hover text, .selection-label:focus-visible text { text-decoration: underline; }
.selection-node { fill: var(--connection-color); stroke: var(--card-bg); stroke-width: 2; }
.selection-leader { fill: none; stroke: var(--ink-dim); stroke-width: 1; opacity: .7; pointer-events: none; }
.stream.connected { opacity: 1; filter: brightness(1.12) saturate(1.2); stroke: var(--accent); stroke-width: 1.5; }

.pop-line { fill: none; stroke: rgba(127, 217, 168, 0.55); stroke-width: 1.6; pointer-events: none; }
.pop-label { fill: rgba(127, 217, 168, 0.75); font-size: 9.5px; text-anchor: end; pointer-events: none; }

/* scrubber internals */
.scrub-track { fill: rgba(10, 13, 26, 0.72); stroke: rgba(130, 150, 210, 0.16); stroke-width: 1; }
.scrub-window { fill: rgba(127, 180, 255, 0.16); stroke: rgba(127, 180, 255, 0.5); stroke-width: 1; cursor: grab; }
.scrub-tick { stroke: rgba(150, 165, 215, 0.35); }
.scrub-tick-label { fill: var(--ink-dim); font-size: 8.5px; font-variant-numeric: tabular-nums; }
.scrub-readout { pointer-events: none; }
.scrub-readout-bg {
  fill: rgba(14, 18, 35, 0.88);
  stroke: rgba(127, 180, 255, 0.34);
  stroke-width: 1;
}
.scrub-readout-year {
  fill: #e8eefc;
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.scrub-readout-pop {
  fill: rgba(127, 217, 168, 0.9);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}
.scrub-readout.mobile .scrub-readout-bg {
  fill: rgba(14, 18, 35, 0.94);
}
.scrub-readout.mobile .scrub-readout-year {
  font-size: 9.5px;
}
.scrub-readout.mobile .scrub-readout-pop {
  font-size: 8.5px;
}
.scrub-era-label {
  fill: rgba(150, 165, 215, 0.55); font-size: 8px;
  letter-spacing: 0.12em; text-transform: uppercase; text-anchor: middle;
}
.scrub-center { stroke: #ffd27a; stroke-width: 1; opacity: 0.7; }

/* ---- panel ---- */
#panel {
  position: fixed; top: var(--topbar-h); right: 0; bottom: var(--tabs-h);
  width: min(400px, 92vw);
  z-index: 30;
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  border-left: 1px solid rgba(130, 150, 210, 0.2);
  transform: translateX(105%);
  transition: transform 0.34s cubic-bezier(0.22, 0.9, 0.3, 1);
  display: flex; flex-direction: column;
}
#panel.open { transform: translateX(0); }
#panel-grip { display: none; }
#panel-close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(10, 13, 26, 0.7); border: 1px solid rgba(130,150,210,0.25);
  color: var(--ink-dim); font-size: 17px;
}
#panel-close:hover { color: #fff; }
#panel-scroll {
  overflow-y: auto;
  padding: 0 0 24px;
  height: 100%;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#panel-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  background-color: var(--panel-bg);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  position: relative;
  touch-action: pan-y;
  transition: background-image 0.15s;
}
#panel-image::after {
  content: ""; position: absolute; inset: 0; z-index: 0;
  display: none;
  background: linear-gradient(to bottom, transparent 40%, var(--panel-bg));
  pointer-events: none;
}
.img-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(8, 10, 22, 0.62); border: 1px solid rgba(150, 165, 220, 0.3);
  color: #dde4f5; font-size: 19px; line-height: 1;
  opacity: 0.65; transition: opacity 0.15s, background 0.15s;
}
.img-nav:hover { opacity: 1; background: rgba(8, 10, 22, 0.85); }
#img-prev { left: 10px; }
#img-next { right: 10px; }
#img-count {
  position: absolute; left: 12px; bottom: 12px; z-index: 2;
  font-size: 10.5px; color: #dde4f5; font-variant-numeric: tabular-nums;
  background: rgba(8, 10, 22, 0.62); border-radius: 9px; padding: 2px 8px;
}
#panel-head { padding: 18px 48px 0 22px; }
#panel-category {
  font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase;
  padding: 2px 9px; border-radius: 9px;
  border: 1px solid currentColor;
}
#panel-title { font-family: var(--serif); font-size: 24px; font-weight: 500; margin: 10px 0 4px; }
#panel-date { color: var(--glow-person); font-size: 13.5px; font-variant-numeric: tabular-nums; }
#panel-blurb { padding: 14px 22px 4px; font-size: 14.5px; line-height: 1.65; color: #d5dbee; }
#panel-connections-jump { display: none; }
#panel-detail-wrap,
#panel-context-wrap,
#panel-media-wrap {
  margin: 14px 22px 0;
  padding-top: 14px;
  border-top: 1px solid rgba(130, 150, 210, 0.18);
}
#panel-detail-wrap h3,
#panel-context-wrap h3,
#panel-media-wrap h3 {
  font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 10px; font-weight: 600;
}
#panel-media { display: grid; gap: 8px; }
.panel-media-more summary {
  min-height: 44px;
  padding: 12px 0;
  color: var(--accent);
  font-size: 12.5px;
  cursor: pointer;
}
.panel-media-more .panel-media-card + .panel-media-card { margin-top: 8px; }
.panel-media-more summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#panel-media-wrap { border-top: 0; padding-top: 0; }
#panel-image { margin-top: 16px; }
.panel-media-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  width: 100%;
  padding: 11px 12px;
  color: #d9e4fb;
  text-decoration: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  background: rgba(90, 118, 185, 0.1);
  border: 1px solid rgba(130, 155, 225, 0.22);
  border-radius: 7px;
  transition: background 0.15s, border-color 0.15s;
}
.panel-media-card:hover {
  background: rgba(100, 132, 210, 0.2);
  border-color: rgba(145, 174, 245, 0.46);
}
.panel-media-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-media-kind {
  color: #91b8ff;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.media-video .panel-media-kind::before { content: "▶ "; }
.media-podcast .panel-media-kind::before { content: "◉ "; color: #d2a8ff; }
.media-podcast .panel-media-kind { color: #d2a8ff; }
.panel-media-audience {
  color: #aeb9d3;
  font-size: 10.5px;
  white-space: nowrap;
}
.panel-media-card strong { font-size: 13.5px; line-height: 1.35; }
.panel-media-meta { color: #9eabc7; font-size: 11.5px; line-height: 1.35; }
.panel-media-note { color: #b7c2d9; font-size: 12px; line-height: 1.45; }

/* ---- in-app video player ---- */
#video-player {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 3, 8, 0.82);
  backdrop-filter: blur(5px);
}
#video-player[hidden] { display: none; }
#video-player-card {
  width: min(960px, calc(100vw - 40px));
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0d101e;
  border: 1px solid rgba(145, 168, 230, 0.34);
  border-radius: 8px;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.82);
}
#video-player-head,
#video-player-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-shrink: 0;
}
#video-player-head {
  min-height: 54px;
  padding: 8px 10px 8px 18px;
  border-bottom: 1px solid rgba(130, 150, 210, 0.18);
}
#video-player-title {
  min-width: 0;
  overflow: hidden;
  color: #edf2ff;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#video-player-close {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(110, 140, 230, 0.1);
  color: #cbd5ee;
  font-size: 25px;
  line-height: 1;
}
#video-player-close:hover { background: rgba(110, 140, 230, 0.24); color: #fff; }
#video-player-frame-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  flex: 0 1 auto;
  min-height: 0;
  background: #000;
}
#video-player-frame { display: block; width: 100%; height: 100%; border: 0; }
#video-player-foot {
  min-height: 48px;
  padding: 8px 16px;
  border-top: 1px solid rgba(130, 150, 210, 0.18);
  color: #9eabc7;
  font-size: 12px;
}
#video-player-external { color: #a9c8ff; text-decoration: none; white-space: nowrap; }
#video-player-external:hover { color: #fff; text-decoration: underline; }

@media (max-width: 720px) {
  #video-player { padding: 8px; }
  #video-player-card { width: 100%; max-height: calc(100dvh - 16px); }
  #video-player-head { min-height: 50px; padding-left: 13px; }
  #video-player-title { font-size: 16px; }
  #video-player-foot { min-height: 52px; padding: 7px 12px; }
  #video-player-source { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #video-player-external { min-height: 40px; display: inline-flex; align-items: center; }
}
#panel-detail,
#panel-context { display: flex; flex-direction: column; gap: 11px; }
.panel-detail-block h4 {
  color: #e8eefc;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 5px;
}
.panel-detail-block p {
  color: #bac4dd;
  font-size: 13.5px;
  line-height: 1.58;
}
.panel-detail-source {
  color: var(--ink-faint);
  font-size: 11.5px;
  line-height: 1.45;
}
#panel-related-wrap { padding: 14px 22px 0; }
#panel-related-wrap h3 {
  font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 9px; font-weight: 600;
}
#panel-related { display: flex; flex-wrap: wrap; gap: 7px; }
.connection-guide { margin: 0 0 12px; color: var(--ink-dim); font-size: 12px; line-height: 1.5; }
.related-chip {
  padding: 5px 12px; font-size: 12.5px;
  background: rgba(110, 140, 230, 0.12);
  border: 1px solid rgba(130, 155, 235, 0.3);
  border-radius: 14px; color: #bcd0f7;
  transition: all 0.15s;
}
.related-chip:hover { background: rgba(110, 140, 230, 0.28); color: #fff; }
#panel-wiki {
  display: inline-block; margin: 18px 22px 0;
  color: var(--accent); font-size: 13px; text-decoration: none;
  border-bottom: 1px solid rgba(127, 180, 255, 0.35);
  padding-bottom: 1px;
}
#panel-wiki:hover { border-bottom-color: var(--accent); }

/* ---- slice ---- */
#slice {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 40;
  width: min(660px, 94vw); max-height: 72vh;
  background: var(--card-bg);
  border: 1px solid rgba(130, 150, 210, 0.28);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  display: flex; flex-direction: column;
  overflow: hidden;
}
#slice-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--line);
}
#slice-head h2 { font-family: var(--serif); font-size: 18px; font-weight: 500; }
#slice-close { background: none; border: none; color: var(--ink-dim); font-size: 20px; }
#slice-close:hover { color: #fff; }
#slice-body { overflow-y: auto; padding: 10px 20px 18px; }
.slice-group { margin-top: 10px; }
.slice-group h3 {
  font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase;
  margin-bottom: 6px; font-weight: 600;
}
.slice-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 13.5px;
}
.slice-item:hover { background: rgba(110, 140, 230, 0.14); }
.slice-item .sl-date { color: var(--ink-faint); font-size: 11.5px; min-width: 84px; font-variant-numeric: tabular-nums; }
.slice-empty { color: var(--ink-faint); font-size: 13px; padding: 8px; }

/* ---- tours ---- */
#tour-menu {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 4, 10, 0.6); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
#tour-menu-card {
  width: min(820px, 92vw);
  max-height: min(88vh, 640px);
  max-height: min(88dvh, 640px);
  background: var(--card-bg);
  border: 1px solid rgba(130, 150, 210, 0.28);
  border-radius: 14px; padding: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  display: flex; flex-direction: column;
  min-height: 0;
}
#tour-menu-card h2 { font-family: var(--serif); font-weight: 500; margin-bottom: 11px; }
#tour-list {
  flex: 1;
  min-height: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
}
.tour-category-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding-bottom: 11px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(130, 150, 210, 0.18);
}
.tour-category-tab {
  min-width: 0;
  min-height: 44px;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: normal;
  line-height: 1.15;
  background: rgba(20, 25, 48, 0.7);
  border: 1px solid rgba(130, 150, 210, 0.24);
  border-radius: 10px 10px 6px 6px;
  color: var(--ink-dim);
  font-size: 11.5px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.tour-category-tab:hover {
  color: #fff;
  border-color: rgba(140, 170, 255, 0.42);
}
.tour-category-tab.active {
  color: #fff;
  border-color: rgba(140, 170, 255, 0.56);
  background: rgba(110, 140, 230, 0.2);
  box-shadow: inset 0 -2px 0 rgba(127, 180, 255, 0.52);
}
.tour-category-grid {
  min-height: 0;
  display: block;
  overflow: visible;
}
.tour-category {
  display: none;
}
.tour-category.active { display: block; }
.tour-category h3 {
  display: none;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 9px;
  font-weight: 600;
}
.tour-category-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
  overflow: visible;
  padding-right: 0;
}
.tour-option {
  display: flex; width: 100%; min-height: 100px; text-align: left;
  flex-direction: column;
  padding: 11px 12px; margin-bottom: 0;
  background: rgba(110, 140, 230, 0.08);
  border: 1px solid rgba(130, 155, 235, 0.22);
  border-radius: 10px; color: var(--ink);
  transition: all 0.15s;
}
.tour-option:hover { background: rgba(110, 140, 230, 0.2); }
.tour-option b { display: block; font-size: 14px; margin-bottom: 3px; }
.tour-option span { font-size: 12px; color: var(--ink-dim); }
.tour-option .tour-stops { font-size: 11px; color: var(--ink-faint); margin-top: auto; padding-top: 8px; }
.tour-category-empty {
  color: var(--ink-faint);
  font-size: 13px;
  padding: 10px 2px;
}
#tour-menu-close {
  align-self: flex-end;
  flex-shrink: 0;
  margin-top: 10px; padding: 7px 16px;
  background: none; border: 1px solid rgba(130,150,210,0.3);
  border-radius: 14px; color: var(--ink-dim);
}
/* while the detail panel is open (every tour stop opens it), shift the HUD
   into the free space left of the panel so it never covers the story */
@media (min-width: 721px) {
  body.panel-open #tour-hud {
    left: calc((100% - min(400px, 92vw)) / 2);
    width: min(560px, calc(100% - min(400px, 92vw) - 24px));
  }
}
#tour-hud {
  position: fixed; bottom: calc(var(--tabs-h) + 14px); left: 50%; transform: translateX(-50%);
  z-index: 35;
  width: min(560px, 92vw);
  background: var(--card-bg);
  border: 1px solid rgba(180, 150, 255, 0.35);
  border-radius: 14px; padding: 14px 18px 12px;
  box-shadow: 0 12px 50px rgba(80, 40, 160, 0.25), 0 12px 50px rgba(0,0,0,0.5);
}
#tour-note { font-size: 13.5px; line-height: 1.5; color: #ddd5f5; margin-bottom: 10px; }
#tour-controls { display: flex; align-items: center; gap: 10px; }
#tour-controls button {
  padding: 6px 14px;
  background: rgba(150, 110, 230, 0.15);
  border: 1px solid rgba(170, 140, 240, 0.35);
  border-radius: 13px; color: #d8ccf5; font-size: 12.5px;
}
#tour-controls button:hover:not(:disabled) { background: rgba(150, 110, 230, 0.3); color: #fff; }
#tour-controls button:disabled { opacity: 0.35; cursor: default; }
#tour-progress { font-size: 12px; color: var(--ink-dim); margin: 0 auto; }
#tour-exit { margin-left: auto; }

/* ---- toast / hint / about ---- */
#toast {
  position: fixed; top: calc(var(--topbar-h) + 12px); left: 50%; transform: translateX(-50%);
  z-index: 45;
  display: flex; align-items: center; gap: 10px;
  max-width: min(520px, 92vw);
  background: var(--card-bg);
  border: 1px solid rgba(255, 210, 122, 0.3);
  border-radius: 12px; padding: 10px 16px;
  font-size: 13px; color: #f0e2c0;
  box-shadow: 0 10px 40px rgba(0,0,0,0.55);
  animation: toast-in 0.5s cubic-bezier(0.22, 0.9, 0.3, 1);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -12px); } }
#toast button { background: none; border: none; color: var(--ink-dim); font-size: 16px; flex-shrink: 0; }
#toast-text b { color: #ffd27a; cursor: pointer; }
#toast-text b:hover { text-decoration: underline; }

#intro-hint {
  position: fixed; bottom: calc(var(--tabs-h) + 16px); left: 50%; transform: translateX(-50%);
  z-index: 15;
  font-size: 12.5px; color: var(--ink-dim);
  background: rgba(13, 16, 30, 0.8);
  padding: 8px 18px; border-radius: 16px;
  border: 1px solid var(--line);
  pointer-events: none;
  transition: opacity 1s;
}
#intro-hint.fade { opacity: 0; }

#overview-zoom-hint {
  position: fixed;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 44;
  width: max-content;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
  padding: 12px 18px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--card-bg);
  color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

#about {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 4, 10, 0.65); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
#about-card,
#feedback-card {
  width: min(560px, 92vw); max-height: 80vh; overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid rgba(130, 150, 210, 0.28);
  border-radius: 14px; padding: 26px;
}
#about-card h2,
#feedback-card h2 { font-family: var(--serif); font-weight: 500; margin-bottom: 12px; }
#about-card p,
#feedback-card p { font-size: 13.5px; line-height: 1.65; color: #cfd6ea; margin-bottom: 12px; }
#about-card kbd {
  background: rgba(120, 140, 210, 0.18); border: 1px solid rgba(130,150,210,0.3);
  border-radius: 4px; padding: 0 5px; font-size: 12px; font-family: inherit;
}
.about-fine { font-size: 12px !important; color: var(--ink-faint) !important; }
#about-card h3 { margin: 20px 0 8px; font-size: 16px; line-height: 1.4; color: var(--ink); }
#about-card .about-tour-intro { margin: 20px 0; padding: 18px; border: 1px solid var(--atlas-tour-border, #d7b35a); border-radius: 8px; }
#about-card .about-tour-intro h3 { margin-top: 0; }
#about-tours { min-height: 44px; padding: 10px 16px; border: 1px solid var(--atlas-tour-border, #d7b35a); border-radius: 6px; background: var(--atlas-tour, #f0cc70); color: var(--atlas-tour-ink, #30240b); font: 600 13px/1.4 "Segoe UI", system-ui, sans-serif; }
#about-tours:hover { background: var(--atlas-tour-hover, #ffda7a); }
.about-notes { margin: 20px 0 16px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.about-notes summary { min-height: 44px; padding: 10px 0; font-size: 13px; line-height: 1.5; cursor: pointer; color: var(--ink); }
.about-notes[open] summary { margin-bottom: 8px; }
#about-card :is(button, summary, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#about-close {
  min-height: 44px; padding: 7px 18px; background: rgba(110, 140, 230, 0.15);
  border: 1px solid rgba(130, 155, 235, 0.35); border-radius: 14px; color: #cdd8f5;
}
#feedback {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 4, 10, 0.65); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.feedback-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  color: var(--ink-dim);
  font-size: 12px;
}
.feedback-field select,
.feedback-field textarea {
  width: 100%;
  background: rgba(12, 16, 31, 0.78);
  border: 1px solid rgba(130, 150, 210, 0.28);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  padding: 9px 11px;
  outline: none;
}
.feedback-field textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.45;
}
.feedback-field select:focus,
.feedback-field textarea:focus {
  border-color: rgba(140, 170, 255, 0.58);
}
#feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
#feedback-actions button {
  padding: 7px 14px;
  background: rgba(110, 140, 230, 0.15);
  border: 1px solid rgba(130, 155, 235, 0.35);
  border-radius: 14px;
  color: #cdd8f5;
}
#feedback-actions button:hover { color: #fff; background: rgba(110, 140, 230, 0.28); }
#feedback-status {
  min-height: 18px;
  margin-top: 10px !important;
  margin-bottom: 0 !important;
  color: var(--ink-faint) !important;
  font-size: 12px !important;
}

/* ---- onboarding walkthrough (coach marks) ---- */
#coach { position: fixed; inset: 0; z-index: 60; }        /* captures clicks behind the callout */
#coach.no-target { background: rgba(3, 4, 10, 0.72); }
#coach.welcome { background: rgba(3, 4, 10, 0.42); }       /* let the cinematic flight glow through */
#coach-hole {
  position: fixed; border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(3, 4, 10, 0.72),
              0 0 0 1.5px rgba(127, 180, 255, 0.9),
              0 0 24px rgba(127, 180, 255, 0.45);
  transition: left 0.35s cubic-bezier(0.22,0.9,0.3,1), top 0.35s cubic-bezier(0.22,0.9,0.3,1),
              width 0.35s cubic-bezier(0.22,0.9,0.3,1), height 0.35s cubic-bezier(0.22,0.9,0.3,1);
}
#coach.no-target #coach-hole, #coach.welcome #coach-hole { display: none; }
#coach-pop {
  position: fixed; width: min(340px, 92vw);
  background: var(--card-bg);
  border: 1px solid rgba(130, 150, 210, 0.32);
  border-radius: 14px; padding: 17px 18px 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.62);
  opacity: 0;
  transition: opacity 0.25s, left 0.3s ease, top 0.3s ease;
}
#coach-pop.shown { opacity: 1; }
#coach-pop { max-height: calc(100dvh - 24px); overflow-y: auto; }
#coach-kicker { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; margin: 0 24px 8px 0; }
#coach-tours {
  display: block; width: 100%; margin-top: 16px; padding: 12px 14px;
  border: 1px solid var(--accent); border-radius: 8px;
  background: var(--accent); color: var(--bg); font: inherit; font-size: 14px; font-weight: 700;
}
#coach-tours:hover { filter: brightness(1.08); }
#coach-tours:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
#coach-pop.tour-first #coach-prev { display: none; }
#coach-pop.tour-first #coach-next { background: transparent; color: var(--ink-dim); border-color: var(--line); }
#coach-dots { flex-shrink: 0; }
#coach.no-target #coach-pop, #coach.welcome #coach-pop {
  left: 50% !important; top: 50% !important;
  transform: translate(-50%, -50%);
}
#coach-skip {
  position: absolute; top: 9px; right: 11px;
  width: 24px; height: 24px; border-radius: 50%;
  background: none; border: none; color: var(--ink-faint); font-size: 15px; line-height: 1;
}
#coach-skip:hover { color: var(--ink); }
#coach-emoji { font-size: 25px; line-height: 1; margin-bottom: 8px; }
#coach-pop h3 { font-family: var(--serif); font-weight: 500; font-size: 18px; margin-bottom: 7px; color: #eaf0ff; }
#coach-body { font-size: 13.5px; line-height: 1.6; color: #cfd6ea; }
#coach-body b { color: #eaf0ff; font-weight: 600; }
#coach-body i { color: #dbe2f5; font-style: italic; }
#coach-foot { margin-top: 15px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
#coach-dismiss-row { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-faint); cursor: pointer; user-select: none; }
#coach-dismiss-row input { width: 13px; height: 13px; accent-color: var(--accent); cursor: pointer; }
#coach-nav { display: flex; align-items: center; gap: 8px; margin-left: auto; }
#coach-dots { display: flex; gap: 5px; }
#coach-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(140, 160, 220, 0.3); transition: background 0.2s, transform 0.2s; }
#coach-dots i.on { background: var(--accent); transform: scale(1.3); }
#coach-prev, #coach-next {
  padding: 6px 13px; border-radius: 13px; font-size: 12.5px;
  border: 1px solid rgba(130, 155, 235, 0.35);
}
#coach-prev { background: transparent; color: var(--ink-dim); }
#coach-prev:hover:not(:disabled) { color: #fff; }
#coach-prev:disabled { opacity: 0.32; cursor: default; }
#coach-next { background: rgba(110, 140, 230, 0.22); color: #eaf0ff; }
#coach-next:hover { background: rgba(110, 140, 230, 0.36); }
@media (max-width: 720px) {
  #coach-foot { gap: 8px; }
  #coach-dismiss-row { order: 2; flex-basis: 100%; }
  #coach-nav { order: 1; width: 100%; }
}

/* ===== Kids edition theme (html.kids) — brighter, rounder, friendlier.
   Purely cosmetic: the adult look is untouched when the class is absent. ===== */
html.kids body { --font: "Comic Sans MS", "Segoe Print", "Comic Neue", sans-serif; }
html.kids #map { filter: saturate(1.35); }
html.kids .stream { opacity: 0.97; }
html.kids .stream-label { font-weight: 700; letter-spacing: 0.02em; }
html.kids .m-label { font-size: 12.5px; stroke-width: 3px; }
html.kids .m-core { r: 4.6px; }
html.kids .m-halo { r: 13px; }
html.kids .era-label { letter-spacing: 0.22em; }
html.kids #brand h1 {
  background: linear-gradient(100deg, #ffd27a, #7fd9a8 40%, #46d4ff 70%, #c9a6ff);
  -webkit-background-clip: text; background-clip: text;
}
html.kids .tab, html.kids #tab-tools button { font-size: 13.5px; border-radius: 19px; }
html.kids #panel-blurb { font-size: 16px; line-height: 1.75; }
html.kids #panel-title { font-size: 26px; }
/* hide the Wikipedia extract + generated context — too advanced; keep the
   kid blurb, photo gallery, connected chips, and the Wikipedia link */
html.kids #panel-detail-wrap, html.kids #panel-context-wrap { display: none !important; }
html.kids .panel-media-card { background: rgba(100, 145, 220, 0.14); }
html.kids .related-chip { font-size: 13.5px; padding: 6px 14px; border-radius: 17px; }
html.kids #tour-hud { border-color: rgba(127, 217, 168, 0.45); }
html.kids .tour-option b { font-size: 15px; }
/* kids tour menu: one simple grid, no category tabs */
.tour-flat-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}
@media (max-width: 720px) {
  .tour-flat-list { grid-template-columns: 1fr; }
}

/* category chip colors */
.cat-civilization { color: #e8b45c; }
.cat-technology { color: var(--glow-tech); }
.cat-religion { color: var(--glow-rel); }
.cat-person { color: var(--glow-person); }
.cat-event { color: var(--glow-event); }

/* ---- mobile ---- */
@media (max-width: 720px) {
  :root { --topbar-h: 54px; --regionbar-h: 44px; --tabs-h: 58px; --scrubber-w: 52px; }
  #topbar { flex-wrap: nowrap; padding: 5px 8px; gap: 6px; height: var(--topbar-h); }
  #brand { flex: 1 1 auto; min-width: 0; }
  #brand h1 {
    font-size: 16px;
    overflow: visible;
    text-overflow: clip;
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    color: #cfe0ff;
  }
  #progress-counter { display: none; }
  #topbar-right { gap: 6px; flex-shrink: 0; }
  #mode-switch { display: none; }
  #year-pill {
    min-width: 0;
    max-width: 96px;
    font-size: 11px;
    padding: 5px 8px;
  }
  #about-btn {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }
  #zoom-controls {
    position: fixed;
    top: calc(var(--topbar-h) + var(--regionbar-h) + 8px);
    right: 8px;
    z-index: 19;
    flex-direction: column;
    gap: 6px;
  }
  #zoom-controls button {
    width: 44px;
    height: 44px;
    background: rgba(18, 22, 40, 0.9);
    border-color: rgba(140, 165, 235, 0.34);
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.28);
  }
  #mobile-region-nav {
    position: fixed;
    display: flex;
    align-items: center;
    gap: 5px;
    top: var(--topbar-h);
    left: var(--scrubber-w);
    right: 0;
    height: var(--regionbar-h);
    padding: 0 7px;
    z-index: 18;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    background: linear-gradient(to bottom, rgba(5, 6, 14, 0.82), rgba(5, 6, 14, 0.34));
    transition: opacity 0.16s;
  }
  #mobile-region-nav::-webkit-scrollbar { display: none; }
  #mobile-region-nav button {
    flex: 0 0 auto;
    min-width: 70px;
    height: 40px;
    padding: 0 11px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #aeb9d9;
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
  }
  #mobile-region-nav button[data-region="mena"] { min-width: 140px; }
  #mobile-region-nav button.active {
    color: #f3f6ff;
    background: rgba(110, 140, 230, 0.18);
    border-color: rgba(140, 170, 255, 0.38);
  }
  body.mobile-search-open #mobile-region-nav { opacity: 0; pointer-events: none; }
  #searchbox {
    display: none;
    position: fixed;
    top: calc(var(--topbar-h) + 6px);
    left: 10px;
    right: 10px;
    max-width: none;
    z-index: 48;
  }
  body.mobile-search-open #searchbox { display: block; }
  body.mobile-search-open #search {
    padding: 10px 14px;
    min-height: 44px;
    font-size: 16px;
    border-radius: 18px;
    background: rgba(18, 22, 40, 0.96);
    box-shadow: 0 14px 44px rgba(0,0,0,0.52);
  }
  body.mobile-search-open #search-results { max-height: min(54vh, 420px); }
  .search-item { min-height: 44px; padding: 10px 12px; font-size: 14px; }
  .search-item .si-date { font-size: 12px; }
  #scrubber { width: var(--scrubber-w); overflow: visible; }
  .scrub-tick-label { font-size: 8px; }
  .scrub-era-label {
    font-size: 8px;
    letter-spacing: 0.08em;
  }
  /* bottom bar: tab row replaced by the drop-up picker; thumb-side ordering
     (right → left): layer picker, dice + Tours, feedback, search */
  #tabs { padding: 0 6px; }
  #tab-group { display: none; }
  #tab-tools { width: 100%; gap: 4px; margin-left: 0; }
  #tab-tools button { height: 44px; min-height: 44px; padding: 0 6px; font-size: 12px; }
  #help-btn { display: none; }
  #surprise-btn, #search-toggle-btn, #feedback-btn { width: 44px; flex: 0 0 44px; }
  #feedback-btn .feedback-label { display: none; }
  #search-toggle-btn {
    display: flex;
    font-size: 15px;
  }
  #search-toggle-btn.active {
    color: #fff;
    border-color: rgba(140, 170, 255, 0.55);
    background: rgba(110, 140, 230, 0.18);
  }
  #tours-btn {
    position: static;
    transform: none;
    z-index: auto;
    flex: 0 0 auto;
    min-width: 60px;
    flex: 0 0 60px;
    text-align: center;
    gap: 5px;
    padding: 0 6px;
  }
  #tours-btn .tour-label-full { display: none; }
  #tours-btn .tour-label-short { display: inline; }
  #tab-menu-btn {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: 5px;
    color: var(--ink);
    border-color: rgba(140, 170, 255, 0.35);
  }
  #tab-menu {
    right: 6px;
    max-height: calc(100dvh - var(--topbar-h) - var(--tabs-h) - 12px);
    overflow-y: auto;
  }
  #tab-menu-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stream-hit.active { pointer-events: stroke; }
  .m-hit, .m-bar-hit { pointer-events: all; }
  .cluster .cluster-hit { pointer-events: all; }
  .marker .m-label { font-size: 13.5px; stroke-width: 3px; }
  .thread-label { font-size: 13px; stroke-width: 3px; }
  .thread-label-secondary { font-size: 12px; }
  .cluster text { font-size: 11px; }
  .thread-hit { stroke-width: 24; }
  #tour-menu {
    align-items: flex-start;
    justify-content: center;
    padding: 10px 10px calc(var(--tabs-h) + 10px);
  }
  #tour-menu-card {
    width: 100%;
    height: min(82vh, calc(100dvh - var(--tabs-h) - 20px));
    max-height: calc(100dvh - var(--tabs-h) - 20px);
    padding: 16px;
    border-radius: 16px;
  }
  #tour-menu-card h2 { margin-bottom: 11px; }
  #tour-list { display: flex; flex-direction: column; }
  .tour-category-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding-bottom: 11px;
    margin-bottom: 11px;
    border-bottom: 1px solid rgba(130, 150, 210, 0.16);
    flex-shrink: 0;
  }
  .tour-category-tab {
    min-width: 0;
    min-height: 66px;
    padding: 8px 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 25, 48, 0.75);
    border: 1px solid rgba(130, 150, 210, 0.22);
    border-radius: 12px;
    color: var(--ink-dim);
    font-size: 12px;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }
  .tour-category-tab.active {
    color: #fff;
    border-color: rgba(140, 170, 255, 0.5);
    background: rgba(110, 140, 230, 0.18);
  }
  .tour-category-grid {
    flex: 1;
    height: auto;
    min-height: 0;
    display: block;
    overflow: hidden;
    padding-bottom: 0;
  }
  .tour-category { display: none; height: 100%; flex-direction: column; }
  .tour-category.active { display: flex; }
  .tour-category h3 { display: none; }
  .tour-category-list {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(150, 170, 225, 0.38) transparent;
  }
  .tour-category-list::-webkit-scrollbar { width: 4px; }
  .tour-category-list::-webkit-scrollbar-track { background: transparent; }
  .tour-category-list::-webkit-scrollbar-thumb {
    background: rgba(150, 170, 225, 0.38);
    border-radius: 4px;
  }
  .tour-option {
    min-height: auto;
    padding: 12px 13px;
  }
  .tour-option span { font-size: 13.5px; line-height: 1.4; }
  .tour-option .tour-stops { font-size: 12px; }
  #tour-menu-close { width: 100%; min-height: 44px; margin-top: 10px; padding: 9px 16px; }
  #panel {
    top: auto; left: 0; right: 0; bottom: var(--tabs-h);
    width: 100%; height: min(66vh, calc(100dvh - var(--topbar-h) - var(--tabs-h) - 6px));
    max-height: none;
    border-left: none; border-top: 1px solid rgba(130, 150, 210, 0.25);
    border-radius: 16px 16px 0 0;
    background: rgba(13, 16, 30, 0.84);
    transform: translateY(110%);
  }
  #panel.open { transform: translateY(0); }
  #panel.open.peek { transform: translateY(calc(100% - 48px)); }
  #panel-grip {
    display: block;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 112px;
    height: 44px;
    z-index: 4;
    border: 0;
    background: transparent;
    cursor: ns-resize;
    touch-action: none;
  }
  #panel-grip::before {
    content: "";
    position: absolute;
    left: 22px;
    right: 22px;
    top: 12px;
    height: 4px;
    border-radius: 999px;
    background: rgba(190, 204, 245, 0.62);
    box-shadow: 0 0 16px rgba(127, 180, 255, 0.28);
  }
  #panel.peek #panel-grip::before { background: rgba(225, 235, 255, 0.82); }
  #panel-close {
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    color: #eef3ff;
    background: rgba(8, 10, 22, 0.82);
  }
  #panel-scroll { padding-top: 22px; }
  #panel-image {
    height: clamp(168px, 24vh, 220px);
    aspect-ratio: auto;
    background-size: cover;
    background-position: center 25%;
  }
  #panel-image::after { display: block; }
  .img-nav { width: 44px; height: 44px; }
  #panel-head { padding: 18px 54px 0 20px; }
  #panel-title { font-size: 25px; }
  #panel-date { font-size: 14px; }
  #panel-blurb {
    padding: 14px 20px 4px;
    font-size: 16px;
    line-height: 1.58;
  }
  #panel-connections-jump {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin: 10px 20px 0;
    padding: 9px 14px;
    border: 1px solid rgba(140, 170, 255, 0.34);
    border-radius: 9px;
    background: rgba(110, 140, 230, 0.13);
    color: #c9d9fb;
    font-size: 14px;
  }
  #panel-detail-wrap,
  #panel-context-wrap,
  #panel-media-wrap { margin-left: 20px; margin-right: 20px; }
  .panel-media-card { min-height: 44px; padding: 12px 13px; }
  .panel-media-card strong { font-size: 14.5px; }
  .panel-media-meta, .panel-media-note { font-size: 13px; }
  .panel-detail-block h4 { font-size: 14px; }
  .panel-detail-block p { font-size: 15px; line-height: 1.58; }
  .panel-detail-source { font-size: 12.5px; }
  #panel-related-wrap { padding-left: 20px; padding-right: 20px; }
  .related-chip {
    min-height: 44px;
    padding: 9px 13px;
    font-size: 14px;
    border-radius: 10px;
  }
  #panel-wiki { margin-left: 20px; font-size: 14px; }
  #tour-hud { width: 94vw; }
  /* on phones the panel is a bottom sheet — dock the tour HUD at the top instead */
  body.panel-open #tour-hud {
    bottom: auto;
    top: calc(var(--topbar-h) + 10px);
  }
  #intro-hint {
    top: calc(var(--topbar-h) + 4px);
    bottom: auto;
    left: calc(var(--scrubber-w) + 8px);
    right: 8px;
    width: auto;
    max-width: none;
    transform: none;
    z-index: 19;
    background: rgba(13, 16, 30, 0.96);
    padding: 7px 11px;
    border-radius: 9px;
    font-size: 13px;
    line-height: 1.3;
    text-align: center;
  }
}

/* very narrow phones: let the brand shrink so the "?" button stays on screen */
@media (max-width: 380px) {
  #brand h1 { font-size: 15px; }
  #year-pill { max-width: 88px; font-size: 10.5px; padding: 5px 6px; }
}
