:root {
  --bg: #202540;
  --bg-deep: #191d33;
  --panel: #282d4e;
  --panel-2: #333a64;
  --panel-3: #3e4678;
  --border: #454c80;
  --text: #ffffff;
  --muted: #a7add2;
  --green: #06d6a0;
  --green-dark: #04a77d;
  --purple: #7b6cff;
  --red: #ff5c64;
  --yellow: #ffcf5c;
  --radius: 14px;
  font-family: 'DM Sans', system-ui, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg-deep); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
kbd {
  display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 6px;
  background: var(--panel-3); border-bottom: 2px solid #20244a; font: 700 12px 'DM Sans', sans-serif; text-align: center;
}
.muted { color: var(--muted); }

/* ---------- Accueil ---------- */
#join {
  position: fixed; inset: 0; display: flex; overflow-y: auto; padding: 16px;
  background:
    radial-gradient(circle at 20% 20%, rgba(123, 108, 255, .25), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(6, 214, 160, .18), transparent 40%),
    var(--bg);
  z-index: 50;
}
.join-card {
  margin: auto; width: min(560px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 22px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 26px; }
.brand-dot { width: 18px; height: 18px; border-radius: 6px; background: linear-gradient(135deg, var(--green), var(--purple)); }
.join-sub { color: var(--muted); margin: 6px 0 22px; }
.join-body { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.preview-wrap {
  flex: 0 0 140px; height: 170px; border-radius: 18px; display: grid; place-items: center;
  background: repeating-linear-gradient(0deg, #c8a273 0 8px, #bf9868 8px 16px);
  border: 3px solid var(--panel-3);
}
#preview { width: 96px; height: 144px; image-rendering: pixelated; cursor: pointer; }
#joinForm { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input {
  width: 100%; min-width: 0; background: var(--bg); border: 2px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--purple); }
.field label small { font-weight: 400; }
.room-row { display: flex; gap: 8px; }
.room-row input { flex: 1; min-width: 0; }
.btn-ghost {
  display: flex; align-items: center; gap: 6px; padding: 0 12px; border-radius: 10px; white-space: nowrap;
  background: var(--panel-2); color: var(--text); font-size: 13px; font-weight: 700;
}
.btn-ghost svg { width: 16px; height: 16px; }
.btn-ghost:hover { background: var(--panel-3); }
.btn-ghost .copied-label, .btn-ghost.done .copy-label { display: none; }
.btn-ghost.done .copied-label { display: inline; color: var(--green); }
.room-link { font-size: 12px; color: var(--muted); word-break: break-all; font-weight: 400; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button {
  padding: 6px 12px; border-radius: 999px; background: var(--bg); border: 2px solid var(--border);
  font-size: 13px; font-weight: 500; color: var(--text);
}
.chips button:hover { border-color: var(--panel-3); }
.chips button.sel { border-color: var(--purple); background: rgba(123, 108, 255, .2); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button {
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid transparent; outline: 2px solid transparent;
}
.swatches button.sel { border-color: var(--panel); outline-color: #fff; }
.btn-primary {
  background: var(--green); color: #10213a; font-weight: 700; padding: 12px 16px; border-radius: 12px; font-size: 15px;
  box-shadow: 0 4px 0 var(--green-dark);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--green-dark); }
.me-pill:hover { background: var(--panel-2); }
.profile-actions { display: flex; gap: 8px; }
.profile-actions .btn-ghost { flex: 1; justify-content: center; padding: 10px; }
#people li.me-row, #people li.join-row { cursor: pointer; }
.join-link { cursor: pointer; }
.join-link:hover { color: var(--green); text-decoration: underline; text-underline-offset: 2px; }
.join-note { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- Monde ---------- */
#app { position: fixed; inset: 0; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; touch-action: none; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.ptt { -webkit-user-select: none; -webkit-touch-callout: none; }
#bar .touch-only { display: none; }
@media (pointer: coarse) { #bar .touch-only { display: grid; } }

#zoneTag {
  position: absolute; top: 14px; left: 14px; padding: 8px 14px; border-radius: 999px;
  background: rgba(32, 37, 64, .9); font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: center;
  border: 1px solid var(--border);
}
#zoneTag .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
#zoneTag.desk .dot { background: var(--purple); }
#zoneTag.main .dot { background: var(--yellow); }
#zoneTag.class .dot { background: var(--green); }
#zoneTag small { font-weight: 400; color: var(--muted); }

#broadcast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--yellow); color: #2a2200; font-weight: 700; padding: 8px 16px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3); font-size: 14px; z-index: 5;
}

#waiting {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: rgba(32, 37, 64, .95); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  font-size: 14px; max-width: calc(100vw - 20px);
}
#waiting.offline { border-color: var(--red); }
#waiting button { padding: 6px 12px; border-radius: 999px; background: var(--panel-3); font-size: 13px; font-weight: 700; white-space: nowrap; }
#waiting button:hover { background: var(--purple); }
#waiting.offline #waitRetry { background: var(--red); color: #fff; }
#waiting button:disabled { opacity: .6; cursor: wait; }
.w-dots { display: flex; gap: 4px; }
.w-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: wdot 1.2s infinite ease-in-out; }
#waiting.offline .w-dots i { background: var(--red); }
.w-dots i:nth-child(2) { animation-delay: .15s; }
.w-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes wdot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

#help {
  position: absolute; left: 14px; bottom: 88px; background: rgba(32, 37, 64, .94); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 34px 12px 14px; font-size: 13px; display: flex; flex-direction: column; gap: 6px;
  max-width: calc(100vw - 28px);
}
.help-close { position: absolute; top: 6px; right: 8px; font-size: 18px; color: var(--muted); }

#videos {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; max-width: calc(100vw - 420px); overflow-x: auto; padding: 4px; z-index: 4;
}
.vtile {
  position: relative; flex: 0 0 auto; width: 240px; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden;
  background: #000; border: 2px solid var(--panel-3); cursor: zoom-in; box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}
.vtile:hover { border-color: var(--green); }
.vtile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.vtile span {
  position: absolute; left: 6px; bottom: 6px; background: rgba(32, 37, 64, .85); padding: 2px 8px; border-radius: 6px; font-size: 12px;
}

#focus { position: fixed; inset: 0; background: rgba(10, 12, 25, .92); z-index: 40; display: flex; flex-direction: column; padding: 16px; }
#focus video { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.focus-bar { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; }
.focus-bar button { font-size: 28px; width: 44px; height: 44px; border-radius: 50%; background: var(--panel-2); }

/* ---------- Barre du bas ---------- */
#bar {
  position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px; padding: 8px 10px; border-radius: 18px;
  background: var(--bg); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  max-width: calc(100vw - 20px); z-index: 10;
}
.me-pill { cursor: pointer; transition: background .15s; display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 6px; background: var(--panel); border-radius: 12px; min-width: 0; }
#meAvatar { width: 32px; height: 40px; image-rendering: pixelated; }
#meName { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
#meZone { font-size: 12px; white-space: nowrap; }
.bar-center, .bar-right { display: flex; gap: 8px; align-items: center; }
.round {
  position: relative; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--panel-2); transition: background .15s;
}
.round:hover { background: var(--panel-3); }
.round:disabled { opacity: .4; cursor: not-allowed; }
#micBtn .on { display: none; }
#micBtn.active { background: var(--green); color: #10213a; }
#micBtn.active .on { display: block; }
#micBtn.active .off { display: none; }
#micBtn.standby { background: var(--panel-3); color: var(--yellow); }
#micBtn.standby .on { display: block; }
#micBtn.standby .off { display: none; }
#micBtn:not(.active):not(.standby) { color: var(--red); }
#shareBtn.active { background: var(--green); color: #10213a; }
.ptt {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--panel-2); font-size: 13px; font-weight: 500; user-select: none; white-space: nowrap;
}
.ptt.active { background: var(--green); color: #10213a; }
.ptt.active kbd { background: #fff; color: #10213a; border-color: var(--green-dark); }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font: 700 11px/18px 'DM Sans', sans-serif; font-style: normal; text-align: center;
}

#handBtn.active { background: var(--yellow); color: #2a2200; }
#reactMenu {
  position: absolute; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 11;
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); display: flex; flex-direction: column; gap: 6px;
}
.r-emojis { display: flex; gap: 4px; }
.r-emojis button { width: 42px; height: 42px; border-radius: 10px; font-size: 22px; display: grid; place-items: center; }
.r-emojis button:hover { background: var(--panel-2); transform: scale(1.12); }
#people .p-hand { font-size: 15px; line-height: 16px; }

/* ---------- Tableau blanc ---------- */
#boardBtn.active { background: var(--green); color: #10213a; }
#board {
  position: absolute; top: 60px; left: 14px; right: 14px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 18px;
  background: rgba(20, 23, 45, .94); border: 1px solid var(--border); box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
}
.board-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.board-head b { font-size: 15px; margin-right: auto; }
#board:not(.owner) .owner-only { display: none !important; }
#penTools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#penTools button { height: 32px; min-width: 32px; border-radius: 8px; background: var(--panel-2); display: grid; place-items: center; border: 2px solid transparent; }
#penTools .pen-color { width: 28px; min-width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); }
#penTools .sel { border-color: var(--green) !important; }
#penTools .pen-size i { display: block; border-radius: 50%; background: #fff; }
#penTools .eraser, #penTools .clear { padding: 0 10px; font-size: 13px; font-weight: 700; }
.board-actions { display: flex; gap: 6px; }
.board-actions button { height: 32px; padding: 0 12px; border-radius: 8px; background: var(--panel-3); font-weight: 700; font-size: 13px; }
#boardClose { background: var(--red); color: #fff; }
#boardWrap { flex: 1; min-height: 0; display: grid; place-items: center; }
/* Mode PiP : petite fenêtre flottante en haut à gauche, toujours à jour ; un clic l'agrandit */
#board.pip {
  top: 60px; left: 14px; right: auto; bottom: auto; width: 320px; padding: 6px; gap: 4px; border-radius: 12px;
}
#board.pip .board-head b { font-size: 12px; }
#board.pip .owner-only { display: none !important; }
#board.pip .board-actions button { height: 26px; padding: 0 8px; font-size: 12px; }
#board.pip #boardWrap { flex: none; height: 180px; }
#board.pip #boardCanvas { cursor: zoom-in; }
#boardCanvas { background: #fff; border-radius: 8px; touch-action: none; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); }
#board.owner #boardCanvas { cursor: crosshair; }
@media (max-width: 560px) {
  #board { top: calc(54px + env(safe-area-inset-top)); left: 6px; right: 6px; bottom: calc(68px + env(safe-area-inset-bottom)); padding: 6px; }
  #board.pip { width: 210px; }
  #board.pip #boardWrap { height: 118px; }
}

/* ---------- Écran diffusé depuis le pupitre (PiP, un clic l'agrandit) ---------- */
#airPip { position: absolute; top: 60px; left: 14px; z-index: 29; display: flex; flex-direction: column; gap: 8px; }
.air-card {
  width: 320px; padding: 6px; border-radius: 12px; cursor: zoom-in;
  background: rgba(20, 23, 45, .94); border: 2px solid var(--yellow); box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.air-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.air-head b { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.air-head button { height: 26px; padding: 0 8px; border-radius: 8px; background: var(--panel-3); font-weight: 700; font-size: 12px; }
.air-card video { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: contain; background: #000; border-radius: 8px; }
@media (max-width: 560px) {
  #airPip { top: calc(54px + env(safe-area-inset-top)); left: 10px; }
  .air-card { width: 210px; }
}

/* ---------- Mains levées ---------- */
#hands {
  position: absolute; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 8;
  display: flex; flex-direction: column-reverse; gap: 10px; align-items: flex-end;
}
.hand-bubble {
  position: relative; width: 58px; height: 58px; border-radius: 50%; padding: 0; overflow: visible;
  background: var(--panel); border: 3px solid var(--yellow); box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  display: grid; place-items: center; animation: hb-in .25s ease-out;
}
.hand-bubble canvas { width: 52px; height: 52px; border-radius: 50%; image-rendering: pixelated; }
.hand-bubble:hover { transform: scale(1.08); }
.hand-bubble.more { font-weight: 700; color: var(--yellow); cursor: default; }
.hb-q {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--yellow); color: #2a2200; font-weight: 700; font-size: 14px; line-height: 22px; text-align: center;
  animation: hb-bounce 1.2s ease-in-out infinite;
}
.hb-name {
  position: absolute; right: 66px; top: 50%; transform: translateY(-50%); white-space: nowrap; pointer-events: none;
  background: rgba(32, 37, 64, .92); padding: 3px 10px; border-radius: 8px; font-size: 13px; font-weight: 700;
  opacity: 0; transition: opacity .15s;
}
.hand-bubble:hover .hb-name, .hand-bubble:focus-visible .hb-name { opacity: 1; }
@keyframes hb-in { from { transform: scale(.4); opacity: 0; } }
@keyframes hb-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@media (max-width: 1100px) { #hands { bottom: calc(84px + env(safe-area-inset-bottom)); } }
@media (max-width: 560px) { #hands { bottom: calc(72px + env(safe-area-inset-bottom)); right: 10px; } .hand-bubble { width: 50px; height: 50px; } .hand-bubble canvas { width: 44px; height: 44px; } }

/* ---------- Panneau latéral ---------- */
#sidebar {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; bottom: calc(86px + env(safe-area-inset-bottom)); width: 340px; max-width: calc(100vw - 28px);
  background: var(--bg); border: 1px solid var(--border); border-radius: 18px; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); z-index: 9;
}
#sidebar.closed { display: none; }
.side-tabs { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--border); align-items: center; }
.side-tabs button { padding: 7px 12px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--muted); }
.side-tabs button.active { background: var(--panel-2); color: var(--text); }
.side-tabs #peopleCount { background: var(--panel-3); border-radius: 8px; padding: 0 6px; font-size: 12px; margin-left: 4px; }
.side-close { margin-left: auto; font-size: 20px !important; }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-tabs { display: flex; gap: 6px; padding: 10px 10px 0; }
.chat-tabs button {
  position: relative; flex: 1; padding: 8px; border-radius: 10px; background: var(--panel); font-size: 13px; font-weight: 500;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow: visible;
}
.chat-tabs button.active { background: var(--purple); color: #fff; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 10px; }
.msg-av { flex: 0 0 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; }
.msg-body { min-width: 0; }
.msg-head { font-size: 13px; }
.msg-head b { margin-right: 6px; }
.msg-head time { color: var(--muted); font-size: 11px; }
.msg-text { font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; color: #e4e6f5; }
.msg-empty { color: var(--muted); font-size: 13px; text-align: center; margin: auto; padding: 20px; }
#chatForm { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
#chatInput { flex: 1; min-width: 0; background: var(--panel); border: 2px solid transparent; border-radius: 10px; padding: 9px 12px; outline: none; }
#chatInput:focus { border-color: var(--purple); }
#chatForm button { width: 42px; border-radius: 10px; background: var(--purple); display: grid; place-items: center; }
#people { list-style: none; margin: 0; padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
#people li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
#people li:hover { background: var(--panel); }
#people .p-info { flex: 1; min-width: 0; }
#people .p-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#people .p-zone { font-size: 12px; color: var(--muted); }
#people .p-icons { display: flex; gap: 4px; color: var(--green); }
#people .p-icons svg { width: 16px; height: 16px; }

/* ---------- Toasts ---------- */
#toasts { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 20; pointer-events: none; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border); padding: 9px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3); animation: toast-in .2s ease-out; max-width: calc(100vw - 32px);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  #videos { max-width: calc(100vw - 28px); }
  .ptt span { display: none; }
  #help:not(.forced) { display: none; }
}
@media (max-width: 420px) {
  #bar .round, #bar .ptt { width: 36px; height: 36px; border-radius: 10px; }
  #bar, .bar-center, .bar-right { gap: 4px; }
  #inviteBtn { display: none; } /* toujours accessible depuis l'écran de connexion et le bandeau d'attente */
  #helpBtn { display: none !important; } /* aide clavier : accessible via le profil sur téléphone */
}
@media (max-width: 560px) {
  .me-pill { display: none; }
  #bar { gap: 6px; padding: 6px; bottom: calc(10px + env(safe-area-inset-bottom)); }
  .bar-center, .bar-right { gap: 6px; }
  .round, .ptt { width: 42px; height: 42px; }
  .ptt { justify-content: center; padding: 0; }
  #sidebar { left: 10px; right: 10px; top: calc(10px + env(safe-area-inset-top)); width: auto; max-width: none; bottom: calc(72px + env(safe-area-inset-bottom)); }
  #zoneTag { top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; justify-content: center; font-size: 13px; }
  #zoneTag small { display: none; }
  #waiting { top: calc(54px + env(safe-area-inset-top)); font-size: 12px; padding-left: 12px; }
  #waiting .w-text { min-width: 0; }
  #waiting.offline #waitInvite { display: none; }
  #broadcast { top: calc(54px + env(safe-area-inset-top)); width: max-content; max-width: calc(100vw - 20px); font-size: 13px; }
  #videos { top: calc(100px + env(safe-area-inset-top)); }
  .vtile { width: 160px; }
  #toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .join-card { padding: 20px; }
  .preview-wrap { flex-basis: 100%; height: 150px; }
  .btn-ghost .copy-label { display: none; }
  #chatInput, .field input { font-size: 16px; } /* évite le zoom auto d'iOS */
}
