:root {
  --bg: #0a1226;
  --panel: rgba(16, 28, 54, 0.82);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef3fb;
  --muted: #8ea0bf;
  --ball: #e4ff3c;
  --a: #ff6b57;
  --b: #3cc8ff;
  --ok: #4ff0a0; --mid: #ffd24a; --bad: #ff5a5a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'Outfit', system-ui, sans-serif; overflow: hidden; }
body {
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(60, 200, 255, 0.16), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(255, 107, 87, 0.16), transparent 60%),
    var(--bg);
}
button, input { font-family: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 20px; }
.screen.active { display: flex; }
#game.screen { padding: 0; }

/* -------- paneles y controles -------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 26px;
  width: min(440px, 94vw); backdrop-filter: blur(14px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column; gap: 12px;
}
.panel.wide { width: min(860px, 96vw); max-height: 94vh; overflow: auto; }
h1, h2 { margin: 0; letter-spacing: 0.5px; }
h2 { font-size: 24px; font-weight: 800; }
.lbl { font-size: 12px; color: var(--muted); letter-spacing: 1.5px; text-transform: uppercase; }
input {
  width: 100%; padding: 13px 15px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05); color: var(--text); font-size: 16px; outline: none; transition: border-color .15s, background .15s;
}
input:focus { border-color: var(--ball); background: rgba(255, 255, 255, 0.08); }
input.code { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 6px; }
.btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font-weight: 800; letter-spacing: 1px; cursor: pointer; font-size: 14px;
  transition: transform .08s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--ball); color: #11200a; border-color: transparent; box-shadow: 0 8px 26px rgba(228, 255, 60, 0.25); flex: 1; }
.btn.primary:hover { background: #efff7a; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 12px; border-radius: 10px; }
.btn.danger { color: #ffb0a6; }
.btn.confirm { background: var(--bad); color: #fff; }
.err { color: var(--bad); margin: 0; font-size: 14px; }

/* -------- menú -------- */
.hero { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.logo { font-size: clamp(54px, 9vw, 92px); font-weight: 900; letter-spacing: 6px; display: flex; align-items: center; gap: 16px; line-height: 1; position: relative; }
.logo em { position: absolute; right: 0; bottom: -18px; font-style: normal; font-size: 14px; letter-spacing: 3px; color: var(--ball); font-weight: 700; }
.ball-ico {
  width: 0.62em; height: 0.62em; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fbffd0, var(--ball) 55%, #a8c414);
  box-shadow: 0 0 40px rgba(228, 255, 60, 0.45); position: relative; animation: bob 1.4s ease-in-out infinite;
}
.ball-ico::after { content: ''; position: absolute; inset: 8%; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.75); border-color: transparent rgba(255,255,255,.75) transparent rgba(255,255,255,.75); transform: rotate(20deg); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.help { max-width: 520px; text-align: center; line-height: 1.6; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; font-weight: 700; }
.rooms { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 230px; overflow: auto; }
.rooms li {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; padding: 10px 12px;
  border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); cursor: pointer; font-size: 14px;
}
.rooms li:hover { background: rgba(255, 255, 255, 0.09); }
.rooms li.empty { display: block; cursor: default; text-align: center; }
.rooms .rv { color: var(--muted); font-weight: 700; }
.st { font-size: 10px; letter-spacing: 1px; padding: 3px 7px; border-radius: 6px; font-weight: 800; }
.st.open { background: rgba(79, 240, 160, 0.15); color: var(--ok); }
.st.live { background: rgba(255, 210, 74, 0.15); color: var(--mid); }
.flag { width: 18px; height: 13px; border-radius: 2px; vertical-align: -1px; object-fit: cover; }
.flag-na { display: inline-block; font-size: 10px; color: var(--muted); }
.pg { font-weight: 800; font-size: 13px; }
.pg-ok { color: var(--ok); } .pg-mid { color: var(--mid); } .pg-bad { color: var(--bad); } .pg-na { color: var(--muted); font-weight: 600; }

/* -------- configuración -------- */
.cfg { display: flex; flex-direction: column; gap: 10px; }
.cfg-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.cfg-row > span { color: var(--muted); font-size: 14px; }
.cfg-row input::placeholder { letter-spacing: 1px; text-transform: none; }
.cfg-row input { width: 170px; padding: 8px 12px; font-size: 14px; text-transform: uppercase; letter-spacing: 3px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--text); padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--ball); color: #11200a; border-color: transparent; }
.chip:disabled { cursor: default; }
.chip:disabled:not(.on) { opacity: 0.45; }
.cfg-surf { display: flex; flex-direction: column; gap: 8px; }
.cfg-surf > span { color: var(--muted); font-size: 14px; }
.surfs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.surf {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 8px 10px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--text); transition: transform .1s, border-color .15s, background .15s;
}
.surf svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.surf b { font-size: 13px; letter-spacing: .3px; }
.surf small { font-size: 11px; color: var(--muted); }
.surf:hover:not(:disabled) { transform: translateY(-2px); background: rgba(255, 255, 255, 0.08); }
.surf.on { border-color: var(--ball); background: rgba(228, 255, 60, 0.08); box-shadow: 0 0 0 3px rgba(228, 255, 60, 0.15); }
.surf:disabled { cursor: default; }
.surf:disabled:not(.on) { opacity: 0.4; }
.cfg.compact { padding: 14px; border-radius: 16px; background: rgba(0, 0, 0, 0.18); border: 1px solid var(--line); }

/* -------- lobby -------- */
.lobby-head { display: flex; justify-content: space-between; align-items: center; }
.codebig { color: var(--ball); letter-spacing: 6px; }
.teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: start; }
.vs { align-self: center; font-weight: 900; font-size: 22px; color: var(--muted); }
.team { border-radius: 18px; padding: 14px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.team.t0 { background: linear-gradient(160deg, rgba(255, 107, 87, 0.16), rgba(255, 107, 87, 0.03)); border-color: rgba(255, 107, 87, 0.35); }
.team.t1 { background: linear-gradient(160deg, rgba(60, 200, 255, 0.16), rgba(60, 200, 255, 0.03)); border-color: rgba(60, 200, 255, 0.35); }
.team-h { display: flex; justify-content: space-between; align-items: center; font-weight: 900; letter-spacing: 1.5px; font-size: 14px; }
.t0 .team-h span { color: var(--a); } .t1 .team-h span { color: var(--b); }
.team ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.team li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.2); font-size: 14px; min-height: 38px; }
.team li.free { color: var(--muted); opacity: 0.45; justify-content: center; font-size: 12px; letter-spacing: 1px; border: 1px dashed var(--line); background: transparent; }
.team li .sw { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.team li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team li .nm i { color: var(--muted); font-style: normal; font-size: 12px; }
.tag { font-size: 10px; font-weight: 800; letter-spacing: 1px; color: var(--muted); }
.tag.host { color: var(--ball); }
.x { border: none; background: rgba(255, 255, 255, 0.08); color: var(--text); width: 24px; height: 24px; border-radius: 7px; cursor: pointer; font-size: 11px; }
.x:hover { background: rgba(255, 255, 255, 0.18); }
.add-bot { align-self: flex-start; }
@media (max-width: 700px) { .teams { grid-template-columns: 1fr; } .vs { display: none; } }

/* -------- partido -------- */
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scorebug {
  position: absolute; top: 14px; left: 14px; min-width: 300px; border-radius: 14px; overflow: hidden;
  background: rgba(8, 14, 30, 0.86); border: 1px solid var(--line); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35); backdrop-filter: blur(8px);
}
.sb-row { display: grid; grid-template-columns: 6px 1fr 18px 34px 46px; align-items: center; height: 40px; }
.sb-row + .sb-row { border-top: 1px solid var(--line); }
.sb-row.mine { background: rgba(255, 255, 255, 0.05); }
.sb-c { height: 100%; }
.sb-n { padding: 0 12px; display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.sb-n b { font-size: 14px; letter-spacing: 1.5px; }
.sb-n small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.sb-s { color: var(--ball); font-size: 12px; text-align: center; }
.sb-g { font-weight: 900; font-size: 20px; text-align: center; color: var(--muted); }
.sb-p { height: 100%; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 20px; background: var(--ball); color: #11200a; }
.sb-row + .sb-row .sb-p { border-top: 1px solid rgba(0, 0, 0, 0.15); }
.sb-foot { font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); padding: 5px 12px; border-top: 1px solid var(--line); }

.banner { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; opacity: 0; }
.banner.show { animation: pop 1.7s cubic-bezier(.2, .9, .3, 1.2) forwards; }
.banner.small { top: 14px; }
.banner.small.show { animation-duration: 1.3s; }
.banner.long.show { animation-duration: 3.5s; }
.b-title { font-size: clamp(34px, 6vw, 64px); font-weight: 900; letter-spacing: 3px; color: #fff; text-shadow: 0 0 30px var(--c), 0 6px 0 rgba(0, 0, 0, 0.3); -webkit-text-stroke: 1px var(--c); white-space: nowrap; }
.b-sub { margin-top: 4px; font-size: 18px; font-weight: 700; color: rgba(255, 255, 255, 0.85); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.b-call { font-size: 30px; font-weight: 900; letter-spacing: 3px; padding: 8px 22px; border-radius: 14px; background: rgba(8, 14, 30, 0.75); border: 1px solid var(--line); color: var(--ball); }
@keyframes pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  12% { opacity: 1; transform: translateX(-50%) scale(1.06); }
  20% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.96) translateY(-10px); }
}
.hint {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; transition: all .25s;
  background: rgba(8, 14, 30, 0.82); border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; font-size: 15px; pointer-events: none; white-space: nowrap;
}
.hint.on { opacity: 1; transform: translateX(-50%); }
.hint em { color: var(--mid); font-style: normal; font-weight: 800; }
.hud-right { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
.pill { background: rgba(8, 14, 30, 0.82); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 700; color: var(--text); }
.btnpill { cursor: pointer; min-width: 40px; }
.btnpill.muted { color: var(--bad); }
.keys { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 6px; flex-wrap: wrap; max-width: 60vw; transition: opacity 1s; }
.keys span { background: rgba(8, 14, 30, 0.7); border: 1px solid var(--line); padding: 6px 10px; border-radius: 10px; font-size: 12px; color: var(--muted); }
.keys b { color: var(--text); }
.keys.fade { opacity: 0; }
.keys.fade:hover { opacity: 1; }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5, 10, 22, 0.55); backdrop-filter: blur(4px); }
.overlay .panel { align-items: stretch; text-align: center; }
#endTitle { font-size: 40px; font-weight: 900; }
.endscore { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.es { display: grid; grid-template-columns: 8px 1fr auto; grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left; padding: 10px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.es span { grid-row: span 2; height: 100%; border-radius: 4px; }
.es b { letter-spacing: 2px; }
.es em { grid-row: span 2; font-style: normal; font-size: 34px; font-weight: 900; }
.es small { color: var(--muted); }
#escMenu .host-esc { display: none; }
#escMenu.host .host-esc { display: block; }
#escMenu.host .guest-esc { display: none; }

.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: rgba(8, 14, 30, 0.92); border: 1px solid var(--line); padding: 12px 20px; border-radius: 12px; z-index: 50; font-weight: 600; }
.conn { position: fixed; bottom: 8px; right: 12px; font-size: 11px; color: var(--muted); z-index: 40; }
.conn.ok { color: var(--ok); }
.conn.bad { color: var(--bad); }
#game.active ~ .conn { display: none; }

/* -------- configuración compacta: dos columnas, que entre sin scrollear -------- */
.panel.wide { padding: 20px 22px; gap: 10px; }
.cfg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; }
.cfg-surf { grid-column: 1 / -1; gap: 6px; }
.cfg-row { flex-direction: column; align-items: flex-start; gap: 6px; }
.cfg-row > span, .cfg-surf > span { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.cfg-row input { width: 100%; }
.surf { flex-direction: row; justify-content: flex-start; text-align: left; gap: 10px; padding: 6px 10px 6px 6px; }
.surf svg { width: 84px; flex: none; }
.surf span.t { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip { padding: 6px 11px; }
#create h2 { font-size: 20px; }
.cfg.compact { padding: 12px 14px; }
@media (max-width: 640px) {
  .cfg { grid-template-columns: 1fr; }
  .surfs { grid-template-columns: 1fr; }
}
@media (max-height: 700px) {
  .surf svg { width: 64px; }
  .team li { min-height: 32px; padding: 5px 10px; }
  .team { padding: 10px; gap: 6px; }
  #lobby h2 { font-size: 20px; }
}

/* -------- lobby en dos columnas (equipos | configuración) en pantallas anchas -------- */
.lobby-body { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 1000px) {
  .panel.wide.lobby-panel { width: min(1180px, 96vw); }
  .lobby-body { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
  .lobby-body .teams { grid-template-columns: 1fr 1fr; gap: 10px; }
  .lobby-body .vs { display: none; }
  #lobbySettings { grid-template-columns: 1fr 1fr; }
  #lobbySettings .surfs { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  #lobbySettings .surf { flex-direction: column; text-align: center; align-items: center; padding: 6px; gap: 4px; }
  #lobbySettings .surf svg { width: 100%; max-width: 92px; }
  #lobbySettings .surf small { display: none; }
}

/* -------- organizar jugadores (anfitrión) -------- */
.team li .num { width: 16px; text-align: center; font-size: 11px; font-weight: 800; color: var(--muted); flex: none; }
.team li .grip { color: var(--muted); cursor: grab; font-size: 12px; letter-spacing: -2px; flex: none; opacity: .6; }
.team li.drag { cursor: grab; }
.team li.drag:hover .grip { opacity: 1; }
.team li.dragging { opacity: .35; }
.team li.mark { box-shadow: inset 0 3px 0 var(--ball); }
.team li.free.mark { box-shadow: none; border-color: var(--ball); color: var(--ball); opacity: .9; }
.team ul.drop { outline: 2px dashed rgba(228, 255, 60, .35); outline-offset: 4px; border-radius: 10px; }
.team li .tools { display: flex; gap: 3px; margin-left: 4px; opacity: .55; transition: opacity .15s; }
.team li:hover .tools { opacity: 1; }
.x.kick:hover { background: rgba(255, 90, 90, .35); }
.x.confirm { width: auto; padding: 0 7px; background: var(--bad); color: #fff; font-weight: 800; font-size: 10px; }
.team-h { min-height: 30px; }

/* -------- grada (espectadores) -------- */
.lobby-left { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.grada { border-radius: 16px; padding: 10px 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); display: flex; flex-direction: column; gap: 6px; }
.grada .team-h span { color: var(--text); font-size: 13px; }
.grada .team-h small { font-weight: 600; letter-spacing: 0; text-transform: none; }
.grada ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; }
.grada li { display: flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 10px; background: rgba(0, 0, 0, 0.22); font-size: 13px; }
.grada li .nm { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grada li .nm i { color: var(--muted); font-style: normal; font-size: 11px; }
.grada li .sw { width: 10px; height: 10px; border-radius: 50%; }
.grada li .num { font-size: 10px; color: var(--muted); font-weight: 800; }
.grada li.free { color: var(--muted); opacity: .5; font-size: 12px; background: transparent; border: 1px dashed var(--line); }
.grada li.mark { box-shadow: inset 3px 0 0 var(--ball); }
.grada ul.drop { outline: 2px dashed rgba(228, 255, 60, .35); outline-offset: 3px; border-radius: 10px; }
.grada li .tools { display: flex; gap: 3px; opacity: .6; }
.grada li:hover .tools { opacity: 1; }
.tag.ump { color: #ffd24a; }

/* -------- chat de la grada -------- */
.chat { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  background: rgba(8, 14, 30, 0.85); border: 1px solid var(--line); border-radius: 999px; padding: 6px 6px 6px 14px; width: min(560px, 92vw); }
.chat input { flex: 1; padding: 8px 12px; border-radius: 999px; font-size: 14px; }
.chat-role { font-size: 12px; font-weight: 800; color: var(--ball); white-space: nowrap; }
#game.spectating .keys, #game.chatting .keys { display: none; }
#game.spectating .hint, #game.chatting .hint { bottom: 72px; }
#game.umpire #view { cursor: pointer; }

/* -------- Tab: la sala durante el partido -------- */
.tabmenu { align-items: center; }
.overlay .panel.tab-panel { width: min(900px, 96vw); text-align: left; max-height: 92vh; overflow: auto; }
.tab-panel .teams { grid-template-columns: 1fr auto 1fr; }

/* -------- lobby: que nada se pise en pantallas medianas -------- */
@media (min-width: 1000px) {
  .lobby-body { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
  .lobby-body .teams { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
.team { min-width: 0; }
.team li { position: relative; min-width: 0; }
.team li .nm { min-width: 0; }
/* los botones del anfitrión aparecen al pasar el mouse, encima del ping: el nombre usa todo el ancho */
.team li .tools {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  padding: 2px 2px 2px 10px; border-radius: 8px; opacity: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, #141d33 14px);
}
.team li:hover .tools, .team li:focus-within .tools { opacity: 1; pointer-events: auto; }
.team-h { gap: 8px; }
.team-h span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.grada-btns { display: flex; gap: 6px; flex: none; }
