/* ==== Thèmes ==== */
:root,
html[data-theme="dark"] {
  --fond: #14162b;
  --fond-2: #1e2140;
  --carte: #252a4d;
  --texte: #eef0ff;
  --texte-2: #9aa0c7;
  --accent: #f5c542;        /* lune */
  --accent-texte: #1a1a1a;
  --vert: #3ecf8e;
  --rouge: #e5484d;
  --jaune: #f5c542;
  --bordure: #34396b;
}
html[data-theme="light"] {
  --fond: #f4f5fb;
  --fond-2: #ffffff;
  --carte: #ffffff;
  --texte: #1c1e33;
  --texte-2: #5a5f85;
  --accent: #d99a00;
  --accent-texte: #ffffff;
  --vert: #14804a;
  --rouge: #c62828;
  --jaune: #b58900;
  --bordure: #d8dbef;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* ==== Header ==== */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  background: var(--fond-2);
  border-bottom: 1px solid var(--bordure);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 {
  flex: 1;
  font-size: 1.15rem;
  text-align: center;
}
.btn-icone {
  min-width: 48px;
  min-height: 48px;
  font-size: 1.3rem;
  background: none;
  border: none;
  color: var(--texte);
  cursor: pointer;
  border-radius: 12px;
}
.btn-icone:active { background: var(--carte); }

/* ==== Écrans ==== */
main { flex: 1; overflow-y: auto; }
.ecran { display: none; min-height: 100%; }
.ecran.actif { display: block; }

/* ==== Accueil ==== */
.accueil {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 24px;
  text-align: center;
  min-height: 70vh;
}
.logo { font-size: 5rem; filter: drop-shadow(0 0 24px rgba(245, 197, 66, .35)); }
.accueil h2 { font-size: 1.6rem; }
.sous-titre { color: var(--texte-2); margin-bottom: 18px; }

.btn {
  width: 100%;
  max-width: 340px;
  min-height: 56px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  padding: 0 18px;
}
.btn-principal { background: var(--accent); color: var(--accent-texte); }
.btn-secondaire {
  background: var(--carte);
  color: var(--texte);
  border: 1px solid var(--bordure);
}
.btn:active { transform: scale(.98); }

/* ==== Onglets ==== */
.onglet { display: none; padding: 16px; }
.onglet.actif { display: block; }

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 56px 20px;
  color: var(--texte-2);
}
.placeholder-icone { font-size: 3rem; }
.placeholder h3 { color: var(--texte); }

/* ==== Navigation basse ==== */
.nav-bas {
  display: flex;
  background: var(--fond-2);
  border-top: 1px solid var(--bordure);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-bas.cachee { display: none; }
.nav-btn {
  flex: 1;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 1.2rem;
  background: none;
  border: none;
  color: var(--texte-2);
  cursor: pointer;
}
.nav-btn span { font-size: .68rem; font-weight: 600; }
.nav-btn.actif { color: var(--accent); }

.cachee { display: none; }

/* ==== Statut serveur (accueil) ==== */
.statut-serveur { font-size: .85rem; color: var(--texte-2); margin-top: 6px; }
.statut-serveur.ok { color: var(--vert); }
.statut-serveur.erreur { color: var(--rouge); }

/* ==== Formulaires ==== */
.formulaire {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 36px 24px;
  text-align: center;
}
.champ {
  width: 100%;
  max-width: 340px;
  text-align: left;
  font-size: .9rem;
  color: var(--texte-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.champ input {
  min-height: 52px;
  padding: 0 14px;
  font-size: 1.05rem;
  border-radius: 12px;
  border: 1px solid var(--bordure);
  background: var(--carte);
  color: var(--texte);
}
.champ input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.champ-code {
  text-transform: uppercase;
  letter-spacing: .35em;
  font-weight: 700;
  text-align: center;
}
.message-erreur { color: var(--rouge); font-size: .9rem; max-width: 340px; }

/* ==== Carte partie (code + QR) ==== */
.carte {
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 16px;
  padding: 18px;
}
.carte-partie {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.libelle { color: var(--texte-2); font-size: .85rem; }
.code-partie {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: .3em;
  color: var(--accent);
}
.code-inline { color: var(--accent); letter-spacing: .15em; }
.qr-partie img { border-radius: 8px; background: #fff; padding: 6px; }

/* ==== Listes de joueurs ==== */
.titre-liste { margin: 18px 4px 8px; font-size: 1rem; }
.liste-joueurs { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.joueur-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
}
.joueur-item.vide { color: var(--texte-2); font-size: .9rem; }
.joueur-avatar { font-size: 1.2rem; }
.joueur-nom { flex: 1; font-weight: 600; }
.joueur-etat {
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.joueur-etat.vert { background: var(--vert); color: #fff; }
.joueur-etat.jaune { background: var(--jaune); color: #1a1a1a; }
.joueur-etat.rouge { background: var(--rouge); color: #fff; }
.joueur-role { font-size: .8rem; color: var(--texte-2); }

/* ==== Composition (narrateur) ==== */
.bloc-composition { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.compo-lignes { display: flex; flex-direction: column; gap: 8px; }
.compo-ligne { display: flex; align-items: center; gap: 10px; }
.compo-nom { flex: 0 0 90px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.compo-ligne select {
  flex: 1;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--bordure);
  background: var(--fond-2);
  color: var(--texte);
  font-size: .95rem;
  padding: 0 8px;
}
.rangee-boutons { display: flex; gap: 10px; }
.rangee-boutons .btn { min-height: 48px; font-size: .95rem; }
.message-info { font-size: .9rem; color: var(--texte-2); }

/* ==== Carte « Mon rôle » (joueur) ==== */
.carte-role {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  margin: 24px auto 0;
  max-width: 340px;
  padding: 28px 22px;
  background: var(--carte);
  border: 2px solid var(--accent);
  border-radius: 20px;
}
.carte-role.cachee { display: none; }
.role-emoji { font-size: 4.5rem; }
.role-description { color: var(--texte-2); }
.role-secret { font-size: .85rem; color: var(--jaune); font-weight: 600; }
@keyframes apparition-role {
  from { transform: scale(.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.animation-role { animation: apparition-role .5s ease; }

/* ==== Trame (narrateur) ==== */
.trame-progression { margin: 4px 4px 10px; }
.carte-etape { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.carte-etape h2 { font-size: 1.35rem; }
.etape-joueurs { color: var(--accent); font-weight: 600; font-size: .95rem; }
.etape-action { display: flex; flex-direction: column; gap: 10px; }
.action-cibles { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--bordure);
  background: var(--fond-2);
  color: var(--texte);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.actif { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
.champ-note {
  min-height: 48px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--bordure);
  background: var(--fond-2);
  color: var(--texte);
}
.case-cocher { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--texte-2); }
.case-cocher input { width: 20px; height: 20px; }

/* ==== Bandeaux joueur ==== */
.bandeau-phase {
  margin: -16px -16px 16px;
  padding: 12px 16px;
  text-align: center;
  font-weight: 700;
  background: var(--fond-2);
  border-bottom: 1px solid var(--bordure);
}
.bandeau-phase.nuit { background: #1a1d3f; color: #cdd3ff; }
.bandeau-phase.jour { background: var(--jaune); color: #1a1a1a; }
.bandeau-phase.cachee { display: none; }
.bandeau-mort {
  margin: 0 0 14px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--rouge);
  color: #fff;
  font-weight: 600;
  text-align: center;
}
.bandeau-mort.cachee { display: none; }
.joueur-mort { opacity: .55; }

/* ==== Votes ==== */
.carte-nouveau-vote { display: flex; flex-direction: column; gap: 12px; }
.carte-nouveau-vote select, .carte-nouveau-vote textarea {
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--bordure);
  background: var(--fond-2);
  color: var(--texte);
  font-size: .95rem;
  padding: 8px;
}
.carte-vote { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.vote-entete { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.vote-decompte { display: flex; flex-direction: column; gap: 6px; }
.vote-ligne {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--fond-2);
  border: 1px solid var(--bordure);
  font-size: .95rem;
}
.vote-ligne.tete { border-color: var(--accent); }
.vote-nb { font-weight: 800; color: var(--accent); }

/* Résultats esthétiques (barres animées) */
.resultat-ligne {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
}
.resultat-ligne.gagnant {
  border-color: var(--accent);
  background: rgba(245, 197, 66, .10);
}
.resultat-entete {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .95rem;
  font-weight: 600;
}
.resultat-nb { color: var(--accent); font-weight: 800; white-space: nowrap; }
.resultat-barre {
  height: 10px;
  border-radius: 999px;
  background: var(--fond-2);
  border: 1px solid var(--bordure);
  overflow: hidden;
}
.resultat-remplissage {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  animation: barre-pousse .8s cubic-bezier(.25, 1, .35, 1);
}
@keyframes barre-pousse {
  from { width: 0; }
}
.gagnant .resultat-remplissage {
  background: linear-gradient(90deg, var(--accent), #ffdf7e);
}
.resultat-detail { font-size: .78rem; color: var(--texte-2); }

/* ==== Timer de débat ==== */
.timer-affichage {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  padding: 6px 0;
}
.timer-affichage.fini { color: var(--rouge); animation: clignote 1s infinite; }
.timer-affichage.cachee { display: none; }
@keyframes clignote { 50% { opacity: .35; } }

/* ==== Point de notification (onglets) ==== */
.nav-btn { position: relative; }
.point-notif {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rouge);
}
.point-notif.cachee { display: none; }
.btn-danger { background: var(--rouge); color: #fff; }

/* ==== Fiche joueur (modale narrateur) ==== */
.voile {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.voile.cachee { display: none; }
.fiche {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--fond);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--bordure);
  padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.fiche-entete { display: flex; align-items: center; justify-content: space-between; }
.fiche-section { display: flex; flex-direction: column; gap: 8px; }
.fiche select {
  flex: 1;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--bordure);
  background: var(--fond-2);
  color: var(--texte);
  padding: 0 8px;
}
.liste-pouvoirs { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.liste-pouvoirs li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--fond-2);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .9rem;
}
.btn-mini {
  background: none;
  border: none;
  color: var(--rouge);
  font-size: 1rem;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
}

/* ==== Casiers / conversations ==== */
.conversation { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.fil-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 45vh;
  overflow-y: auto;
  padding: 4px 0;
}
.bulle {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: .95rem;
  line-height: 1.35;
}
.bulle-moi { align-self: flex-end; background: var(--accent); color: var(--accent-texte); }
.bulle-autre { align-self: flex-start; background: var(--fond-2); border: 1px solid var(--bordure); }
.rangee-envoi { display: flex; gap: 8px; }
.rangee-envoi .champ-note { flex: 1; }
.btn-envoyer { flex: 0 0 auto; width: auto; min-width: 56px; }
.role-etats:empty, .liste-pouvoirs:empty { display: none; }

/* ==== Victoire + journal ==== */
.alerte-victoire {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-color: var(--jaune);
  margin-bottom: 14px;
}
.alerte-victoire.cachee { display: none; }
.journal-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 10px 14px;
}
.journal-meta { font-size: .72rem; color: var(--texte-2); }
.journal-texte { font-size: .95rem; }
#journal-filtre-type {
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--bordure);
  background: var(--fond-2);
  color: var(--texte);
  padding: 0 8px;
}

/* ==== Hors ligne + illustrations ==== */
.bandeau-offline {
  background: var(--rouge);
  color: #fff;
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  padding: 8px 12px;
}
.bandeau-offline.cachee { display: none; }
.role-image {
  max-width: 200px;
  max-height: 200px;
  border-radius: 14px;
  object-fit: cover;
}
.role-image.cachee { display: none; }
.role-recap {
  background: var(--fond-2);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  font-size: .92rem;
}
.role-recap.cachee { display: none; }
.role-recap-titre { font-weight: 700; color: var(--accent); margin-bottom: 4px; font-size: .85rem; }
