:root {
  --paper: #eef1f2;
  --card: #ffffff;
  --line: #d5dbde;
  --ink: #16181d;
  --soft: #5d6670;
  --honey: #ffc21a;
  --live: #0f7a74;
  --mute: #d8432f;
  --display: "Unbounded", system-ui, sans-serif;
  --body: "Instrument Sans", system-ui, sans-serif;
  --on-ink: #ffffff;
  --field: #ffffff;
  --ink-hover: #2c3038;
  --empty: #e1e6e8;
  --hexagon: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  color-scheme: light;
}

/* Mode sombre : noir et jaune */
:root[data-theme="dark"] {
  --paper: #0a0a0a;
  --card: #151512;
  --line: #3a3417;
  --ink: #ffcc1f;
  --soft: #b39a3c;
  --live: #ffd84d;
  --mute: #ff6a4d;
  --on-ink: #0a0a0a;
  --field: #0f0f0d;
  --ink-hover: #ffdd66;
  --empty: #26230f;
  color-scheme: dark;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--body);
}

button, input, select { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sprite { position: absolute; width: 0; height: 0; }

.brand { display: flex; align-items: center; gap: 10px; font: 700 18px var(--display); letter-spacing: -0.03em; }
.logo { width: 26px; height: 26px; fill: var(--honey); stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }

/* ───── Accueil : le seul grand aplat de la page ───── */

.join {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  background-color: var(--honey);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='55.43' height='96'%3E%3Cpath d='M0 16L27.71 0L55.43 16M0 16V48M55.43 16V48M0 48L27.71 64L55.43 48M27.71 64V96' fill='none' stroke='%23f0b300' stroke-width='1.5'/%3E%3C/svg%3E");
  background-size: 110.86px 192px;
}
.join .logo { fill: var(--ink); stroke: none; }

.join-hero {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 48px;
  padding: clamp(24px, 5vw, 72px);
}
.join h1 {
  margin: 0 0 20px;
  max-width: 13ch;
  font: 700 clamp(30px, 4.4vw, 58px) / 1.04 var(--display);
  letter-spacing: -0.045em;
}
.lede { margin: 0; max-width: 44ch; font-size: 18px; line-height: 1.45; }
.hero-text { margin-block: auto; }

.join-panel {
  display: grid;
  align-content: center;
  padding: clamp(24px, 4vw, 56px);
  background: var(--card);
}
.join-panel form { width: min(380px, 100%); }
.join-panel h2 { margin: 0 0 24px; font: 700 22px var(--display); letter-spacing: -0.03em; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 20px; padding: 0; border: 0; }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: block;
  padding: 12px;
  text-align: center;
  font-weight: 600;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
}
.seg input:checked + span { background: var(--ink); color: var(--on-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--honey); outline-offset: 2px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
input:not([type="radio"]):not([type="range"]), select {
  width: 100%;
  padding: 12px 14px;
  background: var(--field);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  font-weight: 400;
  font-size: 16px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--honey); outline-offset: 2px; }

.join[data-role="student"] .t { display: none; }

.go {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: var(--on-ink);
  font: 700 15px var(--display);
  letter-spacing: -0.02em;
  cursor: pointer;
}
.go:hover { background: var(--ink-hover); }
.go:disabled { opacity: 0.5; cursor: wait; }
.go.small { width: auto; margin: 0; padding: 10px 16px; font-size: 14px; }
.err { min-height: 1.5em; margin: 12px 0 0; color: var(--mute); font-size: 14px; font-weight: 500; }

@media (max-width: 800px) {
  .join { grid-template-columns: 1fr; }
  .join-hero { gap: 28px; }
}

/* ───── Classe ───── */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.room-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.who { margin-left: auto; color: var(--soft); font-size: 14px; }
.net { display: flex; align-items: center; gap: 6px; color: var(--live); font-size: 13px; font-weight: 600; }
.net::before { content: ""; width: 9px; height: 10px; background: currentColor; clip-path: var(--hexagon); }
.net.bad { color: var(--mute); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  padding: 20px 24px 96px;
}

.switch select { width: auto; max-width: 260px; padding: 6px 10px; font-size: 14px; font-weight: 600; }
.lobby { max-width: 760px; margin: 0 auto; padding: 20px 24px 40px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .lobby { padding: 14px; }
  .bar { padding: 10px 14px; }
}

.pane { padding: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.pane h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font: 700 15px var(--display); letter-spacing: -0.03em; }
.count { margin-left: auto; color: var(--soft); font: 500 13px var(--body); letter-spacing: 0; }
.hex {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 34px;
  background: var(--honey);
  clip-path: var(--hexagon);
  color: #16181d;
  font: 700 13px var(--display);
  font-style: normal;
}
.hex.empty { background: var(--empty); color: var(--soft); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.tiles.big { grid-template-columns: 1fr; }
.tiles:empty { display: block; }
.tiles:empty::before,
.rooms:empty::before {
  content: attr(data-empty);
  display: block;
  padding: 44px 16px;
  text-align: center;
  color: var(--soft);
  border: 1.5px dashed var(--line);
  border-radius: 10px;
}

.tile { position: relative; margin: 0; aspect-ratio: 16 / 10; overflow: hidden; background: #1c2024; border-radius: 10px; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.cam-off video { visibility: hidden; }
.avatar { position: absolute; inset: 0; display: none; place-items: center; color: var(--honey); font: 700 40px var(--display); }
.tile.cam-off .avatar { display: grid; }
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  box-shadow: inset 0 0 0 3px var(--live);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.tile.speaking::after { opacity: 1; }
.tile figcaption {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 8px;
  background: rgba(22, 24, 29, 0.8);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}
.tile .dot { width: 9px; height: 10px; background: var(--honey); clip-path: var(--hexagon); }
.tile.mic-off .dot { background: var(--mute); }
.tile.screen { grid-column: 1 / -1; aspect-ratio: 16 / 9; background: #000; }
.tile.screen video { object-fit: contain; }
.tiles.big:has(.screen) .tile:not(.screen) { max-width: 260px; } /* la caméra du prof passe en vignette */

/* Agrandir : bouton en haut à droite de chaque tuile, visible au survol (toujours sur écran tactile). */
.expand {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: rgba(22, 24, 29, 0.75);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.expand svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.expand .shrink { display: none; }
.tile:hover .expand, .expand:focus-visible { opacity: 1; }
@media (hover: none) { .expand { opacity: 1; } }

.tile:fullscreen, .tile.expanded { aspect-ratio: auto; border-radius: 0; background: #000; }
.tile.expanded { position: fixed; inset: 0; z-index: 40; max-width: none !important; }
.tile:fullscreen video, .tile.expanded video { object-fit: contain; }
.tile:fullscreen .expand, .tile.expanded .expand { opacity: 1; }
.tile:fullscreen .grow, .tile.expanded .grow { display: none; }
.tile:fullscreen .shrink, .tile.expanded .shrink { display: block; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.controls:empty { display: none; }

.tog, .ghost {
  padding: 9px 14px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.ghost { background: transparent; }
.tog:hover, .ghost:hover { border-color: var(--ink); }
.tog::before { content: ""; display: inline-block; width: 9px; height: 10px; margin-right: 8px; background: var(--mute); clip-path: var(--hexagon); }
.tog[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.tog[aria-pressed="true"]::before { background: var(--honey); }

.vol { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--soft); font-size: 13px; }
input[type="range"] { width: 110px; accent-color: var(--ink); }

/* ───── Salles disponibles ───── */

.rooms { display: grid; gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.room-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.room-info { display: grid; gap: 1px; min-width: 0; margin-right: auto; }
.room-info b { font: 700 14px var(--display); letter-spacing: -0.03em; overflow-wrap: anywhere; }
.room-info small { color: var(--soft); font-size: 13px; }
.room-info .names { color: var(--ink); }
.room-actions { display: flex; align-items: center; gap: 8px; }
.live { display: flex; align-items: center; gap: 6px; color: var(--live); font-size: 13px; font-weight: 600; white-space: nowrap; }
.live::before { content: ""; width: 9px; height: 10px; background: currentColor; clip-path: var(--hexagon); }

.create { display: flex; gap: 8px; }
.create input:not([type="radio"]) { flex: 1; min-width: 0; padding: 10px 12px; font-size: 15px; }

@media (max-width: 520px) {
  .room-card { flex-wrap: wrap; }
  .room-info { flex: 1 1 calc(100% - 42px); }
  .room-actions { flex-basis: 100%; justify-content: flex-end; }
}

/* ───── Fil de discussion ───── */

/* Les boutons restent en bas à droite ; le fil se déploie au-dessus. */
.dock {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Son bloqué par le navigateur : petit bouton à gauche de « Discussion ». */
.gate {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--honey);
  color: #16181d;
  box-shadow: 0 6px 20px rgba(22, 24, 29, 0.25);
  cursor: pointer;
  animation: nudge 1.6s ease-in-out infinite;
}
.gate svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes nudge { 50% { box-shadow: 0 0 0 6px rgba(255, 194, 26, 0.35), 0 6px 20px rgba(22, 24, 29, 0.25); } }

.chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--on-ink);
  font: 700 14px var(--display);
  box-shadow: 0 6px 20px rgba(22, 24, 29, 0.25);
  cursor: pointer;
}
.chat-toggle::before { content: ""; width: 10px; height: 11px; background: var(--honey); clip-path: var(--hexagon); }
.chat-toggle[aria-expanded="true"] { background: var(--ink-hover); }
.unread {
  min-width: 20px;
  padding: 1px 6px;
  color: #fff;
  background: var(--mute);
  border-radius: 999px;
  font: 600 12px var(--body);
  text-align: center;
}

.chat {
  position: fixed;
  right: 20px;
  bottom: 80px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100vw - 40px));
  height: min(540px, calc(100vh - 150px));
  box-shadow: 0 12px 40px rgba(22, 24, 29, 0.18);
}
.chat .close { margin-left: auto; padding: 4px 10px; font-size: 13px; }
.chat-list {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 12px;
  margin: 0 0 12px;
  padding: 0 4px 0 0;
  overflow-y: auto;
  list-style: none;
}
.chat-list:empty::before {
  content: attr(data-empty);
  padding: 28px 12px;
  text-align: center;
  color: var(--soft);
  border: 1.5px dashed var(--line);
  border-radius: 10px;
}
.msg-head { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.msg-head b { font-weight: 600; }
.msg-head time { color: var(--soft); font-size: 12px; }
.msg.mine .msg-head b { color: var(--live); }
.msg p { margin: 2px 0 0; overflow-wrap: anywhere; }
.badge { padding: 0 6px; background: var(--honey); color: #16181d; border-radius: 4px; font-size: 11px; font-weight: 600; }

@media (max-width: 520px) {
  .chat { right: 10px; left: 10px; width: auto; bottom: 76px; height: calc(100vh - 140px); }
  .dock { right: 14px; bottom: 14px; }
}

/* ───── Retours ───── */

.toasts { position: fixed; left: 20px; bottom: 20px; z-index: 20; display: grid; gap: 8px; }
.toast { max-width: 320px; padding: 12px 16px; background: var(--ink); border-radius: 8px; color: var(--on-ink); font-size: 14px; }
/* ───── Bouton de thème (présent sur toutes les vues) ───── */

.theme-toggle {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--ink); }
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

/* Accueil : le bouton flotte en haut à droite, au-dessus du panneau. */
.theme-toggle.floating { position: absolute; top: 16px; right: 16px; z-index: 30; background: var(--card); border-color: var(--ink); }

:root[data-theme="dark"] .join {
  background-color: #0a0a0a;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='55.43' height='96'%3E%3Cpath d='M0 16L27.71 0L55.43 16M0 16V48M55.43 16V48M0 48L27.71 64L55.43 48M27.71 64V96' fill='none' stroke='%2333290a' stroke-width='1.5'/%3E%3C/svg%3E");
}

/* ───── Volume individuel sur chaque vignette ───── */

.tile-vol {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 4px;
  background: rgba(22, 24, 29, 0.8);
  border-radius: 8px;
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s;
}
.tile:hover .tile-vol, .tile-vol:focus-within { opacity: 1; }
@media (hover: none) { .tile-vol { opacity: 1; } }
.tile:fullscreen .tile-vol, .tile.expanded .tile-vol { opacity: 1; }
.vol-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
}
.vol-btn:hover { background: rgba(255, 255, 255, 0.15); }
.vol-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile-vol .cross { display: none; }
.tile-vol.off .cross { display: block; }
.tile-vol.off .waves { display: none; }
.tile-vol input[type="range"] { width: 76px; accent-color: #ffc21a; }

.device-wrap { min-width: 0; }
.device {
  max-width: 190px;
  padding: 9px 10px;
  background: var(--field);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: 500 13px var(--body, inherit);
  text-overflow: ellipsis;
  cursor: pointer;
}
.device:hover, .device:focus-visible { border-color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
