/* =========================================================
   Motion: hero drawing, scroll reveals,
   parallax, timeline progress, gallery lightbox.
   Everything degrades to the static design without JS
   (the `js` class on <html> gates the hidden states).
   ========================================================= */

/* ---------- Hero: self-drawing ball + text fade ---------- */
.js .hero-ball path {
  stroke-dasharray: 3400;
  stroke-dashoffset: 3400;
  animation: ball-draw 2.4s cubic-bezier(.4, 0, .2, 1) forwards;
}
.js .hero-ball path:first-child { animation-delay: .55s; animation-duration: 2.1s; }
.js .hero-ball path:last-child { animation-delay: .15s; }
@keyframes ball-draw { to { stroke-dashoffset: 0; } }

.js .hero-block > *,
.js .hero-translation > * {
  opacity: 0;
  transform: translateY(18px);
  animation: hero-in .9s cubic-bezier(.2, .7, .2, 1) forwards;
}
.js .hero-years { animation-delay: .9s; }
.js .hero-title-wrap { animation-delay: 1.15s; }
.js .hero-quote { animation-delay: 1.5s; }
.js .hero-translation .body-text { animation-delay: 1.7s; }
@keyframes hero-in { to { opacity: 1; transform: none; } }

/* ---------- Scroll reveals ---------- */
.js .rv {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity .9s cubic-bezier(.2, .7, .2, 1), transform .9s cubic-bezier(.2, .7, .2, 1);
  transition-delay: var(--rv-delay, 0ms);
  will-change: opacity, transform;
}
.js .rv.in { opacity: 1; transform: none; }
.js .rv-img {
  opacity: 0;
  transform: scale(1.04);
  transition: opacity 1.1s ease, transform 1.4s cubic-bezier(.2, .7, .2, 1);
  transition-delay: var(--rv-delay, 0ms);
}
.js .rv-img.in { opacity: var(--rv-opacity, 1); transform: none; }
.js .rv-sig { opacity: 0; transition: opacity 1.2s ease .35s; }
.js .rv-sig.in { opacity: 1; }

/* parallax wrapper: JS writes --py (px) based on scroll progress */
.px { transform: translate3d(0, var(--py, 0px), 0); will-change: transform; }

/* ---------- Storia title ---------- */
.js .storia-title.rv, .js .galleria-title.rv { transform: translateY(24px); transition-duration: 1.1s; transition-timing-function: cubic-bezier(.22, .61, .36, 1); }
.js .gallery-intro .body-text.rv { transition-duration: 1.1s; transition-timing-function: cubic-bezier(.22, .61, .36, 1); }
/* gallery intro: fade only, no slide */
.js .gallery-intro .rv, .js .galleria-title.rv { transform: none; }

/* The timeline waits for the title reveal, then fades in (JS adds .in after the title). */
.js .timeline { opacity: 0; transition: opacity .9s cubic-bezier(.22, .61, .36, 1); }
.js .timeline.in { opacity: 1; }

/* ---------- Timeline progress ---------- */
.js .timeline::before { background: rgba(221, 161, 94, .28); }
.js .timeline::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 55px;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--gold);
  transform-origin: top;
  transform: scaleY(var(--tl-progress, 0));
}
/* ---------- Timeline: blur-in ----------
   The content of each row (years, month, heading, text, logo, statue) starts
   blurred and faded and comes into focus as the row enters the viewport.
   Scroll-driven (animation-timeline: view()) where supported, so it follows the
   scroll in both directions; otherwise the IntersectionObserver toggles .in and
   a transition does the same job. The containers keep an opaque cream background
   so the gold line never shows through the animated content. */
.js .tl-row, .js .tl-image-row { position: relative; z-index: 1; }
.js .tl-item > *,
.js .tl-logo-cell > *,
.js .tl-image-row img {
  opacity: .2;
  filter: blur(.5rem);
  transition: opacity .9s cubic-bezier(.2, .7, .2, 1), filter .9s cubic-bezier(.2, .7, .2, 1);
}
.js .tl-years > * {
  position: relative;
  z-index: 1;
  background: var(--cream);
  color: color-mix(in srgb, var(--sea) 20%, var(--cream));
  filter: blur(.5rem);
  transition: color .9s cubic-bezier(.2, .7, .2, 1), filter .9s cubic-bezier(.2, .7, .2, 1);
}
.js .tl-row.in .tl-item > *,
.js .tl-row.in .tl-logo-cell > *,
.js .tl-image-row.in img { opacity: 1; filter: blur(0); }
.js .tl-row.in .tl-years > * { color: var(--sea); filter: blur(0); }
@keyframes tl-blur-in {
  from { opacity: .2; filter: blur(.5rem); }
  to { opacity: 1; filter: blur(0); }
}
@keyframes tl-year-in {
  from { color: color-mix(in srgb, var(--sea) 20%, var(--cream)); filter: blur(.5rem); }
  to { color: var(--sea); filter: blur(0); }
}
@supports (animation-timeline: view()) {
  .js .tl-item > *,
  .js .tl-logo-cell > *,
  .js .tl-image-row img {
    transition: none;
    animation: tl-blur-in linear both;
    animation-timeline: view(block);
    animation-range: entry 5% entry 70%;
  }
  .js .tl-years > * {
    transition: none;
    animation: tl-year-in linear both;
    animation-timeline: view(block);
    animation-range: entry 5% entry 70%;
  }
}

/* ---------- Gallery lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility .3s ease;
}
.lightbox.is-open { opacity: 1; visibility: visible; }
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(244, 241, 232, .88);
  mix-blend-mode: hard-light;
}
.lightbox-stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: min(1100px, calc(100vw - 2 * 260px));
  max-width: 100%;
}
.lightbox-strip {
  display: flex;
  width: 100%;
  max-height: calc(100vh - 170px);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.lightbox-strip::-webkit-scrollbar { display: none; }
.lightbox-slide {
  flex: 0 0 100%;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
.lightbox-slide img {
  max-width: 100%;
  max-height: calc(100vh - 170px);
  width: auto;
  height: auto;
  object-fit: contain;
}
.lightbox-nav { display: flex; align-items: center; justify-content: center; gap: 24px; }
@media (min-width: 1001px) {
  .lightbox-stage {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    grid-template-areas: "prev strip next" ". counter .";
    column-gap: 24px;
    row-gap: 24px;
    align-items: center;
    justify-items: center;
    width: min(1228px, calc(100vw - 2 * 120px));
  }
  .lightbox-strip { grid-area: strip; }
  .lightbox-nav { display: contents; }
  .lightbox-counter { grid-area: counter; }
  .lightbox-stage .lightbox-prev, .lightbox-stage .lightbox-next { position: static; margin: 0; }
  .lightbox-prev { grid-area: prev; }
  .lightbox-next { grid-area: next; }
}
.lightbox-btn {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  transition: background-color .2s ease, transform .2s ease;
}
.lightbox-btn:hover { background: rgba(221, 161, 94, .14); }
.lightbox-btn:active { transform: scale(.94); }
.lightbox-btn svg { width: 24px; height: 24px; display: block; }
.lightbox-prev { left: 200px; top: 50%; margin-top: -20px; }
.lightbox-next { right: 200px; top: 50%; margin-top: -20px; }
.lightbox-prev svg { transform: rotate(180deg); }
.lightbox-close { top: 40px; right: 120px; }
.lightbox-counter {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  letter-spacing: 1px;
  color: var(--pine);
}
body.lightbox-open { overflow: hidden; }

@media (max-width: 1260px) {
  .lightbox-prev { left: 24px; }
  .lightbox-next { right: 24px; }
  .lightbox-close { right: 24px; top: 24px; }
  .lightbox-stage { width: calc(100vw - 2 * 64px); }
}
@media (max-width: 1000px) {
  /* mobile: swipeable strip, chevrons + counter as pagination 24px under the image */
  .lightbox-stage { width: 100vw; }
  .lightbox-strip, .lightbox-slide img { max-height: calc(100vh - 200px); }
  .lightbox-slide { padding: 0 16px; }
  .lightbox-prev, .lightbox-next { position: static; margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .lightbox-strip { scroll-behavior: auto; }
  .js .hero-ball path { animation: none; stroke-dashoffset: 0; }
  .js .hero-block > *, .js .hero-translation > * { animation: none; opacity: 1; transform: none; }
  .js .rv, .js .rv-img, .js .rv-sig { opacity: var(--rv-opacity, 1); transform: none; transition: none; }
  .js .tl-years > *, .js .tl-item > *, .js .tl-logo-cell > *, .js .tl-image-row img { opacity: 1 !important; color: var(--sea); filter: none !important; animation: none !important; transition: none !important; }
  .js .timeline { opacity: 1; transition: none; }
  .px { transform: none !important; }
  .js .timeline::after { transform: none; }
}
