/* Runner — display CSS.
   Page bg is #000000 (transparent on the glasses' additive waveguide,
   so the real world shows through). UI tiles use #0a0a0f so they remain
   visible as opaque elements on the see-through canvas. */

:root {
  --bg-page:      #000000;
  --bg-surface:   #0a0a0f;
  --bg-surface-2: #1C1E21;
  --text:         #FFFFFF;
  --text-dim:     #E4E6EB;
  --text-muted:   #B0B3B8;
  --accent:       #00e5c8;
  --accent-glow:  rgba(0, 229, 200, 0.55);
  --coin:         #ffd24a;
  --danger:       #ff4d6d;
  --focus-glow:   rgba(0, 229, 200, 0.65);
}

* { box-sizing: border-box; }

html, body {
  width: 600px;
  height: 600px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg-page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

.app-root {
  width: 600px;
  height: 600px;
  padding: 8px;
  position: relative;
}

.screen {
  position: absolute;
  inset: 8px;
  display: flex;
  flex-direction: column;
}

.screen.hidden { display: none; }

/* ─────────── Start screen ─────────── */
.start-card {
  background: var(--bg-surface);
  border: 1px solid #1f2127;
  border-radius: 24px;
  padding: 32px 28px;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--accent);
  margin-bottom: 12px;
}

.start-card h1 {
  font-size: 32px;
  font-weight: 800;
  margin: 0 0 8px;
  line-height: 1.1;
}

.tagline {
  font-size: 15px;
  color: var(--text-dim);
  margin: 0 0 24px;
  max-width: 460px;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 0 0 32px;
  text-align: left;
  font-size: 15px;
  color: var(--text-dim);
}

.feature-list li {
  padding: 6px 0;
  display: flex;
  gap: 12px;
  align-items: center;
}

.feature-list .bullet {
  color: var(--accent);
  font-weight: 700;
}

/* Buttons + focus */
.primary {
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text);
  background: var(--bg-surface-2);
  border: 2px solid #2a2d33;
  border-radius: 16px;
  padding: 18px 32px;
  min-height: 64px;
  min-width: 240px;
  cursor: pointer;
  outline: none;
  transition:
    transform 475ms cubic-bezier(0.6, 0, 0.4, 1),
    border-color 300ms cubic-bezier(0.4, 0.04, 0.5, 1),
    box-shadow   300ms cubic-bezier(0.4, 0.04, 0.5, 1);
}

.focusable:focus,
.focusable:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-glow), 0 0 24px var(--accent-glow);
  transform: scale(0.96);
}

/* ─────────── Run screen ─────────── */
#run {
  padding: 0;
  inset: 0;
}

#map {
  position: absolute;
  inset: 0;
  width: 600px;
  height: 600px;
  background: #000;
}

/* MapLibre's default canvas gets a light bg in some Chromium versions — */
/* force-transparent above the WebGL canvas so the additive display works. */
.maplibregl-map { background: transparent !important; }
.maplibregl-canvas { background: transparent !important; }

/* Player marker — fixed at the centre of the map, never rotates. */
.player-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  margin-top: -28px;
  margin-left: -28px;
  pointer-events: none;
  z-index: 10;
}

/* Player dot — solid centre marker (no avatar). The pulsing ring around
   it conveys "live"; this is just the fixed point under the runner. */
.player-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin-top: -9px;
  margin-left: -9px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--bg-surface);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 0 12px rgba(0, 229, 200, 0.45);
}

/* Ghost marker — a small initials badge (we have no avatar). Rendered
   via maplibregl.Marker so it tracks the ghost's lat/lon as the map
   pans. Dimmer than the live runner; no pulse — it should feel
   "ambient", not "live". */
.ghost-marker {
  width: 36px;
  height: 36px;
  pointer-events: none;
}
.ghost-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(179, 157, 255, 0.85);
  background: rgba(20, 20, 28, 0.85);
  color: rgba(210, 200, 255, 0.95);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

/* Pulsing ring — single ::before-style element so we get an outward
   ring that fades as it expands without continuously animating the
   avatar image itself (image animation = re-rasterise per frame).
   2 s cycle is slow enough that it doesn't dominate the eye but fast
   enough to read as "live". */
.player-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  pointer-events: none;
  animation: player-pulse 2s ease-out infinite;
  transform-origin: center center;
  will-change: transform, opacity;
}

@keyframes player-pulse {
  0%   { transform: scale(1.0); opacity: 0.55; }
  100% { transform: scale(1.7); opacity: 0;   }
}

/* ── Approach gate — shown over the map until the player reaches the
   route start. The map stays visible behind it; metrics are hidden. */
.approach {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 18px 60px; pointer-events: none;
}
.approach.hidden { display: none; }
.approach-card {
  background: rgba(10, 10, 15, 0.82);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--accent); border-radius: 16px;
  padding: 16px 22px; text-align: center; max-width: 86%;
}
.approach-title { font-size: 18px; font-weight: 800; color: #fff; }
.approach-dist {
  margin-top: 4px; font-size: 26px; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.approach-hint { margin-top: 6px; font-size: 12px; color: #b0b3b8; }

/* While approaching, hide every in-run metric so nothing reads as live. */
#run.awaiting .hud,
#run.awaiting .leaderboard,
#run.awaiting .ghost-chip,
#run.awaiting .sprint-badge,
#run.awaiting .powerup-bar,
#run.awaiting .hud-status { display: none !important; }

.hud {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 16px 16px 0;
  pointer-events: none;
  gap: 12px;
}

.hud-top    { top: 8px; }
.hud-bottom { bottom: 8px; padding: 0 16px 16px; }

.hud-tile {
  background: rgba(10, 10, 15, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 16px;
  min-width: 130px;
  text-align: left;
}

.hud-tile-right { text-align: right; }

.hud-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.hud-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-status {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  background: rgba(10, 10, 15, 0.78);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 229, 200, 0.3);
  pointer-events: none;
}
.hud-status:empty { display: none; }

/* Pace HUD turns gold when we're inside the pace bonus zone. */
.hud-tile.in-zone {
  border-color: var(--coin);
  box-shadow: 0 0 14px rgba(255, 210, 74, 0.4);
}
.hud-tile.in-zone .hud-value { color: var(--coin); }

/* Sprint badge — sits top-centre below the DEMO/GPS status chip.
   Two states:
     .sprint-badge          → in zone but NOT qualifying (warning yellow,
                              gentle pulse to attract attention).
     .sprint-badge.active   → qualifying pace, ×2 earning (bright orange,
                              steady glow to confirm). */
.sprint-badge {
  position: absolute;
  top: 38px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  background: linear-gradient(180deg, rgba(255, 200, 60, 0.95), rgba(220, 160, 24, 0.95));
  color: #1a1206;
  padding: 5px 14px;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  font-size: 11px;
  pointer-events: none;
  box-shadow: 0 0 14px rgba(255, 200, 60, 0.45);
  animation: sprint-pulse 600ms ease-in-out infinite alternate;
  white-space: nowrap;
  max-width: 540px;
}
.sprint-badge.active {
  background: linear-gradient(180deg, rgba(255, 139, 61, 0.95), rgba(231, 99, 24, 0.95));
  color: #ffffff;
  box-shadow: 0 0 16px rgba(255, 139, 61, 0.65);
  animation: none;     /* steady — confirms you're locked in */
}
.sprint-badge.hidden { display: none; }
@keyframes sprint-pulse {
  from { transform: translateX(-50%) scale(1); }
  to   { transform: translateX(-50%) scale(1.06); }
}

/* Power-up chip bar — between top HUD and the centre of the map. */
.powerup-bar {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.powerup-chip {
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid;
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.powerup-chip-icon { font-size: 13px; }
.powerup-chip.multiplier { border-color: #ff4d8d; color: #ff4d8d; }

/* Toast — short text notification at top-centre. */
.toast {
  position: absolute;
  top: 110px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(10, 10, 15, 0.92);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
  z-index: 20;
  text-align: center;
  max-width: 380px;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.multiplier { border-color: #ff4d8d; color: #ff4d8d; }
.toast.pace-bonus { border-color: var(--coin); color: var(--coin); }
.toast.sprint     { border-color: #ff8b3d; color: #ff8b3d; }

/* Mini leaderboard — appears under the pace tile in the top-right when
   a ghost is loaded. Two rows, leader on top, with the trailer's diff
   shown next to their name. Names and diff text are populated live by
   drawLeaderboard() in app.js. */
.leaderboard {
  position: absolute;
  /* Sits below the top HUD row (which is ~90 px tall: 8 px offset +
     16 px container padding + ~65 px tile) with a little breathing
     room. Was overlapping the pace tile at top: 66 px. */
  top: 110px;
  left: 16px;
  width: 224px;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
}
.leaderboard.hidden { display: none; }
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.leaderboard-pos {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  min-width: 12px;
  text-align: center;
}
.leaderboard-name { flex: 1; }
.leaderboard-diff {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.leaderboard-row.leader {
  color: var(--accent);
}
.leaderboard-row.leader .leaderboard-pos {
  color: var(--coin);
}

/* Ghost differential chip — sits at bottom-centre above the bottom HUD
   tiles. Colour-coded by lead/lag so the runner can see at a glance
   whether to push harder or coast. */
.ghost-chip {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 10, 15, 0.85);
  border: 2px solid #b39dff;
  color: #b39dff;
  padding: 10px 28px;
  border-radius: 18px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}
.ghost-chip.hidden { display: none; }
.ghost-chip.ahead  { border-color: var(--accent); color: var(--accent); }
.ghost-chip.behind { border-color: var(--danger); color: var(--danger); }
.ghost-chip.tied   { border-color: var(--text); color: var(--text); }

.coin-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  /* Offset upward so the +10 sits above the player triangle (which is
     32px tall, centred at 50%). 56px puts the flash baseline ~40 px
     above the marker's tip with a comfortable gap. */
  transform: translate(-50%, calc(-50% - 56px)) scale(0.6);
  font-size: 56px;
  font-weight: 900;
  color: var(--coin);
  text-shadow: 0 0 24px rgba(255, 210, 74, 0.7);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 200ms ease-out,
    transform 350ms cubic-bezier(0.2, 0.9, 0.3, 1);
}
.coin-flash.show {
  opacity: 1;
  transform: translate(-50%, calc(-50% - 56px)) scale(1);
}

/* ─────────── End screen ─────────── */
.end-card {
  background: var(--bg-surface);
  border: 1px solid #1f2127;
  border-radius: 24px;
  padding: 20px 22px 18px;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.end-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.end-stat {
  background: var(--bg-surface-2);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}
.end-stat-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.end-stat-value {
  display: block;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.end-score-row {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(180deg, #1a1a22, #0e0e14);
  border-radius: 12px;
  border: 1px solid var(--accent);
}
.end-score-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
}
.end-score-value {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.end-score-value.new-best::after {
  content: 'NEW BEST';
  display: inline-block;
  margin-left: 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--coin);
  background: rgba(255, 210, 74, 0.18);
  padding: 3px 7px;
  border-radius: 6px;
  vertical-align: middle;
}

.end-section-title {
  width: 100%;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-top: 4px;
}

.achievement-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  flex: 1 1 auto;
  overflow-y: auto;
  align-content: start;
}
.achievement {
  background: var(--bg-surface-2);
  border: 1px solid #2a2d33;
  border-radius: 10px;
  padding: 7px 9px;
  text-align: left;
  position: relative;
}
.achievement.unlocked {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(0, 229, 200, 0.10), var(--bg-surface-2));
}
.achievement.newly-unlocked {
  border-color: var(--coin);
  box-shadow: 0 0 12px rgba(255, 210, 74, 0.45);
}
.achievement.locked {
  opacity: 0.45;
}
.achievement-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
  line-height: 1.1;
}
.achievement.locked .achievement-title { color: var(--text-muted); }
.achievement-check {
  font-size: 12px;
  color: var(--accent);
}
.achievement.newly-unlocked .achievement-check { color: var(--coin); }
.achievement.locked .achievement-check { color: var(--text-muted); }
.achievement-desc {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.25;
}
