:root {
  /* brand palette
     yellow  #fbce3e  (Kingsway Care)
     blue    #009eeb  (Forescout)
     purple  #431f59  (Cyberbridge Services) */
  --purple: #431f59;
  --purple-deep: #31153f;
  --purple-soft: #5c3577;
  --blue: #009eeb;
  --blue-deep: #0072ab;
  --yellow: #fbce3e;
  --ink: #1c0f26;
  --text: #f5eefb;
  --muted: #c6b4d6;
  --card: rgba(67, 31, 89, 0.92);
  --line: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--purple-deep);
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  /* light fallback: if tiles are slow/blocked the map area stays light, not black */
  background: #eef0f2;
}

/* top bar */
#bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(49, 21, 63, 0.97), rgba(49, 21, 63, 0));
}
.bar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  flex: none;
  height: 28px;
  width: auto;
  color: var(--text); /* the SVG logo uses fill: currentColor */
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
}
#ride-name {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

.pill {
  flex: none;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--purple-soft);
  color: #e6d8f2;
}
.pill.live { background: var(--blue); color: var(--ink); }
.pill.paused { background: var(--yellow); color: var(--ink); }
.pill.waiting, .pill.offline { background: var(--purple-soft); color: #d9c9e6; }

#donate {
  flex: none;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  padding: 9px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(251, 206, 62, 0.45);
}

#countdown {
  position: absolute;
  top: calc(52px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: calc(100vw - 24px);
  padding: 8px 18px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 2px solid var(--yellow);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
#countdown .cd-label {
  display: block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
#countdown .cd-time {
  display: block;
  margin-top: 2px;
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--yellow);
}

#recenter {
  position: absolute;
  right: 14px;
  bottom: calc(38vh + 14px);
  z-index: 1000;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 15px;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

/* bottom panel */
#panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 1000;
  max-height: 38vh;
  overflow-y: auto;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--card);
  backdrop-filter: blur(8px);
  border-top: 2px solid var(--yellow);
  border-radius: 16px 16px 0 0;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 8px 10px;
  text-align: center;
}
.stats b { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; color: var(--text); }
.stats span { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

#pause-note {
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--yellow);
}

#blurb { margin: 12px 0 0; font-size: 0.9rem; color: var(--muted); line-height: 1.45; }

.sponsors {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.sponsors span {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: none;
}
.sponsors img { height: 20px; width: auto; flex: none; }
.sponsors img[alt="Forescout Technologies"] { height: 26px; border-radius: 5px; }

#photo-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-top: 12px;
  padding-bottom: 2px;
}
#photo-strip:empty { display: none; }
.thumb {
  flex: none;
  width: 92px;
  height: 68px;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
  cursor: pointer;
}

/* leaflet markers */
.rider-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 0 0 rgba(0, 158, 235, 0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 158, 235, 0.55); }
  70% { box-shadow: 0 0 0 18px rgba(0, 158, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 158, 235, 0); }
}
.photo-wrap, .finish-wrap {
  font-size: 20px;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 1px 3px rgba(28, 15, 38, 0.7));
}
.popup-img { width: 240px; max-width: 60vw; display: block; border-radius: 8px; }
.popup-cap { margin-top: 6px; font-weight: 600; color: var(--purple); }
.popup-time { margin-top: 2px; font-size: 0.75rem; color: #7a6a88; }

/* lightbox */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(28, 15, 38, 0.94);
  display: none; /* only the :not([hidden]) rule below turns this on */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
}
#lightbox:not([hidden]) { display: flex; }
#lightbox img { max-width: 96vw; max-height: 80vh; border-radius: 10px; }
#lightbox-cap { color: var(--text); font-weight: 600; text-align: center; }

@media (min-width: 760px) {
  #panel {
    left: auto;
    right: 14px;
    bottom: 14px;
    width: 340px;
    max-height: min(70vh, 560px);
    border-radius: 16px;
    border: 1px solid var(--line);
    border-top: 2px solid var(--yellow);
  }
  #recenter { bottom: 14px; right: 372px; }
}
