:root {
  --ink: #1a1f2c;
  --ink-2: #4a5163;
  --yellow: #fbde20;
  --yellow-d: #ebc307;
  --mint: #dfeeed;
  --paper: #fffdf6;
  --line: rgba(26, 31, 44, 0.12);
  --shadow: 0 10px 30px rgba(26, 31, 44, 0.16), 0 2px 6px rgba(26, 31, 44, 0.1);
  --st-actif: #1f9d63;
  --st-pilote: #d98a00;
  --st-observation: #3b7bd9;
  --st-nouveau: #8a5cf0;
  --st-prevu: #7b8394;
  --who-auto: #3b7bd9;
  --who-ia: #e8a200;
  --who-humain: #1f9d63;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --pixel: "Silkscreen", "DM Sans", monospace;
  --gutter: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, #bfe3f2 0%, #dfeeed 48%, #fff4cf 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#pins { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- En-tête ---------- */
.brand {
  position: fixed; top: var(--gutter); left: var(--gutter); z-index: 5;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 18px 16px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-radius: 16px; box-shadow: var(--shadow);
}
.brand__logo { height: 28px; width: auto; display: block; margin-bottom: 10px; }
.brand__kicker { margin: 0 0 2px; font-family: var(--pixel); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.brand h1 { margin: 0; font-size: 26px; line-height: 1.1; letter-spacing: -0.02em; font-weight: 700; }
.brand h1 span { background: linear-gradient(transparent 62%, var(--yellow) 62%); }
.brand__sub { margin: 8px 0 0; font-size: 13.5px; line-height: 1.4; color: var(--ink-2); }

/* ---------- Scénarios ---------- */
.scenarios {
  position: fixed; top: var(--gutter); left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 4px; padding: 5px;
  background: color-mix(in srgb, var(--paper) 90%, transparent); backdrop-filter: blur(10px);
  border-radius: 999px; box-shadow: var(--shadow);
}
body.panel-open .scenarios { transform: translateX(calc(-50% - 190px)); }
.scenarios button {
  border: 0; background: transparent; padding: 9px 16px; border-radius: 999px;
  font-weight: 600; font-size: 14px; color: var(--ink-2); white-space: nowrap;
  transition: background .2s, color .2s;
}
.scenarios button:hover { background: var(--mint); color: var(--ink); }
.scenarios button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.toolbar { position: fixed; top: var(--gutter); right: var(--gutter); z-index: 4; }
body.panel-open .toolbar { display: none; }
.btn {
  border: 0; border-radius: 999px; padding: 9px 16px; font-weight: 600; font-size: 14px;
  background: color-mix(in srgb, var(--paper) 90%, transparent); backdrop-filter: blur(10px);
  box-shadow: var(--shadow); transition: transform .15s, background .2s;
}
.btn:hover { background: #fff; transform: translateY(-1px); }
.btn--icon { width: 40px; height: 40px; padding: 0; font-size: 22px; line-height: 1; display: grid; place-items: center; }
.btn--play { background: var(--yellow); min-width: 84px; }
.btn--play:hover { background: var(--yellow-d); }

/* ---------- Légende ---------- */
.legend {
  position: fixed; left: var(--gutter); bottom: var(--gutter); z-index: 4;
  padding: 12px 14px; font-size: 12.5px;
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(10px);
  border-radius: 14px; box-shadow: var(--shadow);
}
.legend ul { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.legend ul:last-child { margin: 0; }
.legend__title { margin: 0 0 5px; font-family: var(--pixel); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot--auto { background: var(--who-auto); }
.dot--ia { background: var(--who-ia); }
.dot--humain { background: var(--who-humain); }
.chip { display: inline-block; width: 22px; height: 10px; border-radius: 3px; }
.chip--actif { background: var(--st-actif); }
.chip--pilote { background: var(--st-pilote); }
.chip--observation { background: var(--st-observation); }
.chip--nouveau { background: var(--st-nouveau); }
.chip--prevu { background: repeating-linear-gradient(90deg, var(--st-prevu) 0 4px, transparent 4px 7px); }

/* ---------- Carte d'étape + barre de commandes ---------- */
.hud { position: fixed; left: 50%; bottom: var(--gutter); transform: translateX(-50%); z-index: 5; width: min(900px, calc(100vw - 2 * var(--gutter) - 170px)); display: grid; gap: 8px; }
body.panel-open .hud { transform: translateX(calc(-50% - 190px)); width: min(780px, calc(100vw - 460px - 170px)); }
.caption { background: var(--paper); border-radius: 18px; box-shadow: var(--shadow); padding: 16px 24px 18px; border-left: 9px solid var(--c, var(--yellow)); }
.caption__meta { margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; font-family: var(--pixel); font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); }
.caption__title { margin: 0 0 6px; font-size: 25px; line-height: 1.15; letter-spacing: -0.02em; }
.caption__text { margin: 0; font-size: 18.5px; line-height: 1.45; font-weight: 500; min-height: 4.3em; }
.dock { background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(12px); border-radius: 16px; box-shadow: var(--shadow); padding: 8px 12px 8px; }
.hud__bar { height: 4px; margin: 0 0 8px; border-radius: 99px; background: rgba(26,31,44,.1); overflow: hidden; }
.hud__bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fbde20, #f2a900); border-radius: 99px; }
.hud__row { display: flex; align-items: center; gap: 12px; }
.hud__ctrl { display: flex; gap: 6px; flex: none; }
.steps { list-style: none; margin: 0; padding: 2px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.steps::-webkit-scrollbar { display: none; }
.steps button {
  border: 2px solid transparent; background: var(--mint); border-radius: 10px; padding: 6px 10px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap; color: var(--ink-2); transition: all .2s;
}
.steps button:hover { background: #fff; border-color: var(--line); }
.steps button[aria-current="step"] { background: var(--yellow); color: var(--ink); border-color: var(--ink); }
.steps button.done { color: var(--ink); }

/* ---------- Pins ---------- */
.pin {
  position: absolute; left: 0; top: 0; pointer-events: auto;
  display: flex; align-items: center; gap: 6px; padding: 3px 12px 3px 3px;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--paper);
  font-size: 12.5px; font-weight: 700; white-space: nowrap; box-shadow: 0 3px 0 var(--ink);
  transition: opacity .3s, background .2s, box-shadow .2s; will-change: transform;
}
.pin__n {
  width: 26px; height: 26px; display: grid; place-items: center; flex: none;
  background: var(--accent, var(--yellow)); color: #fff; font-family: var(--pixel); font-size: 11px;
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
}
.pin--support { border-style: dashed; }
.pin.dim { opacity: .5; }
.pin:hover, .pin.hover { background: #fff; opacity: 1; z-index: 3; }
.pin.current { background: var(--yellow); opacity: 1; z-index: 4; box-shadow: 0 3px 0 var(--ink), 0 0 0 5px color-mix(in srgb, var(--yellow) 55%, transparent); }
.pin.selected { background: var(--ink); color: #fff; opacity: 1; z-index: 5; box-shadow: 0 3px 0 rgba(0,0,0,.4); }
.pin.hidden { opacity: 0; pointer-events: none; }

/* ---------- Panneau ---------- */
.panel {
  position: fixed; z-index: 8; top: var(--gutter); right: var(--gutter); bottom: var(--gutter);
  width: min(430px, calc(100vw - 2 * var(--gutter)));
  background: var(--paper); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column;
  animation: slide .35s cubic-bezier(.2,.9,.3,1);
}
.panel[hidden] { display: none; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel__head {
  position: relative; padding: 22px 22px 18px; color: #fff; background: var(--accent, var(--ink));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='48' viewBox='0 0 56 48'%3E%3Cpath d='M14 2h14l7 12-7 12H14L7 14z M42 26h14l7 12-7 12H42l-7-12z' fill='none' stroke='%23ffffff' stroke-opacity='.16' stroke-width='2'/%3E%3C/svg%3E");
}
.panel__close {
  position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.22); color: #fff; font-size: 20px; line-height: 1;
}
.panel__close:hover { background: rgba(255,255,255,.4); }
.panel__num { margin: 0 0 6px; font-family: var(--pixel); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.panel h2 { margin: 0 40px 6px 0; font-size: 26px; line-height: 1.1; letter-spacing: -0.02em; }
.panel__tag { margin: 0; font-size: 14.5px; line-height: 1.4; opacity: .95; }
.panel__body { flex: 1; overflow-y: auto; padding: 8px 22px 6px; }
.panel__items { list-style: none; margin: 0; padding: 0; }
.panel__items li { display: grid; grid-template-columns: 8px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; line-height: 1.45; }
.panel__items li:last-child { border-bottom: 0; }
.who { width: 8px; border-radius: 4px; }
.who--auto { background: var(--who-auto); }
.who--ia { background: var(--who-ia); }
.who--humain { background: var(--who-humain); }
.item__meta { display: flex; gap: 8px; align-items: center; margin-bottom: 3px; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-2); }
.badge { padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 11px; letter-spacing: .02em; text-transform: none; }
.badge--pilote { background: var(--st-pilote); }
.badge--observation { background: var(--st-observation); }
.badge--nouveau { background: var(--st-nouveau); }
.badge--prevu { background: transparent; color: var(--st-prevu); border: 1.5px dashed var(--st-prevu); }
.panel__foot { padding: 14px 22px 18px; background: var(--mint); font-size: 14px; line-height: 1.4; }
.panel__foot b { display: block; font-family: var(--pixel); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 4px; font-weight: 400; }
.panel__nav { display: flex; gap: 8px; margin-top: 12px; }
.panel__nav a, .panel__nav button {
  flex: 1; text-align: center; text-decoration: none; border: 2px solid var(--ink); border-radius: 12px;
  padding: 8px 10px; font-size: 13px; font-weight: 700; background: #fff; color: var(--ink);
}
.panel__nav a:hover, .panel__nav button:hover { background: var(--yellow); }

/* ---------- Vue liste ---------- */
.list {
  position: fixed; inset: 0; z-index: 9; overflow-y: auto; padding: 84px var(--gutter) 40px;
  background: linear-gradient(180deg, #dfeeed, #fff4cf);
}
.list[hidden] { display: none; }
.list__inner { max-width: 1000px; margin: 0 auto; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.list__top { position: fixed; top: var(--gutter); left: var(--gutter); right: var(--gutter); display: flex; justify-content: space-between; align-items: center; z-index: 10; }
.card {
  text-align: left; border: 0; background: var(--paper); border-radius: 16px; padding: 14px 16px 16px;
  box-shadow: var(--shadow); border-top: 6px solid var(--accent);
}
.card:hover { transform: translateY(-2px); }
.card b { display: block; font-size: 17px; margin-bottom: 4px; }
.card span { font-size: 13.5px; color: var(--ink-2); line-height: 1.4; }
.card em { font-family: var(--pixel); font-style: normal; font-size: 10px; color: var(--ink-2); letter-spacing: .06em; display: block; margin-bottom: 6px; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--ink); color: #fff; transition: opacity .7s ease, visibility .7s;
}
.splash img { filter: brightness(0) invert(1); height: 36px; width: auto; }
.splash p { margin: 0; font-family: var(--pixel); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--yellow); animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: .3; } }
.splash.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.noscript { position: fixed; inset: auto 16px 16px; z-index: 30; background: #fff; padding: 12px; border-radius: 12px; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .brand { padding: 10px 12px; max-width: calc(100vw - 32px); }
  .brand__sub, .brand__kicker { display: none; }
  .brand h1 { font-size: 19px; }
  .brand__logo { height: 22px; margin-bottom: 6px; }
  .scenarios { top: auto; bottom: calc(var(--gutter) + 178px); left: var(--gutter); right: var(--gutter); transform: none; overflow-x: auto; border-radius: 16px; scrollbar-width: none; }
  body.panel-open .scenarios { transform: none; }
  .scenarios button { padding: 8px 12px; font-size: 13px; }
  .hud { left: var(--gutter); right: var(--gutter); width: auto; transform: none; }
  body.panel-open .hud { transform: none; width: auto; }
  .caption { padding: 12px 16px 14px; }
  .caption__title { font-size: 19px; }
  .caption__text { font-size: 15px; min-height: 0; }
  .toolbar { top: 12px; }
  .panel { top: auto; height: 62vh; width: auto; left: var(--gutter); right: var(--gutter); bottom: var(--gutter); }
  body.panel-open .hud, body.panel-open .scenarios { display: none; }
  .pin { font-size: 11px; padding-right: 8px; }
  .pin__t { display: none; }
  .pin.current .pin__t, .pin.selected .pin__t { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Progression ---------- */
.hud__phase { font-style: normal; display: inline-block; margin-right: 8px; padding: 2px 8px; border-radius: 6px; background: var(--c); color: #fff; }
.steps__phase { flex: none; align-self: center; padding: 0 2px 0 8px; font-family: var(--pixel); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--c); white-space: nowrap; border-left: 3px solid var(--c); }
.steps__phase:first-child { border-left: 0; padding-left: 0; }
.pin.done .pin__n { font-size: 0; background: #22a06b; }
.pin.done .pin__n::before { content: "✓"; font-family: var(--font); font-weight: 700; font-size: 14px; }

.badge--tag { background: var(--ink); }

.btn--follow { font-size: 13px; padding: 0 12px; height: 40px; white-space: nowrap; background: var(--mint); }
.btn--follow[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- Garde-fous, états d'échec ---------- */
.hud__top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.guards { display: flex; gap: 6px; flex: none; }
.guard { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: rgba(26,31,44,.07); color: var(--ink-2); transition: background .3s, color .3s; }
.guard i { width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.guard b { font-family: var(--pixel); font-size: 11px; }
.guard.on { color: #fff; }
.guard--auto.on { background: var(--who-auto); }
.guard--ia.on { background: var(--who-ia); }
.guard--humain.on { background: var(--who-humain); }
.hud__phase.state-fail { background: #dc2626 !important; }
.hud__phase.state-warn { background: #d98a00 !important; }
.pin.fail { background: #fee2e2; border-color: #b91c1c; }
.pin.fail .pin__n { font-size: 0; background: #dc2626; }
.pin.fail .pin__n::before { content: "✕"; font-family: var(--font); font-weight: 700; font-size: 13px; }
.pin.warn { background: #fef3c7; }

/* ---------- Introduction ---------- */
.intro { position: fixed; inset: 0; z-index: 15; display: grid; place-items: center; padding: 16px; background: rgba(26,31,44,.55); backdrop-filter: blur(6px); animation: fade .4s ease; }
.intro[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.intro__card { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--paper); border-radius: 22px; padding: 26px 28px 22px; box-shadow: var(--shadow); }
.intro__card img { height: 30px; width: auto; display: block; }
.intro__kicker { margin: 18px 0 4px; font-family: var(--pixel); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.intro h2 { margin: 0 0 16px; font-size: 28px; line-height: 1.12; letter-spacing: -0.02em; }
.intro__points { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 12px; }
.intro__points li { padding-left: 16px; border-left: 4px solid var(--yellow); font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.intro__points b { color: var(--ink); }
.intro__points .dot { margin: 0 3px 0 4px; vertical-align: baseline; }
.intro__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.intro__actions .btn { padding: 12px 20px; font-size: 15px; }
.intro__actions .btn:not(.btn--play) { background: var(--mint); box-shadow: none; }
.intro__tip { margin: 16px 0 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }

/* ---------- Mode présentation ---------- */
body.present .legend, body.present .brand__sub, body.present .brand__kicker, body.present .steps, body.present #btn-list, body.present #btn-help { display: none; }
body.present .caption__text { font-size: 27px; }
body.present .caption__title { font-size: 32px; }
body.present .brand h1 { font-size: 22px; }
.toolbar { display: flex; gap: 8px; }
.toolbar .btn[aria-pressed="true"] { background: var(--ink); color: #fff; }
@media (max-width: 900px) { .toolbar { right: 8px; } .toolbar .btn { padding: 8px 10px; font-size: 12.5px; } .intro h2 { font-size: 22px; } .guards { display: none; } }

/* ---------- Légende repliable ---------- */
.legend { padding: 0; overflow: hidden; }
.legend__toggle { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; padding: 10px 14px; font-weight: 700; font-size: 13px; }
.legend__toggle::after { content: "＋"; margin-left: auto; font-weight: 400; }
.legend.open .legend__toggle::after { content: "－"; }
.legend__body { display: none; padding: 0 14px 12px; }
.legend.open .legend__body { display: block; }
.guards { margin-left: auto; }
.hud { grid-template-columns: minmax(0, 1fr); }
.dock, .caption, .hud__row { min-width: 0; }

/* Dégradé aux bords de la frise quand elle défile */
.steps { --fl: 0px; --fr: 0px; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%); }
.steps.fade-l { --fl: 36px; }
.steps.fade-r { --fr: 36px; }
