:root {
  --fond: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --bord: #d7dad3;
  --texte: #1d211c;
  --texte-2: #5b6258;
  --accent: #2f7a46;
  --accent-texte: #ffffff;
  --vert: #24803f;
  --bleu: #2a62b8;
  --orange: #b86a12;
  --rouge: #c0392b;
  --gris: #7b8279;
  --magenta: #9b3fa3;
  --journal-fond: #171a16;
  --journal-texte: #d9ded6;
  --ombre: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #121411;
    --surface: #1b1e1a;
    --surface-2: #242822;
    --bord: #33382f;
    --texte: #e4e8e1;
    --texte-2: #9aa297;
    --accent: #4fa86a;
    --accent-texte: #0d130e;
    --vert: #5cc27a;
    --bleu: #6fa1ec;
    --orange: #e3a04f;
    --rouge: #ec7466;
    --gris: #8d958a;
    --magenta: #d08ad6;
    --journal-fond: #0c0e0b;
    --journal-texte: #d9ded6;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* hidden doit gagner sur les display: flex/grid poses plus bas. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin-bottom: .6rem; }

button, .bouton {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: .45rem .85rem;
  background: var(--accent);
  color: var(--accent-texte);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
}
button:hover:not(:disabled), .bouton:hover { filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondaire, .bouton.secondaire {
  background: var(--surface);
  color: var(--texte);
  border-color: var(--bord);
}
button.lien {
  background: none;
  color: var(--accent);
  padding: .2rem .3rem;
  font-weight: 500;
}
button.lien.danger { color: var(--rouge); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select {
  font: inherit;
  color: var(--texte);
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 6px;
  padding: .45rem .6rem;
  width: 100%;
  min-width: 0;
}
input:disabled { opacity: .6; }

label { display: block; font-size: .85rem; font-weight: 600; margin: .5rem 0 .25rem; }
label.discret { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin: 0; color: var(--texte-2); }
label.discret select { width: auto; padding: .25rem .4rem; }
label.case { display: inline-flex; align-items: center; gap: .35rem; }
label.case input { width: auto; }

.aide { color: var(--texte-2); font-size: .82rem; font-weight: 400; }
.vide { color: var(--texte-2); padding: .75rem; }

.carte {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--ombre);
}

/* ------------------------------------------------------------- connexion */

.page-connexion {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 16px;
}
.carte-connexion .intro { margin: -.5rem 0 1rem; }
.pied {
  color: var(--texte-2);
  font-size: .8rem;
  text-align: center;
  padding: .5rem 16px 1.5rem;
}
.carte-connexion { width: min(360px, 100%); text-align: center; padding: 2rem 1.5rem; }
.carte-connexion h1 { font-size: 1.3rem; margin: .5rem 0 1.25rem; }
.carte-connexion form { text-align: left; }
.carte-connexion button { width: 100%; justify-content: center; margin-top: 1rem; }
.logo { border-radius: 8px; }
.message-erreur { color: var(--rouge); font-size: .9rem; margin: .75rem 0 0; }

/* ----------------------------------------------------------------- entete */

.entete {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--bord);
  flex-wrap: wrap;
}
.marque { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.marque img { border-radius: 5px; }
.cible {
  background: var(--surface-2);
  color: var(--texte);
  border-color: var(--bord);
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cible-libelle { color: var(--texte-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.cible.cible-vide { border-color: var(--orange); color: var(--orange); }
.entete-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.resume { color: var(--texte-2); font-size: .88rem; }

.bandeau-flux {
  background: var(--orange);
  color: #fff;
  padding: .4rem 16px;
  font-size: .9rem;
}

/* ------------------------------------------------------------------ grille */

.grille {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 860px) {
  .grille { grid-template-columns: minmax(0, 1fr); }
  .entete-actions { margin-left: 0; width: 100%; justify-content: space-between; }
}

.titre-section { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .6rem; }

/* -------------------------------------------------------------------- PNJ */

.liste-pnj { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.pnj {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 10px;
  padding: .7rem .8rem;
  cursor: pointer;
  box-shadow: var(--ombre);
}
.pnj.choisi { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pnj-tete { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.pseudo { color: var(--texte-2); font-size: .9rem; }
.pnj-tete .etat { margin-left: auto; font-size: .82rem; font-weight: 600; }
.pnj-email, .pnj-info { color: var(--texte-2); font-size: .82rem; overflow-wrap: anywhere; }
.pnj-detail { font-size: .82rem; margin-top: .3rem; overflow-wrap: anywhere; }
.pnj-actions { display: flex; gap: .4rem; margin-top: .55rem; align-items: center; }
.pnj-actions button { padding: .3rem .7rem; font-size: .88rem; }
.pnj-actions .lien { margin-left: auto; }
.pnj-actions .lien + .lien { margin-left: 0; }

.pastille { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--gris); }
.pastille.vert { background: var(--vert); }
.pastille.bleu { background: var(--bleu); }
.pastille.orange { background: var(--orange); }
.pastille.rouge { background: var(--rouge); }
.etat.vert, .pnj-detail.vert { color: var(--vert); }
.etat.bleu, .pnj-detail.bleu { color: var(--bleu); }
.etat.orange, .pnj-detail.orange { color: var(--orange); }
.etat.rouge, .pnj-detail.rouge { color: var(--rouge); }
.etat.gris, .pnj-detail.gris { color: var(--texte-2); }

.form-ajout button { margin-top: .8rem; }
.form-ajout .aide { margin: .6rem 0 0; }

/* ------------------------------------------------------------ code Microsoft */

#zone-codes { display: grid; gap: 10px; margin-bottom: 12px; }
#zone-codes:empty { display: none; }
.code-ms { border-color: var(--orange); }
.code-tete { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.code-ligne { display: flex; align-items: center; gap: .6rem; margin: .7rem 0; flex-wrap: wrap; }
.code {
  font: 700 1.6rem/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  letter-spacing: .12em;
  background: var(--surface-2);
  padding: .4rem .7rem;
  border-radius: 6px;
  user-select: all;
}
.code-ms .aide { margin: 0; }

/* ----------------------------------------------------------------- journal */

.barre-journal { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.barre-journal h2 { margin-right: auto; }

.journal {
  background: var(--journal-fond);
  color: var(--journal-texte);
  border-radius: 10px;
  height: min(55vh, 600px);
  min-height: 280px;
  overflow: auto;
  padding: .6rem .2rem;
  font: 12.5px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.journal .vide { color: #8d958a; }
.ligne { display: flex; gap: .6rem; padding: 0 .6rem; }
.ligne:hover { background: rgb(255 255 255 / 4%); }
.ligne .heure { color: #7c8579; flex: none; }
.ligne .bot { color: #9fc2e6; flex: none; min-width: 5ch; }
.ligne .type { color: #7c8579; flex: none; width: 9ch; overflow: hidden; text-overflow: ellipsis; }
.ligne .texte { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.type-chat .texte { color: #e7a8ec; }
.type-titre .texte, .type-barre .texte { color: #c9a5e0; }
.type-envoye .texte { color: #8fd3ff; }
.type-erreur .texte, .type-expulsion .texte, .type-refus .texte, .type-stderr .texte { color: #ff8f80; }
.type-etat .texte { color: #a9e2b6; }
.type-auth .texte { color: #ffc77a; }
.type-pack .texte { color: #e8d48a; }
.type-phase .texte, .type-paquet .texte, .type-sortie .texte { color: #8d958a; }
.type-action .texte, .type-acces .texte { color: #c2c8bf; font-style: italic; }

@media (max-width: 600px) {
  .ligne { flex-wrap: wrap; gap: 0 .5rem; }
  .ligne .texte { flex-basis: 100%; }
}

.form-chat { display: flex; gap: .5rem; margin-top: .6rem; }

.barre-export { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; }
.export-titre { display: flex; flex-direction: column; margin-right: auto; }
.export-options { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

/* ------------------------------------------------------------------- dialog */

dialog {
  color: var(--texte);
  width: min(520px, calc(100vw - 32px));
  padding: 1.25rem;
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h3 + .ligne-champs, dialog h3 { margin-top: .4rem; }
dialog h3:not(:first-child) { margin-top: 1.2rem; }
.ligne-champs { display: flex; gap: .75rem; }
.ligne-champs > div { flex: 1 1 0; min-width: 0; }
.ligne-champs > .champ-large { flex: 2.2 1 0; }
.actions-dialog { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
dialog .aide { margin: .4rem 0 0; }

/* -------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--texte);
  color: var(--fond);
  padding: .6rem 1rem;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
  font-size: .92rem;
  z-index: 10;
}
.toast-erreur { background: var(--rouge); color: #fff; }

/* ---------------------------------------------------------------- pilotage */

.pilotage { margin-bottom: 12px; }
.pilotage-tete { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.objectif {
  background: var(--surface-2);
  border: 1px solid var(--bord);
  border-radius: 999px;
  padding: .1rem .6rem;
  font-size: .82rem;
  color: var(--bleu);
}
.tele {
  font: 12.5px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: var(--texte-2);
  margin: .4rem 0 .8rem;
  overflow-wrap: anywhere;
}
.pilotage-corps {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr);
  gap: 14px;
  align-items: start;
}
@media (max-width: 1100px) {
  .pilotage-corps { grid-template-columns: minmax(0, 1fr); }
}
.ecran {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #0c0e0b;
  border-radius: 8px;
  overflow: hidden;
}
.ecran iframe { width: 100%; height: 100%; border: 0; display: block; }
.vue-vide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: 1rem;
  text-align: center;
  color: #d9ded6;
}
.vue-vide p { margin: 0; }
.vue-vide .aide { color: #9aa297; max-width: 34ch; }
.vue-fermer { position: absolute; top: 8px; right: 8px; }
button.petit { padding: .25rem .6rem; font-size: .82rem; }

.commandes {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  border-radius: 8px;
  padding: .25rem;
}
.commandes:focus-visible { outline: 2px dashed var(--accent); outline-offset: 4px; }
.commandes .aide { margin: 0; }
.pave {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 240px;
  align-self: center;
  width: 100%;
}
.pave button {
  flex-direction: column;
  justify-content: center;
  gap: 0;
  font-size: 1.1rem;
  padding: .45rem 0;
  touch-action: none;
  user-select: none;
}
.pave small, .commandes button small { font-size: .7rem; font-weight: 500; opacity: .75; }
.rang { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.rang button { padding: .35rem .65rem; touch-action: none; user-select: none; }
.rang input[type=number] { width: 4.6rem; flex: 1 1 3.5rem; padding: .35rem .45rem; }
.rang select { width: auto; flex: 1 1 8rem; padding: .35rem .45rem; }
.etiquette { min-width: 4.2rem; font-weight: 600; }
button.enfonce { filter: brightness(.82); box-shadow: inset 0 2px 4px rgb(0 0 0 / 25%); }
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
button.danger:not(.lien) { background: var(--rouge); color: #fff; }
button.plein { justify-content: center; width: 100%; }

/* Inventaire */
.inventaire { border-top: 1px solid var(--bord); margin-top: 14px; padding-top: 10px; }
.inventaire-tete { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.inventaire-tete h3 { margin: 0; font-size: 1rem; }
.inventaire-corps { display: flex; gap: 14px; flex-wrap: wrap; margin-top: .5rem; }
.inv-equipement, .inv-principal { display: flex; flex-direction: column; gap: .3rem; }
.inv-principal { flex: 1 1 320px; min-width: 0; max-width: 520px; }
.inv-grille { display: grid; gap: 4px; }
.inv-neuf { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.inv-colonne { grid-template-columns: 52px; }
.inv-case {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  width: 100%;
  max-width: 52px;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--texte);
  border: 1px solid var(--bord);
  border-radius: 6px;
  font: 600 .62rem/1.1 system-ui, sans-serif;
  text-align: center;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.inv-case.vide { color: var(--gris); font-weight: 400; }
.inv-case .nombre { position: absolute; right: 3px; bottom: 1px; font-size: .7rem; }
.inv-case .usure { position: absolute; left: 3px; right: 3px; bottom: 2px; height: 3px; border-radius: 2px; background: var(--vert); }
.inv-case.tenue { border: 2px solid var(--accent); }
.inv-case.choisie { outline: 2px solid var(--bleu); outline-offset: 1px; }
.inventaire.lecture-seule .inv-case { cursor: default; opacity: .7; }
