/* =====================================================
   Codevgroup — Hero v3 (intro cinematografica + scroll bridge)
   Palette brand: deep blue-black + cyan + indigo.
   Premium dark-tech, no hacker, no neon green.
   ===================================================== */

/* Scroll lock durante l'intro autonoma (~4.5s, rimosso a fine introTl).
   Safety timeout JS-side: se qualcosa va storto, sblocco max 8s. */
html.cine-v3-intro-lock,
html.cine-v3-intro-lock body {
  overflow: hidden !important;
  touch-action: none;
  overscroll-behavior: none;
}

/* =====================================================
   Section 02 — Rotate text (dual-state stack, no layout shift).
   Markup: <h2 class="rotate-h"> con 2 <span class="rstate">.
   Active = visible. Lo swap è gestito via JS toggling .is-active.
   ===================================================== */
.rotate-h,
.rotate-p {
  display: grid;
}
.rotate-h .rstate,
.rotate-p .rstate {
  grid-area: 1 / 1;        /* entrambi gli stati nello stesso cell = max height */
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity .55s cubic-bezier(.16, 1, .3, 1),
    transform .55s cubic-bezier(.16, 1, .3, 1);
  pointer-events: none;
}
.rotate-h .rstate.is-active,
.rotate-p .rstate.is-active {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
/* Tint cyan brand durante scramble (mai verde Matrix) */
.rotate-h .rstate.is-scrambling,
.rotate-h .rstate.is-scrambling em,
.rotate-p .rstate.is-scrambling {
  color: #00f2ff;
  -webkit-text-fill-color: #00f2ff;
  background: none;
}

/* =====================================================
   BACK-TO-TOP button (appare dopo 600px di scroll)
   ===================================================== */
.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(14, 20, 40, .85);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(0, 242, 255, .28);
  color: #00f2ff;
  cursor: pointer;
  z-index: 200;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: translateY(16px) scale(.9);
  pointer-events: none;
  transition:
    opacity .35s cubic-bezier(.16, 1, .3, 1),
    transform .35s cubic-bezier(.16, 1, .3, 1),
    border-color .25s ease,
    box-shadow .25s ease;
  box-shadow:
    0 8px 24px -8px rgba(0, 0, 0, .6),
    inset 0 0 0 1px rgba(0, 242, 255, .08);
}
.back-to-top.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.back-to-top:hover {
  border-color: #00f2ff;
  box-shadow:
    0 10px 28px -8px rgba(0, 242, 255, .35),
    inset 0 0 0 1px rgba(0, 242, 255, .25),
    0 0 18px rgba(0, 242, 255, .25);
  transform: translateY(-2px) scale(1);
}
.back-to-top:active {
  transform: translateY(0) scale(.96);
}
/* Ring SVG (track + progress) come overlay del button */
.back-to-top__ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* -90° = il progress parte dall'alto invece che da destra */
  transform: rotate(-90deg);
}
.back-to-top__track {
  fill: none;
  stroke: rgba(0, 242, 255, .12);
  stroke-width: 2;
}
.back-to-top__progress {
  fill: none;
  stroke: #00f2ff;
  stroke-width: 2;
  stroke-linecap: round;
  /* pathLength=100 sul circle nel markup → 1 unità = 1% di circonferenza.
     dasharray=100 + dashoffset 100→0 = riempimento da 0% a 100%. */
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset .12s linear;
  filter: drop-shadow(0 0 6px rgba(0, 242, 255, .55));
}
/* Freccia (sopra al ring, centrata) */
.back-to-top__arrow {
  width: 18px;
  height: 18px;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 0 6px rgba(0, 242, 255, .35));
}
/* Hint visivo quando il ring è quasi pieno (≥95%): pulsa come "sei in fondo" */
.back-to-top.at-bottom .back-to-top__progress {
  filter: drop-shadow(0 0 10px rgba(0, 242, 255, .85));
  animation: backTopPulse 1.4s ease-in-out infinite;
}
@keyframes backTopPulse {
  0%, 100% { stroke-width: 2; }
  50%      { stroke-width: 2.8; }
}
@media (max-width: 1024px) {
  /* Su mobile c'è la mobile-cta a bottom: 0 (h ≈ 56px), salgo sopra */
  .back-to-top {
    bottom: 84px;
    right: 16px;
    width: 44px;
    height: 44px;
  }
}

/* =====================================================
   HEADER refinement (scoped a questa pagina via :has(.cine-v3))
   Sostituisce mono+uppercase con Inter sans crisp + smoothing.
   Look "premium SaaS" stile Draftly, mantenendo il pill esistente.
   ===================================================== */
body:has(.cine-v3) {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body:has(.cine-v3) .nav {
  display: flex;
  max-width: calc(100vw - 32px);
  justify-self: center;
  padding: 5px;
  background: rgba(14, 20, 40, .55);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, .08);
}

body:has(.cine-v3) .nav__link,
body:has(.cine-v3) .nav__item__trigger {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -.003em;
  text-transform: none;          /* via UPPERCASE, leggibilità ↑↑ */
  padding: 9px 16px;
  color: rgba(244, 246, 251, .72);
  -webkit-font-smoothing: antialiased;
}
body:has(.cine-v3) .nav__link:hover,
body:has(.cine-v3) .nav__item__trigger:hover {
  color: #ffffff;
}
body:has(.cine-v3) .nav__link.active,
body:has(.cine-v3) .nav__item__trigger.active {
  color: #ffffff;
  background: rgba(255, 255, 255, .08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

body:has(.cine-v3) .nav__cta {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.005em;
  text-transform: none;
  padding: 10px 18px 10px 20px;
  -webkit-font-smoothing: antialiased;
}

body:has(.cine-v3) .brand {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -.005em;
}

body:has(.cine-v3) .nav__link--contact {
  color: #ffffff;
  background: rgba(0, 242, 255, .12);
  box-shadow: inset 0 0 0 1px rgba(0, 242, 255, .28);
}

body:has(.cine-v3) .nav__lang-switch {
  border-radius: 999px;
  padding: 8px 12px;
}

@media (max-width: 1180px) {
  body:has(.cine-v3) .header {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  body:has(.cine-v3) .header .brand,
  body:has(.cine-v3) .header > .nav__cta {
    display: none;
  }

  body:has(.cine-v3) .menu-toggle {
    display: none;
  }
}

@media (max-width: 860px) and (min-width: 681px) {
  body:has(.cine-v3) .nav {
    gap: 2px;
    padding: 4px;
  }

  body:has(.cine-v3) .nav__link,
  body:has(.cine-v3) .nav__item__trigger {
    font-size: 11px;
    padding: 8px 11px;
  }

  body:has(.cine-v3) .nav__lang-switch {
    font-size: 10px;
    padding: 7px 9px;
  }
}

@media (max-width: 680px) {
  body:has(.cine-v3) .header {
    grid-template-columns: auto 1fr auto;
    justify-items: stretch;
  }

  body:has(.cine-v3) .header .brand {
    display: inline-flex;
  }

  body:has(.cine-v3) .nav {
    display: none;
  }

  body:has(.cine-v3) .nav.open {
    display: flex;
    max-width: none;
  }

  body:has(.cine-v3) .menu-toggle {
    display: inline-grid;
    place-items: center;
  }
}
/* brand__status resta mono (status indicator tech) ma più piccolo + smoothing */
body:has(.cine-v3) .brand__status {
  font-size: 9.5px;
  letter-spacing: .22em;
  -webkit-font-smoothing: antialiased;
}

/* ===== Section 02 (next): nessun margin che collida col pin-spacer GSAP.
   Position relative + z-index = stacking pulito, niente layout-shift al pin release. */
body:has(.cine-v3) #positioning {
  position: relative;
  margin-top: 0;
  z-index: 1;
}

.cine-v3 {
  --bg:        #05070D;
  --bg-2:      #0A0F1F;
  --grey:      #1A1A1A;
  --cyan:      #00F2FF;
  --cyan-soft: rgba(0, 242, 255, .14);
  --cyan-glow: rgba(0, 242, 255, .45);
  --indigo:    #4F46E5;
  --indigo-soft: rgba(79, 70, 229, .18);
  --white:     #F4F6FB;
  --soft:      rgba(244, 246, 251, .60);
  --mute:      rgba(244, 246, 251, .35);
  --line:      rgba(0, 242, 255, .12);

  position: relative;
  /* 100vh = solo l'altezza dello stage. Il pin-spacer di GSAP aggiungerà
     +80vh di scroll trigger (vedi ScrollTrigger.create con pin + end '+=80%').
     Così abbiamo controllo nativo GSAP sul pin (anticipatePin funziona). */
  height: 100vh;
  height: 100svh;   /* svh = viewport "piccolo" stabile: non cambia quando la
                       barra URL mobile appare/scompare → niente resize→refresh
                       del pin a metà scroll (jump). Fallback 100vh sopra. */
  background: var(--bg);
  z-index: 2;
}

/* Override del position:sticky di style.css: GSAP ora gestisce il pin.
   Se lasciassimo sticky, anticipatePin sarebbe inutile (è proprietà GSAP-only). */
.cine-v3 .cine__stage {
  position: relative;
  top: auto;
  width: 100%;
  height: 100vh;
  height: 100svh;   /* vedi nota su .cine-v3: stabile vs barra URL mobile */
  min-height: 600px;
  overflow: hidden;
  background: var(--bg);
  isolation: isolate;
}

/* ---------- WebGL canvas ---------- */
.cine-v3__gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 1;
}

/* ---------- Cinematic vignette + grain (sopra al canvas, sotto al testo) ---------- */
.cine-v3__vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  /* Vignette radiale: angoli scuri, centro pulito */
  background:
    radial-gradient(ellipse 90% 70% at 50% 50%, transparent 50%, rgba(0, 0, 0, .55) 100%),
    radial-gradient(ellipse 100% 100% at 50% 50%, transparent 70%, rgba(2, 6, 23, .35) 100%);
  mix-blend-mode: multiply;
}
/* Grana sottilissima statica (opzionale, dà texture cinematografica) */
.cine-v3__vignette::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .35 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: .04;
  mix-blend-mode: overlay;
}

/* ---------- Boot text (sistema che si accende, MOLTO secondario) ---------- */
.cine-v3__boot {
  position: absolute;
  bottom: 24px;
  left: 28px;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: .22em;
  color: rgba(0, 242, 255, .65);
  text-shadow: 0 0 8px rgba(0, 242, 255, .25);
  pointer-events: none;
  opacity: 0;
}
.cine-v3__boot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan-glow);
  animation: cineV3Pulse 1.4s ease-in-out infinite;
}
.cine-v3__boot::after {
  content: '_';
  margin-left: 2px;
  animation: cineV3Caret .9s steps(2) infinite;
}
@keyframes cineV3Pulse {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.2); }
}
@keyframes cineV3Caret {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---------- Text overlay (sopra al 3D, mai compenetrato) ---------- */
.cine-v3__text {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: 0 24px;
  text-align: center;
}

.cine-v3__title {
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: clamp(38px, 6.5vw, 96px);
  line-height: 1.05;
  letter-spacing: -.035em;
  font-weight: 500;
  color: var(--white);
  margin: 0;
  max-width: 16ch;
  /* position:relative per ancorare il pseudo backdrop ::before */
  position: relative;
  /* NIENTE text-shadow: veniva tagliata dall'overflow:hidden della .line
     creando un rettangolo scuro netto sotto al testo. */
}
/* Backdrop morbido SOPRA al canvas, SOTTO al testo: alone radiale che sfuma
   completamente nei bordi. Sta sulla .title (non dentro .line) → non è clippato. */
.cine-v3__title::before {
  content: '';
  position: absolute;
  inset: -30% -10%;
  background: radial-gradient(ellipse at 50% 50%,
    rgba(2, 6, 23, .45) 0%,
    rgba(2, 6, 23, .25) 30%,
    transparent 70%);
  filter: blur(28px);
  pointer-events: none;
  z-index: -1;
}
/* Theatrical word-by-word reveal: ogni .line è una "stripe"
   con overflow:hidden e child span che sale da translateY(110%) */
.cine-v3__title .line {
  display: block;
  overflow: hidden;
  padding-bottom: .04em;
}
.cine-v3__title .line > span {
  display: inline-block;
  transform: translateY(110%);
  opacity: 0;
  will-change: transform, opacity;
  transition: transform 1.05s cubic-bezier(.16, 1, .3, 1),
              opacity 1.05s cubic-bezier(.16, 1, .3, 1);
}
.cine-v3__title .line.show > span {
  transform: translateY(0);
  opacity: 1;
}
.cine-v3__title em {
  font-style: normal;
  background: linear-gradient(120deg, var(--cyan), var(--indigo));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  /* NIENTE filter:drop-shadow: anch'esso veniva clippato dalla .line
     (il glow oltre i bordi del box veniva tagliato netto). */
}
.cine-v3__title em.bad {
  background: none;
  -webkit-text-fill-color: initial;
  color: rgba(244, 246, 251, .35);
  position: relative;
  display: inline-block;
}
.cine-v3__title em.bad::after {
  content: '';
  position: absolute;
  left: -4%;
  right: -4%;
  top: 56%;
  height: 3px;
  /* Background gradient: linea piena al centro, trasparente agli estremi.
     Niente più rettangolo netto — sfuma sui lati naturalmente. */
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(0, 242, 255, .65) 12%,
    var(--cyan) 50%,
    rgba(0, 242, 255, .65) 88%,
    transparent 100%);
  /* Glow via drop-shadow: segue l'alpha del background → sfuma anch'esso ai bordi.
     Rimosso box-shadow (rettangolare per natura). */
  filter:
    drop-shadow(0 0 6px rgba(0, 242, 255, .55))
    drop-shadow(0 0 14px rgba(0, 242, 255, .25));
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform .9s cubic-bezier(.16, 1, .3, 1) .65s;
}
.cine-v3__title .line.show em.bad::after {
  transform: scaleX(1);
}

.cine-v3__sub {
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: clamp(17px, 1.4vw, 22px);                /* incrementato — più autorevole, sotto l'H1 */
  font-weight: 400;
  line-height: 1.6;                                    /* respiro tipografico premium */
  letter-spacing: .02em;                               /* spaziatura "agenzia alto livello" */
  color: rgba(255, 255, 255, .75);                     /* argento satinato — alto contrasto su dark */
  margin: 28px 0 0;                                    /* bilanciamento verticale con H1 */
  max-width: 44ch;                                     /* leggermente più largo per evitare a-capo brutti */
  opacity: 0;
  transform: translateY(14px);
  text-wrap: balance;                                  /* a-capo bilanciato (Chrome/Safari) */
  text-shadow: 0 0 22px rgba(0, 242, 255, .10);        /* alone cyan leggermente più presente */
}
.cine-v3__sub em {
  font-style: normal;
  color: #fff;                                          /* bianco pieno sull'em — accent leggibile */
  font-weight: 500;
}

@media (max-width: 700px) {
  .cine-v3__sub {
    font-size: clamp(15px, 4vw, 18px);                  /* mobile: scala leggermente ridotta */
    line-height: 1.55;
    letter-spacing: .015em;
    margin-top: 22px;
    max-width: 30ch;                                    /* mobile: a-capo armonioso su 2-3 righe */
  }
}

/* ---------- Scroll progress (eredita base, palette brand) ---------- */
.cine-v3 .cine__progress {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(10, 15, 31, .72);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  z-index: 11;
  opacity: 0;
  transition: opacity .6s ease .2s;
}
.cine-v3.intro-done .cine__progress { opacity: 1; }
.cine-v3 .cine__progress__bar {
  display: block;
  width: 80px;
  height: 1px;
  background: rgba(255, 255, 255, .10);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
}
.cine-v3 .cine__progress__bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: var(--p, 0%);
  background: linear-gradient(90deg, var(--cyan), var(--indigo));
  border-radius: inherit;
  transition: width .15s linear;
}
.cine-v3 .cine__progress__lbl {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--mute);
  letter-spacing: .2em;
  text-transform: uppercase;
}

/* ---------- Scroll hint ("SCORRI" pulsante) ---------- */
.cine-v3 .cine__hint {
  position: absolute;
  bottom: 76px;
  left: 50%;
  right: auto;                /* annulla il right:24px del .cine__hint legacy (style.css) */
  top: auto;
  transform: translateX(-50%);
  /* IMPORTANTE: annulla l'animation legacy `hintPulse` (style.css ~3572) che usa
     solo translateY(-50%) → cancellerebbe il translateX(-50%) e scentra l'hint.
     L'animazione corretta (cineV3HintBob, con translateX-50%) è riassegnata sotto
     dalla regola .intro-done. */
  animation: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--soft);
  z-index: 11;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s ease;
}
.cine-v3.intro-done:not(.is-scrolled) .cine__hint {
  opacity: 1;
  animation: cineV3HintBob 2s ease-in-out infinite;
}
.cine-v3.is-scrolled .cine__hint { opacity: 0; }
.cine-v3 .cine__hint svg {
  width: 14px;
  height: 14px;
  color: var(--cyan);
  filter: drop-shadow(0 0 6px var(--cyan-glow));
}
@keyframes cineV3HintBob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(6px); }
}

/* ---------- Mobile (≤ 900px) ---------- */
@media (max-width: 900px) {
  .cine-v3 { height: 100vh; height: 100svh; } /* svh: stabile vs barra URL mobile (no jump del pin) */
  .cine-v3__boot {
    bottom: 18px;
    left: 18px;
    right: 18px;
    font-size: 10px;
    letter-spacing: .12em;
  }
  .cine-v3__title { font-size: clamp(32px, 9vw, 56px); max-width: 14ch; }
  .cine-v3__sub   { font-size: 14px; max-width: 30ch; }
  .cine-v3 .cine__hint { bottom: 64px; font-size: 9px; }
}

/* ---------- prefers-reduced-motion: salta intro complessa ---------- */
@media (prefers-reduced-motion: reduce) {
  .cine-v3 { height: 100vh; }
  .cine-v3__gl { opacity: .4; }
  .cine-v3__boot,
  .cine-v3 .cine__hint { display: none; }
  .cine-v3__title,
  .cine-v3__sub {
    opacity: 1 !important;
    transform: none !important;
  }
  .cine-v3 .cine__progress { opacity: 1; }
}

/* ---------- no-hero-3d: dispositivi low-end (deviceMemory < 4 GB o hardwareConcurrency < 4)
   La classe viene aggiunta a <html> dall'IIFE in index.html prima che Three.js venga caricato.
   Obiettivo: mostrare subito il testo, evitare il blocco intro, non caricare il canvas WebGL. ---------- */
html.no-hero-3d .cine-v3__gl {
  display: none;           /* canvas non renderizza: zero GPU overhead */
}
html.no-hero-3d .cine-v3 .cine__stage {
  /* fallback statico: sfondo scuro con gradient cyan/indigo */
  background:
    radial-gradient(ellipse 80% 60% at 20% 50%, rgba(0, 242, 255, .07) 0%, transparent 70%),
    radial-gradient(ellipse 60% 80% at 80% 30%, rgba(79, 70, 229, .09) 0%, transparent 70%),
    #05070D;
}
html.no-hero-3d .cine-v3__boot,
html.no-hero-3d .cine-v3 .cine__hint,
html.no-hero-3d .cine-v3 .cine__progress {
  display: none;           /* nasconde elementi legati all'animazione intro */
}
html.no-hero-3d .cine-v3__title,
html.no-hero-3d .cine-v3__sub {
  opacity: 1 !important;
  transform: none !important;
  transition: none !important;
}
/* Sblocca lo scroll se l'intro-lock viene aggiunto prima che l'IIFE lo prevenga */
html.no-hero-3d.cine-v3-intro-lock,
html.no-hero-3d.cine-v3-intro-lock body {
  overflow: auto !important;
  touch-action: auto !important;
}
