:root {
  --bg: #0b0e13;
  --panel: #121722;
  --line: #222b3a;
  --text: #e6ebf2;
  --muted: #8b97a8;
  --accent: #4c7dff;
  --accent2: #ff4d8d;          /* segundo acento, solo para remates */
  --radius: 10px;
}

* { box-sizing: border-box; }

/**
 * El atributo hidden gana siempre.
 *
 * Su "display: none" viene de la hoja del navegador y lo pisa cualquier regla
 * propia que fije un display —basta un ".panel > div { display: flex }"— y el
 * elemento reaparece aunque el JavaScript lo haya ocultado. Con esto no vuelve
 * a pasar en ningún sitio.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  /* La página nunca hace scroll: el juego ocupa exactamente la ventana y el pie
     de teclas tiene que estar siempre visible. Lo que no quepa, que se desplace
     por dentro de su propio panel. */
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  position: relative;
  height: 100%;
  height: 100dvh;              /* en móvil, la altura real sin la barra del navegador */
  overflow: hidden;
  display: grid;
  /* minmax(0, 1fr) y no 1fr: un ítem de grid no baja de su min-content, y un
     <canvas> tiene relación de aspecto intrínseca, así que reclamaba más alto
     del que había y empujaba el pie fuera de la pantalla. */
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* ------------------------------ HUD ------------------------------ */

/* Cada uno en su fila, sin depender de la colocación automática: al ocultar el
   HUD en el menú el canvas se iba a la fila "auto" y se dimensionaba por su
   relación de aspecto en vez de llenar la pantalla. */
#app::after {
  content: '';
  position: absolute; inset: 0;
  z-index: 1;                  /* sobre el campo, por debajo de los paneles */
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .022) 0 1px, transparent 1px 3px),
    radial-gradient(125% 85% at 50% 42%, transparent 52%, rgba(0, 0, 0, .6) 100%);
}

#hud { grid-row: 1; }
#stage { grid-row: 2; }
#keys { grid-row: 3; }

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.hud-item { display: flex; flex-direction: column; gap: 2px; min-width: 110px; }
.hud-right { align-items: flex-end; }
.hud-center { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }

.hud-label {
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.hud-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hud-value.sm { font-size: 15px; }
.hud-value.xl { font-size: 28px; }

#progress {
  width: min(420px, 45vw);
  height: 3px;
  background: #1b2330;
  border-radius: 2px;
  overflow: hidden;
}
#progress-fill { height: 100%; width: 0; background: var(--accent); }

#stage { display: block; width: 100%; height: 100%; min-height: 0; touch-action: none; }

/* El marcador y el pie de teclas son cosa de la partida: en el menú solo
   mostrarían ceros y le quitan sitio al campo del modo atracción. */
body:not(.jugando) #hud,
body:not(.jugando) #keys { display: none; }

/* Aviso del ajuste fino, sobre el campo y sin robarle sitio. */
#nudge {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text);
  background: rgba(18, 23, 34, .94);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

/* ---------------------------- Ayuda de comandos ---------------------------- */

#help {
  position: absolute; inset: 0; z-index: 25;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(8, 10, 14, .9);
}

#help dl {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 7px 16px;
  margin: 0;
  max-width: 420px; width: 100%;
  max-height: 100%; overflow-y: auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  animation: panelIn .18s ease both;
}
#help .hud-label { grid-column: 1 / -1; margin: 10px 0 2px; }
#help .hud-label:first-child { margin-top: 0; }
#help dt { display: flex; gap: 4px; justify-content: flex-end; }
#help dd { margin: 0; font-size: 13px; }

kbd {
  display: inline-block;
  min-width: 22px; padding: 3px 7px;
  font: inherit; font-size: 11px; font-weight: 600; text-align: center;
  color: var(--text);
  background: #1b2330;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* Medidor de rendimiento (Alt+F). Abajo a la izquierda: arriba tapaba la
   puntuación, y esta esquina queda libre en todos los modos porque el campo va
   centrado y por debajo del receptor solo hay zona muerta. */
#perf {
  position: absolute; bottom: 8px; left: 8px; z-index: 30;
  padding: 7px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; line-height: 1.5; white-space: pre;
  color: #9fe8d0;
  background: rgba(8, 10, 14, .88);
  border: 1px solid var(--line); border-radius: 6px;
  pointer-events: none;
}

/* Permite descartar la rejilla CRT como sospechosa: ritmo.rejilla(false) */
body.sin-rejilla #app::after { display: none; }

#keys {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 14px;
  border-top: 1px solid var(--line);
}
.key.wide { width: 68px; }
.key {
  width: 34px; height: 26px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* ---------------------------- Pantallas ---------------------------- */

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  /* minmax(0, 1fr) y no una fila automática: si la fila se dimensiona por su
     contenido, el "max-height: 100%" del panel se resuelve contra el propio
     panel y no limita nada. Con esto la fila mide el alto disponible, el panel
     se recorta y la lista se desplaza por dentro. */
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  background: rgba(8, 10, 14, .82);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.menu-screen {
  /* Oscuro en el centro, donde va el panel, y translúcido arriba y abajo: así
     se ven a la vez las notas cayendo y los receptores encendiéndose. */
  background: linear-gradient(180deg,
    rgba(8, 10, 14, .50) 0%,
    rgba(8, 10, 14, .90) 32%,
    rgba(8, 10, 14, .90) 64%,
    rgba(8, 10, 14, .58) 100%);
  backdrop-filter: none;
}

/* Entrada suave de cualquier panel al abrirse su pantalla. */
.screen:not([hidden]) > .panel { animation: panelIn .22s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px) scale(.99); }
}
@media (prefers-reduced-motion: reduce) {
  .screen:not([hidden]) > .panel { animation: none; }
}

.panel {
  width: 100%;
  min-width: 0;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
}
.panel.wide { max-width: 480px; text-align: left; }

h1 { margin: 0 0 10px; font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0 0 18px; line-height: 1.55; font-size: 13.5px; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.hint { margin: 14px 0 0; font-size: 11.5px; color: var(--muted); text-align: center; }
.hint b { color: #b9c4d3; font-weight: 600; }

/* ----------------------------- Controles ----------------------------- */

.controls { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.ctrl { display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--muted); }
.ctrl b { color: var(--text); font-variant-numeric: tabular-nums; }
.ctrl.row { flex-direction: row; align-items: center; gap: 9px; cursor: pointer; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 3px; border-radius: 2px;
  background: #1f2836; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

.offset-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; margin-bottom: 18px;
  border: 1px solid var(--line); border-radius: 8px; background: #0e131c;
}
.offset-row > div { display: flex; flex-direction: column; gap: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  font: inherit; font-size: 12px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text);
  background: #1b2330;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { background: #222c3c; border-color: #2e3a4d; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 0 0 1px rgba(76, 125, 255, .3), 0 8px 24px -8px rgba(76, 125, 255, .75);
}
.btn.primary:hover:not(:disabled) {
  background: #3f6ff0; border-color: #3f6ff0;
  box-shadow: 0 0 0 1px rgba(76, 125, 255, .45), 0 10px 30px -8px rgba(76, 125, 255, .9);
}
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 14px; font-size: 13px; letter-spacing: .12em; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; white-space: nowrap; }

/* ---------------------------- Calibración ---------------------------- */

.calib-grid { display: flex; gap: 26px; margin-bottom: 14px; }
.calib-grid > div { display: flex; flex-direction: column; gap: 3px; }

#cal-meter {
  position: relative; height: 26px; margin-bottom: 12px;
  background: #0e131c; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
#cal-meter::after {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 0;
  width: 1px; background: #3b4759;
}
#cal-meter-fill {
  position: absolute; top: 4px; bottom: 4px; width: 3px;
  background: var(--accent); border-radius: 2px;
  left: 50%; transition: left .08s linear;
}

/* ---------------------------- Resultados ---------------------------- */

.result-top { display: flex; gap: 26px; margin-bottom: 18px; }
.result-top > div { display: flex; flex-direction: column; gap: 3px; }

.tally { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 13px; }
.tally td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.tally td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 9px; vertical-align: middle; }

.spinner {
  width: 22px; height: 22px; margin: 0 auto 16px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  #hud { padding: 10px 12px; }
  .hud-item { min-width: 72px; }
  .hud-value { font-size: 17px; }
  .calib-grid, .result-top { gap: 16px; }
  .panel { padding: 20px; }
}

/* ---------------------------- Biblioteca ---------------------------- */

.panel.tall {
  max-width: 720px; max-height: 100%;
  display: flex; flex-direction: column; gap: 10px; padding: 20px;
}
.panel.tall > * { flex: none; }
.panel.tall > .song-list { flex: 1 1 auto; min-height: 90px; overflow-y: auto; margin: 0; }
.panel.tall > h1, .panel.tall > p { margin: 0; }

.lib-head { display: flex; align-items: baseline; gap: 10px; }
.lib-head h1 { margin: 0; flex: none; }
.lib-head .muted { flex: 1; }
.btn.icon { padding: 5px 7px; align-self: center; }

.input {
  width: 100%; padding: 8px 11px;
  font: inherit; font-size: 13px;
  color: var(--text); background: #0e131c;
  border: 1px solid var(--line); border-radius: 8px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
select.input { cursor: pointer; }

.filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
.filter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filter .hud-label b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Dos mandos sobre el mismo carril: mínimo y máximo del rango. */
.range-pair { display: flex; align-items: center; gap: 8px; }
.range-pair input[type="range"] { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 4px 10px;
  font: inherit; font-size: 11.5px; font-weight: 550;
  color: var(--muted); background: transparent;
  border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.chip:hover { color: var(--text); border-color: #2e3a4d; }
.chip.on { color: #fff; background: var(--accent); border-color: var(--accent); }

.filter-bottom { display: flex; gap: 8px; align-items: center; }
.filter-bottom .input { flex: 1; min-width: 0; }
.filter-bottom .btn { flex: none; }

.empty { text-align: center; padding: 20px 0; }

.selected {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; margin-bottom: 18px;
  border: 1px solid var(--line); border-radius: 8px; background: #0e131c;
}
.selected > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.selected .hud-value, .selected .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.err { color: #e08b90; margin: 0 0 12px; line-height: 1.5; }

.song-list {
  display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px;
  padding-right: 4px;
  /* Barra de desplazamiento siempre visible: en macOS las superpuestas se
     esconden y no se ve que la lista tiene más contenido. */
  scrollbar-width: thin;
  scrollbar-color: #33425a transparent;
}
.song-list::-webkit-scrollbar { width: 10px; }
.song-list::-webkit-scrollbar-track { background: #0b0e13; border-radius: 6px; }
.song-list::-webkit-scrollbar-thumb {
  background: #33425a; border-radius: 6px;
  border: 2px solid #0b0e13; background-clip: content-box;
}
.song-list::-webkit-scrollbar-thumb:hover { background: #445876; background-clip: content-box; }
.song-list:empty { display: none; }

.song-row {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #0e131c;
}
.song-row.current { border-color: var(--accent); background: #101a2c; }
.song-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.song-meta b { font-size: 13px; font-weight: 600; }
.song-meta span { font-size: 11px; color: var(--muted); }
.song-meta b, .song-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.diffs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-start; }
.diff-group { display: flex; align-items: center; gap: 4px; }

/* Chapa de modo, solo visible con el filtro en "Todos". */
.lane-badge {
  display: flex; flex-direction: column; align-items: center;
  gap: 0; padding: 3px 7px; min-width: 46px; line-height: 1.2;
  color: var(--accent);
  background: rgba(76, 125, 255, .12);
  border: 1px solid rgba(76, 125, 255, .3);
  border-radius: 6px;
}
.lane-badge span {
  font-size: 8.5px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase;
  opacity: .75;
}
.lane-badge b { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.btn.diff {
  flex-direction: column; gap: 0; padding: 3px 7px; min-width: 46px; line-height: 1.2;
  border-radius: 6px;
}
.btn.diff span { font-size: 8.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.btn.diff b { font-size: 13px; font-weight: 650; }

@media (max-width: 560px) {
  .filter-grid { grid-template-columns: 1fr; }
  .filter-bottom { flex-wrap: wrap; }
  .panel.tall { padding: 16px; }
}

/* ------------------------------ Menú ------------------------------ */

.panel.menu { display: flex; flex-direction: column; gap: 14px; }

.brand { display: flex; align-items: center; gap: 13px; }
.brand > div { min-width: 0; }
.brand h1 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.brand p { margin: 2px 0 0; }

/* Un <svg> sin medidas explícitas se estira hasta llenar el contenedor flex. */
.mark { flex: none; width: 40px; height: 28px; color: var(--accent); }
.mark rect { fill: currentColor; transform-box: fill-box; transform-origin: center; }
/* Late al ritmo, pero despacio: es un adorno, no un metrónomo. */
.mark rect:nth-child(1) { animation: barra 1.6s ease-in-out -0.0s infinite; }
.mark rect:nth-child(2) { animation: barra 1.6s ease-in-out -0.4s infinite; }
.mark rect:nth-child(3) { animation: barra 1.6s ease-in-out -0.8s infinite; }
.mark rect:nth-child(4) { animation: barra 1.6s ease-in-out -1.2s infinite; }
@keyframes barra {
  0%, 100% { transform: scaleY(.72); opacity: .55; }
  50%      { transform: scaleY(1);   opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .mark rect { animation: none; } }

.btn.big { position: relative; }
.btn.big kbd {
  position: absolute; right: 12px;
  padding: 2px 6px;
  font: inherit; font-size: 10px; letter-spacing: .04em;
  color: rgba(255, 255, 255, .72);
  background: rgba(255, 255, 255, .14);
  border-radius: 4px;
}
@media (max-width: 420px) { .btn.big kbd { display: none; } }

.menu-row { display: flex; gap: 8px; }
.menu-row .btn { flex: 1; }
.menu-row .btn b { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
#btn-settings[aria-expanded="true"] { background: #1b2330; color: var(--text); }

.settings {
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px; margin: 0;
  background: #0e131c;
  border: 1px solid var(--line); border-radius: 10px;
  animation: panelIn .18s ease both;
}

#menu-stats { margin: 0; }

/* ------------------------------ Marca ------------------------------ */

.panel.menu { position: relative; overflow: hidden; }
/* Remate superior, como el frontal de una recreativa. */
.panel.menu::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

.logo {
  margin: 0;
  font-size: 29px; font-weight: 800; line-height: 1;
  text-transform: uppercase; letter-spacing: .15em;
  color: var(--accent);
  text-shadow: 0 0 22px rgba(76, 125, 255, .5);
}
.logo span { color: var(--text); text-shadow: none; }

.tagline {
  margin: 6px 0 0;
  font-size: 9.5px; letter-spacing: .17em; text-transform: uppercase;
  color: var(--muted);
}

.mark rect:nth-child(2), .mark rect:nth-child(4) { fill: var(--accent2); }

/* La tarjeta de canción y el marcador conservan su caja mayúscula propia. */
.song-card .hud-value, .song-card .muted, .song-meta b, .song-meta span,
.hud-value, .input, .chip { text-transform: none; letter-spacing: normal; }

/* ------------------------------ En línea ------------------------------ */

/**
 * Panel en columna con separación propia.
 *
 * Antes cada bloque se apoyaba en su propio margen y los que no tenían —las
 * filas de botones— acababan pegados al de al lado. Con el hueco puesto en el
 * contenedor, todo queda separado igual sin depender de qué haya dentro.
 */
.panel.col { display: flex; flex-direction: column; gap: 16px; }
.panel.col > h1, .panel.col > p { margin: 0; }
.panel.col > div { display: flex; flex-direction: column; gap: 12px; }
.panel.col .campos.fila { flex-direction: row; }
.panel.col .offset-row { flex-direction: row; margin: 0; }


.campos { display: flex; flex-direction: column; gap: 10px; }
.campos.fila { flex-direction: row; }
.campos.fila .input { flex: 1; min-width: 0; }
.campos.fila .btn { flex: none; }

.codigo {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .22em; color: var(--accent);
}

#sala-jugadores { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.jugador {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px;
  background: #0e131c; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px;
}
.jugador.yo { border-color: #33425a; }
.jugador span { font-size: 11.5px; }
.jugador .ok { color: #5fd3b2; }

/* ------------------------ Marcador del duelo ------------------------ */

#marcador {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  z-index: 4;
  display: flex; flex-direction: column; gap: 5px;
  width: 190px;
  pointer-events: none;
}

.puesto {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px;
  background: rgba(18, 23, 34, .9);
  border: 1px solid var(--line); border-left-width: 3px;
  border-radius: 7px;
}
.puesto.yo { border-left-color: var(--accent); background: rgba(20, 28, 46, .94); }
.puesto.acabado { opacity: .62; }

.puesto-n {
  flex: none; width: 22px;
  font-size: 11px; font-weight: 700; text-align: right;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.puesto:first-child .puesto-n { color: var(--accent2); }

.puesto-datos { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.puesto-datos b {
  font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.puesto-datos span {
  font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums;
  color: var(--text);
}
.puesto.yo .puesto-datos span { color: var(--accent); }

/* En ventanas estrechas el campo llega hasta el borde: el marcador se encoge
   para seguir siendo legible sin comerse los carriles. */
@media (max-width: 900px) {
  #marcador { width: 132px; right: 6px; gap: 4px; }
  .puesto { padding: 5px 7px; gap: 6px; }
  .puesto-datos b { font-size: 10.5px; }
  .puesto-datos span { font-size: 12px; }
}

/* ------------------------------ Vestíbulo ------------------------------ */

/* Con sesión abierta el panel crece para caber las dos columnas; sin ella se
   queda estrecho, que un formulario de acceso ancho queda ridículo. */
.lobby-panel { max-width: 480px; transition: max-width .18s ease; }
.lobby-panel:has(#on-sesion:not([hidden])) { max-width: 740px; }

.lobby { display: grid; grid-template-columns: minmax(0, 1fr) 216px; gap: 16px; }
.lobby-salas { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.lobby-cab { display: flex; align-items: center; gap: 8px; }
.lobby-cab .muted { flex: 1; }

#lobby-lista {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 260px; min-height: 96px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #33425a transparent;
}
#lobby-lista:empty { display: none; }

.sala-fila {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  font: inherit; text-align: left; color: var(--text);
  background: #0e131c; border: 1px solid var(--line); border-radius: 7px;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.sala-fila:hover:not(:disabled) { border-color: #33425a; background: #101724; }
.sala-fila:disabled { cursor: not-allowed; opacity: .5; }

.sala-codigo {
  flex: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; letter-spacing: .12em; color: var(--accent);
}
.sala-datos { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.sala-datos b { font-size: 12.5px; font-weight: 600; }
.sala-datos span,
.sala-datos b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sala-datos span { font-size: 11px; color: var(--muted); }

.sala-estado {
  flex: none; padding: 2px 7px;
  font-size: 9px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  border-radius: 4px;
}
.sala-estado.espera { color: #5fd3b2; background: rgba(95, 211, 178, .12); }
.sala-estado.jugando { color: var(--accent2); background: rgba(255, 77, 141, .12); }
.sala-plazas { flex: none; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.lobby-perfil {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px;
  background: #0e131c; border: 1px solid var(--line); border-radius: 10px;
}
.perfil-nick { font-size: 16px; font-weight: 650; }

/* Cifra grande arriba y etiqueta pequeña debajo: se leen de un vistazo, que es
   lo que se hace con un panel de estadísticas. Antes era una lista con los
   números alineados a la derecha y había que ir emparejando con la vista. */
.perfil-datos { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 2px 0 4px; }
.perfil-datos > div {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px 9px;
  background: #0b0e13; border: 1px solid var(--line); border-radius: 7px;
}
.perfil-datos b {
  font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.perfil-datos span {
  font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}

.perfil-ultimas { display: flex; flex-direction: column; gap: 4px; }
.perfil-ultimas div {
  font-size: 10.5px; color: var(--muted);
  padding: 6px 8px; background: #0b0e13;
  border: 1px solid var(--line); border-radius: 6px;
}
.perfil-ultimas b { display: block; color: var(--text); font-weight: 600; font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perfil-ultimas .nada { color: var(--muted); }

.vacio { text-align: center; padding: 18px 0; }

@media (max-width: 680px) {
  .lobby { grid-template-columns: minmax(0, 1fr); }
  .lobby-perfil { order: -1; }
}

/* --------------------------- Sala y chat --------------------------- */

/* Con la misma especificidad que las reglas que las pisaban: ".panel.wide" y
   ".panel.col > div" ganaban por llevar dos clases. */
.panel.wide.sala-panel { max-width: 700px; }
.panel.col > .sala-cuerpo {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 14px;
}

.crear-sala {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px;
  background: #0e131c; border: 1px solid var(--line); border-radius: 8px;
}
.crear-sala .chips { flex: 1; }
#on-plazas .chip { min-width: 34px; padding: 4px 0; text-align: center; }

.jugador .acciones { display: flex; gap: 6px; align-items: center; }
.btn.echar {
  padding: 3px 8px; font-size: 9.5px;
  color: #e08b90; background: transparent; border-color: rgba(224, 139, 144, .3);
}
.btn.echar:hover:not(:disabled) { background: rgba(224, 139, 144, .12); border-color: #e08b90; }

.chat { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chat-mensajes {
  flex: 1; min-height: 150px; max-height: 220px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px;
  background: #0b0e13; border: 1px solid var(--line); border-radius: 8px;
  font-size: 12px; line-height: 1.45;
  scrollbar-width: thin; scrollbar-color: #33425a transparent;
}
.chat-mensajes p { margin: 0; word-break: break-word; }
.chat-mensajes b { color: var(--accent); font-weight: 600; }
.chat-mensajes .yo b { color: var(--accent2); }
.chat-mensajes .sistema { color: var(--muted); font-style: italic; }
.chat-vacio { color: var(--muted); }

@media (max-width: 640px) {
  .panel.col > .sala-cuerpo { grid-template-columns: minmax(0, 1fr); }
  .chat-mensajes { min-height: 110px; max-height: 160px; }
}

/* ------------------------------ Niveles ------------------------------ */

.perfil-cabeza { display: flex; align-items: center; gap: 11px; }
.perfil-ident { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.perfil-ident > .muted { font-size: 10.5px; }
.jug-nivel.grande { width: 42px; height: 42px; }
.jug-nivel.grande b { font-size: 17px; }

.nivel-chapa {
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 9px; line-height: 1.15;
  color: var(--accent2);
  background: rgba(255, 77, 141, .12);
  border: 1px solid rgba(255, 77, 141, .32);
  border-radius: 6px;
}
.nivel-chapa span { font-size: 8px; letter-spacing: .07em; text-transform: uppercase; opacity: .8; }
.nivel-chapa b { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }

.barra-nivel {
  height: 5px; margin: 2px 0 1px;
  background: #1b2330; border-radius: 3px; overflow: hidden;
}
.barra-nivel > div {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width .5s cubic-bezier(.2, .8, .3, 1);
}

#r-xp {
  display: flex; flex-direction: column; gap: 5px;
  padding: 12px 14px; margin-bottom: 14px;
  background: #0e131c; border: 1px solid var(--line); border-radius: 8px;
}
#r-xp.sube { border-color: var(--accent2); box-shadow: 0 0 22px -8px var(--accent2); }
.xp-cabeza { display: flex; align-items: baseline; justify-content: space-between; }
.xp-cabeza b { font-size: 16px; font-weight: 700; color: var(--accent); }
.xp-cabeza span { font-size: 12px; font-weight: 650; color: var(--accent2); }

/* --------------------- Vista previa de canciones --------------------- */

/* La ficha es un botón: al pulsarla suena un fragmento. */
button.song-meta {
  flex-direction: row; align-items: center; gap: 9px;
  padding: 0; border: 0; background: none; text-align: left;
  font: inherit; color: inherit; text-transform: none; letter-spacing: normal;
  cursor: pointer;
}
.song-meta-texto { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.song-meta-texto > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.muestra-icono {
  flex: none; display: flex; align-items: flex-end; gap: 2px;
  width: 14px; height: 13px;
  opacity: .32; transition: opacity .14s ease;
}
.muestra-icono i { flex: 1; background: var(--muted); border-radius: 1px; height: 45%; }
button.song-meta:hover .muestra-icono { opacity: .7; }

/* Sonando: las barras bailan y el icono toma el color de acento. */
.song-row.sonando .muestra-icono { opacity: 1; }
.song-row.sonando .muestra-icono i { background: var(--accent); }
.song-row.sonando .muestra-icono i:nth-child(1) { animation: eq .7s ease-in-out -.0s infinite; }
.song-row.sonando .muestra-icono i:nth-child(2) { animation: eq .7s ease-in-out -.25s infinite; }
.song-row.sonando .muestra-icono i:nth-child(3) { animation: eq .7s ease-in-out -.5s infinite; }
@keyframes eq { 0%, 100% { height: 25%; } 50% { height: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .song-row.sonando .muestra-icono i { animation: none; height: 70%; }
}

/* ============================== Menú ============================== */

.panel.menu { max-width: 520px; gap: 16px; padding: 22px; }

/* Cabecera: marca a la izquierda, jugador a la derecha. */
.brand { display: flex; align-items: center; gap: 13px; }
.brand-texto { flex: 1; min-width: 0; }

/* Ficha del jugador: disco de nivel + nick con su barra. Antes eran tres
   líneas apiladas en una esquina estrecha y se leía como un amontonamiento. */
.jugador {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 11px 6px 7px;
  background: #0e131c; border: 1px solid var(--line); border-radius: 999px;
}
.jug-nivel {
  flex: none; display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.jug-nivel b { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.jug-txt { display: flex; flex-direction: column; gap: 4px; min-width: 76px; }
.jug-txt > b {
  font-size: 12.5px; font-weight: 650; line-height: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 108px;
}
.jugador .barra-nivel { height: 3px; margin: 0; }

/* Canción seleccionada: el bloque con más peso después de Jugar. */
.hero {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 15px;
  font: inherit; text-align: left; color: var(--text);
  background: linear-gradient(135deg, #10161f 0%, #0d1219 100%);
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .14s ease, transform .14s ease;
}
/* Filo de acento: da la sensación de panel de recreativa sin recargar. */
.hero::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
}
.hero:hover { border-color: #33425a; }
.hero:active { transform: scale(.995); }

.hero-txt { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.hero-txt > b { font-size: 15px; font-weight: 650; }
.hero-txt > b, .hero-txt > .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hero .chev { flex: none; color: var(--muted); transition: transform .14s ease, color .14s ease; }
.hero:hover .chev { transform: translateX(3px); color: var(--text); }

.hero-chips { display: flex; gap: 5px; flex: none; }
.hero-chips span {
  padding: 3px 8px;
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  color: var(--accent); background: rgba(76, 125, 255, .12);
  border: 1px solid rgba(76, 125, 255, .28); border-radius: 5px;
  font-variant-numeric: tabular-nums;
}

/* Accesos secundarios como fichas, no como una fila de botones de texto. */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 13px 6px 11px;
  font: inherit; font-size: 10.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted);
  background: #0e131c; border: 1px solid var(--line); border-radius: 9px;
  cursor: pointer;
  transition: color .14s ease, border-color .14s ease, background .14s ease;
}
.tile svg { color: var(--muted); transition: color .14s ease; }
.tile:hover { color: var(--text); border-color: #33425a; background: #101724; }
.tile:hover svg { color: var(--accent); }
.tile[aria-expanded="true"] { color: var(--text); border-color: var(--accent); }
.tile[aria-expanded="true"] svg { color: var(--accent); }
.tile-dato {
  font-size: 9.5px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums; letter-spacing: normal;
}

@media (max-width: 460px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .jugador { display: none; }
  .hero-chips { display: none; }
}

/* La pantalla de calibrar se toca entera, así que no debe interpretarse como
   texto seleccionable ni provocar el zoom por doble toque en el móvil. */
#screen-calib { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#screen-calib .panel { cursor: pointer; }
#screen-calib button, #screen-calib input { cursor: auto; }
