/* Base condivisa: reset, accessibilità, lightbox, fallback 3D. Gli aspetti visivi restano in ogni demo. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 88px; }
body { margin: 0; min-height: 100vh; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
img, svg, canvas { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
[hidden] { display: none !important; }

.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 1000; padding: 12px 18px; background: #fff; color: #111; font-weight: 700; border-radius: 8px; text-decoration: none; transition: top .2s; }
.skip-link:focus { top: 12px; }

/* Rivelazione allo scroll: senza JS i contenuti restano visibili */
.js .reveal { opacity: 0; transform: translateY(26px); transition: opacity .8s cubic-bezier(.2, .7, .2, 1), transform .8s cubic-bezier(.2, .7, .2, 1); transition-delay: var(--d, 0ms); }
.js .reveal.is-in { opacity: 1; transform: none; }
.js .reveal-img { opacity: 0; transform: translateY(34px) scale(.975); transition: opacity 1s cubic-bezier(.2, .7, .2, 1), transform 1.2s cubic-bezier(.2, .7, .2, 1); transition-delay: var(--d, 0ms); }
.js .reveal-img.is-in { opacity: 1; transform: none; }

/* Scena 3D: l'immagine di riserva resta visibile finché WebGL non è pronto */
[data-scene-wrap] { position: relative; }
[data-scene-wrap] canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity .9s ease; }
[data-scene-wrap] .scene-fallback { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transition: opacity .9s ease; pointer-events: none; }
[data-scene-wrap].scene-ready canvas { opacity: 1; }
[data-scene-wrap].scene-ready .scene-fallback { opacity: 0; }
[data-scene-wrap].scene-failed canvas { display: none; }

/* Lightbox accessibile (dialog nativo) */
.lb { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh; margin: 0; color: #fff; overflow: hidden; }
.lb::backdrop { background: rgba(8, 8, 8, .88); backdrop-filter: blur(6px); }
.lb[open] { display: grid; place-items: center; animation: lbIn .3s ease; }
.lb-fig { margin: 0; display: grid; gap: 14px; justify-items: center; max-width: min(92vw, 1100px); }
.lb-fig img { max-height: 76vh; width: auto; max-width: 100%; border-radius: 6px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); animation: lbImg .35s ease; }
.lb-cap { font-size: 1rem; text-align: center; color: #e9e9e9; max-width: 60ch; }
.lb-btn { position: fixed; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .3); background: rgba(20, 20, 20, .7); color: #fff; transition: transform .2s, background .2s; }
.lb-btn:hover { background: rgba(255, 255, 255, .18); transform: scale(1.06); }
.lb-btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.lb-close { top: 18px; right: 18px; }
.lb-prev { left: 18px; top: 50%; translate: 0 -50%; }
.lb-next { right: 18px; top: 50%; translate: 0 -50%; }
.lb-count { position: fixed; top: 28px; left: 24px; font-size: .9rem; letter-spacing: .08em; color: #cfcfcf; }
@keyframes lbIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes lbImg { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) {
  .lb-prev, .lb-next { top: auto; bottom: 22px; translate: none; }
  .lb-prev { left: calc(50% - 64px); }
  .lb-next { right: calc(50% - 64px); }
}

/* Moduli: stati condivisi */
.field-error { min-height: 0; font-size: .875rem; line-height: 1.3; margin-top: 6px; }
.field-error:empty { display: none; }
.field-error { animation: errIn .28s ease; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger, #d64545) !important; }
form.shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }
@keyframes errIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
[data-confirm]:not([hidden]) { animation: confirmIn .6s cubic-bezier(.2, .7, .2, 1); }
@keyframes confirmIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
form[data-demo-form] { transition: opacity .35s ease, transform .35s ease; }
form[data-demo-form].is-leaving { opacity: 0; transform: translateY(-10px); pointer-events: none; }
.btn-spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -.15em; margin-right: .5em; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important; }
  .js .reveal, .js .reveal-img { opacity: 1; transform: none; }
}
