:root {
  --bg: #0b0e14;
  --bg2: #131824;
  --panel: #1a2030;
  --border: #262d40;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #5865f2;
  --accent2: #4752c4;
  --danger: #ed4245;
  --live: #f23f42;
  --ok: #3ba55d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ---------- HOME ---------- */
body.home {
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2438, var(--bg));
}
.home-card {
  width: min(480px, 100%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.home-card h1 { margin: 0 0 6px; font-size: 34px; }
.tag { color: var(--muted); margin: 0 0 24px; line-height: 1.5; }
#joinForm { display: grid; gap: 14px; }
#joinForm label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
#joinForm input {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
}
#joinForm input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#joinForm button {
  margin-top: 6px;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s;
}
#joinForm button:hover { background: var(--accent2); }

.rooms { margin-top: 28px; }
.rooms h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#roomList { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#roomList li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
#roomList li:hover { border-color: var(--accent); }
#roomList li.empty { color: var(--muted); cursor: default; justify-content: center; }
#roomList li.empty:hover { border-color: var(--border); }
.rname { font-weight: 600; }
.rmeta { font-size: 13px; color: var(--muted); }

/* ---------- ROOM ---------- */
body.room { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar {
  position: relative;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 18px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.pill {
  font-size: 13px; font-weight: 600; color: #fff;
  background: var(--accent); padding: 3px 10px; border-radius: 999px;
}
.controls { display: flex; gap: 10px; }
.btn {
  padding: 10px 16px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); font-weight: 600; font-size: 14px;
  transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary.live { background: var(--live); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }

.stage { flex: 1 1 auto; display: flex; min-height: 0; }

/* Área do palco — holofote (quem transmite) + faixa (quem não transmite) */
.stage-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

/* HOLOFOTE: quadros de quem está transmitindo (grande, centro) */
.spotlight {
  display: grid;
  gap: 12px;
  padding: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  grid-auto-rows: minmax(0, 1fr);
  place-content: center;
  overflow: auto;
}
.spotlight:empty { display: none; }

/* FAIXA: quadros de quem não transmite (avatares) */
.tray {
  display: grid;
  gap: 12px;
  padding: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  grid-auto-rows: minmax(0, 1fr);
  place-content: center;
  overflow: auto;
}
.tray:empty { display: none; }

/* Quando há transmissão: holofote domina, faixa vira uma tira pequena embaixo */
.stage-area.has-spotlight .spotlight { flex: 1 1 auto; }
.stage-area.has-spotlight .tray {
  flex: 0 0 auto;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 170px;
  grid-auto-rows: 96px;
  justify-content: center;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--border);
}
/* Sem transmissão: a faixa ocupa toda a área (grade de avatares) */
.stage-area:not(.has-spotlight) .tray { flex: 1 1 auto; }

/* Miniaturas pequenas: encolhe o quadro e o avatar */
.stage-area.has-spotlight .tray .tile { min-height: 0; }
.stage-area.has-spotlight .tray .avatar {
  width: 44px; height: 44px; font-size: 17px;
}
.stage-area.has-spotlight .tray .tile-label {
  font-size: 11px; padding: 2px 6px; left: 6px; bottom: 6px;
}

.placeholder {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
  color: var(--text); pointer-events: none;
}
.placeholder .muted { color: var(--muted); }

.tile {
  position: relative;
  min-height: 180px;
  background: #0f1420;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.tile.me { border-color: var(--ok); }

/* Avatar (ícone) mostrado quando a pessoa NÃO está transmitindo */
.avatar {
  position: absolute; inset: 0; margin: auto;
  width: clamp(64px, 16vmin, 120px);
  height: clamp(64px, 16vmin, 120px);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
  font-size: clamp(24px, 6vmin, 44px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  user-select: none;
}
.tile.no-video { background: var(--panel); }
.tile.no-video video { display: none; }
.tile:not(.no-video) .avatar { display: none; }
.tile:fullscreen {
  width: 100vw; height: 100vh; max-width: none; aspect-ratio: auto; border: none; border-radius: 0;
}
.tile:fullscreen video { object-fit: contain; }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tile-label {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(0, 0, 0, 0.65); color: #fff;
  padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: 600;
  backdrop-filter: blur(4px);
}
.tile-fs {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0, 0, 0, 0.55); color: #fff; border: none;
  width: 32px; height: 32px; border-radius: 8px; font-size: 15px; opacity: 0;
  transition: opacity 0.15s;
}
.tile:hover .tile-fs { opacity: 1; }

/* Pausar/retomar a exibição clicando no vídeo (local do espectador) */
.tile:not(.no-video) video { cursor: pointer; }
.pause-overlay {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55); color: #fff; cursor: pointer;
  font-size: clamp(36px, 9vmin, 64px);
}
.pause-overlay::after {
  content: "";
  position: absolute; width: clamp(64px, 16vmin, 110px); height: clamp(64px, 16vmin, 110px);
  border-radius: 50%; background: rgba(0, 0, 0, 0.45); z-index: -1;
}
.tile.paused .pause-overlay { display: flex; }

/* Controle de áudio por quadro (som + volume, local do espectador) */
.tile-audio {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, 0.6); border-radius: 8px; padding: 5px 10px;
  backdrop-filter: blur(4px);
  opacity: 0; transition: opacity 0.15s;
}
.tile:hover .tile-audio { opacity: 1; }
.tile-audio .spk {
  background: none; border: none; color: #fff; font-size: 16px;
  cursor: pointer; line-height: 1; padding: 0;
}
.tile-audio .vol { width: 84px; accent-color: var(--accent); cursor: pointer; }
.tile.no-video .tile-audio { display: none; } /* sem vídeo = sem áudio */
.stage-area.has-spotlight .tray .tile-audio { display: none; } /* miniatura pequena */

/* Quando a transmissão TEM áudio, o controle fica sempre visível */
.tile.has-audio .tile-audio { opacity: 1; }
/* Enquanto está mudo, chama a atenção com um rótulo pulsante */
.tile.has-audio.muted-audio .tile-audio::before {
  content: "Ativar som";
  font-size: 12px; color: #fff; font-weight: 600; margin-right: 2px;
}
.tile.has-audio.muted-audio .spk { animation: spkPulse 1.2s ease-in-out infinite; }
@keyframes spkPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

/* Painel de configurações da transmissão */
.settings-panel {
  position: absolute; top: calc(100% + 6px); right: 16px; z-index: 30;
  width: 300px; max-width: calc(100vw - 32px);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: grid; gap: 12px;
}
.settings-panel.hidden { display: none; }
.settings-panel h3 { margin: 0; font-size: 15px; }
.settings-panel label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.settings-panel select {
  padding: 9px 10px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
}
.settings-panel label.chk {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px;
}
.settings-panel label.chk input { width: auto; }
.settings-panel .hint { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.45; }

/* Chat */
.chat {
  flex: 0 0 300px;
  border-left: 1px solid var(--border);
  background: var(--bg2);
  display: flex; flex-direction: column;
}
.chat.hidden { display: none; }
.chat-head {
  padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--border);
}
.messages { flex: 1 1 auto; overflow: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 14px; line-height: 1.4; word-break: break-word; }
.msg .who { font-weight: 700; color: var(--accent); margin-right: 4px; }
.msg.mine .who { color: var(--ok); }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1; padding: 10px 12px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
}
.chat-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.chat-form button {
  padding: 0 16px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 16px;
}

.statusbar {
  flex: 0 0 auto;
  padding: 8px 18px; font-size: 13px; color: var(--muted);
  background: var(--bg2); border-top: 1px solid var(--border);
  min-height: 33px;
}

@media (max-width: 640px) {
  .chat { position: fixed; inset: 0; z-index: 20; flex-basis: auto; }
  .controls .btn { padding: 9px 11px; }
}
