/* Spectator UI. Mobile-first: most people watching a race are on a phone,
   outdoors, in sunlight, checking it for five seconds at a time. Big numbers,
   high contrast, no chrome that isn't load-bearing. */

:root {
  --bg: #0f1115;
  --panel: #181c23;
  --panel-2: #21262f;
  --line: #2d3440;
  --text: #f2f4f7;
  --muted: #98a2b3;
  --accent: #ff6b35;
  --route: #4a9eff;
  --accent-2: #4a9eff;
  --good: #35d07f;
  --warn: #ffb020;
  --bad: #ff4d5e;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ------------------------------------------------------------------- header */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

header .who {
  min-width: 0;
  flex: 1;
}

header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header .sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  white-space: nowrap;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.status.live .dot { background: var(--good); animation: pulse 2s ease-in-out infinite; }
.status.live { color: var(--good); }
.status.stale .dot { background: var(--warn); }
.status.stale { color: var(--warn); }
.status.done .dot { background: var(--accent-2); }
.status.done { color: var(--accent-2); }
.status.error .dot { background: var(--bad); }
.status.error { color: var(--bad); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------------------------------------------------------------------- map */

#map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  background: #1a1d23;
}

.minimap-canvas {
  display: block;
  cursor: grab;
  touch-action: none;
}

.minimap-attribution {
  position: absolute;
  right: 0;
  bottom: 0;
  font-size: 10px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.82);
  color: #333;
  border-top-left-radius: 6px;
}

.minimap-attribution a { color: #0645ad; }

.map-buttons {
  position: absolute;
  left: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.map-buttons button {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(24, 28, 35, 0.92);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.map-buttons button:hover { background: var(--panel-2); }
.map-buttons button.on { background: var(--accent); border-color: var(--accent); color: #14161a; }

/* Zoom controls. Wheel and pinch already work, but on a phone in sunlight
   a spectator wants a target they can hit without thinking. */
.zoom-buttons {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.zoom-buttons button {
  width: 40px;
  height: 40px;
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(24, 28, 35, 0.92);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.zoom-buttons button:active { background: var(--accent); color: #14161a; }

/* Current street, for working out which corner to stand on. */
.street {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 5;
  max-width: calc(100% - 90px);
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(24, 28, 35, 0.92);
  color: var(--text);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.street[hidden] { display: none; }

.street::before {
  content: "▸ ";
  color: var(--accent);
}

.banner {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 6;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  background: var(--warn);
  color: #14161a;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.banner[hidden] { display: none; }

/* ------------------------------------------------------------------ metrics */

.metrics {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
}

.metric {
  background: var(--panel);
  padding: 10px 8px 11px;
  text-align: center;
  min-width: 0;
}

.metric .label {
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}

.metric .value {
  font-family: var(--mono);
  font-size: clamp(17px, 5.2vw, 25px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric .unit {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 500;
}

.metric.wide { grid-column: span 2; }
.metric .value.accent { color: var(--accent); }
.metric .value.dim { color: var(--muted); }

/* progress bar under the metrics */

.progress {
  flex: 0 0 auto;
  height: 4px;
  background: var(--panel-2);
  position: relative;
  overflow: hidden;
}

.progress .fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.6s ease;
}

/* ------------------------------------------------------------------- drawer */

.drawer {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  max-height: 42vh;
  display: flex;
  flex-direction: column;
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  user-select: none;
  flex: 0 0 auto;
}

.drawer-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  flex: 1;
}

.drawer-head .chev {
  color: var(--muted);
  font-size: 11px;
  transition: transform 0.2s;
}

.drawer.open .drawer-head .chev { transform: rotate(180deg); }

.drawer-body {
  display: none;
  overflow-y: auto;
  padding: 0 14px 14px;
  -webkit-overflow-scrolling: touch;
}

.drawer.open .drawer-body { display: block; }

table.splits {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.splits th {
  text-align: right;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
}

table.splits th:first-child, table.splits td:first-child { text-align: left; }

table.splits td {
  padding: 7px 6px;
  text-align: right;
  font-family: var(--mono);
  border-bottom: 1px solid rgba(45, 52, 64, 0.5);
}

table.splits tr.finish td {
  color: var(--accent);
  font-weight: 650;
}

table.splits td.fast { color: var(--good); }
table.splits td.slow { color: var(--warn); }

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 14px 0;
  text-align: center;
}

/* -------------------------------------------------------------------- notify */

.notify-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 2px;
  flex-wrap: wrap;
}

.notify-row button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #14161a;
  cursor: pointer;
}

.notify-row button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.notify-row button:disabled { opacity: 0.45; cursor: default; }

.notify-row .hint {
  font-size: 12px;
  color: var(--muted);
  flex-basis: 100%;
  line-height: 1.45;
}

.notify-row select {
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

/* -------------------------------------------------------------- wide screens */

@media (min-width: 860px) {
  #app {
    display: grid;
    grid-template-columns: 1fr 360px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "header header"
      "map    side";
  }

  header { grid-area: header; }

  #map-wrap { grid-area: map; }

  .side {
    grid-area: side;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--line);
    overflow: hidden;
  }

  .metrics { grid-template-columns: repeat(2, 1fr); border-top: 0; }
  .metric .value { font-size: 24px; }
  .drawer { max-height: none; flex: 1 1 auto; }
  .drawer-body { display: block; }
  .drawer-head { cursor: default; }
  .drawer-head .chev { display: none; }
}

@media (max-width: 859px) {
  .side { display: contents; }
}

/* ─── spectator extras: tips, myth busting, trivia, byline ─────────────────── */

.panel {
  margin: 14px 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel-foot {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

/* Where to stand, and when */
.catch-list { display: flex; flex-direction: column; gap: 8px; }
.catch-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 9px 11px;
  background: var(--bg);
  border-radius: 8px;
}
.catch-when {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.catch-what { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.catch-what .muted { color: var(--muted); font-size: 12px; }
.catch-weather {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.catch-tip {
  margin-top: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-radius: 0 8px 8px 0;
}
.catch-note {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* Myths */
.myth {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.myth:last-child { border-bottom: 0; }
.myth summary {
  cursor: pointer;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.45;
  list-style: none;
}
.myth summary::-webkit-details-marker { display: none; }
.myth summary::after {
  content: " ›";
  color: var(--muted);
}
.myth[open] summary::after { content: " ˅"; }
.myth-tag {
  display: inline-block;
  margin-right: 7px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  vertical-align: 1px;
}
.myth p {
  margin: 9px 0 2px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}

/* Trivia */
#trivia p {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.6;
  min-height: 4.2em;
}

.byline {
  margin: 22px 12px 28px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}
.byline strong { color: var(--text); font-weight: 600; }

/* Race-time predictions */
.predict { margin-top: 18px; }
.predict-head {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.predict-table { width: 100%; border-collapse: collapse; }
.predict-table td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.predict-table tr:last-child td { border-bottom: 0; }
.predict-table tr.faint td { opacity: 0.55; }
.predict-table .pl { font-size: 14px; font-weight: 600; }
.predict-table .pt {
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--accent);
  white-space: nowrap;
}
.predict-table .pp {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--muted);
  padding-left: 12px;
  white-space: nowrap;
}
.predict-table .pn {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding-left: 10px;
}

/* How often positions actually arrive — stops a slow ping looking like a fault. */
.cadence {
  margin: 8px 12px 0;
  padding: 8px 11px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* Vehicle mode — the tracker is in a car, not on foot. */
.mode-banner {
  margin: 8px 12px 0;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #0f1115;
  background: var(--route);
  border-radius: 8px;
}
body.is-driving .value.accent { color: #4a9eff; }
.predict-table .pl .muted { color: var(--muted); font-weight: 400; }

/* Nothing live: an old outing must not masquerade as a current one. */
.stale-event {
  margin: 10px 12px 0;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stale-event strong { color: var(--text); }
/* Hide the live readouts entirely rather than showing yesterday's numbers. */
body.is-stale-event #map-wrap,
body.is-stale-event .metrics,
body.is-stale-event .progress,
body.is-stale-event #catch,
body.is-stale-event .drawer { display: none; }
