/* ==========================================================================
   Motion kit — Insegna Accesa
   Scroll reveals, scrollytelling, image-sequence, shader and 3D model slots.
   No build step. Every effect has a still fallback and respects
   prefers-reduced-motion. Copy into css/ and link after the site's own CSS.
   ========================================================================== */

/* ---------- 1. Reveal on scroll ------------------------------------------
   <h2 data-reveal>…</h2>                 fade + rise
   <ul data-reveal="stagger">…</ul>       children one after another
   data-reveal="left" | "right" | "zoom"  other directions
   Browsers with scroll-driven animations (Chrome, Edge, Safari 26+) do it in
   CSS alone; the others get the same look from motion.js (IntersectionObserver).
   Content is visible by default: hiding only starts once JS or CSS support is
   confirmed, so a failed script never leaves a blank page.
   Don't put data-reveal on an element that already uses `transform` for its
   position (e.g. translateX(-50%) centring): the reveal replaces it. Wrap it. */

:root {
  --m-ease: cubic-bezier(.2, .8, .2, 1);
  --m-dist: 28px;
  --m-dur: .8s;
}

html.m-js [data-reveal]:not(.m-in) { opacity: 0; transform: translateY(var(--m-dist)); }
html.m-js [data-reveal="left"]:not(.m-in)  { transform: translateX(calc(var(--m-dist) * -1.5)); }
html.m-js [data-reveal="right"]:not(.m-in) { transform: translateX(calc(var(--m-dist) * 1.5)); }
html.m-js [data-reveal="zoom"]:not(.m-in)  { transform: scale(.92); }
html.m-js [data-reveal="stagger"]:not(.m-in) { opacity: 1; transform: none; }
html.m-js [data-reveal="stagger"]:not(.m-in) > * { opacity: 0; transform: translateY(var(--m-dist)); }

[data-reveal], [data-reveal="stagger"] > * {
  transition: opacity var(--m-dur) var(--m-ease), transform var(--m-dur) var(--m-ease);
}
[data-reveal="stagger"].m-in > * { transition-delay: calc(var(--i, 0) * 90ms); }

/* CSS-only path: the animation is tied to the element's position in the
   viewport, so it also plays backwards when scrolling up. */
@supports (animation-timeline: view()) {
  html.m-css [data-reveal]:not([data-reveal="stagger"]),
  html.m-css [data-reveal="stagger"] > * {
    opacity: 1; transform: none; transition: none;
    animation: m-rise linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 70%;
  }
  html.m-css [data-reveal="left"]  { animation-name: m-left; }
  html.m-css [data-reveal="right"] { animation-name: m-right; }
  html.m-css [data-reveal="zoom"]  { animation-name: m-zoom; }
  html.m-css [data-reveal="stagger"] > * { animation-range: entry calc(var(--i, 0) * 6%) entry calc(60% + var(--i, 0) * 6%); }
  @keyframes m-rise  { from { opacity: 0; transform: translateY(var(--m-dist)); } }
  @keyframes m-left  { from { opacity: 0; transform: translateX(calc(var(--m-dist) * -1.5)); } }
  @keyframes m-right { from { opacity: 0; transform: translateX(calc(var(--m-dist) * 1.5)); } }
  @keyframes m-zoom  { from { opacity: 0; transform: scale(.92); } }
}

/* ---------- 2. Parallax layers (CSS only, decorative) ---------------------
   <img data-parallax="0.15" …>  moves slower than the page. Use on decorative
   images only, never on text. */
@supports (animation-timeline: scroll()) {
  html.m-css [data-parallax] {
    animation: m-parallax linear both;
    animation-timeline: view();
    animation-range: cover;
  }
  @keyframes m-parallax {
    from { transform: translateY(calc(var(--p, .15) * -120px)); }
    to   { transform: translateY(calc(var(--p, .15) * 120px)); }
  }
}

/* ---------- 3. Scrollytelling: sticky visual + text steps -----------------
   <section class="m-story">
     <div class="m-story__visual"> …one figure per step, data-step="1"… </div>
     <div class="m-story__steps">
       <article class="m-step" data-step="1">…</article> …
     </div>
   </section>
   motion.js sets data-active on the section; the matching figure shows. */
.m-story { display: grid; grid-template-columns: 1fr; gap: 0; position: relative; }
.m-story__visual { position: sticky; top: 0; height: 100vh; height: 100svh; display: grid; place-items: center; overflow: hidden; z-index: 0; }
.m-story__visual > [data-step] { grid-area: 1 / 1; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s var(--m-ease), transform .9s var(--m-ease); transform: scale(1.04); }
.m-story__visual > [data-step].is-on { opacity: 1; transform: none; }
.m-story__steps { position: relative; z-index: 1; margin-top: -100vh; margin-top: -100svh; }
.m-step { min-height: 90vh; min-height: 90svh; display: flex; align-items: center; padding: 0 1rem; }
.m-step > * { max-width: 30rem; background: var(--m-card, rgba(255,255,255,.92)); color: var(--m-card-ink, #111); padding: 1.25rem 1.4rem; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.m-step:last-child { min-height: 100vh; min-height: 100svh; }
@media (min-width: 900px) {
  .m-story { grid-template-columns: 1fr 1fr; }
  .m-story__visual { grid-column: 2; grid-row: 1; }
  .m-story__steps { grid-column: 1; grid-row: 1; margin-top: 0; }
  .m-step > * { background: none; box-shadow: none; padding: 0; color: inherit; }
}

/* ---------- 4. Horizontal gallery pinned while scrolling -------------------
   <section class="m-hscroll"><div class="m-hscroll__track"> cards… </div></section>
   motion.js sets the section height from the track width. On phones, or with
   reduced motion, it degrades to a normal swipeable row. */
.m-hscroll { position: relative; }
.m-hscroll__sticky { position: sticky; top: 0; height: 100vh; height: 100svh; display: flex; align-items: center; overflow: hidden; }
.m-hscroll__track { display: flex; gap: 1.25rem; padding: 0 6vw; will-change: transform; }
.m-hscroll__track > * { flex: 0 0 min(72vw, 420px); }
.m-hscroll.is-static .m-hscroll__sticky { position: static; height: auto; overflow-x: auto; scroll-snap-type: x mandatory; padding: 1rem 0; }
.m-hscroll.is-static .m-hscroll__track { transform: none !important; }
.m-hscroll.is-static .m-hscroll__track > * { scroll-snap-align: center; }

/* ---------- 5. Image sequence (the "product turning" effect) ---------------
   <section class="m-frames" data-frames="img/seq/frame-###.webp" data-count="90">
     <div class="m-frames__sticky"><canvas></canvas><img class="m-frames__poster" …></div>
   </section> */
.m-frames { position: relative; height: 300vh; }
.m-frames__sticky { position: sticky; top: 0; height: 100vh; height: 100svh; display: grid; place-items: center; overflow: hidden; }
.m-frames canvas, .m-frames__poster { grid-area: 1 / 1; max-width: 100%; max-height: 100%; width: auto; height: 100%; object-fit: contain; }
.m-frames canvas { opacity: 0; transition: opacity .4s; }
.m-frames.is-ready canvas { opacity: 1; }
.m-frames.is-ready .m-frames__poster { visibility: hidden; }
.m-frames.is-static { height: auto; }
.m-frames.is-static .m-frames__sticky { position: static; height: auto; padding: 2rem 0; }

/* ---------- 6. Shader background slot --------------------------------------
   <div class="m-shader" style="--m-c1:#0E1E3D;--m-c2:#1F5FA8;--m-c3:#F2CC3A"></div>
   inside a positioned hero (dark colour first). The same three variables paint
   the still gradient (first paint and fallback) and the animation. Keep text on
   the dark colour: the light ones sit in the corners of the gradient. */
.m-shader { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  background: radial-gradient(70% 60% at 90% 10%, var(--m-c2, #3FBCEE) 0%, transparent 70%),
              radial-gradient(50% 45% at 95% 95%, var(--m-c3, #FFD500) 0%, transparent 70%),
              var(--m-c1, #18378A); }
.m-shader canvas { width: 100%; height: 100%; display: block; opacity: 0; transition: opacity 1.2s; }
.m-shader.is-on canvas { opacity: 1; }

/* ---------- 7. 3D model slot (<model-viewer>) -------------------------------- */
model-viewer.m-model { width: 100%; height: min(70vh, 560px); background: transparent; --poster-color: transparent; }
model-viewer.m-model::part(default-progress-bar) { display: none; }

/* ---------- 8. Counters ----------------------------------------------------
   <span data-count-to="200">200</span> — the real number is in the HTML;
   motion.js counts up to it once visible. */


/* ---------- 9. Marquee (sponsor logos, slogans) ---------------------------
   <div class="m-marquee" aria-label="Sponsor"><div class="m-marquee__row">
     logos… (motion.js duplicates the row for a seamless loop, hidden from screen readers)
   </div></div>
   Pauses on hover and focus; static, wrapped row with reduced motion. */
.m-marquee { overflow: hidden; -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent); mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent); }
.m-marquee__inner { display: flex; width: max-content; animation: m-marquee var(--m-marquee-dur, 40s) linear infinite; }
.m-marquee:hover .m-marquee__inner, .m-marquee:focus-within .m-marquee__inner { animation-play-state: paused; }
.m-marquee__row { display: flex; align-items: center; gap: var(--m-marquee-gap, 3rem); padding-right: var(--m-marquee-gap, 3rem); }
.m-marquee__row img { height: var(--m-marquee-h, 56px); width: auto; }
@keyframes m-marquee { to { transform: translateX(-50%); } }

/* ---------- 10. Before / after slider ----------------------------------------
   <figure class="m-ba"><img src="prima.webp" alt="Prima: …"><img src="dopo.webp" alt="Dopo: …">
     <input type="range" min="0" max="100" value="50" aria-label="Confronta prima e dopo"></figure>
   Works with keyboard and touch; without JS both photos show one under the other. */
.m-ba { position: relative; margin: 0; }
.m-ba img { display: block; width: 100%; height: auto; }
html.m-js .m-ba img + img, html.m-css .m-ba img + img { position: absolute; inset: 0; height: 100%; object-fit: cover; clip-path: inset(0 0 0 var(--m-ba, 50%)); }
.m-ba input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
html:not(.m-js):not(.m-css) .m-ba input { display: none; }
.m-ba::after { content: ""; position: absolute; top: 0; bottom: 0; left: var(--m-ba, 50%); width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
.m-ba:focus-within::after { box-shadow: 0 0 0 3px var(--m-focus, #3FBCEE); }

/* ---------- Reduced motion: everything still and visible ------------------ */
@media (prefers-reduced-motion: reduce) {
  html.m-js [data-reveal], html.m-js [data-reveal] > *,
  html.m-css [data-reveal], html.m-css [data-reveal] > *,
  html.m-css [data-parallax] {
    opacity: 1 !important; transform: none !important; animation: none !important; transition: none !important;
  }
  .m-story__visual > [data-step] { transition: none; }
  .m-shader canvas { display: none; }
  .m-marquee { -webkit-mask-image: none; mask-image: none; }
  .m-marquee__inner { animation: none; width: auto; }
  .m-marquee__row { flex-wrap: wrap; justify-content: center; row-gap: 1.5rem; padding-right: 0; }
  .m-marquee__row[aria-hidden] { display: none; }
}
