/* ============================================================
   APERTURA DEL PACCHETTO — scena a tutto schermo in tre fasi:
   1) busta: si strappa scorrendo il dito (o toccando);
   2) pila: le carte coperte si girano una alla volta, la migliore per ultima;
   3) riepilogo: le 4 carte, poi vanno nell'album.
   Le animazioni sono tutte finite e partono solo con la scena aperta.
   ============================================================ */
#apertura { position: fixed; inset: 0; z-index: 40; visibility: hidden; overflow: hidden;
  display: grid; place-items: center; color: var(--testo); touch-action: none;
  background: radial-gradient(70% 55% at 50% 45%, #1b2236 0%, #090b11 70%); }
#apertura.aperto { visibility: visible; }
.ap-scena { position: absolute; inset: 0; display: grid; place-items: center; }
.ap-testo { position: absolute; left: 16px; right: 16px; bottom: max(28px, env(safe-area-inset-bottom)); text-align: center;
  color: var(--testo-2); font-size: 15px; transition: opacity .3s; }
.ap-salta { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 5; }
.ap-luce { position: absolute; inset: -20%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 48%, var(--ap-col, #fff) 0, transparent 45%); mix-blend-mode: screen; }
.ap-lampo { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 4; }

/* --- Busta --- */
.ap-busta { position: relative; width: min(64vw, 280px); aspect-ratio: 5 / 8; cursor: grab;
  filter: drop-shadow(0 30px 40px rgb(0 0 0 / .6)); }
.ap-corpo, .ap-lembo { position: absolute; left: 0; right: 0; overflow: hidden;
  background:
    linear-gradient(115deg, transparent 30%, rgb(255 255 255 / .22) var(--luce, 45%), transparent calc(var(--luce, 45%) + 18%)),
    repeating-linear-gradient(135deg, rgb(242 195 91 / .06) 0 6px, transparent 6px 14px),
    linear-gradient(165deg, #2b3a63, #121a31 50%, #3a2a12); }
.ap-corpo { top: 13%; bottom: 0; border-radius: 0 0 18px 18px; box-shadow: inset 0 0 0 2px rgb(242 195 91 / .55); }
.ap-corpo::before { content: ""; position: absolute; inset: 0; margin: auto; width: 58%; aspect-ratio: 1; top: -8%;
  background: var(--emblema) center / contain no-repeat; filter: drop-shadow(0 0 18px rgb(242 195 91 / .5)); }
.ap-corpo::after { content: "4 carte"; position: absolute; left: 0; right: 0; bottom: 9%; text-align: center;
  font: 700 15px "Cinzel", Georgia, serif; letter-spacing: .18em; color: var(--oro); }
.ap-lembo { top: 0; height: 13.6%; border-radius: 18px 18px 0 0; box-shadow: inset 0 0 0 2px rgb(242 195 91 / .55);
  transform-origin: 0% 100%; }
.ap-lembo::after { content: ""; position: absolute; left: 6%; right: 6%; bottom: 14%; height: 2px;
  background: repeating-linear-gradient(90deg, rgb(242 195 91 / .7) 0 8px, transparent 8px 14px); }
.ap-strappo { position: absolute; left: 6%; top: calc(13.6% - 1px); height: 3px; width: calc(88% * var(--p, 0));
  background: linear-gradient(90deg, #fff6d0, var(--oro)); box-shadow: 0 0 12px 3px rgb(255 220 140 / .8); border-radius: 2px; }

/* --- Carte --- */
.ap-pila { position: relative; width: min(70vw, 300px, calc((100dvh - 200px) * 63 / 88)); aspect-ratio: 63 / 88; }
.ap-slot { position: absolute; inset: 0; transform-style: preserve-3d; perspective: 1200px; }
.ap-giro { position: absolute; inset: 0; transform-style: preserve-3d; }
.ap-faccia, .ap-dorso { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.ap-faccia { transform: rotateY(180deg); }
.ap-faccia .carta, .ap-dorso .carta-retro { --larg: 100%; width: 100%; }
.ap-dorso .carta-retro { box-shadow: inset 0 0 0 2.4cqw #2a2f45, inset 0 0 0 3cqw #c9a14a, inset 0 0 0 4cqw #2a2f45,
  0 0 0 0 var(--ap-col, transparent), 0 2cqw 6cqw rgb(0 0 0 / .5); }
.ap-slot.presagio .ap-dorso .carta-retro { box-shadow: inset 0 0 0 2.4cqw #2a2f45, inset 0 0 0 3cqw var(--ap-col), inset 0 0 0 4cqw #2a2f45,
  0 0 40px 8px var(--ap-col), 0 2cqw 6cqw rgb(0 0 0 / .5); transition: box-shadow .6s; }
.ap-etichetta { position: absolute; left: 0; right: 0; top: calc(100% + 14px); display: flex; justify-content: center; gap: 8px; opacity: 0; transition: opacity .3s; }
.ap-slot.girata .ap-etichetta { opacity: 1; }
.ap-raggi { position: absolute; left: 50%; top: 50%; width: 260vmax; height: 260vmax; margin: -130vmax 0 0 -130vmax; pointer-events: none; opacity: 0;
  background: repeating-conic-gradient(from 0deg, var(--ap-col) 0deg 4deg, transparent 4deg 16deg);
  -webkit-mask-image: radial-gradient(circle, #000 0, transparent 22%); mask-image: radial-gradient(circle, #000 0, transparent 22%); }
.ap-scintilla { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px; border-radius: 50%;
  background: var(--ap-col); box-shadow: 0 0 10px 2px var(--ap-col); pointer-events: none; }
.ap-nome-rarita { position: absolute; left: 0; right: 0; top: calc(50% - min(35vw, 150px) - 54px); text-align: center; opacity: 0;
  font: 700 22px "Cinzel", Georgia, serif; letter-spacing: .2em; text-transform: uppercase; color: var(--ap-col); text-shadow: 0 0 20px var(--ap-col); }
.ap-contatore { position: absolute; top: max(18px, env(safe-area-inset-top)); left: 16px; color: var(--testo-3); font-size: 14px; font-variant-numeric: tabular-nums; }

/* --- Riepilogo --- */
.ap-riepilogo { display: grid; justify-items: center; gap: 20px; padding: 24px 16px; width: 100%; max-width: 760px; }
.ap-riepilogo h2 { font-size: 22px; }
.ap-griglia { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: 100%; }
.ap-griglia > div { display: grid; justify-items: center; gap: 8px; opacity: 0; }
.ap-griglia .carta { --larg: 100%; max-width: 170px; cursor: pointer; }
.ap-azioni { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
@media (max-width: 640px) { .ap-griglia { grid-template-columns: repeat(2, 1fr); max-width: 340px; } }
