:root {
  --violet-900: #2a1559;
  --violet-700: #4b2a9b;
  --violet-600: #5b34c4;
  --violet-500: #7048e8;
  --violet-100: #ece6fd;
  --violet-50: #f6f3fe;
  --ink: #1d1830;
  --ink-soft: #5d577a;
  --line: #e4dff2;
  --bg: #fbfaff;
  --panel: #ffffff;
  --danger: #c2334d;
  --warn: #a8670b;
  --ok: #1f8f5f;
  --radius: 14px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ece8fb; --ink-soft: #a59fc4; --line: #2f2850; --bg: #14111f; --panel: #1c1830;
    --violet-50: #221c3d; --violet-100: #2c2450;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
a { color: var(--violet-500); }

/* ---------- Marque ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--violet-500), var(--violet-900));
  color: #fff; display: grid; place-items: center; font-size: 15px; font-weight: 800;
}
.brand-name { font-size: 20px; }
.brand-name span { color: var(--violet-500); }
.brand-sub { font-size: 12px; font-weight: 600; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; }

/* ---------- Connexion ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 20% 10%, var(--violet-100), transparent 50%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px; box-shadow: 0 20px 50px -30px rgba(75, 42, 155, .5);
}
.login-card h1 { font-size: 22px; margin: 20px 0 6px; }
.login-card p { color: var(--ink-soft); margin: 0 0 20px; font-size: 14px; line-height: 1.5; }
.field {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); font-size: 15px; outline: none;
}
.field:focus { border-color: var(--violet-500); box-shadow: 0 0 0 3px var(--violet-100); }
textarea.field { resize: vertical; line-height: 1.45; }
.code-field { text-transform: uppercase; letter-spacing: .12em; text-align: center; font-weight: 600; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600;
  background: var(--violet-600); color: #fff;
}
.btn:hover { background: var(--violet-700); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-block { width: 100%; margin-top: 12px; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--violet-50); color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn-danger:hover { background: rgba(194, 51, 77, .08); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 20px; }
.note { color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.link-btn { border: 0; background: none; color: var(--violet-500); padding: 0; font-size: 13px; }

/* ---------- Mise en page ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--ink-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; background: var(--violet-50); border: 1px solid var(--line);
  color: var(--ink);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #aaa; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(31, 143, 95, .18); }
.dot.busy { background: var(--violet-500); box-shadow: 0 0 0 3px var(--violet-100); }
.dot.off { background: var(--danger); }

.page { display: grid; grid-template-columns: minmax(340px, 430px) 1fr; gap: 22px; padding: 22px; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel h2 { font-size: 16px; margin: 0 0 4px; }
.panel h3 { font-size: 14px; margin: 16px 0 6px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.tab {
  border: 1px solid transparent; background: transparent; padding: 7px 11px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-soft);
}
.tab:hover { background: var(--violet-50); color: var(--ink); }
.tab.active { background: var(--violet-100); color: var(--ink); border-color: var(--line); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label.titre { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 5px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.45; }
.check input { margin-top: 3px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--bg); padding: 8px 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--violet-600); color: #fff; }
details.avance summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); }
details.avance[open] summary { margin-bottom: 10px; }

.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; font-size: 13.5px;
  color: var(--ink-soft); background: var(--bg); cursor: pointer; position: relative;
}
.drop.sur { border-color: var(--violet-500); background: var(--violet-50); }
.drop img { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin: 0 auto 8px; }
.drop input { display: none; }

.regles {
  border: 1px solid var(--line); background: var(--violet-50); border-radius: 12px; padding: 11px 12px;
  font-size: 12.5px; line-height: 1.5; color: var(--ink-soft);
}
.regles b { color: var(--ink); }

/* ---------- Storyboard ---------- */
.cases { display: flex; flex-direction: column; gap: 10px; }
.case { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: start; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.case img { width: 72px; height: 72px; object-fit: cover; border-radius: 7px; }
.case .num { font-size: 12px; font-weight: 700; color: var(--ink-soft); }

/* ---------- Galerie ---------- */
.galerie-tete { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.galerie-tete h2 { margin: 0; font-size: 18px; }
.filtres { display: flex; gap: 4px; }
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.carte { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.media { background: #0f0c18; aspect-ratio: 9 / 12; display: grid; place-items: center; position: relative; }
.media video, .media img { width: 100%; height: 100%; object-fit: contain; display: block; }
.media .vide { color: #9a93bd; font-size: 13px; padding: 14px; text-align: center; }
.badge {
  position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: rgba(20, 17, 31, .75); color: #fff;
}
.badge.ia { left: auto; right: 8px; background: rgba(112, 72, 232, .85); }
.carte-corps { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.carte-titre { font-size: 13px; line-height: 1.4; max-height: 3.9em; overflow: hidden; }
.carte-meta { font-size: 12px; color: var(--ink-soft); }
.etat { font-size: 12px; font-weight: 700; }
.etat.attente { color: var(--ink-soft); }
.etat.en_cours { color: var(--violet-500); }
.etat.termine { color: var(--ok); }
.etat.erreur, .etat.annule { color: var(--danger); }
.barre { height: 5px; border-radius: 9px; background: var(--violet-100); overflow: hidden; }
.barre > i { display: block; height: 100%; background: var(--violet-500); transition: width .6s; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.vignettes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; width: 100%; height: 100%; }
.vignettes img { object-fit: cover; cursor: zoom-in; }

/* ---------- Styles ---------- */
.style-carte { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 64px 1fr; gap: 10px; }
.style-carte > img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.echantillons { display: flex; gap: 4px; margin-top: 6px; }
.echantillons img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
code.decl { background: var(--violet-50); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }

/* ---------- Fenêtres ---------- */
.voile { position: fixed; inset: 0; background: rgba(20, 17, 31, .55); display: grid; place-items: center; z-index: 20; padding: 20px; }
.fenetre { background: var(--panel); border-radius: 18px; padding: 22px; width: min(620px, 100%); max-height: 90vh; overflow: auto; border: 1px solid var(--line); }
.fenetre h2 { margin: 0 0 10px; font-size: 18px; }
.fenetre pre { background: var(--violet-50); border: 1px solid var(--line); padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.zoom img { max-width: 92vw; max-height: 88vh; border-radius: 10px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 90vw;
}
table.liste { width: 100%; border-collapse: collapse; font-size: 13px; }
table.liste th, table.liste td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.liste th { color: var(--ink-soft); font-weight: 600; font-size: 12px; }

@media (max-width: 900px) {
  .page { grid-template-columns: 1fr; padding: 14px; }
  .topbar { padding: 10px 14px; }
  .topbar-right .qui { display: none; }
}

/* ---------- 0.3 : BD, refaire, assembler ---------- */
.bandeau { border: 1px solid var(--violet-500); background: var(--violet-50); border-radius: 10px; padding: 9px 11px; font-size: 13px; line-height: 1.45; }
.lots { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.lot { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.lot-tete { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.lot-tete b { font-size: 15px; }
.bande { display: flex; gap: 4px; overflow-x: auto; }
.bande .mini { position: relative; flex: none; width: 54px; height: 76px; border-radius: 6px; overflow: hidden; background: #0f0c18; }
.bande .mini img { width: 100%; height: 100%; object-fit: cover; }
.bande .mini span { position: absolute; left: 3px; bottom: 3px; font-size: 10px; font-weight: 700; color: #fff; background: rgba(20,17,31,.75); border-radius: 4px; padding: 0 4px; }
.bande .mini.attente img, .bande .mini.en_cours img { opacity: .45; }
.bande .mini.erreur { outline: 2px solid var(--danger); }
.bande .mini.absente { background: repeating-linear-gradient(45deg, var(--violet-50), var(--violet-50) 6px, var(--line) 6px, var(--line) 12px); }
.case-num { font-size: 11.5px; font-weight: 700; color: var(--violet-500); }
.case .remplacer { font-size: 11.5px; }
.case.decochee { opacity: .45; }
.ordre-ligne { display: grid; grid-template-columns: auto 46px 1fr auto auto; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; font-size: 13px; }
.ordre-ligne img { width: 46px; height: 46px; object-fit: cover; border-radius: 6px; }
.ordre-ligne .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ink-soft); }

/* personnages */
.persos-choix { display: flex; flex-wrap: wrap; gap: 6px; }
.persos-choix label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px 4px 4px; cursor: pointer; font-size: 13px; }
.persos-choix label.on { border-color: var(--violet-600); background: var(--violet-50); }
.persos-choix img { width: 32px; height: 42px; object-fit: cover; border-radius: 6px; background: #fff; }
.persos-choix input { display: none; }
.perso-carte > img { object-fit: contain; background: #fff; }
.propositions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.propositions figure { margin: 0; display: grid; gap: 4px; justify-items: center; }
.propositions img { width: 88px; height: 150px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: zoom-in; }
.fin-carte video { width: 64px; height: 110px; object-fit: cover; border-radius: 8px; background: #000; }
.fin-carte { grid-template-columns: 64px 1fr; }

/* ---------- 0.5 : pages séparées ---------- */
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { padding: 8px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--ink-soft); text-decoration: none; }
.nav a:hover { background: var(--violet-50); color: var(--ink); }
.nav a.active { background: var(--violet-100); color: var(--violet-700); }
@media (prefers-color-scheme: dark) { .nav a.active { color: var(--ink); } }
.contenu { padding: 22px; max-width: 1500px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.vue-tete { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.vue-tete h1, .galerie-tete h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.vue-tete .note { margin: 4px 0 0; max-width: 70ch; }
.sous-titre { font-size: 15px; margin: 0 0 10px; }

/* Mes BD : des tuiles compactes, puis une vue par BD */
.bd-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.bd-tuile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; text-align: left; padding: 0; }
.bd-tuile:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -20px rgba(75, 42, 155, .6); }
.bd-tuile .couv { aspect-ratio: 9 / 13; background: #0f0c18; position: relative; }
.bd-tuile .couv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bd-tuile .couv .vide { position: absolute; inset: 0; background: repeating-linear-gradient(45deg, var(--violet-50), var(--violet-50) 8px, var(--line) 8px, var(--line) 16px); }
.bd-tuile .info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.bd-tuile .info b { font-size: 14px; line-height: 1.3; }
.pastille { position: absolute; left: 8px; top: 8px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(20,17,31,.8); padding: 3px 8px; border-radius: 999px; }
.pastille.ok { background: rgba(31, 143, 95, .9); }
.bd-corps { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 22px; align-items: start; }
.bd-corps #bd-montage:empty { display: none; }
.bd-corps:has(#bd-montage:empty) { grid-template-columns: 1fr; }
#bd-montage video { width: 100%; border-radius: var(--radius); background: #000; display: block; }

/* Personnages : dossiers et grande grille */
.dossiers { display: flex; flex-wrap: wrap; gap: 6px; }
.dossiers button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.dossiers button.on { background: var(--violet-600); border-color: var(--violet-600); color: #fff; }
.dossiers button .n { opacity: .7; font-weight: 500; margin-left: 4px; }
.persos-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
.perso-tuile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.perso-tuile.cliquable { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.perso-tuile.cliquable:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -20px rgba(75, 42, 155, .6); }
.perso-tuile > img, .perso-tuile > .portrait-vide { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #fff; display: block; }
.perso-tuile > .portrait-vide { background: repeating-linear-gradient(45deg, var(--violet-50), var(--violet-50) 8px, var(--line) 8px, var(--line) 16px); }
.perso-tuile .info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.perso-tuile .info b { font-size: 15px; }
.perso-tuile.large { grid-column: span 3; }
@media (max-width: 700px) { .perso-tuile.large { grid-column: 1 / -1; } }
.perso-tuile.large .propositions img { width: 120px; height: 200px; }
.fenetre.fiche { display: grid; grid-template-columns: 220px 1fr; gap: 18px; width: min(720px, 100%); }
.fenetre.fiche img { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
@media (max-width: 640px) { .fenetre.fiche { grid-template-columns: 1fr; } .fenetre.fiche img { max-height: 40vh; } }

/* Réglages */
.reglages-grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .bd-corps { grid-template-columns: 1fr; }
  .contenu { padding: 14px; }
}
.bd-corps { margin-top: 6px; }
#bd-actions { margin-top: 0; }
@media (max-width: 700px) {
  .bd-grille { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .persos-grille { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .vue-tete h1, .galerie-tete h1 { font-size: 20px; }
}
