/* HERO — sfondo nero, foto flottanti */
.hero {
  position: relative;
  min-height: calc(88vh - 70px);
  background: #0a0a0a url('../assets/dark-smart.jpg') center / cover no-repeat;
  overflow: hidden;
  margin-bottom: clamp(48px, 7vh, 88px);
}

/* Motto layer: ora non è più un semplice fade, ma viene scritto riga per riga */
.hero::before {
  content: none;
}

.hero-motto-handwrite {
  position: absolute;
  left: 50%;
  top: 60%;
  z-index: 3;
  width: clamp(220px, 24vw, 320px);
  aspect-ratio: 1371 / 1705;
  transform: translate3d(-50%, -50%, 0) scale(.995);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 0 24px rgba(0,0,0,.72));
  will-change: opacity, transform, filter;
}

.hero-motto-line {
  position: absolute;
  inset: 0;
  display: block;
  background: url('../assets/motto-2026-lowercase-white-transparent-4.png') center / contain no-repeat;
  clip-path: inset(var(--top) 0 var(--bottom) 0);
  opacity: 0;
  -webkit-mask-image: linear-gradient(90deg, #000 0%, #000 100%);
  mask-image: linear-gradient(90deg, #000 0%, #000 100%);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: left center;
  mask-position: left center;
  -webkit-mask-size: 0% 100%;
  mask-size: 0% 100%;
  will-change: opacity, -webkit-mask-size, mask-size;
}

.hero.hero-motto-sequence .hero-motto-handwrite {
  animation: heroMottoHandwriteStage 8s ease forwards;
}

.hero.hero-motto-sequence .hero-motto-line {
  animation: heroMottoLineWrite 1.0s linear var(--delay, 0s) forwards;
}

/* Contenitore foto flottanti */
.hero-photos {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* Ogni foto è un div assoluto creato via JS.
   Il frame resta fermo; lo zoom avviene solo sul layer interno,
   così non tremano clip-path, ombre e dissolvenze. */
.hero-photo {
  position: absolute;
  border-radius: 10px;
  opacity: 0;
  filter: blur(24px) brightness(.67) contrast(1.02) saturate(.90);
  transform: translate3d(0,0,0);
  transform-origin: center center;
  will-change: opacity, filter;
  backface-visibility: hidden;
  contain: paint;
  isolation: isolate;
  transition:
    opacity 2.15s ease,
    filter 3.55s cubic-bezier(.16, .84, .24, 1);
  box-shadow: 0 8px 48px rgba(0,0,0,.6);
  overflow: hidden;
}

.hero-photo-core {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  transform: translate3d(0,0,0) scale(1.02);
  transform-origin: center center;
  will-change: transform;
  backface-visibility: hidden;
  pointer-events: none;
}

@keyframes heroPhotoSlowZoom {
  from { transform: translate3d(0,0,0) scale(1.02); }
  to { transform: translate3d(0,0,0) scale(var(--hero-zoom-end, 1.11)); }
}

/* Gentle, elegant irregularity (subtle handcrafted edges) */
.hero-photo.edge-rough-1 {
  clip-path: polygon(1.2% 1.3%, 20% 1.0%, 40% 1.4%, 60% 1.0%, 80% 1.4%, 98.8% 1.2%, 99% 20%, 98.6% 40%, 99% 60%, 98.6% 80%, 98.8% 98.8%, 80% 99%, 60% 98.6%, 40% 99%, 20% 98.6%, 1.2% 98.8%, 1.0% 80%, 1.4% 60%, 1.0% 40%, 1.4% 20%);
}
.hero-photo.edge-rough-2 {
  clip-path: polygon(1.1% 1.5%, 20% 1.1%, 40% 1.0%, 60% 1.4%, 80% 1.0%, 98.9% 1.4%, 98.8% 20%, 99% 40%, 98.5% 60%, 99% 80%, 98.7% 98.9%, 80% 98.8%, 60% 99%, 40% 98.6%, 20% 99%, 1.3% 98.7%, 1.0% 80%, 1.4% 60%, 1.0% 40%, 1.5% 20%);
}
.hero-photo.edge-rough-3 {
  clip-path: polygon(1.3% 1.1%, 20% 1.4%, 40% 1.0%, 60% 1.4%, 80% 1.1%, 98.7% 1.3%, 99% 20%, 98.5% 40%, 99% 60%, 98.5% 80%, 98.8% 98.7%, 80% 99%, 60% 98.5%, 40% 99%, 20% 98.5%, 1.1% 98.8%, 1.4% 80%, 1.0% 60%, 1.4% 40%, 1.1% 20%);
}
.hero-photo.edge-rough-4 {
  clip-path: polygon(1.0% 1.2%, 20% 1.0%, 40% 1.3%, 60% 1.0%, 80% 1.3%, 99% 1.1%, 98.8% 20%, 99% 40%, 98.6% 60%, 99% 80%, 98.9% 99%, 80% 98.8%, 60% 99%, 40% 98.7%, 20% 99%, 1.2% 98.9%, 1.0% 80%, 1.3% 60%, 1.0% 40%, 1.2% 20%);
}

/* Soft grain + edge falloff to avoid flat-looking frames */
.hero-photo::before,
.hero-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 1.6s ease;
}
.hero-photo::before {
  opacity: .40;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.03),
    inset 0 0 46px rgba(0,0,0,.34),
    inset 0 0 120px rgba(0,0,0,.58),
    inset 0 0 176px rgba(0,0,0,.46);
}
.hero-photo::after {
  opacity: .24;
  mix-blend-mode: multiply;
  background-image:
    radial-gradient(circle at 24% 18%, rgba(0,0,0,.18) 0%, rgba(0,0,0,0) 35%),
    radial-gradient(circle at 78% 24%, rgba(0,0,0,.15) 0%, rgba(0,0,0,0) 32%),
    radial-gradient(circle at 62% 74%, rgba(0,0,0,.16) 0%, rgba(0,0,0,0) 36%),
    radial-gradient(circle at center, transparent 52%, rgba(0,0,0,.26) 76%, rgba(0,0,0,.52) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.25' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 190px 190px;
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, repeat;
}
.hero-photo.visible {
  opacity: .84;
  filter: blur(22px) brightness(.75) contrast(1.03) saturate(.91);
}
.hero-photo.visible.hero-photo--high-ready {
  filter: blur(0px) brightness(.80) contrast(1.04) saturate(.92);
}
.hero-photo.visible .hero-photo-core {
  animation: heroPhotoSlowZoom 7s linear forwards;
}
.hero-photo.visible::before {
  opacity: .56;
}
.hero-photo.visible::after {
  opacity: .30;
}
.hero-photo.crossfade-prep {
  opacity: 0;
  filter: blur(24px) brightness(.67) contrast(1.02) saturate(.9);
}
.hero-photo.crossfade-prep .hero-photo-core,
.hero-photo.crossfade-in .hero-photo-core {
  transform: translate3d(0,0,0) scale(1.05);
}
.hero-photo.crossfade-in {
  opacity: .84;
  filter: blur(22px) brightness(.75) contrast(1.03) saturate(.91);
  transition: opacity 2.25s ease, filter 3.55s cubic-bezier(.16, .84, .24, 1);
}
.hero-photo.crossfade-in.hero-photo--high-ready {
  filter: blur(0px) brightness(.80) contrast(1.04) saturate(.92);
}
.hero-photo.crossfade-in::before {
  opacity: .56;
  transition: opacity 2.2s ease;
}
.hero-photo.crossfade-in::after {
  opacity: .30;
  transition: opacity 2.2s ease;
}
.hero-photo.crossfade-out {
  opacity: 0 !important;
  filter: blur(11px) brightness(.48) contrast(.98) saturate(.88) !important;
  transition: opacity 2.2s ease, filter 2.2s ease !important;
}
.hero-photo.crossfade-out::before {
  opacity: .18;
  transition: opacity 2.2s ease;
}
.hero-photo.crossfade-out::after {
  opacity: .10;
  transition: opacity 2.2s ease;
}
.hero-photo.fading {
  opacity: 0;
  filter: blur(6px) brightness(.56) contrast(.96) saturate(.9);
  transition: opacity 1.8s ease, filter 1.8s ease;
}
.hero-photo.fading::before {
  opacity: .22;
}
.hero-photo.fading::after {
  opacity: .14;
}
/* Uscita: dissolve soltanto; lo zoom continua tramite animazione, senza scatti di transform */
.hero-photo--exit {
  opacity: 0 !important;
  filter: blur(8px) brightness(.4) !important;
  transition:
    opacity 1.8s ease,
    filter 1.8s ease !important;
}

/* Scrim leggero solo in alto e in basso per logo e motto */
.hero-scrim {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(0,0,0,.72) 0%,
      rgba(0,0,0,.18) 18%,
      rgba(0,0,0,.0) 40%,
      rgba(0,0,0,.0) 60%,
      rgba(0,0,0,.22) 80%,
      rgba(0,0,0,.80) 100%);
}

/* ---- NAV brand visibile nella hero: statico, non cliccabile, molto scuro ---- */
.brand { transition: opacity .4s ease, visibility .4s ease, filter .4s ease; }
.brand.hero-hidden { opacity: .60; visibility: visible; pointer-events: none; filter: none; }

/* ---- Logo in alto centrato ---- */
.hero-logo-wrap {
  position: absolute;
  top: clamp(18px, 2.5vh, 36px);
  left: 50%;
  transform-origin: center center;
  transform: translate3d(-50%,0,0) scale(1);
  filter: blur(0);
  opacity: 1;
  z-index: 4;
  width: min(780px, 80vw);
  backface-visibility: hidden;
  will-change: transform, filter, opacity;
  animation: heroLogoSettle 1.05s cubic-bezier(.22,.72,.24,1) .32s both;
}
body.pre-entry .hero-logo-wrap,
body.pre-entry.entry-revealing .hero-logo-wrap {
  animation: none !important;
  opacity: 0 !important;
  transform: translate3d(-50%,0,0) scale(2.15) !important;
  filter: blur(22px) !important;
}
.hero-logo {
  width: 100%;
  height: auto;
  display: block;
  opacity: .90;
  filter: drop-shadow(0 0 24px rgba(0,0,0,.9));
  backface-visibility: hidden;
}

/* ---- Motto in basso centrato ---- */
@keyframes heroLogoSettle {
  from {
    transform: translate3d(-50%,0,0) scale(2.15);
    filter: blur(22px);
    opacity: 0;
  }
  to {
    transform: translate3d(-50%,0,0) scale(1);
    filter: blur(0);
    opacity: 1;
  }
}

@keyframes heroMottoHandwriteStage {
  0% {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) scale(.995);
    filter: blur(.4px) drop-shadow(0 0 24px rgba(0,0,0,.72));
  }
  11% {
    opacity: 1;
  }
  62% {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) scale(1);
    filter: blur(0) drop-shadow(0 0 24px rgba(0,0,0,.72));
  }
  84% {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) scale(1);
    filter: blur(0) drop-shadow(0 0 24px rgba(0,0,0,.72));
  }
  100% {
    opacity: 0;
    transform: translate3d(-50%, -50%, 0) scale(1.045);
    filter: blur(2px) drop-shadow(0 0 18px rgba(0,0,0,.65));
  }
}

@keyframes heroMottoLineWrite {
  0% {
    opacity: 0;
    -webkit-mask-size: 0% 100%;
    mask-size: 0% 100%;
  }
  8% {
    opacity: .22;
  }
  100% {
    opacity: .22;
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
  }
}

/* ============================================================
   HERO — mobile (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  .hero { min-height: 92vh; }

  .hero-logo-wrap {
    top: 44px;
    width: min(88vw, 380px);
  }
}
