* { box-sizing: border-box; margin: 0; }

/* O atributo hidden precisa ganhar de qualquer display abaixo — sem isto, um
   seletor de id (#lobby, #waiting) vence a regra do navegador e o elemento
   "escondido" segue ocupando a tela. */
[hidden] { display: none !important; }

:root {
  --bg: #0e0e14;
  --panel: #1a1a24;
  --text: #e8e8f0;
  --muted: #8a8a9c;
  --accent: #4c6ef5;
  --danger: #e5484d;
  --line: #ffffff1a;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

button { font-family: inherit; }

/* ---------- lobby ---------- */

#lobby {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
}

#lobby h1 { font-size: 2.6rem; letter-spacing: -.02em; }
.tagline { color: var(--muted); margin-bottom: 10px; }

#nameInput {
  background: #ffffff10;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 16px;
  color: var(--text);
  font-size: 1rem;
  width: min(320px, 100%);
  text-align: center;
}
#nameInput:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 13px 32px;
  font-size: 1.05rem;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.12); }
button.primary:disabled { opacity: .5; cursor: wait; }

.error { color: var(--danger); }

/* ---------- sala ---------- */

#call { height: 100%; position: relative; }

#room {
  position: absolute;
  inset: 0 0 92px 0;
  display: flex;
  min-height: 0;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

/* tela compartilhada em destaque */
#spotlight {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
}
#spotlight video { width: 100%; height: 100%; object-fit: contain; }
#spotlightLabel {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: #000000b0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .85rem;
}

/* grade de pessoas */
#grid {
  display: grid;
  gap: 8px;
  flex: 1;
  min-height: 0;
  /* colunas vêm do número de pessoas (via JS): a grade preenche o palco em vez
     de deixar tiles minúsculos boiando no meio */
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}

/* com tela em destaque, a grade vira uma faixa embaixo */
/* com tela em destaque, a grade vira uma faixa embaixo */
.screen-active #grid {
  flex: 0 0 clamp(96px, 16vh, 150px);
  grid-template-columns: repeat(auto-fit, minmax(120px, 160px));
  grid-auto-rows: 100%;
  justify-content: center;
}

.tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  min-height: 0;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.tile.cam-on video { display: block; }
.tile.self video { transform: scaleX(-1); } /* espelho só do meu vídeo */

.tile .avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
}
.tile.cam-on .avatar { display: none; }

.tile .tag {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #000000b0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .8rem;
  max-width: calc(100% - 16px);
}
.tile .tag-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.talking { border-color: var(--accent); }

#status {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #000000c0;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: .95rem;
  z-index: 3;
}
#status:empty { display: none; }

/* ---------- painéis sobre o palco (espera / erro) ---------- */

#waiting, #fatal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  z-index: 4;
}

#waiting h2, #fatal h2 { font-size: 1.4rem; font-weight: 600; }
#waiting p, #fatal p { color: var(--muted); max-width: 44ch; }

.linkrow {
  display: flex;
  gap: 8px;
  width: min(480px, 100%);
  margin-top: 4px;
}

#roomLink {
  flex: 1;
  min-width: 0;
  background: #ffffff10;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: .95rem;
}

.linkrow button.primary { padding: 12px 22px; font-size: 1rem; white-space: nowrap; }

/* com tela compartilhada, o convite vira faixa e nunca cobre a tela */
.screen-active #waiting {
  inset: 0 0 auto 0;
  flex-direction: row;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(#000000e6, #00000000);
}
.screen-active #waiting h2, .screen-active #waiting p { display: none; }
.screen-active .linkrow { width: min(420px, 80%); margin: 0; }

/* ---------- chat ---------- */

#chat {
  width: min(340px, 84vw);
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#chat header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
#chatCloseBtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#messages:empty::after {
  content: 'Nada por aqui ainda.';
  color: var(--muted);
  font-size: .9rem;
}

.msg-who { font-size: .78rem; color: var(--muted); margin-bottom: 3px; }
.msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.4; font-size: .95rem; }
.msg.mine .msg-who { color: var(--accent); }
.msg.system .msg-text { color: var(--muted); font-size: .85rem; font-style: italic; }

#chatForm {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
#chatInput {
  flex: 1;
  min-width: 0;
  background: #ffffff10;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: .95rem;
}
#chatForm button.primary { padding: 11px 18px; font-size: .95rem; }

@media (max-width: 640px) {
  #chat { position: absolute; inset: 0; width: auto; z-index: 5; }
}

/* ---------- controles ---------- */

#controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  z-index: 6;
  transition: opacity .3s, transform .3s;
}

.idle #controls {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
  pointer-events: none;
}
.idle { cursor: none; }

#controls button {
  position: relative;
  background: #ffffff10;
  border: none;
  border-radius: 10px;
  width: 46px;
  height: 46px;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text);
}
#controls button:hover { background: #ffffff22; }
#controls button.off { background: var(--danger); }
#controls button.on { background: var(--accent); }
#controls button.danger { background: var(--danger); }

#chatBadge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: .7rem;
  line-height: 18px;
}

#volume { width: 110px; accent-color: var(--accent); }

#toast {
  position: absolute;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: #000000d8;
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 12px;
  max-width: min(480px, 90vw);
  text-align: center;
  font-size: .95rem;
  z-index: 7;
}

/* erro fatal: sem sala pra operar, sem controles */
.fatal #controls { display: none; }
