:root {
  --bg: #0b0d10;
  --fg: #f2f4f7;
  --muted: #8a93a0;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff5a5a;
  --red: #d91e1e;
  --panel: #161a20;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

body {
  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);
  transition: background-color .2s;
}

/* ---------- Barre d'état ---------- */

#status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--muted);
}
#status #net { flex: 1; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

#btn-settings {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 26px;
  padding: 4px 8px;
}

/* ---------- Zone de danger ---------- */

#zone {
  margin: 0 12px;
  padding: 14px;
  border-radius: 14px;
  background: var(--warn);
  color: #1a1200;
  font-weight: 800;
  font-size: clamp(20px, 6vw, 34px);
  text-align: center;
  letter-spacing: .04em;
  animation: pulse 1.2s ease-in-out infinite;
}
#zone[hidden] { display: none; }

@keyframes pulse {
  50% { opacity: .55; }
}

/* ---------- Tableau de bord ---------- */

#dash {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
}

#speed-wrap { text-align: center; }

#speed {
  font-size: min(42vw, 30vh);
  font-weight: 800;
  line-height: .9;
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}

.unit {
  font-size: 22px;
  color: var(--muted);
}

#limit-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.sign {
  width: min(38vw, 24vh);
  height: min(38vw, 24vh);
  border-radius: 50%;
  background: #fff;
  border: calc(min(38vw, 24vh) * .11) solid var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  font-weight: 800;
  font-size: calc(min(38vw, 24vh) * .38);
  font-variant-numeric: tabular-nums;
}
.sign.estimated {
  border-style: dashed;
  opacity: .8;
}
.sign.unknown {
  border-color: #444;
  background: #222;
  color: var(--muted);
}

#road {
  font-size: 18px;
  color: var(--muted);
  text-align: center;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Excès de vitesse : chiffre rouge et fond qui clignote */
body.over #speed { color: var(--bad); }
body.over { animation: alarm 1s ease-in-out infinite; }
@keyframes alarm {
  50% { background-color: #3a0808; }
}

/* Téléphone à l'horizontale : vitesse et panneau côte à côte */
@media (orientation: landscape) {
  #dash { flex-direction: row; gap: 8vw; }
  #speed { font-size: min(26vw, 50vh); }
  .sign {
    width: min(24vw, 42vh);
    height: min(24vw, 42vh);
    border-width: calc(min(24vw, 42vh) * .11);
    font-size: calc(min(24vw, 42vh) * .38);
  }
}

/* ---------- Fenêtres ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.overlay[hidden] { display: none; }

.panel {
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.panel h1, .panel h2 { margin: 0; }
.panel p { margin: 0; color: var(--muted); line-height: 1.4; }
.small { font-size: 13px; }

button {
  font: inherit;
  border: none;
  border-radius: 12px;
  padding: 12px;
  background: #262c35;
  color: var(--fg);
}
button.big {
  background: var(--ok);
  color: #04120b;
  font-weight: 700;
  font-size: 20px;
  padding: 16px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-size: 17px;
}
.toggle small { display: block; font-size: 13px; color: var(--muted); }
.toggle input { width: 22px; height: 22px; accent-color: var(--ok); }
