:root {
  --bg: #141b2b;
  --card: #1f2940;
  --card-2: #27324d;
  --ink: #f3f5fa;
  --ink-2: #a9b3c9;
  --line: #34405e;
  --accent: #f2b544;
  --fr: #3f7fe0;
  --de: #e0473f;
  --ok: #44b37a;
  --bad: #e0573f;
  --radius: 14px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
i { font-style: italic; color: var(--ink-2); font-weight: 400; }
[hidden] { display: none !important; }

/* ---------- accueil ---------- */
#join { height: 100%; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: radial-gradient(1200px 600px at 20% 0%, #24365c 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 100%, #3a2a3c 0%, transparent 60%), var(--bg); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.join-card { width: min(460px, 100%); padding: 24px 22px; }
.join-card h1 { margin: 0; font-size: 26px; line-height: 1.15; letter-spacing: -.01em; }
.join-card h1 .sep { color: var(--accent); }
.join-card h1 .de { color: #ffd9d6; }
.lead { margin: 6px 0 18px; color: var(--ink-2); }
.bridge { color: var(--accent); font-weight: 700; padding: 0 4px; }
.field { display: block; margin: 14px 0; }
.lbl { display: block; margin-bottom: 6px; font-size: 14px; }
.lbl i { margin-left: 6px; }
input, textarea { width: 100%; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; outline: none; font-size: 16px; }
input:focus, textarea:focus { border-color: var(--accent); }
.langs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lang-btn { background: var(--card-2); border: 2px solid var(--line); border-radius: 12px; padding: 12px 10px;
  cursor: pointer; text-align: left; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.lang-btn.on { border-color: var(--accent); background: #33405f; }
.chip { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px; color: #fff; letter-spacing: .03em; }
.chip.fr { background: var(--fr); } .chip.de { background: var(--de); }
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors button { width: 33px; height: 33px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.colors button.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
details.teacher { margin: 10px 0 16px; color: var(--ink-2); font-size: 14px; }
details.teacher summary { cursor: pointer; margin-bottom: 8px; }
.primary { background: var(--accent); color: #1c1606; border: 0; border-radius: 12px; padding: 12px 16px;
  font-weight: 800; cursor: pointer; width: 100%; font-size: 16px; }
.primary i { color: #5a4512; }
.primary:disabled { opacity: .45; cursor: default; }
.primary.small { width: auto; padding: 8px 12px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer; }
.err { color: #ff9b8d; min-height: 1em; margin: 10px 0 0; font-size: 14px; }

/* ---------- jeu ---------- */
#game { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: pointer; }
.pill { position: absolute; background: rgba(20,27,43,.86); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; backdrop-filter: blur(6px); }
.pill.btn { cursor: pointer; }
#hud-place { top: calc(12px + env(safe-area-inset-top)); left: 12px; max-width: calc(100vw - 190px); }
#hud-place b { margin-right: 6px; }
#hud-online { top: calc(54px + env(safe-area-inset-top)); left: 12px; }
.list { position: absolute; top: calc(94px + env(safe-area-inset-top)); left: 12px; width: min(300px, calc(100vw - 24px));
  max-height: 50vh; overflow: auto; padding: 8px; font-size: 14px; }
.list .row { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 8px; }
.list .row .where { margin-left: auto; color: var(--ink-2); font-size: 12px; text-align: right; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#hud-tools { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; display: flex; flex-direction: column; gap: 8px; }
.round { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: rgba(20,27,43,.86);
  font-size: 22px; cursor: pointer; display: grid; place-items: center; }
.round.small { width: 38px; height: 38px; font-size: 14px; font-weight: 800; align-self: center; }
.round.on { background: var(--accent); color: #1c1606; }

#toast { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: var(--bad); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 700; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: calc(100vw - 140px); }
#toast i { color: #ffe1dc; display: block; font-size: 13px; }

.close { position: absolute; top: 6px; right: 8px; border: 0; background: transparent; font-size: 24px; cursor: pointer; color: var(--ink-2); }
.sign, .prompt { position: absolute; left: 12px; bottom: 12px; width: min(420px, calc(100vw - 24px)); padding: 16px 18px 14px; }
.sign { border-color: #8a6a3f; background: #2b2619; }
.sign h3, .prompt h3 { margin: 0 0 2px; font-size: 18px; padding-right: 22px; }
.sign h4, .prompt h4 { margin: 0 0 10px; font-size: 15px; font-weight: 600; color: var(--ink-2); font-style: italic; }
.sign p { margin: 0 0 8px; line-height: 1.4; }
.sign p.sec { color: var(--ink-2); font-style: italic; font-size: 14px; }
.board { white-space: pre-wrap; background: #24392f; border: 6px solid #6b4a2b; border-radius: 6px; padding: 10px 12px;
  margin: 8px 0; font-family: "Chalkboard SE", "Comic Sans MS", ui-rounded, sans-serif; color: #f4f1e6; }
.prompt { border-color: #3a6d58; background: #1c3029; }
.prompt .tag { font-size: 12px; font-weight: 800; letter-spacing: .06em; color: #8fe0b5; text-transform: uppercase; }
.prompt .q { font-size: 19px; font-weight: 700; margin: 6px 0 4px; line-height: 1.3; }
.prompt .q2 { color: var(--ink-2); font-style: italic; margin-bottom: 10px; }

.chat { position: absolute; right: 12px; bottom: 12px; width: min(360px, calc(100vw - 24px)); display: flex; flex-direction: column;
  max-height: min(46vh, 420px); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 8px; background: var(--card-2); border: 0; border-bottom: 1px solid var(--line);
  padding: 9px 12px; text-align: left; cursor: pointer; font-size: 13px; }
.chat-head .caret { margin-left: auto; color: var(--ink-2); }
.chat.closed #chat-log, .chat.closed #chat-form { display: none; }
.chat.closed .caret { transform: rotate(180deg); }
#chat-log { overflow-y: auto; padding: 8px 12px; flex: 1; min-height: 90px; font-size: 14px; line-height: 1.35; }
#chat-log .m { margin: 0 0 7px; word-wrap: break-word; }
#chat-log .m .who { font-weight: 800; margin-right: 4px; }
#chat-log .m .scope { font-size: 11px; color: var(--ink-2); margin-left: 4px; }
#chat-log .m.watch { opacity: .55; }
#chat-log .m.info { color: var(--ink-2); font-style: italic; font-size: 13px; }
#chat-log .m.annonce { background: #3a3218; border-radius: 8px; padding: 6px 8px; }
#chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
#chat-form input { padding: 9px 10px; }
#chat-form input:disabled { opacity: .5; }

.modal { position: absolute; inset: 0; z-index: 20; background: rgba(8,10,18,.6); display: grid; place-items: center; padding: 16px; }
.modal .card { padding: 18px; width: min(460px, 100%); }
.modal h3 { margin: 0 0 12px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.modal .row .primary { width: auto; }

@media (max-width: 700px) {
  .chat { max-height: 38vh; }
  .sign, .prompt { bottom: auto; top: calc(96px + env(safe-area-inset-top)); }
}

/* ---------- audio / vidéo ---------- */
#media-wrap { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: calc(100vw - 260px); pointer-events: none; }
#media { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
#media-wrap > * { pointer-events: auto; }
.tile { position: relative; width: 150px; height: 112px; border-radius: 12px; overflow: hidden; background: #0d1220;
  border: 2px solid var(--line); box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.tile.big { width: 280px; height: 210px; border-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #0d1220; }
.tile.me video { transform: scaleX(-1); }
.tile .face { position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%; display: none;
  place-items: center; font-weight: 800; font-size: 24px; color: #fff; }
.tile.nocam video { visibility: hidden; }
.tile.nocam .face { display: grid; }
.tile.wait { opacity: .6; }
.tile .tag { position: absolute; left: 4px; bottom: 4px; right: 4px; font-size: 11px; font-weight: 700; color: #fff;
  text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .tag .chip { font-size: 9px; padding: 1px 4px; }
#media-banner { background: rgba(20,27,43,.9); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; text-align: center; }
.round.off { background: #7a2b22; border-color: #b4483b; }
#toast.info { background: #2f6fcf; }

/* ---------- tableau de bord enseignant ---------- */
.teacher-panel { position: absolute; left: 12px; top: calc(94px + env(safe-area-inset-top)); width: min(400px, calc(100vw - 24px));
  max-height: calc(100vh - 120px); overflow: auto; padding: 14px 14px 12px; z-index: 5; }
.teacher-panel h3 { margin: 0 0 10px; font-size: 17px; padding-right: 24px; }
.teacher-panel h4 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.teacher-panel .acts { display: grid; gap: 6px; }
.teacher-panel .acts button { text-align: left; }
.teacher-panel .trow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.teacher-panel .tname { flex: 1; font-size: 14px; min-width: 0; }
.teacher-panel .cnt { color: var(--ink-2); font-size: 12px; margin-left: 4px; }
.teacher-panel .who { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 3px; }
.teacher-panel .who .chip { font-size: 10px; }
.teacher-panel .trow button { flex: none; font-size: 13px; padding: 6px 10px; }
.teacher-panel .wide { width: 100%; margin-top: 12px; }
.teacher-panel .muted { color: var(--ink-2); font-size: 13px; margin: 4px 0; }

@media (max-width: 700px) {
  #media-wrap { max-width: calc(100vw - 80px); left: calc(50% - 20px); top: calc(96px + env(safe-area-inset-top)); }
  .tile { width: 96px; height: 72px; }
  .tile.big { width: 180px; height: 135px; }
}

/* ---------- caméra / micro : accueil et réglages ---------- */
.av-setup { display: flex; gap: 10px; align-items: stretch; }
.av-preview { position: relative; width: 150px; height: 112px; border-radius: 12px; overflow: hidden; background: #0d1220;
  border: 1px solid var(--line); flex: none; }
.av-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.av-preview.small { width: 100%; height: 170px; margin-bottom: 8px; }
.av-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 8px; font-size: 12px;
  color: var(--ink-2); pointer-events: none; }
.av-msg.err { color: #ffb4a8; background: rgba(13,18,32,.85); }
.av-ctl { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.av-ctl.row2 { flex-direction: row; margin: 8px 0; }
.av-ctl.row2 .toggle { flex: 1; }
.toggle { background: var(--card-2); border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer;
  text-align: left; font-size: 14px; }
.toggle.on { border-color: var(--ok); background: #1f3a30; }
.toggle:not(.on) { border-color: #b4483b; background: #3a1f1c; text-decoration: line-through; text-decoration-color: rgba(255,255,255,.4); }
.toggle i { font-size: 12px; }
.meter { height: 8px; border-radius: 4px; background: #0d1220; border: 1px solid var(--line); overflow: hidden; }
.meter.wide { margin: 2px 0 4px; }
.meter > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--accent)); transition: width .08s; }
.avpanel { position: absolute; right: 70px; top: calc(12px + env(safe-area-inset-top)); width: min(340px, calc(100vw - 90px));
  padding: 14px; z-index: 6; max-height: calc(100vh - 30px); overflow: auto; }
.avpanel h3 { margin: 0 0 10px; font-size: 16px; padding-right: 24px; }
.sel { display: block; margin: 8px 0; font-size: 13px; }
.sel span { display: block; margin-bottom: 4px; }
select { width: 100%; background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: var(--ink); font: inherit; }
.hint { font-size: 12px; color: var(--ink-2); margin: 8px 0 0; line-height: 1.4; }

/* ---------- configuration enseignant ---------- */
.config-card { width: min(720px, 100%) !important; max-height: calc(100vh - 32px); display: flex; flex-direction: column; position: relative; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.tabs button { background: transparent; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--ink-2); font-weight: 700; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
#cfg-body { overflow: auto; flex: 1; padding-right: 4px; }
#cfg-body .frow { display: grid; grid-template-columns: 1fr 1fr 80px; gap: 6px; margin-bottom: 6px; align-items: center; }
#cfg-body .frow.head { font-size: 12px; color: var(--ink-2); font-weight: 700; }
#cfg-body .frow input { padding: 7px 9px; font-size: 14px; }
#cfg-body .opt { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 15px; }
#cfg-body .opt input[type=checkbox] { width: 20px; height: 20px; }
#cfg-body .opt input[type=range] { flex: 1; }
#cfg-body .opt input[type=number], #cfg-body .opt input[type=text] { width: 110px; }
#cfg-body .signbox { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#cfg-body .signbox textarea { min-height: 70px; font-size: 14px; }
#cfg-body .signbox input { font-size: 14px; padding: 7px 9px; }
#cfg-body textarea.prompts { min-height: 160px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
#cfg-body .help { font-size: 12px; color: var(--ink-2); margin: 4px 0 10px; }
@media (max-width: 700px) {
  .av-setup { flex-direction: column; }
  .av-preview { width: 100%; height: 150px; }
  #cfg-body .frow { grid-template-columns: 1fr 1fr 60px; }
  #cfg-body .signbox { grid-template-columns: 1fr; }
  .avpanel { right: 12px; width: calc(100vw - 24px); top: calc(96px + env(safe-area-inset-top)); }
}

.teacher-panel .pick-btns { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.teacher-panel .pick-btns button { padding: 4px 10px; font-size: 13px; }
.teacher-panel .picks { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px; }
.teacher-panel .prow { display: flex; align-items: center; gap: 6px; padding: 5px 2px; font-size: 14px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.04); }
.teacher-panel .prow input { width: 18px; height: 18px; flex: none; }
.teacher-panel .prow .where { margin-left: auto; color: var(--ink-2); font-size: 12px; }
.teacher-panel .sendrow { display: flex; gap: 6px; margin-top: 8px; }
.teacher-panel .sendrow select { flex: 1; min-width: 0; }
.teacher-panel .sendrow button:disabled { opacity: .45; }
