/* Page /photos/ : l'instantané (prototype validé : docs/mockups/photobooth/camera-a.css), version réelle.
   Boîtier, viseur (la vraie caméra), déclencheur, pile « Mes photos », photo qui sort, repli sans caméra. */

.cam-page {
  --coral: #ca6f57; --coral-deep: #a9533d; --sand: #deb9a2; --peach: #f6cbbd; --green: #3d6044; --ink: #2a2320;
  --paper: #fbf8f3; --body: #efddcf;
  position: fixed; inset: 0; display: grid; place-items: center; overflow: hidden; background: #d3b09a;
  overscroll-behavior: none; touch-action: manipulation; -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none; font-family: var(--font);
}
.cam-page :where(input) { -webkit-user-select: text; user-select: text; }

.cam {
  position: relative; width: min(100vw, 430px); height: min(100vh, 900px); height: min(100dvh, 900px);
  overflow: hidden; background: var(--body); isolation: isolate; color: var(--ink);
}
@media (min-width: 520px) and (min-height: 700px) { .cam { border-radius: 46px; box-shadow: 0 0 0 10px #17110f, 0 40px 70px -24px rgba(58, 36, 32, .6); } }
.cam[data-boot] .cam__body { visibility: hidden; }
.cam button, .cam a { -webkit-tap-highlight-color: transparent; }
.noscript { position: absolute; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: var(--body); text-align: center; }

/* Boutons et liens communs (viseur de repli, onboarding, feuille) */
.btn { min-height: 48px; padding: 0 22px; border-radius: 99px; font-weight: 600; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; text-align: center; }
.btn--cream { background: var(--body); color: var(--ink); }
.btn--line { color: var(--body); box-shadow: inset 0 0 0 2px rgba(239, 221, 207, .7); }
.link-btn { min-height: 48px; padding: 0 6px; font-size: 14px; font-weight: 600; color: var(--green); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-btn--light { color: var(--body); }
.btn:focus-visible, .link-btn:focus-visible, .a-pile:focus-visible, .a-shutter:focus-visible, .a-pill:focus-visible, .a-brand:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.view .btn:focus-visible, .view .link-btn:focus-visible { outline-color: var(--body); }

/* Le boîtier occupe tout l'écran : seuls une fine bande en haut et le déclencheur en bas ne sont pas le viseur */
.cam__body { position: absolute; inset: 0; display: flex; flex-direction: column; background: linear-gradient(180deg, #f6eadf, #e5cbbb); }
.a-stripes { position: absolute; inset: 0 0 auto; display: grid; }
.a-stripes i { height: 5px; }
.a-stripes i:nth-child(1) { background: var(--green); }
.a-stripes i:nth-child(2) { background: var(--coral); }
.a-stripes i:nth-child(3) { background: var(--sand); }
.a-stripes i:nth-child(4) { background: var(--peach); }
.a-top { flex: none; display: flex; align-items: center; justify-content: space-between; padding: max(26px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); height: calc(max(26px, env(safe-area-inset-top)) + 34px); }
.a-brand { position: relative; font-size: 21px; font-weight: 700; color: var(--green); text-decoration: none; }
.a-brand::before, .a-pill::before { content: ""; position: absolute; inset: -10px -8px; } /* zone tactile de 48 px sans agrandir le dessin */
.a-pill { position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 99px; background: rgba(61, 96, 68, .13); color: var(--green); font-size: 12px; font-weight: 600; cursor: pointer; }
.a-pill[hidden] { display: none; }

.a-finder { flex: 1 1 0; min-height: 0; margin: 6px max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); padding: 8px; border-radius: 34px; background: #1b1514; box-shadow: inset 0 0 0 2px #46392f, 0 14px 22px -14px rgba(58, 36, 32, .6); }
.view { position: relative; height: 100%; border-radius: 27px; overflow: hidden; background: #2a2320; }
.view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; }
.view[data-cam="live"] video { opacity: 1; }
.view[data-mirror] video { transform: scaleX(-1); } /* effet miroir : caméra frontale seulement */
.view .corners { position: absolute; inset: 16px; pointer-events: none; --c: rgba(255, 255, 255, .75);
  background: linear-gradient(var(--c), var(--c)) 0 0 / 22px 2px, linear-gradient(var(--c), var(--c)) 0 0 / 2px 22px, linear-gradient(var(--c), var(--c)) 100% 0 / 22px 2px, linear-gradient(var(--c), var(--c)) 100% 0 / 2px 22px,
    linear-gradient(var(--c), var(--c)) 0 100% / 22px 2px, linear-gradient(var(--c), var(--c)) 0 100% / 2px 22px, linear-gradient(var(--c), var(--c)) 100% 100% / 22px 2px, linear-gradient(var(--c), var(--c)) 100% 100% / 2px 22px;
  background-repeat: no-repeat; }
.view .glass { position: absolute; inset: 0; background: linear-gradient(120deg, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 38%); pointer-events: none; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: 0; } 12% { opacity: .96; } 100% { opacity: 0; } }
.a-chip { position: absolute; z-index: 4; left: 50%; bottom: 36px; translate: -50% 0; max-width: calc(100% - 48px); overflow: hidden; text-overflow: ellipsis; padding: 7px 14px; border-radius: 99px; background: rgba(27, 21, 20, .62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; }
.a-chip:empty { display: none; }

/* Repli : pas de caméra (refusée, HTTP, aucun capteur) */
.nocam { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; padding: 24px 24px 72px; overflow-y: auto; text-align: center; color: var(--body); background: radial-gradient(circle at 50% 30%, #3b302b, #241d1a); }
.nocam[hidden] { display: none; }
.nocam__title { font-size: 20px; font-weight: 600; line-height: 1.2; }
.nocam__text { font-size: 14px; line-height: 1.45; max-width: 30ch; }
.nocam__actions { display: grid; gap: 8px; justify-items: center; margin-top: 8px; width: 100%; max-width: 270px; }
.nocam__actions .btn { width: 100%; }

.a-controls { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center; padding: 12px max(22px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left)); }
.a-ghost { width: 56px; }
.a-shutter { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; background: var(--body); border: 7px solid var(--green); box-shadow: 0 7px 0 -2px #2c4a33, 0 14px 20px rgba(58, 36, 32, .35); transition: translate .08s, box-shadow .08s, opacity .15s; }
.a-shutter i { width: 58px; height: 58px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ee9d85, #ca6f57 55%, #a9533d); }
.a-shutter:active { translate: 0 6px; box-shadow: 0 1px 0 -2px #2c4a33, 0 5px 9px rgba(58, 36, 32, .35); }
.a-shutter.is-busy { pointer-events: none; }

/* La pile : les photos prises s'y rangent ; la dernière est dessus. Un tap ouvre « Mes photos ». */
.a-pile { position: relative; justify-self: start; width: 54px; height: 66px; margin-left: 4px; cursor: pointer; }
.a-pile::before { content: ""; position: absolute; inset: -8px -10px; } /* cible tactile ≥ 48 px */
.a-pile__card, .a-pile__top { position: absolute; inset: 0; background: var(--paper); border-radius: 3px; box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 5px 9px -3px rgba(58, 36, 32, .5); }
.a-pile__card--l { rotate: -10deg; }
.a-pile__card--r { rotate: 7deg; }
.a-pile__top { padding: 4px 4px 15px; rotate: -2deg; }
.a-pile__top::before { content: ""; position: absolute; inset: 4px 4px 15px; background: #cbb9a8; }
.a-pile__top img { position: relative; width: 100%; height: 100%; object-fit: cover; }
.a-pile b { position: absolute; top: -9px; right: -9px; min-width: 22px; height: 22px; padding: 0 5px; display: grid; place-items: center; border-radius: 99px; background: var(--coral-deep); color: #fff; font-size: 12px; font-weight: 700; box-shadow: 0 0 0 2px #f1dfd1; }
.a-pile b[hidden], .a-pile img[hidden] { display: none; }
.a-pile.thump { animation: thump .32s cubic-bezier(.3, 1.6, .5, 1); }
.a-pile b.pop { animation: pop .4s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes thump { 0% { scale: 1; } 35% { scale: 1.16; } 100% { scale: 1; } }
@keyframes pop { 0% { scale: 1; } 40% { scale: 1.5; } 100% { scale: 1; } }
/* Témoin d'envoi honnête : anneau qui tourne = envoi / nouvel essai ; point plein = en échec (à rouvrir) */
.a-pile__net { position: absolute; right: -8px; bottom: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--paper); box-shadow: 0 0 0 2px #f1dfd1; }
.a-pile__net[hidden] { display: none; }
.a-pile__net::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; border: 2.5px solid var(--green); border-top-color: transparent; animation: spin .9s linear infinite; }
.a-pile__net[data-net="retry"]::after { border-color: var(--coral-deep); border-top-color: transparent; }
.a-pile__net[data-net="failed"]::after { inset: 3px; border: 0; background: var(--coral-deep); animation: none; }
@keyframes spin { to { rotate: 360deg; } }

/* La photo : elle apparaît devant l'écran (petit bond), se développe en moins d'une seconde, puis file dans la pile */
.prints { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; pointer-events: none; }
.print { --tilt: 0deg; --shot: 1; --develop: .8s; grid-area: 1 / 1; width: var(--pw, 240px); }
.print__card {
  position: relative; padding: 7% 7% 22%; background: var(--paper); animation: appear .26s cubic-bezier(.2, 1.6, .4, 1) both;
  box-shadow: 0 2px 2px rgba(0, 0, 0, .25), 0 26px 40px -12px rgba(0, 0, 0, .6);
}
@keyframes appear { from { scale: .5; rotate: calc(var(--tilt) - 10deg); translate: 0 70px; opacity: 0; } to { scale: 1; rotate: var(--tilt); translate: 0 0; opacity: 1; } }
.print__photo { position: relative; aspect-ratio: var(--shot); overflow: hidden; background: radial-gradient(circle at 40% 35%, #a9b29c, #8b9682); }
.print__photo canvas { display: block; width: 100%; height: 100%; opacity: 0; filter: brightness(1.7) contrast(.45) saturate(.15) blur(3px); animation: develop var(--develop) ease-out forwards; } /* vert-gris, puis l'image */
@keyframes develop { 0% { opacity: 0; } 25% { opacity: .55; } 100% { opacity: 1; filter: none; } }
.print__name { position: absolute; left: 7%; right: 7%; bottom: 5.5%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; color: #4a3f39; }

/* Écran court (360×640) : on rend de la place au viseur, qui doit rester au-dessus de 70 % de la hauteur */
@media (max-height: 700px) {
  .a-top { height: calc(max(14px, env(safe-area-inset-top)) + 34px); padding-top: max(14px, env(safe-area-inset-top)); }
  .a-finder { margin-top: 2px; }
  .a-controls { padding-top: 8px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .a-shutter { width: 80px; height: 80px; border-width: 6px; }
  .a-shutter i { width: 50px; height: 50px; }
  .a-chip { bottom: 28px; }
}

/* Téléphone couché : le déclencheur passe à droite du viseur */
@media (orientation: landscape) and (max-height: 520px) {
  .cam { width: 100vw; border-radius: 0; box-shadow: none; }
  .cam__body { display: grid; grid-template-columns: minmax(0, 1fr) 150px; grid-template-rows: auto minmax(0, 1fr); }
  .a-top { grid-column: 2; grid-row: 1; flex-direction: column; align-items: flex-end; gap: 6px; height: auto; padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 0; }
  .a-finder { grid-column: 1; grid-row: 1 / 3; margin: 24px 0 10px max(10px, env(safe-area-inset-left)); }
  .a-controls { grid-column: 2; grid-row: 2; padding: 0 max(14px, env(safe-area-inset-right)) 0 0; grid-template-columns: 1fr; grid-template-rows: auto auto; row-gap: 22px; justify-items: end; align-content: center; }
  .a-controls .a-shutter { grid-row: 1; }
  .a-controls .a-pile { grid-row: 2; justify-self: end; margin-right: 18px; }
  .a-ghost { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .print__card { animation: fade-in .15s linear both; rotate: var(--tilt); }
  .flash.go { animation: flash-soft .5s linear; }
  .a-pile.thump, .a-pile b.pop { animation: none; }
  .a-pile__net::after { animation-duration: 3s; }
  .view video { transition: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes flash-soft { 0% { opacity: 0; } 20% { opacity: .5; } 100% { opacity: 0; } }
