:root {
  --bg: #000000;
  --fg: #ffffff;
  --dim: #6b6b6b;
  --accent: #00e676;
  --danger: #ff5252;
  --btn-bg: #1a1a1a;
  --btn-border: #2e2e2e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  /* min-height (not height) so the page grows and scrolls when content is tall,
     but still centers vertically when it fits. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.25rem, 4vh, 2.5rem);
  padding: calc(env(safe-area-inset-top) + 1.5rem) 1.25rem
    calc(env(safe-area-inset-bottom) + 1.5rem);
  text-align: center;
}

/* Hero speed number */
.speed-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
}

.speed {
  font-size: clamp(7rem, 42vw, 18rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  transition: color 0.25s ease, text-shadow 0.25s ease;
}

.unit {
  margin-top: 0.4rem;
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 600;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--dim);
  padding-left: 0.35em;
}

/* Max speed */
.max-block {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.max-label {
  font-size: 0.85rem;
  letter-spacing: 0.3em;
  color: var(--dim);
}

.max-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.max-unit {
  font-size: 0.9rem;
  color: var(--dim);
}

/* Trip readout: distance + elapsed time */
.trip-block {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  font-variant-numeric: tabular-nums;
}

.trip-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.trip-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.trip-unit {
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--dim);
}

.trip-divider {
  width: 1px;
  height: 2.2rem;
  background: var(--btn-border);
}

/* Continuous-driving (fatigue) timer */
.drive-timer {
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.drive-timer.warn {
  color: var(--danger);
  font-weight: 700;
}

/* Status line */
.status {
  min-height: 1.2em;
  font-size: 0.9rem;
  color: var(--dim);
  max-width: 22rem;
}

.status.error {
  color: var(--danger);
}

/* Controls */
.controls {
  display: flex;
  gap: 0.75rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 1.05rem;
  padding: 0.85rem 2rem;
  border-radius: 999px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease, opacity 0.2s ease;
  min-width: 7rem;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04210f;
}

.btn-primary.tracking {
  background: var(--danger);
  border-color: var(--danger);
  color: #2a0606;
}

.btn-ghost {
  background: transparent;
}

/* Subtle pulse on the hero while tracking */
.speed.live {
  text-shadow: 0 0 32px rgba(255, 255, 255, 0.18);
}

/* Over-speed (>120 km/h) — red flashing warning */
.speed.over-limit {
  color: var(--danger) !important;
  animation: over-pulse 0.6s ease-in-out infinite;
}

@keyframes over-pulse {
  0%,
  100% {
    text-shadow: 0 0 24px rgba(255, 82, 82, 0.45);
    opacity: 1;
  }
  50% {
    text-shadow: 0 0 60px rgba(255, 82, 82, 0.95);
    opacity: 0.78;
  }
}

@media (prefers-reduced-motion: reduce) {
  .speed.over-limit {
    animation: none;
    text-shadow: 0 0 48px rgba(255, 82, 82, 0.85);
  }
}

/* Settings: alert-limit stepper + test sound */
.settings {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.limit-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-variant-numeric: tabular-nums;
}

.set-label,
.set-unit {
  font-size: 0.9rem;
  color: var(--dim);
}

.limit-val {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 2.6ch;
  text-align: center;
}

.step {
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease;
}

.step:active {
  transform: scale(0.92);
}

/* Install button + hint */
.btn-install {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
  font-size: 0.95rem;
  padding: 0.7rem 1.6rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--dim);
  max-width: 20rem;
}

.hint strong {
  color: var(--fg);
}

/* GPS-disabled banner */
.gps-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
  background: #2a0606;
  border-top: 1px solid var(--danger);
  color: #ffd9d9;
  font-size: 0.9rem;
  text-align: center;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.gps-banner.show {
  transform: translateY(0);
}

.gps-banner strong {
  color: #fff;
}
