/* ==========================================================================
   World Recycling srl: "Il viaggio dei tuoi rifiuti" / "The journey of your
   waste", on the two home pages since 04/12/2026. Loaded after v3.css.

   The scene is drawn by assets/js/viaggio.js, which adds .viaggio--attivo
   at once and .viaggio--pronto when the drawing is whole. Without it, on
   paper and on a phone lying down, the section is the six steps as a list.
   ========================================================================== */

.viaggio {
  position: relative;
  background: var(--abisso);
  color: var(--on-dark);
  --focus: var(--giallo);
}

/* "Salta il viaggio": hidden until a keyboard reaches it */
.viaggio__salta {
  position: absolute;
  z-index: 60;
  top: calc(var(--header-h) + 0.75rem);
  left: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--giallo);
  color: var(--mare);
  font-weight: 700;
  text-decoration: none;
  border-radius: 0.25rem;
}
.viaggio__salta:not(:focus) {
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- The plain version (no script, a phone lying down) ---------- */

.viaggio__stage { position: relative; }
.viaggio__scena,
.viaggio__rotta,
.viaggio__carte { display: none; }

.viaggio__testi { padding-block: var(--space); }

.viaggio__titolo,
.viaggio__passo h3 { color: var(--on-dark); }

.viaggio__titolo {
  margin: 0 0 2.25rem;
  font-family: var(--font-wide);
  font-stretch: var(--wide);
  font-weight: 800;
  font-size: var(--step-3);
  line-height: 1.05;
}

.viaggio__passi {
  display: grid;
  gap: 2rem 3rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.viaggio__passo h3 {
  margin: 0 0 0.5rem;
  font-family: var(--font-wide);
  font-stretch: var(--wide);
  font-weight: 800;
  font-size: var(--step-2);
  line-height: 1.1;
}

.viaggio__n {
  display: inline-block;
  margin-right: 0.35em;
  color: var(--giallo);
  font-family: var(--font-board);
  font-stretch: normal;
  font-weight: 600;
}

.viaggio__passo p {
  max-width: 34rem;
  margin: 0;
  color: var(--on-dark-2);
}

/* ---------- The scene (with the script) ---------- */

.viaggio--attivo {
  height: 760vh;
  /* behind the words, where a crane, a lamp or a white post can pass */
  --vg-ombra: 0 0 0.2em rgba(3, 15, 23, 0.95), 0 0 0.5em rgba(3, 15, 23, 0.9), 0 0 1em rgba(3, 15, 23, 0.7);
}

.viaggio--attivo .viaggio__stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: #030F17;
}

/* it is built a piece at a time and shows when it is whole; 0.001 and not 0,
   so the browser prepares the pieces in the meantime */
.viaggio--attivo .viaggio__scena {
  display: block;
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0.001;
}

.viaggio--pronto .viaggio__scena {
  opacity: 1;
  transition: opacity 0.4s ease;
}

.vg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.vg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  will-change: transform;
}

.vg-sp {
  position: absolute;
  top: 0;
  left: 0;
}

.vg-sp svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.vg-sp--dyn { will-change: transform; }

/* the words over the sky, with a veil so they stay legible over the cranes */
.viaggio--attivo .viaggio__testi {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  left: 0;
  margin-inline: auto;
  padding-top: calc(var(--header-h) + clamp(1rem, 4.5vh, 3rem));
  padding-bottom: 0;
  pointer-events: none;
}

.viaggio--attivo .viaggio__testi::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  right: calc(50% - 50vw);
  bottom: -7rem;
  left: calc(50% - 50vw);
  background: linear-gradient(180deg, rgba(3, 15, 23, 0.85) 0%, rgba(3, 15, 23, 0.55) 55%, rgba(3, 15, 23, 0) 100%);
}

@media (min-width: 56em) {
  .viaggio--attivo .viaggio__testi::before {
    background: linear-gradient(90deg, rgba(3, 15, 23, 0.72) 0%, rgba(3, 15, 23, 0.4) 40%, rgba(3, 15, 23, 0) 62%);
    -webkit-mask-image: linear-gradient(180deg, #000 50%, transparent);
    mask-image: linear-gradient(180deg, #000 50%, transparent);
  }
}

/* short phones: the words go down to the drawing, and the veil with them */
@media (max-width: 55.99em) and (max-height: 38em) {
  .viaggio--attivo .viaggio__testi::before {
    bottom: -13rem;
    background: linear-gradient(180deg, rgba(3, 15, 23, 0.88) 0%, rgba(3, 15, 23, 0.66) 68%, rgba(3, 15, 23, 0) 100%);
  }
}

/* step 5 begins while the port's crane is still going by behind its three lines: a deeper shade, only
   while that step shows */
@media (min-width: 56em) {
  .viaggio--attivo .viaggio__testi::after {
    content: "";
    position: absolute;
    z-index: -1;
    top: 0;
    right: calc(50% - 50vw);
    bottom: -18rem;
    left: calc(50% - 50vw);
    background: linear-gradient(90deg, rgba(3, 15, 23, 0.8) 0%, rgba(3, 15, 23, 0.62) 38%, rgba(3, 15, 23, 0) 66%);
    -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent);
    mask-image: linear-gradient(180deg, #000 70%, transparent);
    opacity: 0;
    transition: opacity 0.35s ease;
  }

  .viaggio--attivo .viaggio__testi:has(.viaggio__passo:nth-child(5).is-attivo)::after { opacity: 1; }
}

/* in a low window (a laptop with its browser's bars) the crane is behind step 4's words too */
@media (min-width: 56em) and (max-height: 48em) {
  .viaggio--attivo .viaggio__testi:has(.viaggio__passo:nth-child(4).is-attivo)::after { opacity: 1; }
}

.viaggio--attivo .viaggio__titolo {
  margin: 0 0 0.9rem;
  font-family: var(--font);
  font-stretch: normal;
  font-size: var(--step-0);
  font-weight: 600;
  color: var(--celeste-chiaro);
}

.viaggio--attivo .viaggio__passi {
  display: block;
  position: relative;
}

.viaggio--attivo .viaggio__passo {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 40rem;
  opacity: 0;
  transform: translateY(0.9rem);
}

/* the fades start only after the first drawing, so the list never flashes while the scene sets up */
.viaggio--pronto .viaggio__passo {
  transition: opacity 0.35s ease, transform 0.6s var(--ease-out);
}

.viaggio--attivo .viaggio__passo.is-attivo {
  opacity: 1;
  transform: none;
}

.viaggio--attivo .viaggio__passo h3 {
  margin-bottom: 0.8rem;
  font-size: clamp(2rem, 1.15rem + 3.4vw, 3.75rem);
  line-height: 1;
}

.viaggio--attivo .viaggio__passo p {
  font-size: clamp(1rem, 0.92rem + 0.35vw, 1.25rem);
  line-height: 1.45;
  text-shadow: var(--vg-ombra);
}

@media (prefers-reduced-motion: reduce) {
  .viaggio--attivo .viaggio__passo { transform: none; }
  .viaggio--pronto .viaggio__passo { transition: opacity 0.2s linear; }
}

/* step 5: its sentence is the longest; even lines, and three of them on wide screens, keep the papers
   under it clear of the ship */
.viaggio--attivo .viaggio__passo:nth-child(5) p { text-wrap: balance; }

@media (min-width: 56em) {
  .viaggio--attivo .viaggio__passo:nth-child(5) p { max-width: min(39rem, 60vw); }
}

/* step 5: the papers that travel with the load */
.viaggio--attivo .viaggio__carte {
  display: grid;
  gap: 0.3rem;
  max-width: 15.5rem; /* clear of the docked ship's mast */
  margin: 0.75rem 0 0;
  padding: 0.65rem 1.1rem 0.7rem;
  list-style: none;
  background: var(--schiuma);
  color: var(--ink-2);
  border-top: 4px solid var(--verde);
  border-radius: 0.2rem;
  font-size: var(--step--1);
  box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.35);
}

.viaggio__spunta {
  position: relative;
  padding-left: 1.75rem;
}

.viaggio__spunta::before {
  content: "";
  position: absolute;
  top: 0.12em;
  left: 0;
  width: 1.15rem;
  height: 1.15rem;
  border: 2px solid var(--line);
  border-radius: 50%;
  box-sizing: border-box;
}

.viaggio__spunta.is-fatta {
  color: var(--ink);
  font-weight: 600;
}

.viaggio__spunta.is-fatta::before {
  background: var(--verde);
  border-color: var(--verde);
}

.viaggio__spunta.is-fatta::after {
  content: "";
  position: absolute;
  top: 0.32em;
  left: 0.4rem;
  width: 0.3rem;
  height: 0.56rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* the route along the bottom: one stop per step */
.viaggio--attivo .viaggio__rotta {
  display: block;
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 0;
  left: 0;
  height: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(0deg, rgba(3, 15, 23, 0.7), rgba(3, 15, 23, 0));
}

.viaggio__linea {
  position: absolute;
  top: 1.75rem;
  right: calc(clamp(2.5rem, 5vw, 4.5rem) + 3.25rem);
  left: clamp(1.5rem, 4vw, 3.5rem);
  height: 2px;
  background: rgba(156, 195, 232, 0.3);
}

.viaggio__fill {
  position: absolute;
  inset: 0;
  background: var(--giallo);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.viaggio__tappa {
  position: absolute;
  top: 0;
  width: 2.25rem;
  height: 2.25rem;
  margin: -1.125rem 0 0 -1.125rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--on-dark-2);
  font: 500 0.8125rem/1 var(--font-board);
  cursor: pointer;
}

.viaggio__tappa::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.75rem;
  height: 0.75rem;
  margin: -0.375rem 0 0 -0.375rem;
  border: 2px solid var(--celeste-chiaro);
  border-radius: 50%;
  background: #030F17;
  box-sizing: border-box;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.viaggio__tappa.is-passata::before {
  border-color: var(--giallo);
  background: var(--giallo);
}

.viaggio__tappa[aria-current="step"]::before {
  border-color: var(--giallo);
  background: var(--giallo);
  transform: scale(1.4);
  box-shadow: 0 0 0 4px rgba(253, 224, 0, 0.22);
}

.viaggio__tappa span {
  position: absolute;
  top: 2.1rem;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

.viaggio__tappa[aria-current="step"] span { color: var(--giallo); }

.viaggio__tappa:focus-visible {
  outline: 2px solid var(--giallo);
  outline-offset: 2px;
  border-radius: 50%;
}

/* the pause for the details that move on their own, level with the route
   (its round look is the hero's .hero__pause in v3.css) */
.viaggio__pausa {
  position: absolute;
  z-index: 4;
  right: 1rem;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

.viaggio:not(.viaggio--attivo) .viaggio__pausa { display: none; }

/* ---------- Film grain, and the owner's own videos ---------- */

/* a fine grain and a soft vignette over the drawing, as on film; the grain
   moves eight times a second, as film grain does, by a transform only (no
   repaint); it stops with the pause and, for those who ask for less motion,
   it stands still */
.viaggio--attivo .viaggio__scena::before,
.viaggio--attivo .viaggio__scena::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
}

.viaggio--attivo .viaggio__scena::before {
  inset: -120px;
  animation: vg-grana 1s steps(1, end) infinite;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 .55 0 0 0 -.2'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23g)'/%3E%3C/svg%3E");
  opacity: 0.5;
}

.viaggio--attivo .viaggio__scena::after {
  background: radial-gradient(ellipse 78% 72% at 50% 56%, rgba(2, 8, 12, 0) 52%, rgba(2, 8, 12, 0.55) 100%);
}

@keyframes vg-grana {
  0% { transform: translate(0, 0); }
  12.5% { transform: translate(-63px, 41px); }
  25% { transform: translate(37px, -88px); }
  37.5% { transform: translate(-101px, -19px); }
  50% { transform: translate(79px, 57px); }
  62.5% { transform: translate(-22px, 103px); }
  75% { transform: translate(96px, -44px); }
  87.5% { transform: translate(-47px, -71px); }
  100% { transform: translate(0, 0); }
}

.viaggio:has(.viaggio__pausa.is-paused) .viaggio__scena::before { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .viaggio--attivo .viaggio__scena::before { animation: none; }
}

/* the real video: a small vertical frame beside the drawing, at its step only */
.viaggio__vero { display: none; }

.viaggio--attivo .viaggio__vero:not([hidden]) {
  display: block;
  position: absolute;
  z-index: 3;
  top: calc(var(--header-h) + clamp(1rem, 4.5vh, 3rem));
  right: clamp(1.5rem, 5vw, 4.5rem);
  width: clamp(9rem, 15vw, 14.5rem);
  /* in a low window its caption stays above the route */
  width: clamp(7rem, min(15vw, (100vh - var(--header-h) - 11.5rem) * 0.5625), 14.5rem);
  container-type: inline-size;
  margin: 0;
  opacity: 0;
  transform: translateY(1rem) scale(0.97);
  transition: opacity 0.5s ease, transform 0.7s var(--ease-out);
  pointer-events: none;
}

.viaggio--attivo .viaggio__vero.is-visibile {
  opacity: 1;
  transform: none;
}

.viaggio__vero video {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #0A1E29;
  border-radius: 0.9rem;
  box-shadow: 0 1.2rem 2.6rem rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(156, 195, 232, 0.3);
}

.viaggio__vero figcaption {
  margin-top: 0.55rem;
  color: var(--on-dark-2);
  font-size: var(--step--1);
  line-height: 1.3;
  text-shadow: var(--vg-ombra);
}

/* small frames: even lines; on the smallest, narrower than "termovalorizzatore", and only there, that word
   breaks at its soft hyphen */
.viaggio__vero figcaption { -webkit-hyphens: none; hyphens: none; }

@container (max-width: 9rem) {
  .viaggio__vero figcaption { text-wrap: balance; }
}

@container (max-width: 8rem) {
  .viaggio__vero figcaption { -webkit-hyphens: manual; hyphens: manual; }
}

/* the bales going aboard are filmed lying down: a wider, lower frame */
.viaggio--attivo .viaggio__vero--largo:not([hidden]) { width: clamp(14rem, 24vw, 22rem); }
.viaggio__vero--largo video { aspect-ratio: 16 / 9; }

/* placed by the script under the words (top, left and width inline) */
.viaggio--attivo .viaggio__vero.viaggio__vero--cielo { right: auto; }

/* narrow screens: the script puts the frame in the sky under the words
   (--cielo) or, with too little room, small above the route (--angolo);
   the caption sits on the video, as it does on the frame the script places
   on the left of wide screens */
.viaggio__vero--cielo figcaption,
.viaggio__vero--angolo figcaption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0;
  padding: 1.75rem 0.6rem 0.55rem;
  background: linear-gradient(180deg, rgba(3, 15, 23, 0), rgba(3, 15, 23, 0.88));
  border-radius: 0 0 0.9rem 0.9rem;
  color: #FFFFFF;
  font-size: 0.75rem;
  line-height: 1.25;
}

/* and in a low window, where the drawing comes up to the frame's foot */
@media (min-width: 56em) and (max-height: 48em) {
  .viaggio__vero:not(.viaggio__vero--cielo) figcaption {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    margin: 0;
    padding: 1.75rem 0.7rem 0.6rem;
    background: linear-gradient(180deg, rgba(3, 15, 23, 0), rgba(3, 15, 23, 0.88));
    border-radius: 0 0 0.9rem 0.9rem;
    color: #FFFFFF;
    font-size: 0.8125rem;
    line-height: 1.25;
  }
}

@media (max-width: 55.99em) {
  .viaggio--attivo .viaggio__vero:not([hidden]) { right: auto; }
  .viaggio--attivo .viaggio__vero.viaggio__vero--angolo {
    top: auto;
    right: 1rem;
    bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
    left: auto;
    width: 5.75rem;
  }
  .viaggio--attivo .viaggio__vero--largo.viaggio__vero--angolo { width: 9.5rem; }
  /* on the road the cab is on the right: that step's frame takes the left corner */
  .viaggio--attivo .viaggio__vero--angolo[data-angolo="sinistra"] { right: auto; left: 1rem; }
}

/* no room for it, or for step 5's papers: the words come first (viaggio.js, mettiVeri) */
.viaggio__vero--fuori,
.viaggio__carte.is-via { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .viaggio--attivo .viaggio__vero:not([hidden]) { transform: none; }
}

/* on phones only the current stop says its name */
@media (max-width: 47.99em) {
  .viaggio--attivo { height: 680vh; }
  .viaggio__tappa span {
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  .viaggio__tappa[aria-current="step"] span {
    clip-path: none;
    width: auto;
    height: auto;
    overflow: visible;
  }
  .viaggio__tappa:first-of-type[aria-current="step"] span { left: 0; transform: none; }
  .viaggio__tappa:last-of-type[aria-current="step"] span { right: 0; left: auto; transform: none; }
}

/* ---------- On paper: the six steps as a list, dark on white ---------- */

@media print {
  .viaggio { background: none; color: #000; }
  .viaggio--attivo {
    height: auto;
    --vg-ombra: none;
  }

  .viaggio--attivo .viaggio__stage {
    position: static;
    height: auto;
    overflow: visible;
    background: none;
  }

  .viaggio--attivo .viaggio__testi { position: static; padding-block: 1.5rem; }

  .viaggio__salta,
  .viaggio .viaggio__pausa,
  .viaggio--attivo .viaggio__scena,
  .viaggio--attivo .viaggio__rotta,
  .viaggio--attivo .viaggio__carte,
  .viaggio--attivo .viaggio__vero:not([hidden]),
  .viaggio--attivo .viaggio__testi::before,
  .viaggio--attivo .viaggio__testi::after { display: none; }

  .viaggio--attivo .viaggio__passi { display: grid; }

  .viaggio--attivo .viaggio__passo,
  .viaggio--attivo .viaggio__passo:nth-child(5) p {
    position: static;
    max-width: none;
    opacity: 1;
    transform: none;
    transition: none;
  }

  .viaggio--attivo .viaggio__passo h3 { font-size: var(--step-1); }

  .viaggio--attivo .viaggio__titolo,
  .viaggio__n,
  .viaggio__passo p { color: #000; }
}
