/* 092 — Scroll Progress
   Barre de progression de lecture sticky en haut d'un scroller interne :
   remplissage scaleX (gradient accent → accent-2), glow au bout, pourcentage.
   Piloté par animation-timeline: scroll(nearest block) — le pourcentage est
   un compteur CSS animé via @property. Fallback (Firefox) : anim.js pose
   --scroll-progress-p (0→1) sur la racine via un listener scroll passif.
   Sans JS ni support : barre pleine (état final), jamais rien de cassé. */

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

.scroll-progress__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;
}

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

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

/* Bandeau sticky : piste + barre + pourcentage */
.scroll-progress__head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 10px;
  background: linear-gradient(to bottom,
    var(--ml-surface, #151a24) 60%,
    color-mix(in oklab, var(--ml-surface, #151a24) 55%, transparent));
}

.scroll-progress__track {
  position: relative;
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--ml-fg, #e8eaf2) 10%, transparent);
}

.scroll-progress__bar {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ml-accent, #7c8cff), var(--ml-accent-2, #2dd4bf));
  transform-origin: left center;
  /* Fallback JS : anim.js pose --scroll-progress-p ; sans rien : barre pleine */
  transform: scaleX(var(--scroll-progress-p, 1));
}

/* Pointe lumineuse : élément pleine largeur translaté, le point vit à son
   bord droit — pas de distorsion, contrairement à un glow dans la barre scalée */
.scroll-progress__glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transform: translateX(calc(var(--scroll-progress-p, 1) * 100% - 100%));
}

.scroll-progress__glow::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -4px;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--ml-accent-2, #2dd4bf);
  box-shadow:
    0 0 10px 2px color-mix(in oklab, var(--ml-accent-2, #2dd4bf) 65%, transparent),
    0 0 22px 6px color-mix(in oklab, var(--ml-accent-2, #2dd4bf) 28%, transparent);
}

.scroll-progress__pct {
  min-width: 4ch;
  text-align: right;
  font: 600 11px/1 system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--ml-muted, #8b91a3);
}

/* Article de démo */
.scroll-progress__article {
  padding: 4px 16px 8px;
}

.scroll-progress__title {
  margin: 0 0 10px;
  font: 600 16px/1.3 system-ui, -apple-system, sans-serif;
  letter-spacing: -0.01em;
  color: var(--ml-fg, #e8eaf2);
}

.scroll-progress__sub {
  margin: 14px 0 6px;
  font: 600 10.5px/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ml-accent, #7c8cff);
}

.scroll-progress__text {
  margin: 0 0 10px;
  font: 400 12.5px/1.6 system-ui, -apple-system, sans-serif;
  color: var(--ml-muted, #8b91a3);
}

/* Indice « faites défiler », épinglé en bas du scrollport */
.scroll-progress__hint {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 0 -16px;
  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);
}

.scroll-progress__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: scroll-progress-nudge 1.5s ease-in-out infinite;
}

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

/* Compteur entier interpolable pour le pourcentage CSS pur */
@property --scroll-progress-n {
  syntax: "<integer>";
  inherits: true;
  initial-value: 0;
}

/* ——— Scroll-driven (Chrome/Edge 115+, Safari 26+) ——— */

@supports (animation-timeline: scroll()) {
  .scroll-progress__bar {
    animation-name: scroll-progress-fill;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest block);
  }

  .scroll-progress__glow {
    animation-name: scroll-progress-tip;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest block);
  }

  .scroll-progress__pct {
    animation-name: scroll-progress-count;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest block);
  }

  .scroll-progress__pct::after {
    counter-reset: scroll-progress-c var(--scroll-progress-n);
    content: counter(scroll-progress-c) "%";
  }

  .scroll-progress__hint {
    animation-name: scroll-progress-hint-out;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: scroll(nearest);
    animation-range: 0% 15%;
  }
}

@keyframes scroll-progress-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

@keyframes scroll-progress-tip {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

@keyframes scroll-progress-count {
  from { --scroll-progress-n: 0; }
  to   { --scroll-progress-n: 100; }
}

@keyframes scroll-progress-hint-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* État posé par anim.js en fallback */
.scroll-progress__hint.is-hidden {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

/* ——— Reduced motion : la barre reste (feedback de position, pas un décor),
   seul le chevron en boucle est coupé — le fondu de l'indice (opacité
   mappée sur le scroll) est conservé ——— */

@media (prefers-reduced-motion: reduce) {
  .scroll-progress__hint::after {
    animation: none;
  }
}
