:root {
  color-scheme: dark;
  --navy: #001f3f;
  --cyan: #7fdbff;
  --panel: #11233a;
  --panel-soft: #182d48;
  --text: #f4f8fc;
  --muted: #aebdd0;
  --danger: #ef4444;
  --success: #22c55e;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #071426; color: var(--text); font-family: Inter, system-ui, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar { height: 72px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #203651; background: rgba(7, 20, 38, .94); }
.brand { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 12px; font-weight: 700; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--navy); border: 1px solid #34506f; }
.brand-mark span { color: var(--cyan); }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.status-pill { padding: 7px 12px; border-radius: 999px; background: #23334a; color: var(--muted); font-size: 13px; }
.status-pill[data-state="online"] { color: #b7f7ca; background: #123b2a; }
.status-pill[data-state="connecting"] { color: #ffe3a3; background: #463817; }
.text-button { border: 0; background: transparent; color: var(--cyan); }

main { min-height: calc(100vh - 72px); }
.center-card { width: min(520px, calc(100% - 32px)); margin: 0 auto; min-height: calc(100vh - 72px); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.center-card h1 { margin: 18px 0 8px; font-size: clamp(28px, 5vw, 42px); }
.center-card p { color: var(--muted); line-height: 1.6; }
.card-icon { font-size: 52px; }
.spinner { width: 46px; height: 46px; border: 4px solid #29415e; border-top-color: var(--cyan); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.primary-button { margin-top: 22px; padding: 14px 25px; min-width: 220px; border: 0; border-radius: 12px; background: var(--cyan); color: var(--navy); font-weight: 700; }
.primary-button:hover { filter: brightness(1.08); }
.secondary-link { margin-top: 18px; color: var(--cyan); }
.lobby-options { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.lobby-options label { display: flex; gap: 9px; align-items: center; justify-content: center; padding: 14px; border: 1px solid #29415e; border-radius: 12px; background: var(--panel); }
.privacy-note { font-size: 12px; max-width: 440px; }

.room { max-width: 1500px; margin: 0 auto; padding: 30px 30px 120px; }
.room-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 22px; }
.room-heading h1 { margin: 3px 0 0; font-size: 30px; }
.room-heading > p { color: var(--muted); }
.eyebrow { margin: 0; color: var(--cyan); font-size: 12px; font-weight: 700; letter-spacing: .18em; }
/* Duas colunas: video a esquerda, chat fixo a direita.
   `minmax(0, 1fr)` na primeira coluna porque conteudo de video nao encolhe
   sozinho — sem isso a coluna estoura a largura e empurra o chat para fora. */
.room-corpo { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.room-principal { min-width: 0; }

/* Com o chat ocupando a direita, sobra menos largura para os videos: duas
   colunas em vez de tres. */
.video-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.video-tile { position: relative; aspect-ratio: 16 / 10; overflow: hidden; border: 1px solid #29415e; border-radius: 18px; background: var(--panel); box-shadow: 0 18px 50px rgba(0, 0, 0, .18); }
.video-tile video { width: 100%; height: 100%; display: block; object-fit: cover; background: #0c1a2d; }
/* Espelho Ã© apenas uma preferÃªncia de quem estÃ¡ olhando a prÃ³pria prÃ©via.
   A faixa WebRTC continua intacta, portanto os outros participantes recebem
   a imagem na orientaÃ§Ã£o real da cÃ¢mera. */
#local-video { transform: scaleX(-1); }
.camera-placeholder { position: absolute; inset: 0; display: none; place-items: center; background: radial-gradient(circle at 50% 30%, #294663, #101f33 70%); }
.camera-placeholder span { width: 82px; height: 82px; display: grid; place-items: center; border-radius: 50%; background: var(--cyan); color: var(--navy); font-size: 31px; font-weight: 700; }
.video-tile.camera-off .camera-placeholder { display: grid; }
.tile-footer { position: absolute; left: 0; right: 0; bottom: 0; padding: 28px 14px 12px; display: flex; justify-content: space-between; background: linear-gradient(transparent, rgba(0, 0, 0, .82)); font-weight: 600; }
/* Estado da conexao P2P, por participante.
   Sem isto a falha de ICE era invisivel: os dois se viam na LISTA (que vem do
   Firestore) e concluiam que a chamada funcionava, enquanto o video nunca
   chegava. A lista provar presenca e a conexao nao e a armadilha. */
.conn-badge { margin-left: auto; margin-right: 10px; align-self: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .02em; background: rgba(7, 20, 38, .85); border: 1px solid #47627e; color: #cfe3f7; white-space: nowrap; }
.conn-badge[data-state="connected"] { border-color: #2f7d4f; color: #7ee0a4; }
.conn-badge[data-state="relay"] { border-color: #8a6d1f; color: #ffd978; }
.conn-badge[data-state="failed"] { border-color: #8d3030; color: #ff9d9d; }
.tile-badges { display: flex; gap: 8px; }
.tile-badges .off { filter: grayscale(1); opacity: .45; }
.remote-controls { position: absolute; top: 10px; right: 10px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; opacity: 0; transition: opacity .2s; }
.video-tile:hover .remote-controls, .video-tile:focus-within .remote-controls { opacity: 1; }
.remote-controls button { border: 1px solid #47627e; border-radius: 8px; padding: 7px 9px; background: rgba(7, 20, 38, .9); color: var(--text); font-size: 11px; }
.screen-stage { position: relative; margin-bottom: 20px; overflow: hidden; border: 2px solid var(--cyan); border-radius: 18px; background: #020913; }
.screen-stage video { width: 100%; max-height: 65vh; display: block; object-fit: contain; }
.stage-label { position: absolute; z-index: 2; left: 12px; top: 12px; display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 11px; border-radius: 8px; background: rgba(0, 16, 32, .82); font-size: 13px; }
#screen-fullscreen-button { border: 1px solid #47627e; border-radius: 6px; padding: 5px 8px; background: rgba(7, 20, 38, .94); color: var(--text); font-size: 12px; }
#screen-fullscreen-button:hover { border-color: var(--cyan); color: var(--cyan); }
.screen-stage.local-screen-share #screen-fullscreen-button { display: none; }
/* A API de tela cheia expande somente o palco: chat, cÃ¢meras e controles
   ficam fora, e o compartilhamento preserva a proporÃ§Ã£o em toda a tela. */
.screen-stage:fullscreen { width: 100vw; height: 100vh; margin: 0; border: 0; border-radius: 0; display: grid; place-items: center; }
.screen-stage:fullscreen video { width: 100vw; height: 100vh; max-height: none; }
/* Chat da sala: coluna fixa a direita, sempre visivel.
   `position: sticky` mantem o chat na tela enquanto a lista de videos rola —
   sem ele, quem rola para ver um participante perde a conversa de vista. */
.chat { position: sticky; top: 20px; display: flex; flex-direction: column; height: calc(100vh - 190px); min-height: 380px; border: 1px solid #47627e; border-radius: 12px; background: rgba(7, 20, 38, .85); overflow: hidden; }
.chat-cabecalho { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px 9px 14px; border-bottom: 1px solid #2a3f57; }
.chat-titulo { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: #90a9c4; }
.chat-config-button { border: 1px solid #47627e; border-radius: 7px; padding: 5px 8px; background: rgba(7, 20, 38, .9); color: var(--text); font-size: 11px; }
.chat-config-button:hover { border-color: var(--cyan); color: var(--cyan); }
.chat-config-button:disabled { opacity: .5; cursor: default; }
.chat-config-button:disabled:hover { border-color: #47627e; color: var(--text); }
/* Botão de configurações virou engrenagem: mesmo formato do botão de texto,
   só que quadrado e com o emoji maior — ele precisa parecer um ícone, não uma
   palavra que encolheu. */
.chat-config-icone { padding: 4px 7px; font-size: 15px; line-height: 1; }
.chat-settings { padding: 11px 14px; border-bottom: 1px solid #2a3f57; background: #0c1a2d; color: var(--muted); font-size: 12px; }
.chat-settings label { display: block; margin-bottom: 7px; color: var(--text); font-weight: 600; }
.chat-settings-controls { display: flex; gap: 8px; }
.chat-settings select { flex: 1; min-width: 0; border: 1px solid #47627e; border-radius: 7px; padding: 6px 8px; background: #071426; color: var(--text); font: inherit; }
/* Linha do interruptor de notificação: mesma família visual do rótulo do
   select acima, mas em linha (checkbox + texto) em vez de bloco em negrito —
   são pesos visuais diferentes de propósito, o toggle é secundário. */
.chat-settings-toggle-linha { display: flex; align-items: center; gap: 7px; margin: 10px 0 0; font-weight: 400; cursor: pointer; }
.chat-settings-toggle-linha input { margin: 0; accent-color: var(--cyan); cursor: pointer; }
.chat-settings p { margin: 8px 0 0; font-size: 11px; line-height: 1.4; }
.chat-typing { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; margin-top: 2px; padding: 7px 0 0; border-top: 1px solid #2a3f57; color: var(--muted); font-size: 12px; font-style: italic; }
.chat-typing-dots { display: inline-flex; align-items: center; gap: 3px; }
.chat-typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--cyan); animation: chat-dot-bounce 1.1s infinite ease-in-out; }
.chat-typing-dots i:nth-child(2) { animation-delay: .15s; }
.chat-typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }
/* `flex: 1` com `min-height: 0`: sem o minimo, um item flex se recusa a
   encolher abaixo do conteudo e a barra de rolagem nunca aparece — a lista
   cresceria empurrando o campo de escrever para fora da tela. */
.chat-lista { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { font-size: 13px; line-height: 1.5; }
.chat-msg .autor { font-weight: 700; color: var(--cyan); margin-right: 6px; }
.chat-msg .hora { font-size: 11px; color: #90a9c4; }
.chat-msg .corpo { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg img { margin-top: 6px; max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid #2a3f57; display: block; cursor: zoom-in; }
.chat-vazio { color: #90a9c4; font-size: 13px; }
.chat-previa { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid #2a3f57; }
.chat-previa img { max-height: 70px; border-radius: 6px; border: 1px solid #2a3f57; }
.chat-previa button { border: 1px solid #8d3030; border-radius: 8px; padding: 5px 9px; background: rgba(7, 20, 38, .9); color: #ff9d9d; font-size: 11px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px; border-top: 1px solid #2a3f57; }
.chat-form textarea { flex: 1; resize: none; max-height: 120px; padding: 9px 11px; border: 1px solid #47627e; border-radius: 10px; background: #0c1a2d; color: var(--text); font: inherit; font-size: 13px; }
.chat-botao { border: 1px solid #47627e; border-radius: 10px; padding: 9px 12px; background: rgba(7, 20, 38, .9); color: var(--text); font-size: 13px; }
.chat-botao.primario { background: var(--cyan); color: var(--navy); font-weight: 700; border-color: var(--cyan); }
.chat-botao:disabled { opacity: .5; }
.chat-lightbox { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; background: rgba(2, 9, 19, .93); cursor: zoom-out; }
.chat-lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* Painel de diagnostico: fica fechado e so aparece quando pedido. */
.diagnostico { margin: 14px 0 0; padding: 12px 14px; border: 1px solid #47627e; border-radius: 12px; background: rgba(7, 20, 38, .85); font-size: 12px; line-height: 1.6; }
.diag-linha { padding: 8px 0; border-bottom: 1px solid #2a3f57; }
.diag-linha:last-child { border-bottom: 0; }
.diag-linha i { color: #cfe3f7; }
.diag-erro { color: #ff9d9d; }
.room-notice { position: fixed; z-index: 10; left: 50%; bottom: 108px; transform: translateX(-50%); padding: 11px 18px; border-radius: 10px; background: #f5f9fd; color: #10233c; box-shadow: 0 10px 35px rgba(0, 0, 0, .35); }
.controls { position: fixed; z-index: 5; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; gap: 10px; padding: 10px; border: 1px solid #2d4663; border-radius: 18px; background: rgba(11, 27, 47, .94); backdrop-filter: blur(10px); box-shadow: 0 14px 40px rgba(0, 0, 0, .35); }
.control-button { width: 82px; height: 62px; border: 0; border-radius: 12px; background: var(--panel-soft); color: var(--text); display: grid; place-items: center; gap: 2px; }
.control-button span { font-size: 20px; }
.control-button small { font-size: 10px; }
.control-button[aria-pressed="false"] { background: #3d2631; }
.control-button.danger { background: #782d36; }

/* Abaixo de 1100px nao cabem video e chat lado a lado sem espremer os dois:
   o chat desce para baixo dos videos, com altura propria. */
@media (max-width: 1100px) {
  .room-corpo { grid-template-columns: 1fr; }
  .chat { position: static; height: 420px; }
}
@media (max-width: 900px) {
  .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .topbar { padding: 0 16px; }
  .brand > span:last-child, .status-pill { display: none; }
  .room { padding: 22px 12px 112px; }
  .video-grid { grid-template-columns: 1fr; }
  .remote-controls { opacity: 1; }
  .lobby-options { grid-template-columns: 1fr; }
  .control-button { width: 66px; }
  .stage-label { max-width: calc(100% - 24px); }
}
