/* =============================================
   CALCESTRUZZI MAGNATI – Animazioni
   Gli stati "nascosti in attesa di comparire" sono attivi solo con JavaScript
   (classe .js su <html>): senza JS i contenuti restano sempre visibili.
   Le animazioni usano solo transform/opacity (accelerate dalla GPU).
   ============================================= */

/* ---------- 1. PRELOADER ---------- */
#preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  transition: opacity .55s ease, visibility .55s ease;
}
html:not(.js) #preloader { display: none; }
#preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.preloader__logo {
  display: flex;
  align-items: center;
  gap: 14px;
  animation: preloaderLogoIn .7s cubic-bezier(.22,.61,.36,1) forwards;
  opacity: 0;
  transform: translateY(20px);
}
@keyframes preloaderLogoIn {
  to { opacity: 1; transform: translateY(0); }
}
.preloader__logo img {
  width: min(260px, 70vw);
  height: auto;
}
.preloader__bar-wrap {
  width: 240px;
  height: 3px;
  background: rgba(255,255,255,.1);
  border-radius: 3px;
  overflow: hidden;
  animation: preloaderLogoIn .7s .2s cubic-bezier(.22,.61,.36,1) forwards;
  opacity: 0;
}
.preloader__bar {
  height: 100%;
  width: 100%;
  background: var(--primary);
  border-radius: 3px;
  transform: scaleX(0);
  transform-origin: left;
  animation: preloaderBar 1.8s .3s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes preloaderBar {
  0%   { transform: scaleX(0); }
  60%  { transform: scaleX(.75); }
  100% { transform: scaleX(1); }
}
.preloader__pct {
  font-family: var(--font-cond);
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255,255,255,.4);
  letter-spacing: .12em;
  animation: preloaderLogoIn .7s .25s cubic-bezier(.22,.61,.36,1) forwards;
  opacity: 0;
}

/* ---------- 2. BLOCCO SCROLL DURANTE IL CARICAMENTO ---------- */
.js body.is-loading { overflow: hidden; }

/* ---------- 3. COMPARSA ALLO SCORRIMENTO ---------- */
.js [data-sr] {
  opacity: 0;
  transition: opacity .7s cubic-bezier(.22,.61,.36,1),
              transform .7s cubic-bezier(.22,.61,.36,1);
}
.js [data-sr].sr-visible {
  opacity: 1 !important;
  transform: none !important;
}
.js [data-sr="fade-up"]    { transform: translateY(48px); }
.js [data-sr="fade-down"]  { transform: translateY(-48px); }
.js [data-sr="fade-left"]  { transform: translateX(60px); }
.js [data-sr="fade-right"] { transform: translateX(-60px); }
.js [data-sr="zoom-in"]    { transform: scale(.88); }

/* Su smartphone spostamento laterale ridotto (niente elementi fuori schermo) */
@media (max-width: 768px) {
  .js .contact-item:not(.sr-visible) { transform: translateY(20px); }
  .js [data-sr="fade-left"]  { transform: translateX(24px); }
  .js [data-sr="fade-right"] { transform: translateX(-24px); }
  .js [data-sr="fade-up"]    { transform: translateY(32px); }
}

/* ---------- 4. TITOLO HERO PAROLA PER PAROLA ---------- */
.hero__title .word {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  padding: 0 .02em .04em;
}
.hero__title .word span {
  display: inline-block;
  transform: translateY(110%);
  transition: transform .7s cubic-bezier(.22,.61,.36,1);
}
.hero__content.hero-entered .hero__title .word span { transform: translateY(0); }
.hero__title .word:nth-child(1) span { transition-delay: .25s; }
.hero__title .word:nth-child(2) span { transition-delay: .38s; }
.hero__title .word:nth-child(3) span { transition-delay: .51s; }
.hero__title .word:nth-child(4) span { transition-delay: .64s; }
.hero__title .word:nth-child(5) span { transition-delay: .77s; }
.hero__title .word:nth-child(6) span { transition-delay: .9s; }

.js .hero__badge,
.js .hero__desc,
.js .hero__actions { opacity: 0; }
.js .hero__badge   { transform: translateX(-20px); transition: opacity .5s ease .1s, transform .5s ease .1s; }
.js .hero__desc    { transform: translateY(20px);  transition: opacity .6s ease .6s, transform .6s ease .6s; }
.js .hero__actions { transform: translateY(20px);  transition: opacity .6s ease .8s, transform .6s ease .8s; }
.js .hero__content.hero-entered .hero__badge,
.js .hero__content.hero-entered .hero__desc,
.js .hero__content.hero-entered .hero__actions { opacity: 1; transform: none; }

/* ---------- 5. RIVELAZIONE IMMAGINE A TENDINA ---------- */
.clip-reveal { position: relative; overflow: hidden; }
.js .clip-reveal::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--primary);
  z-index: 2;
  transition: transform .9s cubic-bezier(.77,0,.175,1);
}
.js .clip-reveal.revealed::before { transform: translateX(101%); }
.js .clip-reveal img {
  transform: scale(1.08);
  transition: transform .9s cubic-bezier(.77,0,.175,1) .15s;
}
.js .clip-reveal.revealed img { transform: scale(1); }

/* ---------- 6. SERVIZI: COMPARSA A CASCATA ----------
   Il ritardo dipende da --i (posizione della card, impostata in PHP) e vale
   solo per la comparsa: l'effetto al passaggio del mouse resta immediato. */
.js .services__grid .service-card {
  opacity: 0;
  transform: translateY(50px);
  transition: opacity .6s cubic-bezier(.22,.61,.36,1) calc(var(--i, 0) * .12s),
              transform .6s cubic-bezier(.22,.61,.36,1) calc(var(--i, 0) * .12s),
              background .3s ease,
              border-color .3s ease,
              box-shadow .3s ease;
}
.js .services__grid .service-card.sr-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- 7. ALTRI ELEMENTI A CASCATA ---------- */
.js .why__cards .why-card,
.js .contact-item,
.js .footer__col {
  opacity: 0;
  transition: opacity .55s cubic-bezier(.22,.61,.36,1),
              transform .55s cubic-bezier(.22,.61,.36,1),
              background .3s ease, color .3s ease, box-shadow .3s ease;
}
.js .why__cards .why-card { transform: translateY(35px); }
.js .contact-item         { transform: translateX(-30px); }
.js .footer__col          { transform: translateY(24px); }
.js .why__cards .why-card.sr-visible,
.js .contact-item.sr-visible,
.js .footer__col.sr-visible { opacity: 1; transform: none; }
.js .why__cards .why-card.sr-visible:hover { transform: translateY(-4px); }

.why__cards .why-card:nth-child(2) { transition-delay: .12s; }
.why__cards .why-card:nth-child(3) { transition-delay: .24s; }
.contact-item:nth-child(1) { transition-delay: .1s; }
.contact-item:nth-child(2) { transition-delay: .22s; }
.contact-item:nth-child(3) { transition-delay: .34s; }
.contact-item:nth-child(4) { transition-delay: .46s; }
.footer__col:nth-child(2) { transition-delay: .1s; }
.footer__col:nth-child(3) { transition-delay: .2s; }
.footer__col:nth-child(4) { transition-delay: .3s; }

/* ---------- 8. PULSANTI: TRANSIZIONI, MAGNETE, RIPPLE ---------- */
.btn {
  position: relative;
  overflow: hidden;
  transition: transform .2s cubic-bezier(.22,.61,.36,1),
              background .3s ease,
              color .3s ease,
              box-shadow .3s ease,
              border-color .3s ease;
}
.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.35);
  transform: scale(0);
  animation: rippleEffect .55s linear;
  pointer-events: none;
}
@keyframes rippleEffect {
  to { transform: scale(4); opacity: 0; }
}

/* ---------- 9. CURSORE PERSONALIZZATO (solo mouse) ---------- */
.cursor,
.cursor-ring {
  position: fixed;
  left: -100px;
  top: -100px;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: left, top;
}
.cursor {
  width: 10px; height: 10px;
  background: var(--primary);
  z-index: 99999;
  transition: width .15s ease, height .15s ease, background .15s ease;
  mix-blend-mode: difference;
}
.cursor-ring {
  width: 36px; height: 36px;
  border: 2px solid var(--primary);
  z-index: 99998;
  transition: width .3s ease, height .3s ease, border-color .3s ease, opacity .3s ease;
  opacity: .5;
}
.cursor-ring.hovering {
  width: 56px; height: 56px;
  opacity: .9;
}
@media (hover: none), (pointer: coarse) {
  .cursor, .cursor-ring { display: none; }
}

/* ---------- 10. CHI SIAMO (Home): IMMAGINE FLUTTUANTE E BADGE ---------- */
.about__img-secondary { animation: floatY 5s ease-in-out infinite; }
@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-12px); }
}
.about__exp-badge { animation: badgePulse 3s ease-in-out infinite; }
@keyframes badgePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(227,6,19,.45); }
  50%       { box-shadow: 0 0 0 14px rgba(227,6,19,0); }
}

/* ---------- 11. MENU: SOTTOLINEATURA ---------- */
.nav__link { position: relative; }
.nav__link::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--primary);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform .3s cubic-bezier(.22,.61,.36,1);
  border-radius: 2px;
}
.nav__link:hover::after,
.nav__link.active::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* ---------- 12. INDICATORE "SCORRI" (Hero) ---------- */
.hero__scroll-hint {
  position: absolute;
  bottom: 50px;
  right: 40px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0;
  animation: hintIn 1s 1.8s ease forwards;
}
@keyframes hintIn { to { opacity: 1; } }
.hero__scroll-hint span {
  writing-mode: vertical-rl;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: rgba(255,255,255,.55);
}
.hero__scroll-hint-line {
  width: 2px;
  height: 50px;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.hero__scroll-hint-line::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--primary);
  transform: translateY(-100%);
  animation: scrollLine 2s 2s ease-in-out infinite;
}
@keyframes scrollLine {
  0%   { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

/* ---------- 13. VARIE ---------- */
.scroll-top:hover .icon { animation: arrowBounce .5s ease; }
@keyframes arrowBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}

/* Pausa di marquee e ticker al passaggio del mouse */
.projects-marquee:hover .projects-marquee__track,
.hero__ticker:hover .hero__ticker-track { animation-play-state: paused; }

/* Header che scende al caricamento */
.js .header {
  animation: headerSlideDown .7s .3s cubic-bezier(.22,.61,.36,1) backwards;
}
.js .topbar {
  animation: headerSlideDown .6s .1s cubic-bezier(.22,.61,.36,1) backwards;
}
@keyframes headerSlideDown {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

/* Icone che ruotano al passaggio del mouse */
.service-card:hover .service-card__icon .icon,
.why-card:hover .why-card__icon .icon,
.contact-item:hover .contact-item__icon .icon {
  animation: iconSpin .5s ease;
}
@keyframes iconSpin {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(15deg) scale(1.15); }
  100% { transform: rotate(0deg) scale(1); }
}

.form-group input:not([type="checkbox"]):focus,
.form-group select:focus,
.form-group textarea:focus { transform: scale(1.005); }

/* ---------- 14. ANIMAZIONI RIDOTTE ----------
   Rispetta l'impostazione di sistema "Riduci movimento" (iOS, Android, Windows, macOS). */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
  .hero__ticker-track, .projects-marquee__track { animation: none !important; }
  .hero__ticker, .projects-marquee { overflow-x: auto; scrollbar-width: none; }
  .js [data-sr], .js .services__grid .service-card, .js .why__cards .why-card,
  .js .contact-item, .js .footer__col, .gallery-item { transform: none !important; }
  .hero__title .word span { transform: none !important; }
  .cursor, .cursor-ring { display: none; }
}
