:root {
  --rose-50: #fff6f9;
  --rose-100: #fde7ef;
  --rose-200: #f9c9da;
  --rose-600: #d81b60;
  --rose-700: #b0124f;
  --encre: #3a1028;
  --encre-douce: #7a4a62;
  --rayon: 22px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Éléments liés à la caméra : visibles seulement quand elle fonctionne. */
body:not(.camera) .si-camera, body.camera .invite { display: none !important; }

/* Chaque élément n'apparaît qu'aux étapes listées dans son attribut data-modes. */
body[data-etat="vide"] [data-modes]:not([data-modes~="vide"]),
body[data-etat="edition"] [data-modes]:not([data-modes~="edition"]),
body[data-etat="resultat"] [data-modes]:not([data-modes~="resultat"]) { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--encre);
  background-color: #fff;
  background-image: linear-gradient(180deg, var(--rose-100) 0, #fff 340px);
  background-repeat: no-repeat;
  -webkit-tap-highlight-color: transparent;
}

.page {
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

/* En-tête */
.entete { text-align: center; }
.ruban { width: 22px; height: 33px; display: block; margin: 0 auto 2px; }
h1 {
  margin: 0;
  font-size: clamp(1.3rem, 6.6vw, 2.2rem);
  font-weight: 900;
  letter-spacing: .02em;
  line-height: 1.1;
  color: var(--rose-700);
}
.slogan { margin: 4px 0 0; font-size: 1rem; line-height: 1.35; color: var(--encre-douce); }

.alerte {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--rose-200);
  font-size: .9rem;
  line-height: 1.4;
  text-align: center;
}

.principal {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 14px;
}

/* Zone de l'image : carrée, la plus grande possible sans pousser les boutons hors de l'écran. */
/* --ratio (hauteur / largeur du cadre) et --reserve (place laissée aux boutons) règlent la taille :
   la scène prend la forme du cadre, la plus grande possible sans pousser les boutons hors de l'écran. */
.scene {
  position: relative;
  width: 100%;
  max-width: calc((100vh - var(--reserve, 300px)) / var(--ratio, 1));
  min-width: 200px;
  border-radius: var(--rayon);
  overflow: hidden;
  background: var(--rose-50);
  box-shadow: 0 12px 32px rgba(176, 18, 79, .16), 0 0 0 1px rgba(176, 18, 79, .06);
  -webkit-user-select: none;
  user-select: none;
}
@supports (height: 100svh) {
  .scene { max-width: calc((100svh - var(--reserve, 300px)) / var(--ratio, 1)); }
}
.scene::before { content: ""; display: block; padding-top: calc(var(--ratio, 1) * 100%); }
.scene > canvas, .scene > img, .scene > video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}
/* La vidéo reste sous le canvas (opaque) qui la redessine dans le cadre. Elle n'est pas masquée
   par opacité : Safari iOS cesserait alors de la mettre à jour. */
.scene > video { object-fit: cover; pointer-events: none; }

.basculer {
  position: absolute;
  right: 3%; bottom: 3%;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: #fff;
  color: var(--rose-700);
  box-shadow: 0 4px 14px rgba(176, 18, 79, .25);
  cursor: pointer;
  touch-action: manipulation;
}
.basculer svg { width: 26px; height: 26px; }
.basculer:focus-visible { outline: 3px solid var(--rose-600); outline-offset: 2px; }

/* Éclair blanc au déclenchement. */
.scene.flash::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #fff;
  pointer-events: none;
  animation: flash .35s ease-out forwards;
}
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

body[data-etat="edition"] .scene {
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
}
body[data-etat="edition"] .scene.saisie { cursor: grabbing; }
.scene:focus-visible { outline: 3px solid var(--rose-600); outline-offset: 3px; }

/* Invitation dans la zone photo, positionnée par le script sur la partie transparente du cadre. */
.invite {
  position: absolute;
  top: 10%; left: 14%; width: 72%; height: 65%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--rose-700);
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
.invite svg {
  width: 56px; height: 56px;
  padding: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 14px rgba(176, 18, 79, .2);
}
.invite:focus-visible { outline: 3px solid var(--rose-600); outline-offset: -6px; border-radius: 50%; }

.chargement {
  position: absolute;
  inset: 0;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, .82);
  font-weight: 600;
  color: var(--rose-700);
}
.rond {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 4px solid var(--rose-200);
  border-top-color: var(--rose-600);
  animation: tourne .8s linear infinite;
}
@keyframes tourne { to { transform: rotate(360deg); } }

.aide { margin: 10px 0 0; font-size: .88rem; color: var(--encre-douce); text-align: center; }

.zoom {
  width: 100%;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  color: var(--rose-700);
}
.zoom svg { width: 22px; height: 22px; flex: none; }
.zoom input { flex: 1; height: 36px; accent-color: var(--rose-600); cursor: pointer; }

/* Boutons */
.actions {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 0 24px;
  border: 2px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .12s ease, background-color .2s ease, box-shadow .2s ease;
}
.btn svg { width: 24px; height: 24px; flex: none; }
.btn-principal {
  background: var(--rose-600);
  color: #fff;
  box-shadow: 0 8px 20px rgba(216, 27, 96, .32);
}
.btn-principal:hover { background: var(--rose-700); }
.btn:active { transform: scale(.98); }
/* Quand « Partager » est disponible, « Télécharger » devient secondaire ;
   de même pour « Ajouter ma photo » quand la caméra est active. */
.btn-secondaire, .btn-secondaire:hover,
body.camera #btn-ajouter, body.camera #btn-ajouter:hover {
  background: #fff;
  color: var(--rose-700);
  border-color: var(--rose-200);
  box-shadow: none;
}
.btn:focus-visible, .lien:focus-visible { outline: 3px solid var(--encre); outline-offset: 3px; }
.btn:disabled { opacity: .6; cursor: progress; }

.liens { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 22px; }
.lien {
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  background: none;
  color: var(--rose-700);
  font: inherit;
  font-size: .98rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  touch-action: manipulation;
}

.astuce { margin: 0; font-size: .88rem; line-height: 1.4; text-align: center; color: var(--encre-douce); }

.message { min-height: 1.4em; margin: 10px 0 0; font-size: .95rem; text-align: center; font-weight: 600; color: var(--rose-700); }
.message.erreur { color: #b00020; }

.confidentialite {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 400px;
  margin: 6px 0 0;
  font-size: .85rem;
  line-height: 1.4;
  color: var(--encre-douce);
}
.confidentialite svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--rose-600); }

.pied {
  margin-top: auto;
  padding-top: 20px;
  text-align: center;
  font-size: .8rem;
  color: var(--encre-douce);
}
.pied p { margin: 2px 0; }
.devise { letter-spacing: .08em; font-weight: 600; color: var(--rose-700); }

.visuellement-cache {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 720px) {
  .page { padding-top: 32px; }
  .scene { max-width: min(520px, calc((100vh - 320px) / var(--ratio, 1))); }
}

/* Cadre vertical (format téléphone) : le cadre porte déjà le titre, il occupe toute la hauteur. */
body.format-vertical { --reserve: 160px; }
body.format-vertical .entete { display: none; }
body.format-vertical .principal { margin-top: 0; }
body.format-vertical .scene { border-radius: 16px; }
@media (min-width: 720px) {
  body.format-vertical .scene { max-width: min(520px, calc((100vh - 200px) / var(--ratio, 1))); }
}
/* Sur téléphone, le pincement suffit : consigne affichée sur l'image, curseur de zoom masqué. */
body.format-vertical.tactile #aide, body.format-vertical.tactile .zoom,
body.format-vertical.tactile .aide.si-camera { display: none !important; }
.aide-incrustee {
  position: absolute;
  top: 16%; left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(20, 0, 10, .62);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .3s ease;
}
body:not(.format-vertical) .aide-incrustee, body:not(.tactile) .aide-incrustee { display: none !important; }
.scene.deja-touchee .aide-incrustee { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .rond { animation-duration: 2.4s; }
  .scene.flash::after { animation: none; opacity: 0; }
}
