:root {
  --bg: #0b0f1a;
  --card: rgba(18, 24, 40, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef2ff;
  --muted: #9aa4c0;
  --accent: #3ddc97;
  --accent2: #ffcc33;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: 'Baloo 2', system-ui, sans-serif; -webkit-user-select: none; user-select: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: crosshair; }
.hidden { display: none !important; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(5, 8, 15, 0.55); backdrop-filter: blur(3px); z-index: 10; }
.card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); text-align: center; }
h1 { margin: 0; font-size: 52px; line-height: 1; font-weight: 800;
  background: linear-gradient(90deg, #3ddc97, #4cc9f0 50%, #f15bb5); -webkit-background-clip: text;
  background-clip: text; color: transparent; }
h1 span { font-size: 26px; }
h2 { margin: 0 0 8px; font-size: 34px; }
.sub { margin: 4px 0 18px; color: var(--muted); }
.label { text-align: left; margin: 14px 0 6px; color: var(--muted); font-size: 14px; }
.label small { opacity: .7; }
input { width: 100%; padding: 12px 14px; font: inherit; font-size: 18px; color: var(--text);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 12px; outline: none; }
input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; }
button { font: inherit; cursor: pointer; border-radius: 12px; border: 0; }
.primary { width: 100%; margin-top: 18px; padding: 12px; font-size: 24px; font-weight: 800; color: #062015;
  background: linear-gradient(180deg, #5ff0ae, #2fbf7f); box-shadow: 0 6px 0 #1f8a5b; }
.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #1f8a5b; }
.ghost { padding: 10px 14px; color: var(--text); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); }
.ghost.wide { width: 100%; margin-top: 10px; }
/* Colores: una sola fila con scroll horizontal, tamaño fijo (no hace crecer el menú) */
#skins { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 2px 2px 8px; scroll-snap-type: x proximity;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
#skins canvas { flex: 0 0 52px; width: 52px; height: 52px; border-radius: 50%; cursor: pointer; border: 3px solid transparent;
  scroll-snap-align: center; }
#skins::-webkit-scrollbar { height: 6px; }
#skins::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 3px; }

/* Top del menú: alto fijo, scroll interno */
#top, #skins { min-width: 0; max-width: 100%; }
#top { margin-top: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; text-align: left; }
.topTabs { display: flex; gap: 6px; margin-bottom: 6px; }
.topTabs button { flex: 1; padding: 6px 4px; font-size: 14px; font-weight: 700; color: var(--muted); background: transparent;
  border: 1px solid transparent; border-radius: 10px; white-space: nowrap; }
.topTabs button small { font-weight: 500; opacity: .75; }
.topTabs button.sel { color: var(--text); background: rgba(255, 255, 255, 0.08); border-color: var(--line); }
#topList { list-style: none; margin: 0; padding: 0 2px 0 0; height: 158px; overflow-y: auto; font-size: 15px;
  scrollbar-width: thin; overscroll-behavior: contain; counter-reset: pos; }
#topList li { display: flex; align-items: center; gap: 8px; padding: 4px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  counter-increment: pos; line-height: 1.2; }
#topList li::before { content: counter(pos); flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; background: rgba(255, 255, 255, 0.08); color: var(--muted); }
#topList li:nth-child(1)::before { background: #ffd166; color: #3a2a00; }
#topList li:nth-child(2)::before { background: #d6dce8; color: #262b36; }
#topList li:nth-child(3)::before { background: #e0975a; color: #3a1d00; }
#topList .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topList .v { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
#topList li.me .n { color: var(--accent); font-weight: 700; }
#topList li.vacio { justify-content: center; color: var(--muted); border: 0; font-size: 14px; text-align: center; height: 100%; }
#topList li.vacio::before { display: none; }
#skins canvas.sel { border-color: #fff; }
#msg { min-height: 1.2em; margin: 10px 0 0; color: var(--accent2); }
.help { margin: 8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
#deathInfo { color: var(--muted); font-size: 18px; margin: 0 0 6px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#stats { position: absolute; left: 16px; bottom: 16px; font-size: 18px; text-shadow: 0 2px 4px #000; line-height: 1.25; }
#stats b { color: var(--accent); font-size: 24px; }
#rank, #kills { color: var(--muted); }
#board { position: absolute; right: 16px; top: 12px; width: 190px; background: rgba(0, 0, 0, 0.35);
  border-radius: 12px; padding: 8px 12px; font-size: 14px; }
#board h3 { margin: 0 0 2px; font-size: 16px; color: var(--accent2); }
#lb { margin: 0; padding-left: 22px; }
#lb li { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }
#lb li span:first-child { overflow: hidden; text-overflow: ellipsis; }
#lb li.me { color: var(--accent); font-weight: 700; }
#minimap { position: absolute; right: 16px; bottom: 16px; width: 150px; height: 150px; }
#feed { position: absolute; left: 16px; top: 12px; font-size: 15px; max-width: 60vw; }
#feed div { background: rgba(0, 0, 0, 0.35); padding: 2px 10px; border-radius: 8px; margin-bottom: 4px;
  transition: opacity .5s; }
#feed b { color: var(--accent2); }
#toast { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); font-size: 30px; font-weight: 800;
  color: var(--accent2); text-shadow: 0 3px 8px #000; opacity: 0; transition: opacity .3s; white-space: nowrap; }
#toast.show { opacity: 1; }
#boost { position: absolute; left: 18px; bottom: 110px; width: 84px; height: 84px; border-radius: 50%;
  font-size: 38px; pointer-events: auto; background: rgba(255, 204, 51, 0.25); border: 2px solid rgba(255, 204, 51, 0.7);
  color: #fff; touch-action: none; }
#boost.on { background: rgba(255, 204, 51, 0.6); }

@media (max-width: 600px) {
  #board { width: 150px; font-size: 12px; padding: 6px 8px; }
  #board h3 { font-size: 13px; }
  #minimap { width: 100px; height: 100px; }
  #stats { font-size: 15px; }
  #feed { font-size: 12px; top: auto; bottom: 210px; }
  h1 { font-size: 42px; }
}

/* ---------- Cuenta, modos y dinero ---------- */
.money { color: #ffd166 !important; }
@keyframes flash { 0% { text-shadow: 0 0 0 transparent; transform: scale(1); } 30% { text-shadow: 0 0 14px #ffd166; transform: scale(1.18); } 100% { text-shadow: 0 0 0 transparent; transform: scale(1); } }
#balance { display: inline-block; }
#balance.flash { animation: flash .9s ease; }
.row { margin-top: 8px; }
.row .grow { flex: 1; }
.small { padding: 6px 10px; font-size: 14px; }
.botlink { display: inline-flex; align-items: center; border-radius: 12px; font-weight: 700; text-decoration: none; }
.botlink.recarga { background: #2ecc71; color: #062b14; }
.botlink.retiro { background: #ff9f43; color: #3a1d00; }
.botlink:hover { filter: brightness(1.1); }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
#account { margin-bottom: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.03); }
#account input { font-size: 16px; padding: 10px 12px; }
.acct { display: flex; justify-content: space-between; gap: 8px; font-size: 17px; }
#hist { list-style: none; margin: 8px 0 0; padding: 0; max-height: 160px; overflow: auto; text-align: left; font-size: 13px; }
#hist li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--line); }
#hist li small { color: var(--muted); display: block; }
#hist .pos { color: var(--accent); white-space: nowrap; }
#hist .neg { color: #ff6b81; white-space: nowrap; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; padding: 8px; color: var(--muted); background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.tab.sel { color: #062015; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.rules { text-align: left; margin: 0; padding-left: 18px; font-size: 14px; color: var(--muted); line-height: 1.35; }
.rules b { color: var(--text); }
#stakes { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
#stakes button { padding: 8px 6px; font-size: 18px; font-weight: 700; line-height: 1.15; color: var(--text);
  background: rgba(255,209,102,.08); border: 1px solid rgba(255,209,102,.35); }
#stakes button small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
#stakes button.live small { color: var(--accent); }
#stakes button.sel { background: #ffd166; color: #2b1d00; }
#stakes button.sel small { color: #5a4300; }
#customStake { font-size: 16px; padding: 10px 12px; }
#tinfo { text-align: left; font-size: 15px; }
#tinfo h4 { margin: 0 0 4px; font-size: 20px; color: var(--accent2); }
#tinfo ol { margin: 4px 0; padding-left: 22px; }
.muted { color: var(--muted); }
.card { max-height: calc(100vh - 32px); overflow-y: auto; }

#tboard { position: absolute; right: 16px; top: 250px; width: 190px; background: rgba(0,0,0,.35);
  border-radius: 12px; padding: 8px 12px; font-size: 14px; }
#tboard h3 { margin: 0 0 2px; font-size: 16px; color: #ffd166; display: flex; justify-content: space-between; }
#tlb { margin: 0; padding-left: 22px; }
#tlb li { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }
#cash { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); pointer-events: auto;
  padding: 12px 22px; font-size: 20px; font-weight: 800; color: #2b1d00; background: #ffd166; box-shadow: 0 5px 0 #b8912f; }
#cash:disabled { opacity: .85; }
@media (max-width: 600px) {
  #tboard { width: 150px; font-size: 12px; top: 215px; }
  #cash { bottom: 130px; font-size: 17px; }
}

/* PC: menú ancho en dos columnas para que quepa todo sin scroll */
@media (min-width: 900px) and (min-height: 560px) {
  .menu-card { max-width: 900px; display: grid; grid-template-columns: 1.15fr 1fr; gap: 28px; text-align: left;
    padding: 26px 30px; }
  .menu-card h1, .menu-card .sub { text-align: center; }
  .menu-card > .col { min-width: 0; }
  .col-b > #top { margin-top: 0; }
  .col-b { display: flex; flex-direction: column; justify-content: center; }
  .col-b > .label:first-child { margin-top: 0; }
  #topList { height: 232px; }
  #hist { max-height: 120px; }
  .menu-card .help { text-align: center; }
  #msg { text-align: center; }
}

/* ---------- Móvil: joystick, juego en horizontal ---------- */
/* Giro de 90° cuando el teléfono sigue en vertical (bloqueo de rotación / iPhone): el jugador voltea el teléfono */
body.rot #stage { position: fixed; top: 0; left: 0; transform-origin: top left; transform: rotate(90deg) translateY(-100%); overflow: hidden; }
body.rot #stage canvas#game, body.rot #stage #hud, body.rot #stage .overlay { position: absolute; }
body.rot #stage canvas#game { inset: auto; top: 0; left: 0; }

#joy { position: absolute; left: 95px; bottom: 25px; top: auto; width: 130px; height: 130px; margin: 0 0 0 -65px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.25);
  pointer-events: none; opacity: .55; transition: opacity .15s; }
#joy.on { opacity: 1; bottom: auto; margin: -65px 0 0 -65px; transition: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.35); border: 2px solid rgba(255, 255, 255, 0.7); box-shadow: 0 4px 12px rgba(0, 0, 0, .4); }

body.touch #stats { left: 14px; top: 8px; bottom: auto; font-size: 13px; line-height: 1.15; }
body.touch #stats b { font-size: 17px; }
body.touch #feed { left: 50%; top: 8px; bottom: auto; transform: translateX(-50%); font-size: 12px; max-width: 42%; text-align: center; }
body.touch #board { right: 10px; top: 8px; width: 140px; font-size: 11px; padding: 5px 8px; }
body.touch #board h3, body.touch #tboard h3 { font-size: 12px; }
body.touch #tboard { left: 14px; right: auto; top: 88px; width: 150px; font-size: 11px; padding: 5px 8px; }
body.touch #minimap { right: 12px; bottom: 12px; width: 90px; height: 90px; }
body.touch #boost { left: auto; right: 118px; bottom: 22px; width: 80px; height: 80px; font-size: 34px; }
body.touch #cash { bottom: 16px; font-size: 16px; padding: 10px 18px; }
body.touch #toast { font-size: 24px; top: 22%; }
body.touch #death .card { max-height: 100%; overflow-y: auto; padding: 18px; }

/* ---------- Crear cuenta (botón con color) y ventanas modales ---------- */
.cta { padding: 10px 14px; font-weight: 800; color: #3a1030;
  background: linear-gradient(180deg, #ff8fd1, #f15bb5); box-shadow: 0 4px 0 #b43a86; }
.cta:hover { filter: brightness(1.07); }
.cta:active { transform: translateY(2px); box-shadow: 0 2px 0 #b43a86; }
.cta-primary { color: #3a1030; background: linear-gradient(180deg, #ff8fd1, #f15bb5); box-shadow: 0 6px 0 #b43a86; }
.cta-primary:active { box-shadow: 0 3px 0 #b43a86; }
.linkbtn { padding: 0; background: none; color: var(--accent); font-size: inherit; text-decoration: underline; }
.tgbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; padding: 10px 14px;
  border-radius: 12px; font-weight: 800; text-decoration: none; color: #fff; background: #229ed9; box-shadow: 0 4px 0 #17739f; }
.tgbtn:hover { filter: brightness(1.08); }
.tgbtn.wide { width: 100%; margin-top: 12px; font-size: 18px; }
.tgbtn.small { width: 100%; margin-top: 8px; padding: 7px 10px; font-size: 14px; box-shadow: 0 3px 0 #17739f; }
.tgbtn small { font-weight: 500; opacity: .85; }

.modal { z-index: 30; background: rgba(5, 8, 15, 0.78); backdrop-filter: blur(5px); }
.modal .card { position: relative; max-width: 380px; max-height: calc(100dvh - 32px); overflow-y: auto; animation: pop .18s ease-out; }
.modal input { margin-top: 10px; }
.modal h2 { font-size: 30px; line-height: 1.15; padding: 0 20px; }
.modal .sub { margin-bottom: 8px; }
.close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; font-size: 26px; line-height: 1;
  color: var(--muted); background: transparent; }
.close:hover { color: var(--text); }
.err { min-height: 1.2em; margin: 10px 0 0; color: #ff8a8a; font-size: 15px; }
.big { font-size: 52px; line-height: 1; }
.tgbox { margin-top: 14px; padding: 14px; text-align: left; border-radius: 14px;
  background: rgba(34, 158, 217, 0.12); border: 1px solid rgba(34, 158, 217, 0.45); }
.tgbox p { margin: 6px 0 0; font-size: 15px; color: var(--text); line-height: 1.35; }
.steps { margin: 10px 0 0; padding-left: 22px; text-align: left; line-height: 1.4; }
.steps li { margin: 6px 0; }
.steps code { padding: 1px 5px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* Salas libres activas (modo libre) */
#freeRooms { display: flex; flex-direction: column; gap: 6px; }
#freeRooms .hint { margin: 0; text-align: left; }
#freeRooms .room { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px;
  color: var(--text); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); text-align: left; }
#freeRooms .room .rname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#freeRooms .room small { flex: none; color: var(--accent); font-weight: 700; }
#freeRooms .room small::before { content: '● '; }
#freeRooms .room.sel { border-color: var(--accent); background: rgba(61, 220, 151, 0.12); }
