:root {
  --fond: #f4f2ee;
  --carte: #ffffff;
  --texte: #23201c;
  --discret: #6d675e;
  --bord: #ddd8cf;
  --accent: #7a3e1d;
  --accent-clair: #f3e6dc;
  --modifie: #fff4c2;
  --modifie-bord: #d9a400;
  --erreur: #b3261e;
  --erreur-fond: #fde7e5;
  --ok: #2f6b3a;
  --ok-fond: #e3f2e5;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--texte);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fond); }
[hidden] { display: none !important; }
button {
  font: inherit; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--bord);
  background: var(--carte); color: var(--texte); cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
button.principal:hover { filter: brightness(1.1); }
button.lien { border: none; background: none; color: var(--discret); text-decoration: underline; padding: 4px; }
button.petit { padding: 2px 8px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; padding: 3px 7px; border: 1px solid var(--bord); border-radius: 5px; background: #fff; color: var(--texte);
}
textarea { width: 100%; min-height: 40px; resize: vertical; }
code { background: #ece8e1; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.discret { color: var(--discret); }
.erreur { color: var(--erreur); }
.avertissement { background: var(--modifie); padding: 8px 10px; border-radius: 6px; }

/* Connexion */
.ecran-connexion { min-height: 100vh; display: grid; place-items: center; }
.carte-connexion {
  background: var(--carte); padding: 32px; border-radius: 12px; width: 360px; border: 1px solid var(--bord);
  display: flex; flex-direction: column; gap: 14px;
}
.carte-connexion h1 { margin: 0; font-size: 22px; }
.carte-connexion label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }

/* Mise en page */
.barre-haut {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--accent); color: #fff;
}
.barre-haut .titre { font-weight: 700; font-size: 17px; white-space: nowrap; }
.barre-haut input[type=search] { flex: 1; max-width: 420px; border: none; }
.barre-haut .droite { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.barre-haut .discret, .barre-haut button.lien { color: #f3e6dc; }
.etat-ligne { font-size: 13px; background: rgba(255,255,255,.15); padding: 3px 8px; border-radius: 10px; }
.bandeau-erreur { background: var(--erreur-fond); color: var(--erreur); padding: 10px 20px; font-weight: 600; }
.corps { display: flex; align-items: flex-start; }
.menu {
  position: sticky; top: 52px; width: 190px; flex: none; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px;
  max-height: calc(100vh - 52px); overflow-y: auto;
}
.menu a {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 12px; border-radius: 6px;
  color: var(--texte); text-decoration: none;
}
.menu a:hover { background: #e9e5de; }
.menu a.actif { background: var(--accent-clair); color: var(--accent); font-weight: 600; }
.menu .pastille { background: var(--modifie-bord); color: #fff; border-radius: 9px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.contenu { flex: 1; padding: 14px 24px 110px; max-width: 1240px; min-width: 0; }
.contenu h1 { margin: 4px 0 2px; font-size: 21px; }
.intro { margin: 0 0 12px; color: var(--discret); max-width: 820px; font-size: 13px; }
.groupe-titre { margin: 18px 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--discret); }

/* Cartes */
.carte {
  background: var(--carte); border: 1px solid var(--bord); border-radius: 8px; margin-bottom: 6px; overflow: hidden;
}
.carte.modifiee { border-color: var(--modifie-bord); }
.carte-tete {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px; min-height: 42px; cursor: pointer; user-select: none;
}
.carte-tete:hover { background: #faf8f5; }
.carte-tete .nom { font-weight: 700; font-size: 15px; white-space: nowrap; }
.carte-tete .resume { color: var(--discret); font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.carte-tete .chevron { color: var(--discret); transition: transform .15s; font-size: 11px; }
.carte.ouverte .chevron { transform: rotate(90deg); }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 9px; background: #ece8e1; color: var(--discret); white-space: nowrap; }
.badge.boss { background: #f6d9d6; color: #8a1f17; }
.badge.elite { background: #efe0f7; color: #6a2c8a; }
.badge.mod { background: var(--modifie); color: #7a5b00; }
.carte-corps { padding: 2px 16px 12px; border-top: 1px solid var(--bord); font-size: 13px; }
.carte-corps input, .carte-corps select, .carte-corps textarea { font-size: 12px; padding: 2px 6px; }
.carte-corps select { padding: 1px 4px; }
.carte-corps button { font-size: 12px; }
.sous-titre { margin: 12px 0 6px; padding-top: 8px; border-top: 1px dashed var(--bord); font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.carte-corps > .sous-titre:first-child, .carte-corps > div:first-child > .sous-titre:first-child { border-top: none; }
.infos { font-size: 12px; color: var(--discret); margin-top: 8px; }

/* Champs */
.champs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 190px)); gap: 8px 14px; margin-top: 6px; }
.champ { display: flex; flex-direction: column; gap: 2px; }
.champ.large { grid-column: 1 / -1; }
.champ > span.lib { font-size: 12px; font-weight: 600; color: #4a443c; }
.champ .saisie { display: flex; align-items: center; gap: 6px; }
.champ .saisie input, .champ .saisie select { width: 100%; min-width: 0; }
.champ .unite { font-size: 12px; color: var(--discret); white-space: nowrap; }
.champ .aide, .aide { font-size: 11.5px; color: var(--discret); line-height: 1.3; }
.champ .avant { font-size: 12px; color: #7a5b00; }
.champ.modifie input, .champ.modifie select, .champ.modifie textarea { background: var(--modifie); border-color: var(--modifie-bord); }
.champ.invalide input { background: var(--erreur-fond); border-color: var(--erreur); }
.champ .msg-err { font-size: 12px; color: var(--erreur); }

/* Tableaux (ingrédients, butin, paliers) */
.tableau { border-collapse: collapse; margin-top: 4px; }
.tableau th { text-align: left; font-size: 11.5px; color: var(--discret); font-weight: 600; padding: 2px 8px; }
.tableau td { padding: 2px 8px 2px 0; }
.tableau td input { width: 70px; }
.tableau td select { min-width: 190px; }
.tableau.modifie { background: var(--modifie); border-radius: 6px; outline: 2px solid var(--modifie-bord); outline-offset: 4px; }
.tableau tr.invalide input { background: var(--erreur-fond); border-color: var(--erreur); }
.tableau .attendu { font-size: 12px; color: var(--discret); padding-left: 8px; }

/* Barre des modifications */
.barre-modifs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: #fffbe8; border-top: 2px solid var(--modifie-bord); box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.barre-modifs #nb-modifs { font-weight: 700; margin-right: auto; }

/* Fenêtres */
dialog { border: none; border-radius: 12px; padding: 0; width: min(720px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(30,20,10,.35); }
dialog form { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 19px; }
.dlg-boutons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.liste-modifs { margin: 0; padding: 0; list-style: none; max-height: 50vh; overflow-y: auto; border: 1px solid var(--bord); border-radius: 8px; }
.liste-modifs li { padding: 7px 12px; border-bottom: 1px solid var(--bord); font-size: 14px; }
.liste-modifs li:last-child { border-bottom: none; }
.liste-modifs li.auto { color: var(--discret); font-style: italic; }
.liste-modifs .fleche { color: var(--accent); font-weight: 700; padding: 0 4px; }
.liste-erreurs { margin: 0; padding: 10px 12px 10px 30px; background: var(--erreur-fond); color: var(--erreur); border-radius: 8px; }
.journal { background: #1f1c18; color: #e8e2d8; font-size: 12px; padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; white-space: pre-wrap; }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 10; max-width: 640px;
  background: var(--ok-fond); color: var(--ok); border: 1px solid var(--ok); padding: 10px 18px; border-radius: 8px; font-weight: 600;
}
.toast.erreur { background: var(--erreur-fond); color: var(--erreur); border-color: var(--erreur); }
.vide { color: var(--discret); font-style: italic; padding: 20px 0; }
.historique { font-size: 14px; }
.historique td { padding: 5px 10px 5px 0; vertical-align: top; }

/* Effet en jeu (artefacts, corps) */
.effet { margin-top: 12px; padding: 2px 14px 8px; background: #f7f3ec; border-radius: 8px; border-left: 3px solid var(--accent); }
.liste-effets { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 7px; }
.liste-effets .formule { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; color: var(--discret); margin-top: 2px; white-space: pre-line; }

/* Images des monstres */
img.vignette, img.portrait { image-rendering: pixelated; image-rendering: crisp-edges; flex: none; }
.case-vignette { flex: none; width: 80px; height: 40px; display: flex; align-items: center; justify-content: center; margin: -10px -4px; }
img.portrait { float: right; margin: 8px 0 8px 16px; background: #efe9df; border-radius: 10px; }
.carte-corps::after { content: ''; display: block; clear: both; }

/* Icônes des ressources */
.icone { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; vertical-align: middle; margin-right: 3px; }
.icone img { image-rendering: pixelated; image-rendering: crisp-edges; }
.carte-tete .icone { min-width: 34px; height: 34px; background: #efe9df; border-radius: 6px; }
.carte-tete .resume .icone { min-width: 22px; height: 22px; background: none; margin-right: 2px; }
.case-icone { width: 34px; text-align: center; }

/* Ressources : monstres qui les lâchent */
.tableau.sources td { vertical-align: middle; }
.tableau.sources td.case-vignette { width: 80px; height: 38px; margin: 0; padding: 0 8px 0 0; display: table-cell; text-align: center; overflow: hidden; }
.tableau.sources td.case-vignette img { display: block; margin: -10px auto; }
.tableau.sources td { padding-right: 16px; }
.tableau.sources td.chance { font-weight: 600; padding-right: 16px; }

/* Outils de page */
.outils-page { display: flex; gap: 8px; margin: -4px 0 4px; }
.effet .sous-titre { border-top: none; padding-top: 0; }
