* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0a0a0f;
  color: #fff;
  height: 100dvh;
  overflow: hidden;
}

/* ── Screens ── */
.screen { display: none; width: 100%; height: 100dvh; }
.screen.active { display: flex; }

/* ── Lobby ── */
#screen-lobby {
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 70%);
}
.lobby-box {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  backdrop-filter: blur(10px);
}
.lobby-box h1 { font-size: clamp(1.6rem, 5vw, 2rem); font-weight: 700; margin-bottom: 8px; letter-spacing: -1px; }
.lobby-box > p { color: rgba(255,255,255,0.5); margin-bottom: 28px; font-size: 0.9rem; }
.separator { color: rgba(255,255,255,0.3); margin: 16px 0; font-size: 0.85rem; }

/* Botão entrar — coluna no mobile, linha se couber */
.join-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (min-width: 380px) {
  .join-row { flex-direction: row; }
  .join-row input { min-width: 0; }
}
.join-row input {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  color: #fff;
  padding: 13px 10px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
  width: 100%;
}
.join-row input:focus { outline: none; border-color: #7c3aed; }
.join-row .btn-secondary { white-space: nowrap; width: 100%; }
@media (min-width: 380px) {
  .join-row .btn-secondary { width: auto; }
}

.btn-primary {
  width: 100%;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  touch-action: manipulation;
}
.btn-primary:hover { background: #6d28d9; }
.btn-primary:active { background: #5b21b6; }

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
  touch-action: manipulation;
}
.btn-secondary:hover  { background: rgba(255,255,255,0.18); }
.btn-secondary:active { background: rgba(255,255,255,0.25); }

.error-msg { color: #f87171; font-size: 0.85rem; margin-top: 12px; min-height: 20px; }

/* ── Waiting ── */
#screen-waiting {
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 70%);
}
.waiting-box {
  text-align: center;
  width: 100%;
  max-width: 340px;
}
.waiting-box h2 { font-size: 1.5rem; margin-bottom: 8px; }
.waiting-box > p { color: rgba(255,255,255,0.5); margin-bottom: 20px; font-size: 0.9rem; }
.room-code {
  font-size: clamp(2rem, 12vw, 3rem);
  font-weight: 800;
  letter-spacing: 8px;
  color: #a78bfa;
  margin-bottom: 16px;
}
.btn-whatsapp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
  background: #25D366;
  color: #fff;
  border-radius: 12px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s;
  touch-action: manipulation;
}
.btn-whatsapp:hover  { background: #1ebe5d; }
.btn-whatsapp:active { background: #17a34a; }

.waiting-text { margin-top: 24px; color: rgba(255,255,255,0.4); font-size: 0.9rem; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Call ── */
#screen-call {
  position: relative;
  background: #000;
}

/* Vídeo remoto principal — tela cheia */
#remote-main-wrap {
  position: absolute;
  inset: 0;
}
#remote-main-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* mostra o frame inteiro sem cortar */
  background: #000;
}
#remote-main-wrap canvas {
  width: 100%;
  height: 100%;
}
#remote-main-wrap canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* Strip de participantes extras — parte de baixo */
#remote-strip {
  position: absolute;
  bottom: 88px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 15;
  pointer-events: none;
}
#remote-strip:empty { display: none; }
#remote-strip::-webkit-scrollbar { display: none; }

.strip-item {
  flex: 0 0 auto;
  width: 80px;
  height: 110px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  position: relative;
  pointer-events: auto;
  background: #111;
}
.strip-item video,
.strip-item canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.strip-item canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
}
.strip-item .avatar-badge {
  top: 4px;
  left: 4px;
  font-size: 0.62rem;
  padding: 2px 6px;
}
@media (min-width: 480px) {
  .strip-item { width: 100px; height: 130px; }
  #remote-strip { bottom: 96px; gap: 10px; }
}
@media (min-width: 768px) {
  .strip-item { width: 130px; height: 170px; }
  #remote-strip { bottom: 104px; gap: 12px; }
}

/* Vídeo local — canto inferior direito */
#video-local-wrap {
  position: absolute;
  bottom: 88px;
  right: 12px;
  width: 90px;
  height: 120px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.2);
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
#video-local, #canvas-local {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#canvas-local {
  position: absolute;
  inset: 0;
  z-index: 2;
}

@media (min-width: 480px) {
  #video-local-wrap {
    width: 130px;
    height: 170px;
    bottom: 96px;
    right: 16px;
  }
}
@media (min-width: 768px) {
  #video-local-wrap {
    width: 200px;
    height: 150px;
    bottom: 100px;
    right: 24px;
  }
}

/* Badge de avatar ativo */
.avatar-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.6);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.72rem;
  z-index: 5;
  backdrop-filter: blur(4px);
}
.avatar-badge.hidden { display: none; }

/* ── Controles ── */
#call-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#call-controls button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  background: rgba(255,255,255,0.15);
  color: #fff;
  transition: background 0.2s, transform 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#call-controls button:active { transform: scale(0.92); }
@media (min-width: 480px) {
  #call-controls { gap: 16px; bottom: 24px; }
  #call-controls button { width: 56px; height: 56px; font-size: 1.4rem; }
}
#btn-hangup  { background: rgba(239,68,68,0.7) !important; }
#btn-hangup:hover { background: rgba(239,68,68,0.9) !important; }
#btn-mute.muted    { background: rgba(239,68,68,0.5) !important; }
#btn-camera.cam-off { background: rgba(239,68,68,0.5) !important; }

/* ── Status ── */
#call-status {
  position: absolute;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(0,0,0,0.5);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
  z-index: 20;
  backdrop-filter: blur(4px);
}

/* ── Painel de convite (criador sozinho) ── */
.invite-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10,10,20,0.92);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  backdrop-filter: blur(20px);
  z-index: 25;
  width: min(320px, 90vw);
}
.invite-panel.hidden { display: none; }
.invite-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  color: rgba(255,255,255,0.4);
  font-size: 1.1rem; cursor: pointer;
  padding: 4px 8px;
  touch-action: manipulation;
}
.invite-panel p { color: rgba(255,255,255,0.6); font-size: 0.88rem; margin-bottom: 14px; }
.invite-code {
  font-size: clamp(2rem, 10vw, 2.8rem);
  font-weight: 800;
  letter-spacing: 8px;
  color: #a78bfa;
  margin-bottom: 20px;
}
.invite-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.invite-actions .btn-secondary { flex: 1; min-width: 110px; font-size: 0.88rem; padding: 11px 10px; }
.btn-whatsapp-sm {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #25D366;
  color: #fff;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  flex: 1;
  min-width: 110px;
  justify-content: center;
  touch-action: manipulation;
}
.btn-whatsapp-sm:hover { background: #1ebe5d; }

/* ── Painel de avatares ── */
.avatar-panel {
  position: absolute;
  bottom: 80px;
  left: 0;
  right: 0;
  background: rgba(10,10,20,0.95);
  border-top: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(20px);
  z-index: 30;
  padding: 16px 16px 20px;
  max-height: 60dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
}
.avatar-panel.hidden { display: none; }
.avatar-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 0.95rem;
}
.avatar-panel-header button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  touch-action: manipulation;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
@media (min-width: 480px) {
  .avatar-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 12px; }
}
.avatar-card {
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  background: rgba(255,255,255,0.05);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.avatar-card:active  { transform: scale(0.95); }
.avatar-card:hover   { border-color: #7c3aed; }
.avatar-card.selected { border-color: #a78bfa; box-shadow: 0 0 10px rgba(167,139,250,0.3); }
.avatar-card img  { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.avatar-card span { display: block; text-align: center; font-size: 0.7rem; padding: 4px 2px; color: rgba(255,255,255,0.7); }

.btn-danger {
  width: 100%;
  background: rgba(239,68,68,0.2);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 10px;
  padding: 11px;
  cursor: pointer;
  font-size: 0.9rem;
  touch-action: manipulation;
}
.btn-danger:active { background: rgba(239,68,68,0.35); }
