:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --text: #f2f3f5;
  --muted: #9aa0ab;
  --accent: #4f8cff;
  --danger: #ff4d5e;
  --border: #2c313b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- Formulario ---------- */
#setup { min-height: 100dvh; display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; }
.card { width: 100%; max-width: 680px; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px 20px; display: flex; flex-direction: column; gap: 16px; }
h1 { margin: 0; font-size: 28px; }
.online { margin: -8px 0 0; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
input[type=text], input:not([type]), select { padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 16px; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input, .chip input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px; border-radius: 10px; border: 1px solid var(--border); }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); }
.all-toggle { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.all-toggle input { width: 18px; height: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; max-height: 320px; overflow-y: auto; }
.chips.disabled { opacity: .35; pointer-events: none; }
.chip span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); font-size: 14px; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); }
.primary { padding: 14px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.detected { margin: 0; font-size: 15px; color: var(--muted); }

/* ---------- Login con Google / usuario conectado ---------- */
.login-card { align-items: center; text-align: center; gap: 20px; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 20px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: #1f1f1f; font-weight: 600; font-size: 15px; text-decoration: none; }
.google-btn:hover { background: #f5f5f5; }
.user-badge { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.user-badge .avatar { width: 28px; height: 28px; border-radius: 50%; }
.user-badge .logout-link { margin-left: auto; color: var(--muted); text-decoration: underline; font-size: 13px; }
.detected strong { color: var(--text); }

/* ---------- Videochat: persona remota arriba, tú abajo ---------- */
#chat { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; touch-action: pan-y; }
.panel { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.panel video { width: 100%; height: 100%; object-fit: cover; display: block; }
.remote { border-bottom: 2px solid var(--bg); transition: transform .25s ease, opacity .25s ease; }
.remote.swipe-left { transform: translateX(-100%); opacity: 0; }
.remote.swipe-right { transform: translateX(100%); opacity: 0; }
.mirror { transform: scaleX(-1); }

.status { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: rgba(0,0,0,.75); color: var(--text); font-size: 17px; }
.spinner { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { position: absolute; left: 12px; top: 12px; padding: 6px 12px; border-radius: 999px;
  background: rgba(0,0,0,.55); font-weight: 600; backdrop-filter: blur(6px); }

.icon-btn { width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.55); color: #fff; backdrop-filter: blur(6px); }
.corner { position: absolute; top: 12px; right: 12px; }
.stop-btn { position: absolute; left: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 6px;
  padding: 12px 18px; border: 0; border-radius: 999px; background: var(--danger); color: #fff; font-weight: 700; }
.next-btn { position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); width: 64px; height: 64px; border-radius: 50%;
  border: 0; display: grid; place-items: center; background: var(--accent); color: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.hint { position: absolute; left: 0; right: 0; bottom: calc(88px + env(safe-area-inset-bottom)); margin: 0; text-align: center;
  color: rgba(255,255,255,.7); font-size: 12px; pointer-events: none; }

/* Chat de texto sobre el video: transparente salvo los globos de texto y la caja de escribir,
   para que no tape la imagen. pointer-events:none en el contenedor deja pasar el swipe por los huecos. */
.chat-overlay { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column;
  gap: 6px; padding: 8px 10px; pointer-events: none; }
.chat-messages { display: flex; flex-direction: column; gap: 4px; max-height: 34%; overflow-y: auto; pointer-events: none; }
.chat-msg { align-self: flex-start; max-width: 78%; padding: 6px 11px; border-radius: 14px; font-size: 13px;
  line-height: 1.3; color: #fff; background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  text-shadow: 0 1px 2px rgba(0,0,0,.4); word-wrap: break-word; pointer-events: auto; }
.chat-msg.mine { align-self: flex-end; background: rgba(79,140,255,.65); }
.chat-form { display: flex; gap: 6px; pointer-events: auto; }
.chat-form input { flex: 1; min-width: 0; padding: 10px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.3);
  background: rgba(0,0,0,.4); backdrop-filter: blur(4px); color: #fff; font-size: 16px; }
.chat-form input::placeholder { color: rgba(255,255,255,.65); }
.chat-send { flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: rgba(79,140,255,.8); color: #fff; display: grid; place-items: center; }

/* Computador: persona arriba y tú abajo, cada video en 4:3 (casi cuadrado) para no recortar la cara */
@media (min-width: 800px) and (orientation: landscape) {
  #chat { align-items: center; justify-content: center; gap: 8px; padding: 8px; }
  .panel { flex: 0 0 auto; aspect-ratio: 4 / 3; border-radius: 14px;
    height: calc((100dvh - 24px) / 2); width: auto; }
  .remote { border-bottom: 0; }
}
