/* Studio IA — interface */
:root {
  --fond: #fafafa; --surface: #ffffff; --surface-2: #f4f4f5; --texte: #18181b; --doux: #71717a;
  --pale: #a1a1aa; --ligne: #e4e4e7; --ligne-forte: #d4d4d8;
  --accent: #18181b; --accent-texte: #ffffff;
  --ok: #16a34a; --ok-fond: #f0fdf4; --info: #2563eb; --info-fond: #eff6ff;
  --att: #d97706; --att-fond: #fffbeb; --err: #dc2626; --err-fond: #fef2f2;
  --ombre: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.02);
  --ombre-haut: 0 8px 30px rgba(0,0,0,.08);
  --r: 12px; --r-petit: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0b0b0c; --surface: #141416; --surface-2: #1c1c1f; --texte: #f4f4f5; --doux: #a1a1aa;
    --pale: #71717a; --ligne: #26262a; --ligne-forte: #34343a;
    --accent: #fafafa; --accent-texte: #18181b;
    --ok: #4ade80; --ok-fond: rgba(74,222,128,.1); --info: #60a5fa; --info-fond: rgba(96,165,250,.1);
    --att: #fbbf24; --att-fond: rgba(251,191,36,.1); --err: #f87171; --err-fond: rgba(248,113,113,.1);
    --ombre: 0 0 0 1px rgba(255,255,255,.02); --ombre-haut: 0 8px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--fond); color: var(--texte);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: inherit; }
svg { width: 16px; height: 16px; flex: none; }
p svg, .sous svg, .pale svg { width: 14px; height: 14px; vertical-align: -2px; }
::selection { background: color-mix(in srgb, var(--info) 25%, transparent); }

/* --- structure --- */
.app { display: flex; min-height: 100%; }
.cote { position: sticky; top: 0; height: 100vh; width: 232px; flex: none; display: flex; flex-direction: column;
  padding: 18px 12px; border-right: 1px solid var(--ligne); background: var(--surface); }
.cote[hidden] { display: none; }
.marque { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; text-decoration: none;
  font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-texte);
  display: grid; place-items: center; }
.logo svg { width: 18px; height: 18px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-petit);
  color: var(--doux); text-decoration: none; font-weight: 500; transition: background .12s, color .12s; }
nav a:hover { background: var(--surface-2); color: var(--texte); }
nav a.actif { background: var(--surface-2); color: var(--texte); }
.cote-bas { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }

main { flex: 1; min-width: 0; padding: 40px 48px 80px; max-width: 1180px; margin: 0 auto; }

/* --- textes --- */
.entete { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 13px; font-weight: 600; margin: 36px 0 12px; color: var(--doux); }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
.sous { color: var(--doux); margin: 6px 0 0; }
.pale { color: var(--pale); }
.petit { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.retour { display: inline-flex; align-items: center; gap: 6px; color: var(--doux); text-decoration: none;
  font-size: 13px; margin-bottom: 16px; }
.retour:hover { color: var(--texte); }

/* --- surfaces --- */
.carte { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--r); padding: 20px;
  box-shadow: var(--ombre); }
.carte.plate { padding: 0; overflow: hidden; }
.grille { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
a.carte { display: flex; flex-direction: column; gap: 10px; text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s; }
a.carte:hover { border-color: var(--ligne-forte); box-shadow: var(--ombre-haut); transform: translateY(-1px); }
.vide { text-align: center; padding: 48px 20px; color: var(--doux); border: 1px dashed var(--ligne-forte);
  border-radius: var(--r); }
.vide svg { width: 22px; height: 22px; color: var(--pale); margin-bottom: 8px; }

/* --- boutons --- */
button, .bouton { font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--r-petit); cursor: pointer;
  border: 1px solid var(--ligne-forte); background: var(--surface); color: var(--texte);
  transition: background .12s, border-color .12s, opacity .12s; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--info) 60%, transparent); outline-offset: 2px; }
button.principal { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
button.principal:hover { opacity: .88; }
button.petit { height: 28px; padding: 0 10px; font-size: 13px; }
button.fantome { border-color: transparent; background: transparent; color: var(--doux); }
button.fantome:hover { background: var(--surface-2); color: var(--texte); }
button.danger:hover { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); background: var(--err-fond); }
button:disabled { opacity: .45; cursor: default; }
.lien-discret { border: 0; background: none; color: var(--pale); height: 30px; justify-content: flex-start; padding: 0 10px; }
.lien-discret:hover { color: var(--texte); background: var(--surface-2); }

.pause { justify-content: flex-start; width: 100%; gap: 10px; }
.pause .point { width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.pause.active { background: var(--err-fond); border-color: color-mix(in srgb, var(--err) 35%, transparent); color: var(--err); }
.pause.active .point { background: var(--err); box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 20%, transparent); }

/* --- formulaires --- */
input, textarea, select { font: inherit; color: var(--texte); background: var(--surface); width: 100%;
  border: 1px solid var(--ligne-forte); border-radius: var(--r-petit); padding: 8px 11px; transition: border-color .12s, box-shadow .12s; }
input, select { height: 36px; }
input::placeholder, textarea::placeholder { color: var(--pale); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--texte);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--texte) 8%, transparent); }
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 500; margin: 0 0 14px; }
label > input, label > textarea, label > select { margin-top: 6px; font-weight: 400; }
label .opt { color: var(--pale); font-weight: 400; }
.champs { display: grid; gap: 0 14px; grid-template-columns: 2fr 1fr; }
.champs.trois { grid-template-columns: repeat(3, 1fr); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- pastilles --- */
.pastille { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
  padding: 2px 9px 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--doux); white-space: nowrap; }
.pastille::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pastille.ok { background: var(--ok-fond); color: var(--ok); }
.pastille.info { background: var(--info-fond); color: var(--info); }
.pastille.att { background: var(--att-fond); color: var(--att); }
.pastille.err { background: var(--err-fond); color: var(--err); }
.pastille.barre-txt { text-decoration: line-through; }
.pastille.info::before { animation: pouls 1.6s ease-in-out infinite; }
@keyframes pouls { 50% { opacity: .3; } }

/* --- cartes épisode --- */
.ep-haut { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ep-titre { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.ep-meta { display: flex; gap: 14px; color: var(--doux); font-size: 13px; flex-wrap: wrap; }
.ep-meta span { display: inline-flex; align-items: center; gap: 5px; }
.ep-meta svg { width: 14px; height: 14px; color: var(--pale); }
.mini-etapes { display: flex; gap: 4px; margin-top: 2px; }
.mini-etapes i { flex: 1; height: 3px; border-radius: 2px; background: var(--ligne); }
.mini-etapes i.fait { background: var(--texte); }
.mini-etapes i.cours { background: var(--info); }

/* --- étapes --- */
.etapes { display: flex; gap: 0; margin: 4px 0 28px; padding: 0; list-style: none; overflow-x: auto; }
.etapes li { flex: 1; min-width: 92px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px;
  color: var(--pale); font-weight: 500; }
.etapes li::before { content: ""; height: 3px; border-radius: 2px; background: var(--ligne); margin-right: 6px; }
.etapes li.fait { color: var(--texte); } .etapes li.fait::before { background: var(--texte); }
.etapes li.cours { color: var(--info); } .etapes li.cours::before { background: var(--info); }

/* --- tableau --- */
.table { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--ligne); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { color: var(--doux); font-weight: 500; font-size: 12px; background: var(--surface-2); border-bottom-color: var(--ligne); }
tbody tr { transition: background .1s; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.fin { text-align: right; width: 1%; }
.barre { height: 4px; background: var(--ligne); border-radius: 2px; overflow: hidden; min-width: 70px; }
.barre > i { display: block; height: 100%; background: var(--info); border-radius: 2px; transition: width .4s; }
.barre.ok > i { background: var(--ok); }
.message { color: var(--doux); font-size: 12.5px; white-space: pre-wrap; max-width: 340px; overflow-wrap: anywhere; }
.replique { min-width: 240px; }
td textarea { min-height: 58px; font-size: 13.5px; }

/* --- détails --- */
.resume { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
.resume dt { font-size: 12px; color: var(--doux); font-weight: 500; margin-bottom: 4px; }
.resume dd { margin: 0; }
.resume .large { grid-column: 1 / -1; }

.cle { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--surface-2);
  padding: 12px 14px; border-radius: var(--r-petit); overflow-wrap: anywhere; border: 1px solid var(--ligne); }
.alerte { margin-top: 16px; padding: 16px; border-radius: var(--r); background: var(--att-fond);
  border: 1px solid color-mix(in srgb, var(--att) 30%, transparent); }
.alerte p { margin: 0 0 10px; }

.medias { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.medias figure { margin: 0; background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--r); overflow: hidden; }
.medias img, .medias video { width: 100%; display: block; background: #000; aspect-ratio: 16/9; object-fit: cover; }
.medias audio { width: 100%; padding: 10px; }
.medias .fichier { display: grid; place-items: center; aspect-ratio: 16/9; background: var(--surface-2); color: var(--doux); text-decoration: none; }
.medias figcaption { font-size: 12px; color: var(--doux); padding: 8px 12px; overflow-wrap: anywhere; }

/* --- personnages --- */
.champ-lib { font-size: 13px; font-weight: 500; margin: 0 0 8px; }
.distribution { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.choix-perso { position: relative; display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 3px 12px 3px 3px;
  border-radius: 99px; border: 1px solid var(--ligne-forte); background: var(--surface); cursor: pointer; font-weight: 500;
  user-select: none; transition: border-color .12s, background .12s, box-shadow .12s; }
.choix-perso input { position: absolute; opacity: 0; pointer-events: none; }
.choix-perso:hover { border-color: var(--pale); }
.choix-perso:has(input:checked) { border-color: var(--couleur, var(--texte));
  background: color-mix(in srgb, var(--couleur, var(--texte)) 9%, var(--surface));
  box-shadow: 0 0 0 1px var(--couleur, var(--texte)); }
.choix-perso:has(input:not(:checked)) { color: var(--doux); }
.choix-perso:has(input:not(:checked)) .vignette { filter: grayscale(1); opacity: .6; }
.choix-perso:has(input:focus-visible) { outline: 2px solid color-mix(in srgb, var(--info) 60%, transparent); outline-offset: 2px; }
.choix-perso:has(input:disabled) { cursor: default; }
.vignette { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; object-position: 50% 15%; flex: none;
  background: var(--couleur, var(--ligne)); display: inline-grid; place-items: center; color: #fff; font-size: 12px; font-weight: 600; }
#distribution .distribution { margin-bottom: 14px; }
#distribution .distribution:last-child { margin-bottom: 0; }

.ajout { display: flex; gap: 8px; }
.ajout input { width: 220px; }
.fiches { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.fiche { padding: 0; overflow: hidden; display: flex; flex-direction: column; border-top: 3px solid var(--couleur, var(--ligne)); }
.fiche.archive { opacity: .55; }
.fiche.archive:hover { opacity: .85; }
.portrait-zone { position: relative; margin: 0; cursor: pointer; display: block; background: var(--surface-2); }
.portrait-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.fiche .portrait { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; display: block;
  background: color-mix(in srgb, var(--couleur, #888) 12%, var(--surface-2)); }
.fiche .sans-image { width: 100%; aspect-ratio: 4 / 3; display: grid; place-items: center;
  background: color-mix(in srgb, var(--couleur, #888) 18%, var(--surface-2)); color: var(--couleur, var(--doux));
  font-size: 44px; font-weight: 600; }
.portrait-action { position: absolute; left: 10px; bottom: 10px; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 99px; color: #fff; background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px); opacity: 0; transition: opacity .15s; max-width: calc(100% - 20px); }
.portrait-action .nom-fichier { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portrait-zone:hover .portrait-action, .portrait-zone:focus-within .portrait-action { opacity: 1; }
.fiche-corps { padding: 16px 18px 18px; }
.fiche-tete { display: flex; gap: 8px; align-items: center; }
.fiche-nom { font-size: 16px; font-weight: 600; letter-spacing: -.01em; border-color: transparent; padding-left: 6px;
  margin-left: -7px; background: transparent; }
.fiche-nom:hover { border-color: var(--ligne-forte); }
input[type=color] { width: 36px; height: 36px; padding: 3px; flex: none; cursor: pointer; }
.fiche label { margin-top: 14px; margin-bottom: 0; }
.fiche label .opt { margin-left: 4px; }
.fiche textarea { min-height: 64px; font-size: 13.5px; }
.fiche .actions { margin-top: 16px; }

.bandeau { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; margin: -12px 0 24px;
  border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--ligne); }
.bandeau svg { margin-top: 2px; color: var(--doux); }
.bandeau .sous { display: block; margin-top: 2px; }

/* --- miniatures --- */
.mini-champs { grid-template-columns: 1fr 120px; }
.miniatures { display: grid; gap: 12px; margin-top: 12px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.idee { display: flex; flex-direction: column; gap: 14px; padding: 16px; }
.texte-idee { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; font-weight: 600;
  letter-spacing: -.01em; }
.idee-formats { display: grid; grid-template-columns: 1fr 30%; gap: 10px; align-items: end; }
.mini { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.mini a { display: block; border-radius: var(--r-petit); overflow: hidden; outline: 1px solid var(--ligne);
  transition: outline-color .12s, box-shadow .12s; }
.mini a:hover { outline-color: var(--pale); }
.mini img { width: 100%; display: block; background: var(--surface-2); }
.mini-16x9 img, .mini-16x9 .mini-vide { aspect-ratio: 16 / 9; }
.mini-9x16 img, .mini-9x16 .mini-vide { aspect-ratio: 9 / 16; }
.mini img { object-fit: cover; }
.mini.choisie a { outline: 2px solid var(--ok); box-shadow: 0 0 0 4px var(--ok-fond); }
.mini-vide { display: grid; place-items: center; border-radius: var(--r-petit); border: 1px dashed var(--ligne-forte);
  color: var(--pale); font-size: 12px; }
.mini figcaption { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px;
  color: var(--doux); min-height: 28px; flex-wrap: wrap; }

/* --- agents --- */
.agent { display: flex; flex-direction: column; gap: 14px; }
.jauges { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.jauge .lib { display: flex; justify-content: space-between; font-size: 12px; color: var(--doux); margin-bottom: 6px; }
.jauge .lib b { color: var(--texte); font-weight: 500; font-variant-numeric: tabular-nums; }
.puces { display: flex; gap: 6px; flex-wrap: wrap; }
.puce { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--doux); }

/* --- connexion --- */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 24px; width: 100%; }
.connexion form { width: 100%; max-width: 380px; }
.connexion .logo { width: 40px; height: 40px; border-radius: 11px; margin-bottom: 20px; }
.connexion .logo svg { width: 24px; height: 24px; }
.connexion h1 { font-size: 22px; }
.connexion .sous { margin-bottom: 28px; }
.connexion button { width: 100%; height: 38px; }
.connexion .erreur { min-height: 20px; margin-top: 10px; font-size: 13px; }
main.plein { padding: 0; max-width: none; }

.erreur { color: var(--err); }
.sous.intro { margin: 0 0 22px; } .sous.serre { margin: 0; } .serre-haut { margin: 12px 0 0; }
.espace-bas { margin-bottom: 20px; } .fort { font-weight: 500; color: var(--texte); } .gpu { margin-bottom: 12px; }
.c-info { color: var(--info); } tr.eteint { opacity: .5; }
td.n { white-space: nowrap; }
.chargement { display: grid; place-items: center; padding: 80px 0; }
.spin { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--ligne); border-top-color: var(--texte);
  animation: tourne .7s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: calc(100vw - 32px); }
.toast { background: var(--texte); color: var(--fond); padding: 11px 16px; border-radius: 10px; box-shadow: var(--ombre-haut);
  font-size: 13.5px; max-width: 420px; animation: entre .2s ease-out; }
.toast.erreur { background: var(--err); color: #fff; }
@keyframes entre { from { opacity: 0; transform: translateY(6px); } }

/* --- mobile --- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .cote { position: sticky; top: 0; z-index: 5; height: auto; width: 100%; flex-direction: row; align-items: center;
    padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--ligne);
    background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(12px); }
  .marque { padding: 0; } .marque > span:last-child { display: none; }
  nav { flex-direction: row; overflow-x: auto; flex: 1; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; padding: 6px 10px; }
  nav a svg { display: none; }
  .cote-bas { margin: 0; flex-direction: row; }
  .pause { width: auto; padding: 0 10px; } .pause .txt { display: none; }
  .lien-discret { padding: 0 8px; } .lien-discret .txt { display: none; }
  main { padding: 24px 16px 60px; }
  .champs, .champs.trois, .resume { grid-template-columns: 1fr; }
  .ajout { width: 100%; } .ajout input { width: auto; flex: 1; }
  .portrait-action { opacity: 1; }
  th.opt, td.opt { display: none; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
}
