/* ─── 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;
}

/* ─── Brand card ────────────────────────────────────────────── */
.brand-card {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 16px;
  backdrop-filter: blur(14px);
}

.brand-card .card-lockup {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

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

.card.hidden { display: none; }

/* Brand lockup at top of card */
.card-lockup {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  line-height: 1;
}

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


/* Shared divider between rows */
.card-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
}

/* Each row: big value + small label below, left-aligned */
.card-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 0;
}

.card-row-value {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 22px;
  color: var(--text);
  line-height: 1;
  letter-spacing: 0.02em;
}

.card-row-unit {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.card-row-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

/* First card-row gets extra top spacing to separate from lockup */
.card-row:first-of-type {
  padding-top: 12px;
}

/* Runner name row — slightly larger */
.runner-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 26px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1;
}

.leg-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-transform: uppercase;
  margin-top: 2px;
}

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

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

.sponsor-line {
  line-height: 1.3;
}

.sponsor-by {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.7;
}

.sponsor-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}

/* ─── 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;
  pointer-events: none;
  overflow: visible;
}

#runner-strip, #elev-section, #progress-bar-container {
  pointer-events: auto; /* re-enable for interactive content */
}

/* ─── Runner strip ──────────────────────────────────────────── */
#runner-strip {
  display: flex;
  gap: 6px;
  padding: 4px 12px 10px;
  overflow-x: auto;
  overflow-y: visible;
  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.25s, background 0.25s, transform 0.2s, box-shadow 0.25s;
  cursor: pointer;
}

.runner-tile:hover {
  transform: translateY(-2px) scale(1.04);
  background: rgba(245,196,0,0.08);
  border-color: rgba(245,196,0,0.45);
  box-shadow: 0 4px 16px rgba(245,196,0,0.12);
}

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

/* ─── Sponsor card ──────────────────────────────────────────── */
.sponsor-card {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 8px 14px;
  backdrop-filter: blur(12px);
  text-align: right;
  line-height: 1.3;
}

/* ─── Right panel ───────────────────────────────────────────── */
.right-panel {
  position: fixed;
  top: 90px;
  right: 16px;
  z-index: 10;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 32px rgba(0,0,0,0.6);
  min-width: 110px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.right-panel.hidden { display: none; }

.right-panel-row {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 8px 0;
}

.right-panel-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
}

.right-panel-value {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 22px;
  color: var(--text);
  line-height: 1;
  letter-spacing: 0.02em;
}

.right-panel-unit {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.right-panel-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

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

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

.runner-card {
  position: fixed;
  bottom: 190px; /* sit above the bottom bar */
  left: 50%;
  transform: translateX(-50%);
  z-index: 31;
  min-width: 260px;
  max-width: 340px;
  width: calc(100% - 32px);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 16px 16px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.7), 0 0 0 1px rgba(245,196,0,0.06);
  animation: cardIn 0.2s ease;
}

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

@keyframes cardIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.runner-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.runner-card-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 0 0 8px;
  line-height: 1;
  transition: color 0.2s;
}
.runner-card-close:hover { color: var(--text); }

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

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

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

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

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

.drawer-legs-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 110px;
  overflow-y: auto;
  scrollbar-width: none;
}
.drawer-legs-list::-webkit-scrollbar { display: none; }

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

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

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

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

/* ─── Off-grid full overlay ─────────────────────────────────── */
.offgrid-full {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 0, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: offgridFullIn 0.5s ease;
}

.offgrid-full.hidden { display: none; }

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

.offgrid-full-icon {
  font-size: 48px;
  color: var(--amber);
  animation: offgridPulse 1.8s ease-in-out infinite;
  margin-bottom: 16px;
}

.offgrid-full-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 52px;
  letter-spacing: 0.18em;
  color: var(--amber);
  text-transform: uppercase;
  line-height: 1;
  margin-bottom: 12px;
}

.offgrid-full-sub {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.offgrid-full-age {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(255,200,100,0.6);
  margin-bottom: 32px;
}

.offgrid-full-close {
  background: none;
  border: 1px solid rgba(255,170,0,0.4);
  border-radius: 8px;
  padding: 10px 24px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.offgrid-full-close:hover {
  color: var(--amber);
  border-color: var(--amber);
}

/* ─── Off-grid banner ───────────────────────────────────────── */
.offgrid-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(20, 10, 0, 0.92);
  border: 1px solid rgba(255,170,0,0.7);
  border-radius: 12px;
  padding: 12px 22px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 0 0 1px rgba(255,170,0,0.15), 0 6px 32px rgba(0,0,0,0.7), 0 0 40px rgba(255,140,0,0.12);
  animation: offgridIn 0.4s ease;
  white-space: nowrap;
}

.offgrid-banner.hidden { display: none; }

@keyframes offgridIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.offgrid-banner .offgrid-icon {
  font-size: 16px;
  color: var(--amber);
  animation: offgridPulse 1.8s ease-in-out infinite;
}

@keyframes offgridPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.95); }
  50%       { opacity: 1;   transform: scale(1.1); }
}

.offgrid-banner .offgrid-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.14em;
  color: var(--amber);
  text-transform: uppercase;
}

.offgrid-banner .offgrid-sep {
  color: rgba(255,170,0,0.35);
  font-size: 14px;
}

.offgrid-banner .offgrid-age {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(255,200,100,0.7);
}

/* ─── 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);
}

/* ─── Telemetry widget ──────────────────────────────────────── */
#telemetry-widget {
  position: fixed;
  bottom: 200px;
  left: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#telemetry-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: color 0.2s, border-color 0.2s;
}

#telemetry-btn:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.2);
}

#telemetry-btn.live {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(245,196,0,0.08);
}

.telem-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s, box-shadow 0.3s;
  flex-shrink: 0;
}

.telem-indicator.live {
  background: var(--accent);
  box-shadow: 0 0 5px var(--accent);
}

#telemetry-panel {
  margin-bottom: 6px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  min-width: 130px;
  animation: telemIn 0.15s ease;
}

#telemetry-panel.hidden { display: none; }

@keyframes telemIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.telem-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-top: 1px solid rgba(255,255,255,0.05);
  justify-content: space-between;
}

.telem-row:first-child { border-top: none; }

.telem-row-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.telem-row-dot.live {
  background: var(--accent);
  box-shadow: 0 0 5px var(--accent);
  animation: pulse 2s infinite;
}

.telem-row-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  flex: 1;
}

.telem-row-name.live { color: var(--text); }

.telem-row-age {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ─── Mobile stats row (hidden on desktop) ─────────────────── */
#mobile-stats-row {
  display: none;
}

/* ─── Mobile tweaks ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .brand-card {
    top: 10px;
    left: 10px;
  }

  .card {
    top: 56px;
    left: 10px;
    padding: 12px 14px 10px;
    min-width: 170px;
  }
  .runner-name { font-size: 22px; }
  #bottom-bar { padding-top: 20px; }
  .sponsor-card { top: 10px; right: 10px; }
  .leaflet-control-zoom { display: none !important; }
  .right-panel { display: none !important; }

  /* Mobile stats row: prominent 3×2 grid with labels */
  #mobile-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 0;
    padding: 10px 16px 8px;
    pointer-events: auto;
  }
  .mobile-stat {
    text-align: center;
  }
  .mobile-stat-value {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 18px;
    color: var(--text);
    line-height: 1;
  }
  .mobile-stat-unit {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 11px;
    color: var(--text-muted);
  }
  .mobile-stat-label {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 8px;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 1px;
  }

  /* Runner tiles: name + mileage on mobile, no dots */
  #runner-strip {
    gap: 6px !important;
    padding: 4px 10px !important;
  }
  .runner-tile {
    min-width: unset !important;
    padding: 4px 8px !important;
  }
  .runner-tile .tile-dot,
  .runner-tile .tile-info {
    display: none !important;
  }
  .runner-tile .tile-name {
    font-size: 10px !important;
  }
  .runner-tile .tile-dist {
    font-size: 8px !important;
    color: #44cc66 !important;
    opacity: 0.8 !important;
  }
}

/* ─── Admin button ──────────────────────────────────────────── */
.admin-btn {
  position: fixed;
  bottom: 370px;
  right: 12px;
  z-index: 10;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: color 0.2s, border-color 0.2s;
  text-decoration: none;
  display: block;
  line-height: 1;
}
.admin-btn:hover {
  color: var(--accent);
  border-color: rgba(245,196,0,0.5);
}

/* ─── Fun mode toggle button ─────────────────────────────────── */
.fun-btn {
  position: fixed;
  bottom: 320px;
  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;
}
.fun-btn:hover,
body.fun-mode .fun-btn {
  color: #FF6B6B;
  border-color: #FF6B6B;
  background: rgba(255, 107, 107, 0.12);
}

/* ─── Fun mode overrides ─────────────────────────────────────── */
body.fun-mode {
  --accent:      #FF6B6B;
  --accent-dim:  rgba(255, 107, 107, 0.35);
  --card-bg:     rgba(255, 255, 255, 0.92);
  --card-border: rgba(255, 107, 107, 0.5);
  --bg:          #f5f0e8;
  --text:        #1a1a1a;
  --text-muted:  #888;
  --font-display: 'Boogaloo', 'Outfit', sans-serif;
}

body.fun-mode .card,
body.fun-mode .waiting-card,
body.fun-mode .right-panel,
body.fun-mode #bottom-bar {
  color: #1a1a1a;
}

body.fun-mode .card-lockup,
body.fun-mode .card-header {
  color: #FF6B6B;
}

.fun-status-label {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: #FF6B6B;
  text-transform: uppercase;
  margin-bottom: 1px;
}

body.fun-mode .runner-name {
  color: #1a1a1a;
  font-size: 22px;
  letter-spacing: 0.05em;
}

body.fun-mode .leg-label {
  color: #FF6B6B;
}

body.fun-mode .card-row-value {
  color: #1a1a1a;
}

body.fun-mode .card-divider {
  border-color: rgba(255, 107, 107, 0.2);
}

body.fun-mode #bottom-bar {
  background: rgba(255, 255, 255, 0.92);
  border-top: 1px solid rgba(255, 107, 107, 0.3);
}

body.fun-mode .runner-tile {
  background: rgba(255, 107, 107, 0.06);
  border-color: rgba(255, 107, 107, 0.15);
  color: #1a1a1a;
}

body.fun-mode .tile-name,
body.fun-mode .tile-info,
body.fun-mode .tile-dist {
  color: #555;
}

/* emoji decorators along the route */
.fun-decorator {
  font-size: 48px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.35));
  pointer-events: none;
  user-select: none;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-5px); }
}

body.fun-mode .runner-head-outer {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.fun-mode .runner-head-emoji {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}

.runner-head-img {
  width: 115px;
  height: 115px;
  border-radius: 0;
  border: none;
  object-fit: cover;
  display: block;
}

body.fun-mode .runner-tile.active {
  background: rgba(255, 107, 107, 0.14);
  border-color: #FF6B6B;
}

body.fun-mode .runner-tile.active .tile-dot {
  background: #FF6B6B;
  box-shadow: 0 0 6px #FF6B6B;
  animation: none;
}

body.fun-mode .runner-tile.active .tile-name,
body.fun-mode .runner-tile.active .tile-info,
body.fun-mode .runner-tile.active .tile-dist {
  color: #FF6B6B;
}

body.fun-mode #progress-bar-fill {
  background: linear-gradient(90deg, #FF6B6B 0%, #c44dff 100%);
  box-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

body.fun-mode #elev-cursor {
  background: #FF6B6B;
  box-shadow: 0 0 6px #FF6B6B;
}

body.fun-mode #telemetry-btn.live,
body.fun-mode .telem-row-dot.live {
  background: #FF6B6B;
  box-shadow: 0 0 5px #FF6B6B;
}

body.fun-mode .telem-indicator.live {
  background: #FF6B6B;
  box-shadow: 0 0 5px #FF6B6B;
}

body.fun-mode .leg-label,
body.fun-mode .drawer-status {
  color: #FF6B6B;
}

/* ─── Side panel container (tabs + content) ─────────────────────────────────── */
#side-panel {
  position: fixed;
  left: 16px;
  bottom: 190px;
  width: 240px;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

/* Tab bar */
#panel-tabs {
  display: flex;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  border: 1px solid var(--card-border);
  border-bottom: none;
  flex-shrink: 0;
}
.panel-tab {
  flex: 1;
  background: rgba(245,196,0,0.1);
  border: none;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.12em;
  padding: 8px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: center;
  position: relative;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.panel-tab:not(:last-of-type) {
  border-right: 1px solid var(--card-border);
}
.panel-tab.active {
  color: var(--text-muted);
  background: var(--card-bg);
}
.panel-close-btn {
  display: none; /* hidden on desktop */
}

/* Notification dot on poll tab */
.poll-dot {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 4px var(--accent);
}
.poll-dot.hidden { display: none; }

/* Shared panel content area */
.panel-content {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 10px 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: 280px;
  overflow-y: auto;
  scrollbar-width: none;
}
.panel-content::-webkit-scrollbar { display: none; }
.panel-content.hidden { display: none; }

/* ─── Chat panel ─────────────────────────────────────────────────────────────── */
#chat-panel {
  gap: 0;
}

#chat-feed {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-bottom: 4px;
  scrollbar-width: none;
  min-height: 0;
}
#chat-feed::-webkit-scrollbar { display: none; }

.chat-msg {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  word-break: break-word;
}
.chat-vote {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}
.chat-vote .chat-msg-author {
  color: var(--text-muted);
}
.chat-msg-author {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}
.chat-empty {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-display);
  letter-spacing: 0.06em;
}

#chat-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  flex-shrink: 0;
  margin: 7px 0 6px;
}

#chat-name-row {
  display: flex;
  gap: 4px;
  margin-bottom: 5px;
  flex-shrink: 0;
}
#chat-name-first, #chat-name-initial {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 11px;
  padding: 4px 6px;
}
#chat-name-first { flex: 1; min-width: 0; }
#chat-name-initial { width: 52px; flex-shrink: 0; text-align: center; }

#chat-input-row {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 11px;
  padding: 5px 7px;
}
#chat-send {
  flex-shrink: 0;
  background: rgba(245,196,0,0.12);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  padding: 3px 8px;
  cursor: pointer;
  line-height: 1;
}
#chat-send:disabled { opacity: 0.4; cursor: default; }

/* ─── Poll panel ─────────────────────────────────────────────────────────────── */
#poll-panel {
  gap: 8px;
}

.poll-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ─── Mobile overrides for side panel ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Side panel: becomes bottom sheet */
  #side-panel {
    position: fixed;
    left: 12px;
    bottom: 250px;
    width: auto;
    z-index: 10;
    flex-direction: row;
  }
  #side-panel.sheet-open {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 55vh;
    flex-direction: column;
    z-index: 40;
  }

  /* Tabs: inline row when collapsed — bigger touch targets */
  #side-panel:not(.sheet-open) #panel-tabs {
    border-radius: 8px;
    border-bottom: 1px solid var(--card-border);
  }
  #side-panel:not(.sheet-open) .panel-tab {
    padding: 10px 16px;
    font-size: 11px;
    min-height: 40px;
  }
  #side-panel:not(.sheet-open) .panel-content {
    display: none !important;
  }

  /* Tabs: in sheet mode */
  #side-panel.sheet-open #panel-tabs {
    border-radius: 16px 16px 0 0;
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
  }
  #side-panel.sheet-open .panel-content {
    flex: 1;
    height: auto;
    border-radius: 0;
    border: none;
    border-top: none;
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }
  .panel-close-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 8px 12px;
    line-height: 1;
  }
  #side-panel.sheet-open .panel-close-btn {
    display: block;
  }

  #chat-name-first, #chat-name-initial, #chat-input {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 10px;
  }
  #chat-name-initial { width: 56px; }
  #chat-send { font-size: 18px; padding: 8px 12px; }

  /* Sponsor card: compact badge on mobile */
  .sponsor-card {
    display: block !important;
    padding: 5px 10px;
    line-height: 1.2;
  }
  .sponsor-card .sponsor-by {
    font-size: 8px;
  }
  .sponsor-card .sponsor-name {
    font-size: 13px;
  }
}

.poll-question {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  line-height: 1.25;
  flex-shrink: 0;
}
.poll-winner {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 16px;
  color: var(--accent);
  line-height: 1.15;
  flex-shrink: 0;
}
.poll-winner .winner-pct {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  margin-left: 4px;
}
.poll-winner.hidden { display: none; }
#poll-options { display: flex; flex-direction: column; gap: 5px; }

.poll-option-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 11px;
  padding: 7px 9px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.poll-option-btn:hover {
  border-color: rgba(245,196,0,0.5);
  background: rgba(245,196,0,0.06);
}

/* Result bars */
.poll-result { display: flex; flex-direction: column; gap: 3px; }
.poll-result-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text);
}
.poll-result-pct {
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
}
.poll-result-bar-bg {
  height: 5px;
  background: rgba(255,255,255,0.07);
  border-radius: 3px;
  overflow: hidden;
}
.poll-result-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.poll-result.my-pick .poll-result-label { color: var(--accent); }
.poll-result.my-pick .poll-result-bar-fill { background: var(--accent); }
.poll-result:not(.my-pick) .poll-result-bar-fill { background: rgba(245,196,0,0.35); }

.poll-countdown {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  flex-shrink: 0;
}
.poll-countdown.urgent { color: #ff6b6b; }
.poll-countdown.hidden { display: none; }

/* ─── Replay bar ───────────────────────────────────────────── */
.replay-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: rgba(8, 8, 8, 0.92);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  backdrop-filter: blur(10px);
}
.replay-bar.hidden { display: none; }
.replay-ctrl-btn {
  background: none;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  color: var(--accent);
  font-size: 18px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.replay-ctrl-btn:hover { background: rgba(245,196,0,0.1); }
.replay-progress-wrap { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.replay-progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
}
.replay-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}
.replay-time-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.replay-speed-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.replay-speed-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.replay-speed-val {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 13px;
  color: var(--accent);
  min-width: 50px;
  text-align: center;
}
#replay-speed-slider {
  width: 90px;
  accent-color: var(--accent);
}

