/* =================================================================
   Salles Webcam — feuille de style unique.

   Organisation : jetons de design et icones, base, composants generiques,
   puis les blocs specifiques (accueil, salle, mediatheque, diaporama,
   discussion), les adaptations mobiles et enfin l'accessibilite.

   Les noms de jetons (--bg, --bg-card, --border, --accent...) sont aussi
   lus par le mur (wall.ejs) et repris par le mode fort contraste : on peut
   en changer les valeurs, jamais les noms.
   ================================================================= */

:root {
  /* Couleurs */
  --bg: #0a0c11;
  --bg-soft: #0f1218;
  --bg-card: #13161e;
  --bg-elev: #1a1e28;
  --bg-hover: #222735;
  --bg-input: #0d1016;
  --border: #232836;
  --border-strong: #323949;
  --text: #eceef4;
  --muted: #8b94a8;
  --accent: #6366f1;
  --accent-hover: #5457e8;
  --accent-soft: rgba(99, 102, 241, .16);
  --accent-text: #c3c5ff;
  --danger: #ef4444;
  --danger-hover: #dc3535;
  --danger-soft: rgba(239, 68, 68, .14);
  --ok: #22c55e;
  --warn: #f59e0b;
  --stage: #07080b;

  /* Rayons et ombres */
  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 18px 50px rgba(0, 0, 0, .55);

  /* Rythme vertical */
  --gap: 18px;
  --pad-card: 20px;
  --topbar-h: 60px;

  /* Hauteur minimale d'une cible tactile */
  --tap: 40px;

  /* Discussion : taille du texte et hauteur du fil. Le panneau
     d'accessibilite (voir a11y.js) ne fait que reposer ces trois jetons,
     et tout le tchat suit -- salle comme fenetres du mur. */
  --chat-font: 14px;
  --chat-log-h: 260px;
  --chat-log-max: 440px;

  /* Icones (trace Lucide, licence ISC), utilisees en masque : elles
     prennent la couleur du texte, donc suivent aussi le fort contraste. */
  --i-mic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z'/%3E%3Cpath d='M19 10v2a7 7 0 0 1-14 0v-2'/%3E%3Cpath d='M12 19v3'/%3E%3C/svg%3E");
  --i-mic-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m2 2 20 20'/%3E%3Cpath d='M18.89 13.23A7.12 7.12 0 0 0 19 12v-2'/%3E%3Cpath d='M5 10v2a7 7 0 0 0 12 5'/%3E%3Cpath d='M15 9.34V5a3 3 0 0 0-5.68-1.33'/%3E%3Cpath d='M9 9v3a3 3 0 0 0 5.12 2.12'/%3E%3Cpath d='M12 19v3'/%3E%3C/svg%3E");
  --i-cam: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m16 13 5.22 3.48a.5.5 0 0 0 .78-.42V7.87a.5.5 0 0 0-.75-.43L16 10.5'/%3E%3Crect x='2' y='6' width='14' height='12' rx='2'/%3E%3C/svg%3E");
  --i-cam-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.66 6H14a2 2 0 0 1 2 2v2.5l5.25-3.06a.5.5 0 0 1 .75.43v8.2'/%3E%3Cpath d='M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2'/%3E%3Cpath d='m2 2 20 20'/%3E%3C/svg%3E");
  --i-webcam: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='10' r='8'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3Cpath d='M7 22h10'/%3E%3Cpath d='M12 22v-4'/%3E%3C/svg%3E");
  --i-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='9' cy='9' r='2'/%3E%3Cpath d='m21 15-3.09-3.09a2 2 0 0 0-2.82 0L6 21'/%3E%3C/svg%3E");
  --i-expand: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6'/%3E%3Cpath d='M9 21H3v-6'/%3E%3Cpath d='m21 3-7 7'/%3E%3Cpath d='m3 21 7-7'/%3E%3C/svg%3E");
  --i-shrink: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 14h6v6'/%3E%3Cpath d='M20 10h-6V4'/%3E%3Cpath d='m14 10 7-7'/%3E%3Cpath d='m3 21 7-7'/%3E%3C/svg%3E");
  --i-fullscreen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 3H5a2 2 0 0 0-2 2v3'/%3E%3Cpath d='M21 8V5a2 2 0 0 0-2-2h-3'/%3E%3Cpath d='M3 16v3a2 2 0 0 0 2 2h3'/%3E%3Cpath d='M16 21h3a2 2 0 0 0 2-2v-3'/%3E%3C/svg%3E");
  --i-pip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='4' width='20' height='16' rx='2'/%3E%3Crect x='12' y='11' width='7' height='6' rx='1'/%3E%3C/svg%3E");
  --i-pip-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 4h12a2 2 0 0 1 2 2v10'/%3E%3Cpath d='M18 20H4a2 2 0 0 1-2-2V6'/%3E%3Cpath d='m2 2 20 20'/%3E%3C/svg%3E");
  --i-flip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 19H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5'/%3E%3Cpath d='M13 5h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-5'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='m18 22-3-3 3-3'/%3E%3Cpath d='m6 2 3 3-3 3'/%3E%3C/svg%3E");
  --i-volume: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4.7a.7.7 0 0 0-1.2-.5L6.4 7.6A1.4 1.4 0 0 1 5.4 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.4a1.4 1.4 0 0 1 1 .4l3.4 3.4a.7.7 0 0 0 1.2-.5z'/%3E%3Cpath d='M16 9a5 5 0 0 1 0 6'/%3E%3Cpath d='M19.36 18.36a9 9 0 0 0 0-12.72'/%3E%3C/svg%3E");
  --i-play: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M7 4.5v15a.6.6 0 0 0 .9.5l12-7.5a.6.6 0 0 0 0-1l-12-7.5a.6.6 0 0 0-.9.5Z'/%3E%3C/svg%3E");
  --i-stop: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Crect x='5' y='5' width='14' height='14' rx='2.5'/%3E%3C/svg%3E");
  --i-prev: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 18-6-6 6-6'/%3E%3C/svg%3E");
  --i-next: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
  --i-upload: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpath d='m17 8-5-5-5 5'/%3E%3Cpath d='M12 3v12'/%3E%3C/svg%3E");
  --i-folder-plus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 10v6'/%3E%3Cpath d='M9 13h6'/%3E%3Cpath d='M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z'/%3E%3C/svg%3E");
  --i-slides: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 4v16'/%3E%3Cpath d='M22 4v16'/%3E%3Crect x='6' y='3' width='12' height='18' rx='2'/%3E%3C/svg%3E");
  --i-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='8' y='8' width='14' height='14' rx='2'/%3E%3Cpath d='M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'/%3E%3C/svg%3E");
  --i-link: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E");
  --i-exit: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='m16 17 5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E");
  --i-shield: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E");
  --i-user: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='5'/%3E%3Cpath d='M20 21a8 8 0 0 0-16 0'/%3E%3C/svg%3E");
  --i-eye: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.06 12.35a1 1 0 0 1 0-.7 10.75 10.75 0 0 1 19.88 0 1 1 0 0 1 0 .7 10.75 10.75 0 0 1-19.88 0'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");

  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Un display: pose sur une classe l'emporte sur le [hidden] du navigateur :
   sans cette regle, l'attribut hidden pose depuis le JS reste sans effet. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 460px at 50% -180px, rgba(99, 102, 241, .13), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: rgba(99, 102, 241, .35); }

/* Icone en masque : posee par la classe .ico, choisie par --icon. Le
   pseudo-element survit aux textContent poses par le JS sur les boutons. */
.ico::before {
  content: "";
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

/* ---------------------------------------------------------------- */
/* Structure de page                                                 */
/* ---------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: var(--topbar-h);
  padding: 10px max(22px, env(safe-area-inset-left)) 10px max(22px, env(safe-area-inset-right));
  background: rgba(13, 15, 21, .82);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  font-weight: 650;
  font-size: 15.5px;
  letter-spacing: -.1px;
  white-space: nowrap;
}
/* Pictogramme de la marque : un objectif dessine en CSS, sans image. */
.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #818cf8, #6366f1 45%, #a855f7);
  box-shadow: 0 4px 14px rgba(99, 102, 241, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand-mark::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 2.5px solid #fff;
}
.brand-mark::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: #fff;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; }
.brand-section {
  color: var(--muted);
  font-weight: 500;
  font-size: 12.5px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.brand-section:empty { display: none; }

.topbar nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  flex-shrink: 0;
}
/* Les liens de navigation arrivent en HTML brut depuis les vues : on les
   habille en boutons discrets. */
.topbar nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.topbar nav a:hover { background: var(--bg-elev); border-color: var(--border); text-decoration: none; }
.topbar nav a.nav-exit {
  border-color: var(--border);
  background: var(--bg-card);
}
.topbar nav a.nav-exit:hover { background: var(--danger-soft); border-color: rgba(239, 68, 68, .45); color: #fecaca; }

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px max(24px, env(safe-area-inset-left)) calc(56px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-right));
}
.wrap.narrow { max-width: 470px; }
/* Pages de salle : la largeur va d'abord a la video. */
.wrap.room { max-width: 1760px; padding-top: 20px; }

/* ---------------------------------------------------------------- */
/* Typographie                                                       */
/* ---------------------------------------------------------------- */

h1 { font-size: 25px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.4px; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 14px; letter-spacing: -.15px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 10px; }
.subtitle { color: var(--muted); margin: 0 0 22px; font-size: 14.5px; }
.muted { color: var(--muted); }
.hint { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin-top: 10px; }
.mono { font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace; font-size: 13px; word-break: break-all; }
.empty { color: var(--muted); text-align: center; padding: 34px 14px; font-size: 14px; line-height: 1.6; }

/* En-tete de page : titre a gauche, etat et actions a droite. */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 18px;
  margin-bottom: 20px;
}
.page-head .subtitle { margin: 6px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- */
/* Cartes                                                            */
/* ---------------------------------------------------------------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-card);
  margin-bottom: var(--gap);
  box-shadow: var(--shadow-1);
}
.card.tight { padding: 12px 14px; }

/* ---------------------------------------------------------------- */
/* Formulaires                                                       */
/* ---------------------------------------------------------------- */

label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 7px; }

input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%;
  padding: 10px 13px;
  min-height: var(--tap);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:hover, input[type=password]:hover, input[type=search]:hover,
input[type=number]:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input::placeholder, textarea::placeholder { color: #5f6880; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .25);
}
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); margin: 0; }

/* Etiquette + controle sur une seule ligne (duree, boucle, monitoring). */
.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 400;
  white-space: nowrap;
}
.field-inline input[type=number] { width: 70px; min-height: 34px; padding: 5px 8px; text-align: center; }

/* Selecteur compact utilise dans les barres d'outils. */
.select-mini {
  width: auto;
  min-height: 38px;
  padding: 5px 30px 5px 12px;
  font-size: 13px;
  background: var(--bg-elev);
  border-radius: 999px;
}

/* ---------------------------------------------------------------- */
/* Boutons                                                           */
/* ---------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.3;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, opacity .15s, transform .08s;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, .28), inset 0 1px 0 rgba(255, 255, 255, .15);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: none; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }
/* Variante discrete : action destructive secondaire, repetee dans une liste. */
.btn.danger.subtle { background: transparent; border-color: rgba(239, 68, 68, .4); color: #fca5a5; }
.btn.danger.subtle:hover:not(:disabled) { background: var(--danger-soft); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; gap: 6px; }
.btn.small.ico::before { width: 15px; height: 15px; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.block { width: 100%; }
.btn.grow { flex: 1 1 auto; }
.btn.lg { min-height: 48px; font-size: 15px; padding: 11px 20px; border-radius: 12px; }

/* ---------------------------------------------------------------- */
/* Utilitaires de disposition                                        */
/* ---------------------------------------------------------------- */

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row.tight { gap: 7px; }
.spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------------- */
/* Messages et pastilles                                             */
/* ---------------------------------------------------------------- */

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
  border: 1px solid;
  animation: alert-in .2s ease-out;
}
.alert.error { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .38); color: #fecaca; }
.alert.ok { background: rgba(34, 197, 94, .1); border-color: rgba(34, 197, 94, .38); color: #bbf7d0; }
.alert.warn { background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .38); color: #fde68a; }
.alert.info { background: rgba(99, 102, 241, .1); border-color: rgba(99, 102, 241, .4); color: var(--accent-text); }
@keyframes alert-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  line-height: 1.4;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.on { background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .4); color: #86efac; }
.badge.off { background: rgba(139, 148, 168, .1); }
.badge.closed { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); color: #fca5a5; }

/* Voyant d'etat de la liaison : vert qui respire quand on est connecte. */
#link-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .9;
}
#link-status.on::before { animation: live-dot 2s ease-in-out infinite; }
@keyframes live-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
  50% { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

code.code {
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px 9px;
  letter-spacing: 2.5px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ---------------------------------------------------------------- */
/* Tableaux                                                          */
/* ---------------------------------------------------------------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 550; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255, 255, 255, .015); }
tr:last-child td { border-bottom: none; }

/* ================================================================= */
/* Accueil                                                           */
/* ================================================================= */

.wrap.home { max-width: 1080px; padding-top: 56px; }

.hero { text-align: center; max-width: 680px; margin: 0 auto 40px; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 13px;
  margin-bottom: 18px;
  border: 1px solid rgba(99, 102, 241, .35);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .2px;
}
.eyebrow::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .2);
}
.hero h1 { font-size: clamp(30px, 4.6vw, 46px); letter-spacing: -1.2px; line-height: 1.08; margin-bottom: 14px; }
.hero h1 em {
  font-style: normal;
  background: linear-gradient(90deg, #a5b4fc, #c084fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .lead { color: var(--muted); font-size: 17px; line-height: 1.6; margin: 0 auto; max-width: 560px; }

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
  max-width: 940px;
  margin: 0 auto;
}
.home-grid .card { margin: 0; padding: 26px; display: flex; flex-direction: column; }
.home-grid .card form { display: flex; flex-direction: column; flex: 1 1 auto; }
.home-grid .card .push { margin-top: auto; padding-top: 20px; }
.home-grid > :only-child { grid-column: 1 / -1; max-width: 520px; width: 100%; margin: 0 auto; }
.card-title { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.card-title h2 { margin: 0; font-size: 18px; }
.card-title p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.card-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid rgba(99, 102, 241, .3);
}
.card-icon.ico::before { width: 20px; height: 20px; }
.card-icon.alt { background: rgba(168, 85, 247, .14); color: #e9d5ff; border-color: rgba(168, 85, 247, .3); }

.code-input {
  letter-spacing: 6px;
  text-transform: uppercase;
  text-align: center;
  font-size: 22px !important;
  font-weight: 650;
  min-height: 56px !important;
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace !important;
}
.code-input::placeholder { letter-spacing: 4px; color: #3f4659; }

/* Choix du role : deux cartes radio plutot qu'une liste deroulante. */
.role-pick { border: 0; padding: 0; margin: 20px 0 0; min-width: 0; }
.role-pick legend { padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.role-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-opt { position: relative; margin: 0; cursor: pointer; color: var(--text); }
.role-opt input { position: absolute; opacity: 0; pointer-events: none; }
.role-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  height: 100%;
  padding: 13px 14px 13px 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-input);
  transition: border-color .15s, background .15s, box-shadow .15s;
  position: relative;
}
.role-card::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 15px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  transition: border .15s;
}
.role-card b { font-size: 14.5px; font-weight: 650; }
.role-card small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.role-opt:hover .role-card { border-color: var(--border-strong); }
.role-opt input:checked + .role-card {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.role-opt input:checked + .role-card::before {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--accent) 0 3.5px, transparent 4px);
}
.role-opt input:focus-visible + .role-card { outline: 2px solid var(--accent); outline-offset: 2px; }

.features {
  list-style: none;
  padding: 0;
  margin: 44px auto 0;
  max-width: 940px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.features li { display: flex; gap: 12px; align-items: flex-start; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.features li b { display: block; color: var(--text); font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.features .ico::before {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--accent-text);
}
.features .ico {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--accent-text);
}

/* Page simple centree (connexion, salle indisponible). */
.center-card { text-align: center; padding: 34px 28px; }
.center-card .card-icon { margin: 0 auto 16px; }

/* ================================================================= */
/* Salle : en-tete, scene, videos, commandes                         */
/* ================================================================= */

.room-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 24px;
  margin-bottom: 18px;
}
.room-title { min-width: 0; }
.room-title h1 { margin: 0 0 7px; font-size: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.room-meta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--border-strong); }

/* Barre du lien spectateur. */
.share-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex: 0 1 520px;
  min-width: 0;
  padding: 6px 6px 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.share-bar .share-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 550;
  white-space: nowrap;
}
.share-bar .share-label.ico::before { width: 15px; height: 15px; --icon: var(--i-link); }
.share-bar input {
  flex: 1 1 90px;
  min-width: 0;
  min-height: 34px;
  padding: 5px 10px;
  background: transparent;
  border-color: transparent;
  color: var(--accent-text);
}
.share-bar input:hover { border-color: transparent; }
.share-bar input:focus { box-shadow: none; border-color: var(--border); background: var(--bg-input); }
#btn-copy-link { --icon: var(--i-copy); }

/* Trois zones : le direct, le panneau lateral, la discussion.
   Sur mobile elles s'empilent dans cet ordre pour que la mediatheque
   et le diaporama restent a portee immediate sous les videos. */
.stage {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 400px;
  grid-template-areas:
    "main side"
    "chat side";
  align-items: start;
}
.stage-main { grid-area: main; min-width: 0; }
.stage-chat { grid-area: chat; min-width: 0; }
.stage-side {
  grid-area: side;
  min-width: 0;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
}

/* Spectateur : la video a gauche, la discussion en colonne a droite. */
/* La colonne de discussion prend exactement la hauteur de la scene. */
.stage.stage--viewer {
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-areas: "main chat";
  align-items: stretch;
}
.stage--viewer .stage-chat > .card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 420px;
  margin: 0;
}
.stage--viewer .stage-chat .chat-log { flex: 1 1 auto; height: auto; min-height: 160px; }

/* Cadre de la scene : la video et sa barre de commandes forment un bloc. */
.stage-frame {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-1);
}

.videos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.video-box {
  position: relative;
  background: var(--stage);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.video-box video { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--stage); }
.video-box .tag {
  position: absolute; top: 10px; left: 10px;
  background: rgba(8, 10, 14, .62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .1);
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .1px;
  pointer-events: none;
  z-index: 2;
}
.video-box .state {
  position: absolute; bottom: 10px; left: 10px; right: 10px;
  display: flex; gap: 6px; flex-wrap: wrap;
  pointer-events: none;
  z-index: 2;
}
.video-box .state .badge {
  background: rgba(8, 10, 14, .66);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.video-box .placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; text-align: center; padding: 24px;
  background: radial-gradient(circle at 50% 40%, #141824, var(--stage) 70%);
}
.video-box.mirrored video { transform: scaleX(-1); }

/* Barre d'outils en surimpression : son, agrandissement, plein ecran. */
.video-box .box-tools {
  position: absolute; top: 9px; right: 9px; z-index: 3;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  justify-content: flex-end;
  max-width: calc(100% - 18px);
}
.video-box .box-tools .btn {
  padding: 4px 10px;
  min-height: 32px;
  font-size: 12px;
  background: rgba(8, 10, 14, .62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-color: rgba(255, 255, 255, .14);
  color: #fff;
}
.video-box .box-tools .btn:hover:not(:disabled) { background: rgba(30, 34, 46, .9); }
/* Activer le son : l'appel a l'action doit se voir du premier coup d'oeil. */
.video-box .box-tools .btn.sound {
  --icon: var(--i-volume);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(99, 102, 241, .4);
}
.video-box .box-tools .btn.sound::before {
  content: "";
  width: 15px;
  height: 15px;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

/* Salle (hote et spectateur) : les outils de vue deviennent des pastilles
   rondes a icone. Le libelle reste dans le bouton -- le JS le met a jour,
   et c'est lui que lit un lecteur d'ecran -- mais il est rendu invisible. */
#room-root .box-tools [data-zoom],
#room-root .box-tools [data-hide-mini],
#room-root .box-tools [data-fullscreen],
#room-root .box-tools #btn-flip-cam {
  width: 34px;
  min-height: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 0;
  gap: 0;
}
#room-root .box-tools [data-zoom]::before,
#room-root .box-tools [data-hide-mini]::before,
#room-root .box-tools [data-fullscreen]::before,
#room-root .box-tools #btn-flip-cam::before {
  content: "";
  width: 16px;
  height: 16px;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
#room-root [data-zoom] { --icon: var(--i-expand); }
#room-root .focused [data-zoom] { --icon: var(--i-shrink); }
#room-root [data-hide-mini] { --icon: var(--i-pip-off); }
#room-root .hide-mini [data-hide-mini] { --icon: var(--i-pip); }
#room-root [data-fullscreen] { --icon: var(--i-fullscreen); }
#room-root #btn-flip-cam { --icon: var(--i-flip); }

/* Etiquette de salle precedee d'un voyant. */
#room-root .video-box .tag { display: inline-flex; align-items: center; gap: 6px; }
#room-root .video-box .tag::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
#room-root #remote-box .tag::before { background: var(--ok); }

/* Invitations : un pictogramme au-dessus du texte. */
#room-root .video-box .placeholder::before {
  content: "";
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .05) center / 22px no-repeat;
  border: 1px solid rgba(255, 255, 255, .08);
}
#room-root #local-placeholder::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b94a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m16 13 5.22 3.48a.5.5 0 0 0 .78-.42V7.87a.5.5 0 0 0-.75-.43L16 10.5'/%3E%3Crect x='2' y='6' width='14' height='12' rx='2'/%3E%3C/svg%3E");
}
#room-root #remote-placeholder::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b94a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='5'/%3E%3Cpath d='M20 21a8 8 0 0 0-16 0'/%3E%3C/svg%3E");
}

/* Sur un ecran a souris, les outils n'apparaissent qu'au survol de la
   video : l'image reste nette. Le bouton « Activer le son » reste affiche. */
@media (hover: hover) {
  #room-root .video-box .box-tools .btn:not(.sound) { opacity: 0; transition: opacity .18s, background .15s; }
  #room-root .video-box:hover .box-tools .btn,
  #room-root .video-box:focus-within .box-tools .btn { opacity: 1; }
}

/* Mode agrandi : une video occupe toute la largeur, l'autre passe en vignette.
   Sur ordinateur, la vue agrandie est une scene de hauteur fixe, calee sur
   l'ecran (commandes comprises) : une photo en portrait y prend toute la
   hauteur, une photo en paysage toute la largeur, et la page ne saute pas
   d'une diapo a l'autre. Le telephone suit, lui, le format du flux (voir les
   adaptations mobiles). */
.videos.focus-mode { grid-template-columns: 1fr; position: relative; }
.videos.focus-mode .video-box { display: none; }
.videos.focus-mode .video-box.focused { display: block; }
#room-root .videos.focus-mode .video-box.focused {
  aspect-ratio: auto;
  height: calc(100vh - var(--topbar-h) - 210px);
  height: calc(100dvh - var(--topbar-h) - 210px);
  min-height: 320px;
}
/* La vignette garde la forme de son flux : une camera de telephone tenue
   droite reste en portrait, plus etroite. --ar et data-orient sont poses par
   bindVideoAspect (rtc.js). */
.videos.focus-mode .video-box.minimized {
  display: block;
  position: absolute;
  right: 14px; bottom: 14px;
  width: 24%; min-width: 130px; max-width: 290px;
  aspect-ratio: var(--ar, 16 / 9);
  z-index: 4;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, .22);
  border-radius: 10px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .6);
  transition: transform .15s, border-color .15s;
}
.videos.focus-mode .video-box.minimized[data-orient="portrait"] { width: 13%; min-width: 84px; max-width: 170px; }
.videos.focus-mode .video-box.minimized:hover { transform: scale(1.03); border-color: rgba(255, 255, 255, .4); }
.videos.focus-mode .video-box.minimized .box-tools,
.videos.focus-mode .video-box.minimized .state,
.videos.focus-mode .video-box.minimized .placeholder { display: none; }

/* Bouton "Masquer la vignette" : uniquement sur la vue agrandie, en mode focus. */
[data-hide-mini] { display: none; }
.videos.focus-mode .video-box.focused [data-hide-mini] { display: inline-flex; }
.videos.focus-mode.hide-mini .video-box.minimized { display: none; }
.videos.focus-mode .video-box.minimized .tag { top: 6px; left: 6px; font-size: 11px; padding: 2px 7px; }

/* Plein ecran natif : on libere la contrainte 16/9 pour occuper tout l'ecran. */
/* Les !important l'emportent sur les tailles du mode agrandi et du format
   mobile, plus specifiques : sans eux, le plein ecran garderait la hauteur
   de la scene. */
.video-box:fullscreen {
  aspect-ratio: auto !important;
  width: 100vw !important;
  height: 100vh !important;
  min-height: 0 !important;
  max-height: none !important;
  border: none !important;
  border-radius: 0 !important;
}

/* Barre de commandes du direct : centree sous la video. */
.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.controls .btn { min-height: 44px; padding: 9px 18px; border-radius: 12px; }
.controls .btn:not(:disabled):not(.active) { background: var(--bg-elev); }
.controls .btn:hover:not(:disabled):not(.active) { background: var(--bg-hover); }
#btn-mic { --icon: var(--i-mic); }
#btn-mic.active { --icon: var(--i-mic-off); }
#btn-cam { --icon: var(--i-cam); }
#btn-cam.active { --icon: var(--i-cam-off); }
#btn-source-cam { --icon: var(--i-webcam); }
#btn-source-media { --icon: var(--i-image); max-width: 300px; overflow: hidden; }
/* Micro ou camera coupes : le bouton passe au rouge, l'etat se lit de loin. */
.controls #btn-mic.active,
.controls #btn-cam.active {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, .5);
  color: #fecaca;
}
.controls #btn-source-cam.active,
.controls #btn-source-media.active {
  background: var(--accent-soft);
  border-color: rgba(99, 102, 241, .6);
  color: #fff;
}
.controls .divider { width: 1px; align-self: stretch; margin: 6px 4px; background: var(--border); }

/* Options du media diffuse, rattachees a la scene. */
.media-options {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}
.media-options .row { gap: 8px; }
.media-options .title { font-size: 13px; font-weight: 600; margin-right: 6px; }
.media-options .hint { margin: 8px 0 0; }

/* ---------------------------------------------------------------- */
/* Discussion                                                        */
/* ---------------------------------------------------------------- */

/* En-tete de la discussion : titre, compteur de non-lus, boutons d'alertes
   et d'accessibilite. Le retour a la ligne evite que le second bouton ne
   deborde de la carte sur les ecrans etroits. */
.chat-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.chat-head h2 { margin: 0; }
.chat-head .btn.small { padding: 5px 10px; min-height: 32px; font-size: 12.5px; }
.chat-unread {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.chat-log {
  height: var(--chat-log-h);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #343c4e transparent;
}
.chat-empty { margin: auto; color: var(--muted); font-size: calc(var(--chat-font) * .96); text-align: center; }
.chat-msg {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: var(--chat-font);
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: msg-in .18s ease-out;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-msg .who { display: block; font-size: calc(var(--chat-font) * .8); font-weight: 600; margin-bottom: 2px; color: var(--muted); }
.chat-msg.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, #6366f1, #7c5cf5);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.chat-msg.mine .who { color: rgba(255, 255, 255, .75); }
.chat-msg.theirs { align-self: flex-start; background: var(--bg-elev); border: 1px solid var(--border); border-bottom-left-radius: 5px; }

.chat-form { display: flex; gap: 8px; margin-top: 10px; position: relative; }
.chat-form input { flex: 1 1 auto; min-width: 0; margin: 0; border-radius: 12px; }
.chat-form .btn { border-radius: 12px; }
#chat-emoji-btn { font-size: 18px; line-height: 1; padding: 6px 11px; flex: 0 0 auto; }

/* Voile de fermeture : invisible, il couvre toute la page pendant que le
   panneau d'emojis est ouvert. Tout clic hors du panneau — y compris sur
   l'icone qui l'a ouvert — atterrit donc sur un element reel, et referme.
   Il passe au-dessus de la barre superieure (z-index 20) pour qu'aucune
   zone de la page n'echappe a ce geste. */
.emoji-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

/* Panneau d'emojis : en-tete avec fermeture, puis grille defilante.
   Les colonnes s'ajustent a la largeur disponible (auto-fill) : le panneau
   ne peut plus deborder de la carte, quelle que soit la taille d'ecran. */
.emoji-panel {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  width: min(348px, 100%);
  max-height: 372px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  z-index: 50;
  box-shadow: var(--shadow-2);
}
.emoji-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 6px 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.emoji-close {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
}
.emoji-close:hover { background: var(--bg-hover); }

/* Raccourcis de familles : une rangee qui defile horizontalement. */
.emoji-nav {
  flex: 0 0 auto;
  display: flex;
  gap: 3px;
  padding: 6px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.emoji-nav::-webkit-scrollbar { display: none; }
.emoji-nav button {
  flex: 0 0 auto;
  width: 36px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}
.emoji-nav button:hover { background: var(--bg-input); }

/* Intitule de famille : occupe toute la largeur de la grille. */
.emoji-group {
  grid-column: 1 / -1;
  padding: 8px 2px 2px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--muted);
}
.emoji-group:first-child { padding-top: 0; }

.emoji-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  display: grid;
  /* Cases larges et glyphes genereux : a 19px on ne distinguait pas 😘 de 😚. */
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 4px;
}
.emoji-grid button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 28px;
  line-height: 1.15;
  padding: 6px 2px;
  border-radius: 9px;
  min-width: 0;
}
.emoji-grid button:hover { background: var(--bg-input); }

/* ---------------------------------------------------------------- */
/* Discussion en fenetre libre                                       */
/* ---------------------------------------------------------------- */

/* Detachee, la discussion quitte la grille : la rangee qui lui etait
   reservee disparait, et le direct reprend toute la hauteur. */
.stage.chat-detached { grid-template-areas: "main side"; }

/* La fenetre. Son plan doit rester AU-DESSUS du voile de fermeture des
   emojis (.emoji-backdrop, 40) -- sinon ce voile transparent avalerait les
   clics qui la visent -- et AU-DESSOUS du panneau d'accessibilite (79 et
   80), qui doit pouvoir la recouvrir. */
.stage-chat.floating {
  position: fixed;
  z-index: 60;
}
.stage-chat.floating > .card {
  position: relative;
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  /* Volontairement visible : la palette d'emojis deborde par le haut. */
  overflow: visible;
  box-shadow: var(--shadow-2);
  border-color: var(--border-strong);
}

/* La barre de titre entiere sert de poignee, comme sur le mur. */
.stage-chat.floating .chat-head {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stage-chat.floating.dragging .chat-head { cursor: grabbing; }
.stage-chat.floating.dragging,
.stage-chat.floating.resizing { user-select: none; -webkit-user-select: none; }

/* C'est la fenetre qui porte la hauteur (voir les poignees) ; le fil prend
   simplement toute la place qui reste. */
.stage-chat.floating .chat-log {
  flex: 1 1 auto;
  height: auto;
  min-height: 60px;
}
.stage-chat.floating .chat-form { flex: 0 0 auto; }

/* Le rappel sous le formulaire mangerait la hauteur que l'on vient de
   gagner : il reste lisible dans la page ancree. */
.stage-chat.floating .chat-form ~ .hint { display: none; }

/* La palette s'ouvre vers le haut par defaut ; chat-window.js la bascule
   vers le bas quand la fenetre est posee trop pres du bord superieur. */
.stage-chat.floating .emoji-panel.below { bottom: auto; top: calc(100% + 6px); }

/* Poignee de deplacement : trois barres, l'image d'une prise a saisir. Elle
   double la barre de titre pour le clavier -- focalisable, elle repond aux
   fleches, ce qu'un glisser a la souris ne permet pas.

   Les barres sont dessinees sur un ::before et non sur le fond du bouton :
   toute regle de survol posant le raccourci "background" (.btn:hover, et sa
   variante en fort contraste) effacerait l'image de fond au passage de la
   souris, et la poignee deviendrait un bouton vide. */
.chat-handle {
  width: 34px;
  padding: 0;
  cursor: grab;
  touch-action: none;
}
.chat-handle::before {
  content: "";
  width: 14px;
  height: 12px;
  background-image:
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor);
  background-size: 14px 2px;
  background-repeat: no-repeat;
  background-position: left top, left center, left bottom;
}
.stage-chat.dragging .chat-handle { cursor: grabbing; }

/* Poignee de taille, coin bas-droit. Dessinee a la main : la propriete CSS
   "resize" imposerait un debordement masque, qui rognerait la palette
   d'emojis ouverte par-dessus le bord superieur. */
.chat-grip {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background-color: transparent;
  background-image:
    linear-gradient(135deg, transparent 46%, var(--border-strong) 46%, var(--border-strong) 54%, transparent 54%),
    linear-gradient(135deg, transparent 71%, var(--border-strong) 71%, var(--border-strong) 79%, transparent 79%);
  cursor: nwse-resize;
  touch-action: none;
}
.chat-grip:hover { background-color: var(--bg-input); }

/* ================================================================= */
/* Panneau a onglets : mediatheque et diaporama                      */
/* ================================================================= */

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100vh - var(--topbar-h) - 32px);
  max-height: calc(100dvh - var(--topbar-h) - 32px);
}

/* Onglets : toujours visibles, ils evitent d'empiler deux longues listes. */
.panel-tabs {
  display: flex;
  gap: 4px;
  margin: 10px 10px 0;
  padding: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex: 0 0 auto;
}
.tab-btn {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab-btn.ico::before { width: 16px; height: 16px; }
#tab-media { --icon: var(--i-image); }
#tab-slides { --icon: var(--i-slides); }
.tab-btn:hover { color: var(--text); }
.tab-btn[aria-selected="true"] {
  background: var(--bg-elev);
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow-1);
}
.tab-count {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .07);
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tab-btn[aria-selected="true"] .tab-count { background: var(--accent-soft); color: var(--accent-text); }

.panel-body { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }

/* Barre d'outils fixe : recherche, tri, dossiers, commandes du diaporama.
   Elle reste au-dessus de la liste, quelle que soit la longueur de celle-ci. */
.panel-toolbar {
  flex: 0 0 auto;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toolbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#btn-media-upload { --icon: var(--i-upload); }
#btn-folder-new { --icon: var(--i-folder-plus); }
#btn-media-add-all { --icon: var(--i-slides); }

/* La liste seule defile : les commandes ne partent jamais hors ecran. */
.panel-scroll {
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: #343c4e transparent;
}
.panel-scroll::-webkit-scrollbar, .chat-log::-webkit-scrollbar { width: 10px; }
.panel-scroll::-webkit-scrollbar-thumb, .chat-log::-webkit-scrollbar-thumb { background: #2d3443; border-radius: 99px; border: 3px solid var(--bg-card); }
.panel-scroll::-webkit-scrollbar-thumb:hover { background: #3b4457; }

.panel-foot {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 12.5px;
  color: var(--muted);
}
.panel-foot .hint { margin: 0; }

/* Champ de recherche avec loupe dessinee en CSS. */
.search-field { position: relative; flex: 1 1 150px; min-width: 0; }
.search-field input {
  padding-left: 36px;
  min-height: 38px;
  font-size: 14px;
  border-radius: 999px;
}
.search-field::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 11px;
  height: 11px;
  margin-top: -7px;
  border: 1.7px solid var(--muted);
  border-radius: 50%;
  pointer-events: none;
}
.search-field::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 50%;
  width: 6px;
  height: 1.7px;
  margin-top: 3px;
  background: var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}

/* ---------------------------------------------------------------- */
/* Dossiers de mediatheque                                           */
/* ---------------------------------------------------------------- */

/* La barre de dossiers defile horizontalement plutot que de s'etaler
   sur quatre lignes des qu'il y a beaucoup de dossiers. */
.folders {
  display: flex;
  gap: 7px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 2px 2px;
  margin: 0 -2px;
}
.folders::-webkit-scrollbar { display: none; }
.folder-chip {
  display: inline-flex; align-items: center; gap: 6px;
  flex: 0 0 auto;
  padding: 6px 12px;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.folder-chip:hover { background: var(--bg-elev); }
.folder-chip.active { border-color: var(--accent); background: var(--accent-soft); color: #fff; }
.folder-chip .count { color: var(--muted); font-size: 12px; }
.folder-chip.active .count { color: rgba(255, 255, 255, .72); }

.media-move {
  width: 100%; margin-top: 7px;
  padding: 5px 7px; font-size: 12px;
  min-height: 32px;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit;
}

/* ---------------------------------------------------------------- */
/* Grille de medias                                                  */
/* ---------------------------------------------------------------- */

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-input);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.media-item:hover { border-color: var(--border-strong); box-shadow: 0 8px 22px rgba(0, 0, 0, .35); }
.media-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 22px rgba(99, 102, 241, .2); }
.media-thumb {
  width: 100%; aspect-ratio: 16/10; object-fit: cover; display: block; background: #000; cursor: pointer;
}

/* Pastille de type posee sur la vignette. */
.media-kind {
  position: absolute;
  top: 7px; left: 7px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(8, 10, 14, .7);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
  pointer-events: none;
}

/* Ajout au diaporama : bouton rond pose sur la vignette, toujours atteignable. */
.media-add {
  position: absolute;
  top: 6px; right: 6px;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(8, 10, 14, .75);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: background .15s, transform .1s;
}
.media-add:hover { background: rgba(30, 36, 50, .95); transform: scale(1.06); }
.media-add.on { background: var(--accent); border-color: var(--accent); }

.media-meta { padding: 9px 10px 10px; font-size: 12px; }
.media-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px; font-size: 12.5px; font-weight: 550;
}
.media-info { color: var(--muted); margin-bottom: 8px; font-size: 11.5px; }

/* Les actions se partagent la largeur de la vignette et passent a la ligne
   plutot que de se comprimer jusqu'a l'illisible. */
/* flex-basis auto : c'est la taille du libelle, et non une base fixe, qui
   decide du passage a la ligne — trois actions tiennent sur une vignette. */
.media-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.media-actions .btn { flex: 1 1 auto; justify-content: center; padding: 5px 6px; min-height: 32px; font-size: 12px; border-radius: 8px; }
.media-actions .icon-btn { flex: 0 0 32px; padding: 0; font-size: 13px; }

/* ---------------------------------------------------------------- */
/* Diaporama                                                         */
/* ---------------------------------------------------------------- */

/* Etat de lecture affiche au-dessus des commandes. */
.slide-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-input);
  font-size: 13px;
}
.slide-status strong { font-size: 14px; font-weight: 650; }
.slide-status .now {
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}
.slide-status .now:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--danger);
  vertical-align: 1px;
  animation: rec-blink 1.4s ease-in-out infinite;
}
@keyframes rec-blink { 50% { opacity: .3; } }

#btn-slide-start { --icon: var(--i-play); min-height: 46px; font-size: 15px; }
#btn-slide-start.danger { --icon: var(--i-stop); }
#btn-slide-prev { --icon: var(--i-prev); }
#btn-slide-next { --icon: var(--i-next); flex-direction: row-reverse; }

.playlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.playlist li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  transition: border-color .15s, background .15s;
}
.playlist li:hover { border-color: var(--border-strong); }
.playlist li.current { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.playlist .idx { color: var(--muted); min-width: 18px; text-align: right; font-variant-numeric: tabular-nums; flex: 0 0 auto; font-size: 12px; font-weight: 600; }
.playlist li.current .idx { color: var(--accent-text); }
.playlist .pthumb {
  width: 56px; height: 36px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 7px;
  background: #000;
  display: block;
}
.playlist .pbody { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.playlist .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.playlist .pmeta { color: var(--muted); font-size: 11.5px; }
.playlist .pactions { display: flex; gap: 4px; flex: 0 0 auto; }
.playlist .mini {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.playlist .mini:hover:not(:disabled) { background: var(--bg-hover); }
.playlist .mini:disabled { opacity: .32; cursor: not-allowed; }
.playlist .mini.remove:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- */
/* Depot de fichiers                                                 */
/* ---------------------------------------------------------------- */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  background: rgba(255, 255, 255, .01);
  transition: border-color .15s, background .15s, color .15s;
}
.dropzone:hover, .dropzone.hover { border-color: var(--accent); background: rgba(99, 102, 241, .07); color: var(--text); }
.dropzone.compact { padding: 14px; font-size: 13px; }
.dropzone b { color: var(--accent-text); font-weight: 600; }

.progress { height: 5px; background: var(--bg-input); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, #6366f1, #a855f7); transition: width .15s; }

/* ================================================================= */
/* Adaptations mobiles                                               */
/* ================================================================= */

/* Ecran moyen : panneau lateral un peu plus etroit. */
@media (max-width: 1280px) {
  .stage { grid-template-columns: minmax(0, 1fr) 360px; }
  .stage.stage--viewer { grid-template-columns: minmax(0, 1fr) 340px; }
}

/* Tablette : le panneau lateral passe sous le direct, la discussion en bas. */
@media (max-width: 1040px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "main" "side" "chat";
  }
  .stage.stage--viewer { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "chat"; }
  .stage.chat-detached { grid-template-areas: "main" "side"; }
  .stage-side { position: static; }
  .stage--viewer .stage-chat > .card { height: auto; min-height: 0; }
  .stage--viewer .stage-chat .chat-log { flex: 0 0 auto; height: var(--chat-log-h); }
  .panel { max-height: none; }
  .panel-scroll { max-height: 56vh; max-height: 56dvh; }

  .home-grid { grid-template-columns: minmax(0, 1fr); max-width: 560px; }
  .features { grid-template-columns: minmax(0, 1fr); max-width: 560px; gap: 14px; }
}

@media (max-width: 760px) {
  :root { --gap: 14px; --pad-card: 16px; --tap: 44px; --topbar-h: 56px; }

  .topbar { padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right)); gap: 10px; }
  .topbar .brand { font-size: 15px; gap: 9px; }
  .brand-mark { width: 28px; height: 28px; }
  .brand-section { display: none; }
  .topbar nav { gap: 4px; font-size: 13.5px; }
  .topbar nav a { padding: 6px 11px; }

  .wrap {
    padding: 18px max(14px, env(safe-area-inset-left)) calc(40px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  }
  .wrap.room { padding-top: 14px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .wrap.home { padding-top: 30px; }

  h1 { font-size: 21px; }
  .subtitle { margin-bottom: 16px; }
  .hero { margin-bottom: 26px; }
  .hero .lead { font-size: 15px; }
  .home-grid .card { padding: 20px; }
  .role-options { grid-template-columns: 1fr; }

  /* iOS zoome sur un champ dont la police descend sous 16px. */
  input[type=text], input[type=password], input[type=search], input[type=number], select, textarea { font-size: 16px; }
  .select-mini { font-size: 14px; }
  .field-inline input[type=number] { min-height: 40px; }

  /* En-tete de salle : titre puis lien, chacun sur toute la largeur. */
  .room-head { gap: 12px; margin-bottom: 12px; padding: 0 4px; }
  .room-title { flex: 1 1 100%; }
  .room-title h1 { font-size: 19px; white-space: normal; }
  .share-bar { flex: 1 1 100%; padding-left: 12px; }
  .share-bar .share-label .txt { display: none; }

  .stage { gap: 14px; }

  /* La scene va d'un bord a l'autre de l'ecran : chaque pixel de largeur
     revient a l'image. Seules les commandes gardent une marge. */
  .stage-frame {
    margin-left: calc(-1 * max(10px, env(safe-area-inset-left)));
    margin-right: calc(-1 * max(10px, env(safe-area-inset-right)));
    padding: 0 0 10px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .stage-frame .controls,
  .stage-frame .media-options { margin-left: 10px; margin-right: 10px; }

  /* Deux videos empilees : chacune garde un format lisible. */
  .videos { grid-template-columns: 1fr; gap: 6px; }
  .stage-frame .video-box { border-radius: 0; border-left: 0; border-right: 0; }

  /* Sur telephone, le cadre prend la forme du flux : une photo en portrait
     occupe la hauteur de l'ecran au lieu d'etre reduite dans une bande 16/9.
     La hauteur reste bornee pour garder les commandes a portee de pouce. */
  #room-root .video-box {
    aspect-ratio: var(--ar, 16 / 9);
    max-height: 62vh;
    max-height: 62dvh;
  }
  #room-root .videos.focus-mode .video-box.focused {
    aspect-ratio: var(--ar, 16 / 9);
    height: auto;
    min-height: 200px;
    max-height: 76vh;
    max-height: 76dvh;
  }
  .videos.focus-mode .video-box.minimized { width: 24%; min-width: 80px; right: 8px; bottom: 8px; border-radius: 8px; }
  .videos.focus-mode .video-box.minimized[data-orient="portrait"] { width: 19%; min-width: 64px; }
  #room-root .videos.focus-mode .video-box.minimized { max-height: none; }
  .videos.focus-mode .video-box.minimized .tag { font-size: 10px; padding: 1px 6px; white-space: nowrap; }

  /* Les commandes principales se partagent la largeur, deux par ligne.
     Leur libelle peut alors passer sur deux lignes plutot que deborder. */
  .controls { gap: 8px; margin-top: 8px; }
  .controls .divider { display: none; }
  .controls .btn {
    flex: 1 1 calc(50% - 4px);
    white-space: normal;
    text-align: center;
    padding: 8px 10px;
    font-size: 13.5px;
    min-height: 48px;
  }
  #btn-source-media { max-width: none; }
  .media-options { margin-top: 8px; }

  /* Zone de discussion genereuse : c'est la partie qu'on lit le plus
     longtemps sur telephone. */
  .chat-log { height: 60vh; height: min(60dvh, var(--chat-log-max)); }
  .stage--viewer .stage-chat .chat-log { height: 60vh; height: min(60dvh, var(--chat-log-max)); }

  /* Poignee de taille au doigt : 18px se rate une fois sur deux. */
  .chat-grip { width: 26px; height: 26px; right: 2px; bottom: 2px; }

  /* Le panneau prend toute la largeur du formulaire et des cases plus
     grandes : on vise un emoji au doigt sans deborder. */
  .emoji-panel { width: 100%; right: 0; left: 0; max-height: min(58dvh, 430px); }
  .emoji-nav button { width: 40px; height: 38px; font-size: 23px; }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; }
  .emoji-grid button { padding: 8px 2px; font-size: 32px; }
  .emoji-close { width: 34px; height: 34px; }

  .panel { border-radius: 16px; }
  .panel-toolbar { padding: 12px; }
  .panel-scroll { padding: 12px; max-height: 62vh; max-height: 62dvh; }
  .tab-btn { font-size: 13px; }

  .media-grid { grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 10px; }
  .media-actions .btn { min-height: 36px; }
  .media-move { min-height: 36px; }
  .playlist .mini { width: 34px; height: 34px; font-size: 14px; }
  .playlist li { padding: 8px; gap: 8px; }

  /* Tableaux : chaque ligne devient une fiche lisible sans defilement lateral. */
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  .table-cards tr:last-child { margin-bottom: 0; }
  .table-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, .07);
    text-align: right;
  }
  .table-cards td:last-child { border-bottom: none; padding-bottom: 0; }
  .table-cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12.5px;
    text-align: left;
    flex: 0 0 auto;
  }
  .table-cards td.full { display: block; text-align: left; }
  .table-cards td.full::before { content: none; }
  .table-cards td .row { justify-content: flex-end; flex-wrap: wrap; }
  .table-cards td .btn { flex: 1 1 auto; }
}

@media (max-width: 420px) {
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .media-meta { padding: 8px 8px 9px; }
  .playlist .pthumb { width: 46px; height: 30px; }
  .topbar nav a .txt { display: none; }
}

/* Telephone a l'horizontale : la video prend toute la hauteur utile. */
@media (max-height: 520px) and (orientation: landscape) {
  #room-root .videos.focus-mode .video-box.focused { height: calc(100dvh - 40px); max-height: none; min-height: 0; }
  .topbar { position: static; }
}

/* Ecrans tactiles : effets de survol neutralises. */
@media (hover: none) {
  .btn:hover:not(:disabled) { background: var(--bg-elev); border-color: var(--border); }
  .btn.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
  .btn.danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); }
  .btn.danger.subtle:hover:not(:disabled) { background: transparent; border-color: rgba(239, 68, 68, .4); }
  .btn.active:hover:not(:disabled) { background: var(--accent); }
  .controls #btn-mic.active:hover, .controls #btn-cam.active:hover { background: var(--danger-soft); }
  .controls #btn-source-cam.active:hover, .controls #btn-source-media.active:hover { background: var(--accent-soft); }
  .video-box .box-tools .btn:hover:not(:disabled) { background: rgba(8, 10, 14, .62); }
  .video-box .box-tools .btn.sound:hover:not(:disabled) { background: var(--accent); }
  .folder-chip:hover { background: var(--bg-input); }
  .folder-chip.active:hover { background: var(--accent-soft); }
  .tab-btn:hover { color: var(--muted); }
  .tab-btn[aria-selected="true"]:hover { color: var(--text); }
  .media-item:hover { box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ================================================================= */
/* Accessibilite malvoyants                                          */
/* ================================================================= */

/* ---------------------------------------------------------------- */
/* Grossissement du texte de la discussion                           */
/* ---------------------------------------------------------------- */

/* Les classes sont posees sur <html> : les fenetres de tchat et les panneaux
   sont ajoutes a <body> au fil de l'eau, la racine est le seul ancetre
   certain. Le fil grandit avec le texte, sinon un palier eleve n'y laisserait
   plus tenir que deux messages. */
html.a11y-text-1 { --chat-font: 16.5px; --chat-log-h: 300px; --chat-log-max: 460px; }
html.a11y-text-2 { --chat-font: 20px;   --chat-log-h: 350px; --chat-log-max: 500px; }
html.a11y-text-3 { --chat-font: 25px;   --chat-log-h: 400px; --chat-log-max: 540px; }

/* Le champ de saisie suit le fil : relire ce que l'on vient de taper fait
   partie de la discussion. La specificite doit depasser celle de la regle
   mobile sur input[type=text] et celle du mur sur .wall-win .chat-form input,
   d'ou la racine en tete du selecteur. */
html[class*="a11y-text-"] .chat-form input,
html[class*="a11y-text-"] .wall-win .chat-form input {
  font-size: var(--chat-font);
}

/* Le reste du bloc suit : titre, boutons d'envoi, rappel sous le fil.
   Agrandir les bulles en laissant « Envoyer » en petit ne servirait qu'a
   moitie. Le bouton d'emojis porte un identifiant dans style.css, d'ou une
   regle a part : sans elle, sa taille ecrite en dur l'emporterait. */
html[class*="a11y-text-"] .chat-head h2,
html[class*="a11y-text-"] .chat-form .btn,
html[class*="a11y-text-"] .wall-win .chat-form .btn {
  font-size: var(--chat-font);
}
html[class*="a11y-text-"] #chat-emoji-btn { font-size: calc(var(--chat-font) * 1.25); }
html[class*="a11y-text-"] .chat-form ~ .hint { font-size: calc(var(--chat-font) * .86); }

/* Une bulle plus large : a 25px, 82% d'une colonne etroite ne laisse plus
   que quelques mots par ligne. */
html.a11y-text-2 .chat-msg,
html.a11y-text-3 .chat-msg { max-width: 94%; }

/* ---------------------------------------------------------------- */
/* Fort contraste                                                    */
/* ---------------------------------------------------------------- */

/* Noir absolu, blanc pur, jaune pour tout ce qui attire l'oeil : le triplet
   le plus lisible en basse vision, et celui que retiennent les modes
   contraste eleve des systemes. On repose les jetons plutot que de recrire
   les composants -- toute la page suit, y compris ce qui viendra plus tard. */
html.a11y-contrast {
  --bg: #000;
  --bg-soft: #000;
  --bg-card: #000;
  --bg-elev: #000;
  --bg-hover: #333;
  --bg-input: #000;
  --border: #fff;
  --border-strong: #fff;
  --text: #fff;
  --muted: #ffe873;
  --accent: #ffd400;
  --accent-hover: #ffe14d;
  --accent-soft: rgba(255, 212, 0, .25);
  --accent-text: #ffe873;
  --danger: #ff5a5a;
  --danger-hover: #ff7b7b;
  --danger-soft: #000;
  --ok: #4ae06d;
  --warn: #ffc247;
  --stage: #000;
  --shadow-1: none;
  --shadow-2: 0 0 0 2px #fff;
}
html.a11y-contrast body { background: #000; }
html.a11y-contrast .topbar { background: #000; -webkit-backdrop-filter: none; backdrop-filter: none; }

/* Le fond accentue devient jaune : le texte blanc qu'il portait jusque-la
   disparaitrait dessus. */
html.a11y-contrast .btn.primary,
html.a11y-contrast .btn.active,
html.a11y-contrast .btn.danger,
html.a11y-contrast .chat-msg.mine,
html.a11y-contrast .chat-unread,
html.a11y-contrast .wall-unread,
html.a11y-contrast .wall-win-head .n,
html.a11y-contrast .video-box .box-tools .btn.sound { color: #000; }
html.a11y-contrast .chat-msg.mine { background: var(--accent); }
html.a11y-contrast .btn.primary,
html.a11y-contrast .video-box .box-tools .btn.sound { box-shadow: none; }

html.a11y-contrast .chat-msg.mine .who,
html.a11y-contrast .wall-msg.mine .who b { color: rgba(0, 0, 0, .82); }

html.a11y-contrast .btn:hover:not(:disabled) { background: #333; }
html.a11y-contrast .btn:disabled { opacity: 1; color: #9a9a9a; border-color: #9a9a9a; }
html.a11y-contrast .btn.danger.subtle { color: #ff9a9d; border-color: #ff5a5a; }
html.a11y-contrast input::placeholder { color: #c9c9c9; }
html.a11y-contrast .controls #btn-mic.active,
html.a11y-contrast .controls #btn-cam.active { background: #000; border-color: #ff5a5a; color: #ff9a9d; }
html.a11y-contrast .controls #btn-source-cam.active,
html.a11y-contrast .controls #btn-source-media.active { background: #000; border-color: #ffd400; color: #ffe873; }

/* Pastilles et alertes : leurs teintes sont ecrites en dur, elles ne suivent
   pas les jetons. On les ramene au meme triplet. */
html.a11y-contrast .badge { background: #000; color: #fff; border-color: #fff; }
html.a11y-contrast .badge.on { color: #4ae06d; border-color: #4ae06d; }
html.a11y-contrast .badge.closed { color: #ff8a8a; border-color: #ff8a8a; }
html.a11y-contrast .alert { background: #000; color: #fff; }
html.a11y-contrast .alert.error { border-color: #ff5a5a; color: #ff9a9d; }
html.a11y-contrast .alert.ok { border-color: #4ae06d; color: #8ff1a5; }
html.a11y-contrast .alert.warn { border-color: #ffc247; color: #ffd98a; }
html.a11y-contrast .alert.info { border-color: #ffd400; color: #ffe873; }

/* Surimpressions video : un cadre franc plutot qu'un voile translucide. */
html.a11y-contrast .video-box .tag,
html.a11y-contrast .video-box .state .badge,
html.a11y-contrast .video-box .box-tools .btn {
  background: #000;
  border: 1px solid #fff;
  color: #fff;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
html.a11y-contrast .video-box .box-tools .btn.sound { background: #ffd400; color: #000; }
html.a11y-contrast .video-box { border-width: 2px; border-color: #fff; }
html.a11y-contrast .video-box .placeholder { background: #000; }

/* Mur : tuiles detachees, fenetres et bulles d'alerte. */
html.a11y-contrast .wall-tile.floating,
html.a11y-contrast .wall-win,
html.a11y-contrast .wall-alert,
html.a11y-contrast .wall-picker { background: #000; border-color: #fff; }
html.a11y-contrast .wall-alert span { color: #ffe873; }
html.a11y-contrast .table-cards td { border-bottom-color: #6d6d6d; }

/* ---------------------------------------------------------------- */
/* Reperes de focus renforces                                        */
/* ---------------------------------------------------------------- */

/* Au clavier et sans bonne vue, savoir ou l'on est compte autant que lire :
   un lisere epais et jaune, visible sur tous les fonds du site. */
html.a11y-focus :focus-visible {
  outline: 4px solid #ffd400 !important;
  outline-offset: 3px !important;
  border-radius: 4px;
}
html.a11y-focus input:focus,
html.a11y-focus select:focus,
html.a11y-focus textarea:focus {
  outline: 4px solid #ffd400 !important;
  outline-offset: -2px !important;
}

/* ---------------------------------------------------------------- */
/* Panneau d'accessibilite                                           */
/* ---------------------------------------------------------------- */

/* Son voile se place juste sous le panneau, donc AU-DESSUS des fenetres de
   tchat du mur (60) et de son choix de salles (70) : sans cela, un clic a
   cote tomberait sur une fenetre et ne refermerait rien. */
.a11y-backdrop {
  position: fixed;
  inset: 0;
  z-index: 79;
  background: rgba(0, 0, 0, .55);
  -webkit-tap-highlight-color: transparent;
}

.a11y-panel {
  position: fixed;
  z-index: 80;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(390px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  /* --bg-card et non --bg-elev : les boutons du panneau sont en --bg-elev,
     ils disparaitraient sur un fond de la meme couleur. */
  background: var(--bg-card);
  box-shadow: var(--shadow-2);
}

.a11y-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
  /* Opaque : l en-tete reste collee en haut d un panneau qui defile. */
  background: var(--bg-card);
}
.a11y-head h2 { margin: 0; font-size: 16px; }

.a11y-body { padding: 14px 16px 16px; }

/* Un trait entre les familles de reglages : la lecture, puis la taille, puis
   les couleurs. On retrouve la bonne section sans tout parcourir. */
.a11y-group { padding-bottom: 13px; margin-bottom: 13px; border-bottom: 1px solid var(--border); }
.a11y-group:last-of-type { border-bottom: none; }
.a11y-group .field-inline { display: flex; white-space: normal; margin-bottom: 8px; }
.a11y-group .field-inline:last-child { margin-bottom: 0; }
.a11y-group .hint { margin: 6px 0 0; }

.a11y-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.a11y-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.a11y-row .btn { flex: 1 1 auto; }

/* Le palier courant, entre les deux boutons A- / A+. */
.a11y-size {
  flex: 1 1 auto;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.a11y-keys { margin: 0; line-height: 1.8; }
.a11y-keys b {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
}

@media (max-width: 760px) {
  /* Plein ecran sur telephone : centrer un panneau de reglages sur un petit
     ecran laisse des bandes inutilisables de chaque cote. */
  .a11y-panel {
    top: 0;
    left: 0;
    transform: none;
    width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border-width: 0 0 1px;
  }
}

/* ================================================================= */
/* Spectateur sur telephone : appel plein ecran, discussion en panneau */
/* ================================================================= */

/* Icones propres a cette vue (trace Lucide, licence ISC). */
:root {
  --i-chat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7.9 20A9 9 0 1 0 4 16.1L2 22Z'/%3E%3C/svg%3E");
  --i-close: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E");
}

/* Sur ordinateur, la discussion reste en colonne : ces elements n'existent
   que pour le telephone. */
.chat-toggle, .chat-close, .chat-peek, .chat-scrim { display: none; }

/*
 * Telephone (et telephone tenu en paysage, ecran bas) : la page devient un
 * appel video, comme une application de visio. La vue de l'hote remplit
 * l'ecran, la camera du spectateur flotte en vignette, les commandes sont
 * des boutons ronds poses sur l'image, et la discussion s'ouvre en panneau
 * par-dessus -- au lieu d'etre releguee sous la video, hors de vue.
 */
@media (max-width: 760px), (max-height: 520px) and (pointer: coarse) {
  #room-root.room-viewer {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
    max-width: none;
    padding: 0;
    overflow: hidden;
  }

  /* En-tete reduit a une ligne : nom de la salle et etat de la liaison. */
  .room-viewer .room-head { flex: 0 0 auto; margin: 0; padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right)); }
  .room-viewer .room-title { display: flex; align-items: center; gap: 10px; flex: 1 1 100%; min-width: 0; }
  #room-root.room-viewer .room-title h1 { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .room-viewer .room-meta { flex: 0 0 auto; }
  .room-viewer .room-meta > span:not(.badge),
  .room-viewer .room-meta .code { display: none; }

  /* Les avis flottent sous la barre au lieu de pousser la video. */
  /* Sous le panneau de discussion (61-62) : un avis ne cache pas la saisie. */
  .room-viewer #flash { position: fixed; z-index: 60; top: calc(var(--topbar-h) + 8px); left: 12px; right: 12px; }
  /* Fond opaque : l'avis passe par-dessus l'en-tete et l'image. Un toucher le
     ferme (voir flash() dans viewer.js). */
  .room-viewer #flash .alert { background-color: var(--bg-elev); box-shadow: var(--shadow-2); cursor: pointer; }

  .room-viewer .stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 0; }
  .room-viewer .stage-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .room-viewer .stage-hint { display: none; }

  #room-root.room-viewer .stage-frame {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--stage);
    box-shadow: none;
    overflow: hidden;
  }

  /* La vue de l'hote occupe tout le cadre, quel que soit le format du flux. */
  #room-root.room-viewer .videos { position: absolute; inset: 0; display: block; }
  #room-root.room-viewer .videos.focus-mode .video-box.focused {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
  }

  /* Vignette en haut a droite : le bas de l'ecran revient aux commandes. */
  #room-root.room-viewer .videos.focus-mode .video-box.minimized {
    top: 12px;
    right: 12px;
    bottom: auto;
    width: 30%;
    min-width: 96px;
    max-width: 160px;
    max-height: 42%;
    border-radius: 14px;
  }
  #room-root.room-viewer .videos.focus-mode .video-box.minimized[data-orient="portrait"] { width: 26%; min-width: 84px; max-width: 130px; }

  /* « Agrandir » remettrait les deux videos cote a cote : sans objet ici. */
  .room-viewer .box-tools [data-zoom] { display: none !important; }
  /* Outils de la vue de l'hote en colonne a gauche, sous l'etiquette : a
     droite, la vignette les recouvrirait. */
  #room-root.room-viewer .video-box.focused .box-tools {
    top: 46px;
    left: 10px;
    right: auto;
    flex-direction: column;
    align-items: flex-start;
  }

  /* Barre d'appel : boutons ronds sur un degrade, a portee de pouce. */
  #room-root.room-viewer .controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    margin: 0;
    padding: 36px 16px calc(16px + env(safe-area-inset-bottom));
    gap: 20px;
    flex-wrap: nowrap;
    justify-content: center;
    background: linear-gradient(to top, rgba(5, 6, 10, .82), rgba(5, 6, 10, 0));
    pointer-events: none;
  }
  #room-root.room-viewer .controls .btn {
    pointer-events: auto;
    position: relative;
    flex: 0 0 auto;
    justify-content: center;
    width: 60px;
    height: 60px;
    min-height: 0;
    padding: 0;
    border-radius: 50%;
    /* Le libelle reste le nom accessible du bouton ; seule l'icone se voit. */
    font-size: 0;
    color: #fff;
    background: rgba(32, 36, 48, .74);
    border: 1px solid rgba(255, 255, 255, .16);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  }
  #room-root.room-viewer .controls .btn::before { width: 25px; height: 25px; }
  #room-root.room-viewer .controls #btn-mic.active,
  #room-root.room-viewer .controls #btn-cam.active { background: #ef4444; border-color: #ef4444; color: #fff; }

  #room-root.room-viewer .controls .chat-toggle { display: inline-flex; --icon: var(--i-chat); }
  #room-root.room-viewer .controls .chat-toggle[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); }
  .chat-toggle-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    border: 2px solid var(--stage);
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* Apercu du dernier message, au-dessus des commandes. */
  .room-viewer .chat-peek {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    position: absolute;
    z-index: 6;
    left: 14px;
    right: 14px;
    bottom: calc(108px + env(safe-area-inset-bottom));
    max-width: 440px;
    margin: 0 auto;
    padding: 10px 14px;
    font: inherit;
    font-size: 14.5px;
    line-height: 1.4;
    text-align: left;
    color: #fff;
    background: rgba(22, 25, 35, .9);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 18px 18px 18px 6px;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-2);
    cursor: pointer;
    animation: msg-in .2s ease-out;
  }
  .chat-peek-who { font-size: 12px; font-weight: 650; color: var(--accent-text); }
  .chat-peek-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
  }

  /* Discussion : panneau qui monte du bas. La video reste visible au-dessus.
     --kb et --vvh suivent le clavier virtuel (voir viewer.js). */
  .room-viewer .chat-scrim { display: block; position: fixed; inset: 0; z-index: 61; background: rgba(0, 0, 0, .38); }
  #room-root.room-viewer .stage-chat {
    position: fixed;
    z-index: 62;
    left: 0;
    right: 0;
    bottom: var(--kb, 0px);
    height: 72vh;
    height: min(72dvh, calc(var(--vvh, 100dvh) - 48px));
    transform: translateY(calc(100% + 24px));
    visibility: hidden;
    transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
  }
  #room-root.room-viewer .stage-chat.open {
    transform: none;
    visibility: visible;
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  }
  #room-root.room-viewer .stage-chat > .card {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 8px max(14px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    box-shadow: 0 -14px 44px rgba(0, 0, 0, .55);
  }
  /* Repere visuel de panneau. */
  #room-root.room-viewer .stage-chat > .card::before {
    content: "";
    flex: 0 0 auto;
    align-self: center;
    width: 40px;
    height: 5px;
    margin: 2px 0 10px;
    border-radius: 3px;
    background: var(--border-strong);
  }
  #room-root.room-viewer .stage-chat .chat-head { flex-wrap: nowrap; gap: 6px; margin-bottom: 10px; }
  #room-root.room-viewer .stage-chat .chat-head h2 { font-size: 17px; }
  #room-root.room-viewer .stage-chat .chat-log { flex: 1 1 auto; height: auto; min-height: 0; }
  #room-root.room-viewer .stage-chat .chat-form ~ .hint { display: none; }
  #room-root.room-viewer .stage-chat .chat-form input { font-size: 16px; min-height: 46px; }
  #room-root.room-viewer .stage-chat .chat-form .btn { min-height: 46px; }
  #room-root.room-viewer .chat-close { display: inline-flex; justify-content: center; width: 36px; height: 36px; padding: 0; border-radius: 50%; --icon: var(--i-close); }
  #room-root.room-viewer .chat-close::before { width: 18px; height: 18px; }
}

/* Ecran etroit : alertes et accessibilite reduites a leur emoji, pour que
   l'en-tete du panneau tienne sur une ligne. Le libelle (.lbl) reste lu par
   les lecteurs d'ecran. */
@media (max-width: 420px) {
  #room-root.room-viewer .stage-chat .chat-head .lbl {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  #room-root.room-viewer .stage-chat .chat-head #chat-alerts,
  #room-root.room-viewer .stage-chat .chat-head #chat-a11y {
    width: 38px;
    height: 36px;
    padding: 0;
    justify-content: center;
    font-size: 16px;
  }
}

/* Telephone en paysage : la discussion s'ouvre sur le cote droit. */
@media (max-height: 520px) and (pointer: coarse) and (orientation: landscape) {
  #room-root.room-viewer .stage-chat {
    top: 0;
    left: auto;
    bottom: 0;
    width: min(400px, 52vw);
    height: auto;
    transform: translateX(calc(100% + 24px));
  }
  #room-root.room-viewer .stage-chat > .card { border-radius: 22px 0 0 22px; padding-top: 14px; }
  #room-root.room-viewer .stage-chat > .card::before { display: none; }
  #room-root.room-viewer .controls { padding-top: 24px; padding-bottom: 10px; }
  #room-root.room-viewer .controls .btn { width: 52px; height: 52px; }
  .room-viewer .chat-peek { bottom: 80px; }
}
