:root {
  --bg: #0b0c10; --panel: #14161d; --line: #262a35; --text: #e8e9ee; --muted: #8a8f9e;
  --accent: #ff3d2e; --accent2: #ffb020; --ok: #3ddc84; --warn: #ffb020; --bad: #ff4d4d;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 "IBM Plex Sans", system-ui, sans-serif; }
[hidden] { display: none !important; }
h2, h3, .brand, button, .roomCode { font-family: "Chakra Petch", system-ui, sans-serif; letter-spacing: .02em; }
h2 { font-size: 17px; margin: 0 0 10px; text-transform: uppercase; }
h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; }
code, kbd { font-family: ui-monospace, Menlo, monospace; }
.muted { color: var(--muted); } .small { font-size: 12px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.brand { font-size: 20px; font-weight: 700; }
.mark { background: var(--accent); color: #fff; padding: 1px 8px; border-radius: 4px; margin-right: 6px; transform: skew(-10deg); display: inline-block; }
.net { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; }
.net.on .dot { background: var(--ok); } .net.off .dot { background: var(--bad); }

.lobby { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; padding: 20px; max-width: 1100px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
input { background: #0e1015; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 10px 12px; font: inherit; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.code { width: 110px; text-transform: uppercase; letter-spacing: .3em; font-family: "Chakra Petch", monospace; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px; font-size: 15px; font-weight: 700; cursor: pointer; flex: 1; }
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.danger { background: #2a1214; color: #ff8a80; border: 1px solid #4a1d20; width: 100%; flex: none; }
button.small { padding: 6px 10px; font-size: 13px; }

.drop { display: block; border: 1.5px dashed var(--line); border-radius: 8px; padding: 18px; text-align: center; cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--accent); }
.romInfo { margin: 8px 0 0; font-size: 13px; min-height: 1em; }
.romInfo.ok { color: var(--ok); } .romInfo.err { color: var(--bad); }

.rooms { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rooms li.room { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: #0e1015; border: 1px solid var(--line); border-radius: 8px; }
.rooms .rc { font-family: "Chakra Petch", monospace; font-weight: 700; color: var(--accent2); letter-spacing: .15em; }
.rooms .rn { flex: 1; } .rooms button { flex: 0 0 auto; padding: 6px 14px; font-size: 13px; }

.keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.keys table { border-collapse: collapse; width: 100%; font-size: 13px; }
.keys td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.keys td:last-child { text-align: right; }
kbd { background: #1f2330; border: 1px solid #343a4a; border-bottom-width: 2px; border-radius: 4px; padding: 0 6px; margin-left: 3px; font-size: 12px; }

.game { display: grid; grid-template-columns: 1fr 260px; gap: 0; height: calc(100vh - 53px); }
.stage { position: relative; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.stage canvas, .stage video { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; outline: none; display: block; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(0,0,0,.75); text-align: center; padding: 20px; }
.overlay p { max-width: 420px; margin: 0; }
.spinner { width: 36px; height: 36px; border: 3px solid #333; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.side { background: var(--panel); border-left: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.roomBox { text-align: center; }
.roomCode { font-size: 34px; font-weight: 700; color: var(--accent2); letter-spacing: .25em; margin: 2px 0 6px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.stats div { background: #0e1015; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.stats dt { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.stats dd { margin: 0; font-family: "Chakra Petch", monospace; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 140px; gap: 6px; }
.chat ul { flex: 1; list-style: none; margin: 0; padding: 8px; background: #0e1015; border: 1px solid var(--line); border-radius: 8px; overflow: auto; font-size: 13px; }
.chat li b { color: var(--accent2); } .chat li.sys { color: var(--muted); font-style: italic; }

@media (max-width: 760px) {
  .lobby { padding: 16px; }
  .game { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .stage { aspect-ratio: 4 / 3; }
}

.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opts label { font-size: 11px; color: var(--muted); text-transform: uppercase; display: grid; gap: 4px; }
.opts label[hidden] { display: none !important; }
select { background: #0e1015; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 8px; font: 13px "IBM Plex Sans", system-ui, sans-serif; width: 100%; }
.diag { font: 12px/1.5 ui-monospace, Menlo, monospace; background: #0e1015; border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: var(--muted); white-space: pre-line; }
.diag b { color: var(--text); font-weight: 600; }
.diag .bad { color: var(--bad); } .diag .warn { color: var(--warn); } .diag .ok { color: var(--ok); }
/* Imagen: JS calcula tamaño y posición en px (layoutScreen). */
.stage canvas, .stage video { position: absolute; flex: none; object-fit: fill; }
.stage.pix canvas, .stage.pix video { image-rendering: pixelated; }
/* Pantalla completa: toda la página, sin barra ni panel. */
body.fs { overflow: hidden; }
body.fs .top, body.fs .side { display: none !important; }
body.fs .stage { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 50; }
body.fs .stage { cursor: none; }
.okTxt { color: var(--ok); } .warnTxt { color: var(--warn); } .badTxt { color: var(--bad); }
/* El video del anfitrión se decodifica en este <video> invisible y se dibuja en #canvas (WebGL). */
.stage video.vsrc { position: absolute; left: 0; top: 0; width: 2px; height: 2px; opacity: 0.01; pointer-events: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 6px; cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }
.progress { width: min(360px, 80%); height: 8px; background: #22252f; border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s; }
.roomLink { font-size: 12px; padding: 6px 8px; margin-bottom: 6px; text-align: center; color: var(--muted); }

/* ---- Lobby con panel derecho (conectados + chat general) ---- */
.lobbyWrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 0; max-width: 1400px; margin: 0 auto; min-height: calc(100vh - 53px); }
.lobbyWrap .lobby { max-width: none; margin: 0; }
.people { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; height: calc(100vh - 53px); position: sticky; top: 0; }
.peopleBox { padding: 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.peopleBox:first-child { max-height: 45%; }
.peopleBox h2 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--ok); color: #06210f; border-radius: 99px; padding: 0 8px; font-size: 12px; }
.users { list-style: none; margin: 0; padding: 0; overflow: auto; }
.users li { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 6px; font-size: 14px; }
.users li:hover { background: #0e1015; }
.users li.me .uname { color: var(--accent2); }
.uname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ustat { font-size: 11px; color: var(--muted); white-space: nowrap; }
.ustat.play { color: var(--accent); } .ustat.room { color: var(--accent2); cursor: pointer; text-decoration: underline dotted; }
.flag { width: 20px; height: 15px; border-radius: 2px; flex: none; object-fit: cover; box-shadow: 0 0 0 1px #0006; }
.flagTxt { width: 20px; font-size: 10px; color: var(--muted); text-align: center; flex: none; font-family: ui-monospace, monospace; }
.gchat { flex: 1; border-bottom: 0; }
.chatlog { flex: 1; list-style: none; margin: 0 0 8px; padding: 8px; background: #0e1015; border: 1px solid var(--line); border-radius: 8px; overflow: auto; font-size: 13px; min-height: 120px; }
.chatlog li, .chat ul li { margin: 2px 0; line-height: 1.35; }
.chatlog li b, .chat ul li b { color: var(--accent2); }
.chatlog li .flag, .chat ul li .flag { width: 16px; height: 12px; vertical-align: -1px; margin-right: 4px; }
.chatlog li.sys { color: var(--muted); font-style: italic; }
.row.nomargin { margin-top: 0; }
select.country { width: 92px; flex: none; }
.tabs { display: flex; gap: 4px; }
.tab { flex: 1; padding: 5px 8px; font-size: 12px; background: transparent; border: 1px solid var(--line); color: var(--muted); }
.tab.on { background: #1f2330; color: var(--text); }
.tab .dotNew { display: inline-block; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; margin-left: 5px; vertical-align: middle; }
@media (max-width: 1000px) {
  .lobbyWrap { grid-template-columns: 1fr; }
  .people { height: auto; position: static; border-left: 0; border-top: 1px solid var(--line); }
  .peopleBox:first-child { max-height: 260px; }
}
.row.nomargin { flex-wrap: nowrap; } .row.nomargin input { flex: 1; width: auto; min-width: 0; }

/* ---- Ventana de controles ---- */
.topRight { display: flex; align-items: center; gap: 14px; }
.topRight button { flex: none; }
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(5,6,10,.72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modalBox { width: min(680px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 20px 60px #000a; display: flex; flex-direction: column; gap: 12px; }
.modalHead { display: flex; align-items: center; justify-content: space-between; }
.modalHead h2 { margin: 0; }
.modalHead button { flex: none; }
.ctlTabs .tab { font-size: 13px; padding: 7px 8px; }
.ctlList { display: grid; gap: 4px; }
.ctlRow { display: grid; grid-template-columns: 190px 1fr auto auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #0e1015; border: 1px solid var(--line); transition: background .08s; }
.ctlRow.live { background: #2a1a12; border-color: var(--accent); }
.ctlRow button { flex: none; }
.ctlName { font-size: 14px; }
.ctlBinds { display: flex; flex-wrap: wrap; gap: 4px; min-height: 24px; align-items: center; }
.ctlBinds kbd { cursor: pointer; font-size: 12px; padding: 2px 7px; margin: 0; }
.ctlBinds kbd:hover { border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.ctlWait { color: var(--accent2); font-size: 13px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .45; } }
.modalFoot { display: flex; gap: 12px; align-items: flex-end; }
.modalFoot p { margin: 0; flex: 1; }
.modalFoot button { flex: none; }
#ctlPadBox select { width: 100%; }
@media (max-width: 560px) { .ctlRow { grid-template-columns: 1fr auto auto; } .ctlBinds { grid-column: 1 / -1; order: 3; } }

/* ---- Panel lateral compacto en partida ---- */
.side { position: relative; gap: 10px; }
.roomLine { display: flex; align-items: center; gap: 8px; }
.roomLine .roomCode { font-size: 22px; letter-spacing: .18em; margin: 0; flex: 1; text-align: left; }
.roomLine button { flex: none; }
.roomBox { text-align: left; }
.roomBox .roomLink { margin: 6px 0 0; }
.vsLine { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); background: #0e1015; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.vsLine b { color: var(--text); font-family: "Chakra Petch", monospace; margin-left: 4px; }
.toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tool { position: relative; flex: none; padding: 7px 4px; font-size: 12px; background: transparent; border: 1px solid var(--line); color: var(--text); white-space: nowrap; }
.tool.on { background: #1f2330; border-color: var(--accent); }
.alertDot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px var(--panel); }
.pop { position: absolute; left: 14px; right: 14px; z-index: 20; background: #171a22; border: 1px solid #343a4a; border-radius: 10px; padding: 12px; box-shadow: 0 14px 40px #000c; display: flex; flex-direction: column; gap: 10px; }
.pop .stats { margin: 0; }
.pop #btnFull { width: 100%; }
.side .chat { min-height: 0; }
.bottomRow { margin-top: 0; }
.bottomRow button { flex: 1; }
.bottomRow .danger { width: auto; }
/* ajustes de ancho del panel en partida */
.game { grid-template-columns: 1fr 310px; }
#roomTitle { white-space: nowrap; }
.tool { font-size: 11.5px; padding: 7px 2px; overflow: hidden; text-overflow: ellipsis; }
.pop .stats { grid-template-columns: 1fr 1fr; }
.pop .stats div { min-width: 0; }
.pop .stats dd { font-size: 14px; }
.pop .opts select { min-width: 0; }
.toolbar { grid-template-columns: 1.4fr 1fr 1fr; gap: 5px; }
.tool { font-size: 11.5px; letter-spacing: 0; }
.pop .stats dd#stMode { white-space: normal; font-size: 13px; }
.specCount { color: var(--accent2); cursor: help; }
.rooms li.room > .ustat { flex: none; }
.rooms li.room button.ghost { border: 1px solid var(--line); }

/* Modo competitivo */
.muted.small { font-size: 12px; margin: 8px 0 0; line-height: 1.4; }
.modeTag { flex: none; font-size: 11px; padding: 2px 7px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.modeTag.comp { color: #ffd34d; border-color: #6b5a1e; background: #2a240c; }

/* Lobby a pantalla completa: ROM y Jugador arriba, salas abiertas ocupando el resto. */
.lobbyWrap { max-width: none; }
.lobbyWrap .lobby { grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; align-content: stretch;
  min-height: calc(100vh - 53px); padding: 20px 24px; }
.lobbyWrap .lobby > .card:not(.wide) { display: flex; flex-direction: column; }
.lobbyWrap .lobby .card.wide { display: flex; flex-direction: column; min-height: 240px; }
.lobbyWrap .lobby .card.wide .rooms { flex: 1; overflow: auto; }
.lobbyWrap .people { width: auto; }
@media (min-width: 1600px) { .lobbyWrap { grid-template-columns: minmax(0, 1fr) 380px; } }
@media (max-width: 760px) { .lobbyWrap .lobby { grid-template-columns: 1fr; grid-template-rows: auto; min-height: 0; } }

/* Aviso de "abierto en otra pestaña" */
#tabBlock { position: fixed; inset: 0; z-index: 1000; background: rgba(5,6,10,.88); display: grid; place-items: center; padding: 16px; }
#tabBlock .tbBox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 440px; text-align: center; }
#tabBlock h2 { margin: 0 0 8px; font-size: 18px; } #tabBlock button { margin-top: 14px; }

/* Calidad de conexión (barras) y rendimiento del equipo (⚡) en la lista de conectados */
.netq { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; flex: none; cursor: help; }
.netq i { width: 3px; background: #3a3f4d; border-radius: 1px; }
.netq i:nth-child(1) { height: 5px; } .netq i:nth-child(2) { height: 8px; } .netq i:nth-child(3) { height: 12px; }
.netq[data-q="3"] i.on { background: #3ddc84; } .netq[data-q="2"] i.on { background: #f5c542; } .netq[data-q="1"] i.on { background: #ff5a4e; }
.perf { flex: none; font-size: 12px; cursor: help; filter: grayscale(1); opacity: .35; }
.perf.excelente, .perf.bueno { filter: none; opacity: 1; }
.perf.justo { filter: sepia(1) saturate(3); opacity: .9; } .perf.insuficiente { filter: hue-rotate(-50deg) saturate(4); opacity: .9; }
.benchRow { align-items: center; }
.benchRow .muted.small { margin: 0; flex: 1; min-width: 160px; }
#tabBlock .tbBox { text-align: left; } #tabBlock .tbBox h2 { text-align: center; }
.benchRes { margin: 10px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.5; }
.benchTier { font-size: 22px; font-weight: 800; text-align: center; margin: 4px 0 8px; }
.benchTier.excelente, .benchTier.bueno { color: #3ddc84; } .benchTier.justo { color: #f5c542; } .benchTier.insuficiente { color: #ff5a4e; }

/* Opciones y cuenta */
.modalBox.small { width: min(420px, 100%); }
.optGrid { display: grid; gap: 12px; }
.optGrid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.optGrid select, .optGrid input[type=range] { width: 100%; }
.optGrid input[type=range] { accent-color: var(--accent); }
.accTabs { margin-bottom: 4px; }
.accFields { display: flex; flex-direction: column; gap: 10px; margin: 6px 0; }
.accErr { color: #ff6b5e; font-size: 13px; margin: 0; }
.regMark { color: #3ddc84; font-size: 11px; margin-left: 4px; }
.topRight { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 600px) { .topRight .net span { display: none; } .topRight button { padding: 6px 8px; } }

/* Cable / WiFi y ping directo en la lista de conectados */
.conn { flex: none; display: inline-flex; width: 14px; cursor: help; }
.conn.cable { color: #3ddc84; } .conn.wifi { color: #6cb6ff; } .conn.none { width: 0; }
.pchip { flex: none; font-size: 11px; font-variant-numeric: tabular-nums; padding: 1px 5px; border-radius: 6px; background: #1a1e28; cursor: help; }
.pchip:empty { display: none; }
.pchip.ok { color: #3ddc84; } .pchip.warn { color: #f5c542; } .pchip.bad { color: #ff6b5e; } .pchip.wait { color: var(--muted); }

.connAsk { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border: 1px solid var(--accent2, #6cb6ff); border-radius: var(--radius); background: var(--panel); font-size: 14px; }
.connAsk span { flex: 1; min-width: 200px; } .connAsk button svg { vertical-align: -2px; }
