/* 171 — Path Draw
   Scène line-art épinglée (sticky) dans un scroller interne : chaque tracé
   se dessine à son tour au fil du défilement — pathLength="1" +
   stroke-dashoffset 1→0, piloté par animation-timeline: scroll(nearest)
   avec des animation-range échelonnés. Les remplissages fondent en fin de
   parcours. Reculer rembobine le dessin.
   Fallback (Firefox) : anim.js pose .path-draw--live et publie la
   progression dans --path-draw-p ; les mêmes fenêtres sont recalculées en
   calc()/clamp(). Sans JS ni support : scène entièrement dessinée. */

.path-draw {
  position: relative;
  width: min(340px, 100%);
}

/* Scroller interne — c'est lui qui porte la timeline */
.path-draw__viewport {
  height: 230px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 14px;
  border: 1px solid color-mix(in oklab, var(--ml-fg, #e8eaf2) 8%, transparent);
  background: var(--ml-surface, #151a24);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in oklab, var(--ml-fg, #e8eaf2) 16%, transparent) transparent;
}

.path-draw__viewport:focus-visible {
  outline: 2px solid var(--ml-accent-2, #2dd4bf);
  outline-offset: 2px;
}

.path-draw__viewport::-webkit-scrollbar { width: 6px; }
.path-draw__viewport::-webkit-scrollbar-track { background: transparent; }
.path-draw__viewport::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: color-mix(in oklab, var(--ml-fg, #e8eaf2) 16%, transparent);
}

/* Scène épinglée : reste visible pendant tout le défilement */
.path-draw__stage {
  position: sticky;
  top: 0;
  display: grid;
  place-items: center;
  height: 230px;
  padding: 14px 18px;
}

.path-draw__svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Piste invisible : donne la course de défilement */
.path-draw__track {
  height: 340px;
}

/* ——— Tracés ——— */

.path-draw__stroke {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.path-draw__stroke--sun    { stroke: var(--ml-accent, #7c8cff); }
.path-draw__stroke--mont   { stroke: color-mix(in oklab, var(--ml-fg, #e8eaf2) 55%, transparent); }
.path-draw__stroke--mont2  { stroke: var(--ml-fg, #e8eaf2); }
.path-draw__stroke--vague1,
.path-draw__stroke--vague2 { stroke: var(--ml-accent-2, #2dd4bf); }
.path-draw__stroke--oiseau { stroke: var(--ml-muted, #8b91a3); stroke-width: 1.6; }

/* ——— Remplissages (alpha baké dans la couleur, on anime opacity) ——— */

.path-draw__fill--sun   { fill: color-mix(in oklab, var(--ml-accent, #7c8cff) 22%, transparent); }
.path-draw__fill--mont  { fill: color-mix(in oklab, var(--ml-fg, #e8eaf2) 6%, transparent); }
.path-draw__fill--mont2 { fill: color-mix(in oklab, var(--ml-accent, #7c8cff) 10%, transparent); }

/* Indice « faites défiler », épinglé en bas du scrollport */
.path-draw__hint {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 22px 0 10px;
  pointer-events: none;
  font: 500 10.5px/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ml-muted, #8b91a3);
  background: linear-gradient(to top, var(--ml-surface, #151a24) 35%, transparent);
}

.path-draw__hint::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-top: -4px;
  border-right: 1.5px solid var(--ml-accent, #7c8cff);
  border-bottom: 1.5px solid var(--ml-accent, #7c8cff);
  transform: rotate(45deg);
  animation: path-draw-nudge 1.5s ease-in-out infinite;
}

@keyframes path-draw-nudge {
  0%, 100% { transform: translateY(-2px) rotate(45deg); opacity: 0.55; }
  50%      { transform: translateY(2px) rotate(45deg); opacity: 1; }
}

/* ——— Scroll-driven (Chrome/Edge 115+, Safari 26+) ———
   Fenêtres de dessin échelonnées : chaque tracé prend le relais du
   précédent avec un léger recouvrement. */

@supports (animation-timeline: scroll()) {
  .path-draw__stroke {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation-name: path-draw-line;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest);
  }

  .path-draw__stroke--sun    { animation-range: 0% 18%; }
  .path-draw__stroke--mont   { animation-range: 10% 36%; }
  .path-draw__stroke--mont2  { animation-range: 28% 54%; }
  .path-draw__stroke--vague1 { animation-range: 46% 66%; }
  .path-draw__stroke--vague2 { animation-range: 56% 74%; }
  .path-draw__stroke--oiseau { animation-range: 66% 80%; }

  .path-draw__fill {
    opacity: 0;
    animation-name: path-draw-fill;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest);
    animation-range: 78% 96%;
  }

  /* L'indice s'efface sur les premiers 15 % de défilement */
  .path-draw__hint {
    animation-name: path-draw-hint-out;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest);
    animation-range: 0% 15%;
  }
}

@keyframes path-draw-line {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}

@keyframes path-draw-fill {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes path-draw-hint-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* ——— Fallback JS (.path-draw--live posée par anim.js) ———
   anim.js publie la progression 0→1 dans --path-draw-p ; on rejoue les
   mêmes fenêtres en calc()/clamp(). Sans la classe : tout reste dessiné. */

.path-draw--live .path-draw__stroke {
  stroke-dasharray: 1;
}

.path-draw--live .path-draw__stroke--sun {
  stroke-dashoffset: calc(1 - clamp(0, (var(--path-draw-p, 1) - 0) / 0.18, 1));
}
.path-draw--live .path-draw__stroke--mont {
  stroke-dashoffset: calc(1 - clamp(0, (var(--path-draw-p, 1) - 0.10) / 0.26, 1));
}
.path-draw--live .path-draw__stroke--mont2 {
  stroke-dashoffset: calc(1 - clamp(0, (var(--path-draw-p, 1) - 0.28) / 0.26, 1));
}
.path-draw--live .path-draw__stroke--vague1 {
  stroke-dashoffset: calc(1 - clamp(0, (var(--path-draw-p, 1) - 0.46) / 0.20, 1));
}
.path-draw--live .path-draw__stroke--vague2 {
  stroke-dashoffset: calc(1 - clamp(0, (var(--path-draw-p, 1) - 0.56) / 0.18, 1));
}
.path-draw--live .path-draw__stroke--oiseau {
  stroke-dashoffset: calc(1 - clamp(0, (var(--path-draw-p, 1) - 0.66) / 0.14, 1));
}

.path-draw--live .path-draw__fill {
  opacity: clamp(0, (var(--path-draw-p, 1) - 0.78) / 0.18, 1);
}

.path-draw__hint.is-hidden {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

/* ——— Reduced motion : scène entièrement dessinée, zéro animation ——— */

@media (prefers-reduced-motion: reduce) {
  .path-draw .path-draw__stroke {
    animation: none;
    stroke-dashoffset: 0;
  }
  .path-draw .path-draw__fill {
    animation: none;
    opacity: 1;
  }
  .path-draw__hint::after {
    animation: none;
  }
}
