:root {
  --fond: #f5f5f7;
  --surface: #fff;
  --surface-2: #f5f5f7;
  --texte: #1d1d1f;
  --texte-2: #6e6e73;
  --texte-3: #86868b;
  --trait: rgba(0, 0, 0, .09);
  --accent: #0071e3;
  --accent-doux: rgba(0, 113, 227, .1);
  --vert: #1d8a4a;
  --vert-doux: rgba(29, 138, 74, .1);
  --rouge: #d70015;
  --rouge-doux: rgba(215, 0, 21, .08);
  --rayon: 18px;
  --rayon-s: 12px;
  --ombre: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 28px -12px rgba(0, 0, 0, .18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -.01em;
}

/* ------------------------------------------------------------------ entête */
.retour {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--texte-2);
  text-decoration: none;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--trait);
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.retour:hover {
  color: var(--texte);
  background: var(--surface-2);
  border-color: rgba(0, 0, 0, .16);
}

.entete {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 40px;
  height: 60px;
  border-bottom: 1px solid var(--trait);
  background: rgba(245, 245, 247, .78);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.marque { flex: none; height: 21px; width: auto; }

.entete h1 {
  margin: 0;
  font-size: 16px; font-weight: 600; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entete__sous {
  margin: 1px 0 0;
  font-size: 12px; color: var(--texte-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entete__titre { min-width: 0; padding-left: 18px; border-left: 1px solid var(--trait); margin-right: auto; }
.entete__actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* --------------------------------------------------------------- contrôles */
.btn {
  appearance: none;
  border: 0;
  background: rgba(0, 0, 0, .05);
  color: var(--texte);
  padding: 7px 14px;
  border-radius: 980px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -.01em;
  cursor: pointer;
  transition: background .18s, opacity .18s, color .18s;
}
.btn:hover:not(:disabled) { background: rgba(0, 0, 0, .09); }
.btn:disabled { opacity: .32; cursor: default; }
.btn:focus-visible,
.hu:focus-visible,
.option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------- scène */
.scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 262px;
  gap: 18px;
  align-items: start;
  padding: 14px 20px 18px;
  max-width: 1800px;
  margin: 0 auto;
}
@media (max-width: 1000px) {
  .scene { grid-template-columns: 1fr; padding: 20px; }
  .entete { padding: 0 20px; }
  .panneau { position: static; }
}

.panneau {
  background: var(--surface);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 20px;
  position: sticky;
  top: 74px;
}

.consigne {
  margin: 0 0 14px;
  font-size: 18px; font-weight: 600; line-height: 1.3;
  letter-spacing: -.022em;
  color: var(--texte);
  min-height: 44px;
}
.consigne.termine { color: var(--vert); }
.consigne.erreur { color: var(--rouge); animation: secousse .3s; }

@keyframes secousse {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ----------------------------------------------------------------- stepper */
.progres { display: flex; align-items: center; gap: 14px; margin-top: 10px; }

.lecteur {
  appearance: none; border: 0; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .05); color: var(--texte);
  cursor: pointer; padding: 0;
  transition: background .18s, opacity .18s;
}
.lecteur:hover:not(:disabled) { background: rgba(0, 0, 0, .1); }
.lecteur:disabled { opacity: .3; cursor: default; }
.lecteur:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lecteur svg { width: 14px; height: 14px; fill: currentColor; }
.lecteur[data-etat="lecture"] .lecteur__fleche,
.lecteur[data-etat="pause"] .lecteur__barre { display: none; }
.compteur {
  flex: none; font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--texte-3);
}
.stepper { display: flex; flex: none; width: 220px; gap: 3px; list-style: none; margin: 0; padding: 0; }
.stepper li {
  flex: 1; height: 3px; border-radius: 2px;
  background: rgba(0, 0, 0, .1);
  transition: background .3s;
}
.stepper li[data-etat="fait"] { background: rgba(0, 113, 227, .4); }
.stepper li[data-etat="actif"] { background: var(--accent); }

/* ---------------------------------------------------------------------- HU */
.hu-liste { display: flex; flex-direction: column; gap: 6px; }

/* Rail étroit : la référence tient sur sa propre ligne, le badge en dessous. */
.hu {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 11px; row-gap: 3px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--rayon-s);
  background: var(--surface-2);
  color: inherit;
  font: inherit;
  cursor: pointer;
  position: relative;
  transition: background .2s, box-shadow .2s, opacity .2s;
}
.hu[hidden] { display: none; }
.hu:hover:not([disabled]) { background: #ececef; }
.hu[disabled] { cursor: default; }

.hu--cible {
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent), 0 8px 20px -10px rgba(0, 113, 227, .6);
  animation: respire 2.6s ease-in-out infinite;
}
@keyframes respire {
  50% { box-shadow: 0 0 0 2px var(--accent), 0 10px 26px -8px rgba(0, 113, 227, .8); }
}

.hu[data-etat="attendu"]:not(.hu--cible) { opacity: .55; }
.hu[data-etat="recu"] { opacity: .6; }
.hu[data-etat="manquant"] { background: var(--rouge-doux); opacity: 1; }
.hu.flash { animation: flash .55s; }
@keyframes flash {
  0% { background: var(--vert-doux); box-shadow: 0 0 0 2px var(--vert); }
  100% { background: var(--surface-2); box-shadow: none; }
}
.hu.refus { animation: secousse .3s; box-shadow: 0 0 0 2px var(--rouge); }

/* La HU de remplacement entre en scène en cours de scénario. */
.hu[data-etat="attendu"] { animation: revele .45s ease-out; }
@keyframes revele {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: .55; transform: none; }
}

/* Silhouette de colis, remplacée par la photo quand elle existe. */
.hu__visuel {
  position: relative;
  grid-row: 1 / span 2;
  width: 44px; height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(158deg, #e3bd88 0%, #c99a5f 52%, #ab7d43 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .07);
  background-size: cover;
  background-position: center;
}
.hu__visuel::before {
  content: "";
  position: absolute; inset: 0 auto 0 50%;
  width: 10px; transform: translateX(-50%);
  background: rgba(255, 255, 255, .22);
}
/* la photo elle-même est posée en style inline par app.js */
.hu__visuel--photo::before { display: none; }

/* HU jamais arrivée : silhouette vide et barrée */
.hu[data-etat="manquant"] .hu__visuel {
  background: repeating-linear-gradient(135deg, #f4dcde 0 6px, #fbeced 6px 12px);
  box-shadow: inset 0 0 0 1px rgba(215, 0, 21, .18);
}
.hu[data-etat="manquant"] .hu__visuel::before { display: none; }
.hu[data-etat="manquant"] .hu__visuel::after {
  content: "?";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 600; color: rgba(215, 0, 21, .55);
}

.hu__ref {
  min-width: 0;
  font-weight: 600; font-size: 13.5px; letter-spacing: -.015em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.hu__etat {
  justify-self: start;
  font-size: 10px; font-weight: 600;
  letter-spacing: .02em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 980px;
  background: rgba(0, 0, 0, .06); color: var(--texte-2);
}
.hu--cible .hu__etat { background: var(--accent-doux); color: var(--accent); }
.hu[data-etat="recu"] .hu__etat { background: var(--vert-doux); color: var(--vert); }
.hu[data-etat="manquant"] .hu__etat { background: rgba(215, 0, 21, .12); color: var(--rouge); }

/* ------------------------------------------------- zone d'action / décision */
.zone:empty { display: none; }
.zone {
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--trait);
  display: flex; flex-direction: column; gap: 7px;
}
.zone__consequence {
  margin: 3px 0 0; padding: 9px 11px;
  border-radius: 10px;
  background: var(--rouge-doux);
  font-size: 12.5px; color: var(--rouge); line-height: 1.45;
}

.btn--primaire {
  background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 500; padding: 11px 18px;
}
.btn--primaire:hover:not(:disabled) { background: #0077ed; }

.btn--passer {
  align-self: flex-end;
  padding: 6px 12px; font-size: 12px;
  background: transparent; color: var(--texte-2);
}
.btn--passer:hover:not(:disabled) { background: rgba(0, 0, 0, .05); color: var(--texte); }
.btn--passer::after { content: " ›"; font-weight: 600; }

.option {
  display: flex; align-items: flex-start; gap: 10px;
  width: 100%; text-align: left;
  padding: 10px 11px; border: 0; border-radius: var(--rayon-s);
  background: var(--surface-2); color: inherit; font: inherit; cursor: pointer;
  transition: background .2s, box-shadow .2s, opacity .2s;
}
.option:hover { background: #ececef; }
.option--recommandee { background: var(--surface); box-shadow: 0 0 0 2px var(--vert); }
.option--ecartee { opacity: .4; }

.option__rang {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  background: rgba(0, 0, 0, .07); color: var(--texte-2);
  margin-top: 1px;
}
.option--recommandee .option__rang { background: var(--vert); color: #fff; }

.option__corps { min-width: 0; flex: 1; }
.option__titre { display: block; font-size: 13.5px; font-weight: 600; letter-spacing: -.015em; line-height: 1.3; }
.option__detail { display: block; font-size: 12px; color: var(--texte-2); margin-top: 2px; line-height: 1.35; }
.option__badge {
  display: inline-block; margin-top: 6px;
  font-size: 10px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 980px;
  background: var(--vert-doux); color: var(--vert);
}

.astuce { margin: 14px 0 0; font-size: 11.5px; color: var(--texte-3); line-height: 1.9; }
kbd {
  font: inherit; font-size: 10.5px; font-weight: 500;
  background: rgba(0, 0, 0, .05); border-radius: 5px; padding: 2px 6px;
  color: var(--texte-2);
}

/* ------------------------------------------------------------------- écran */
/* La fenêtre est le sujet : on la dimensionne par la hauteur disponible pour
 * qu'elle soit la plus large possible sans jamais déborder de l'écran. */
.ecran { --largeur: min(100%, calc((100vh - 212px) * 16 / 9)); }
.ecran > * { width: var(--largeur); margin-inline: auto; }

.onglets { display: flex; justify-content: center; gap: 2px; margin-bottom: 8px; flex-wrap: wrap; }
.onglet {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; letter-spacing: -.01em;
  padding: 5px 12px; border-radius: 980px;
  color: var(--texte-3);
  transition: color .25s, background .25s;
}
.onglet::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .3;
  transition: background .25s, opacity .25s;
}
.onglet[data-actif="oui"] {
  color: var(--texte); background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .09);
}
.onglet[data-actif="oui"]::before { background: var(--teinte); opacity: 1; }

.fenetre {
  border-radius: var(--rayon);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 24px 60px -24px rgba(0, 0, 0, .3);
}

.fenetre__barre {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--trait);
}
.feu { width: 9px; height: 9px; border-radius: 50%; background: rgba(0, 0, 0, .12); }
.fenetre__url {
  margin: 0 auto;
  font-size: 12px; color: var(--texte-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, "Cascadia Mono", Consolas, monospace;
  background: var(--surface-2);
  padding: 4px 16px; border-radius: 980px;
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.fenetre__corps { position: relative; aspect-ratio: 16 / 9; background: #fff; }
.fenetre__corps video,
.fenetre__corps .gel {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block; object-fit: contain;
}

/* Gel : on affiche l'image précédente pendant une recherche pour éviter le clignotement. */
.gel { opacity: 0; pointer-events: none; transition: opacity .06s; }
body.gele .gel { opacity: 1; }

.voile {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 16px;
  padding: 40px;
  background: rgba(255, 255, 255, .94);
  color: var(--texte-2); font-size: 14px; text-align: center;
  transition: opacity .3s;
}
.voile[hidden] { display: none; }
.voile.erreur { color: var(--rouge); }
.voile p { margin: 0; max-width: 46ch; line-height: 1.5; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid rgba(0, 0, 0, .1); border-top-color: var(--accent);
  animation: tourne .8s linear infinite;
}
.voile.erreur .spinner { display: none; }
@keyframes tourne { to { transform: rotate(360deg); } }

.legende {
  flex: 1; min-width: 0; margin: 0;
  font-size: 13px; color: var(--texte-2); line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.legende.termine { color: var(--vert); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* -------------------------------------------------------------- mode auteur */
.auteur {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  width: 340px;
  background: var(--surface);
  border-radius: var(--rayon-s);
  padding: 16px;
  font-size: 13px;
  box-shadow: 0 20px 50px -18px rgba(0, 0, 0, .35);
}
.auteur[hidden] { display: none; }
.auteur h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--texte-3);
}
.auteur__temps {
  font-family: ui-monospace, SFMono-Regular, Menlo, "Cascadia Mono", Consolas, monospace;
  font-size: 22px; color: var(--accent); margin-bottom: 8px;
}
.auteur__temps small { font-size: 12px; color: var(--texte-3); }
.auteur input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0 10px; }
.auteur__rangee { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.auteur .btn { padding: 5px 10px; font-size: 12px; }
.auteur select, .auteur textarea {
  width: 100%; background: var(--surface-2); color: var(--texte);
  border: 0; border-radius: 8px; padding: 7px; font: inherit; font-size: 12px;
}
.auteur textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, "Cascadia Mono", Consolas, monospace;
  height: 108px; margin-top: 8px; resize: vertical;
}

/* ------------------------------- écrans peu hauts (portables Windows 13/14") */
/* Le rail de droite doit tenir sans défilement jusqu'à l'étape de décision. */
@media (max-height: 900px) {
  .panneau { padding: 16px; }
  .consigne { margin-bottom: 10px; font-size: 16px; min-height: 38px; }
  .hu-liste { gap: 5px; }
  .hu { padding: 5px 9px; }
  .hu__visuel { width: 38px; height: 38px; }
  .zone { margin-top: 10px; padding-top: 10px; gap: 6px; }
  .option { padding: 8px 10px; }
  .option__badge { margin-top: 4px; }
  .astuce { margin-top: 10px; line-height: 1.6; }
}
