/* Thème sombre et chaud par défaut (cours de nuit), clair si demandé */
/* Bleu et blanc */
:root {
  color-scheme: light;
  --fond: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #e6edf8;
  --bord: #c8d5ea;
  --texte: #12244a;
  --texte-doux: #5b6c8e;
  --or: #1f5fbf;        /* bleu principal */
  --or-fonce: #164a96;
  --sur-or: #ffffff;    /* texte sur bleu */
  --rouge: #c8423a;
  --vert: #2f8a4c;
  --rayon: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fond);
  color: var(--texte);
  font-family: "EB Garamond", Garamond, Georgia, serif;
  font-size: 18px;
  line-height: 1.45;
}
h1, h2 { font-family: "Cinzel", serif; font-weight: 700; letter-spacing: .04em; margin: 0; }
[hidden] { display: none !important; }

.btn {
  font: inherit; font-size: 16px;
  padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--bord); background: var(--surface-2); color: var(--texte);
  cursor: pointer;
}
.btn:hover { border-color: var(--or); }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--or); outline-offset: 2px; }
.btn.principal { background: var(--or); border-color: var(--or); color: var(--sur-or); font-weight: 600; }
.btn.principal:hover { background: var(--or-fonce); }

/* Entrée */
.entree { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.carte {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--bord); border-radius: var(--rayon); padding: 32px 24px;
}
.carte h1 { color: var(--or); font-size: 30px; text-align: center; }
.sous-titre { text-align: center; color: var(--texte-doux); font-style: italic; margin: 4px 0 24px; }
label { display: block; margin-bottom: 16px; color: var(--texte-doux); font-size: 16px; }
input {
  display: block; width: 100%; margin-top: 6px; font: inherit; color: var(--texte);
  background: var(--fond); border: 1px solid var(--bord); border-radius: 8px; padding: 10px 12px;
}
.choix { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.erreur { color: var(--rouge); min-height: 1.4em; margin: 12px 0 0; }
.note { color: var(--texte-doux); font-size: 15px; margin: 8px 0 0; }

/* Salle */
.btn.large { width: 100%; margin-top: 8px; }
.salle { display: flex; flex-direction: column; min-height: 100%; padding: 12px 16px 88px; gap: 12px; }
.bandeau { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.bandeau h1 { color: var(--or); font-size: 22px; }
.compteur, .ailleurs { color: var(--texte-doux); }
.etat-connexion { color: var(--rouge); margin-left: auto; }

/* Cours au milieu, caméras sur les côtés */
.scene { display: grid; grid-template-columns: 220px minmax(0, 1fr) 220px; gap: 12px; align-items: start; }
.cote { display: flex; flex-direction: column; gap: 10px; }
.centre { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.direct { position: relative; background: #000; border-radius: var(--rayon); overflow: hidden; aspect-ratio: 16 / 9; }
.direct video { width: 100%; height: 100%; display: block; background: #000; }
.son-direct { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.info-direct { position: absolute; left: 12px; top: 8px; margin: 0; color: #ddd; font-size: 15px; pointer-events: none; }

/* Chambre : on se voit en grand, sans le cours */
.salle.en-chambre .scene { grid-template-columns: minmax(0, 1fr); }
.salle.en-chambre .cote { display: none; }
.grille-chambre { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }

.discussion {
  display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px;
}
.messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; height: 200px; }
.messages li { margin-bottom: 8px; overflow-wrap: anywhere; }
.messages .auteur { font-weight: 600; color: var(--or); }
.messages .heure { color: var(--texte-doux); font-size: 13px; margin-left: 6px; }
.messages .systeme { color: var(--texte-doux); font-style: italic; font-size: 15px; }
.messages audio { display: block; margin-top: 4px; max-width: 100%; height: 36px; }
.form-chat { display: flex; gap: 8px; margin-top: 8px; }
.form-chat input { margin: 0; flex: 1; min-width: 0; }
#btn-vocal.enregistre { background: var(--rouge); border-color: var(--rouge); color: #fff; }

.vignette {
  position: relative; aspect-ratio: 4 / 3; background: var(--surface-2);
  border-radius: var(--rayon); overflow: hidden;
}
.vignette video { width: 100%; height: 100%; object-fit: cover; display: block; }
.vignette.moi video { transform: scaleX(-1); }
.vignette.sans-camera video { visibility: hidden; }
.vignette .initiale {
  position: absolute; inset: 0; display: none; place-items: center;
  font-family: "Cinzel", serif; font-size: 42px; color: var(--or);
}
.vignette.sans-camera .initiale { display: grid; }
.vignette .etiquette {
  position: absolute; left: 6px; right: 6px; bottom: 6px; display: flex; gap: 6px; align-items: center;
  background: rgba(0,0,0,.6); color: #f3eadc; border-radius: 8px; padding: 2px 8px; font-size: 15px;
}
.vignette .etiquette .nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vignette .badge { font-size: 13px; padding: 0 6px; border-radius: 6px; background: var(--rouge); display: none; }
.vignette.muet .badge { display: inline; }

.commandes {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 10px;
  flex-wrap: wrap; padding: 12px 16px; background: var(--fond); border-top: 1px solid var(--bord);
}
#btn-micro[aria-pressed="false"], #btn-camera[aria-pressed="false"] { color: var(--rouge); }
#btn-micro[aria-pressed="true"], #btn-camera[aria-pressed="true"] { color: var(--vert); border-color: var(--vert); }
.btn.quitter { background: var(--rouge); border-color: var(--rouge); color: #fff; }

@media (max-width: 900px) {
  /* Téléphone : le cours, puis les caméras juste dessous, puis la discussion */
  .salle { padding: 8px 10px 150px; gap: 8px; }
  .bandeau h1 { font-size: 18px; }
  .scene { display: flex; flex-direction: column; gap: 8px; }
  .centre { display: contents; }
  .direct { order: 1; }
  .grille-chambre { order: 1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #cote-gauche { order: 2; }
  #cote-droit { order: 3; }
  .discussion { order: 4; }
  .cote { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .cote:empty { display: none; }
  .cote .vignette { width: calc((100% - 12px) / 3); }
  .vignette .etiquette { font-size: 13px; padding: 1px 6px; left: 4px; right: 4px; bottom: 4px; }
  .vignette .badge { display: none !important; }
  .vignette .initiale { font-size: 30px; }
  .messages { height: 150px; }
  .commandes { gap: 6px; padding: 8px 10px; }
  .btn { padding: 7px 11px; font-size: 14px; }
}


/* Bouton de l'administrateur sur chaque vignette */
.vignette .couper {
  position: absolute; top: 6px; right: 6px; font: inherit; font-size: 13px; cursor: pointer;
  background: var(--rouge); color: #fff; border: 0; border-radius: 8px; padding: 3px 8px; display: none;
}
.salle.admin .vignette:not(.moi):not(.muet) .couper { display: block; }

/* ---- Ordinateur : caméras | cours | caméras | discussion, bandeau du bas fin ---- */
.salle { padding-bottom: 60px; }
.scene { grid-template-columns: 160px minmax(0, 1fr) 160px 360px; }
.discussion { position: sticky; top: 12px; height: calc(100vh - 120px); min-height: 360px; }
.messages { flex: 1; height: auto; min-height: 0; }
.salle.en-chambre .scene, .salle.gros-plan .scene { grid-template-columns: minmax(0, 1fr) 360px; }
.salle.gros-plan .cote { display: none; }
.commandes { padding: 6px 12px; gap: 8px; }
.commandes .btn { padding: 5px 12px; font-size: 15px; }

/* Barre sous le cours : langue, gros plan, plein écran */
.barre-direct { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.barre-direct .langue { display: flex; align-items: center; gap: 8px; margin: 0 auto 0 0; font-size: 15px; color: var(--texte-doux); }
.barre-direct select {
  font: inherit; font-size: 15px; color: var(--texte); background: var(--surface);
  border: 1px solid var(--bord); border-radius: 8px; padding: 4px 8px;
}
.btn.petit { padding: 4px 12px; font-size: 15px; }
#btn-gros-plan[aria-pressed="true"] { background: var(--or); border-color: var(--or); color: var(--sur-or); }
.salle.en-chambre .barre-direct { display: none; }

@media (max-width: 900px) {
  /* Téléphone : cours, caméras, puis discussion en dessous */
  .salle { padding-bottom: 120px; }
  .barre-direct { order: 1; }
  .discussion { position: static; height: auto; min-height: 0; }
  .messages { flex: none; height: 150px; }
  .commandes { padding: 6px 8px; gap: 6px; }
  .commandes .btn { padding: 5px 10px; font-size: 14px; }
  .barre-direct .langue, .barre-direct select, .btn.petit { font-size: 14px; }
}
#btn-son-cours[aria-pressed="false"] { color: var(--rouge); }
#btn-leger[aria-pressed="true"] { background: var(--or); border-color: var(--or); color: var(--sur-or); }

/* Champ de message avec le trombone à droite */
.champ-message { position: relative; flex: 1; min-width: 0; display: flex; }
.champ-message input { margin: 0; flex: 1; min-width: 0; padding-right: 44px; }
.trombone {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%; color: var(--or); cursor: pointer;
}
.trombone:hover { background: var(--surface-2); }
.trombone:disabled { opacity: .5; cursor: wait; }
.messages .piece-jointe {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; padding: 6px 10px;
  border: 1px solid var(--bord); border-radius: 8px; background: var(--surface-2);
  color: var(--or); text-decoration: none; max-width: 100%;
}
.messages .piece-jointe:hover { border-color: var(--or); }
.messages .piece-jointe .taille { color: var(--texte-doux); font-size: 14px; white-space: nowrap; }
.messages .piece-jointe .nom-fichier { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages img.apercu { display: block; max-width: 220px; max-height: 160px; margin-top: 4px; border-radius: 8px; }
.salle { background: var(--fond); }
.bandeau { border-bottom: 2px solid var(--or); padding-bottom: 6px; }
