:root {
  --bg: #0b0d12; --panel: #161a22; --panel2: #1d2230; --line: #2a3040;
  --text: #eef1f6; --muted: #9aa3b2; --accent: #3b82f6;
  --ok: #22c55e; --warn: #f59e0b; --danger: #ef4444;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overflow: hidden; }

/* ---------- Botones ---------- */
.btn { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; margin-top: 10px; padding: 15px; }
.btn:active { transform: scale(.98); }

/* ---------- Lobby ---------- */
.lobby { height: 100%; display: grid; place-items: center; padding: 18px; }
.card { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 24px; }
.card h1 { margin: 0 0 4px; font-size: 26px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.linkrow { display: flex; gap: 8px; margin-bottom: 8px; }
.linkrow input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 11px 12px; font-size: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 12px; text-align: center; }

/* ---------- Sala ---------- */
.room { position: relative; height: 100dvh; overflow: hidden; }

.topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center;
  gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { color: #fff; background: rgba(239,68,68,.92); font-weight: 700; font-size: 12px;
  padding: 4px 10px; border-radius: 999px; }
.badge { background: rgba(0,0,0,.5); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; color: #fff; }
#connBadge { margin-left: auto; }
.btn-badge { background: rgba(0,0,0,.5); border: 1px solid var(--line); color: #fff; border-radius: 999px;
  width: 34px; height: 34px; cursor: pointer; font-size: 14px; }

/* videos */
.videos { position: absolute; inset: 0; background: #000; }
.tile { position: absolute; overflow: hidden; background: #11151c; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.local video { transform: scaleX(-1); }
.tile.remote { inset: 0; }
.tile.local { width: 33%; max-width: 150px; aspect-ratio: 3 / 4; right: 12px; top: 64px;
  border-radius: 14px; border: 2px solid rgba(255,255,255,.25); box-shadow: 0 4px 16px rgba(0,0,0,.45); z-index: 4; }
.tile .avatar { position: absolute; inset: 0; display: none; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; text-align: center; color: var(--muted);
  background: radial-gradient(circle at 50% 40%, #243042, #11151c); padding: 10px; }
.tile.cam-off .avatar { display: flex; }
.tile.cam-off video { visibility: hidden; }
.tap-to-play { position: absolute; inset: 0; z-index: 3; border: none; cursor: pointer;
  background: rgba(0,0,0,.62); color: #fff; font-size: 16px; font-weight: 700; display: grid; place-items: center; padding: 20px; text-align: center; }
.tap-to-play[hidden] { display: none; }
.avatar-ic { font-size: 40px; width: 84px; height: 84px; display: grid; place-items: center;
  background: var(--panel2); border-radius: 50%; }
.tile.local .avatar-ic { font-size: 22px; width: 44px; height: 44px; }
.tile.local .avatar div:last-child { font-size: 11px; }

/* controles */
.controls { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 12px;
  justify-content: center; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.ctrl { width: 54px; height: 54px; border-radius: 50%; border: none; background: rgba(255,255,255,.16);
  backdrop-filter: blur(6px); color: #fff; font-size: 22px; cursor: pointer; display: grid; place-items: center; }
.ctrl:active { transform: scale(.93); }
.ctrl.off { background: rgba(255,255,255,.92); color: #111; }
.ctrl.danger { background: var(--danger); }
.ctrl[hidden] { display: none; }

/* chat (móvil: panel deslizable desde abajo) */
.chat { position: absolute; left: 0; right: 0; bottom: 0; z-index: 8; height: 78%;
  background: var(--panel); border-top-left-radius: 18px; border-top-right-radius: 18px;
  display: flex; flex-direction: column; transform: translateY(100%); transition: transform .25s ease;
  border-top: 1px solid var(--line); }
body.chat-open .chat { transform: translateY(0); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
  border-bottom: 1px solid var(--line); font-weight: 700; }
.chatlog { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px;
  background: var(--bg); }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.35;
  overflow-wrap: anywhere; }
.msg .meta { display: block; font-size: 10px; opacity: .65; margin-top: 3px; text-align: right; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--panel2); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; }
.chatform { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--panel); }
.chatform input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 22px; padding: 12px 16px; font-size: 15px; }
.chatform .btn { border-radius: 50%; width: 46px; height: 46px; padding: 0; flex: none; }

/* diagnóstico */
.diag-panel { position: absolute; top: 56px; left: 12px; z-index: 7; background: rgba(0,0,0,.72);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
dl.diag { margin: 0; display: grid; grid-template-columns: auto auto; gap: 5px 14px; font-size: 12.5px; }
dl.diag dt { color: var(--muted); }
dl.diag dd { margin: 0; text-align: right; }
.ok { color: var(--ok); } .warn { color: var(--warn); }

/* toast */
.toast { position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%); z-index: 9;
  background: rgba(0,0,0,.88); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px;
  max-width: 88%; text-align: center; }
.toast[hidden] { display: none; }

/* ---------- Escritorio ---------- */
@media (min-width: 860px) {
  body { overflow: auto; }
  .room { display: grid; grid-template-columns: 1fr 340px; grid-template-rows: 1fr 78px; height: 100dvh; }
  .topbar { right: 340px; }
  .videos { position: relative; inset: auto; grid-column: 1; grid-row: 1; }
  .controls { position: relative; inset: auto; grid-column: 1; grid-row: 2; align-items: center; padding: 0; }
  .chat { position: relative; inset: auto; transform: none; grid-column: 2; grid-row: 1 / span 2;
    height: auto; border-radius: 0; border-top: none; border-left: 1px solid var(--line); }
  body.chat-open .chat { transform: none; }
  .chat-head .btn-badge { display: none; }
  #chatBtn { display: none; }
  .tile.local { top: auto; bottom: 14px; width: 190px; max-width: 26%; }
}
