/* ─── Design tokens ─────────────────────────────────────────── */
:root {
  --bg:         #080808;
  --accent:     #F5C400;
  --accent-dim: rgba(245, 196, 0, 0.35);
  --text:       #f5f4f0;
  --text-muted: #888888;
  --card-bg:    rgba(11, 11, 11, 0.82);
  --card-border: rgba(245, 196, 0, 0.18);
  --red:        #ff4444;
  --amber:      #ffaa00;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body:    'Outfit', sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}

/* ─── Map ───────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* Hide Leaflet attribution (small race, private use) */
.leaflet-control-attribution { display: none !important; }

/* Style zoom controls to match the dark theme */
.leaflet-control-zoom {
  border: 1px solid var(--card-border) !important;
  border-radius: 8px !important;
  overflow: hidden;
  margin-bottom: 185px !important; /* sit above the bottom bar (~170px tall) */
  margin-right: 12px !important;
}
.leaflet-control-zoom a {
  background: var(--card-bg) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--card-border) !important;
  backdrop-filter: blur(12px);
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 16px !important;
}
.leaflet-control-zoom a:hover {
  background: rgba(245,196,0,0.15) !important;
  color: var(--accent) !important;
}

/* ─── Stats card ────────────────────────────────────────────── */
.card {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  min-width: 186px;
  max-width: 220px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 16px 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 32px rgba(0,0,0,0.6);
}

.card.hidden { display: none; }

.card-header {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.card-header .x {
  color: var(--accent);
}

.runner-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 26px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.1;
}

.leg-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-bottom: 10px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.stat-icon {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  line-height: 1;
}

.stat-unit {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-text {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.progress-sep {
  color: var(--text-muted);
  margin: 0 3px;
}

.last-updated {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.last-updated.stale-amber { color: var(--amber); }
.last-updated.stale-red   { color: var(--red); }

/* ─── Waiting card ──────────────────────────────────────────── */
.waiting-card {
  text-align: center;
  max-width: 240px;
}

.waiting-text {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.1em;
  color: var(--text);
  margin-bottom: 8px;
}

.waiting-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Bottom bar ────────────────────────────────────────────── */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: linear-gradient(to top, rgba(8,8,8,0.96) 0%, rgba(8,8,8,0.7) 70%, transparent 100%);
  padding-top: 50px;
}

/* ─── Runner strip ──────────────────────────────────────────── */
#runner-strip {
  display: flex;
  gap: 6px;
  padding: 0 12px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
#runner-strip::-webkit-scrollbar { display: none; }

.runner-tile {
  flex: 1;
  min-width: 52px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 7px 6px 6px;
  text-align: center;
  transition: border-color 0.3s, background 0.3s;
  cursor: default;
}

.runner-tile.active {
  background: rgba(245,196,0,0.12);
  border-color: var(--accent);
}

.runner-tile.done {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.12);
}

.tile-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  margin: 0 auto 4px;
  transition: background 0.3s;
}

.runner-tile.active  .tile-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); animation: pulse 2s infinite; }
.runner-tile.done    .tile-dot { background: #44cc66; }

.tile-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.runner-tile.active .tile-name { color: var(--accent); }

.tile-info {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.runner-tile.active .tile-info  { color: rgba(245,196,0,0.7); }
.runner-tile.done   .tile-info  { color: #44cc66; opacity: 0.8; }

.tile-dist {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0.6;
}

.runner-tile.active .tile-dist { color: rgba(245,196,0,0.5); }

/* ─── Elevation section ─────────────────────────────────────── */
#elev-section {
  padding: 0 12px 6px;
}

#elev-labels {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

#elev-label-title {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
}

#elev-label-range {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

#elev-container {
  position: relative;
  height: 56px;
}

#elev-svg {
  width: 100%;
  height: 100%;
  display: block;
}

#elev-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
  box-shadow: 0 0 6px var(--accent);
  transform: translateX(-50%);
  transition: left 1s ease;
  display: none;
}

/* Progress bar */
#progress-bar-container {
  position: relative;
  height: 6px;
  margin: 0 16px 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 1s ease;
  box-shadow: 0 0 10px var(--accent-dim);
}

#progress-bar-label {
  position: absolute;
  right: 0;
  top: -16px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
}

/* ─── Runner dot on map ─────────────────────────────────────── */
.runner-dot-outer {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(245, 196, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s ease-in-out infinite;
}

.runner-dot-inner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent), 0 0 20px rgba(245,196,0,0.4);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.3); opacity: 0.7; }
}

/* ─── Conditions pill ───────────────────────────────────────── */
.conditions-pill {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 8px 14px;
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text);
}

.conditions-pill.hidden { display: none; }

.cond-item { white-space: nowrap; }
.cond-sep  { color: var(--text-muted); }

/* ─── Runner drawer ─────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0,0,0,0.4);
}

.drawer-backdrop.hidden { display: none; }

.runner-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 31;
  background: #111;
  border-top: 1px solid var(--card-border);
  border-radius: 16px 16px 0 0;
  padding: 12px 20px 32px;
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.runner-drawer.hidden {
  display: none;
}

.drawer-handle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.drawer-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 4px;
}

.drawer-status {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 20px;
}

.drawer-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.drawer-stat-value {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 28px;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}

.drawer-stat-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.drawer-legs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-leg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 13px;
}

.drawer-leg-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  min-width: 50px;
}

.drawer-leg-dist {
  color: var(--text);
  font-weight: 600;
}

.drawer-leg-time {
  color: var(--text-muted);
  font-size: 12px;
}

/* ─── Follow button ─────────────────────────────────────────── */
.follow-btn {
  position: fixed;
  bottom: 265px; /* above zoom controls (185px bottom bar + 64px controls + 16px gap) */
  right: 12px;
  z-index: 10;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.follow-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(245,196,0,0.1);
}

.follow-btn:hover {
  color: var(--accent);
  border-color: rgba(245,196,0,0.5);
}

/* ─── Toast notification ────────────────────────────────────── */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 10px 20px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  white-space: nowrap;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.toast.hidden {
  display: none;
}

.toast.fading {
  opacity: 0;
  transform: translateX(-50%) translateY(-8px);
}

/* ─── Leaflet popup overrides ───────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  backdrop-filter: blur(14px);
  color: var(--text);
  font-family: var(--font-body);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.leaflet-popup-tip {
  background: var(--card-bg);
}

/* ─── Mobile tweaks ─────────────────────────────────────────── */
@media (max-width: 400px) {
  .card {
    top: 10px;
    left: 10px;
    padding: 12px 14px 10px;
    min-width: 170px;
  }
  .runner-name { font-size: 22px; }
  #bottom-bar { padding-top: 30px; }
}
