/* ============================================================
   Greek World Atlas — custom theme
   Concept: aged parchment / limestone stelae, Aegean sea-blue,
   terracotta accent. Classical but not costume-y.
   ============================================================ */

:root,
[data-theme='light'] {
  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* Type scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --text-3xl: clamp(2.5rem, 1rem + 4vw, 5rem);
  --text-hero: clamp(3rem, 0.5rem + 7vw, 8rem);

  /* Surfaces — warm limestone / parchment */
  --color-bg: #f3ecdd;
  --color-surface: #f8f2e6;
  --color-surface-2: #fbf7ee;
  --color-surface-offset: #ece3d0;
  --color-surface-offset-2: #e3d7bd;
  --color-surface-dynamic: #d9caa8;
  --color-divider: #d8c9a8;
  --color-border: #c7b489;

  /* Text — ink / basalt */
  --color-text: #2b2418;
  --color-text-muted: #6f6350;
  --color-text-faint: #a89a7c;
  --color-text-inverse: #f8f2e6;

  /* Primary accent — Aegean sea blue */
  --color-primary: #1f5f6b;
  --color-primary-hover: #164852;
  --color-primary-active: #0f353d;
  --color-primary-highlight: #cfe0e0;

  /* Warning / secondary accent — terracotta */
  --color-warning: #a1502c;
  --color-warning-hover: #7d3c20;
  --color-warning-active: #582915;
  --color-warning-highlight: #e6cdb9;

  --color-error: #9a2f2f;
  --color-error-hover: #7a2323;
  --color-error-active: #591a1a;
  --color-error-highlight: #e2cbc2;

  --color-success: #4a7a3a;
  --color-success-hover: #375c2b;
  --color-success-highlight: #d3ddc5;

  --radius-sm: 0.3rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1.1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-sm: 0 1px 2px oklch(0.25 0.03 60 / 0.10);
  --shadow-md: 0 4px 14px oklch(0.25 0.03 60 / 0.14);
  --shadow-lg: 0 14px 36px oklch(0.25 0.03 60 / 0.20);

  --content-narrow: 640px;
  --content-default: 1000px;
  --content-wide: 1320px;
  --content-full: 100%;

  --font-display: 'Boska', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;

  /* Map-specific: sea + land base tones (light) — aligned with NatGeo terrain basemap */
  --map-sea: #b6d6ea;
  --map-sea-2: #a0c5dc;
  --map-land: #d9e0b4;
  --map-land-line: #b8a878;
  --map-grid: oklch(0.4 0.02 70 / 0.12);
}

[data-theme='dark'] {
  --color-bg: #17181a;
  --color-surface: #1c1d1f;
  --color-surface-2: #212224;
  --color-surface-offset: #1e1f21;
  --color-surface-offset-2: #262628;
  --color-surface-dynamic: #2e2f31;
  --color-divider: #2a2b2d;
  --color-border: #3a3b3d;

  --color-text: #e6e1d4;
  --color-text-muted: #98917e;
  --color-text-faint: #625c4e;
  --color-text-inverse: #201f1c;

  --color-primary: #5fa7ae;
  --color-primary-hover: #7fbcc2;
  --color-primary-active: #3f8288;
  --color-primary-highlight: #223638;

  --color-warning: #d08a5e;
  --color-warning-hover: #e0a27c;
  --color-warning-active: #b16f45;
  --color-warning-highlight: #3a2e24;

  --color-error: #d3695f;
  --color-error-hover: #e08a80;
  --color-error-highlight: #3a2624;

  --color-success: #8fbf72;
  --color-success-hover: #a6d18a;
  --color-success-highlight: #2a3324;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.35);
  --shadow-md: 0 4px 14px oklch(0 0 0 / 0.45);
  --shadow-lg: 0 14px 36px oklch(0 0 0 / 0.55);

  --map-sea: #2a2418;
  --map-sea-2: #211c12;
  --map-land: #2b271c;
  --map-land-line: #4a4636;
  --map-grid: oklch(0.9 0.02 70 / 0.08);
}

@media (color-gamut: p3) {
  :root, [data-theme='light'] { --color-primary: oklch(0.42 0.06 205); }
  [data-theme='dark'] { --color-primary: oklch(0.68 0.07 205); }
}

/* ============================================================
   Base layout
   ============================================================ */

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  z-index: 40;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand svg { width: 34px; height: 34px; flex-shrink: 0; color: var(--color-primary); }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }

.brand-text .title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-text .subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  cursor: pointer;
  transition: var(--transition-interactive);
}
.icon-btn:hover { background: var(--color-surface-offset); box-shadow: var(--shadow-sm); }
.icon-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.icon-btn svg { width: 18px; height: 18px; }

.about-btn span, .compare-btn span, .search-btn span, .search-btn .kbd-hint,
.legend-btn span, .share-btn span, .itineraries-btn span {
  display: none;
}

/* Overflow menu button: only shown when secondary controls are collapsed */
.hdr-overflow-btn { display: none; }

@media (min-width: 900px) {
  .about-btn, .compare-btn, .search-btn, .legend-btn, .share-btn, .itineraries-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    width: auto;
    padding: 0 var(--space-3);
  }
  .about-btn span, .compare-btn span, .search-btn span,
  .legend-btn span, .share-btn span, .itineraries-btn span { display: inline; font-size: var(--text-sm); font-weight: 500; }
  .search-btn .kbd-hint { display: inline-flex; }
}
@media (min-width: 640px) and (max-width: 899px) {
  /* Icon-only mode for medium widths */
  .about-btn, .compare-btn, .search-btn, .legend-btn, .share-btn, .itineraries-btn {
    display: inline-flex;
  }
}
@media (max-width: 639px) {
  /* On narrow mobile, hide secondary tools and show overflow menu */
  .hdr-secondary { display: none !important; }
  .hdr-overflow-btn { display: inline-flex; }
}
.search-btn {
  color: var(--color-text-muted);
}
.search-btn:hover {
  color: var(--color-text);
}
.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  line-height: 1;
}
.kbd-hint .kbd-key {
  font-size: 13px;
  line-height: 1;
}

/* ---------- Era bar ---------- */

.era-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-divider);
  overflow-x: auto;
  scrollbar-width: thin;
  position: relative;
  z-index: 30;
}

.era-select-wrap {
  position: relative;
  flex-shrink: 0;
}

.era-select {
  appearance: none;
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-10) var(--space-2) var(--space-4);
  cursor: pointer;
  min-width: 300px;
  transition: var(--transition-interactive);
}
.era-select:hover { border-color: var(--color-primary); }
.era-select:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.era-select-wrap::after {
  content: '';
  position: absolute;
  right: var(--space-3);
  top: 50%;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.era-nav-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-interactive);
}
.era-nav-btn:hover:not(:disabled) { background: var(--color-primary); color: var(--color-text-inverse); border-color: var(--color-primary); }
.era-nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.era-nav-btn svg { width: 16px; height: 16px; }

.era-track {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding-right: var(--space-3);
  mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 24px), transparent 100%);
}
.era-track::-webkit-scrollbar { display: none; }

.era-chip {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-interactive);
}
.era-chip:hover { background: var(--color-surface-offset); color: var(--color-text); }
.era-chip.active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
  font-weight: 600;
}

@media (max-width: 860px) {
  .era-track { display: none; }
}

/* ---------- Main / map area ---------- */

.main-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

#map {
  flex: 1;
  height: 100%;
  background: var(--map-sea);
  isolation: isolate;
}

.leaflet-container {
  background: var(--map-sea);
  font-family: var(--font-body);
}

/* Illustrated basemap: warm the shaded relief; the ocean pane provides the blue sea */
.basemap-relief {
  filter: sepia(0.4) saturate(1.4) hue-rotate(-8deg) brightness(1.05) contrast(1.15);
  mix-blend-mode: multiply;
}
.basemap-ocean {
  filter: saturate(1.15) hue-rotate(-3deg) brightness(1.02);
}
[data-theme='dark'] .basemap-relief {
  filter: sepia(0.3) saturate(0.8) brightness(0.55) contrast(1.1);
  mix-blend-mode: multiply;
}
[data-theme='dark'] .basemap-ocean {
  filter: brightness(0.35) saturate(0.9);
}

.leaflet-control-attribution {
  background: color-mix(in oklab, var(--color-surface) 88%, transparent) !important;
  color: var(--color-text-muted) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--color-primary) !important; }

.leaflet-control-zoom a {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}
.leaflet-control-zoom a:hover { background: var(--color-surface-offset) !important; }

.leaflet-control-recenter { margin-top: var(--space-2) !important; }
.leaflet-control-recenter a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
  font-size: 16px;
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.leaflet-control-recenter a:hover { background: var(--color-surface-offset) !important; }

/* ---------- Era info panel ---------- */

.era-panel {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  width: 340px;
  max-width: calc(100vw - 2 * var(--space-4));
  max-height: calc(100% - var(--space-8));
  background: color-mix(in oklab, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.era-panel.is-collapsed .era-panel-body {
  display: none;
}

.panel-collapse-btn {
  display: none;
  position: absolute;
  top: var(--space-2);
  left: auto;
  right: var(--space-2);
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  z-index: 5;
  font-size: 14px;
  transition: transform 0.2s ease;
}
.panel-collapse-btn:hover { background: var(--color-surface-offset); }
.era-panel.is-collapsed .panel-collapse-icon { transform: rotate(-90deg); display: inline-block; }

.era-panel-header {
  padding: var(--space-4) var(--space-4) var(--space-2);
  border-bottom: 1px solid var(--color-divider);
}

.era-panel-header .era-year {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.1;
}

.era-panel-header .era-title {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

.era-panel-body {
  padding: var(--space-3) var(--space-4) var(--space-4);
  overflow-y: auto;
  flex: 1;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--color-primary) transparent;
}
.era-panel-body::-webkit-scrollbar {
  width: 6px;
}
.era-panel-body::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--color-primary) 55%, transparent);
  border-radius: 3px;
}

.era-panel::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, color-mix(in oklab, var(--color-surface) 92%, transparent));
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.era-panel.is-collapsed::after {
  display: none;
}

.era-summary {
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}

.legend-heading {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
  font-weight: 600;
}

.legend-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 3px var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-interactive);
  font-size: var(--text-xs);
  line-height: 1.35;
  color: var(--color-text);
  text-align: left;
  background: transparent;
  border: none;
  width: 100%;
}
.legend-item:hover { background: var(--color-surface-offset); }
.legend-item.dimmed { opacity: 0.4; }

.legend-swatch {
  width: 13px;
  height: 13px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  border: 1px solid oklch(0 0 0 / 0.2);
}

.legend-item .status-tag {
  margin-left: auto;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--color-text-faint);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.era-panel-collapse {
  display: none;
}

@media (max-width: 640px) {
  .era-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    max-height: 55vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    border-left: none;
    border-right: none;
    box-shadow: 0 -8px 28px oklch(0 0 0 / 0.18);
    z-index: 400;
  }
  .panel-collapse-btn {
    display: flex;
  }
  .era-panel-header {
    padding-right: var(--space-8);
    padding-top: var(--space-4);
    position: relative;
  }
  /* Drag handle affordance */
  .era-panel-header::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
  }
  .era-panel.is-collapsed {
    max-height: 68px;
    overflow: hidden;
  }
  .era-panel.is-collapsed .era-panel-body { display: none; }
  .leaflet-control-attribution {
    max-width: 55vw;
    font-size: 9px;
  }
  /* Keep leaflet controls out of the way of the bottom drawer */
  .leaflet-bottom.leaflet-left,
  .leaflet-bottom.leaflet-right {
    bottom: 60px;
  }
}

/* ---------- Popup styling (Leaflet override) ---------- */

.leaflet-popup-content-wrapper {
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
}
.leaflet-popup-tip { background: var(--color-surface); border: 1px solid var(--color-border); }
.leaflet-popup-content { margin: var(--space-3) var(--space-4); font-family: var(--font-body); }
.leaflet-popup-close-button { color: var(--color-text-muted) !important; }

.popup-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  margin-bottom: var(--space-1);
  color: var(--color-primary);
}
.popup-desc {
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}
.popup-sources {
  font-size: 11px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-2);
}
.popup-sources a { color: var(--color-primary); text-decoration: none; }
.popup-sources a:hover { text-decoration: underline; }

.city-marker {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--color-surface);
  box-shadow: 0 0 0 1px oklch(0 0 0 / 0.25);
}
.capital-marker {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--color-surface);
  box-shadow: 0 0 0 1px oklch(0 0 0 / 0.3), var(--shadow-sm);
}

/* ---------- Mobile era select fallback ---------- */

@media (max-width: 640px) {
  .era-select-wrap { min-width: 0; flex: 1; max-width: 100%; }
  .era-select { min-width: 0; width: 100%; font-size: var(--text-sm); max-width: 100%; }
  .brand-text .subtitle { display: none; }
  .brand-text .title { font-size: var(--text-base); white-space: nowrap; }
  .brand svg { width: 28px; height: 28px; flex-shrink: 0; }
  .site-header {
    padding: var(--space-3) var(--space-3);
    gap: var(--space-2);
    position: relative;
    flex-wrap: nowrap;
  }
  .brand { min-width: 0; flex-shrink: 1; overflow: hidden; }
  .brand-text { min-width: 0; overflow: hidden; }
  .brand-text .title { overflow: hidden; text-overflow: ellipsis; }
  .header-controls { flex-shrink: 0; }
  .era-bar {
    padding: var(--space-3) var(--space-3);
  }
  .era-bar > .era-nav-btn { flex-shrink: 0; }
}
@media (max-width: 480px) {
  /* Very narrow: hide 'World' word to keep title from truncating */
  .brand-text .title .brand-word-2 { display: none; }
  .brand-text .title { font-size: var(--text-sm); }
  .brand svg { width: 24px; height: 24px; }
  .site-header { padding: var(--space-2) var(--space-3); }
}

/* ---------- About modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0.15 0.02 60 / 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  padding: var(--space-6);
}

.modal-card h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  margin-bottom: var(--space-3);
  color: var(--color-primary);
}

.modal-card p {
  font-size: var(--text-sm);
  line-height: 1.6;
  margin-bottom: var(--space-3);
  color: var(--color-text);
}

.modal-card ul {
  font-size: var(--text-sm);
  line-height: 1.6;
  margin: 0 0 var(--space-3);
  padding-left: var(--space-5);
  color: var(--color-text);
}

.modal-close-row {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-4);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-interactive);
}
.btn-primary:hover { background: var(--color-primary-hover); }

/* ---------- Attribution footer strip ---------- */

.leaflet-control-attribution {
  max-width: min(60vw, 320px);
  font-size: 10px;
  line-height: 1.4;
  text-align: right;
}

/* ---------- Skeleton loader ---------- */

@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--map-sea);
}
.map-loading .spinner-text {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  background: linear-gradient(90deg, var(--color-surface-offset) 25%, var(--color-surface) 50%, var(--color-surface-offset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
}

@media (prefers-reduced-motion: reduce) {
  .map-loading .spinner-text { animation: none; }
}

/* ============================================================
   NEW FEATURES: battles, figures, compare mode, timeline scrubber
   ============================================================ */

/* ---------- Panel sections ---------- */
.panel-section {
  margin-bottom: var(--space-4);
}
.panel-section:last-child {
  margin-bottom: 0;
}

/* ---------- Battle list ---------- */
.battle-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.battle-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: 4px var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
  color: var(--color-text);
  font-family: var(--font-body);
  transition: var(--transition-interactive);
}
.battle-item:hover {
  background: var(--color-surface-offset);
}
.battle-item .battle-year {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-warning);
  font-size: var(--text-xs);
  flex-shrink: 0;
  min-width: 3.5em;
}
.battle-item .battle-name {
  font-size: var(--text-xs);
  line-height: 1.4;
}

/* ---------- Figure list ---------- */
.figure-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.figure-item {
  display: block;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-surface-offset);
  border: 1px solid transparent;
  transition: var(--transition-interactive);
  text-decoration: none;
  color: inherit;
}
.figure-item:hover {
  background: var(--color-surface-offset-2);
  border-color: var(--color-border);
}
.figure-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-primary);
  line-height: 1.2;
}
.figure-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
  font-style: italic;
}
.figure-blurb {
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--color-text);
  margin-top: 3px;
}

/* ---------- Battle map marker (crossed swords) ---------- */
.battle-icon {
  background: transparent !important;
  border: none !important;
}
.battle-icon-inner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1.5px solid var(--color-warning);
  box-shadow: 0 1px 4px oklch(0 0 0 / 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-warning);
  transition: transform 0.15s ease;
}
.battle-icon-inner svg {
  width: 12px;
  height: 12px;
  stroke-width: 2.2;
}
.battle-icon:hover .battle-icon-inner {
  transform: scale(1.15);
  background: var(--color-warning);
  color: var(--color-surface);
}

/* ---------- Compare button + mode ---------- */
.compare-btn[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}
.compare-btn[aria-pressed="true"] svg { color: var(--color-text-inverse); }

.compare-btn { flex-shrink: 0; }
.compare-btn span {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Right-side "B" era layers get clipped by JS-set --compare-x */
.leaflet-pane.compare-b-pane {
  clip-path: inset(0 0 0 var(--compare-x, 50%));
  transition: none;
}

.compare-select {
  width: 100%;
  padding: 6px var(--space-2);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Divider bar */
.compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  z-index: 480;
  pointer-events: none;
}
.compare-divider[hidden] { display: none; }
.compare-divider-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--color-primary);
  opacity: 0.85;
  box-shadow: 0 0 12px color-mix(in oklab, var(--color-primary) 60%, transparent);
}
.compare-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
  color: var(--color-primary);
  cursor: ew-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  box-shadow: var(--shadow-md);
  z-index: 5;
  touch-action: none;
}
.compare-handle:hover {
  background: var(--color-primary);
  color: var(--color-surface);
}
.compare-handle svg { width: 20px; height: 20px; }

.compare-label {
  position: absolute;
  top: var(--space-3);
  padding: 4px var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  white-space: nowrap;
}
.compare-label-left {
  right: calc(100% + var(--space-3));
}
.compare-label-right {
  left: calc(100% + var(--space-3));
}

/* Dim the era-panel a bit so the map dominates when comparing */
body.is-comparing .era-panel {
  opacity: 0.94;
}

/* ---------- Timeline scrubber ---------- */
.timeline-scrubber {
  position: absolute;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 4 * var(--space-4)));
  z-index: 490;
  background: color-mix(in oklab, var(--color-surface) 92%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 10px var(--space-4) 6px;
  box-shadow: var(--shadow-md);
}
.timeline-track {
  position: relative;
  height: 20px;
  cursor: pointer;
}
.timeline-line {
  position: absolute;
  top: 9px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-divider);
  border-radius: 1px;
}
.timeline-dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.timeline-dot {
  position: absolute;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  transform: translateX(-50%);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.timeline-dot:hover {
  transform: translateX(-50%) scale(1.35);
  border-color: var(--color-primary);
}
.timeline-dot.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  transform: translateX(-50%) scale(1.25);
}
.timeline-dot .timeline-dot-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  padding: 3px 8px;
  background: var(--color-text);
  color: var(--color-text-inverse);
  font-family: var(--font-display);
  font-size: 11px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.timeline-dot:hover .timeline-dot-tooltip {
  opacity: 1;
}
.timeline-marker {
  position: absolute;
  top: -2px;
  width: 3px;
  height: 24px;
  background: var(--color-primary);
  border-radius: 2px;
  transform: translateX(-50%);
  transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  box-shadow: 0 0 8px color-mix(in oklab, var(--color-primary) 50%, transparent);
}
.timeline-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--color-text-faint);
  letter-spacing: 0.03em;
}

/* Mobile: hide scrubber & compare labels */
@media (max-width: 640px) {
  .timeline-scrubber {
    display: none;
  }
  .compare-label {
    top: var(--space-2);
    padding: 2px var(--space-2);
    font-size: 10px;
  }
  .compare-label-left { right: calc(100% + 6px); }
  .compare-label-right { left: calc(100% + 6px); }
  .compare-btn span { display: none; }
}

/* ---------- Dark-mode adjustments for new elements ---------- */
[data-theme='dark'] .battle-icon-inner {
  background: var(--color-surface);
  border-color: var(--color-warning);
}
[data-theme='dark'] .compare-handle {
  background: var(--color-surface);
}
[data-theme='dark'] .timeline-scrubber {
  background: color-mix(in oklab, var(--color-surface) 92%, transparent);
}

/* ---------- Temple (capital) marker ---------- */
.temple-icon {
  background: transparent !important;
  border: none !important;
}
.temple-icon-inner {
  position: relative;
  width: 28px;
  height: 24px;
  transform-origin: center bottom;
  cursor: pointer;
  filter: drop-shadow(0 1px 0 rgba(255, 250, 240, 0.75)) drop-shadow(0 1px 2px rgba(60, 40, 15, 0.4));
  transition: transform var(--transition-interactive, 150ms ease);
}
.temple-icon-inner svg {
  width: 28px;
  height: 24px;
  display: block;
}
.temple-icon:hover .temple-icon-inner {
  transform: scale(1.15);
}
.temple-label {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display, Georgia), serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #3a2712;
  white-space: nowrap;
  text-shadow:
    0 0 3px rgba(255, 250, 240, 1),
    1px 0 2px rgba(255, 250, 240, 0.9),
    -1px 0 2px rgba(255, 250, 240, 0.9),
    0 1px 2px rgba(255, 250, 240, 0.9),
    0 -1px 2px rgba(255, 250, 240, 0.9);
  pointer-events: none;
}
[data-theme='dark'] .temple-label {
  color: #f4e9d0;
  text-shadow:
    0 0 3px rgba(20, 15, 5, 1),
    1px 0 2px rgba(20, 15, 5, 0.9),
    -1px 0 2px rgba(20, 15, 5, 0.9),
    0 1px 2px rgba(20, 15, 5, 0.9),
    0 -1px 2px rgba(20, 15, 5, 0.9);
}
[data-theme='dark'] .temple-icon-inner {
  filter: drop-shadow(0 1px 0 rgba(20, 15, 5, 0.9)) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
}

/* ---------- Region + sea labels ---------- */
.region-label-wrap,
.sea-label-wrap {
  background: transparent !important;
  border: none !important;
  overflow: visible;
}
.region-label,
.sea-label {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: center center;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  font-family: var(--font-display, Georgia), serif;
}
.region-label {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #2d1e0a;
  text-shadow:
    0 0 3px rgba(255, 250, 240, 0.95),
    1px 1px 2px rgba(255, 250, 240, 0.9),
    -1px -1px 2px rgba(255, 250, 240, 0.9),
    1px -1px 2px rgba(255, 250, 240, 0.9),
    -1px 1px 2px rgba(255, 250, 240, 0.9);
  opacity: 0.85;
}
.region-label-sm { font-size: 10px; letter-spacing: 0.1em; opacity: 0.75; }
.region-label-md { font-size: 12px; }
.region-label-lg { font-size: 14px; }

.sea-label {
  font-style: italic;
  font-weight: 500;
  color: #1a3a55;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-shadow:
    0 0 3px rgba(200, 225, 240, 0.75),
    1px 1px 2px rgba(200, 225, 240, 0.7);
  opacity: 0.9;
}
.sea-label-sm { font-size: 11px; }
.sea-label-md { font-size: 14px; }
.sea-label-lg { font-size: 17px; letter-spacing: 0.24em; }

[data-theme='dark'] .region-label {
  color: #f4e0b8;
  text-shadow:
    0 0 3px rgba(20, 15, 5, 0.95),
    1px 1px 2px rgba(20, 15, 5, 0.9),
    -1px -1px 2px rgba(20, 15, 5, 0.9);
}
[data-theme='dark'] .sea-label {
  color: #8ec4e6;
  text-shadow:
    0 0 3px rgba(5, 15, 25, 0.95),
    1px 1px 2px rgba(5, 15, 25, 0.9);
}

/* Zoom-responsive label density */
.leaflet-container.zoom-far .temple-label { display: none; }
.leaflet-container.zoom-far .region-label-sm { display: none; }
.leaflet-container.zoom-far .region-label { font-size: 11px; }
.leaflet-container.zoom-mid .region-label-sm { font-size: 9px; opacity: 0.65; }

/* At zoom <=4 (whole-empire views), hide fine-grained region labels; show only
   subcontinent-scale ones tagged tier="wide" */
.leaflet-container.zoom-veryfar .region-label { display: none; }
.leaflet-container.zoom-veryfar .region-label.region-tier-wide {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  opacity: 0.75;
}
.leaflet-container.zoom-veryfar .sea-label-md,
.leaflet-container.zoom-veryfar .sea-label-sm { display: none; }

/* ================================================================
   NEW: Filter bar, era bands, play button, journey UI, arrow layer
   ================================================================ */

/* ---------- Filter chips (above the map) ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: color-mix(in oklab, var(--color-surface-2) 96%, transparent);
  border-bottom: 1px solid var(--color-divider);
  flex-wrap: wrap;
}
.filter-bar-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-right: var(--space-1);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text-muted);
  opacity: 0.55;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}
.filter-chip svg {
  width: 14px;
  height: 14px;
}
.filter-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-text);
  opacity: 0.85;
}
.filter-chip.is-active {
  background: var(--color-primary-highlight);
  color: var(--color-primary-active);
  border-color: color-mix(in oklab, var(--color-primary) 60%, var(--color-border));
  opacity: 1;
}
[data-theme='dark'] .filter-chip.is-active {
  color: var(--color-primary-hover);
}

/* Hide the marker classes when filtered off */
.leaflet-container.filter-hide-capitals .temple-icon,
.leaflet-container.filter-hide-cities .city-marker,
.leaflet-container.filter-hide-battles .battle-icon,
.leaflet-container.filter-hide-routes .route-path,
.leaflet-container.filter-hide-labels .region-label,
.leaflet-container.filter-hide-labels .sea-label-md,
.leaflet-container.filter-hide-labels .sea-label-sm {
  display: none !important;
}

/* ---------- Timeline: era-period bands + play button ---------- */
.timeline-scrubber {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
}
.timeline-play {
  grid-column: 1;
  grid-row: 1 / span 1;
  align-self: center;
}
.timeline-track {
  grid-column: 2;
  grid-row: 1;
}
.timeline-ends {
  grid-column: 2;
  grid-row: 2;
  margin-top: 0;
}
.timeline-band-legend {
  grid-column: 1 / span 2;
  grid-row: 3;
  margin-top: 2px;
}
.timeline-play {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--color-primary);
  background: var(--color-surface);
  color: var(--color-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.timeline-play svg { width: 14px; height: 14px; }
.timeline-play .tp-pause { display: none; }
.timeline-play[aria-pressed="true"] .tp-play { display: none; }
.timeline-play[aria-pressed="true"] .tp-pause { display: inline-block; }
.timeline-play:hover {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  transform: scale(1.06);
}
.timeline-play[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.timeline-bands {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  height: 12px;
  pointer-events: none;
  border-radius: 6px;
  overflow: hidden;
  opacity: 0.35;
}
.timeline-band {
  position: absolute;
  top: 0;
  bottom: 0;
}
/* Archaic (750–500 BCE) — sepia / bronze */
.timeline-band.band-archaic     { background: linear-gradient(180deg, #c99358 0%, #a5773f 100%); }
/* Classical (500–323 BCE) — Greek blue */
.timeline-band.band-classical   { background: linear-gradient(180deg, #3f7ba5 0%, #2a5d80 100%); }
/* Hellenistic (323–146 BCE) — royal purple */
.timeline-band.band-hellenistic { background: linear-gradient(180deg, #7d5aa5 0%, #55407b 100%); }
/* Roman conquest tip (146 BCE) — Roman red */
.timeline-band.band-roman       { background: linear-gradient(180deg, #a94040 0%, #7c2c2c 100%); }

.timeline-line {
  z-index: 1;
}
.timeline-dots, .timeline-marker {
  z-index: 2;
}

/* Timeline band legend below the bar */
.timeline-band-legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  text-transform: uppercase;
}
.timeline-band-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.timeline-band-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* ---------- Guided journeys — list + overlay ---------- */
.journey-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.journey-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.journey-item:hover {
  border-color: var(--color-primary);
  transform: translateY(-1px);
}
.journey-swatch {
  flex: none;
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  margin-top: 2px;
}
.journey-item-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.journey-item-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text);
  line-height: 1.25;
}
.journey-item-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
  line-height: 1.3;
}
.journey-item-arrow {
  flex: none;
  margin-left: auto;
  color: var(--color-text-faint);
  align-self: center;
}
.journey-item-arrow svg { width: 14px; height: 14px; }

.journey-overlay {
  position: absolute;
  right: var(--space-4);
  bottom: calc(var(--space-4) + 62px);
  z-index: 495;
  width: min(360px, calc(100vw - 2 * var(--space-4)));
  pointer-events: auto;
}
.journey-overlay[hidden] { display: none; }
.journey-card {
  background: color-mix(in oklab, var(--color-surface) 96%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-3) 10px;
  box-shadow: var(--shadow-lg);
}
.journey-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: 6px;
}
.journey-card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text);
  line-height: 1.25;
}
.journey-card-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 1px;
  letter-spacing: 0.02em;
}
.journey-close {
  flex: none;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}
.journey-close:hover {
  color: var(--color-text);
  background: var(--color-surface-offset);
}
.journey-close svg { width: 16px; height: 16px; display: block; }

.journey-step-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
  margin-bottom: 4px;
}
.journey-step-year {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-warning);
  font-weight: 600;
}
.journey-step-place {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}
.journey-step-text {
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text);
  margin: 0 0 10px;
}

.journey-progress {
  height: 3px;
  background: var(--color-divider);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.journey-progress-bar {
  height: 100%;
  background: var(--color-primary);
  transition: width 0.35s ease;
}

.journey-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.journey-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.journey-btn svg { width: 14px; height: 14px; }
.journey-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.journey-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.journey-step-counter {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
}

/* ---------- Route arrow markers (SVG lines) ---------- */
.route-path {
  pointer-events: none;
}
.route-arrowhead {
  background: transparent !important;
  border: none !important;
  pointer-events: none;
}
.route-arrowhead-inner {
  /* transform-origin is set inline to match iconAnchor so rotation pivots
     around the arrow tip and keeps it locked to the endpoint. */
  color: currentColor;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15));
}
/* Trade routes: warm ochre dashed */
.route-trade {
  stroke: #a9752c;
  stroke-width: 2.2;
  fill: none;
  stroke-dasharray: 6 5;
  stroke-linecap: round;
  opacity: 0.85;
}
[data-theme='dark'] .route-trade { stroke: #d09a4a; }

/* Colonization routes: deep teal solid */
.route-colony {
  stroke: #1f7079;
  stroke-width: 2.4;
  fill: none;
  stroke-linecap: round;
  opacity: 0.9;
}
[data-theme='dark'] .route-colony { stroke: #6ab3bb; }

/* Military campaigns: crimson solid */
.route-campaign {
  stroke: #9a3030;
  stroke-width: 2.6;
  fill: none;
  stroke-linecap: round;
  opacity: 0.9;
}
[data-theme='dark'] .route-campaign { stroke: #d15b5b; }

/* Journey path highlight */
.journey-path {
  stroke: currentColor;
  stroke-width: 3;
  fill: none;
  opacity: 0.85;
  stroke-linecap: round;
  stroke-dasharray: 8 4;
}
.journey-waypoint {
  background: transparent !important;
  border: none !important;
}
.journey-waypoint-inner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: currentColor;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.journey-waypoint-inner.is-current {
  background: currentColor;
  color: var(--color-surface);
  transform: scale(1.15);
}

/* Route label bubble */
.route-label {
  background: transparent !important;
  border: none !important;
  pointer-events: none;
}
.route-label-inner {
  display: inline-block;
  padding: 2px 6px;
  background: color-mix(in oklab, var(--color-surface) 90%, transparent);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Mobile fine-tuning */
@media (max-width: 640px) {
  .filter-bar { padding: 6px var(--space-3); gap: 4px; overflow-x: auto; flex-wrap: nowrap; }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-bar-label { display: none; }
  .filter-chip { padding: 4px 8px; font-size: 11px; }
  .journey-overlay {
    right: var(--space-2);
    left: var(--space-2);
    bottom: var(--space-2);
    width: auto;
  }
}

/* Below the mobile-hide breakpoint keep the play button available with the scrubber */
@media (max-width: 640px) {
  .timeline-band-legend { display: none; }
}

/* ==================== Upgrade 6/7/8: attribute chips + geographies + dossiers ==================== */

/* Filter-bar sub-labels & dividers (second row of chips) */
.filter-bar-label-sub {
  margin-left: var(--space-2);
  color: color-mix(in oklab, var(--color-text-muted) 80%, var(--color-primary) 20%);
}
.filter-bar-divider {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: color-mix(in oklab, var(--color-divider) 65%, transparent);
  margin: 0 4px;
}

/* Attribute chips: use an amber accent so the second row is visually distinct
   from the primary layer chips (which use the teal --color-primary). */
.filter-chip.attr-chip.is-active {
  background: color-mix(in oklab, #c4a86a 22%, transparent);
  color: color-mix(in oklab, #7a5a20 90%, var(--color-text) 10%);
  border-color: #c4a86a;
}
[data-theme='dark'] .filter-chip.attr-chip.is-active {
  background: color-mix(in oklab, #c4a86a 30%, transparent);
  color: #f4e0a5;
}
.filter-chip.attr-chip:hover {
  border-color: #c4a86a;
}

/* Geography chips: distinct hue per layer type */
.filter-chip.geo-chip[data-geo="oracles"].is-active {
  background: color-mix(in oklab, #c48f2a 22%, transparent);
  color: color-mix(in oklab, #6d4a10 90%, var(--color-text) 10%);
  border-color: #c48f2a;
}
[data-theme='dark'] .filter-chip.geo-chip[data-geo="oracles"].is-active { color: #ecc98a; }
.filter-chip.geo-chip[data-geo="schools"].is-active {
  background: color-mix(in oklab, #4b6c8a 22%, transparent);
  color: color-mix(in oklab, #24405c 90%, var(--color-text) 10%);
  border-color: #4b6c8a;
}
[data-theme='dark'] .filter-chip.geo-chip[data-geo="schools"].is-active { color: #a8c4e0; }
.filter-chip.geo-chip[data-geo="festivals"].is-active {
  background: color-mix(in oklab, #7f4a8a 22%, transparent);
  color: color-mix(in oklab, #55265f 90%, var(--color-text) 10%);
  border-color: #7f4a8a;
}
[data-theme='dark'] .filter-chip.geo-chip[data-geo="festivals"].is-active { color: #d5b0e0; }

/* Geography markers on the map */
.geo-marker {
  background: transparent;
  border: none;
}
.geo-marker-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 250, 236, 0.95);
  border: 1.5px solid currentColor;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
[data-theme='dark'] .geo-marker-inner {
  background: rgba(28, 26, 22, 0.95);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.geo-marker-inner svg {
  width: 16px;
  height: 16px;
}
.geo-marker:hover .geo-marker-inner {
  transform: scale(1.08);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22);
}

/* Attribute-ring tooltip */
.attr-ring-tooltip {
  background: rgba(255, 250, 236, 0.96);
  border: 1px solid #c4a86a;
  color: #6d4a10;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.04em;
}
[data-theme='dark'] .attr-ring-tooltip {
  background: rgba(28, 26, 22, 0.96);
  border-color: #c4a86a;
  color: #f4e0a5;
}
.attr-ring-tooltip::before { display: none; }

/* Figure list: mark dossier-enabled items */
.figure-item-has-dossier {
  border-left: 2.5px solid #7a5aa5;
  padding-left: calc(var(--space-3) - 2.5px);
}
.figure-item-has-dossier:hover {
  border-left-color: #a37bd0;
}
.figure-dossier-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  padding: 1px 6px 1px 7px;
  background: color-mix(in oklab, #7a5aa5 18%, transparent);
  color: #7a5aa5;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 1px;
}
[data-theme='dark'] .figure-dossier-badge {
  background: color-mix(in oklab, #a37bd0 20%, transparent);
  color: #d3bff0;
}
.figure-dossier-badge svg { width: 10px; height: 10px; }

/* Dossier itinerary stops (numbered markers) */
.dossier-stop {
  background: transparent;
  border: none;
}
.dossier-stop > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease;
}
.dossier-stop-active > span {
  transform: scale(1.25);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.75), 0 3px 6px rgba(0, 0, 0, 0.4);
}
[data-theme='dark'] .dossier-stop > span {
  border-color: #23201b;
}
[data-theme='dark'] .dossier-stop-active > span {
  box-shadow: 0 0 0 3px rgba(35, 32, 27, 0.75), 0 3px 6px rgba(0, 0, 0, 0.55);
}
.dossier-stop-tooltip {
  background: rgba(255, 250, 236, 0.96);
  border: 1px solid #7a5aa5;
  color: #4a2f70;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 11px;
}
[data-theme='dark'] .dossier-stop-tooltip {
  background: rgba(28, 26, 22, 0.96);
  color: #d3bff0;
}
.dossier-stop-tooltip::before { display: none; }

/* Dossier overlay reuses journey-overlay layout; add a purple accent stripe on the card */
.dossier-overlay .journey-card {
  border-top: 3px solid #7a5aa5;
}
/* Battle-dossier variant gets a red accent to match battle-marker convention */
.dossier-overlay--battle .journey-card {
  border-top-color: #b04a3a;
}

/* ---------- Search palette (Cmd/Ctrl-K) ---------- */

.palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 16px;
  background: rgba(20, 16, 8, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: paletteFadeIn 0.14s ease-out;
}
[data-theme="dark"] .palette-overlay { background: rgba(0, 0, 0, 0.55); }
.palette-overlay[hidden] { display: none; }

@keyframes paletteFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.palette-card {
  width: 100%;
  max-width: 620px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 20px 60px -20px rgba(20, 16, 8, 0.55), 0 4px 12px -6px rgba(20, 16, 8, 0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 78vh;
  animation: paletteSlideIn 0.16s cubic-bezier(0.2, 0.9, 0.4, 1);
}
@keyframes paletteSlideIn {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.palette-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.palette-search-icon {
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  flex: 0 0 18px;
}
.palette-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  padding: 4px 0;
}
.palette-input::placeholder { color: var(--color-text-faint); }

.palette-esc {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 2px 7px;
  letter-spacing: 0.4px;
}

.palette-results {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 0;
  min-height: 60px;
}

.palette-group {
  padding: 8px 16px 4px;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 1.4px;
}

.palette-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 9px 16px;
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  text-align: left;
  cursor: pointer;
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-sm);
  transition: background 0.08s ease;
}
.palette-item:hover,
.palette-item.is-active {
  background: var(--color-surface-offset);
  border-left-color: var(--color-primary);
  outline: 0;
}
.palette-item-icon {
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  flex: 0 0 18px;
}
.palette-item.is-active .palette-item-icon { color: var(--color-primary); }

.palette-item-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.palette-item-title {
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.palette-item-sub {
  font-size: 11.5px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.palette-item-title mark,
.palette-item-sub mark {
  background: transparent;
  color: var(--color-primary);
  font-weight: 600;
}

.palette-item-meta {
  font-size: 10.5px;
  color: var(--color-text-faint);
  font-family: var(--font-display);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
}
.palette-item-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #7a5aa5;
  background: rgba(122, 90, 165, 0.12);
  border-radius: 3px;
  vertical-align: 1px;
}
[data-theme="dark"] .palette-item-badge { color: #b598de; background: rgba(122, 90, 165, 0.22); }

.palette-empty {
  padding: 26px 20px 30px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.palette-empty strong { color: var(--color-text); font-family: var(--font-display); font-weight: 600; }
.palette-empty-hint { display: block; margin-top: 4px; font-size: 12px; color: var(--color-text-faint); }

.palette-footer {
  display: flex;
  gap: 18px;
  padding: 8px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 11px;
  color: var(--color-text-muted);
}
.palette-footer kbd {
  display: inline-block;
  min-width: 15px;
  padding: 0 4px;
  margin-right: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  text-align: center;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 3px;
}

@media (max-width: 640px) {
  .palette-overlay { padding: 6vh 8px 8px; }
  .palette-card { max-height: 88vh; }
  .kbd-hint { display: none; }
  .palette-footer { gap: 12px; font-size: 10.5px; }
  .palette-footer span:last-child { display: none; }
}

/* ---------- Legend modal ---------- */
.legend-modal-card {
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}
.legend-lede {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-top: 0;
  margin-bottom: var(--space-4);
}
.legend-section {
  margin-bottom: var(--space-5);
}
.legend-section:last-of-type {
  margin-bottom: var(--space-3);
}
.legend-section > h3 {
  font-family: var(--font-display, var(--font-body));
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3) 0;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}
.legend-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}
@media (min-width: 520px) {
  .legend-grid { grid-template-columns: 1fr 1fr; }
}
.legend-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: var(--space-3);
  align-items: center;
}
.legend-row > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.legend-row strong {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}
.legend-row span {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.4;
}
.legend-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
}
.legend-glyph svg {
  width: 22px;
  height: 22px;
}
.legend-glyph-temple {
  color: #7a5d34;
}
.legend-glyph-temple svg {
  width: 26px;
  height: 22px;
  fill: currentColor;
}
.legend-glyph-battle {
  color: #7a2a2a;
}
.legend-glyph-route svg {
  width: 36px;
  height: 12px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4b6c8a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.legend-ring {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #c4a86a;
  background: rgba(247, 236, 201, 0.35);
}
/* Powers grid inside legend */
.legend-power-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: var(--space-3);
  align-items: center;
}
.legend-power-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
}
.legend-power-swatch::before {
  content: '';
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--power-color, #4b6c8a);
}
.legend-power-row strong {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}
.legend-power-row .status-tag {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  vertical-align: 1px;
}
.legend-power-row span.legend-power-note {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ---------- Toast (copy feedback) ---------- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: var(--space-3) var(--space-4);
  background: var(--color-text);
  color: var(--color-surface);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 1300;
}
.toast[hidden] {
  display: block !important; /* keep it in the DOM to enable transition */
  opacity: 0;
  visibility: hidden;
}
.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* ========================================================
   Header overflow menu (mobile)
   ======================================================== */
.hdr-menu {
  position: absolute;
  top: calc(100% - var(--space-2));
  right: var(--space-3);
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hdr-menu[hidden] { display: none; }
.hdr-menu button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  width: 100%;
  transition: background 120ms ease;
}
.hdr-menu button:hover,
.hdr-menu button:focus-visible {
  background: var(--color-surface-offset);
  outline: none;
}
.hdr-menu button svg {
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* ========================================================
   First-run coach mark (Compare hint)
   ======================================================== */
.coach-mark {
  position: fixed;
  top: 72px;
  right: 20px;
  max-width: 280px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 28px oklch(0 0 0 / 0.22);
  z-index: 900;
  animation: coachSlide 320ms cubic-bezier(0.16, 1, 0.3, 1);
}
.coach-mark[hidden] { display: none; }
@keyframes coachSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.coach-mark-inner {
  padding: var(--space-4) var(--space-4) var(--space-3);
}
.coach-mark-inner strong {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.coach-mark-inner p {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--color-text);
}
.coach-mark-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
.coach-mark-dismiss {
  background: var(--color-primary);
  color: var(--color-surface);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 120ms ease;
}
.coach-mark-dismiss:hover { background: var(--color-primary-hover); }
.coach-mark-arrow {
  position: absolute;
  top: -6px;
  right: 40px;
  width: 12px;
  height: 12px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-primary);
  border-left: 1px solid var(--color-primary);
  transform: rotate(45deg);
}
/* On very narrow screens, coach mark anchors above the overflow button */
@media (max-width: 639px) {
  .coach-mark {
    top: 60px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
  .coach-mark-arrow {
    right: 20px;
  }
}

/* ========================================================
   Itineraries grid modal
   ======================================================== */
.itineraries-modal-card {
  max-width: 720px;
}
.itineraries-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}
.itinerary-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  font-family: var(--font-body);
  color: var(--color-text);
}
.itinerary-card:hover,
.itinerary-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  outline: none;
}
.itinerary-card-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-primary);
  line-height: 1.2;
}
.itinerary-card-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.itinerary-card-blurb {
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--color-text);
  margin-top: 4px;
}
@media (max-width: 480px) {
  .itineraries-grid {
    grid-template-columns: 1fr;
  }
}

/* ========================================================
   Enhance existing figure dossier badge — arrow affordance
   ======================================================== */
.figure-item-has-dossier .figure-dossier-badge::after {
  content: ' →';
  margin-left: 2px;
  letter-spacing: 0;
}
.figure-item-has-dossier {
  cursor: pointer;
}

/* ========================================================
   Dossier positioning: bottom sheet on mobile
   ======================================================== */
@media (max-width: 640px) {
  .dossier-card {
    left: var(--space-2) !important;
    right: var(--space-2) !important;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    max-height: 60vh;
  }
  /* Timeline scrubber stays hidden on mobile (defined earlier) */
}

/* ========================================================
   Dark-mode polish
   ======================================================== */
[data-theme='dark'] .icon-btn {
  background: color-mix(in oklab, var(--color-surface-2) 100%, transparent);
  border-color: color-mix(in oklab, var(--color-border) 100%, var(--color-primary) 15%);
}
[data-theme='dark'] .icon-btn:hover {
  background: var(--color-surface-offset-2);
  border-color: var(--color-primary);
}
[data-theme='dark'] .search-btn {
  color: var(--color-text);
}
[data-theme='dark'] .kbd-hint {
  background: var(--color-surface-offset);
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

/* Era panel headings in dark: swap dark-green for lighter accent */
[data-theme='dark'] .era-panel h2,
[data-theme='dark'] .era-panel-title,
[data-theme='dark'] .panel-h3,
[data-theme='dark'] .modal-card h2,
[data-theme='dark'] .modal-card h3 {
  color: var(--color-primary);
}
[data-theme='dark'] .figure-name {
  color: var(--color-primary);
}

/* Legend glyphs — brighten dashed trade line and other icons in dark */
[data-theme='dark'] .legend-glyph-trade svg,
[data-theme='dark'] .legend-glyph-campaign svg {
  filter: brightness(1.4) saturate(0.9);
}
[data-theme='dark'] .legend-glyph {
  filter: brightness(1.25);
}
[data-theme='dark'] .legend-lede {
  color: var(--color-text-muted);
}
[data-theme='dark'] .legend-row strong {
  color: var(--color-text);
}
[data-theme='dark'] .legend-row span {
  color: var(--color-text-muted);
}

/* Basemap dark tinting: shift toward parchment-on-navy */
[data-theme='dark'] .basemap-relief {
  filter: sepia(0.15) saturate(0.7) hue-rotate(180deg) brightness(0.48) contrast(1.15);
  mix-blend-mode: screen;
  opacity: 0.55;
}
[data-theme='dark'] .basemap-ocean {
  filter: brightness(0.32) saturate(0.6) hue-rotate(180deg);
  opacity: 0.85;
}

/* Toast/coach mark repositioning to avoid mobile scrubber overlap */
@media (max-width: 640px) {
  .toast {
    bottom: 88px;
  }
}

/* ========================================================
   Final mobile override: keep timeline scrubber hidden on narrow screens
   (must be after later .timeline-scrubber base rule to win)
   ======================================================== */
@media (max-width: 640px) {
  .timeline-scrubber { display: none !important; }
}
