:root {
  --bg: #0b0f14; --card: #141b24; --text: #fff; --muted: #9aa7b6; --accent: #22d3a6; --amber: #f5b942;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
#root {
  min-height: 100%; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen {
  flex: 1; width: 100%; max-width: 420px; margin: 0 auto; padding: 16px 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
}
#permission { text-align: center; }
#permission h1 { margin: 0; font-size: 1.65rem; }
#permission p { margin: 0; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.btn-primary, .btn-outline, .chip {
  font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn-primary { background: var(--accent); color: #000; border: 0; border-radius: 999px; padding: 12px 28px; font-weight: 600; }
.btn-outline { background: none; color: var(--accent); border: 1px solid #3a4452; border-radius: 999px; padding: 10px 24px; }
.btn-outline:hover { border-color: var(--accent); }

.toggle { display: flex; gap: 8px; align-items: center; }
.chip {
  height: 32px; padding: 0 16px; border-radius: 8px; font-size: 14px; font-weight: 500;
  background: none; color: var(--muted); border: 1px solid #3a4452;
}
.chip.is-on[data-unit] { background: var(--accent); color: #000; border-color: var(--accent); }
.chip-mini.is-on { color: var(--accent); border-color: var(--accent); }
.chip-mini:not(.is-on) { text-decoration: line-through; }

.gauge-wrap { width: 100%; }
#gauge { display: block; width: 100%; height: auto; }
#gauge .num { fill: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
#gauge .unit { fill: #9aa7b6; }
#gauge .lbl { fill: #8593a3; font-weight: 500; }

.gps {
  display: inline-flex; align-items: center; gap: 8px; background: var(--card);
  border-radius: 999px; padding: 8px 14px; font-size: 13px;
}
.gps .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.gps.good .dot { background: var(--accent); }

.stats { display: flex; gap: 10px; width: 100%; }
.stat {
  flex: 1; min-width: 0; background: var(--card); border-radius: 16px; padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat .k { font-size: 11px; letter-spacing: 1px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .u { font-size: 11px; color: var(--muted); }
.note { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }

.foot { text-align: center; padding: 8px 16px 16px; font-size: 14px; color: var(--muted); }
.foot a { color: var(--accent); }

/* Landscape phones: gauge left, controls right. */
@media (orientation: landscape) and (max-height: 520px) {
  #main { max-width: none; flex-direction: row; flex-wrap: wrap; gap: 12px 24px; align-content: center; justify-content: center; }
  .gauge-wrap { flex: 0 1 min(46vw, 60vh * 1.15); width: auto; }
  .toggle, .gps, .stats, .btn-outline, .note { flex: 0 0 auto; }
  #main > * { max-width: 100%; }
}

/* Mini view: a compact speed-only display, used in the Picture-in-Picture window and as an in-page fallback. */
.mini {
  position: fixed; inset: 0; z-index: 10; background: var(--bg);
  display: flex; align-items: center; justify-content: center; container-type: size;
}
.mini-read { display: flex; align-items: baseline; gap: 0.12em; font-size: min(26cqw, 60cqh); }
.mini-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-unit { font-size: 0.4em; color: var(--muted); }
.mini-close {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid #3a4452; background: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer;
}
.in-pip .mini-close { display: none; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
