/*
 * Régie 5 — feuille de style, pensée d'abord pour le téléphone.
 *
 * Trois plans, comme dans une régie vidéo :
 *   le mur     (gris neutre sombre, comme une salle d'étalonnage),
 *   l'écran    (noir : ce qui sort du serveur GPU),
 *   le pupitre (gris clair : ce que l'on saisit).
 * La couleur ne sert qu'aux voyants d'état et aux images elles-mêmes.
 * Un seul signal traverse toute l'application : la barre témoin sous l'en-tête,
 * verte quand le GPU répond, rouge quand il travaille, éteinte quand il est arrêté.
 */

@font-face {
  font-family: "Saira";
  src: url("../fonts/saira.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 50% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --wall: #2f2f31;
  --wall-up: #3c3c3f;
  --wall-line: #57575b;
  --screen: #000;
  --bezel: #161617;
  --desk: #ebebea;
  --desk-down: #dbdbd9;
  --well: #fff;
  --line: #b3b3b0;
  --ink: #121212;
  --ink-soft: #4b4b4b;
  --text: #f5f5f4;
  --text-soft: #c2c2c0;

  /* Voyants */
  --ready: #2fd468;
  --air: #ff453a;
  --fault: #ffb224;
  --unlit: #8c8c8c;
  /* Mêmes sens, lisibles sur le pupitre clair */
  --ready-ink: #0b6b30;
  --air-ink: #b3261e;
  --fault-ink: #7a4d00;

  --r-screen: 4px;
  --r-key: 10px;
  --r-desk: 20px;

  --font: "Saira", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --wide: 118%;
  --narrow: 84%;
  --col: 980px;
  --gut: 14px;
  --top-h: 54px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 16px); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--wall);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, p, dl, dd, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; }
a { color: inherit; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 8px; top: -80px; z-index: 60;
  padding: 10px 14px; background: var(--desk); color: var(--ink); border-radius: var(--r-key);
}
.skip:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }
.desk :focus-visible, .sheet :focus-visible, .drawer :focus-visible { outline-color: var(--ink); }

.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ En-tête de l'application */

.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  min-height: calc(var(--top-h) + var(--safe-t)); padding: var(--safe-t) var(--gut) 0;
  background: var(--wall);
}
.brand {
  flex: 1 1 auto; min-width: 0;
  font-stretch: 125%; font-weight: 650; font-size: 19px; letter-spacing: .01em;
  text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Barre témoin : l'état du serveur GPU, visible sur toutes les pages. */
.strip {
  position: sticky; top: calc(var(--top-h) + var(--safe-t)); z-index: 29;
  height: 3px; background: var(--wall-line);
}
.strip[data-state="connected"] { background: var(--ready); box-shadow: 0 0 14px rgba(47, 212, 104, .55); }
.strip[data-state="busy"] { background: var(--air); box-shadow: 0 0 14px rgba(255, 69, 58, .6); animation: breathe 2.4s ease-in-out infinite; }
.strip[data-state="error"] { background: repeating-linear-gradient(90deg, var(--fault) 0 14px, transparent 14px 22px); }
.strip[data-state="offline"], .strip[data-state="unconfigured"] { background: repeating-linear-gradient(90deg, var(--unlit) 0 4px, transparent 4px 10px); }

/* Onglets : barre fixe en bas sur téléphone, dans l'en-tête sur grand écran. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 0 4px var(--safe-b);
  background: var(--bezel); border-top: 1px solid #000;
}
.tab {
  position: relative;
  display: grid; justify-items: center; align-content: center; gap: 2px;
  min-height: var(--tab-h); padding: 6px 2px;
  color: #a9a9a7; text-decoration: none;
  font-size: 12.5px; font-weight: 550; font-stretch: var(--narrow); line-height: 1.1; letter-spacing: .01em;
}
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--text); }
.tab[aria-current="page"]::before {
  content: ""; position: absolute; top: -1px; left: 26%; right: 26%; height: 3px; border-radius: 0 0 3px 3px; background: var(--text);
}
.tab:active { background: #232324; }
.tab-badge {
  position: absolute; top: 7px; left: calc(50% + 7px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--air); color: #fff; font-size: 11.5px; font-weight: 700; font-stretch: 100%; line-height: 18px; text-align: center;
}

.logout { margin: 0; }
.quiet {
  background: none; border: 0; padding: 8px 4px; color: var(--text-soft);
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.quiet:hover { color: var(--text); }
.desk .quiet, .sheet .quiet, .drawer .quiet { color: var(--ink-soft); }
.desk .quiet:hover, .sheet .quiet:hover, .drawer .quiet:hover { color: var(--ink); }

/* ------------------------------------------------------------------ Voyant d'état (tally) */

.tally {
  flex: none; display: inline-flex; align-items: center; gap: 9px;
  max-width: 62vw; min-height: 38px; padding: 6px 13px 6px 11px;
  background: var(--bezel); color: var(--text);
  border: 1px solid #000; border-radius: 999px;
  font-weight: 600; font-stretch: var(--wide); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.tally:hover { background: #242425; }
.tally-label { overflow: hidden; text-overflow: ellipsis; }
.tally-session { color: var(--text-soft); font-weight: 500; font-stretch: var(--narrow); font-variant-numeric: tabular-nums; }
.tally-session:empty { display: none; }

.lamp {
  position: relative; flex: none; width: 12px; height: 12px; border-radius: 50%;
  background: #555;
}
[data-state="connected"] > .lamp { background: var(--ready); box-shadow: 0 0 10px 1px rgba(47, 212, 104, .7); }
[data-state="busy"] > .lamp { background: var(--air); box-shadow: 0 0 10px 1px rgba(255, 69, 58, .75); }
[data-state="busy"] > .lamp::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid var(--air); opacity: 0; animation: ring 1.6s ease-out infinite;
}
[data-state="offline"] > .lamp,
[data-state="unconfigured"] > .lamp { background: transparent; box-shadow: inset 0 0 0 2px var(--unlit); }
[data-state="error"] > .lamp {
  width: 14px; height: 13px; border-radius: 0; background: var(--fault);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
@keyframes ring {
  0% { transform: scale(.6); opacity: .9; }
  100% { transform: scale(1.5); opacity: 0; }
}

.lien {
  position: relative; z-index: 2;
  max-width: var(--col); margin: 10px var(--gut) 0; padding: 14px 16px;
  background: var(--bezel); border: 1px solid #000; border-radius: var(--r-key);
}
.lien-message { font-size: 17px; font-weight: 500; }
.lien-hint { margin-top: 4px; color: var(--text-soft); }
.lien-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.lien-when { color: var(--text-soft); font-size: 14px; }

.lien-pod { margin-top: 14px; padding-top: 12px; border-top: 1px solid #2b2b2c; }
.lien-pod-text { color: var(--text-soft); font-size: 14.5px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 3px 16px; margin-top: 10px; font-size: 14px; }
.facts:empty { display: none; }
.facts dt { color: var(--text-soft); }
.facts dd { overflow-wrap: anywhere; }
.sheet .facts dt, .desk .facts dt { color: var(--ink-soft); }

/* Rappel : le serveur tourne sans rien générer. Informatif, sans aucun bouton d'arrêt. */
.banner {
  display: flex; gap: 10px 14px; align-items: center; flex-wrap: wrap;
  max-width: var(--col); margin: 10px var(--gut) 0; padding: 11px 14px;
  background: #3b3320; border: 1px solid #6b5720; border-left: 5px solid var(--fault); border-radius: var(--r-key);
  font-size: 15px;
}
.banner p { flex: 1 1 220px; }
.banner strong { font-weight: 650; }

/* ------------------------------------------------------------------ Mise en page */

.main { max-width: calc(var(--col) + 2 * var(--gut)); margin: 0 auto; padding: 14px var(--gut) calc(var(--tab-h) + var(--safe-b) + 34px); }
.main > * + * { margin-top: 22px; }
.page-login .main, .page-install .main, body:not(.has-tabs) .main { padding-bottom: 48px; }

.title { font-size: 25px; line-height: 1.2; font-weight: 650; font-stretch: var(--wide); }
.subtitle { font-size: 19px; line-height: 1.25; font-weight: 650; font-stretch: var(--wide); }
.lead { color: var(--text-soft); max-width: 62ch; }
.bar { display: flex; align-items: end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ Écran (moniteur) */

.monitor { position: relative; isolation: isolate; }
.monitor::before {
  /* Éclairage d'ambiance derrière le moniteur : il prend la couleur de l'état. */
  content: ""; position: absolute; z-index: -1; inset: 10px; border-radius: 8px;
  box-shadow: 0 0 70px 12px var(--halo, transparent);
  opacity: 0; transition: opacity .7s ease;
}
.monitor[data-state="connected"] { --halo: rgba(47, 212, 104, .45); }
.monitor[data-state="busy"] { --halo: rgba(255, 69, 58, .6); }
.monitor[data-state="error"] { --halo: rgba(255, 178, 36, .5); }
.monitor[data-state="connected"]::before,
.monitor[data-state="error"]::before { opacity: .8; }
.monitor[data-state="busy"]::before { opacity: 1; animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

.screen {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden;
  background: var(--screen); border: 5px solid var(--bezel);
  border-radius: var(--r-screen); box-shadow: 0 0 0 1px #000;
}
.screen video, .screen img.film { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
/* Sur téléphone, le moniteur du studio va d'un bord à l'autre. */
.stage { margin-left: calc(-1 * var(--gut)); margin-right: calc(-1 * var(--gut)); margin-top: -14px; }
.stage .screen { border-left: 0; border-right: 0; border-radius: 0; }
.stage .monitor::before { inset: 0 0 10px; }
.stage .note { padding: 0 var(--gut); }
/* Hors lecture, l'écran du téléphone est plus haut : le pourcentage, l'étape et la touche d'annulation y tiennent. */
.stage .screen:not(.playing) { aspect-ratio: 4 / 3; }
.stage .slate { padding: 34px 6% 38px; }

.slate {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px;
  padding: 7% 7%; text-align: center;
}
.slate-big {
  font-stretch: 125%; font-weight: 300; line-height: 1; letter-spacing: -.02em;
  font-size: clamp(42px, 13vw, 104px); font-variant-numeric: tabular-nums;
}
.slate-big:empty { display: none; }
.slate-title {
  font-stretch: 125%; font-weight: 550; line-height: 1.2;
  font-size: clamp(18px, 4.6vw, 31px); max-width: 24ch; text-wrap: balance;
}
.slate-sub { color: var(--text-soft); max-width: 46ch; font-size: clamp(14px, 3.4vw, 17px); text-wrap: pretty; }
.slate-sub:empty { display: none; }
.slate-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.slate-actions:empty { display: none; }

/* Incrustations façon « burn-in » de moniteur */
.burn {
  position: absolute; z-index: 3; max-width: 62%;
  padding: 1px 8px; background: rgba(0, 0, 0, .78); color: #fff;
  font-size: 12px; line-height: 1.6; font-weight: 500; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.burn:empty { display: none; }
.burn-tl { top: 7px; left: 7px; display: inline-flex; align-items: center; gap: 7px; }
.burn-tr { top: 7px; right: 7px; }
.burn-bl { bottom: 11px; left: 7px; }
.burn-br { bottom: 11px; right: 7px; }
.burn .lamp { width: 9px; height: 9px; }
.burn[data-state="error"] .lamp { width: 11px; height: 10px; }
.screen.playing .burn-bl, .screen.playing .burn-br { display: none; }

.meter { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; height: 5px; background: #2b2b2b; }
.meter > span { display: block; height: 100%; width: calc(var(--p, 0) * 100%); background: var(--air); transition: width .5s linear; }
.meter[data-mode="wait"] > span {
  width: 28%; background: var(--text-soft); animation: sweep 1.6s ease-in-out infinite alternate;
}
.meter[data-mode="save"] > span { background: var(--ready); }
@keyframes sweep {
  from { transform: translateX(0); }
  to { transform: translateX(260%); }
}

.note { position: relative; z-index: 1; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-top: 12px; color: var(--text-soft); font-size: 14.5px; }
.note strong { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------ Pupitre (saisie) */

.desk {
  position: relative; z-index: 1; /* au-dessus du halo du moniteur */
  background: var(--desk); color: var(--ink); color-scheme: light;
  border-radius: var(--r-desk); padding: 16px;
}
.sheet {
  background: var(--desk); color: var(--ink); color-scheme: light;
  border-radius: var(--r-desk); padding: 18px 16px;
}
#e-res { min-height: 84px; }
.sheet > * + * { margin-top: 16px; }
.sheet .subtitle { padding-bottom: 8px; border-bottom: 2px solid var(--ink); }
.sheet .lead, .desk .lead { color: var(--ink-soft); }
.sheet a, .desk a { text-underline-offset: 3px; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .field > .label, legend { font-weight: 600; font-size: 15px; }
.hint { color: var(--ink-soft); font-size: 14px; max-width: 70ch; }
.hint[data-tone="bad"] { color: var(--air-ink); font-weight: 550; }
.wall-hint { color: var(--text-soft); font-size: 14px; }

input[type="text"], input[type="url"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  background: var(--well); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-key);
  font-size: 16px; /* en dessous, iOS zoome sur le champ */
}
input[type="file"] { max-width: 100%; font-size: 15px; }
input[type="file"]::file-selector-button {
  min-height: 42px; margin-right: 10px; padding: 8px 14px;
  background: var(--well); color: var(--ink); border: 1px solid var(--ink); border-radius: var(--r-key);
  font: inherit; font-weight: 600; cursor: pointer;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; min-height: 180px; white-space: pre; overflow: auto; }
select { appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat;
}
input:disabled, select:disabled, textarea:disabled { background: var(--desk-down); color: var(--ink-soft); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--air-ink); box-shadow: inset 0 0 0 1px var(--air-ink); }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--ink); flex: none; }
input[type="range"] { width: 100%; accent-color: var(--ink); min-height: 48px; }

.check { display: flex; gap: 10px; align-items: flex-start; }
.check > span { line-height: 1.35; }

.cols { display: grid; gap: 14px 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: start; }
.cols-3 { grid-template-columns: 1fr; }
.stack > * + * { margin-top: 14px; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; }

/* Touches */
.key {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  background: var(--ink); color: #fff; border: 1px solid var(--ink); border-radius: var(--r-key);
  font-weight: 600; font-stretch: var(--wide); text-decoration: none; cursor: pointer; text-align: center;
}
.key:hover { background: #2c2c2c; }
.key:active { transform: translateY(1px); }
.key:disabled, .key[aria-disabled="true"] { background: #a6a6a6; border-color: #a6a6a6; color: #f0f0f0; cursor: not-allowed; transform: none; }
.key-ghost { background: transparent; color: var(--ink); }
.key-ghost:hover { background: var(--desk-down); }
.key-small { min-height: 40px; padding: 6px 14px; font-size: 15px; }
.key-danger { background: var(--air-ink); border-color: var(--air-ink); }
.key-danger:hover { background: #8f1d17; }
/* Sur le mur et sur l'écran : touche claire */
.on-wall.key, .slate .key, .lien .key, .banner .key { background: var(--desk); color: var(--ink); border-color: var(--desk); }
.on-wall.key:hover, .slate .key:hover, .lien .key:hover, .banner .key:hover { background: #fff; }
.on-wall.key-ghost, .slate .key-ghost, .banner .key-ghost { background: transparent; color: var(--text); border-color: var(--wall-line); }
.on-wall.key-ghost:hover, .slate .key-ghost:hover, .banner .key-ghost:hover { background: var(--wall-up); }
.on-wall.key[aria-pressed="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }

.actions { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.actions-end { justify-content: flex-end; }
.why { flex: 1 1 240px; color: var(--ink-soft); font-size: 15px; }
.why[data-tone="bad"] { color: var(--air-ink); font-weight: 500; }

.msg { padding: 10px 14px; border-radius: var(--r-key); border-left: 5px solid var(--ink); background: var(--desk-down); }
.msg[data-tone="ok"] { border-color: var(--ready-ink); }
.msg[data-tone="bad"] { border-color: var(--air-ink); }
.msg[data-tone="warn"] { border-color: var(--fault-ink); }
.msg ul { margin-top: 6px; padding-left: 18px; list-style: disc; font-size: 14px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ Studio : ce que l'on veut créer */

.modes {
  display: flex; gap: 6px; margin: 0 calc(-1 * var(--gut)); padding: 2px var(--gut);
  overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
}
.modes::-webkit-scrollbar { display: none; }
.mode {
  flex: none; scroll-snap-align: start;
  min-height: 44px; padding: 8px 16px;
  background: transparent; color: var(--text-soft);
  border: 1px solid var(--wall-line); border-radius: 999px;
  font-weight: 600; font-stretch: var(--wide); font-size: 15px; cursor: pointer; white-space: nowrap;
}
.mode:hover { color: var(--text); }
.mode[aria-pressed="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }

/* Pupitre de composition */
.composer { display: grid; gap: 14px; }
.composer textarea#prompt { min-height: 118px; font-size: 17px; }
.composer .counter { justify-self: end; color: var(--ink-soft); font-size: 13px; margin-top: -8px; }
.composer .counter:empty { display: none; }
.range-line { display: flex; align-items: center; gap: 12px; }
.range-line output { flex: none; min-width: 5.5ch; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.prompt-tools { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; margin-top: -4px; }
.linkish {
  background: none; border: 0; padding: 8px 0; min-height: 40px;
  color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.linkish:hover { text-decoration-thickness: 2px; }

/* Ingrédients : un geste ajoute une indication de mise en scène au prompt. */
.chips { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 6px 13px;
  background: var(--well); color: var(--ink); border: 1px solid var(--line); border-radius: 999px;
  font-size: 14.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

details.more > summary { cursor: pointer; font-weight: 600; padding: 10px 0; width: fit-content; }
details.more[open] > summary { margin-bottom: 8px; }

/* La touche « Générer » reste sous le pouce pendant que l'on règle le reste. */
.dock {
  position: sticky; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 5;
  margin: 2px -16px -16px; padding: 12px 16px 14px;
  background: var(--desk); border-top: 1px solid var(--line); border-radius: 0 0 var(--r-desk) var(--r-desk);
}
.dock .why { flex: 1 1 100%; }
.dock .why:empty { display: none; }
.dock .key { flex: 1 1 100%; min-height: 56px; font-size: 18px; }

/* File d'attente du site */
.queue { display: grid; gap: 8px; }
.q-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center;
  padding: 10px 12px; background: var(--bezel); border: 1px solid #000; border-radius: var(--r-key);
}
.q-pos { font-stretch: 125%; font-weight: 300; font-size: 26px; line-height: 1; min-width: 1.4ch; text-align: center; font-variant-numeric: tabular-nums; }
.q-item[data-status="failed"] { border-color: #6b5720; }
.q-item[data-status="failed"] .q-pos { color: var(--fault); font-weight: 600; }
.q-text { min-width: 0; }
.q-prompt { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-meta { color: var(--text-soft); font-size: 13px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ Mur d'écrans (galerie, dernières générations) */

.wallgrid { display: grid; gap: 12px 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* Dernières générations : un rail que l'on fait glisser au doigt. */
.rail {
  display: flex; gap: 10px; margin: 0 calc(-1 * var(--gut)); padding: 2px var(--gut) 6px;
  overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail > .tile { flex: 0 0 62%; max-width: 280px; scroll-snap-align: start; }

.tile { position: relative; display: grid; grid-template-rows: auto 1fr; min-width: 0; background: var(--bezel); border-radius: 8px; box-shadow: 0 0 0 1px #000; overflow: hidden; }
.tile-screen { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; display: block; }
.tile-screen img, .tile-screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-screen .burn { top: 6px; left: 6px; font-size: 12px; }
.tile-slate { position: absolute; inset: 0; display: grid; place-content: center; padding: 26px 10px 8px; text-align: center; color: var(--text-soft); font-size: 13px; line-height: 1.3; overflow: hidden; }
.tile-label { padding: 8px 10px 10px; display: grid; gap: 2px; align-content: start; }
.tile-prompt {
  font-size: 14px; line-height: 1.3; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.tile-meta { color: var(--text-soft); font-size: 12.5px; font-stretch: var(--narrow); font-variant-numeric: tabular-nums; }
.tile a.tile-screen:hover + .tile-label .tile-prompt, .tile a.tile-screen:focus-visible + .tile-label .tile-prompt { text-decoration: underline; }
.tile-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.tile-kind {
  position: absolute; z-index: 2; left: 6px; bottom: 6px; padding: 0 7px;
  background: rgba(0, 0, 0, .78); color: #fff; font-size: 11.5px; font-weight: 600; font-stretch: var(--narrow); line-height: 1.7; border-radius: 3px;
}

/* Favori : une étoile pleine ou creuse, jamais la couleur seule. */
.fav {
  position: absolute; z-index: 3; top: 4px; right: 4px;
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0;
  background: rgba(0, 0, 0, .55); color: #fff; border: 0; border-radius: 50%; cursor: pointer;
}
.fav svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.fav[aria-pressed="true"] svg { fill: currentColor; }
.fav:hover { background: rgba(0, 0, 0, .8); }

.empty { padding: 30px 18px; border: 1px dashed var(--wall-line); border-radius: var(--r-key); color: var(--text-soft); text-align: center; }
.empty strong { display: block; color: var(--text); font-size: 18px; font-weight: 600; margin-bottom: 4px; }

.search { display: flex; gap: 8px; flex: 1 1 100%; min-width: 0; }
.search input { flex: 1 1 auto; min-width: 0; }
.search input { background: var(--bezel); color: var(--text); border-color: #000; }
.search input::placeholder { color: #a5a5a5; }

.filters { display: flex; gap: 6px; margin: 0 calc(-1 * var(--gut)); padding: 2px var(--gut); overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters a {
  flex: none; display: inline-flex; align-items: center; gap: 7px; min-height: 42px; padding: 7px 15px;
  color: var(--text-soft); border: 1px solid var(--wall-line); border-radius: 999px;
  font-weight: 600; font-stretch: var(--wide); font-size: 15px; text-decoration: none; white-space: nowrap;
}
.filters a[aria-current="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }
.filters .count { font-weight: 500; font-stretch: var(--narrow); font-variant-numeric: tabular-nums; opacity: .75; }

/* ------------------------------------------------------------------ Fiche d'un média */

.prompt-full { font-size: 17px; line-height: 1.45; max-width: 68ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.specs { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-variant-numeric: tabular-nums; font-size: 15px; }
.specs dt { color: var(--text-soft); }
.specs dd { overflow-wrap: anywhere; }
.actions-main { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.actions-main .key { padding: 10px 8px; }
.actions-main .key-wide { grid-column: 1 / -1; }

/* ------------------------------------------------------------------ Page « Plus » */

.statgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { padding: 12px 14px; background: var(--bezel); border: 1px solid #000; border-radius: var(--r-key); }
.stat-n { font-stretch: 125%; font-weight: 300; font-size: 34px; line-height: 1.05; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--text-soft); font-size: 13.5px; font-stretch: var(--narrow); }
.stat-wide { grid-column: 1 / -1; }

.menu { display: grid; border-radius: var(--r-desk); overflow: hidden; background: var(--bezel); border: 1px solid #000; }
.menu > li + li { border-top: 1px solid #2b2b2c; }
.menu a, .menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 56px; padding: 12px 16px;
  background: none; border: 0; color: var(--text); text-align: left; text-decoration: none; font-weight: 550; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: #232324; }
.menu .menu-sub { display: block; color: var(--text-soft); font-size: 13.5px; font-weight: 400; }
.menu .menu-go { flex: none; color: var(--text-soft); font-size: 14px; font-stretch: var(--narrow); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.switch input { width: 26px; height: 26px; }

/* ------------------------------------------------------------------ Tiroir (prompts enregistrés) */

.drawer {
  width: 100%; max-width: 640px; max-height: 86dvh; margin: auto auto 0; padding: 0;
  background: var(--desk); color: var(--ink); color-scheme: light;
  border: 0; border-radius: var(--r-desk) var(--r-desk) 0 0;
}
.drawer::backdrop { background: rgba(0, 0, 0, .62); }
.drawer-in { display: grid; gap: 14px; padding: 18px 16px calc(18px + var(--safe-b)); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.plist { display: grid; gap: 8px; }
.plist li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; padding: 10px 12px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r-key); }
.plist .p-use { grid-column: 1; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; min-width: 0; }
.plist .p-name { display: block; font-weight: 600; }
.plist .p-body { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; color: var(--ink-soft); font-size: 14px; }

/* ------------------------------------------------------------------ Administration */

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--wall-line); margin: 0 calc(-1 * var(--gut)); padding: 0 var(--gut); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 11px 14px; text-decoration: none; color: var(--text-soft); font-weight: 600; font-stretch: var(--wide);
  border-radius: var(--r-key) var(--r-key) 0 0; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="true"] { background: var(--desk); color: var(--ink); }
.tabs + .sheet { margin-top: 0; border-top-left-radius: 0; }

.steps { display: grid; gap: 8px; }
.steps li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: baseline; }
.steps .mark { font-weight: 700; text-align: center; }
.steps li[data-ok="true"] .mark { color: var(--ready-ink); }
.steps li[data-ok="false"] .mark { color: var(--air-ink); }
.steps li[data-ok="null"] .mark { color: var(--fault-ink); }
.steps b { font-weight: 600; }

.rows { display: grid; gap: 10px; }
.rowcard { display: grid; gap: 8px 16px; grid-template-columns: 1fr; align-items: center; padding: 14px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r-key); }
.rowcard h3 { font-size: 17px; font-weight: 600; }
.rowcard .state { font-size: 14px; color: var(--ink-soft); }
.rowcard .state[data-tone="ok"] { color: var(--ready-ink); }
.rowcard .state[data-tone="bad"] { color: var(--air-ink); }
.rowcard .state[data-tone="warn"] { color: var(--fault-ink); }
.rowcard .tile-actions { margin: 0; justify-content: flex-start; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--desk-down); font-size: 13px; font-weight: 600; vertical-align: 2px; }
.pill[data-on="1"] { background: var(--ink); color: #fff; }
.pill[data-tone="live"] { background: var(--air-ink); color: #fff; }

.maprow { display: grid; grid-template-columns: 1fr; gap: 6px 14px; padding: 10px 0; border-top: 1px solid var(--line); align-items: start; }
.maprow:first-child { border-top: 0; }
.maprow .what { font-weight: 600; }
.maprow .choices { display: grid; gap: 6px; }
.maprow .none { color: var(--ink-soft); font-size: 14px; }
.maprow label { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; overflow-wrap: anywhere; }
.maprow .val { color: var(--ink-soft); }

table.log { width: 100%; border-collapse: collapse; font-size: 14px; }
table.log th, table.log td { text-align: left; padding: 6px 10px 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
table.log th { border-top: 0; color: var(--ink-soft); font-weight: 600; }
table.log td.when { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
table.log tr[data-level="error"] td.what { color: var(--air-ink); }
table.log tr[data-level="warn"] td.what { color: var(--fault-ink); }
.scroll-x { overflow-x: auto; }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; overflow-wrap: anywhere; }
pre.cmd { margin: 0; padding: 10px 12px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r-key); overflow-x: auto; font-size: 13px; }

/* ------------------------------------------------------------------ Assistant de mise en route */

.wizard { display: grid; gap: 16px; counter-reset: none; }
.wizard > li > .subtitle { display: flex; align-items: center; gap: 12px; }
.wnum {
  flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px;
  border-radius: 50%; background: var(--ink); color: #fff; font-size: 17px; font-stretch: 100%;
}
.wmark { margin-left: auto; color: var(--ready-ink); font-size: 22px; visibility: hidden; }
.wizard > li[data-done="1"] .wmark { visibility: visible; }
.wizard > li[data-done="1"] .wnum { background: var(--ready-ink); }

/* ------------------------------------------------------------------ Connexion / installation */

.gate { max-width: 460px; margin: 6vh auto 0; }
.gate .brand { display: block; font-size: 30px; margin-bottom: 18px; }
.gate-wide { max-width: 640px; }
.bars { display: flex; height: 6px; margin-bottom: 22px; border-radius: 2px; overflow: hidden; }
.bars i { flex: 1; }
.bars i:nth-child(1) { background: #c4c4c4; }
.bars i:nth-child(2) { background: #c4c400; }
.bars i:nth-child(3) { background: #00c4c4; }
.bars i:nth-child(4) { background: #00c400; }
.bars i:nth-child(5) { background: #c400c4; }
.bars i:nth-child(6) { background: #c40000; }
.bars i:nth-child(7) { background: #0000c4; }

.checks { display: grid; gap: 6px; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; }
.checks li[data-ok="1"] .mark { color: var(--ready-ink); font-weight: 700; }
.checks li[data-ok="0"] .mark { color: var(--air-ink); font-weight: 700; }

/* ------------------------------------------------------------------ Messages éphémères */

.toasts { position: fixed; z-index: 45; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 12px); transform: translateX(-50%); display: grid; gap: 8px; width: min(94vw, 520px); pointer-events: none; }
body:not(.has-tabs) .toasts { bottom: 18px; }
.toast { color-scheme: light; pointer-events: auto; padding: 12px 16px; background: var(--desk); color: var(--ink); border-radius: var(--r-key); box-shadow: 0 6px 22px rgba(0, 0, 0, .5); border-left: 5px solid var(--ink); }
.toast[data-tone="bad"] { border-color: var(--air-ink); }
.toast[data-tone="ok"] { border-color: var(--ready-ink); }

/* ---------------------------------------------------------------- Films (dossiers de scènes) */
textarea.tall { min-height: 240px; white-space: pre-wrap; }
.film-head { display: grid; gap: 12px; }
.film-state { font-size: 17px; }
.film-meter { position: relative; height: 8px; border-radius: 99px; overflow: hidden; background: var(--desk-down); }
.film-meter > span { background: var(--ready-ink); }
.scenes { display: grid; gap: 10px; }
.scene { display: grid; grid-template-columns: 28px 1fr; gap: 6px 12px; align-items: start; padding: 12px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r-key); }
.scene[data-status="active"] { border-color: var(--air-ink); }
.scene[data-status="failed"] { border-color: var(--fault-ink); }
.scene-no { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.scene-thumb { grid-column: 2; max-width: 240px; display: block; aspect-ratio: 16 / 9; background: #111; border-radius: 6px; overflow: hidden; }
.scene-body { grid-column: 2; min-width: 0; }
.scene-thumb img, .scene-thumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
.scene-prompt { font-size: 14px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.scene-state { font-size: 14px; font-weight: 600; margin-top: 4px; }
.scene-state[data-tone="ok"] { color: var(--ready-ink); }
.scene-state[data-tone="bad"] { color: var(--fault-ink); }
.scene-state[data-tone="live"] { color: var(--air-ink); }
.scene-why { font-size: 13px; color: var(--ink-soft); overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- Photo de départ */
.photo-line { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.photo-line > div { min-width: 0; flex: 1 1 180px; }
.photo-prev { width: 112px; max-height: 132px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #111; }
.photo-prev[hidden] { display: none; }

/* ---------------------------------------------------------------- Musique */
.note-glyph { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--ready); font-size: clamp(40px, 12vw, 120px); line-height: 1; background: #000; }
.tile-screen .note-glyph, .scene-thumb .note-glyph { font-size: 44px; }
.scene-thumb a { position: relative; display: block; height: 100%; }
.screen audio.film { position: absolute; left: 5%; right: 5%; bottom: 8%; width: 90%; z-index: 2; }
.specs .lyrics { white-space: normal; max-height: 16em; overflow: auto; }

/* ---------------------------------------------------------------- Vidéo de départ */
.clip-prev { width: 200px; max-width: 100%; max-height: 220px; background: #000; border-radius: 8px; border: 1px solid var(--line); }
.clip-prev[hidden] { display: none; }

/* ---------------------------------------------------------------- Personnages */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.thumbs li { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: #111; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x { position: absolute; top: 2px; right: 2px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .7); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.thumb-x:hover, .thumb-x:focus-visible { background: #000; }
#ch-list { margin-top: 16px; }
.train-meter { position: relative; height: 8px; border-radius: 99px; overflow: hidden; background: var(--desk-down); }
.train-meter > span { display: block; height: 100%; width: calc(var(--p, 0) * 100%); background: var(--air-ink); transition: width .5s linear; }

/* ------------------------------------------------------------------ Grands écrans */

@media (min-width: 620px) {
  .wallgrid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px 14px; }
  .rail > .tile { flex-basis: 240px; }
  .statgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .search { flex: 0 1 400px; }
  .actions-main { display: flex; flex-wrap: wrap; }
  .actions-main .key { padding: 10px 18px; }
  .rowcard { grid-template-columns: 1fr auto; }
  .rowcard .tile-actions { justify-content: flex-end; }
  .maprow { grid-template-columns: 150px 1fr; }
  .scene { grid-template-columns: 34px 132px 1fr; }
  .scene-thumb { grid-column: auto; max-width: none; }
  .scene-body { grid-column: auto; }
  .drawer { margin: auto; border-radius: var(--r-desk); }
}

@media (min-width: 900px) {
  :root { --gut: 24px; --tab-h: 0px; --top-h: 60px; }
  .top { max-width: calc(var(--col) + 48px); margin: 0 auto; gap: 18px; }
  .brand { flex: none; font-size: 20px; }
  .tabbar {
    position: static; flex: 1 1 auto; display: flex; gap: 2px; padding: 0;
    background: none; border: 0;
  }
  .tab {
    display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 12px;
    border-radius: var(--r-key); font-size: 15px; font-stretch: 100%; font-weight: 500;
  }
  .tab svg { width: 19px; height: 19px; }
  .tab:hover { color: var(--text); background: var(--wall-up); }
  .tab[aria-current="page"]::before { top: auto; bottom: -11px; left: 12px; right: 12px; border-radius: 3px 3px 0 0; }
  .tab-badge { position: static; }
  .tally { max-width: none; font-size: 15px; }
  .lien, .banner { margin-left: auto; margin-right: auto; width: calc(100% - 48px); }
  .main { padding-top: 20px; padding-bottom: 64px; }
  .main > * + * { margin-top: 28px; }
  .title { font-size: 28px; }
  .stage { margin: 0; }
  .stage .screen { border: 10px solid var(--bezel); border-radius: var(--r-screen); }
  .stage .monitor::before { inset: 10px; }
  .stage .note { padding: 0; }
  .stage .screen:not(.playing) { aspect-ratio: 16 / 9; }
  .stage .slate { padding: 7%; }
  .desk { padding: 22px; }
  .sheet { padding: 26px; }
  .modes, .filters, .tabs { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; flex-wrap: wrap; }
  .chips { margin: 0; padding: 2px 0; flex-wrap: wrap; }
  .rail { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px 14px; margin: 0; padding: 0; overflow: visible; }
  .rail > .tile { max-width: none; }
  .dock { position: static; margin: 0; padding: 0; background: none; border: 0; display: flex; }
  .dock .why { flex: 1 1 240px; }
  .dock .key { flex: none; min-height: 50px; font-size: 16px; padding: 10px 30px; }
  .toasts { bottom: 18px; }
  .burn { font-size: 13px; padding: 2px 9px; }
  .burn-tl, .burn-tr { top: 10px; }
  .burn-tl, .burn-bl { left: 10px; }
  .burn-tr, .burn-br { right: 10px; }
  .burn-bl, .burn-br { bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .monitor[data-state="busy"]::before { opacity: .85; }
  .meter[data-mode="wait"] > span { width: 100%; opacity: .35; }
}
