:root {
  color-scheme: light dark;
  --fond: #ffffff;
  --texte: #0c0c0e;
  --gris: #76767c;
  --gris-leger: #b4b4ba;
  --orange: #d4660a;
  --voile: rgba(0, 0, 0, 0.4);
  --trait: rgba(0, 0, 0, 0.1);
  --appui: rgba(0, 0, 0, 0.06);
  --feuille: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #000000;
    --texte: #f4f4f6;
    --gris: #8e8e94;
    --gris-leger: #5a5a60;
    --orange: #ff9f0a;
    --voile: rgba(0, 0, 0, 0.6);
    --trait: rgba(255, 255, 255, 0.12);
    --appui: rgba(255, 255, 255, 0.08);
    --feuille: #151517;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

button {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--gris);
  outline-offset: 4px;
  border-radius: 8px;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- bouton « i » */

#info {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gris-leger);
  border-radius: 50%;
  transition: color 0.2s;
}

#info:active {
  color: var(--texte);
}

/* ---- mesure */

#mesure {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0 16px;
  transition: opacity 0.3s;
}

#mesure[hidden],
#message[hidden] {
  display: none;
}

#voie {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 44px;
  padding: 8px 20px 4px;
  font-size: clamp(17px, 5.4vw, 24px);
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--texte);
  transition: color 0.3s;
}

#voie-code:empty::before {
  content: "\00a0";
}

#voie-points {
  display: flex;
  gap: 5px;
  height: 8px;
  margin-top: 6px;
}

#voie-points i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gris-leger);
  transition: background 0.2s;
}

#voie-points i.actif {
  background: var(--texte);
}

#pk {
  position: relative;
  padding: 0 8px;
  font-size: min(23vw, 24vh, 200px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.035em;
  white-space: nowrap;
  color: var(--texte);
  transition: color 0.3s, opacity 0.3s;
}

#pk:active {
  opacity: 0.6;
}

#sens {
  font-weight: 500;
  color: var(--texte);
}

#ligne {
  margin: 10px 0 0;
  max-width: 90%;
  min-height: 1.3em;
  font-size: 15px;
  line-height: 1.3;
  text-align: center;
  color: var(--gris);
  text-wrap: balance;
  transition: color 0.3s;
}

#ligne:empty::before {
  content: "\00a0";
}

#infos {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--gris);
  text-align: center;
  max-width: 100%;
}

#infos .mauvaise {
  color: var(--orange);
  font-weight: 500;
}

#infos .retry {
  color: var(--texte);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- hors voie */

#app[data-etat="hors-voie"] #pk,
#app[data-etat="hors-voie"] #voie {
  color: var(--gris-leger);
}

#app[data-etat="hors-voie"] #ligne {
  color: var(--gris);
}

/* ---- messages (attente, refus, erreur) */

#message {
  max-width: 300px;
  padding: 0 24px;
  text-align: center;
}

#message-texte {
  margin: 0;
  font-size: 17px;
  line-height: 1.45;
  color: var(--gris);
}

#app[data-etat="attente"] #message-texte {
  animation: respire 2.4s ease-in-out infinite;
}

@keyframes respire {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

#reessayer {
  margin-top: 18px;
  padding: 10px 22px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 500;
  color: var(--texte);
  border: 1px solid var(--trait);
  border-radius: 999px;
}

#reessayer:active {
  background: var(--appui);
}

#reessayer[hidden] {
  display: none;
}

/* ---- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 36px);
  transform: translate(-50%, 6px);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fond);
  background: var(--texte);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

#toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- feuille d’informations */

#feuille {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 85vh;
  margin: 0;
  padding: 22px 24px calc(env(safe-area-inset-bottom) + 20px);
  border: 0;
  border-top: 1px solid var(--trait);
  border-radius: 22px 22px 0 0;
  background: var(--feuille);
  color: var(--texte);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}

#feuille::backdrop {
  background: var(--voile);
}

#feuille h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

#feuille dl {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

#feuille dt {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gris);
}

#feuille dd {
  margin: 2px 0 0;
}

#feuille-avertissement {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--trait);
  font-size: 14px;
  line-height: 1.45;
  color: var(--texte);
}

#fermer {
  display: block;
  width: 100%;
  margin-top: 18px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 500;
  color: var(--gris);
}

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

/* ---- GPS perdu : dernier PK grisé */

#app[data-gps="perdu"] #pk {
  color: var(--gris);
}

.hors-ecran {
  position: fixed;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
}
