/* Visite 3D · interface (Prisme), d'après da.md section 7.
   Mêmes jetons que css/style.css. Pas de backdrop-filter par-dessus le canvas : voiles opaques seulement.
   Couches : canvas 0 · carte, pastilles, aide, joystick 2 · « Salta » 3 · chargement 4 · erreur 5 · barre 6 */

html.v3d-aperta { overflow: hidden; }

#visite3d {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  overflow: hidden;
  background: var(--nero); color: var(--avorio);
  font-family: var(--font-testo);
}
#visite3d::backdrop { background: var(--nero); }
#visite3d:fullscreen { width: 100vw; height: 100vh; }

#visite3d-scena {
  position: absolute; inset: 0; z-index: 0;
  width: 100%; height: 100%;
  touch-action: none; cursor: grab;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#visite3d-scena:active { cursor: grabbing; }
#visite3d-scena.v3d-punta { cursor: pointer; }
#visite3d-scena:focus-visible { outline-offset: -3px; }

/* Avant que la scène soit prête, ou en cas d'erreur : seule la barre (titre + fermer) reste. */
#visite3d:not(.v3d-pronta) :is(#v3d-tappe, #v3d-carta, #v3d-aiuto, #v3d-joystick, .v3d-modi, #v3d-alto, .v3d-salta) { display: none !important; }

/* ---------- Barre haute ---------- */
.v3d-barra {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: var(--s-2);
  min-height: calc(56px + var(--safe-top));
  padding: calc(6px + var(--safe-top)) 12px 6px;
  background: var(--velo-3d);
  border-bottom: 1px solid var(--filo);
}
.v3d-titolo {
  display: none; margin: 0 auto 0 0; min-width: 0;
  font: 700 18px/1.2 var(--font-titre); color: var(--avorio);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.v3d-modi { margin-right: auto; flex: none; }
.v3d-modi button { padding: 0 16px; }
/* v2 : .lang passe en overflow: visible (anneau de focus non rogné) → les segments portent eux-mêmes l'arrondi de la pilule */
.v3d-modi button:first-child { border-radius: var(--r-pill) 0 0 var(--r-pill); }
.v3d-modi button:last-child { border-radius: 0 var(--r-pill) var(--r-pill) 0; }
#v3d-alto { position: relative; flex: none; min-height: 44px; width: 44px; padding: 0; }
.v3d-alto-testo {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
#v3d-chiudi { flex: none; color: var(--avorio); background: transparent; }

@media (min-width: 640px) {
  .v3d-titolo { display: block; }
  .v3d-modi { margin-right: 0; }
  #v3d-alto { width: auto; padding: 0 16px; }
  .v3d-alto-testo { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; clip-path: none; }
}

/* ---------- Pastilles des étapes ---------- */
#v3d-tappe {
  position: absolute; z-index: 2;
  top: calc(56px + var(--safe-top) + 8px); left: 0; right: 0;
  display: flex; justify-content: center; gap: 4px;
  margin: 0; padding: 0; list-style: none;
  pointer-events: none;
}
#v3d-tappe li { pointer-events: auto; }
#v3d-tappe button {
  display: grid; place-items: center;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 44 44'%3E%3Cpath d='M42 22 32 4.7H12L2 22l10 17.3h20Z' fill='rgba(11,10,9,.82)' stroke='%23D6B15E' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center / 44px 44px no-repeat;
  color: var(--avorio);
  font: 700 18px/1 var(--font-titre);
  font-variant-numeric: lining-nums;
  cursor: pointer;
}
#v3d-tappe button[aria-current="step"] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 44 44'%3E%3Cpath d='M42 22 32 4.7H12L2 22l10 17.3h20Z' fill='%23D6B15E' stroke='%23D6B15E' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E");
  color: var(--nero);
}
@media (min-width: 1024px) {
  #v3d-tappe { top: 50%; right: 20px; left: auto; flex-direction: column; transform: translateY(-50%); }
}

/* ---------- Carte d'étape ---------- */
#v3d-carta {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 0;
  max-height: 45vh; max-height: 45svh;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--velo-carta);
  border-top: 1px solid rgba(214, 177, 94, .4);
  border-radius: var(--r-2) var(--r-2) 0 0;
}
#v3d-carta:not([hidden]) { animation: v3d-sale 280ms cubic-bezier(.215, .61, .355, 1) both; }
#v3d-contatore { margin: 0; color: var(--oro); }
.v3d-carta-corpo { display: flex; align-items: flex-start; gap: var(--s-3); margin-top: var(--s-2); }
#v3d-foto {
  flex: none; width: 72px; height: 90px;
  object-fit: cover; border-radius: var(--r-1);
  background: var(--marmo-alto);
}
.v3d-carta-testo { min-width: 0; }
#v3d-titolo { margin: 0; font: 700 20px/1.2 var(--font-titre); color: var(--avorio); }
#v3d-testo { margin: 4px 0 0; font-size: 16px; line-height: 1.45; color: var(--avorio-2); }
#v3d-prezzo {
  display: flex; flex-wrap: wrap; align-items: center; column-gap: var(--s-3);
  margin: var(--s-3) 0 0;
  font: 600 16px/1.5 var(--font-testo); letter-spacing: .01em;
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--oro);
}
.v3d-extra { margin-top: var(--s-3); }
.v3d-extra .tappa-wa { margin-top: 0; width: 100%; }
.v3d-carta-nav { display: flex; gap: var(--s-2); margin-top: var(--s-3); }
.v3d-carta-nav .btn { flex: 1 1 0; min-height: 48px; padding: 0 12px; }
.v3d-carta-nav .btn:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }
#v3d-carta.v3d-cambio :is(#v3d-contatore, .v3d-carta-corpo, #v3d-prezzo, .v3d-extra) { animation: v3d-fondu 200ms ease-out both; }

@media (min-width: 1024px) {
  #v3d-carta {
    left: 24px; right: auto; bottom: 24px; width: 380px;
    max-height: calc(100vh - 56px - 48px); max-height: calc(100dvh - 56px - var(--safe-top) - 48px);
    padding: 20px;
    border: 1px solid rgba(214, 177, 94, .4); border-radius: var(--r-2);
  }
  #v3d-foto { width: 120px; height: 150px; }
}

/* ---------- Aide ---------- */
#v3d-aiuto {
  position: absolute; z-index: 2; left: 50%;
  top: calc(56px + var(--safe-top) + 8px + 44px + 8px);
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  margin: 0; padding: 8px 16px;
  background: var(--velo-3d); color: var(--avorio);
  border-radius: var(--r-pill);
  font-size: 16px; line-height: 1.4; text-align: center;
  pointer-events: none;
  transition: opacity 600ms ease;
}
#v3d-aiuto.v3d-spento { opacity: 0; }
#v3d-aiuto .v3d-aiuto-alto { display: none; }
#v3d-aiuto.v3d-is-alto .v3d-aiuto-alto { display: inline; }
#v3d-aiuto.v3d-is-alto :is(.v3d-aiuto-tattile, .v3d-aiuto-mouse) { display: none; }
@media (min-width: 1024px) { #v3d-aiuto { top: calc(56px + var(--safe-top) + 12px); } }

/* ---------- Joystick (tactile, mode libre, carte fermée) ---------- */
#v3d-joystick { display: none; }
@media (pointer: coarse) {
  #v3d-joystick.v3d-on {
    position: absolute; z-index: 2;
    left: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    display: grid; place-items: center;
    width: 120px; height: 120px; border-radius: 50%;
    background: rgba(11, 10, 9, .55);
    border: 2px solid var(--avorio-2);
    box-shadow: 0 0 0 2px var(--velo-3d);
    touch-action: none;
  }
  .v3d-manetta {
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--oro); border: 2px solid var(--nero);
    pointer-events: none;
  }
}

/* ---------- « Salta l'intro » ---------- */
.v3d-salta {
  position: absolute; z-index: 3;
  right: 20px; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--velo-3d);
}

/* ---------- Chargement ---------- */
#visite3d-caricamento {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s-4);
  padding: 24px;
  background: var(--nero); text-align: center;
  transition: opacity 400ms ease;
}
#visite3d-caricamento.v3d-fuori { opacity: 0; pointer-events: none; }
.v3d-esagono { width: 96px; height: 84px; color: var(--neon-bianco); }
.v3d-esagono path { stroke-dasharray: 1 1; stroke-dashoffset: 1; animation: v3d-traccia 1.4s cubic-bezier(.65, 0, .35, 1) infinite; }
#visite3d-caricamento p { margin: 0; font: 500 24px/1.3 var(--font-titre); color: var(--avorio); }
.v3d-barra-progresso { width: 200px; height: 2px; background: var(--filo); overflow: hidden; }
.v3d-barra-progresso span { display: block; height: 100%; background: var(--oro); transform: scaleX(0); transform-origin: left center; transition: transform 300ms ease-out; }

/* ---------- Secours ---------- */
#visite3d-errore {
  position: absolute; z-index: 5; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(28rem, calc(100% - 40px));
  padding: 24px;
  background: var(--marmo-alto); color: var(--avorio);
  border: 1px solid var(--filo); border-radius: var(--r-2);
  text-align: center;
}
#visite3d-errore p { margin: 0 0 var(--s-5); font-size: 16px; line-height: 1.5; }

/* ---------- Mesure des images/s (?fps) ---------- */
.v3d-fps {
  position: absolute; z-index: 6; right: 8px; bottom: 8px;
  padding: 2px 6px; background: var(--velo-3d); color: var(--avorio);
  font: 12px/1.4 ui-monospace, monospace; pointer-events: none;
}

@keyframes v3d-sale { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes v3d-fondu { from { opacity: 0; } to { opacity: 1; } }
@keyframes v3d-traccia { 0% { stroke-dashoffset: 1; } 50% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -1; } }

/* ---------- Mouvement réduit : pas de tracé en boucle, fondus courts seulement ---------- */
@media (prefers-reduced-motion: reduce) {
  .v3d-esagono path { animation: none; stroke-dasharray: none; stroke-dashoffset: 0; }
  #v3d-carta:not([hidden]) { animation: v3d-fondu 150ms linear both; }
  #v3d-carta.v3d-cambio :is(#v3d-contatore, .v3d-carta-corpo, #v3d-prezzo, .v3d-extra) { animation: v3d-fondu 150ms linear both; }
  #visite3d-caricamento, #v3d-aiuto, .v3d-barra-progresso span { transition: none; }
}
