/* Guidage en « stories » : une étape par écran, plein écran sur téléphone.
   Voir docs/DESIGN.md et docs/PAGES.md. */

/* Pendant une story, l'en-tête et le pied du site s'effacent : rien ne distrait du trajet. */
html:has([data-story]) .entete,
html:has([data-story]) .pied,
html:has([data-story]) .evitement { display: none; }
html:has([data-story]) body { background: var(--encre); }

.story {
  --story-texte: var(--blanc);
  --story-doux: rgb(255 255 255 / .72);
  --story-voile: rgb(255 255 255 / .16);
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--encre);
  color: var(--story-texte);
}
.story-clair {
  --story-texte: var(--encre);
  --story-doux: rgb(14 18 51 / .72);
  --story-voile: rgb(14 18 51 / .14);
}
.story-couleur { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; }
.story.story-fonce[class*="cat-"] { background: var(--cat, var(--encre)); }
.story :where(a:not(.bouton)) { color: inherit; }

/* Barres de progression : une par étape */
.story-tete { position: relative; z-index: 3; display: grid; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px 6px; }
.story-barres { display: flex; gap: 5px; margin: 0; padding: 0; list-style: none; }
.story-barres li { flex: 1; min-width: 0; }
.story-barre { position: relative; display: block; height: 22px; }
.story-barre::before, .story-barre::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 9px;
  height: 4px;
  border-radius: 2px;
  background: var(--story-voile);
}
.story-barre::after { background: var(--story-texte); transform: scaleX(0); transform-origin: left; }
.story-barre-fait::after { transform: scaleX(1); }
.story-barre-courant::after { animation: og-barre .6s var(--ease-trace) .1s both; }
.story-barre:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; border-radius: 4px; }
.story-infos { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 700; }
.story-infos p { margin: 0; }
.story-terminus { margin-left: auto !important; color: var(--story-doux); }
.story-terminus strong { color: var(--story-texte); font-family: var(--titre); font-stretch: 84%; font-size: 16px; }
.story-fermer {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-left: -8px;
  border-radius: 50%;
  transition: background .2s, transform .3s var(--ease-pop);
}
.story-fermer:hover { background: var(--story-voile); }
.story-fermer:active { transform: scale(.9); }

/* Zones de toucher : à gauche pour revenir, à droite pour avancer */
.story-zone { position: absolute; top: 96px; bottom: 96px; z-index: 1; width: 22%; -webkit-tap-highlight-color: transparent; }
.story-zone-arriere { left: 0; }
.story-zone-avant { right: 0; }

/* Corps d'une étape */
.story-corps {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 12px 22px 18px;
  pointer-events: none;
}
.story-corps > * { pointer-events: auto; }
.story-sur {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--story-doux);
}
.story-titre {
  margin: 0;
  font-size: clamp(34px, 9.5vw, 54px);
  font-stretch: 92%;
  line-height: .98;
  letter-spacing: -.02em;
  text-wrap: balance;
}
.story h1:focus { outline: none; }

/* Étape en transport : la ligne en très grand, sur sa couleur */
.story-ligne { display: flex; align-items: center; gap: 14px; margin: 0; line-height: 1; }
.story-jeton {
  display: grid;
  place-items: center;
  flex: none;
  min-width: 56px;
  height: 56px;
  padding: 0 10px;
  border: 4px solid currentColor;
  border-radius: 14px;
  font-family: var(--titre);
  font-size: 20px;
  font-weight: 800;
}
.story-jeton-rond { border-radius: 50%; padding: 0; }
.story-numero {
  font-family: var(--titre);
  font-size: clamp(64px, 24vw, 132px);
  font-weight: 800;
  font-stretch: 78%;
  letter-spacing: -.03em;
  overflow-wrap: anywhere;
}
.story-direction { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0; font-size: 18px; color: var(--story-doux); }
.story-direction strong { color: var(--story-texte); font-size: 21px; }
.story-fleche { width: 26px; height: 4px; border-radius: 2px; background: currentColor; }
.story-compte {
  align-self: flex-start;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--story-voile);
  font-family: var(--titre);
  font-size: 18px;
  font-weight: 800;
  font-stretch: 88%;
}
.story-compte:empty { display: none; }
.story-compte.est-proche { background: var(--signal); color: var(--encre); }
.story-alerte { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--blanc); color: var(--alerte); font-weight: 700; }

.story-parcours { display: grid; margin: 6px 0 0; padding: 0; list-style: none; }
.story-arret { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.story-arret p { margin: 0; }
.story-point { width: 22px; height: 22px; border: 5px solid var(--story-texte); border-radius: 50%; }
.story-point-plein { background: var(--story-texte); }
.story-verbe { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--story-doux); }
.story-nom { font-size: 23px; font-weight: 700; line-height: 1.12; text-wrap: balance; }
.story-voie { display: inline-block; padding: 1px 8px; border: 2px solid currentColor; border-radius: 8px; font-size: 13px; vertical-align: middle; }
.story-heure { font-family: var(--titre); font-size: 26px; font-weight: 800; font-stretch: 84%; font-variant-numeric: tabular-nums; text-align: right; }
.story-retard { display: block; font-family: var(--texte); font-size: 13px; font-stretch: 100%; }
.story-entre { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 14px; min-height: 54px; }
.story-rail { justify-self: center; width: 5px; margin: -2px 0; background: var(--story-texte); opacity: .55; transform-origin: top; animation: og-rail .7s var(--ease-trace) .25s both; }
.story-entre .depliable, .story-direct { align-self: center; margin: 8px 0; }
.story-direct { font-size: 15px; color: var(--story-doux); }
.story .depliable summary { color: var(--story-texte); }
.story .arrets time { font-size: 14px; font-weight: 700; color: var(--story-doux); }
.story-arrets .arrets { max-height: 30vh; overflow: auto; overscroll-behavior: contain; }

/* Étape à pied : la carte remplit l'écran, une feuille glisse en bas */
.story-marche { grid-template-rows: auto minmax(0, 1fr) auto auto; background: var(--papier); }
.story-marche .story-tete {
  --story-texte: var(--blanc);
  --story-doux: rgb(255 255 255 / .8);
  --story-voile: rgb(255 255 255 / .28);
  color: var(--blanc);
  background: linear-gradient(to bottom, rgb(14 18 51 / .82), rgb(14 18 51 / .5) 70%, transparent);
  padding-bottom: 22px;
}
.story-carte { position: absolute; inset: 0; z-index: 0; }
.story-carte .guide-carte { width: 100%; height: 100%; max-height: none; border-radius: 0; }
.story-marche .story-zone { bottom: 46%; }
.story-feuille {
  grid-row: 3;
  position: relative;
  z-index: 2;
  display: grid;
  gap: 10px;
  margin: 0 8px;
  padding: 18px 18px 14px;
  border-radius: 24px;
  background: var(--blanc);
  color: var(--encre);
  box-shadow: 0 -8px 40px rgb(14 18 51 / .18);
  animation: og-feuille .5s var(--ease-out) both;
}
.story-feuille .story-sur { color: var(--gris); }
.story-feuille .story-titre { font-size: clamp(26px, 7vw, 38px); }
.story-feuille .sortie { margin: 0; }
.story-feuille .guide-etat { font-size: clamp(22px, 6vw, 30px); }
.story-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.story-actions .bouton { flex: 1 1 auto; justify-content: center; }
.story .story-feuille .depliable summary { color: var(--gris); }
.story-note { margin: 4px 0; font-size: 13px; color: var(--gris); }
.story-marche .story-pied { grid-row: 4; color: var(--encre); }
.story-marche .story-nav { background: var(--blanc); box-shadow: 0 2px 12px rgb(14 18 51 / .12); }

.guide-carte { display: block; background: var(--papier); touch-action: pan-y; }
.guide-nom {
  font-family: var(--texte);
  font-weight: 700;
  fill: var(--gris);
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: var(--blanc);
  stroke-width: .28em;
  stroke-linejoin: round;
}
.guide-trace { stroke-dasharray: 1; animation: og-trace 1.1s var(--ease-trace) .2s both; }
.guide-arrivee { transform-box: fill-box; transform-origin: center; animation: og-rebond .5s var(--ease-pop) 1.1s both; }
.guide-moi { display: none; }
.guide-moi.est-visible { display: inline; }
.guide-moi-halo { fill: var(--outremer); fill-opacity: .16; }
.guide-moi-fleche { fill: var(--outremer); stroke: var(--blanc); stroke-width: 3.5; stroke-linejoin: round; }
.guide-vue[hidden] { display: none; }
.guide-vue[aria-pressed="true"] { background: var(--encre); border-color: var(--encre); color: var(--blanc); }
.guide-etat {
  margin: 0;
  font-family: var(--titre);
  font-weight: 800;
  font-stretch: 84%;
  line-height: 1.08;
  color: var(--outremer);
}
.guide-etat:empty { display: none; }

/* Arrivée : le trait se dessine, le bilan s'affiche */
.story.story-arrivee { background: var(--outremer); }
.story-fin { justify-content: center; gap: 18px; }
.story-trait { width: min(240px, 60%); }
.story-trait-ligne { fill: none; stroke: var(--signal); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 1; animation: og-trace .9s var(--ease-trace) .2s both; }
.story-trait-depart { fill: var(--outremer); stroke: var(--blanc); stroke-width: 5; }
.story-trait-arrivee { fill: var(--blanc); transform-box: fill-box; transform-origin: center; animation: og-rebond .5s var(--ease-pop) 1s both; }
.story-bilan { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.story-bilan div { display: grid; gap: 2px; padding: 14px; border-radius: 18px; background: var(--story-voile); animation: og-apparait .6s var(--ease-out) both; }
.story-bilan div:nth-child(2) { animation-delay: .08s; }
.story-bilan div:nth-child(3) { animation-delay: .16s; }
.story-bilan div:nth-child(4) { animation-delay: .24s; }
.story-bilan dd { margin: 0; font-family: var(--titre); font-size: 24px; font-weight: 800; font-stretch: 84%; }
.story-bilan dt { font-size: 13px; color: var(--story-doux); }
.story .story-fin .bouton-principal { background: var(--signal); color: var(--encre); }
.story .story-fin .bouton-secondaire { background: transparent; border-color: var(--story-doux); color: var(--blanc); }

/* Pied : précédent / suivant, toujours accessibles au pouce */
.story-pied {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px max(14px, env(safe-area-inset-bottom));
}
.story-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--story-voile);
  font-weight: 700;
  text-decoration: none;
  transition: transform .3s var(--ease-pop), background .2s;
}
.story-nav:active { transform: scale(.95); }
.story .story-nav-avant { margin-left: auto; background: var(--story-texte); color: var(--encre); }
.story-clair .story-nav-avant { color: var(--blanc); }
.story .story-nav-arriere { color: var(--story-texte); }
.story.story-marche .story-nav-avant { background: var(--encre); color: var(--blanc); }
.story.story-marche .story-nav-arriere { color: var(--encre); }

/* Entrées : chaque élément monte à son tour */
.story-corps > *, .story-feuille > * { animation: og-apparait .5s var(--ease-out) both; }
.story-corps > :nth-child(2), .story-feuille > :nth-child(2) { animation-delay: .05s; }
.story-corps > :nth-child(3), .story-feuille > :nth-child(3) { animation-delay: .1s; }
.story-corps > :nth-child(4), .story-feuille > :nth-child(4) { animation-delay: .15s; }
.story-corps > :nth-child(n+5), .story-feuille > :nth-child(n+5) { animation-delay: .2s; }

@keyframes og-barre { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes og-rail { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes og-feuille { from { transform: translateY(40px); opacity: 0; } }
.story-barre-courant::after { transform: scaleX(1); }

/* D'une étape à l'autre, l'écran glisse dans le sens de la marche */
@keyframes og-story-sort-avant { to { transform: translateX(-28%); opacity: 0; } }
@keyframes og-story-entre-avant { from { transform: translateX(100%); } }
@keyframes og-story-sort-arriere { to { transform: translateX(28%); opacity: 0; } }
@keyframes og-story-entre-arriere { from { transform: translateX(-100%); } }
html[data-sens="avant"]::view-transition-old(page) { animation: og-story-sort-avant .38s var(--ease-swap) both; }
html[data-sens="avant"]::view-transition-new(page) { animation: og-story-entre-avant .38s var(--ease-swap) both; }
html[data-sens="arriere"]::view-transition-old(page) { animation: og-story-sort-arriere .38s var(--ease-swap) both; }
html[data-sens="arriere"]::view-transition-new(page) { animation: og-story-entre-arriere .38s var(--ease-swap) both; }

/* Grand écran : la story devient une colonne centrée, au format d'un téléphone */
@media (min-width: 760px) {
  html:has([data-story]) main { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
  .story { width: 430px; min-height: min(860px, calc(100dvh - 48px)); border-radius: 36px; box-shadow: 0 30px 90px rgb(0 0 0 / .45); }
  .story-zone { width: 18%; }
}
@media (max-height: 640px) {
  .story-numero { font-size: clamp(48px, 16vw, 84px); }
  .story-nom { font-size: 19px; }
}
