/* Renocall — estética basada en Renovatio (oklch, JetBrains Mono, esquinas rectas) */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500&display=swap');

:root {
  --bg:        oklch(0.09 0.012 245);
  --bg-2:      oklch(0.12 0.014 245);
  --bg-3:      oklch(0.16 0.014 245);
  --fg:        oklch(0.96 0.005 245);
  --fg-dim:    oklch(0.62 0.012 245);
  --fg-faint:  oklch(0.32 0.014 245);
  --accent:    oklch(0.82 0.16 72);
  --accent-fg: oklch(0.09 0.012 245);
  --line:      oklch(0.22 0.014 245);
  --danger:    oklch(0.62 0.18 25);
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  /* Alturas reservadas para cabecera/controles fixed + margen de seguridad */
  --header-h: 72px;
  --controls-h: 104px;
  --safety: 24px;
  --avail: calc(100vh - var(--header-h) - var(--controls-h) - var(--safety));
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;            /* sin scroll de página */
}
a { color: var(--accent); }

/* ---- Cabecera (fixed + transparente; solo dentro de la sala) ---- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: none; align-items: start; gap: 14px;
  padding: 18px 24px; background: transparent;
  pointer-events: none;        /* no bloquea el vídeo de debajo */
  background: linear-gradient(to bottom, rgba(0,0,0,.45), transparent);
}
body.in-room .topbar { display: flex; }
.topbar .logo { height: 24px; pointer-events: auto; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
/* El nombre de la sala se oculta en todas las vistas (redundante con la URL/insignias) */
.topbar .room-name { display: none; }
.room-lock { align-items: center; color: var(--accent); pointer-events: auto; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); margin-top: 7px;}
.room-lock svg { width: 16px; height: 16px; display: block; }
.room-count { display: inline-flex; align-items: center; gap: 5px; color: var(--fg); pointer-events: auto; font-size: 13px; letter-spacing: .02em; margin-top: 6px; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.room-count svg { width: 16px; height: 16px; }
.room-timer { display: inline-flex; align-items: center; gap: 5px; color: var(--fg); pointer-events: auto; font-size: 13px; letter-spacing: .02em; margin-top: 6px; text-shadow: 0 1px 2px rgba(0,0,0,.6); font-variant-numeric: tabular-nums; }
.room-timer svg { width: 16px; height: 16px; }
/* Avatar del usuario (iniciales) arriba a la derecha */
.me-avatar {
  margin-left: auto; width: 40px; height: 40px;
  transition: transform .25s ease;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-fg);
  font-weight: 500; font-size: 22px; letter-spacing: .02em;
  pointer-events: auto; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* ---- Control de pantallas ----
   Solo #boot es visible en el primer pintado; el resto las activa el JS
   mediante showScreen(). Así nunca se ve el modal ni la salida antes de tiempo. */
#join, #stage, #left { display: none; }
.boot-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.boot-wrap .logo { height: 34px; opacity: .65; animation: bootPulse 1.4s ease-in-out infinite; }
@keyframes bootPulse { 0%, 100% { opacity: .35; } 50% { opacity: .8; } }

/* ---- Pantalla de entrada ---- */
.join-wrap { align-items: center; justify-content: center; min-height: 100vh; padding: 20px; overflow-y: auto; }
.join-card { width: 100%; max-width: 760px; background: var(--screen-bg, var(--bg-2)); color: var(--screen-fg, var(--fg)); border: 1px solid var(--line); padding: 36px; }
.join-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: start; }
.join-col { display: flex; flex-direction: column; min-width: 0; }
.join-col .preview { margin-top: 0; }
.join-col label:first-child { margin-top: 0; }
@media (max-width: 680px) { .join-cols { grid-template-columns: 1fr; gap: 8px; } }
.join-card img.logo { height: 30px; margin-bottom: 28px; }
.join-card h1 { font-size: 18px; font-weight: 500; margin: 0 0 4px; letter-spacing: .02em; color: var(--screen-fg, var(--fg)); }
.join-card p.sub { color: var(--screen-fg, var(--fg-dim)); font-size: 13px; margin: 0 0 24px; }
label { display: block; margin: 16px 0 6px; font-size: 12px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: .08em; }
.join-card label { color: var(--screen-fg, var(--fg-dim)); }
input[type=text], input[type=email] {
  width: 100%; padding: 12px 14px; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); font-family: var(--mono); font-size: 14px;
}
input[type=text]:focus, input[type=email]:focus { outline: none; border-color: var(--accent); }
input:disabled { opacity: .6; }
/* Botones unificados con el panel de admin (mono, mayúsculas, esquinas rectas) */
.btn {
  font-family: var(--mono); font-size: 10px; font-weight: 400; cursor: pointer;
  letter-spacing: .16em; text-transform: uppercase;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--fg-dim);
  padding: 13px 20px; transition: filter .15s, border-color .15s, color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { background: none; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: var(--fg); filter: none; }
.btn.full { width: 100%; margin-top: 24px; padding: 14px; }
/* Acceso de admin desde el formulario de entrada: secundario, pegado bajo "Entrar" */
.join-admin { margin-top: 10px; }
.status { font-size: 12px; color: var(--fg-dim); margin-top: 14px; min-height: 16px; }
.status.err { color: var(--danger); }

/* ---- Sala no encontrada ---- */
.not-found h1 { font-size: 18px; font-weight: 500; margin: 0; letter-spacing: .02em; }

/* ---- Pantalla de salida ---- */
.left-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--screen-bg, transparent); }
.left-card { width: 100%; max-width: 440px; text-align: center; }
.left-card .logo { height: 30px; margin-bottom: 28px; }
.left-msg { color: var(--screen-fg, var(--fg)); font-size: 15px; line-height: 1.6; margin: 0 0 28px; }

/* ---- Preview de cámara/micro en la entrada ---- */
.preview {
  position: relative; width: 100%; aspect-ratio: 16/9;
  background: #000; border: 1px solid var(--line); overflow: hidden;
  margin: 6px 0 14px;
}
.preview video { width: 100%; height: 100%; object-fit: cover; background: #000; }
/* Espejo de la autovista (solo afecta a cómo te ves tú, no a los demás) */
.mirror { transform: scaleX(-1); }
.preview-off {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  color: var(--fg-faint); font-size: 13px; letter-spacing: .03em;
}
.mic-meter {
  position: absolute; left: 10px; right: 10px; bottom: 10px; height: 6px;
  background: rgba(255,255,255,.16); overflow: hidden;
}
.mic-meter .bar { height: 100%; width: 0%; background: var(--accent); transition: width .08s linear; }

/* ---- Toggles de dispositivo (entrar con micro/cámara on-off) ---- */
.dev-toggles { display: flex; gap: 10px; margin-bottom: 6px; }
.dev-toggle {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--mono); font-size: 13px; font-weight: 400; cursor: pointer;
  padding: 10px 12px; border: 1px solid var(--line); background: var(--bg-3); color: var(--fg);
  transition: background .15s, border-color .15s, color .15s;
}
.dev-toggle svg { width: 18px; height: 18px; }
.dev-toggle:hover { border-color: var(--fg-dim); }
.dev-toggle.off { background: var(--danger); border-color: var(--danger); color: var(--fg); }

/* ---- Selector de efecto de fondo (modal y popover del avatar) ---- */
.fx-section { margin: 10px 0 4px; }
.fx-title { font-size: 12px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.fx-options { display: flex; flex-wrap: wrap; gap: 8px; }
.fx-opt {
  position: relative; width: 76px; height: 52px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-3) center/cover no-repeat; color: var(--fg);
  font-family: var(--mono); font-size: 11px; letter-spacing: .02em;
  display: flex; align-items: flex-end; justify-content: center; overflow: hidden;
}
.fx-opt span {
  width: 100%; text-align: center; padding: 3px 2px;
  background: rgba(0,0,0,.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fx-opt:hover { border-color: var(--fg-dim); }
.fx-opt.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* Popover del avatar */
.fx-panel {
  position: fixed; top: 78px; right: 24px; z-index: 50; display: none;
  background: var(--bg-2); border: 1px solid var(--line); padding: 16px; width: 280px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
.fx-panel.show { display: block; }

/* Sección de administrador dentro del popover de perfil */
.fx-admin { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.fx-admin .who { font-size: 12px; color: var(--fg-dim); margin-bottom: 10px; word-break: break-word; }
.fx-admin .who b { color: var(--accent); font-weight: 500; }
.fx-admin .btn { width: 100%; }

/* Panel lateral de administración (se abre como el chat, deslizando) */
.side-panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 340px; z-index: 60;
  background: var(--bg-2); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease;
}
.side-panel.show { transform: translateX(0); }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-dim);
}
.side-close { background: none; border: 0; color: var(--fg-dim); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.side-close:hover { color: var(--fg); }
.side-body { padding: 20px 16px; overflow-y: auto; }
.side-body p { font-size: 13px; color: var(--fg-dim); line-height: 1.5; margin: 0 0 14px; }
.side-body p b { color: var(--fg); }
#adminCode {
  letter-spacing: .4em; text-align: center; font-size: 20px; padding: 14px;
}
.side-body .btn { margin-top: 14px; }

.me-avatar { cursor: pointer; border: none; font-family: var(--mono); }
.me-avatar:hover { filter: brightness(1.08); }

/* Switch "verme en espejo" */
.mirror-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 10px; color: var(--fg); margin-top: 14px; }
/* Switch unificado con el admin: cuadrado, sin bordes redondeados */
.mirror-chk {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 38px; height: 20px; position: relative; cursor: pointer;
  background: none; border: 1px solid var(--line);
  display: inline-flex; align-items: center; padding: 3px;
  transition: border-color .2s;
}
.mirror-chk::after {
  content: ""; width: 12px; height: 12px;
  background: var(--fg-faint); transition: transform .2s, background .2s;
}
.mirror-chk:checked { border-color: var(--accent); }
.mirror-chk:checked::after { transform: translateX(18px); background: var(--accent); }

/* ---- Escenario / sala ---- */
#stage { display: none; height: 100vh; flex-direction: column; }
/* Al entrar en la sala (se añade body.in-room) todo aparece con un fundido */
body.in-room #stage, body.in-room .topbar, body.in-room .controls { animation: stageFade .5s ease both; }
@keyframes stageFade { from { opacity: 0; } to { opacity: 1; } }
/* La cabecera y los controles son fixed: reservamos su espacio con padding
   para que las ventanas de usuario nunca se solapen con ellos. */
.stage-body {
  flex: 1; display: flex; min-height: 0;
  padding-top: var(--header-h); padding-bottom: var(--controls-h);
}
#grid {
  flex: 1; padding: 16px; display: grid; gap: 12px;
  align-content: center; justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  overflow: hidden;            /* la rejilla no scrollea */
  min-height: 0;
}
/* Un solo participante: el ancho se deriva del alto disponible (16/9),
   así la ventana nunca supera el alto entre cabecera y controles. */
#grid.solo { grid-template-columns: min(100%, calc(var(--avail) * 16 / 9)); }
#spotSide { display: none; }       /* solo visible en modo spotlight */
.tile {
  position: relative; background: #000; border: 1px solid var(--line);
  aspect-ratio: 16/9; overflow: hidden; min-height: 0;
  width: 100%; max-width: 100%;
  max-height: var(--avail);    /* nunca más alto que el hueco disponible */
  align-self: center; justify-self: center;
}
/* La pantalla compartida es un tile más, con borde dorado para distinguirla */
.tile.screen { border-color: var(--accent); }

/* ---- Modo spotlight (doble click): destacada a la izquierda, resto en columna a la derecha ---- */
#grid.spotlight {
  display: flex; gap: 12px; align-items: center; justify-content: center;
}
#grid.spotlight > .tile {            /* la ventana destacada: se ajusta a su proporción real
                                        (sin estirar el ancho) → sin barras negras a los lados */
  flex: 0 1 auto; min-width: 0; width: auto; max-width: 100%;
  height: var(--avail); max-height: var(--avail);
}
#grid.spotlight #spotSide {
  display: flex; flex-direction: column; gap: 12px; flex: none;
  width: 240px; max-height: var(--avail); overflow-y: auto;
  /* Scroll con el estilo de renovatio-comunicacion.com: fino, thumb en accent, pista transparente */
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}
#spotSide::-webkit-scrollbar { width: 8px; height: 8px; }
#spotSide::-webkit-scrollbar-track { background: transparent; }
#spotSide::-webkit-scrollbar-thumb { background: var(--accent); }
#spotSide .tile { width: 100%; max-height: none; flex: none; }
.tile { cursor: pointer; }           /* indica que el doble click hace algo */
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile.camera video { object-fit: cover; }
.tile .label {
  position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,.65);
  padding: 3px 9px; font-size: 12px; letter-spacing: .03em;
}
/* Indicador de micro apagado: badge en una esquina, en todos los tiles */
.tile .mic-badge {
  position: absolute; bottom: 8px; right: 8px; z-index: 3; display: none;
  width: 26px; height: 26px; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.tile .mic-badge svg { width: 15px; height: 15px; }
/* Insignia de anfitrión verificado (rol del token, infalsificable) */
.host-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent); color: var(--accent-fg); font-weight: normal;
  letter-spacing: .03em; border-radius: 999px; white-space: nowrap; text-transform: uppercase;
}
.host-badge svg { width: 13px; height: 13px; flex: none; }
.tile .host-badge {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  padding: 3px 8px; box-shadow: 0 1px 4px rgba(0,0,0,.5);
  font-size: 9px;
    font-weight: normal;
    text-transform: uppercase;
}
.host-badge.sm { padding: 2px 7px; font-size: 10px; margin-left: 6px; }
.host-badge.sm svg { width: 12px; height: 12px; }
.host-badge.icon-only { padding: 2px; gap: 0; }
/* Cámara apagada: en el tile mostramos solo el escudo, sin la palabra "Anfitrión" */
.tile.no-video .host-badge { gap: 0; padding: 4px; }
.tile.no-video .host-badge .host-label { display: none; }
/* Botón de expulsar en el tile (solo admin, al pasar el ratón) */
.tile .kick-btn {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 5; display: none;
  width: 36px; height: 36px; padding: 0; cursor: pointer; align-items: center; justify-content: center;
  background: rgba(190,40,40,.92); color: #fff; border: none;
}
.tile .kick-btn svg { width: 19px; height: 19px; }
.tile .kick-btn:hover { background: var(--danger); }
/* Con vídeo: barra superior del tile. Con cámara apagada usamos .ph-kick (sobre la imagen). */
.tile.kickable:not(.no-video):hover .kick-btn { display: inline-flex; }
/* Botón de expulsar sobre la imagen/inicial cuando la cámara está apagada */
.ph-ini .ph-kick {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 6; display: none;
  width: 36px; height: 36px; padding: 0; cursor: pointer; align-items: center; justify-content: center;
  background: rgba(190,40,40,.92); color: #fff; border: none;
}
.ph-ini .ph-kick svg { width: 19px; height: 19px; }
.ph-ini .ph-kick:hover { background: var(--danger); }
.tile.no-video.kickable:hover .ph-ini .ph-kick { display: inline-flex; }

/* Botón de pantalla completa (solo en tiles de pantalla compartida) */
.fs-btn {
  position: absolute; top: 8px; right: 8px; z-index: 3; display: none;
  width: 34px; height: 34px; padding: 0; cursor: pointer;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); color: #fff; border: 1px solid var(--line);
}
.fs-btn svg { width: 18px; height: 18px; }
.fs-btn:hover { background: rgba(0,0,0,.8); border-color: var(--fg-dim); }
.tile.screen .fs-btn { display: inline-flex; }
/* En pantalla completa el tile ocupa toda la pantalla */
.tile:fullscreen { width: 100vw; height: 100vh; max-height: none; aspect-ratio: auto; border: 0; }
.tile:fullscreen video { object-fit: contain; }
.tile:-webkit-full-screen { width: 100vw; height: 100vh; max-height: none; border: 0; }

/* Placeholder cuando no hay vídeo (cámara apagada): inicial 80x80 + nombre */
.tile .ph {
  position: absolute; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: transparent;
}
.tile.no-video { background: transparent; border-color: transparent; }
.tile.no-video .ph { display: flex; }
.tile.no-video video { display: none; }
.tile.no-video .label { display: none; }

/* Modo compacto: todas las cámaras apagadas → cada caja se ajusta a la imagen + nombre
   (sin el área 16/9 del vídeo) y se agrupan centradas, sin huecos enormes entre usuarios. */
#grid.compact {
  display: flex; flex-wrap: wrap; gap: 24px;
  align-content: center; justify-content: center; align-items: center;
}
#grid.compact .tile {
  aspect-ratio: auto; width: auto; max-width: none;
  height: auto; max-height: none; min-height: 0; flex: 0 0 auto;
}
#grid.compact .tile .ph { position: static; inset: auto; padding: 4px; }
.ph-ini {
  position: relative;
  width: 80px; height: 80px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-fg); font-size: 34px; font-weight: 500;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
/* Quien habla con la cámara apagada: el avatar se enmarca con un anillo dorado que late.
   Solo en tiles .no-video (con cámara ya se le ve). El color sigue a --accent de la sala. */
.tile.no-video.speaking .ph-ini {
  box-shadow: 0 0 0 3px var(--accent), 0 0 14px rgba(0, 0, 0, .5);
}
.tile.no-video.speaking .ph-ini::before {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  border: 2px solid var(--accent);
  animation: speakPulse 1.2s ease-out infinite;
}
@keyframes speakPulse {
  0%   { opacity: .85; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.18); }
}
.ph-mic {
  position: absolute; bottom: -8px; right: -8px;
  width: 30px; height: 30px; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; border-radius: 50%; border: 2px solid var(--bg);
}
.ph-mic svg { width: 16px; height: 16px; }
/* Insignia de anfitrión sobre la imagen/inicial cuando la cámara está apagada (junto al avatar,
   esquina superior; el micro va en la inferior para que no se solapen) */
.ph-host {
  position: absolute; top: -4px; right: -8px;
  width: 30px; height: 30px; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-fg); border-radius: 50%; border: 2px solid var(--bg);
}
.ph-host svg { width: 16px; height: 16px; }
.ph-name { font-size: 14px; color: #fff; letter-spacing: .03em; }
/* Avatar con imagen (placeholder y botón de perfil) */
.ph-ini.has-img { background-size: cover; background-position: center; }
.ph-ini.has-img .ph-letter { display: none; }
.me-avatar.has-img { background-size: cover; background-position: center; color: transparent; }
.avatar-row { display: flex; gap: 8px; }
.avatar-row .btn { flex: 1; padding: 9px 10px; font-size: 10px; }

/* ---- Chat ---- */
#chat {
  position: fixed; top: 0; right: 0; height: 100vh; height: 100dvh; z-index: 40;
  width: 340px; border-left: 1px solid var(--line); background: var(--bg-2);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
}
#chat.show { transform: translateX(0); }
/* Con el chat abierto, la rejilla deja hueco para que no se solapen los vídeos */
body.chat-open .stage-body { padding-right: 340px; }
/* …y el avatar de la topbar se desplaza el ancho del chat para no quedar oculto tras él */
body.chat-open .me-avatar { transform: translateX(-340px); }
#chat .chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-dim); flex: none; }
/* El input/enviar quedan fijos abajo; solo la lista de mensajes hace scroll */
.chat-input { flex: none; }
#messages {
  flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px;
  /* Scroll con el estilo de renovatio-comunicacion.com: fino, thumb en accent, pista transparente */
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--accent); }
.msg .who { color: var(--accent); font-size: 11px; letter-spacing: .03em; }
.msg .who .time { color: var(--fg-faint); margin-left: 6px; }
.msg .text { font-family: var(--sans); font-size: 13px; font-weight: 300; color: var(--chat-fg, var(--fg)); word-break: break-word; white-space: pre-wrap;margin-top: 10px; }
.msg .text a { color: var(--accent); text-decoration: underline; word-break: break-all; }
/* Imagen enviada en el chat: miniatura clicable (se amplía en un lightbox dentro de la app) */
.msg .chat-img { display: block; max-width: 100%; max-height: 260px; height: auto; margin-top: 6px; border: 1px solid var(--line); cursor: zoom-in; }
/* Vídeo de YouTube incrustado en el chat */
.msg .chat-yt { display: block; width: 100%; aspect-ratio: 16 / 9; margin-top: 6px; border: 1px solid var(--line); background: #000; }
/* Vídeo enviado en el chat: reproductor + botón de descarga en una esquina */
.msg .chat-video { position: relative; display: block; margin-top: 6px; width: 100%; max-width: 320px; border: 1px solid var(--line); background: #000; }
.msg .chat-video video { display: block; width: 100%; max-height: 280px; background: #000; }
.chat-video-dl {
  position: absolute; top: 6px; right: 6px; z-index: 2; display: inline-flex;
  align-items: center; justify-content: center; width: 30px; height: 30px;
  background: rgba(0,0,0,.6); color: #fff; border: 1px solid rgba(255,255,255,.25); text-decoration: none;
}
.chat-video-dl:hover { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chat-video-dl svg { width: 16px; height: 16px; }
/* Documento enviado en el chat: tarjeta con icono del formato, nombre y tamaño (descarga) */
.msg .chat-file {
  display: flex; align-items: center; gap: 10px; margin-top: 6px; padding: 8px 10px;
  background: var(--bg-3); border: 1px solid var(--line); text-decoration: none; color: var(--fg);
  transition: border-color .15s;
}
.msg .chat-file:hover { border-color: var(--accent); }
.chat-file-ic { flex: none; display: inline-flex; }
.chat-file-ic svg { width: 30px; height: 36px; display: block; }
.chat-file-meta { display: flex; flex-direction: column; min-width: 0; }
.chat-file-name { font-family: var(--sans); font-size: 13px; line-height: 1.3; word-break: break-word; }
.chat-file-size { font-size: 11px; color: var(--fg-dim); margin-top: 2px; letter-spacing: .02em; }
/* Lightbox de imagen a pantalla completa */
#imgLightbox {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 32px;
  background: rgba(0,0,0,.85); cursor: zoom-out;
}
#imgLightbox.show { display: flex; }
#imgLightbox img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 4px 24px rgba(0,0,0,.6); }
/* Zona de "soltar para enviar" al arrastrar una imagen sobre el chat */
#chat.drag::after {
  content: "Suelta el archivo para enviarlo";
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px;
  background: color-mix(in oklch, var(--bg) 72%, transparent);
  border: 2px dashed var(--accent); color: var(--accent);
  font-size: 13px; letter-spacing: .03em;
}
.msg.self .who { color: var(--fg-dim); }
.chat-input { display: flex; border-top: 1px solid var(--line); }
.chat-input input,
.chat-input textarea { flex: 1; border: 0; background: var(--bg); color: var(--fg); padding: 12px 14px; font-family: var(--mono); font-size: 13px; }
.chat-input input:focus,
.chat-input textarea:focus { outline: none; }
/* Caja de chat multilínea: una fila por defecto, crece con el contenido (límite por JS),
   sin tirador de redimensión y respetando los saltos de línea al escribir. */
.chat-input textarea { resize: none; line-height: 1.4; max-height: 120px; overflow-y: auto; align-self: stretch; }
.chat-input button { border: 0; background: var(--accent); color: var(--accent-fg); padding: 0 18px; cursor: pointer; font-family: var(--mono); font-size: 10px;text-transform: uppercase;}
/* Botón de adjuntar imagen: icono discreto, no el botón sólido de "Enviar" */
.chat-input .chat-attach {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; color: var(--fg-dim); padding: 0 12px; transition: color .15s;
}
.chat-input .chat-attach:hover { color: var(--accent); }
.chat-input .chat-attach svg { width: 20px; height: 20px; }

/* ---- Barra de controles (fixed, siempre visible) ---- */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 14px; padding: 22px 20px;
  align-items: center; justify-content: center;
  background: linear-gradient(to top, rgba(0,0,0,.55), transparent);
}
.ctrl { position: relative; display: inline-flex; }
.ctrl-btn {
  width: 54px; height: 54px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
  border: 1px solid var(--line); background: color-mix(in oklch, var(--bg-3) 88%, transparent);
  color: var(--icon, var(--fg)); backdrop-filter: blur(6px);
  transition: background .15s, border-color .15s, color .15s;
}
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn:hover { border-color: var(--fg-dim); background: var(--bg-3); }
.ctrl-btn.active { border-color: var(--accent); color: var(--accent); }
/* Mic/cámara desactivados: fondo rojo bien visible */
.ctrl-btn.off { background: var(--danger); border-color: var(--danger); color: var(--fg); }
.ctrl-btn.off:hover { background: var(--danger); border-color: var(--danger); filter: brightness(1.1); }
.ctrl-btn.danger { border-color: var(--danger); color: var(--danger); }
.ctrl-btn.danger:hover { background: var(--danger); color: var(--fg); border-color: var(--danger); }
.ctrl .badge { position: absolute; top: -4px; right: -4px; background: var(--accent); color: var(--accent-fg); font-size: 10px; border-radius: 50%; width: 16px; height: 16px; display: none; align-items: center; justify-content: center; }
.ctrl .badge.show { display: flex; }

/* Botón IA / indicador de grabación */
.ctrl-btn.ai-active { border-color: var(--accent); color: var(--accent); }
.ctrl-btn.recording { border-color: var(--danger); color: var(--danger); animation: recPulse 1.6s ease-in-out infinite; }
.ctrl-btn.indicator { pointer-events: none; cursor: default; }
@keyframes recPulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* Menú del botón de compartir (pantalla / vídeo de YouTube) */
.share-menu {
  position: fixed; bottom: calc(var(--controls-h) - 8px); left: 50%; transform: translateX(-50%);
  z-index: 40; flex-direction: column; gap: 2px; padding: 6px;
  background: var(--bg-2); border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
.share-menu.show { display: flex; }
.share-item {
  display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer;
  font-family: var(--mono); font-size: 12px; color: var(--fg); text-align: left;
  background: none; border: none; padding: 11px 16px; white-space: nowrap;
}
.share-item:hover { background: var(--bg-3); color: var(--accent); }
.share-item svg { width: 18px; height: 18px; flex: none; }

/* Modal: URL del vídeo de YouTube */
.yt-modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,.6); padding: 20px;
}
.yt-modal.show { display: flex; }
.yt-modal-box {
  width: 100%; max-width: 460px; background: var(--bg-2); border: 1px solid var(--line); padding: 26px;
}
.yt-modal-title { font-size: 16px; font-weight: 500; letter-spacing: .02em; margin-bottom: 8px; }
.yt-modal-sub { color: var(--fg-dim); font-size: 13px; line-height: 1.5; margin: 0 0 18px; }
.yt-modal-box input { width: 100%; padding: 12px 14px; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); font-family: var(--mono); font-size: 14px; }
.yt-modal-box input:focus { outline: none; border-color: var(--accent); }
.yt-modal-err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 8px; }
.yt-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.yt-modal-actions .btn { margin: 0; }

/* Tile de vídeo de YouTube: el iframe llena el tile; overlay para espectadores */
.tile.yt-tile { background: #000; }
.yt-host { position: absolute; inset: 0; }
.yt-host iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.yt-overlay { position: absolute; inset: 0; z-index: 2; display: none; }
.yt-overlay.block { display: block; }            /* espectadores: bloquea el control */
.yt-overlay.prompt {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  background: rgba(0,0,0,.45); color: #fff; font-size: 14px; letter-spacing: .03em; text-align: center;
}
.yt-overlay.prompt::before { content: "▶"; margin-right: 10px; font-size: 20px; }

/* Mockup responsive: ventana flotante movible y redimensionable con una web embebida */
.mockup-win {
  position: fixed; z-index: 50; display: flex; flex-direction: column;
  background: #111; border: 1px solid var(--line); box-shadow: 0 14px 44px rgba(0,0,0,.6);
  min-width: 220px; min-height: 240px; overflow: hidden;
}
.mockup-bar {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; cursor: move;
  background: var(--bg-2); border-bottom: 1px solid var(--line); user-select: none; flex: none;
}
.mockup-title { flex: 1; font-size: 12px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mockup-bar button {
  width: 26px; height: 24px; cursor: pointer; background: none; border: 1px solid var(--line);
  color: var(--fg-dim); font-size: 13px; line-height: 1; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.mockup-bar button:hover { color: var(--accent); border-color: var(--accent); }
.mockup-body { position: relative; flex: 1; background: #fff; min-height: 0; }
.mockup-body iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
/* Escudo que cubre el iframe durante el arrastre/redimensionado (si no, el iframe roba el ratón) */
.mockup-shield { position: absolute; inset: 0; z-index: 2; display: none; }
.mockup-shield.on { display: block; }
.mockup-resize {
  position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize; z-index: 3;
  background: linear-gradient(135deg, transparent 0 45%, var(--fg-dim) 45% 55%, transparent 55% 68%, var(--fg-dim) 68% 78%, transparent 78%);
}

/* Aviso de peticiones de acceso (lo ve el admin dentro de la sala) */
.knock-notice {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 35;
  display: none; flex-direction: column; gap: 8px; width: min(440px, calc(100% - 32px));
}
.knock-notice.show { display: flex; }
.knock-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-2); border: 1px solid var(--accent); padding: 10px 12px 10px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.knock-row .kn-name { flex: 1; font-size: 14px; color: var(--fg); min-width: 0; }
.knock-row .kn-name small { display: block; color: var(--fg-dim); font-size: 11px; letter-spacing: .02em; }
.knock-row .btn { padding: 8px 12px; font-size: 10px; margin: 0; }

/* Switch de bloqueo en el perfil del admin */
.fx-admin .lock-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 10px; color: var(--fg); cursor: pointer; }

/* Panel de participantes */
#peopleList { padding: 8px 0; }
.person-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.person-name { flex: 1; min-width: 0; font-size: 14px; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-ico {
  width: 32px; height: 32px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: none; color: var(--fg-dim); padding: 0;
}
.person-ico svg { width: 16px; height: 16px; }
.person-ico.on { color: var(--accent); border-color: var(--accent); }
.person-ico.off { color: var(--danger); border-color: var(--danger); }
button.person-ico { cursor: pointer; transition: filter .15s; }
button.person-ico:hover { filter: brightness(1.25); }
button.person-ico.on { } /* admin puede cortar (on = pulsable) */
.person-ico.idle { cursor: default; }
.person-kick { color: var(--danger); border-color: var(--danger); cursor: pointer; }
.person-kick:hover { background: var(--danger); color: #fff; }

/* ============================================================
   Responsive (móvil ≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  /* Cabecera y controles fixed más compactos (se reserva su espacio con estos vars) */
  :root { --header-h: 60px; --controls-h: 68px; --safety: 8px; }

  /* ---- Header (fixed; nombre de sala ya oculto globalmente) ---- */
  .topbar { padding: 12px 14px; gap: 10px; }
  .me-avatar { width: 36px; height: 36px; font-size: 18px; }

  /* ---- Vista de sala / Stage ----
     Tu cámara (tile .local) arriba a ancho completo; el resto (con cámara o no) debajo
     en 2 columnas. La rejilla hace scroll vertical. */
  /* El stage se acota al viewport VISIBLE (dvh). Con 100vh, en móvil el stage es más alto
     que la pantalla (barra del navegador) y la rejilla no scrolleaba / quedaba pegada arriba. */
  #stage { height: 100vh; height: 100dvh; }
  .stage-body { min-height: 0; }
  #grid, #grid.solo, #grid.compact {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 8px; padding: 10px;
    align-content: start; justify-content: stretch;
    min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  #grid .tile, #grid.solo .tile, #grid.compact .tile {
    width: 100%; max-width: none; height: auto; max-height: none;
    aspect-ratio: 16 / 9; align-self: start;
  }
  /* En compacto (todas las cámaras apagadas) el placeholder vuelve a ocupar el tile entero */
  #grid.compact .tile .ph { position: absolute; inset: 0; padding: 0; }
  /* Tu propio tile: primera fila, a ancho completo */
  .tile.local { grid-column: 1 / -1; order: -1; }
  /* El badge de admin en los tiles muestra solo el escudo (sin la palabra "Administrador") */
  .tile .host-badge { gap: 0; padding: 4px; }
  .tile .host-badge .host-label { display: none; }

  /* Pantalla compartida (spotlight): apilado en columna en vez de columna lateral.
     justify-content: flex-start anula el `center` de la regla base, que en columna bajaba
     los tiles al centro vertical (parecía que "se caían"). Ahora quedan pegados arriba. */
  #grid.spotlight { flex-direction: column; align-items: stretch; justify-content: flex-start; align-content: flex-start; overflow-y: auto; padding: 10px; }
  #grid.spotlight > .tile { width: 100%; height: auto; max-height: 60vh; aspect-ratio: 16 / 9; flex: none; }
  /* Apilado en columna: los participantes crecen hacia abajo y se ven scrolleando
     la rejilla en vertical (antes era una fila con scroll horizontal, incómodo en móvil). */
  #grid.spotlight #spotSide {
    flex-direction: column; width: 100%; max-height: none; flex: none;
    overflow: visible; gap: 8px;
  }
  #spotSide .tile { width: 100%; flex: none; }

  /* Chat y paneles laterales a pantalla completa (si no, taparían/empujarían la rejilla) */
  #chat, .side-panel { width: 100%; }
  body.chat-open .stage-body { padding-right: 0; }
  body.chat-open .me-avatar { transform: none; }
  /* Con el chat abierto, el header queda por encima del panel: lo ocultamos (vuelve al cerrar) */
  body.chat-open .topbar { display: none; }
  .fx-panel { left: 12px; right: 12px; width: auto; top: 64px; }

  /* ---- Footer / controles (fixed abajo) ---- */
  .controls { gap: 6px; padding: 10px 8px; }
  .ctrl-btn { width: 44px; height: 44px; }
  .ctrl-btn svg { width: 20px; height: 20px; }
  /* En móvil ocultamos: alertas (notif), compartir (screen) y Picture-in-Picture */
  #notifBtn, #screenBtn, #pipBtn { display: none !important; }

  /* Evita el auto-zoom de iOS Safari al enfocar un campo: con font-size ≥ 16px no hace zoom.
     El chat necesita su propia regla por tener un selector más específico (.chat-input input). */
  input, textarea, select { font-size: 16px; }
  .chat-input input, .chat-input textarea { font-size: 16px; }

  /* ---- Vista de entrada ----
     La tarjeta hace scroll y el botón Entrar queda fijo abajo, siempre visible. */
  .join-wrap {
    align-items: flex-start; justify-content: flex-start;
    /* Altura acotada al viewport para que el scroll interno funcione (min-height crecía
       con el contenido y, con body overflow:hidden, lo de abajo quedaba inalcanzable). */
    height: 100vh; height: 100dvh; min-height: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 16px 16px 92px;
  }
  .join-card { padding: 22px 18px; }
  #joinBtn {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    margin: 0; border-radius: 0; padding: 16px;
    box-shadow: 0 -2px 14px rgba(0,0,0,.55);
  }
}

/* ============================================================
   PWA instalada (standalone): respeta las zonas seguras (notch / barra de inicio).
   Como la barra de estado es translúcida (black-translucent + viewport-fit=cover),
   el contenido va por debajo y hay que apartarlo con env(safe-area-inset-*).
   ============================================================ */
@media (display-mode: standalone) {
  .topbar          { padding-top: max(14px, env(safe-area-inset-top)); }
  .controls        { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  #chat .chat-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .chat-input      { padding-bottom: env(safe-area-inset-bottom); }
  .side-head       { padding-top: max(14px, env(safe-area-inset-top)); }
  #joinBtn         { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .join-wrap       { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* ---------- Traducción simultánea ---------- */
#transBtn { position: relative; }
.lang-tag { position: absolute; bottom: 3px; right: 3px; font-size: 9px; font-weight: 700; line-height: 1; letter-spacing: .3px; }
/* Mismo estilo que el menú de compartir (.share-menu / .share-item) */
.lang-menu {
  position: fixed; bottom: calc(var(--controls-h) - 8px); left: 50%; transform: translateX(-50%);
  z-index: 40; display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: var(--bg-2); border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
.lang-menu-head {
  font-family: var(--mono); font-size: 11px; color: var(--fg); opacity: .5;
  padding: 6px 16px 4px; white-space: nowrap;
}
.lang-opt {
  display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer;
  font-family: var(--mono); font-size: 12px; color: var(--fg); text-align: left;
  background: none; border: none; padding: 11px 16px; white-space: nowrap;
}
.lang-opt:hover { background: var(--bg-3); color: var(--accent); }
.lang-opt.sel { color: var(--accent); }
.lang-opt.sel::after { content: "✓"; margin-left: auto; padding-left: 14px; }
.captions {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  max-width: min(90vw, 720px); background: rgba(0,0,0,.72); color: #fff;
  padding: 8px 14px; border-radius: 10px; font-size: 16px; line-height: 1.35;
  text-align: center; z-index: 55; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.captions.show { opacity: 1; }
