/* Thème : changez ces variables pour modifier tout l'aspect de la feuille. */
:root {
  --fond: #17130e;            /* fond de page */
  --papier: #241d15;          /* fond des sections */
  --papier-clair: #2f261b;    /* fond des champs */
  --entete-tableau: #392e20;  /* fond des en-têtes de tableau */
  --encre: #eadfc8;           /* texte principal */
  --encre-douce: #b3a689;     /* texte secondaire, étiquettes */
  --bordure: #4a3c2a;
  --accent: #c9a45c;          /* or : titres, onglet actif, boutons, mention « Équipé », barre d'XP */
  --accent-texte: #1a140c;    /* texte sur fond doré */
  --mj: #c0604f;              /* repère des champs réservés au MJ */
  --calc: #8fc9ae;            /* valeurs calculées automatiquement */
  --calc-fond: #1c2a24;
  --negatif: #e07a5f;         /* modificateur négatif */
  --negatif-fond: #3a1f1a;
  --nul: #9a958c;             /* modificateur à 0 */
  --vie: #5fae5a;             /* barre de PV */
  --mana: #4f8fd6;            /* barre de filiés, points de vie restants (mort) */
  --dette: #c94a3d;           /* barre de dette */
  --point-perdu: #5a544b;     /* point gris (vie perdue) */
  --poids: #8a8378;           /* barre de poids (hachures) */
  --poids-clair: #5f5a52;
  --maudit: #9b59b6;          /* part inutilisable (malédiction) */
  --alerte: #e07a5f;
  --ok: #8fc9ae;
  --police-titres: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --police-texte: Georgia, "Times New Roman", serif;
  --rayon: 6px;
  --espace: 1rem;
  color-scheme: dark; /* listes déroulantes et contrôles natifs en sombre */
}
option { background: var(--papier-clair); color: var(--encre); }

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

body {
  margin: 0;
  background: var(--fond);
  color: var(--encre);
  font: 16px/1.45 var(--police-texte);
}

h1, h2, h3 { font-family: var(--police-titres); color: var(--accent); font-weight: normal; margin: 0 0 .6em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.5rem; border-bottom: 1px solid var(--bordure); padding-bottom: .3em; }
h3 { font-size: 1.1rem; margin-top: 1.4em; }

/* ---------- Barre du haut ---------- */
.barre {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .8rem var(--espace);
  border-bottom: 1px solid var(--bordure);
  background: var(--papier);
}
.barre h1 { margin: 0; }
.vue { font-size: .8rem; color: var(--mj); border: 1px solid var(--mj); border-radius: 99px; padding: .05em .6em; vertical-align: middle; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
#etat-sauvegarde { font-size: .9rem; margin-left: .3rem; }
#etat-sauvegarde.ok { color: var(--ok); }
#etat-sauvegarde.erreur, .erreur { color: var(--alerte); }

#message { margin: .6rem var(--espace); padding: .6rem .8rem; border-radius: var(--rayon); background: var(--papier-clair); border: 1px solid currentColor; }
#message.ok { color: var(--ok); }

/* ---------- Boutons ---------- */
button, .bouton {
  font: inherit; font-size: .95rem; cursor: pointer;
  color: var(--accent-texte); background: var(--accent);
  border: 0; border-radius: var(--rayon); padding: .4em .8em;
  display: inline-block;
}
button:hover, .bouton:hover { filter: brightness(1.1); }
button:focus-visible, .bouton:focus-within, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.bouton-mj { background: transparent; color: var(--encre); border: 1px solid var(--mj); }
.suppr { background: transparent; color: var(--encre-douce); padding: .2em .5em; }
.suppr:hover { color: var(--alerte); }
[data-ajout] { margin-top: .5rem; background: transparent; color: var(--accent); border: 1px dashed var(--accent); }

/* ---------- Onglets ---------- */
.onglets {
  display: flex; gap: .25rem; overflow-x: auto;
  padding: .6rem var(--espace) 0;
  border-bottom: 1px solid var(--bordure);
}
.onglets button {
  background: transparent; color: var(--encre-douce); white-space: nowrap;
  border-radius: var(--rayon) var(--rayon) 0 0; padding: .45em .8em;
}
.onglets button[aria-selected="true"] { background: var(--papier); color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: var(--espace); }
.panneau { background: var(--papier); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: var(--espace); }

/* ---------- Champs ---------- */
/* Intitulé (+ badge) sur une ligne, champ en dessous sur toute la largeur : les cases d'une rangée restent alignées */
label, .case {
  display: flex; flex-wrap: wrap; align-items: center; align-content: flex-start; gap: .2rem .4rem;
  color: var(--encre-douce); font-size: .9rem; margin-bottom: .7rem;
}
label > input:not([type="radio"]), label > select, label > textarea, .case > output, .case > .points { flex: 1 0 100%; }
input, select, textarea, .valeur {
  font: inherit; font-size: 1rem; color: var(--encre);
  background: var(--papier-clair); border: 1px solid var(--bordure); border-radius: var(--rayon);
  padding: .4em .5em; width: 100%; min-width: 0;
}
.valeur { display: block; min-height: 2.3em; }
textarea { resize: vertical; min-height: 4.5em; field-sizing: content; }
textarea.grand { min-height: 9em; }
.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 var(--espace); }
.aide { color: var(--encre-douce); font-size: .9rem; }
fieldset { border: 1px solid var(--bordure); border-radius: var(--rayon); margin: 0 0 .7rem; padding: .3rem .8rem; }
legend { color: var(--encre-douce); font-size: .9rem; padding: 0 .3rem; }
.radio { display: inline-flex; flex-wrap: nowrap; margin: 0 1.2rem 0 0; color: var(--encre); font-size: 1rem; }
.radio input { width: auto; accent-color: var(--accent); }

/* Champs réservés au MJ : contour rouge seulement + badge */
.mj input, .mj select, .mj textarea, .mj .valeur { border-color: var(--mj); }
.badge-mj {
  display: inline-block; font-family: var(--police-texte); font-size: .7rem; letter-spacing: .03em; line-height: 1.4;
  color: var(--encre); background: var(--mj); border-radius: 99px; padding: 0 .55em;
}
.zone-mj { border-color: var(--mj); }
/* Mode serveur : écran de connexion, liste des fiches (MJ) */
.serveur { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem; width: 100%; }
.serveur label { margin: 0; flex-direction: row; align-items: center; }
.serveur select { width: auto; max-width: 16rem; }
#compte { color: var(--encre-douce); font-size: .9rem; margin-left: auto; }
.connexion { max-width: 380px; margin: 2rem auto; padding: var(--espace); background: var(--papier); border: 1px solid var(--bordure); border-radius: var(--rayon); }
body[data-ecran] .onglets, body[data-ecran] main, body[data-ecran] .actions { display: none !important; }
body[data-mode="serveur"] #btn-reset { display: none; }
body[data-vue="joueur"] .mj-seul { display: none !important; }
.joueur-seul { display: none; }
body[data-vue="joueur"] .joueur-seul { display: inline; }
/* Vue joueur : pas d'Espace MJ (ni à l'écran ni à l'impression) */
body[data-vue="joueur"] #mj, body[data-vue="joueur"] [data-onglet="mj"] { display: none !important; }
body[data-vue="joueur"] .vue { color: var(--accent); border-color: var(--accent); }

/* Valeurs calculées : fond vert sombre, bordure pointillée */
.calc {
  display: block; color: var(--calc); background: var(--calc-fond);
  border: 1px dashed var(--calc); border-radius: var(--rayon);
  padding: .4em .5em; font-weight: bold; min-height: 2.3em;
}
.calc.alerte { color: var(--alerte); border-color: var(--alerte); }
.calc.negatif { color: var(--negatif); border-color: var(--negatif); background: var(--negatif-fond); }
.calc.nul { color: var(--nul); border-color: var(--nul); background: var(--papier-clair); }

/* ---------- Barres (PV, filiés / dette, XP) ---------- */
.jauge { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .5rem; color: var(--encre-douce); font-size: .9rem; margin-bottom: .8rem; }
.jauge output { color: var(--encre); }
.barre-fond { flex: 1 0 100%; height: 14px; background: var(--papier-clair); border: 1px solid var(--bordure); border-radius: 99px; overflow: hidden; margin-top: .2rem; }
.barre-remplie { height: 100%; width: 0; transition: width .3s; }
[data-jauge="pv"] { background: var(--vie); }
[data-jauge="filies"] { background: var(--mana); }
[data-jauge="filies"].dette { background: var(--dette); }
[data-jauge="xp"] { background: var(--accent); }
/* poids porté : gris hachuré */
[data-jauge="poids"] { background: repeating-linear-gradient(45deg, var(--poids) 0 6px, var(--poids-clair) 6px 12px); }
[data-jauge="poids"].surcharge { background: repeating-linear-gradient(45deg, var(--alerte) 0 6px, var(--dette) 6px 12px); }
/* part de barre rendue inutilisable par une malédiction */
.barre-fond { position: relative; }
.barre-maudite {
  position: absolute; top: 0; right: 0; height: 100%;
  background: repeating-linear-gradient(-45deg, var(--maudit) 0 4px, transparent 4px 8px);
  border-left: 2px solid var(--maudit);
}
.jauge-dette { display: grid; grid-template-columns: 1fr minmax(160px, 220px); gap: 0 var(--espace); align-items: start; }

.montee {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .7rem .9rem; margin-bottom: var(--espace);
  border: 1px solid var(--accent); border-radius: var(--rayon); color: var(--accent);
}
.recharge { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.recharge .calc { flex: 1 1 200px; }

/* ---------- Mort : points bleus ---------- */
.points { display: flex; gap: .5rem; padding: .3rem 0; }
.point { width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--point-perdu); }
.point.vivant { background: var(--mana); }

/* ---------- Identité ---------- */
.identite-haut { display: grid; grid-template-columns: 180px 1fr; gap: var(--espace); }
.portrait { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.portrait img, #portrait-vide {
  width: 160px; height: 200px; object-fit: cover;
  border: 1px solid var(--bordure); border-radius: var(--rayon); background: var(--papier-clair);
}
#portrait-vide { display: flex; align-items: center; justify-content: center; color: var(--encre-douce); font-size: .9rem; }

/* ---------- Statistiques ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--espace); }
.stat { text-align: center; border: 1px solid var(--bordure); border-radius: var(--rayon); padding: .6rem; }
.stat label { justify-content: center; margin-bottom: .4rem; color: var(--encre); }
.stat input { text-align: center; font-size: 1.3rem; }
.stat .calc { margin-top: .4rem; font-size: 1.3rem; }

/* ---------- Tableaux (style commun) ---------- */
.defile { overflow-x: auto; }
.liste { width: 100%; border-collapse: collapse; border: 1px solid var(--bordure); }
.liste th {
  text-align: left; color: var(--encre); font-weight: normal; font-size: .85rem;
  background: var(--entete-tableau); padding: .4rem .5rem; border: 1px solid var(--bordure);
}
.liste td { border: 1px solid var(--bordure); padding: 0; vertical-align: top; }
.liste td input, .liste td textarea, .liste td select { border: 0; border-radius: 0; background: transparent; outline: none; }
.liste td textarea { min-height: 2.4em; }
/* repère de sélection sur toute la case, quelle que soit la hauteur de la ligne */
.liste td:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.liste td.texte, .liste td.vide { padding: .45rem .5rem; }
.liste td.vide { color: var(--encre-douce); font-style: italic; }
.liste input[type="number"] { min-width: 5rem; }
.liste td input { min-width: 7rem; }
.col-suppr { width: 2.5rem; text-align: center; }
.liste tr.equipe td:first-child::after {
  content: "Équipé"; display: inline-block; margin: 0 0 .35rem .5rem;
  font-size: .7rem; color: var(--accent-texte); background: var(--accent); border-radius: 99px; padding: 0 .5em;
}
#bord-equipement select { min-width: 7rem; }
.bloc .liste td, .bloc .liste th { font-size: .85rem; }
.filtre { max-width: 260px; }

/* ---------- Tableau de bord ---------- */
.bord {
  display: grid; gap: var(--espace);
  grid-template-columns: 170px minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "stats id     barres barres"
    "stats equip  quetes quetes"
    "stats equip  notes  etats";
}
.bloc { border: 1px solid var(--bordure); border-radius: var(--rayon); padding: .8rem; min-width: 0; }
.bloc h3 { margin-top: 0; }
.bloc h3 ~ h3 { margin-top: 1rem; }
.bord-id { grid-area: id; }
.bord-barres { grid-area: barres; }
.bord-stats { grid-area: stats; }
.bord-equip { grid-area: equip; }
.bord-quetes { grid-area: quetes; }
.bord-notes { grid-area: notes; }
.bord-etats { grid-area: etats; }
.bord-notes label { margin: 0; }
.nom-perso { font-family: var(--police-titres); font-size: 1.5rem; color: var(--encre); margin: 0 0 .3rem; }
.niveau-perso { margin: 0; color: var(--encre-douce); font-size: .9rem; }
.mini-stat { display: grid; grid-template-columns: 1fr auto 3rem; align-items: center; gap: .4rem; font-size: .85rem; margin-bottom: .4rem; color: var(--encre-douce); }
.mini-stat strong { color: var(--encre); }
.mini-stat .calc { padding: .1em .3em; min-height: 0; text-align: center; }

/* ---------- Cartes ---------- */
.dossier { margin-top: var(--espace); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: .5rem .8rem .8rem; }
.dossier summary { cursor: pointer; font-family: var(--police-titres); color: var(--accent); font-size: 1.1rem; padding: .2rem 0; }
.cartes-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--espace); margin-top: .5rem; }
.carte { margin: 0; min-width: 0; }
.carte figcaption { color: var(--encre); font-size: .9rem; margin-bottom: .3rem; overflow-wrap: anywhere; }
.carte img {
  display: block; width: 100%; height: 150px; object-fit: contain;
  background: var(--papier-clair); border: 1px solid var(--bordure); border-radius: var(--rayon);
}
.carte-erreur { color: var(--alerte); margin: 0; font-size: .9rem; }

/* ---------- Dés ---------- */
.des-boutons { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: var(--espace); }
.des-boutons button { min-width: 3.5rem; }
.formule { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; }
.formule label { flex: 1 1 200px; margin-bottom: 0; }
.resultat { margin-top: var(--espace); font-size: 1.1rem; }
.journal-des { padding-left: 2rem; color: var(--encre-douce); }
.journal-des li:first-child { color: var(--encre); }

/* ---------- Tablette et téléphone ---------- */
@media (max-width: 900px) {
  .bord {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "id id" "barres barres" "stats equip" "quetes quetes" "etats etats" "notes notes";
  }
}
@media (max-width: 600px) {
  .identite-haut { grid-template-columns: 1fr; }
  .bord { grid-template-columns: 1fr; grid-template-areas: "id" "barres" "stats" "equip" "quetes" "etats" "notes"; }
  .jauge-dette { grid-template-columns: 1fr; }
  h1 { font-size: 1.15rem; }
  main { padding: .5rem; }
}

/* ---------- Impression / PDF ---------- */
@media print {
  @page { margin: 12mm; }
  :root {
    --fond: #fff; --papier: #fff; --papier-clair: #fff; --entete-tableau: #eee; --encre: #000; --encre-douce: #444;
    --bordure: #999; --accent: #000; --accent-texte: #fff; --mj: #8a2b1c; --calc: #000; --calc-fond: #eee; --negatif-fond: #eee;
    color-scheme: light;
  }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  body { font-size: 11pt; }
  .barre, .onglets, #message, #des, button, .bouton, .col-suppr, .aide, .montee, .filtre { display: none !important; }
  .panneau[hidden] { display: block !important; }
  main { max-width: none; padding: 0; }
  .panneau { border: 0; padding: 0; margin-bottom: 6mm; }
  #bord { break-after: page; }
  h2, h3 { break-after: avoid; }
  label, .case, .stat, tr, .jauge, .bord-id, .bord-barres { break-inside: avoid; }
  input:not([type="radio"]), select, textarea, .valeur { border: 0; border-bottom: 1px solid var(--bordure); border-radius: 0; padding: .1em 0; appearance: none; }
  .mj input, .mj select, .mj textarea, .mj .valeur { border-bottom-color: var(--mj); }
  .defile { overflow: visible; }
  .carte { break-inside: avoid; }
  .carte img { height: 6cm; }
  #bord-equipement select { min-width: 0; }
  textarea, textarea.grand { min-height: 0; resize: none; }
  .liste td input, .liste td textarea, .liste td select { border: 0; padding: .3em .4em; }
  .calc { border: 0; padding: .1em .3em; min-height: 0; }
  .badge-mj { color: var(--mj); background: none; border: 1px solid var(--mj); }
  .portrait img { border: 0; }
  #portrait-vide { display: none !important; }
}
