/* ---------- Base ---------- */
/* Univers unique sombre (écran de jeu), indépendant du thème */
:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* Le jeu occupe exactement l'écran : pas de défilement, pas de zoom,
   pas de « tirer pour rafraîchir » qui gênerait les swipes. */
html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #23324a, #0e1420 70%);
  color: #f2f4f8;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  display: flex;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.jeu {
  width: 100%;
  max-width: 480px;
  height: 100%;
  padding-block: 10px 14px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ---------- En-tête ---------- */
.entete {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.5px;
}

.bouton-son {
  border: none;
  background: #2d3b55;
  color: #fff;
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
}

/* ---------- Score ---------- */
.tableau-bord {
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: #182235;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.95rem;
}

.tableau-bord p {
  margin: 0;
}

.tableau-bord strong {
  color: #ffd23f;
  font-size: 1.15rem;
}

/* ---------- Canvas ---------- */
/* La zone du Canvas prend toute la hauteur restante ;
   script.js calcule la plus grande taille 2:3 qui y tient. */
.zone-canvas {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

/* Coordonnées du jeu : 360 x 540 (attributs HTML).
   La taille affichée et la netteté (écrans haute densité) sont gérées en JS. */
canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  background: #2b2b2b;
  touch-action: none;
}

/* ---------- Boutons ---------- */
.commandes {
  width: 100%;
  display: flex;
  gap: 14px;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  flex-shrink: 0;
}

.entete,
.tableau-bord,
.commandes,
.pied {
  flex-shrink: 0;
}

/* Message et bouton Recommencer sur une même ligne */
.pied {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
}

.bouton-direction {
  flex: 1;
  min-height: 60px;
  font-size: 1.15rem;
  font-weight: bold;
  border: none;
  border-radius: 14px;
  background: #3a6df0;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #2449a8;
}

.bouton-direction:active,
.bouton-direction.actif {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2449a8;
}

.message {
  flex: 1;
  min-width: 0;
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  font-size: 0.95rem;
  font-weight: bold;
  color: #ffd23f;
}

.message.perdu {
  color: #ff5a5a;
}

.bouton-recommencer {
  min-height: 50px;
  padding: 0 22px;
  font-size: 1.1rem;
  font-weight: bold;
  border: none;
  border-radius: 25px;
  background: #22b35e;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #167a3f;
}

.bouton-recommencer:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #167a3f;
}

/* ---------- Petits écrans ---------- */
@media (max-height: 700px) {
  .jeu {
    gap: 6px;
    padding-block: 6px 8px;
  }
  h1 {
    font-size: 1.1rem;
  }
  .bouton-son {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }
  .tableau-bord {
    padding: 4px 10px;
    font-size: 0.85rem;
  }
  .bouton-direction {
    min-height: 50px;
  }
  .bouton-recommencer {
    min-height: 44px;
  }
}

@media (max-width: 360px) {
  .tableau-bord {
    font-size: 0.8rem;
  }
  .tableau-bord strong {
    font-size: 1rem;
  }
}

/* Téléphone à l'horizontale : commandes de part et d'autre de la route */
@media (orientation: landscape) and (max-height: 500px) {
  .jeu {
    max-width: none;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "entete canvas score"
      "gauche canvas droite"
      "pied   canvas .";
    column-gap: 16px;
  }
  .entete { grid-area: entete; }
  .tableau-bord { grid-area: score; flex-direction: column; gap: 4px; }
  .zone-canvas { grid-area: canvas; width: calc((100dvh - 24px) * 2 / 3); height: 100%; }
  .commandes { display: contents; }
  #boutonGauche { grid-area: gauche; align-self: center; min-height: 90px; }
  #boutonDroite { grid-area: droite; align-self: center; min-height: 90px; }
  .pied { grid-area: pied; flex-direction: column; }
}
