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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #f2f2f2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  background: #000;
}

#video {
  display: none;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
}

/* Overlay d'état (permission, erreurs) */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  text-align: center;
  background: rgba(0, 0, 0, 0.88);
  z-index: 20;
}

#overlay.hidden {
  display: none;
}

#overlay-message {
  font-size: 18px;
  line-height: 1.5;
  color: #e8e8e8;
  max-width: 32em;
}

/* Boutons génériques */
.btn {
  border: none;
  border-radius: 16px;
  background: #1c1c1e;
  color: #f2f2f2;
  font-size: 17px;
  font-weight: 600;
  padding: 14px 28px;
  cursor: pointer;
}

.btn:active {
  background: #2c2c2e;
}

.btn.hidden {
  display: none;
}

.btn-primary {
  background: #39d3bb;
  color: #04231f;
}

.btn-primary:active {
  background: #2fb9a4;
}

/* Barre basse : grille à 3 pistes pour garder le bouton capture toujours
   centré sans jamais chevaucher le groupe de zoom, quelle que soit la
   largeur d'écran. */
#bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 20px calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
}

/* Contrôles de zoom */
#controls {
  grid-column: 1;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(28, 28, 30, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 10px;
}

.btn-round {
  width: 64px;
  height: 64px;
  min-width: 64px;
  border-radius: 50%;
  background: #2c2c2e;
  font-size: 30px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-round:active {
  background: #3a3a3c;
}

.btn-round:disabled {
  opacity: 0.35;
}

#zoom-level {
  min-width: 64px;
  text-align: center;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  color: #f2f2f2;
}

/* Bouton de capture */
.btn-capture {
  grid-column: 2;
  justify-self: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255, 255, 255, 0.35);
  padding: 0;
}

.btn-capture:active {
  background: #d8d8d8;
}

.btn-capture.flash {
  animation: flash 220ms ease-out;
}

@keyframes flash {
  0% { background: #fff; }
  40% { background: #39d3bb; }
  100% { background: #fff; }
}

/* Paysage : barre verticale à droite, capture toujours centrée sur la
   hauteur, contrôles de zoom au-dessus. Même principe de grille que la
   barre du bas pour éviter tout chevauchement. */
@media (orientation: landscape) {
  #bottom-bar {
    left: auto;
    top: 0;
    bottom: 0;
    right: 0;
    width: auto;
    height: 100%;
    grid-template-columns: none;
    grid-template-rows: 1fr auto 1fr;
    padding: calc(20px + env(safe-area-inset-top, 0px)) calc(24px + env(safe-area-inset-right, 0px))
      calc(20px + env(safe-area-inset-bottom, 0px)) 20px;
  }

  #controls {
    grid-column: auto;
    grid-row: 1;
    justify-self: center;
    align-self: start;
    flex-direction: column;
  }

  .btn-capture {
    grid-column: auto;
    grid-row: 2;
    justify-self: center;
    align-self: center;
  }
}
