/* ============ DESIGN TOKENS ============ */
:root {
  --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.0625rem);
  --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.375rem);
  --text-xl: clamp(1.375rem, 1.1rem + 1vw, 1.9rem);

  --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;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.9rem;
  --radius-xl: 1.25rem;
  --radius-full: 9999px;

  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);
  --font-display: 'Archivo', 'Arial Narrow', sans-serif;
  --font-body: 'Inter', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;
}

/* Ice-rink palette: cool slate/navy dark ice, blue-white primary accent, rink-red secondary */
:root,
[data-theme='light'] {
  --color-bg: #eef2f6;
  --color-surface: #ffffff;
  --color-surface-2: #f7f9fb;
  --color-surface-offset: #e4e9ef;
  --color-divider: #d7dee6;
  --color-border: #c6d0da;

  --color-text: #101823;
  --color-text-muted: #57657a;
  --color-text-faint: #93a1b2;
  --color-text-inverse: #f4f8fb;

  --color-primary: #0a6cbf;
  --color-primary-hover: #0857a0;
  --color-primary-active: #064478;
  --color-primary-highlight: #d3e6f7;
  --color-accent: #0a6cbf;
  --color-accent-soft: rgba(10, 108, 191, 0.12);
  --color-text-secondary: #3d4a5c;

  --color-rink-red: #c8253d;
  --color-rink-red-highlight: #f6d6da;
  --color-gold: #c8862a;
  --color-gold-highlight: #f1e2c4;
  --color-success: #2f8f5b;

  --shadow-sm: 0 1px 2px rgba(16, 24, 35, 0.08);
  --shadow-md: 0 6px 20px rgba(16, 24, 35, 0.12);
  --shadow-lg: 0 16px 40px rgba(16, 24, 35, 0.18);

  --map-tile-filter: none;
}

[data-theme='dark'] {
  --color-bg: #0a0f16;
  --color-surface: #111926;
  --color-surface-2: #16202e;
  --color-surface-offset: #1c2836;
  --color-divider: #263447;
  --color-border: #2d3d51;

  --color-text: #e6edf5;
  --color-text-muted: #90a1b5;
  --color-text-faint: #566a80;
  --color-text-inverse: #0a0f16;

  --color-primary: #4db3ff;
  --color-primary-hover: #79c6ff;
  --color-primary-active: #a3d9ff;
  --color-primary-highlight: #1a3550;
  --color-accent: #4db3ff;
  --color-accent-soft: rgba(77, 179, 255, 0.15);
  --color-text-secondary: #b7c3d1;

  --color-rink-red: #ff5d75;
  --color-rink-red-highlight: #3a1c25;
  --color-gold: #e8ab5a;
  --color-gold-highlight: #3a2e18;
  --color-success: #57c98a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);

  --map-tile-filter: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-bg: #0a0f16;
    --color-surface: #111926;
    --color-surface-2: #16202e;
    --color-surface-offset: #1c2836;
    --color-divider: #263447;
    --color-border: #2d3d51;
    --color-text: #e6edf5;
    --color-text-muted: #90a1b5;
    --color-text-faint: #566a80;
    --color-text-inverse: #0a0f16;
    --color-primary: #4db3ff;
    --color-primary-hover: #79c6ff;
    --color-primary-active: #a3d9ff;
    --color-primary-highlight: #1a3550;
    --color-rink-red: #ff5d75;
    --color-rink-red-highlight: #3a1c25;
    --color-gold: #e8ab5a;
    --color-gold-highlight: #3a2e18;
    --color-success: #57c98a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
    --map-tile-filter: none;
  }
}

/* ============ LAYOUT SHELL ============ */
html, body { height: 100%; overflow: hidden; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  position: relative;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); }
.logo { color: var(--color-primary); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); letter-spacing: -0.01em; }
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); }
.topbar-right { display: flex; align-items: center; gap: var(--space-2); }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  position: relative;
}
.icon-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.icon-btn svg { width: 19px; height: 19px; }
[data-tooltip] { position: relative; }

.app-shell {
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: 280px 1fr 340px;
}

.panel {
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}
.panel-left { border-right: 1px solid var(--color-divider); padding: var(--space-5) var(--space-4); gap: var(--space-5); }
.panel-right { border-left: 1px solid var(--color-divider); padding: var(--space-5); }

.panel-section { display: flex; flex-direction: column; gap: var(--space-2); }
.franchise-list-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.field-label { font-size: var(--text-xs); font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; }

/* ============ SEARCH ============ */
.search-box { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: var(--space-3); width: 16px; height: 16px; color: var(--color-text-faint); pointer-events: none; }
.search-box input {
  width: 100%;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-8);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.search-box input:focus { border-color: var(--color-primary); background: var(--color-surface); }

/* ============ CHIPS ============ */
.chip-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.chip:hover { border-color: var(--color-primary); color: var(--color-text); }
.chip.is-active { background: var(--color-primary); border-color: var(--color-primary); color: white; }

/* ============ FRANCHISE LIST ============ */
.franchise-list { overflow-y: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-1); }
.franchise-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  text-align: left;
  width: 100%;
  font-size: var(--text-sm);
}
.franchise-item:hover { background: var(--color-surface-offset); }
.franchise-item.is-selected { background: var(--color-primary-highlight); }
.franchise-swatch { width: 10px; height: 10px; border-radius: var(--radius-full); flex-shrink: 0; margin-top: 6px; }
.franchise-item-text { display: flex; flex-direction: column; overflow: hidden; flex: 1; min-width: 0; gap: 1px; }
.franchise-item-name { font-weight: 600; line-height: 1.25; overflow-wrap: break-word; }
.franchise-item-meta { font-size: var(--text-xs); color: var(--color-text-faint); overflow-wrap: break-word; line-height: 1.3; }
.franchise-item-badge {
  margin-left: auto;
  margin-top: 1px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge-active { background: var(--color-success); color: #06210f; }
.badge-defunct { background: var(--color-text-faint); color: var(--color-surface); }
.franchise-list-empty { padding: var(--space-6) var(--space-2); text-align: center; color: var(--color-text-faint); font-size: var(--text-sm); }

/* ============ MAP COLUMN ============ */
.map-column { display: flex; flex-direction: column; min-height: 0; position: relative; }

.map-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
  z-index: 10;
  flex-wrap: wrap;
}
.year-readout { display: flex; align-items: baseline; gap: var(--space-2); }
.year-readout-label { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.year-readout-value { font-family: var(--font-display); font-weight: 800; font-size: var(--text-xl); color: var(--color-primary); font-variant-numeric: tabular-nums; }
.map-toolbar-stats { font-size: var(--text-sm); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.map-toolbar-stats strong { color: var(--color-text); font-weight: 700; }
.map-toolbar-actions { display: flex; gap: var(--space-2); margin-left: auto; }

.text-btn {
  display: flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-sm); font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.text-btn:hover { color: var(--color-text); border-color: var(--color-primary); }
.text-btn svg { width: 15px; height: 15px; }
.text-btn.is-playing { color: var(--color-primary); border-color: var(--color-primary); background: var(--color-primary-highlight); }

#map { flex: 1; min-height: 0; background: var(--color-surface-2); }
.leaflet-container { background: var(--color-surface-2); font-family: var(--font-body); }
.leaflet-tile-pane { filter: var(--map-tile-filter); }

/* ============ TIMELINE DOCK ============ */
.timeline-dock {
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
  padding: var(--space-2) var(--space-6) var(--space-3);
  position: relative;
  z-index: 10;
}
.timeline-header { position: relative; height: 44px; margin-bottom: 2px; }
.timeline-eras { position: relative; height: 100%; }
.era-marker {
  position: absolute;
  top: 0;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-text-faint);
  transform: translateX(-50%);
  white-space: nowrap;
  cursor: default;
}
.era-marker-row2 { top: 14px; }
.era-marker-row3 { top: 28px; }

.year-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: var(--radius-full);
  background: linear-gradient(to right, var(--color-primary) 0%, var(--color-primary) var(--slider-pct, 100%), var(--color-surface-offset) var(--slider-pct, 100%), var(--color-surface-offset) 100%);
  cursor: pointer;
}
.year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-surface);
  box-shadow: var(--shadow-md);
  cursor: pointer;
}
.year-slider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-surface);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  border: none;
}
.year-slider::-moz-range-track { height: 6px; border-radius: var(--radius-full); background: var(--color-surface-offset); }

.timeline-ticks { position: relative; height: 14px; margin-top: 2px; }
.tick-label {
  position: absolute;
  font-size: 0.65rem;
  color: var(--color-text-faint);
  transform: translateX(-50%);
  font-variant-numeric: tabular-nums;
}

/* ============ DETAIL PANEL ============ */
.detail-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding: var(--space-10) var(--space-4); color: var(--color-text-muted); margin: auto; }
.detail-empty-icon { width: 36px; height: 36px; color: var(--color-text-faint); }
.detail-empty p { font-size: var(--text-sm); }

.detail-content { display: flex; flex-direction: column; gap: var(--space-5); }
.detail-content[hidden], .detail-empty[hidden] { display: none; }

.detail-head { display: flex; flex-direction: column; gap: var(--space-1); }
.detail-back {
  display: flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-xs); font-weight: 600; color: var(--color-text-muted);
  margin-bottom: var(--space-2);
  align-self: flex-start;
}
.detail-back:hover { color: var(--color-primary); }
.detail-back svg { width: 13px; height: 13px; }

.detail-title-row { display: flex; align-items: center; gap: var(--space-2); }
.detail-swatch { width: 14px; height: 14px; border-radius: var(--radius-full); flex-shrink: 0; }
.detail-title { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); letter-spacing: -0.01em; }
.detail-status { font-size: var(--text-xs); font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-years { font-size: var(--text-sm); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }

/* Genealogy tree */
.genealogy-tree { display: flex; flex-direction: column; }
.genealogy-node {
  position: relative;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
  border-left: 2px solid var(--color-border);
  cursor: pointer;
  border-radius: 0;
}
.genealogy-node:last-child { border-left-color: transparent; }
.genealogy-node::before {
  content: '';
  position: absolute;
  left: -6px;
  top: var(--space-4);
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
}
.genealogy-node.is-current::before { background: var(--color-primary); }
.genealogy-node:hover { background: var(--color-surface-2); }
.genealogy-node.is-active-node { background: var(--color-primary-highlight); }
.gnode-team { font-weight: 700; font-size: var(--text-sm); }
.gnode-city { font-size: var(--text-xs); color: var(--color-text-muted); }
.gnode-years { font-size: var(--text-xs); color: var(--color-text-faint); font-variant-numeric: tabular-nums; }
.gnode-arrow-reason {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: none;
}
.gnode-arrow-reason.is-open { display: block; }
.gnode-arrow-reason strong { color: var(--color-text); }

.detail-section-label { font-size: var(--text-xs); font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-2); }

.stint-detail { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3); background: var(--color-surface-2); border-radius: var(--radius-lg); border: 1px solid var(--color-divider); }
.stint-detail-row { display: flex; flex-direction: column; gap: 2px; }
.stint-detail-key { font-size: 0.7rem; font-weight: 700; color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.stint-detail-value { font-size: var(--text-sm); }
.stint-detail-value.reason { color: var(--color-text); }
.stint-sources { display: flex; flex-direction: column; gap: 2px; }
.stint-sources a { font-size: var(--text-xs); color: var(--color-primary); text-decoration: none; word-break: break-all; }
.stint-sources a:hover { text-decoration: underline; }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 12, 0.6);
  display: grid; place-items: center;
  z-index: 2100;
  padding: var(--space-4);
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  max-width: 520px;
  width: 100%;
  padding: var(--space-8);
  position: relative;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.modal h2 { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 800; }
.modal p { font-size: var(--text-sm); color: var(--color-text-muted); }
.modal-note { font-size: var(--text-xs); padding: var(--space-3); background: var(--color-surface-2); border-radius: var(--radius-md); }
.modal-close { position: absolute; top: var(--space-4); right: var(--space-4); width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--radius-md); color: var(--color-text-muted); }
.modal-close:hover { background: var(--color-surface-offset); }
.modal-close svg { width: 18px; height: 18px; }

/* ============ LEAFLET MARKER / POPUP OVERRIDES ============ */
.nhl-marker { display: grid; place-items: center; }
.nhl-marker-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.25), var(--shadow-sm);
}
.nhl-marker-dot.is-defunct { opacity: 0.55; border-style: dashed; }
.nhl-marker-dot.is-selected { width: 18px; height: 18px; box-shadow: 0 0 0 4px rgba(77,179,255,0.35), var(--shadow-md); }

.leaflet-popup-content-wrapper { background: var(--color-surface); color: var(--color-text); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); }
.leaflet-popup-tip { background: var(--color-surface); }
.leaflet-popup-content { margin: var(--space-3) var(--space-4); font-family: var(--font-body); }
.popup-title { font-weight: 700; font-size: var(--text-sm); margin-bottom: 2px; }
.popup-meta { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-2); }
.popup-link { font-size: var(--text-xs); font-weight: 600; color: var(--color-primary); }
.leaflet-control-attribution { background: var(--color-surface); color: var(--color-text-faint); font-size: 10px; }
.leaflet-control-attribution a { color: var(--color-text-muted); }
.leaflet-control-zoom a { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.leaflet-control-zoom a:hover { background: var(--color-surface-offset); }

/* ============ RESPONSIVE ============ */
@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 240px 1fr 300px; }
}

@media (max-width: 860px) {
  html, body { overflow: auto; height: auto; }
  .app-shell { grid-template-columns: 1fr; height: auto; }
  .panel-left, .panel-right { max-height: 320px; border: none; border-bottom: 1px solid var(--color-divider); }
  .map-column { height: 70vh; min-height: 480px; }
  .brand-sub { display: none; }
}

@media (max-width: 520px) {
  .map-toolbar { gap: var(--space-2); padding: var(--space-2) var(--space-3); }
  .map-toolbar-actions .text-btn span { display: none; }
  .topbar { padding: 0 var(--space-3); }

  /* Era text labels can't fit on narrow screens — collapse to small tick dots, full label still available via native title tooltip on tap-hold. */
  .timeline-header { height: 10px; }
  .era-marker {
    font-size: 0;
    width: 6px; height: 6px;
    top: 2px;
    border-radius: 50%;
    background: var(--color-primary);
  }
  .era-marker-row2 { top: 2px; }
  .era-marker-row3 { top: 2px; }
}

/* ========== Enhanced features CSS ========== */

/* --- Marker pop animation --- */
@keyframes nhl-marker-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes nhl-cup-pop {
  0% { transform: scale(0) rotate(-20deg); }
  70% { transform: scale(1.2) rotate(0deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* --- Stanley Cup marker --- */
.nhl-cup-marker { background: transparent !important; border: none !important; }
.nhl-cup-badge {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, #f9d94a 0%, #c99a1f 100%);
  color: #4a2f00;
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(0,0,0,0.35);
  animation: nhl-cup-pop 0.5s ease-out;
}
[data-theme="dark"] .nhl-cup-badge { border-color: #111; }
.nhl-cup-popup .leaflet-popup-content { min-width: 190px; }

/* --- Flight arc pulse --- */
.nhl-flight-arc { animation: nhl-arc-dash 1.8s linear; }
@keyframes nhl-arc-dash {
  from { stroke-dashoffset: 40; opacity: 0.2; }
  to { stroke-dashoffset: 0; opacity: 0.9; }
}
.nhl-flight-pulse-icon { background: transparent !important; border: none !important; }
.nhl-flight-pulse {
  width: 12px; height: 12px; border-radius: 50%;
  box-shadow: 0 0 0 rgba(255,255,255,0.6);
  animation: nhl-pulse 1s ease-out infinite;
}
@keyframes nhl-pulse {
  0% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  100% { box-shadow: 0 0 0 16px transparent; opacity: 0; }
}

/* --- Milestone caption (top-center of map) --- */
.milestone-caption {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -18px);
  z-index: 500;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 12px 18px 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 520px;
  min-width: 280px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s, transform 0.4s;
}
.milestone-caption.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.milestone-year {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
  padding-right: 10px;
  border-right: 1px solid var(--color-border);
}
.milestone-body {
  display: flex; flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.milestone-body strong {
  font-size: 0.95rem;
  color: var(--color-text);
  line-height: 1.2;
}
.milestone-caption-text {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  line-height: 1.35;
}
.milestone-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--color-text-faint);
  cursor: pointer;
  padding: 0 2px;
  align-self: flex-start;
}
.milestone-close:hover { color: var(--color-text); }

@media (max-width: 720px) {
  .milestone-caption { max-width: calc(100vw - 40px); padding: 10px 12px; gap: 10px; }
  .milestone-year { font-size: 1.2rem; padding-right: 8px; }
  .milestone-body strong { font-size: 0.85rem; }
  .milestone-caption-text { font-size: 0.75rem; }
}

/* --- Cup toggle switch --- */
.toggle-row {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-slider {
  position: relative;
  width: 36px; height: 20px;
  background: var(--color-border);
  border-radius: 999px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-row input:checked + .toggle-slider { background: var(--color-accent); }
.toggle-row input:checked + .toggle-slider::after { transform: translateX(16px); }
.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.88rem;
  color: var(--color-text);
  font-weight: 500;
}
.toggle-label svg { width: 15px; height: 15px; color: #c99a1f; }
.toggle-hint {
  margin-top: 4px;
  padding-left: 46px;
  font-size: 0.75rem;
  color: var(--color-text-faint);
  line-height: 1.35;
}

/* --- Topbar tour button --- */
.topbar-btn { padding: 6px 12px; }
.topbar-btn svg { width: 16px; height: 16px; }

/* --- Stint arena image --- */
.stint-arena-figure {
  margin: 0 0 12px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-surface-2);
}
.stint-arena-figure img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}
.stint-arena-figure figcaption {
  font-size: 0.72rem;
  padding: 6px 10px;
  color: var(--color-text-faint);
  background: var(--color-surface-2);
  border-top: 1px solid var(--color-border);
}
.stint-arena-figure figcaption a {
  color: var(--color-text-secondary);
  text-decoration: none;
}
.stint-arena-figure figcaption a:hover { color: var(--color-accent); }

/* --- Stint city facts list --- */
.stint-facts {
  margin: 4px 0 0 0;
  padding-left: 18px;
  list-style: disc;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  line-height: 1.45;
}
.stint-facts li { margin-bottom: 3px; }

/* --- Cup wins in stint card --- */
.stint-cups {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(90deg, rgba(249, 217, 74, 0.15), rgba(249, 217, 74, 0.02));
  border-left: 3px solid #c99a1f;
  border-radius: 4px;
  margin: 8px 0;
  flex-wrap: wrap;
}
.stint-cup-label {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #7a5a10;
}
[data-theme="dark"] .stint-cup-label { color: #f9d94a; }
.stint-cup-label svg { width: 15px; height: 15px; }
.stint-cup-years {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.cup-chip {
  background: rgba(201, 154, 31, 0.2);
  color: #7a5a10;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
}
[data-theme="dark"] .cup-chip { color: #f9d94a; }

/* --- Franchise-level cup summary --- */
.detail-cups-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(90deg, rgba(249, 217, 74, 0.15), transparent 90%);
  border-left: 3px solid #c99a1f;
  border-radius: 4px;
  margin: 10px 0 14px 0;
  flex-wrap: wrap;
}
.detail-cups-badge {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600;
  color: #7a5a10;
  white-space: nowrap;
}
[data-theme="dark"] .detail-cups-badge { color: #f9d94a; }
.detail-cups-years {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* --- Story mode overlay --- */
.story-overlay {
  z-index: 2000;
  align-items: center;
  justify-content: center;
  background: rgba(20, 24, 33, 0.55);
}
.story-modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 28px 32px 24px;
  max-width: 720px;
  width: calc(100vw - 32px);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  position: relative;
}
/* Story step: anchor to bottom so map remains visible above */
.story-modal-narrow {
  max-width: 720px;
  width: calc(100vw - 60px);
  margin: auto auto 32px auto;
  align-self: flex-end;
  padding: 20px 24px;
}
.story-overlay:has(.story-modal-narrow) {
  background: transparent;
  align-items: flex-end;
  pointer-events: none;
}
.story-modal-narrow { pointer-events: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.45); }
.story-menu-intro {
  color: var(--color-text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 6px 0 20px 0;
}
.story-menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.story-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  color: var(--color-text);
  font-family: inherit;
}
.story-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-accent);
  background: var(--color-surface);
}
.story-card-icon {
  width: 40px; height: 40px;
  background: var(--color-accent-soft, rgba(0, 118, 168, 0.12));
  color: var(--color-accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.story-card-icon svg { width: 20px; height: 20px; }
.story-card-body {
  display: flex; flex-direction: column; gap: 3px;
  flex: 1; min-width: 0;
}
.story-card-body strong {
  font-size: 0.98rem;
  color: var(--color-text);
}
.story-card-sub {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}
.story-card-count {
  font-size: 0.72rem;
  color: var(--color-text-faint);
  margin-top: 2px;
}
.story-card-arrow {
  color: var(--color-text-faint);
  flex-shrink: 0;
}

/* Story step */
.story-progress {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 16px;
}
.story-progress-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.story-progress-dots {
  display: flex; gap: 6px;
}
.story-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  transition: background 0.2s;
}
.story-dot.is-done { background: var(--color-accent); opacity: 0.5; }
.story-dot.is-current { background: var(--color-accent); transform: scale(1.3); }
.story-progress-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-faint);
}
.story-step-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 20px;
  align-items: baseline;
}
.story-step-year {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
  grid-row: 1 / 3;
  padding-right: 16px;
  border-right: 1px solid var(--color-border);
  align-self: stretch;
  display: flex; align-items: center;
}
.story-step-title {
  font-size: 1.15rem;
  margin: 0;
  color: var(--color-text);
  line-height: 1.25;
  font-weight: 600;
}
.story-step-caption {
  color: var(--color-text-secondary);
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 4px 0 0 0;
}
.story-step-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}
.story-step-actions .text-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.story-step-actions .is-primary {
  background: var(--color-primary);
  color: #fff !important;
  border-color: var(--color-primary);
}
.story-step-actions .is-primary:hover { filter: brightness(1.08); border-color: var(--color-primary); }
.story-step-actions .is-primary svg { color: #fff; }
.story-menu-btn { color: var(--color-text-secondary); }

@media (max-width: 640px) {
  .story-modal { padding: 20px 20px 18px; }
  .story-step-year { font-size: 1.9rem; }
  .story-step-title { font-size: 1.1rem; }
  .story-menu-grid { grid-template-columns: 1fr; }
  .story-step-actions { flex-wrap: wrap; }
  .story-progress-label { font-size: 0.78rem; }
}

/* --- Ensure map has relative positioning so milestone caption is anchored --- */
#map { position: relative; }
