:root {
  --fondo: #0e1116;
  --fondo2: #131820;
  --panel: #171d26;
  --borde: #26303d;
  --texto: #e7ecf3;
  --suave: #93a1b5;
  --acento: #e0b354;
  --acento2: #7aa2f7;
  --ok: #4ade80;
  --mal: #f87171;
  --clara: #eadbc0;
  --oscura: #7d6752;
  --radio: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2432 0%, var(--fondo) 55%) no-repeat, var(--fondo);
  color: var(--texto);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ cabecera */
.cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 4vw, 32px);
  border-bottom: 1px solid var(--borde);
  background: rgba(14, 17, 22, .72);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.marca {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--texto);
  text-decoration: none;
  font-weight: 650;
  letter-spacing: .2px;
  font-size: 1.05rem;
}
.marca span { color: var(--acento); }

.sala-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--borde);
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 14px;
}
.sala-chip .etiqueta { color: var(--suave); font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; }
.sala-chip strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; color: var(--acento); }

/* -------------------------------------------------------------------- lobby */
.lobby {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(28px, 7vh, 72px) 22px 60px;
  text-align: center;
}
.lobby h1 { font-size: clamp(1.6rem, 4.4vw, 2.6rem); line-height: 1.15; margin: 0 0 14px; letter-spacing: -.02em; }
.lobby .sub { color: var(--suave); margin: 0 auto 32px; max-width: 46ch; line-height: 1.6; }
.acciones-lobby { margin-bottom: 34px; }

.boton {
  border: 1px solid var(--borde);
  background: var(--panel);
  color: var(--texto);
  border-radius: 11px;
  padding: 11px 18px;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease, opacity .15s;
  font-weight: 560;
}
.boton:hover { background: #1e2632; border-color: #38455a; }
.boton:active { transform: translateY(1px); }
.boton:disabled { opacity: .45; cursor: not-allowed; }
.boton.primario {
  background: linear-gradient(180deg, #f0c76a, #d9a63f);
  color: #241a05;
  border-color: #f3d085;
  font-weight: 700;
}
.boton.primario:hover { background: linear-gradient(180deg, #f7d386, #e2b04a); }
.boton.grande { padding: 15px 34px; font-size: 1.05rem; border-radius: 13px; }
.boton.chico { padding: 8px 12px; font-size: .86rem; border-radius: 9px; }
.boton.peligro { color: #ffd7d7; border-color: #4a2a2f; }
.boton.peligro:hover { background: #2a1b1e; border-color: #6b343c; }

.unirse { margin-top: 8px; }
.unirse label { display: block; color: var(--suave); font-size: .9rem; margin-bottom: 10px; }
.fila { display: flex; gap: 8px; justify-content: center; }

input {
  background: #0b0f14;
  border: 1px solid var(--borde);
  border-radius: 11px;
  padding: 11px 14px;
  color: var(--texto);
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
input:focus { border-color: #46587a; }

#codigoEntrada { text-transform: uppercase; letter-spacing: .22em; text-align: center; width: 150px; font-family: ui-monospace, monospace; }

.aviso { color: var(--acento); font-size: .86rem; min-height: 1.2em; margin: 12px 0 0; }
.aviso.pequeno { font-size: .78rem; margin: 6px 0 0; }

.reglas {
  list-style: none;
  padding: 0;
  margin: 44px auto 0;
  text-align: left;
  color: var(--suave);
  font-size: .9rem;
  line-height: 1.65;
  max-width: 56ch;
  border-top: 1px solid var(--borde);
  padding-top: 22px;
}
.reglas li { margin-bottom: 8px; padding-left: 18px; position: relative; }
.reglas li::before { content: "·"; position: absolute; left: 4px; color: var(--acento); }

/* -------------------------------------------------------------------- juego */
.juego {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: clamp(16px, 2.4vw, 32px);
  padding: clamp(14px, 2.4vw, 30px);
  max-width: 1180px;
  margin: 0 auto;
  align-items: start;
}

.zona-tablero { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.tablero-marco {
  width: 100%;
  max-width: min(74vh, 100%);
  padding: 10px;
  border-radius: 18px;
  background: linear-gradient(160deg, #2a2118, #17130e 60%);
  border: 1px solid #3a2f21;
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, .9), inset 0 1px 0 rgba(255, 255, 255, .06);
}

.tablero {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}

.casilla {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 5.6vw, 52px);
  line-height: 1;
  cursor: default;
  border: 0;
  padding: 0;
  background: transparent;
}
.casilla.clara { background: var(--clara); }
.casilla.oscura { background: var(--oscura); }
.casilla.jugable { cursor: pointer; }

.casilla .coord {
  position: absolute;
  font-size: clamp(7px, 1.1vw, 10px);
  font-weight: 700;
  opacity: .55;
  pointer-events: none;
}
.casilla .coord.fila { top: 3px; left: 4px; }
.casilla .coord.col { bottom: 2px; right: 4px; }
.casilla.clara .coord { color: var(--oscura); }
.casilla.oscura .coord { color: var(--clara); }

.pieza {
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .45));
  transition: transform .08s ease;
}
.pieza.blanca { color: #fbfbf7; -webkit-text-stroke: 2px #3c3128; text-shadow: 0 2px 3px rgba(0,0,0,.35); }
.pieza.negra { color: #1b1b1b; -webkit-text-stroke: 2px #0a0a0a; text-shadow: 0 2px 3px rgba(0,0,0,.35); }
.casilla.jugable:hover .pieza { transform: scale(1.04); }

.casilla.ultima::after {
  content: "";
  position: absolute; inset: 0;
  background: rgba(224, 179, 84, .32);
  pointer-events: none;
}
.casilla.seleccionada::after {
  content: "";
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 4px var(--acento);
  pointer-events: none;
}
.casilla.destino::before {
  content: "";
  position: absolute;
  width: 26%; height: 26%;
  border-radius: 50%;
  background: rgba(30, 40, 30, .38);
  pointer-events: none;
}
.casilla.destino.ocupada::before {
  width: 88%; height: 88%;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 5px rgba(30, 40, 30, .35);
}
.casilla.jaque::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(220, 38, 38, .85) 0%, rgba(220, 38, 38, .25) 55%, transparent 72%);
  pointer-events: none;
}

.barra-estado {
  font-size: .92rem;
  color: var(--suave);
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 999px;
  padding: 7px 18px;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.barra-estado.fuerte { color: var(--texto); border-color: #3d4b60; }

/* -------------------------------------------------------------------- panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 78px;
}

.marcador { display: flex; flex-direction: column; gap: 8px; }
.jugador {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border-radius: 10px;
  background: #10151d;
  border: 1px solid transparent;
  font-size: .93rem;
}
.jugador.turno { border-color: var(--acento); background: #1d1a12; }
.punto { width: 9px; height: 9px; border-radius: 50%; background: #41506a; flex: 0 0 auto; }
.punto.en-linea { background: var(--ok); box-shadow: 0 0 8px rgba(74, 222, 128, .7); }
.jugador .nombre { font-weight: 600; }
.jugador .rol { margin-left: auto; font-size: .74rem; color: var(--suave); text-transform: uppercase; letter-spacing: .1em; }

.compartir label { display: block; font-size: .78rem; color: var(--suave); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .1em; }
.compartir .fila { justify-content: stretch; }
.compartir input { flex: 1; font-size: .82rem; padding: 9px 10px; }

.resultado {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #1d2419; border: 1px solid #35472c; border-radius: 10px; padding: 10px 12px;
  font-size: .9rem;
}

.jugadas { display: flex; flex-direction: column; min-height: 0; }
.titulo-jugadas { font-size: .74rem; color: var(--suave); text-transform: uppercase; letter-spacing: .12em; margin-bottom: 7px; }
#listaJugadas {
  margin: 0; padding: 0; list-style: none;
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 2px 6px;
  max-height: 190px; overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .84rem;
  align-content: start;
}
#listaJugadas li {
  display: flex; gap: 6px;
  padding: 3px 7px; border-radius: 6px;
  background: #10151d;
}
#listaJugadas li .num { color: var(--suave); min-width: 1.6em; }
#listaJugadas li.blanca { grid-column: 1; }
#listaJugadas li.negra { grid-column: 2; background: #0e131a; }
#listaJugadas li.vacia { visibility: hidden; }

.controles { display: flex; gap: 8px; }
.controles .boton { flex: 1; padding: 9px 8px; font-size: .86rem; }

.chat { display: flex; flex-direction: column; gap: 6px; }
.chat-mensajes {
  height: 110px; overflow-y: auto;
  background: #0b0f14; border: 1px solid var(--borde); border-radius: 9px;
  padding: 8px; font-size: .84rem; line-height: 1.45;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-mensajes .mio { color: #cfe0ff; }
.chat-mensajes .otro { color: var(--texto); }
.chat-mensajes .sistema { color: var(--suave); font-style: italic; }
.chat-mensajes b { color: var(--acento); font-weight: 600; }
.chat .fila { justify-content: stretch; }
.chat input { flex: 1; padding: 8px 10px; font-size: .86rem; }

/* -------------------------------------------------------------------- modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 8, 12, .78);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-caja {
  background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 20px 24px; text-align: center;
}
.modal-caja p { margin: 0 0 14px; color: var(--suave); }
.opciones-promocion { display: flex; gap: 8px; }
.opciones-promocion button {
  width: 62px; height: 62px; font-size: 2.1rem; line-height: 1;
  background: var(--clara); color: #1b1b1b;
  border: 1px solid #b9a588; border-radius: 12px; cursor: pointer;
}
.opciones-promocion button:hover { background: #f5e8d2; }

/* ------------------------------------------------------------------ móvil */
@media (max-width: 860px) {
  .juego { grid-template-columns: 1fr; }
  .panel { position: static; order: 2; }
  .tablero-marco { max-width: min(92vw, 560px); }
  #listaJugadas { max-height: 140px; }
}

[hidden] { display: none !important; }
