@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:       #08090b;
  --surf:     rgba(11, 13, 16, 0.90);
  --surf2:    rgba(11, 13, 16, 0.95);
  --brd:      rgba(255, 255, 255, 0.09);
  --brd-hi:   rgba(255, 255, 255, 0.15);

  /* Text — high enough contrast for all use cases */
  --text:     rgba(255, 255, 255, 0.88);
  --dim:      rgba(255, 255, 255, 0.55);
  --xdim:     rgba(255, 255, 255, 0.42);

  /* Accent */
  --green:    #39ff8c;
  --cyan:     #28d7ff;
  --yellow:   rgba(255, 204, 0,  0.90);
  --red:      rgba(255, 80,  80, 0.90);

  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow:    0 20px 60px rgba(0, 0, 0, 0.65), 0 4px 16px rgba(0, 0, 0, 0.45);
}

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

html, body {
  height: 100%; height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; height: 100dvh; width: 100%; position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; z-index: 1; }

/* ── Live marker (injected by map.js) ──────────────────────────────────── */
.live-marker {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--green);
  border: 2.5px solid rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 0 5px rgba(57, 255, 140, 0.14), 0 0 22px rgba(57, 255, 140, 0.35);
  transform: translate(-50%, -50%);
  animation: pulse-marker 2.2s ease-in-out infinite;
}
@keyframes pulse-marker {
  0%, 100% { box-shadow: 0 0 0 5px rgba(57,255,140,.14), 0 0 22px rgba(57,255,140,.35); }
  50%       { box-shadow: 0 0 0 9px rgba(57,255,140,.06), 0 0 32px rgba(57,255,140,.50); }
}

/* ── Glass surface ─────────────────────────────────────────────────────── */
.glass {
  background: var(--surf);
  border: 1px solid var(--brd);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  box-shadow: var(--shadow);
}

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  position: absolute; top: 14px; left: 14px; right: 14px;
  height: 48px; z-index: 20;
  display: flex; align-items: center;
  padding: 0 14px; gap: 10px;
  border-radius: var(--radius-lg);
}

.topbar-brand {
  font-size: 13px; font-weight: 600; letter-spacing: .08em;
  color: rgba(255, 255, 255, 0.60); text-transform: uppercase;
  white-space: nowrap; user-select: none;
  display: flex; align-items: center; gap: 9px;
}
.brand-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 8px var(--green);
  flex-shrink: 0;
}

.topbar-sep { width: 1px; height: 20px; background: var(--brd); flex-shrink: 0; }
.topbar-spacer { flex: 1; }

.topbar-controls { display: flex; align-items: center; gap: 6px; }
.topbar-actions  { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Live status in topbar (viewer only) */
.topbar-live {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-family: 'DM Mono', monospace;
  letter-spacing: .06em; color: var(--green); font-weight: 500;
}
.topbar-live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 7px var(--green);
}

/* ── Control buttons ───────────────────────────────────────────────────── */
.ctrl-btn {
  height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--brd-hi); background: rgba(255, 255, 255, 0.05);
  font-size: 11px; letter-spacing: .04em; color: var(--dim); font-weight: 500;
  cursor: pointer; display: flex; align-items: center; gap: 6px;
  font-family: inherit; white-space: nowrap; flex-shrink: 0;
  transition: background .14s, border-color .14s, color .14s;
}
.ctrl-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--brd-hi);
  color: var(--text);
}
.ctrl-btn:active:not(:disabled) { transform: translateY(1px); }
.ctrl-btn:disabled { opacity: .35; cursor: not-allowed; }

.ctrl-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }

.ctrl-btn--start { color: var(--green); border-color: rgba(57, 255, 140, 0.28); }
.ctrl-btn--start:hover:not(:disabled) { background: rgba(57,255,140,.08); }
.ctrl-btn--start .ctrl-dot { background: var(--green); box-shadow: 0 0 5px var(--green); }

.ctrl-btn--pause .ctrl-dot { background: var(--yellow); }
.ctrl-btn--stop  .ctrl-dot { background: var(--red); }

.ctrl-btn--ghost { color: var(--dim); }

/* File input hidden */
#gpxInput { display: none; }

/* ── Mode pill ─────────────────────────────────────────────────────────── */
.mode-pill {
  position: absolute; left: 14px; top: 76px; z-index: 20;
}
.mode-pill__inner {
  display: inline-flex; align-items: center; gap: 7px;
  height: 28px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid rgba(57, 255, 140, 0.20);
  background: var(--surf);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 10px; font-family: 'DM Mono', monospace;
  letter-spacing: .08em; color: var(--green); font-weight: 500;
  white-space: nowrap;
  transition: border-color .3s, color .3s;
}
.mode-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
  transition: background .3s, box-shadow .3s;
}
.mode-dot.dot--green  { background: var(--green);  box-shadow: 0 0 6px var(--green);  animation: blink 1.5s ease-in-out infinite; }
.mode-dot.dot--yellow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.mode-dot.dot--red    { background: var(--red);    box-shadow: 0 0 6px var(--red); }
.mode-dot.dot--dim    { background: rgba(255,255,255,.28); }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.35} }

.mode-pill__inner.pill--running { border-color: rgba(57,255,140,.28);  color: var(--green); }
.mode-pill__inner.pill--paused  { border-color: rgba(255,204,0,.25);   color: var(--yellow); }
.mode-pill__inner.pill--stopped { border-color: rgba(255,80,80,.25);   color: var(--red); }

/* ── Bottom HUD ────────────────────────────────────────────────────────── */
.hud {
  position: absolute; left: 14px; right: 14px; bottom: 16px;
  border-radius: var(--radius-lg); z-index: 20;
  padding: 14px 18px 16px;
  display: flex; gap: 20px;
  max-height: 200px;
}

/* Left: progress + stats */
.hud-left { width: 320px; min-width: 260px; flex-shrink: 0; }

.progress-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.progress-label {
  font-size: 9px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--xdim);
}
.progress-pct {
  font-family: 'DM Mono', monospace; font-size: 12px;
  font-weight: 500; color: var(--green);
}

.progress-bar {
  height: 3px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.10); margin-bottom: 14px;
  overflow: visible; position: relative;
}
.progress-fill {
  height: 3px; border-radius: 999px; position: relative;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  box-shadow: 0 0 8px rgba(57, 255, 140, 0.22);
  transition: width .35s ease;
}
.progress-fill::after {
  content: '';
  position: absolute; right: -3px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px var(--green);
  transition: opacity .35s;
}

.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px;
}
.stat-label {
  font-size: 9px; font-weight: 600; letter-spacing: .13em;
  text-transform: uppercase; color: var(--xdim); margin-bottom: 3px;
}
.stat-value {
  font-family: 'DM Mono', monospace;
  font-size: 22px; font-weight: 400; color: var(--text); line-height: 1;
}
.stat-value.acc { color: var(--green); }
.stat-unit {
  font-size: 11px; color: var(--dim); margin-left: 2px;
}

/* Divider */
.hud-divider {
  width: 1px; background: var(--brd); flex-shrink: 0; align-self: stretch;
}

/* Right: elevation chart */
.hud-right {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 7px;
}
.chart-label {
  font-size: 9px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--xdim);
}
.chart-wrap {
  flex: 1; border-radius: var(--radius-sm); overflow: hidden;
  background: rgba(0, 0, 0, 0.28); border: 1px solid rgba(255,255,255,.05);
  min-height: 64px; max-height: 140px; position: relative;
}
#elevationChart { width: 100%; height: 100%; display: block; }

.chart-marker {
  position: absolute; left: 0; top: 0;
  width: 1px; height: 100%;
  background: rgba(57, 255, 140, 0.45);
  pointer-events: none; box-shadow: 0 0 4px rgba(57,255,140,.3);
}
.chart-bubble {
  position: absolute; top: 5px;
  transform: translateX(-50%);
  padding: 2px 7px; border-radius: 999px;
  font-family: 'DM Mono', monospace; font-size: 10px; font-weight: 500;
  color: var(--green); background: rgba(0,0,0,.55);
  border: 1px solid rgba(57,255,140,.22);
  pointer-events: none; white-space: nowrap;
}


/* ── Toast ─────────────────────────────────────────────────────────────── */
#toastWrap {
  position: fixed; bottom: 22px; right: 18px; z-index: 9000;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: var(--radius-md);
  font-family: 'DM Mono', monospace; font-size: 11px; letter-spacing: .04em;
  border: 1px solid var(--brd); background: rgba(11,13,16,.96);
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px) scale(.97);
  transition: opacity .22s ease, transform .22s ease;
  max-width: 360px;
}
.toast--visible   { opacity: 1; transform: none; }
.toast--success   { border-color: rgba(57,255,140,.30); color: var(--green); }
.toast--error     { border-color: rgba(255,80,80,.30);  color: var(--red); }
.toast--info      { color: var(--dim); }

/* ── Mapbox overrides ──────────────────────────────────────────────────── */
.mapboxgl-ctrl-group {
  background: rgba(11,13,16,.88) !important;
  border: 1px solid var(--brd) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.5) !important;
  backdrop-filter: blur(10px) !important;
}
.mapboxgl-ctrl-group button {
  width: 34px !important; height: 34px !important;
  color: var(--dim) !important;
}
.mapboxgl-ctrl-group button:hover { color: var(--text) !important; }
.mapboxgl-ctrl-group button + button { border-top: 1px solid var(--brd) !important; }
.mapboxgl-ctrl-top-right { top: 80px !important; right: 14px !important; }
.mapboxgl-ctrl-top-right .mapboxgl-ctrl { margin: 0 0 8px !important; }
.mapboxgl-ctrl-attrib { display: none !important; }

/* ── Utility ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE (≤ 820px)
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 820px) {

  /* ── Viewer mobile: no topbar ── */
  html[data-role="viewer"] .topbar  { display: none; }
  html[data-role="viewer"] .mode-pill { top: 14px; left: 14px; }
  html[data-role="viewer"] .mapboxgl-ctrl-top-right { top: 14px !important; right: 14px !important; }

  /* ── HUD mobile: single column, no chart ── */
  .hud {
    left: 10px; right: 10px; bottom: 14px;
    padding: 14px 16px 20px;
    flex-direction: column; gap: 12px;
    border-radius: 20px 20px 0 0;
  }
  .hud-left   { width: 100%; min-width: 0; }
  .hud-divider { display: none; }
  .hud-right   { display: none; }
  .stat-value  { font-size: 24px; }

  /* Drag handle on mobile HUD */
  .hud::before {
    content: '';
    display: block; width: 36px; height: 3px;
    background: var(--brd-hi); border-radius: 2px;
    margin: -4px auto 10px; flex-shrink: 0;
  }

  /* ── Driver mobile: topbar wraps ── */
  html[data-role="driver"] .topbar {
    display: flex !important;
    flex-wrap: wrap; height: auto;
    padding: 10px 12px; gap: 8px;
    top: 0; left: 0; right: 0; border-radius: 0;
    border-top: none; border-left: none; border-right: none;
  }

  /* brand row */
  html[data-role="driver"] .topbar-brand {
    width: 100%; padding-top: 28px; /* below notch */
  }

  /* controls: full width, equal flex buttons */
  html[data-role="driver"] .topbar-controls {
    width: 100%; margin: 0; gap: 6px;
  }
  html[data-role="driver"] .topbar-controls .ctrl-btn {
    flex: 1; justify-content: center; height: 40px;
    border-radius: var(--radius-md);
  }

  /* actions: full width */
  html[data-role="driver"] .topbar-actions {
    width: 100%; margin: 0; gap: 6px;
  }
  html[data-role="driver"] .topbar-actions .ctrl-btn {
    flex: 1; justify-content: center; height: 36px;
    border-radius: var(--radius-md);
  }

  /* hide decorative items in driver mobile */
  html[data-role="driver"] .topbar-sep    { display: none; }
  html[data-role="driver"] .topbar-spacer { display: none; }
  html[data-role="driver"] .topbar-live   { display: none; }

  /* Mode pill + map controls offset below driver panel */
  html[data-role="driver"] .mode-pill {
    top: calc(var(--driver-panel-h, 172px) + 8px);
    left: 10px;
  }
  html[data-role="driver"] .mapboxgl-ctrl-top-right {
    top: calc(var(--driver-panel-h, 172px) + 8px) !important;
    right: 10px !important;
  }
}
