:root {
  --bg: #0b1020;
  --panel: #151c33;
  --panel-2: #1d2647;
  --text: #e8ecf6;
  --muted: #8a93ad;
  --accent: #5b8cff;
  --ok: #2fd07a;
  --fail: #ff5a6e;
  --pending: #f2b94b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100dvh;
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.1;
}
.brand h1 span { display: block; color: var(--accent); }
.phase { margin: 8px 0 0; color: var(--muted); font-size: 14px; }

/* --- Formulario de unirse --- */
.join { display: flex; flex-direction: column; gap: 18px; margin-top: 8px; }
.join label { display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--muted); }
.join input {
  padding: 16px;
  font-size: 17px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: 12px;
  outline: none;
}
.join input:focus { border-color: var(--accent); }
.hint { margin: 0; color: var(--fail); font-size: 14px; min-height: 18px; }

/* --- Canales (chips) --- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 14px; color: var(--muted); }
.channels { display: flex; flex-wrap: wrap; gap: 10px; }
.channel {
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1.5px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}
.channel:active { transform: scale(0.97); }
.channel.active {
  background: rgba(91, 140, 255, 0.18);
  border-color: var(--accent);
  color: var(--text);
}

/* --- Estado de conexión --- */
.status {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 15px;
  color: var(--muted);
}

/* --- Lista de participantes --- */
.section-title { font-size: 14px; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.peers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.peer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
}
.peer.me { background: var(--panel-2); }
.peer-main { display: flex; align-items: center; gap: 12px; }

/* Volumen por participante */
.vol-row { display: flex; align-items: center; gap: 10px; }
.vol-ico { font-size: 15px; opacity: 0.7; }
.vol {
  flex: 1;
  height: 28px;
  accent-color: var(--accent);
  touch-action: manipulation;
}

/* --- Indicadores --- */
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); }
.dot.fail { background: var(--fail); }

/* --- Botones --- */
.primary, .danger {
  padding: 20px;
  font-size: 18px;
  font-weight: 700;
  color: white;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
}
.primary { background: var(--accent); }
.danger { margin-top: auto; background: var(--fail); }

/* --- Header en llamada --- */
.call-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.leave-x {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--panel);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
.leave-x:active { transform: scale(0.94); }

/* --- Participante hablando --- */
.peer.speaking {
  background: rgba(47, 208, 122, 0.16);
  box-shadow: inset 0 0 0 1.5px var(--ok);
}
.peer.speaking .dot { background: var(--ok); animation: pulse 0.9s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* --- Calidad de conexión (barras) --- */
.quality { margin-left: auto; display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.quality i { width: 3px; background: var(--muted); border-radius: 1px; opacity: 0.5; }
.quality i:nth-child(1) { height: 5px; }
.quality i:nth-child(2) { height: 9px; }
.quality i:nth-child(3) { height: 14px; }
.quality.q-buena i { background: var(--ok); opacity: 1; }
.quality.q-media i:nth-child(-n+2) { background: var(--pending); opacity: 1; }
.quality.q-mala i:nth-child(1) { background: var(--fail); opacity: 1; }

/* --- Botón Push-to-talk --- */
.ptt {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 180px;
  padding: 24px;
  border: none;
  border-radius: 28px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  /* Evita scroll, zoom, selección y menú al mantener presionado en mobile. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.08s ease, background 0.08s ease;
}
.ptt-icon { font-size: 48px; line-height: 1; }
.ptt-label { font-size: 17px; font-weight: 700; text-align: center; line-height: 1.3; }
.ptt.active {
  background: var(--ok);
  transform: scale(0.98);
  box-shadow: 0 0 0 6px rgba(47, 208, 122, 0.25);
}

/* --- Panel de diagnóstico --- */
.debug { margin-top: 8px; }
.debug summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 8px 0; }
.debug pre {
  background: #05080f;
  color: #9fe0b0;
  font-size: 11px;
  line-height: 1.5;
  border-radius: 10px;
  padding: 12px;
  margin: 0;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.primary:active, .danger:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.6; cursor: default; }
