/* ── App layout ─────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#header {
  height: 52px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  z-index: 10;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

#header-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#header-brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-header);
  letter-spacing: 0.01em;
  line-height: 1.1;
}

#header-sub {
  font-size: 0.58rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  line-height: 1.1;
}

#header-divider {
  width: 1px;
  height: 28px;
  background: var(--border-light);
  margin: 0 4px;
  flex-shrink: 0;
}

#header-event {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-header);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ── Header right: theme toggle + Kenya flag ─────────────────────────────── */
#header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#theme-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

#theme-toggle:hover {
  transform: scale(1.15);
}

#kenya-flag {
  font-size: 1.2rem;
  line-height: 1;
  cursor: default;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

#kenya-flag:hover {
  transform: scale(1.2);
}

/* ── Map container ───────────────────────────────────────────────────────── */
#map {
  flex: 1;
  width: 100%;
  position: relative;
}

/* ── Custom zoom buttons ─────────────────────────────────────────────────── */
#custom-zoom {
  position: absolute;
  bottom: 90px;
  right: 14px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#custom-zoom button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: rgba(15,15,26,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  transition: background 0.15s, transform 0.1s;
}

#custom-zoom button:hover {
  background: rgba(40,40,60,0.9);
  transform: scale(1.08);
}

body.light-theme #custom-zoom button {
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.1);
  color: #111122;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}

body.light-theme #custom-zoom button:hover {
  background: rgba(235,235,245,0.95);
}

/* ── Circuit markers ─────────────────────────────────────────────────────── */
.f1-marker {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  letter-spacing: 0.03em;
}

.f1-marker:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}

/* Upcoming race — hollow style */
.f1-marker.upcoming {
  background: transparent;
  border: 2.5px solid var(--accent);
  color: var(--accent);
}

body.light-theme .f1-marker {
  border-color: rgba(0,0,0,0.2);
}

body.light-theme .f1-marker.upcoming {
  background: rgba(255,255,255,0.85);
}

/* ── Status bar ──────────────────────────────────────────────────────────── */
#status-bar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,15,26,0.82);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.66rem;
  color: var(--text-secondary);
  z-index: 500;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

body.light-theme #status-bar {
  background: rgba(255,255,255,0.82);
  border-color: rgba(0,0,0,0.08);
}

/* ── Leaflet tile fix ────────────────────────────────────────────────────── */
.leaflet-tile {
  outline: none;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #header {
    padding: 0 10px;
    gap: 6px;
  }

  #header-logo {
    width: 28px;
    height: 28px;
    font-size: 0.62rem;
  }

  #header-title {
    font-size: 0.88rem;
  }

  #header-sub {
    font-size: 0.5rem;
  }

  #header-divider {
    height: 22px;
    margin: 0 2px;
  }

  #header-event {
    font-size: 0.76rem;
  }

  #theme-toggle {
    font-size: 1.05rem;
  }

  #kenya-flag {
    font-size: 1.05rem;
  }

  #custom-zoom {
    bottom: 110px;
    right: 10px;
  }

  #custom-zoom button {
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
  }
}


/* ── Track centroid marker (shown when track outline is revealed) ────────── */
.track-centroid-marker {
  width: 26px;
  height: 26px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}


.track-centroid-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--circuit-color, var(--accent));
  opacity: 0.9;
  position: relative;
  z-index: 2;
  box-shadow: 0 0 6px color-mix(in srgb, var(--circuit-color, var(--accent)) 60%, transparent);
  animation: centroidDotPulse 1.8s ease-in-out infinite;
}

.track-centroid-pulse {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px dashed var(--circuit-color, var(--accent));
  opacity: 0.6;
  animation: centroidSpin 5s linear infinite;
}


@keyframes centroidSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}


@keyframes centroidDotPulse {
  0%, 100% { transform: scale(1);   opacity: 0.9; }
  50%      { transform: scale(1.3); opacity: 0.5; }
}

@media (max-width: 768px) {
  .track-centroid-marker {
    width: 18px;
    height: 18px;
  }

  .track-centroid-dot {
    width: 7px;
    height: 7px;
  }

  .track-centroid-pulse {
    width: 18px;
    height: 18px;
  }
}

/* ── On-map track stats overlay (shown when a circuit panel is open) ──────── */
#track-stats-overlay {
  position: absolute;
  z-index: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

#track-stats-overlay.visible {
  opacity: 1;
}

#track-stats-overlay.position-top {
  top: 64px;
  left: 20px;
  transform: none;
  max-width: calc(100% - 380px);
  text-align: left;
}

#track-stats-overlay.position-left {
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  max-width: 220px;
  text-align: left;
}

#track-stats-overlay.position-right {
  top: 50%;
  right: 376px;
  transform: translateY(-50%);
  max-width: 220px;
  text-align: left;
}

.track-overlay-inner {
  padding: 0;
}

.track-overlay-gp {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 3px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 10px rgba(0,0,0,0.5);
}

body.light-theme .track-overlay-gp {
  text-shadow: 0 1px 4px rgba(255,255,255,0.9), 0 0 10px rgba(255,255,255,0.6);
}

.track-overlay-circuit-name {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 10px rgba(0,0,0,0.5);
}

body.light-theme .track-overlay-circuit-name {
  color: #111122;
  text-shadow: 0 1px 4px rgba(255,255,255,0.9), 0 0 10px rgba(255,255,255,0.6);
}

.track-overlay-stats {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 14px;
  white-space: nowrap;
}


#track-stats-overlay.position-top .track-overlay-stats {
  justify-content: flex-start;
}


#track-stats-overlay.position-left .track-overlay-stats,
#track-stats-overlay.position-right .track-overlay-stats {
  flex-direction: column;
  align-items: flex-start;
  white-space: normal;
  gap: 8px;
}

.track-overlay-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.track-overlay-stat-label {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
}

body.light-theme .track-overlay-stat-label {
  color: rgba(0,0,0,0.6);
  text-shadow: 0 1px 4px rgba(255,255,255,0.9), 0 0 8px rgba(255,255,255,0.6);
}

.track-overlay-stat-value {
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
}

body.light-theme .track-overlay-stat-value {
  color: #111122;
  text-shadow: 0 1px 4px rgba(255,255,255,0.9), 0 0 8px rgba(255,255,255,0.6);
}

.track-overlay-stat-unit {
  font-size: 0.6rem;
  font-weight: 400;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

body.light-theme .track-overlay-stat-unit {
  color: rgba(0,0,0,0.55);
  text-shadow: 0 1px 4px rgba(255,255,255,0.9);
}

.track-overlay-divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.35);
  flex-shrink: 0;
}

body.light-theme .track-overlay-divider {
  background: rgba(0,0,0,0.25);
}

#track-stats-overlay.position-left .track-overlay-divider,
#track-stats-overlay.position-right .track-overlay-divider {
  width: 100%;
  height: 1px;
}


.track-overlay-record {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.4);
  -webkit-text-stroke: 0px;
}

body.light-theme .track-overlay-record {
  text-shadow: 0 1px 3px rgba(255,255,255,1), 0 0 12px rgba(255,255,255,1),
               0 2px 6px rgba(255,255,255,0.9);
}


.track-overlay-record-meta {
  font-size: 0.62rem;
  font-weight: 400;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

body.light-theme .track-overlay-record-meta {
  color: rgba(0,0,0,0.55);
  text-shadow: 0 1px 4px rgba(255,255,255,0.9);
}


/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #track-stats-overlay.position-top,
  #track-stats-overlay.position-left,
  #track-stats-overlay.position-right {
    top: 56px;
    left: 10px;
    right: 10px;
    transform: none;
    max-width: none;
    text-align: left;
  }

  .track-overlay-gp {
    font-size: 0.52rem;
    margin-bottom: 1px;
    display: inline;
  }

  .track-overlay-circuit-name {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 4px;
    display: block;
  }


  /* Stats can wrap to a second line on mobile instead of being clipped */
  .track-overlay-stats {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: baseline !important;
    white-space: normal !important;
    gap: 4px 0 !important;
    overflow: visible;
  }


  .track-overlay-stat {
    flex-direction: row;
    align-items: baseline;
    gap: 3px;
    flex-shrink: 0;
  }

  .track-overlay-stat-label {
    font-size: 0.44rem;
    font-weight: 700;
    opacity: 0.7;
    margin-right: 2px;
  }

  .track-overlay-stat-value {
    font-size: 0.7rem;
    font-weight: 700;
  }

  .track-overlay-stat-unit {
    font-size: 0.5rem;
  }

  .track-overlay-divider {
    width: 1px;
    height: 12px;
    background: rgba(255,255,255,0.3);
    display: block;
    margin: 0 8px;
    flex-shrink: 0;
  }

  body.light-theme .track-overlay-divider {
    background: rgba(0,0,0,0.2);
  }

  /* Lap record inline */
  .track-overlay-record {
    font-size: 0.62rem;
  }

  .track-overlay-record-meta {
    font-size: 0.5rem;
  }
}

/* ── Mobile map maximize button ─────────────────────────────────────────── */
#map-maximize-btn {
  position: absolute;
  bottom: var(--maximize-btn-bottom, 160px);
  right: 14px;
  z-index: 1300;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(15,15,26,0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35),
              0 0 0 0 rgba(225,6,0,0.55);
  animation: maximize-btn-glow 2.4s ease-in-out infinite;
  transition: background 0.15s, transform 0.1s;
}

@keyframes maximize-btn-glow {
  0%, 100% {
    box-shadow: 0 2px 10px rgba(0,0,0,0.35),
                0 0 0 0 rgba(225,6,0,0.45);
  }
  50% {
    box-shadow: 0 2px 10px rgba(0,0,0,0.35),
                0 0 8px 3px rgba(225,6,0,0.45);
  }
}

#map-maximize-btn:hover {
  background: rgba(40,40,60,0.9);
  transform: scale(1.08);
}

body.light-theme #map-maximize-btn {
  background: rgba(255,255,255,0.85);
  border-color: rgba(0,0,0,0.1);
  color: #111122;
}

/* Only show on mobile */
@media (min-width: 769px) {
  #map-maximize-btn { display: none !important; }
}

body.circuit-panel-open #status-bar {
  display: none;
}