:root {
  --fond: #f4f4f6;
  --carte: #ffffff;
  --texte: #1d1d22;
  --discret: #62626d;
  --bord: #d9d9e0;
  --accent: #5865f2;
  --accent-texte: #ffffff;
  --erreur: #b3261e;
  --erreur-fond: #fdecea;
  --info-fond: #eef0fe;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #1e1f22;
    --carte: #2b2d31;
    --texte: #ececf1;
    --discret: #a3a6ae;
    --bord: #3f4147;
    --accent: #5865f2;
    --accent-texte: #ffffff;
    --erreur: #ffb4ab;
    --erreur-fond: #4a1f1c;
    --info-fond: #313338;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0 auto;
  max-width: 860px;
  padding: 16px;
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0 0 8px; font-size: 1.1rem; }
h3 { margin: 14px 0 6px; font-size: 0.95rem; }
.sous-titre { margin: 2px 0 12px; color: var(--discret); }
.discret { color: var(--discret); }

.cle { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cle input { flex: 1 1 200px; }

.bloc {
  margin-top: 14px;
  padding: 14px;
  background: var(--carte);
  border: 1px solid var(--bord);
  border-radius: 10px;
}

.titre-bloc { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
label, .champ { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; color: var(--discret); }

input, select, button {
  font: inherit;
  color: var(--texte);
  background: var(--fond);
  border: 1px solid var(--bord);
  border-radius: 6px;
  padding: 6px 8px;
  min-height: 36px;
}

button { cursor: pointer; background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: default; }
button.secondaire { background: var(--fond); color: var(--texte); border-color: var(--bord); }
button.discret { background: transparent; color: var(--discret); border-color: transparent; }
a.discret { text-decoration: none; }
a.discret:hover { text-decoration: underline; }

#messages p { margin: 12px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--info-fond); }
#messages p.erreur { background: var(--erreur-fond); color: var(--erreur); }

#etapes { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.etape { padding: 10px; border: 1px solid var(--bord); border-radius: 8px; }
.entete-etape { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.boutons button { min-width: 36px; padding: 4px 8px; }
.etat-upload { margin: 6px 0 0; font-size: 0.85rem; }
.etat-upload:empty { display: none; }

.etape[data-genre="texte"] .si-bibliotheque,
.etape[data-genre="texte"] .si-upload,
.etape[data-genre="bibliotheque"] .si-texte,
.etape[data-genre="bibliotheque"] .si-upload,
.etape[data-genre="upload"] .si-texte,
.etape[data-genre="upload"] .si-bibliotheque { display: none; }

.choisir { display: flex; align-items: center; gap: 8px; text-align: left; }
.vignette { width: 32px; height: 32px; border-radius: 4px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

.rendu { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.rendu p { margin: 0 0 6px; }
.damier {
  padding: 8px;
  border-radius: 8px;
  background: repeating-conic-gradient(#cfcfd6 0% 25%, #f0f0f3 0% 50%) 50% / 16px 16px;
}
.damier img { display: block; max-width: 100%; image-rendering: auto; }
#telecharger { display: inline-block; margin-top: 4px; color: var(--accent); font-weight: 600; }

dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: var(--carte);
  color: var(--texte);
  border: 1px solid var(--bord);
  border-radius: 10px;
  padding: 14px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.grille-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.case-image {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--fond); color: var(--texte); border-color: var(--bord); font-size: 0.8rem;
}
.case-image img { width: 64px; height: 64px; border-radius: 6px; }
