:root {
  /* CDI Brand Palette (Light Theme Defaults) */
  --bg-color: #f8fafc;
  --text-primary: #001e40;
  --text-secondary: #475569;
  --brand-red: #b6171e;
  --brand-red-bright: #d82b33;
  --panel-bg: rgba(248, 250, 252, 0.72);
  --panel-border: rgba(0, 30, 64, 0.08);
  --ticker-bg: rgba(248, 250, 252, 0.75);
  --map-overlay-bg: rgba(248, 250, 252, 0.7);
  --btn-bg: rgba(0, 30, 64, 0.05);
  --btn-hover: rgba(0, 30, 64, 0.1);
  --glass-shadow: 0 10px 40px -10px rgba(0, 30, 64, 0.12);
  --card-border: rgba(255, 255, 255, 0.6);

  /* Shared Variables */
  --laurel: #10b981;
  --laurel-dim: #059669;
}

html.dark {
  /* Dark Theme Overrides */
  --bg-color: #020617;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --panel-bg: rgba(2, 6, 23, 0.68);
  --panel-border: rgba(248, 250, 252, 0.08);
  --ticker-bg: rgba(2, 6, 23, 0.7);
  --map-overlay-bg: rgba(2, 6, 23, 0.65);
  --btn-bg: rgba(248, 250, 252, 0.08);
  --btn-hover: rgba(216, 43, 51, 0.25);
  --brand-red: #d82b33;
  --brand-red-bright: #ff4d4d;
  --glass-shadow: 0 12px 48px -8px rgba(0, 0, 0, 0.45);
  --card-border: rgba(255, 255, 255, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-color);
  overflow: hidden;
  font-family: "Plus Jakarta Sans", sans-serif;
  color: var(--text-primary);
  transition:
    background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Glassmorphism Styles */
.glass-panel {
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border);
  box-shadow: var(--glass-shadow);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Navbar */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 72px;
  background: var(--panel-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1.5px solid var(--panel-border);
  z-index: 10000;
  display: flex;
  align-items: center;
  transition:
    background 0.3s ease,
    border-color 0.3s ease;
}

.nav-container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 44px);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  transition:
    transform 0.2s ease,
    opacity 0.2s ease;
}

.nav-brand:hover {
  transform: scale(1.01);
  opacity: 0.9;
}

.nav-logo {
  height: 44px;
  width: auto;
  object-fit: contain;
}

.nav-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.nav-brand-main {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  transition: color 0.3s ease;
}

.nav-brand-sub {
  font-weight: 700;
  font-size: 10px;
  color: var(--brand-red);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-top: 1px;
  transition: color 0.3s ease;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  background: var(--btn-bg);
  border: 1.5px solid var(--panel-border);
  color: var(--text-primary);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle:hover {
  background: var(--btn-hover);
  color: var(--brand-red-bright);
  transform: rotate(15deg) scale(1.05);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--brand-red-bright);
  outline-offset: 2px;
}

/* Language Selector Styles */
.lang-selector {
  position: relative;
}

.lang-toggle-btn {
  background: var(--btn-bg);
  border: 1.5px solid var(--panel-border);
  color: var(--text-primary);
  border-radius: 24px;
  padding: 0 12px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
}

.lang-toggle-btn:hover {
  background: var(--btn-hover);
  color: var(--brand-red-bright);
  transform: scale(1.02);
}

.icon-globe {
  flex-shrink: 0;
}

.active-lang-label {
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 140px;
  border-radius: 14px;
  list-style: none;
  margin: 0;
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 10100;
  background: var(--bg-color);
  opacity: 0.95;
}

.lang-dropdown.open {
  display: flex;
}

.lang-option {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
}

.lang-option:hover {
  background: var(--btn-hover);
  color: var(--brand-red-bright);
}

.lang-option[aria-selected="true"] {
  background: var(--brand-red);
  color: #fff !important;
}

/* Accent for hover focus */
.lang-option:focus-visible {
  outline: 2px solid var(--brand-red-bright) !important;
  outline-offset: -2px !important;
  background: var(--btn-hover);
}

.icon-sun {
  display: none;
  color: #f59e0b; /* Golden Amber Sun */
}

.icon-moon {
  display: block;
}

html.dark .icon-sun {
  display: block;
}

html.dark .icon-moon {
  display: none;
}

/* Map */
#map {
  position: fixed;
  top: 72px;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-color);
  z-index: 1;
  transition: background 0.4s ease;
}

/* Map tiles inversion in dark mode (on all Leaflet map containers!) */
html.dark .leaflet-tile-pane {
  filter: invert(1) grayscale(0.55) brightness(0.95) contrast(1.05)
    hue-rotate(180deg);
}

/* Leaflet Attribution & Controls styling */
.leaflet-control-attribution {
  background: var(--map-overlay-bg) !important;
  color: var(--text-secondary) !important;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 10px !important;
  border-radius: 8px 0 0 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--panel-border);
  border-right: none;
  border-bottom: none;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
  font-weight: 500;
}

.leaflet-control-zoom {
  border: none !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.leaflet-control-zoom a {
  background: var(--panel-bg) !important;
  color: var(--text-primary) !important;
  border: 1.5px solid var(--panel-border) !important;
  border-radius: 10px !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  width: 38px !important;
  height: 38px !important;
  line-height: 34px !important;
  font-size: 16px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--btn-hover) !important;
  color: var(--brand-red-bright) !important;
  transform: scale(1.05);
}

.leaflet-bar {
  box-shadow: none !important;
}

/* HUD Panel */
.hud {
  z-index: 500;
}

/* Standard stage badges / pins on map */
.stage-badge {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-secondary);
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.stage-badge:hover {
  transform: scale(1.2);
  color: var(--text-primary);
  border-color: var(--brand-red-bright);
}

.stage-badge.active {
  color: #fff;
  background: var(--brand-red-bright);
  border-color: var(--brand-red-bright);
  box-shadow: 0 0 15px rgba(216, 43, 51, 0.4);
}

.stage-badge.passed {
  color: var(--laurel);
  border-color: rgba(79, 122, 82, 0.7);
}

.stage-badge.selected {
  color: var(--bg-color);
  background: var(--text-primary);
  border-color: var(--text-primary);
  transform: scale(1.15);
}

/* Side details panel */
#panel {
  background: var(--panel-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--glass-shadow);
  overflow-y: auto;
}

#panel .panel-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--panel-border);
  background: var(--btn-bg);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#panel .panel-close:hover {
  background: var(--btn-hover);
  border-color: var(--brand-red-bright);
  color: var(--brand-red-bright);
  transform: rotate(90deg) scale(1.05);
}

#panel .panel-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brand-red-bright);
  margin: 0 0 8px 0;
}

#panel h2 {
  font-weight: 800;
  font-size: 24px;
  margin: 0 0 6px 0;
  line-height: 1.2;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

#panel .panel-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 20px 0;
  font-weight: 500;
}

#panel .points-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

#panel .point-card .minimap {
  width: 100%;
  height: 120px;
  border-radius: 12px;
  border: 1.5px solid var(--panel-border);
  background: #f1f5f9;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

html.dark #panel .point-card .minimap {
  background: #0f172a;
}

#panel .point-card .map-link {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
}

#panel .point-card .map-link:hover .minimap {
  border-color: var(--brand-red-bright);
}

#panel .point-card .point-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--brand-red-bright);
  margin: 10px 0 4px 0;
}

#panel .point-card .point-town {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
  margin: 0 0 2px 0;
}

#panel .point-card .point-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

#panel .point-card .point-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--brand-red);
  text-decoration: none;
  border-bottom: 1.5px solid rgba(182, 23, 30, 0.3);
  transition: all 0.2s ease;
}

#panel .point-card .point-link:hover {
  color: var(--brand-red-bright);
  border-bottom-color: var(--brand-red-bright);
}

.minimap-pin {
  width: 14px;
  height: 14px;
  border-radius: 50% 50% 50% 0;
  background: var(--brand-red-bright);
  transform: rotate(-45deg);
  box-shadow: 0 0 0 3px rgba(216, 43, 51, 0.2);
}

#panel .stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

#panel .stat {
  background: var(--btn-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 14px;
  transition: transform 0.2s ease;
}

#panel .stat:hover {
  transform: translateY(-2px);
}

#panel .stat .label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

#panel .stat .value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
}

#panel .stat .value .unit {
  font-size: 0.6em;
  color: var(--text-secondary);
  margin-left: 3px;
  font-weight: 600;
}

#panel .difficulty-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 20px;
}

#panel .difficulty-chip.d-facil {
  background: rgba(16, 185, 129, 0.1);
  color: #047857;
  border: 1.5px solid rgba(16, 185, 129, 0.25);
}

html.dark #panel .difficulty-chip.d-facil {
  color: #34d399;
  background: rgba(16, 185, 129, 0.15);
  border: 1.5px solid rgba(52, 211, 153, 0.25);
}

#panel .difficulty-chip.d-moderada {
  background: rgba(245, 158, 11, 0.1);
  color: #b45309;
  border: 1.5px solid rgba(245, 158, 11, 0.25);
}

html.dark #panel .difficulty-chip.d-moderada {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.15);
  border: 1.5px solid rgba(251, 191, 36, 0.25);
}

#panel .difficulty-chip.d-exigente {
  background: rgba(249, 115, 22, 0.1);
  color: #c2410c;
  border: 1.5px solid rgba(249, 115, 22, 0.25);
}

html.dark #panel .difficulty-chip.d-exigente {
  color: #fdba74;
  background: rgba(249, 115, 22, 0.15);
  border: 1.5px solid rgba(253, 186, 116, 0.25);
}

#panel .difficulty-chip.d-muito-exigente {
  background: rgba(220, 38, 38, 0.1);
  color: #b91c1c;
  border: 1.5px solid rgba(220, 38, 38, 0.25);
}

html.dark #panel .difficulty-chip.d-muito-exigente {
  color: #fca5a5;
  background: rgba(220, 38, 38, 0.15);
  border: 1.5px solid rgba(252, 165, 165, 0.25);
}

#panel .desc-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

#panel .desc {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  font-weight: 500;
  margin: 0 0 28px 0;
}

#panel .panel-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#panel .nav-btn {
  flex: 1;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  background: var(--btn-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-btn:hover {
  background: var(--btn-hover);
  border-color: var(--brand-red-bright);
  color: var(--brand-red-bright);
}

/* Runner pulse styles */
.runner-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand-red-bright);
  box-shadow:
    0 0 0 4px rgba(216, 43, 51, 0.25),
    0 0 20px 8px rgba(216, 43, 51, 0.6);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 0 4px rgba(216, 43, 51, 0.25),
      0 0 20px 8px rgba(216, 43, 51, 0.6);
  }
  50% {
    transform: scale(1.25);
    box-shadow:
      0 0 0 6px rgba(216, 43, 51, 0.35),
      0 0 26px 12px rgba(216, 43, 51, 0.8);
  }
}

/* Hint panel at bottom center */
.hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  background: var(--map-overlay-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 24px;
  padding: 8px 18px;
  pointer-events: none;
  z-index: 499;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  transition: opacity 0.5s ease;
  opacity: 0;
}

/* General button layouts for lists */
.event-info a {
  display: block;
  text-align: center;
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  border-radius: 9999px;
  padding: 12px 18px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.event-info a:first-of-type {
  background: var(--btn-bg);
  color: var(--text-primary);
  border: 1.5px solid var(--panel-border);
}

.event-info a:first-of-type:hover {
  background: var(--btn-hover);
  border-color: var(--brand-red-bright);
}

.event-info a.primary-btn {
  background: var(--brand-red);
  color: white;
  border: 1.5px solid transparent;
}

.event-info a.primary-btn:hover {
  background: var(--brand-red-bright);
  transform: scale(1.02);
  box-shadow: 0 6px 20px rgba(182, 23, 30, 0.3);
}

.event-info a.primary-btn:active {
  transform: scale(0.98);
}

/* -------------------------------------------------------------------------- */
/* DESKTOP VIEW LAYOUT (min-width: 1024px)                                    */
/* -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
  /* HUD is a beautiful floating glass sidebar on the left */
  .hud {
    position: fixed;
    top: 96px;
    bottom: 24px;
    left: 24px;
    width: 420px;
    background: var(--panel-bg);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1.5px solid var(--panel-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 20px;
    pointer-events: auto;
    max-height: fit-content;
    overflow-y: auto;
    scrollbar-width: thin;
    transition:
      transform 0.38s cubic-bezier(0.22, 0.8, 0.32, 1),
      opacity 0.38s cubic-bezier(0.22, 0.8, 0.32, 1);
  }

  .hud::-webkit-scrollbar {
    width: 6px;
  }
  .hud::-webkit-scrollbar-thumb {
    background-color: var(--panel-border);
    border-radius: 3px;
  }

  /* Hide HUD when stage details panel is open in desktop mode */
  .hud.dimmed {
    transform: translateX(calc(-100% - 48px));
    opacity: 0;
    pointer-events: none;
  }

  .stage-picker {
    width: 100%;
  }

  .stage-picker select {
    appearance: none;
    -webkit-appearance: none;
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px 38px 12px 16px;
    width: 100%;
    cursor: pointer;
    outline: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%238b9891' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 16px center;
    transition: all 0.25s ease;
  }

  .stage-picker select:hover,
  .stage-picker select:focus-visible {
    border-color: var(--brand-red-bright);
    background-color: var(--btn-hover);
  }

  .top-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
  }

  .hero-panel {
    background: transparent;
    border: none;
    padding: 0;
    backdrop-filter: none;
  }

  .eyebrow {
    font-size: 11px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--brand-red-bright);
    margin: 0 0 8px 0;
    font-weight: 700;
  }

  h1 {
    font-weight: 800;
    font-size: 32px;
    line-height: 1.15;
    margin: 0 0 12px 0;
    color: var(--text-primary);
    letter-spacing: -0.02em;
  }

  .sub {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
    font-weight: 500;
  }

  /* Legend & Altitude profile */
  .legend {
    width: 100%;
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
  }

  .legend .bar {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    margin: 8px 0 6px 0;
    background: linear-gradient(90deg, #10b981, #f59e0b, #f97316);
  }

  .legend .scale {
    display: flex;
    justify-content: space-between;
    width: 100%;
  }

  /* Event Participation card */
  .event-info {
    width: 100%;
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .event-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
  }

  .event-info p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    font-weight: 500;
  }

  /* Bottom Row container */
  .bottom-row {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* Statistics ticker */
  .ticker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 14px;
    padding: 12px;
  }

  .ticker .item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
  }

  .ticker .label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
    min-height: 24px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    line-height: 1.1;
  }

  .ticker .value {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
  }

  .ticker .value .unit {
    font-size: 0.6em;
    color: var(--text-secondary);
    margin-left: 1px;
    font-weight: 600;
  }

  /* Controls line */
  .controls {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 14px;
    padding: 10px 14px;
  }

  .cta {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
  }

  .cta strong {
    color: var(--brand-red-bright);
    font-weight: 800;
  }

  .ctrl-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1.5px solid var(--panel-border);
    background: var(--panel-bg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }

  .ctrl-btn:hover {
    border-color: var(--brand-red-bright);
    background: var(--btn-hover);
    color: var(--brand-red-bright);
    transform: scale(1.05);
  }

  .ctrl-btn svg {
    width: 15px;
    height: 15px;
  }

  /* Zoom controls positioning on desktop */
  .leaflet-bottom.leaflet-right {
    bottom: 24px !important;
    right: 24px !important;
    transition: transform 0.38s cubic-bezier(0.22, 0.8, 0.32, 1);
  }

  /* Translate Zoom controls out of the way when the side panel is open */
  body:has(#panel.open) .leaflet-bottom.leaflet-right {
    transform: translateX(-404px);
  }

  /* Floating desktop side details panel */
  #panel {
    position: fixed;
    top: 96px !important;
    bottom: 24px !important;
    right: 24px !important;
    width: 380px !important;
    border-radius: 24px !important;
    border: 1.5px solid var(--panel-border) !important;
    height: auto !important;
    padding: 24px !important;
    z-index: 6000;
    transform: translateX(calc(100% + 48px));
    transition: transform 0.38s cubic-bezier(0.22, 0.8, 0.32, 1);
  }

  #panel.open {
    transform: translateX(0) !important;
  }

  /* Floating desktop Animation & Stats Card */
  #animationStatsCard {
    position: fixed;
    top: 96px;
    right: 24px;
    width: 380px;
    z-index: 5000;
    background: var(--panel-bg);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1.5px solid var(--panel-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    padding: 6px;
    transition:
      transform 0.38s cubic-bezier(0.22, 0.8, 0.32, 1),
      opacity 0.38s cubic-bezier(0.22, 0.8, 0.32, 1);
  }

  #animationStatsCard .collapsible-trigger {
    padding: 12px 14px;
  }

  #animationStatsCard .collapsible-content {
    padding: 0 14px 14px 14px;
    gap: 14px;
  }

  /* Slide off-screen on desktop when details panel is open */
  body:has(#panel.open) #animationStatsCard {
    transform: translateX(calc(100% + 48px));
    opacity: 0;
    pointer-events: none;
  }
}

/* -------------------------------------------------------------------------- */
/* TABLET AND MOBILE VIEW LAYOUT (max-width: 1023px)                          */
/* -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  /* Let the map occupy the full space beneath the navbar */
  #map {
    top: 72px;
    bottom: 0;
    left: 0;
    right: 0;
  }

  /* Complete HUD overlay overrides */
  .hud {
    position: fixed;
    top: 72px;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
  }

  /* 1. TOP HEADER FLOATING GLASS CARD */
  .top-row {
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: auto;
  }

  .hero-panel {
    width: 100%;
    max-width: 480px;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--panel-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
    padding: 12px 16px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease;
  }

  .hero-panel:active {
    transform: scale(0.98);
  }

  .eyebrow {
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--brand-red-bright);
    margin: 0 0 3px 0;
    font-weight: 700;
  }

  h1 {
    font-weight: 800;
    font-size: 18px;
    line-height: 1.2;
    margin: 0;
    color: var(--text-primary);
  }

  /* Hide description & legend to free up mobile screen space */
  .sub,
  .legend,
  .hud .event-info h3,
  .hud .event-info p {
    display: none !important;
  }

  /* 2. BOTTOM CONTROLS FLOATING GLASS CARD */
  .bottom-row {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--panel-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 18px;
    box-shadow: var(--glass-shadow);
    padding: 14px;
    pointer-events: auto;
  }

  /* Row 1: Stage Picker */
  .stage-picker {
    width: 100%;
    position: static;
    transform: none;
  }

  .stage-picker select {
    appearance: none;
    -webkit-appearance: none;
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 10px;
    padding: 10px 34px 10px 14px;
    width: 100%;
    cursor: pointer;
    outline: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%238b9891' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    transition: all 0.2s ease;
  }

  /* Row 2: Stats Ticker */
  .ticker {
    display: flex !important; /* Overwrite standard display none if any */
    justify-content: space-between;
    width: 100%;
    background: rgba(0, 30, 64, 0.02);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 8px 10px;
  }

  html.dark .ticker {
    background: rgba(248, 250, 252, 0.03);
  }

  .ticker .item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    flex: 1;
  }

  .ticker .label {
    font-size: 8.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 2px;
    min-height: 22px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    line-height: 1.1;
  }

  .ticker .value {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-primary);
  }

  .ticker .value .unit {
    font-size: 0.65em;
    color: var(--text-secondary);
    margin-left: 1px;
    font-weight: 600;
  }

  /* Row 3: Action Buttons (Play & CTAs) */
  .controls {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .controls .cta {
    display: none !important; /* Hide static text on mobile controls */
  }

  .ctrl-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid var(--panel-border);
    background: var(--btn-bg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
  }

  .ctrl-btn svg {
    width: 16px;
    height: 16px;
  }

  /* Incorporate .event-info links directly into bottom controls on mobile/tablet */
  .hud .event-info {
    display: flex !important;
    flex-direction: row;
    gap: 8px;
    width: 100%;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
  }

  .hud .event-info a {
    flex: 1;
    font-size: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    margin: 0 !important;
    white-space: nowrap;
  }

  /* 3. MOBILE SLIDE-UP DETAIL PANEL Drawer */
  #panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 75dvh;
    border-radius: 24px 24px 0 0;
    border-top: 1.5px solid var(--panel-border);
    border-left: none;
    border-right: none;
    z-index: 10001;
    padding: 24px;
    transform: translateY(100%);
    transition: transform 0.38s cubic-bezier(0.22, 0.8, 0.32, 1);
  }

  #panel.open {
    transform: translateY(0);
  }

  #panel .panel-close {
    top: 16px;
    right: 16px;
  }

  /* Layout refinements for point maps inside drawer */
  #panel .points-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #panel .point-card .minimap {
    height: 100px;
  }

  /* Hide desktop zoom controls adjustment */
  body:has(#panel.open) .leaflet-bottom.leaflet-right {
    transform: none;
  }

  /* Relocate zoom controls to topright so they stay clear of bottom card */
  .leaflet-top.leaflet-right {
    top: 154px !important; /* Move below top card height */
    right: 16px !important;
  }
}

/* Extra Mobile Adjustments */
@media (max-width: 480px) {
  .nav-brand-sub {
    display: block;
    font-size: 9px;
  }

  .nav-brand-main {
    font-size: 16px;
  }

  .hud {
    padding: 10px;
  }

  .bottom-row {
    padding: 10px;
  }

  .hud .event-info a {
    font-size: 11px;
    padding: 10px 8px;
  }
}

/* Ensure select options render with legible backgrounds in light and dark mode */
select option {
  background-color: var(--bg-color);
  color: var(--text-primary);
}

/* Accessibility Focus States */
a:focus-visible,
button:focus-visible,
select:focus-visible,
.nav-btn:focus-visible {
  outline: 3px solid var(--brand-red-bright) !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 5px rgba(216, 43, 51, 0.25) !important;
}

/* Collapsible Animation & Stats Card */
.collapsible-card {
  width: 100%;
  background: var(--btn-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.collapsible-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 14px 16px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 13.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  transition: background 0.2s ease;
  outline: none;
}

.collapsible-trigger:hover {
  background: var(--btn-hover);
}

.collapsible-trigger:focus-visible {
  background: var(--btn-hover);
  outline: 2px solid var(--brand-red-bright) !important;
  outline-offset: -2px !important;
}

.trigger-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.trigger-icon {
  color: var(--brand-red-bright);
}

.chevron-icon {
  transition: transform 0.3s ease;
  color: var(--text-secondary);
}

/* Rotate Chevron when collapsed */
.collapsible-card.collapsed .chevron-icon {
  transform: rotate(-90deg);
}

/* Collapsible Content area */
.collapsible-content {
  max-height: 500px;
  opacity: 1;
  transition:
    max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s ease,
    padding 0.35s ease;
  padding: 0 14px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.collapsible-card.collapsed .collapsible-content {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

/* Remove individual background and borders when inside the collapsible container to prevent double styling */
.collapsible-content .legend,
.collapsible-content .ticker,
.collapsible-content .controls {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Welcome Modal (Mobile/Tablet only) - Hidden by default on Desktop */
.welcome-modal-backdrop {
  display: none;
}

/* Fix mobile alignment inside collapsible */
@media (max-width: 1023px) {
  .collapsible-card {
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    margin-top: 4px;
  }
  .collapsible-trigger {
    padding: 12px 14px;
    font-size: 13px;
    background: var(--btn-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 10px;
  }
  .collapsible-content {
    padding: 12px 0 0 0;
    gap: 10px;
  }

  /* Mobile/Tablet Welcome Modal Styles */
  .welcome-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(2, 6, 23, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 20000; /* Over everything */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
  }

  .welcome-modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  .welcome-modal-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    border-radius: 24px;
    padding: 32px 24px 24px 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .welcome-modal-backdrop.show .welcome-modal-card {
    transform: translateY(0);
  }

  .modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
  }

  .modal-close-btn:hover {
    color: var(--brand-red-bright);
    background: var(--btn-bg);
  }

  .modal-eyebrow {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--brand-red-bright);
    margin: 0;
  }

  .welcome-modal-card h2 {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.25;
    color: var(--text-primary);
    margin: 0;
  }

  .modal-desc {
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 500;
  }

  .modal-action-btn {
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    border-radius: 12px;
    padding: 12px;
    background: var(--brand-red);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(182, 23, 30, 0.2);
    transition: all 0.25s ease;
  }

  .modal-action-btn:hover {
    background: var(--brand-red-bright);
    transform: scale(1.02);
  }
}
