/* =========================================
   SEZIONE TIMELINE - STILI
   ========================================= */

/* --- Layout Generale --- */
.timeline-section {
  position: relative;
  width: 100%;
  padding: 8rem 0; /* Full width, padding vertical */
  background-color: var(--color-bg-beige);
  overflow: hidden; /* Importante: le nuvole escono dallo schermo */
}

/* --- Decorazioni Sfondo (Atmosphere) --- */
.timeline-atmosphere {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* Pattern Onde */
.bg-wave-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  color: var(--color-brand-brown);
}

/* Bussola */
.bg-compass {
  position: absolute;
  top: 2.5rem;
  right: 1rem;
  width: 6rem;
  height: 6rem;
  color: rgba(62, 52, 43, 0.2); /* Brand brown transparent */
  animation: rotate-compass 120s linear infinite;
}

@media (min-width: 768px) {
  .bg-compass {
    right: 2.5rem;
    width: 8rem;
    height: 8rem;
  }
}

@keyframes rotate-compass {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Nuvole */
.bg-cloud {
  position: absolute;
  width: 100px;
  opacity: 0.4;
  color: #ffffff;
  /* Variabili CSS impostate inline nell'HTML */
  transform: scale(var(--scale));
  animation: cloud-float var(--duration) ease-in-out infinite;
  animation-delay: var(--delay);
}

@keyframes cloud-float {
  0%,
  100% {
    transform: scale(var(--scale)) translateX(0);
  }
  50% {
    transform: scale(var(--scale)) translateX(100px);
  }
}

/* Alberi */
.bg-tree {
  position: absolute;
  width: 40px;
  color: rgba(122, 153, 57, 0.3); /* brand-green transparent */
  transform: scale(var(--scale));
  animation: tree-sway 4s ease-in-out infinite;
  animation-delay: var(--delay);
}

@keyframes tree-sway {
  0%,
  100% {
    transform: scale(var(--scale)) rotate(-2deg);
  }
  50% {
    transform: scale(var(--scale)) rotate(2deg);
  }
}

/* --- 5. DETRITI FORESTA (Funghi/Sassi) --- */
.forest-debris-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  display: none; /* Nascondi su mobile per pulizia */
}
@media (min-width: 768px) {
  .forest-debris-layer {
    display: block;
  }
}

.debris-item {
  position: absolute;
  transform: scale(var(--scale));
  transition: transform 0.3s ease;
}
.debris-item:hover {
  transform: scale(calc(var(--scale) * 1.1));
}

/* --- Header Sezione --- */
.timeline-header-wrapper {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 0 1.5rem;
  margin-bottom: 8rem;
}

.timeline-title-box {
  /* Animazione entrata gestita poi da JS Observer */
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity 0.8s ease-out,
    transform 0.8s ease-out;
}

.timeline-title-box.visible {
  opacity: 1;
  transform: translateY(0);
}

.timeline-pill {
  display: inline-block;
  background-color: #a68a64;
  color: #ffffff;
  padding: 0.25rem 1rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem; /* xs */
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 9999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.timeline-title {
  font-family: var(--font-primary);
  font-size: 2.5rem; /* 7xl */
  line-height: 1.5;
  letter-spacing: -0.15em;
  color: var(--color-brand-brown);
  margin: 0;
}

@media (min-width: 768px) {
  .timeline-title {
    font-size: 4rem; /* 9xl */
  }
}

.timeline-desc {
  font-family: var(--font-secondary);
  color: rgba(62, 52, 43, 0.8);
  margin-top: 1rem;
  font-size: 0.875rem;
  max-width: 32rem;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 768px) {
  .timeline-desc {
    font-size: 1rem;
  }
}

/* Contenitore Timeline */
.timeline-container {
  position: relative;
  max-width: 80rem; /* 6xl */
  margin: 0 auto;
  padding: 0 1rem;
  /* Altezza provvisoria per vedere il contenuto, poi sarà automatica */
  min-height: 500px;
}

/* --- SVG Sentiero --- */
.timeline-svg-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0; /* Dietro agli eventi */
  pointer-events: none;
  overflow: visible;
}

.timeline-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Gestione visibilità Mobile/Desktop */
.mobile-only {
  display: block;
}
.desktop-only {
  display: none;
}

@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
  .desktop-only {
    display: block;
  }
}

/* Stile Linee */
.path-base {
  fill: none;
  stroke: var(--timeline-path); /* #8C7558 */
  stroke-linecap: round;
  opacity: 0.4;
}

.path-glow {
  fill: none;
  stroke: var(--timeline-path-glow); /* #FFFFFF */
  stroke-linecap: round;
  /* Preparazione per animazione Scroll Draw */
  stroke-dasharray: 10000; /* Valore altissimo iniziale */
  stroke-dashoffset: 10000; /* Nasconde tutto inizialmente */
  will-change: stroke-dashoffset;

  /* Togliamo il filtro blur di default per performance */
  filter: none;
}

/* Applichiamo il filtro SOLO su desktop o se il device è potente */
@media (min-width: 768px) {
  .path-glow {
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.8)); /* Drop shadow è spesso più leggero di GaussianBlur su SVG */
    /* Oppure tieni il tuo url(#glow-desktop) se su PC va bene */
  }
}

/* Spessori specifici */
#path-mobile-base {
  stroke-width: 12px;
}
#path-mobile-glow {
  stroke-width: 2px;
  stroke-dasharray: 12 24;
} /* Tratteggio mobile */

#path-desktop-base {
  stroke-width: 8px;
}
#path-desktop-glow {
  stroke-width: 1.5px;
  stroke-dasharray: 16 32;
} /* Tratteggio desktop */

/* =========================================
   7. LAYOUT EVENTI (FIX SOVRAPPOSIZIONE)
   ========================================= */

.timeline-events-wrapper {
  position: relative;
  z-index: 10;
  padding-bottom: 4rem;
}

/* QUESTO È IL BLOCCO CHE MANCAVA O ERA SBAGLIATO */
.timeline-event-row {
  position: relative;
  width: 100%;
  /* Altezza fissa di 400px per corrispondere allo step matematico del JS */
  height: 400px;
  display: flex;
  pointer-events: none; /* Lascia cliccare attraverso gli spazi vuoti */
}

/* ANCHOR: IL CEPPO CENTRALE */
.timeline-anchor {
  position: absolute;
  top: 2rem;
  left: var(--mobile-x); /* Variabile inline HTML */
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: auto;
}
@media (min-width: 768px) {
  .timeline-anchor {
    left: var(--desktop-x);
  }
}

/* Stile Ceppo */
.stump-node {
  position: relative;
  width: 2.5rem;
  height: 2.5rem;
  z-index: 30;
  display: flex;
  justify-content: center;
  align-items: center;
}
.stump-wood {
  width: 2rem;
  height: 2rem;
  background-color: #e6ded1;
  border: 3px solid #5c4033;
  border-radius: 50%;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}
.stump-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(92, 64, 51, 0.3);
}
.ring-1 {
  transform: scale(0.7);
}
.ring-2 {
  transform: scale(0.4);
}
.stump-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 4px;
  background-color: #5c4033;
  border-radius: 50%;
}
.stump-grass {
  position: absolute;
  bottom: -0.5rem;
  left: -0.5rem;
  width: 3.5rem;
  height: 2rem;
  color: #7a9939;
  z-index: -1;
}

/* TRAVE DI LEGNO (Connector Beam) */
.connector-beam {
  position: absolute;
  top: 50%;
  height: 1rem;
  background-color: #5c4033;
  transform-origin: left center;
  z-index: 10;
  border-top: 1px solid #3e2f26;
  border-bottom: 1px solid #3e2f26;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);

  /* Mobile Default */
  left: 0;
  width: 25vw;
}

@media (min-width: 768px) {
  /* Desktop Logic */
  .timeline-event-row[data-alignment="left"] .connector-beam {
    left: auto;
    right: 0; /* Parte dal ceppo verso sinistra */
    width: 180px;
    transform-origin: right center;
    border-radius: 4px 0 0 4px;
  }
  .timeline-event-row[data-alignment="right"] .connector-beam {
    left: 0; /* Parte dal ceppo verso destra */
    width: 180px;
    border-radius: 0 4px 4px 0;
  }
}

.timeline-wood-texture-overlay {
  position: absolute;
  inset: 0;
  opacity: 0.2;
  background-image: url("../img/wood-pattern.png");
  pointer-events: none;
}
.connector-vine-decoration {
  position: absolute;
  top: -5px;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* --- 8. CARTELLO (Card Wrapper) --- */
.timeline-card-wrapper {
  position: relative;
  z-index: 15;
  width: 85%;
  max-width: 400px;
  margin-left: calc(15% + 1.5rem); /* Spazio da mobile */

  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: auto;

  will-change: opacity, transform;
  /* Evita sfarfallii su iOS */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.timeline-card-wrapper.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 768px) {
  .timeline-card-wrapper {
    margin: 0;
    position: absolute;
    top: 0; /* Si posiziona relativo alla riga */
  }

  /* Posizionamento Desktop preciso */
  .timeline-event-row[data-alignment="left"] .timeline-card-wrapper {
    right: 50%;
    /* margin-right: 160px; */
  }

  .timeline-event-row:nth-child(1) .timeline-card-wrapper {
    margin-right: -20px;
  }

  .timeline-event-row:nth-child(3) .timeline-card-wrapper {
    margin-right: -90px;
  }

  .timeline-event-row:nth-child(5) .timeline-card-wrapper {
    margin-right: -53px;
  }

  .timeline-event-row:nth-child(7) .timeline-card-wrapper {
    margin-right: 48px;
  }

  .timeline-event-row[data-alignment="right"] .timeline-card-wrapper {
    left: 50%;
  }

  .timeline-event-row:nth-child(2) .timeline-card-wrapper {
    margin-left: -97px;
  }

  .timeline-event-row:nth-child(4) .timeline-card-wrapper {
    margin-left: -33px;
  }

  .timeline-event-row:nth-child(6) .timeline-card-wrapper {
    margin-left: -53px;
  }
}
@media (min-width: 1024px) {
  .timeline-card-wrapper {
    max-width: 500px;
  }
}

/* Stile Grafico Card */
.timeline-card {
  position: relative;
  background-color: #f2f0e6;
  border: 2px solid #5c4033;
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(62, 52, 43, 0.2);
  overflow: visible; /* IMPORTANTE: per far uscire i rami */
}
.timeline-card:hover {
  transform: translateY(-5px);
  transition: transform 0.3s ease;
}

.card-bg-texture {
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image: url("../img/wood-pattern.png");
  pointer-events: none;
  z-index: 0;
}

/* Rami Decorativi */
.sign-overgrowth {
  position: absolute;
  width: 80px;
  height: 80px;
  z-index: 30;
  pointer-events: none;
  filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.15));
}
.sign-overgrowth.pos-top-left {
  top: -10px;
  left: -10px;
  transform: rotate(0deg);
}
.sign-overgrowth.pos-top-right {
  top: -10px;
  right: -10px;
  transform: rotate(90deg);
}
.sign-overgrowth.pos-bottom-right {
  bottom: -10px;
  right: -10px;
  transform: rotate(180deg);
}
.sign-overgrowth.pos-bottom-left {
  bottom: -10px;
  left: -10px;
  transform: rotate(270deg);
}

/* Header Card */
.timeline-card-header {
  background-color: #4a5d23;
  padding: 0.5rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #5c4033;
  position: relative;
  border-top-left-radius: 0.6rem;
  border-top-right-radius: 0.6rem;
}
.header-wood-overlay {
  position: absolute;
  inset: 0;
  opacity: 0.1;
  background-image: url("../img/wood-pattern.png");
  pointer-events: none;
}
.card-time {
  font-family: "Stencil", serif;
  font-size: 0.75rem;
  color: #e6ded1;
  letter-spacing: 0.05em;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.card-checkpoint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: rgba(230, 222, 209, 0.8);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  position: relative;
  z-index: 1;
}
.dot {
  width: 6px;
  height: 6px;
  background-color: rgba(230, 222, 209, 0.5);
  border-radius: 50%;
}

/* Body Card */
.card-body {
  padding: 2rem;
  position: relative;
  z-index: 1;
}
.card-bg-icon {
  position: absolute;
  bottom: -10px;
  right: -10px;
  font-size: 6rem;
  color: #5c4033;
  opacity: 0.03;
  transform: rotate(-15deg);
  pointer-events: none;
  z-index: 0;
}
.event-headline {
  font-family: var(--font-primary);
  font-size: 1rem;
  letter-spacing: -0.15em;
  line-height: 0.8;
  color: #3e342b;
  margin-bottom: 0.5rem;
  transition: color 0.3s;
}
.timeline-card:hover .event-headline {
  color: #7a9939;
}

@media (min-width: 375px) {
  .card-time {
    font-size: 1.2rem;
  }
  .event-headline {
    font-size: 1.2rem;
  }
}
@media (min-width: 425px) {
  .card-time {
    font-size: 1.5rem;
  }
  .event-headline {
    font-size: 1.5rem;
  }
}
@media (min-width: 768px) {
  .event-headline {
    font-size: 2rem;
  }
}

.timeline-card-subtitle {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: #7a9939;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 1rem;
}
.timeline-card-desc {
  font-family: var(--font-secondary);
  font-size: 0.95rem;
  color: rgba(92, 64, 51, 0.9);
  line-height: 1.5;
}
.card-footer-line {
  height: 4px;
  width: 100%;
  background-color: rgba(62, 47, 38, 0.1);
}

/* Chiodi */
.nail {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #2a211c;
  border-radius: 50%;
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.5);
  z-index: 20;
}
.nail::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%) rotate(45deg);
}
.nail.top-left {
  top: 0.5rem;
  left: 0.5rem;
}
.nail.top-right {
  top: 0.5rem;
  right: 0.5rem;
}
.nail.bottom-left {
  bottom: 0.5rem;
  left: 0.5rem;
}
.nail.bottom-right {
  bottom: 0.5rem;
  right: 0.5rem;
}

/* --- 9. FINALE (TRAMONTO E PAPERA) --- */
.timeline-end-marker {
  position: relative;
  z-index: 10;
  margin-top: 5rem;
  /* Extra padding per evitare che la papera venga tagliata */
  /* padding-bottom: 12rem; */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: visible; /* Fondamentale per i coriandoli */
}

.sunset-graphic {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -45%);
  width: 300px;
  height: 300px;
  pointer-events: none;
}
@media (min-width: 768px) {
  .sunset-graphic {
    width: 600px;
    height: 600px;
  }
}
.sunset-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Animazioni Sole */
.sun-rays-anim {
  animation: rotate-sun 120s linear infinite;
}
@keyframes rotate-sun {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
.sun-pulse-anim {
  animation: pulse-sun 5s ease-in-out infinite;
  transform-origin: 250px 300px;
}
@keyframes pulse-sun {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Onde */
.wave-anim-1 {
  animation: wave-morph 4s ease-in-out infinite;
}
.wave-anim-2 {
  animation: wave-morph 5s ease-in-out infinite 0.5s;
}
@keyframes wave-morph {
  0%,
  100% {
    d: path("M150,315 Q250,335 350,315");
  }
  50% {
    d: path("M150,315 Q250,295 350,315");
  }
}

/* MASCOTTE (Duck) */
.mascot-wrapper {
  width: 200px;
  height: 200px;
  position: relative;
  z-index: 50;
  margin-top: -65px;
  margin-left: 20px;
}

@media (min-width: 768px) {
  .mascot-wrapper {
    width: 280px;
    height: 280px;
    /* margin-top: -180px; */
  }
}

.duck-svg {
  width: 80%;
  height: 90%;
  overflow: visible;
  display: block;
}

@media (min-width: 768px) {
  .duck-svg {
    margin-top: 15px;
    margin-left: 30px;
  }
}

.duck-float-anim {
  animation: duck-bounce 3s ease-in-out infinite;
}
@keyframes duck-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-30px);
  }
}
.confetti {
  transform-origin: center;
  animation: confetti-fall 3s linear infinite;
}
.c1 {
  animation-delay: 0s;
}
.c2 {
  animation-delay: 1.5s;
}
.c3 {
  animation-delay: 2s;
}
.c4 {
  animation-delay: 0.5s;
}
@keyframes confetti-fall {
  0% {
    transform: translateY(-500px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(1000px) rotate(360deg);
    opacity: 0;
  }
}
