/* ============ EnduroGPX design system ============ */
:root {
  --bg: #0b0e12;
  --glass: rgba(16, 19, 24, .66);
  --glass-strong: rgba(14, 17, 22, .86);
  --stroke: rgba(255, 255, 255, .09);
  --stroke-strong: rgba(255, 255, 255, .16);
  --text: #f2f5f8;
  --muted: #8d99a6;
  --accent: #ff6b1a;
  --accent-grad: linear-gradient(135deg, #ff7a26, #ff5500);
  --danger: #ff453a;
  --blue: #0a84ff;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --shadow: 0 10px 34px rgba(0, 0, 0, .45);
  --blur: blur(18px) saturate(1.4);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
#map { position: absolute; inset: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.45; }
button { font-family: inherit; }

svg { pointer-events: none; }
.iconbtn svg, .fab svg, .vis svg { width: 21px; height: 21px; fill: none;
  stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar { position: absolute; top: calc(var(--safe-top) + 12px); left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  z-index: 20; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.iconbtn { display: inline-flex; align-items: center; gap: 8px;
  background: var(--glass); color: var(--text); border: 1px solid var(--stroke);
  border-radius: 999px; padding: 10px 16px 10px 13px;
  font-size: 14px; font-weight: 600; letter-spacing: .01em; cursor: pointer;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow); transition: background .15s; }
.iconbtn:active { background: var(--glass-strong); }
.pill { background: var(--glass); border: 1px solid var(--stroke); border-radius: 999px;
  padding: 7px 14px; font-size: 12px; font-weight: 600; color: var(--muted);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); }

/* ---------- floating action buttons ---------- */
.sidebtns { position: absolute; right: 12px; bottom: calc(var(--safe-bottom) + 108px);
  display: flex; flex-direction: column; gap: 10px; z-index: 20; }
.fab { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--stroke);
  background: var(--glass); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow); transition: background .15s, border-color .15s, color .15s; }
.fab.active { background: var(--accent-grad); border-color: transparent; color: #fff;
  box-shadow: 0 6px 22px rgba(255, 90, 0, .45); }
.fab.rec .rec-dot { width: 15px; height: 15px; border-radius: 50%; background: var(--danger);
  box-shadow: 0 0 0 4.5px rgba(255, 255, 255, .22); transition: border-radius .2s, transform .2s; }
.fab.rec.active { background: rgba(255, 69, 58, .22); border-color: rgba(255, 69, 58, .5);
  animation: pulse 1.5s infinite; }
.fab.rec.active .rec-dot { border-radius: 3.5px; transform: scale(.85); }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px rgba(255, 69, 58, .18); } }

/* ---------- panels ---------- */
.panel { position: absolute; top: 0; left: 0; bottom: 0; width: min(390px, 100%);
  background: var(--glass-strong); z-index: 40;
  padding: calc(var(--safe-top) + 18px) 20px calc(var(--safe-bottom) + 18px);
  overflow-y: auto; backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border-right: 1px solid var(--stroke); box-shadow: 18px 0 60px rgba(0, 0, 0, .45); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.close { background: rgba(255, 255, 255, .07); border: none; color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }

.btn { background: rgba(255, 255, 255, .08); color: var(--text);
  border: 1px solid var(--stroke); border-radius: var(--r-sm);
  padding: 12px 18px; font-size: 14px; font-weight: 600; letter-spacing: .01em;
  cursor: pointer; display: inline-block; transition: background .15s; }
.btn:active { background: rgba(255, 255, 255, .14); }
.btn.primary { background: var(--accent-grad); border-color: transparent; color: #fff;
  box-shadow: 0 4px 16px rgba(255, 90, 0, .35); }
.btn.danger { background: transparent; border-color: rgba(255, 69, 58, .45); color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
hr { border: none; border-top: 1px solid var(--stroke); margin: 18px 0; }

/* ---------- track list ---------- */
.track-list { list-style: none; margin: 0; padding: 0; }
.track-list li { display: flex; align-items: center; gap: 12px; padding: 13px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, .06); cursor: pointer; }
.track-list .dot { width: 10px; height: 26px; border-radius: 5px; flex: none; }
.track-list .tname { flex: 1; min-width: 0; }
.track-list .tname strong { display: block; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.track-list .tname span { font-size: 12px; color: var(--muted); }
.track-list .vis { background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px; display: flex; }
.track-list .vis.on { color: var(--accent); }

/* ---------- progress ---------- */
.progress { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, .09);
  overflow: hidden; margin: 12px 0 8px; }
.progress-fill { height: 100%; width: 0; background: var(--accent-grad); transition: width .2s; }

/* ---------- bottom sheet ---------- */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--glass-strong);
  border-radius: var(--r-lg) var(--r-lg) 0 0; z-index: 30;
  padding: 16px 20px calc(var(--safe-bottom) + 14px);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border-top: 1px solid var(--stroke); box-shadow: 0 -14px 50px rgba(0, 0, 0, .5); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-head strong { font-size: 17px; font-weight: 700; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statrow { display: flex; gap: 20px; flex-wrap: wrap; margin: 12px 0;
  font-size: 12px; color: var(--muted); }
.statrow b { display: block; color: var(--text); font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
#ele-profile { width: 100%; background: rgba(255, 255, 255, .05); border-radius: var(--r-sm); }

/* ---------- draw bar ---------- */
.drawbar { position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 22px); background: var(--glass);
  border: 1px solid var(--stroke); border-radius: 999px; padding: 8px 10px 8px 18px;
  display: flex; align-items: center; gap: 8px; z-index: 30;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow); }
.drawbar .btn { border-radius: 999px; padding: 9px 15px; font-size: 13px; }
#draw-stats { font-weight: 700; font-size: 14px; min-width: 56px;
  font-variant-numeric: tabular-nums; }
.btn.snap { opacity: .5; }
.btn.snap.on { opacity: 1; background: rgba(255, 107, 26, .16);
  border-color: rgba(255, 107, 26, .55); color: var(--accent); }
.btn.snap.busy { animation: pulse 1s infinite; }

/* ---------- live HUD ---------- */
.hud { position: absolute; left: 10px; right: 10px; bottom: calc(var(--safe-bottom) + 14px);
  background: var(--glass); border: 1px solid var(--stroke); border-radius: var(--r-lg);
  z-index: 30; padding: 14px 16px 12px;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); box-shadow: var(--shadow); }
.hud-grid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; }
.hud-grid span { display: block; font-size: 27px; font-weight: 800; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; }
.hud-grid label { font-size: 10px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .12em; }
.hud-actions { display: flex; justify-content: center; margin-top: 10px; }
.offroute { margin-top: 10px; text-align: center; background: var(--danger); color: #fff;
  font-weight: 800; border-radius: var(--r-sm); padding: 9px; letter-spacing: .06em;
  animation: pulse 1s infinite; }

/* ---------- toast ---------- */
.toast { position: absolute; top: calc(var(--safe-top) + 66px); left: 50%;
  transform: translateX(-50%); background: var(--glass-strong); border: 1px solid var(--stroke);
  color: var(--text); padding: 11px 18px; border-radius: 999px; z-index: 60;
  font-size: 13px; font-weight: 500; max-width: 88%; text-align: center;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); box-shadow: var(--shadow); }

/* ---------- ride telemetry ---------- */
/* While telemetry is open the map chrome gets out of the way: no FABs, HUD,
   draw bar or scale bar can overlap the gauges. */
.tele-open .sidebtns, .tele-open .hud, .tele-open .drawbar,
.tele-open .maplibregl-ctrl-bottom-left { display: none !important; }
.tele-open .topbar { z-index: 85; }

.telemetry { position: absolute; z-index: 80; pointer-events: none;
  display: flex; align-items: flex-end; justify-content: center; gap: 10px; }
.telemetry > * { pointer-events: auto; }
.tele-chip { flex-shrink: 0; background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--r-lg); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .07); }
/* small control bar above the gauges */
.tele-bar { position: absolute; left: 0; right: 0; bottom: calc(100% + 10px);
  display: flex; justify-content: flex-end; gap: 8px; pointer-events: none; }
.tele-bar > * { pointer-events: auto; }
.tele-pill { height: 38px; min-width: 38px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--stroke); background: var(--glass);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .08em; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.tele-pill .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.tele-pill.active { background: rgba(255, 69, 58, .22); border-color: rgba(255, 69, 58, .55);
  animation: pulse 1.5s infinite; }
.tele-pill.active .rec-dot { border-radius: 2px; }

/* gauges */
.gauge-chip, .speed-chip { position: relative; text-align: center; cursor: pointer;
  user-select: none; -webkit-user-select: none; }
.gauge-chip { width: clamp(96px, 28vw, 132px); padding: 8px 6px 9px; }
.speed-chip { width: clamp(112px, 34vw, 156px); padding: 8px 6px 9px; }
.gauge-chip svg, .speed-chip svg { width: 100%; display: block; }
.g-track { fill: none; stroke: rgba(255, 255, 255, .10); stroke-width: 7; stroke-linecap: round; }
.g-ticks line { stroke: rgba(255, 255, 255, .28); stroke-width: 1.5; stroke-linecap: round; }
.g-ticks line.zero { stroke: rgba(255, 255, 255, .85); stroke-width: 2; }
.g-arc { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(255, 107, 26, .4)); }
.g-arc.pitch { stroke: #38d6ff; filter: drop-shadow(0 0 4px rgba(56, 214, 255, .35)); }
.g-arc.speed { stroke: #fff; filter: none; }
.g-arc.warn { stroke: var(--danger); filter: drop-shadow(0 0 5px rgba(255, 69, 58, .5)); }
.g-limit line { stroke: rgba(255, 69, 58, .75); stroke-width: 2; stroke-linecap: round; }
.g-peak line { stroke: rgba(255, 255, 255, .75); stroke-width: 2; stroke-linecap: round; }
.g-toggle { background: none; border: 1px solid transparent; border-radius: 999px; padding: 2px 8px;
  color: rgba(255,255,255,.5); cursor: pointer; }
.g-toggle.on { color: var(--accent); border-color: rgba(255,107,26,.4); }
.g-num { position: absolute; left: 0; right: 0; top: 30%;
  font-size: clamp(22px, 7.4vw, 32px); font-weight: 800; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; color: #fff; line-height: 1; }
.g-num i { font-style: normal; font-size: .5em; font-weight: 600; color: rgba(255,255,255,.55);
  vertical-align: top; margin-left: 1px; }
.s-num { position: absolute; left: 0; right: 0; top: 27%;
  font-size: clamp(32px, 11vw, 48px); font-weight: 800; letter-spacing: -.045em;
  font-variant-numeric: tabular-nums; color: #fff; line-height: 1;
  text-shadow: 0 0 20px rgba(255, 255, 255, .2); }
.g-label { position: absolute; left: 0; right: 0; top: 60%; font-size: 9.5px;
  letter-spacing: .28em; text-transform: uppercase; color: rgba(255, 255, 255, .55); }
.g-sub { margin-top: 2px; font-size: 10px; color: rgba(255, 255, 255, .5);
  font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.g-sub span { color: #fff; font-weight: 700; }
.tele-chip.calibrating { outline: 2px solid var(--accent); outline-offset: -2px;
  animation: pulse 1s infinite; }

/* portrait: one row above the attribution bar */
@media (orientation: portrait) {
  .telemetry { left: 8px; right: 8px; bottom: calc(var(--safe-bottom) + 30px);
    gap: clamp(6px, 2.5vw, 12px); }
}
/* landscape: gauges spread to the corners, speed centred, map stays visible between */
@media (orientation: landscape) {
  .telemetry { left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    bottom: calc(var(--safe-bottom) + 30px); justify-content: space-between; }
  .gauge-chip { width: clamp(84px, 30vh, 120px); }
  .speed-chip { width: clamp(104px, 38vh, 150px); }
  .g-num { font-size: clamp(20px, 8vh, 30px); }
  .s-num { font-size: clamp(30px, 12vh, 46px); }
}
#tele-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% + 58px);
  background: var(--glass-strong); padding: 7px 14px; border-radius: 999px; margin: 0;
  white-space: nowrap; border: 1px solid var(--stroke); max-width: 95vw; overflow: hidden;
  text-overflow: ellipsis; }

/* ---------- modal ---------- */
.modal { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.modal-box { background: var(--glass-strong); border: 1px solid var(--stroke);
  border-radius: var(--r-lg); padding: 20px; width: min(340px, 100%);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.modal-box p { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.modal-input { width: 100%; background: rgba(255, 255, 255, .07);
  border: 1px solid var(--stroke-strong); color: var(--text);
  border-radius: var(--r-sm); padding: 12px 14px; font-size: 16px; outline: none; }
.modal-input:focus { border-color: var(--accent); }

/* ---------- location marker ---------- */
.loc-wrap { position: relative; width: 24px; height: 24px; }
.loc-marker { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 17px; height: 17px; border-radius: 50%; background: var(--blue);
  border: 2.5px solid #fff; box-shadow: 0 0 0 5px rgba(10, 132, 255, .28), 0 2px 8px rgba(0,0,0,.4); }
.loc-arrow { position: absolute; left: 50%; top: -13px; transform: translateX(-50%);
  width: 0; height: 0; border: 7px solid transparent; border-bottom: 12px solid var(--blue); }

.maplibregl-ctrl-attrib { font-size: 10px; background: rgba(255,255,255,.75) !important; }
