/* Crucigrama Compumundo multijugador: lo que se agrega a css/estilos.css (que es el de la versión de un jugador). */

/* Colores de los jugadores: se asignan en orden de llegada (0 a 7) */
:root {
  --j0: #C2410C; --j1: #1D4ED8; --j2: #15803D; --j3: #9333EA;
  --j4: #BE185D; --j5: #0E7490; --j6: #A16207; --j7: #4338CA;
  --j-txt: #FFFFFF;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --j0: #FB923C; --j1: #60A5FA; --j2: #4ADE80; --j3: #C084FC;
    --j4: #F472B6; --j5: #22D3EE; --j6: #FACC15; --j7: #A5B4FC;
    --j-txt: #11161C;
  }
}
:root[data-theme="dark"] {
  --j0: #FB923C; --j1: #60A5FA; --j2: #4ADE80; --j3: #C084FC;
  --j4: #F472B6; --j5: #22D3EE; --j6: #FACC15; --j7: #A5B4FC;
  --j-txt: #11161C;
}
[data-c="0"], [data-autor="0"] { --jc: var(--j0); }
[data-c="1"], [data-autor="1"] { --jc: var(--j1); }
[data-c="2"], [data-autor="2"] { --jc: var(--j2); }
[data-c="3"], [data-autor="3"] { --jc: var(--j3); }
[data-c="4"], [data-autor="4"] { --jc: var(--j4); }
[data-c="5"], [data-autor="5"] { --jc: var(--j5); }
[data-c="6"], [data-autor="6"] { --jc: var(--j6); }
[data-c="7"], [data-autor="7"] { --jc: var(--j7); }

/* ---------- Inicio ---------- */
.lobby { display: flex; flex-direction: column; gap: 2rem; max-width: 42rem; width: 100%; align-self: center; }
.lobby .masthead { gap: .35rem; }
.lobby h1 { font-size: min(3.1rem, 8.6cqi); }
.mast-slot { display: contents; }
.lb-card {
  border: 3px solid var(--block); background: var(--cell);
  padding: 1.4rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: .9rem;
}
.lb-card h2 { margin: 0; font-family: var(--font-display); font-size: 1.75rem; line-height: 1.1; }
.lb-card p { margin: 0; }
.lb-texto { max-width: 52ch; }
.lb-form { display: flex; flex-wrap: wrap; gap: .7rem 1rem; align-items: flex-end; }
.lb-form > .ax-field:first-child { flex: 1 1 100%; }
.lb-tam { flex: 0 1 auto; display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.lb-form > button { margin-left: auto; }
.lobby input[type="text"] {
  font: inherit; color: var(--ink); background: var(--cell); border: 2px solid var(--ink); border-radius: 3px;
  padding: .45rem .6rem; width: 100%; min-width: 0;
}
.lobby input::placeholder { color: var(--ink-soft); opacity: .65; }
.lobby input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.lobby input:disabled { opacity: .6; }
.lb-form button, .lb-fila button { padding-block: .5rem; }
.lb-msg { min-height: 1.5em; font-size: .92rem; color: var(--ink-soft); }
.lb-msg.bad { color: var(--bad); font-weight: 700; }
.lb-msg:empty { display: none; }
.lb-otra:has(> [hidden]) { display: none; }
button.linkish {
  border: 0; background: none; padding: 0; color: var(--accent); font-weight: 700;
  text-decoration: underline; text-underline-offset: 3px;
}
button.linkish:hover { background: none; color: var(--ink); }
.lb-unirse, .lb-recientes { display: flex; flex-direction: column; gap: .4rem; border-top: 2px solid var(--rule); padding-top: .9rem; }
.lb-fila { display: grid; grid-template-columns: minmax(0, 12rem) auto; gap: .5rem; justify-content: start; }
#lb-codigo { font-family: var(--font-grid); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.lb-recientes h3 { margin: 0; }
.lb-recientes ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .45rem; }
button.lb-sala { display: inline-flex; flex-direction: column; align-items: flex-start; gap: .05rem; padding: .35rem .7rem; line-height: 1.25; }
.lb-sala .cod { font-family: var(--font-grid); letter-spacing: .08em; }
.lb-sala small { font-weight: 400; color: var(--ink-soft); font-size: .78rem; }
.lb-como { display: flex; flex-direction: column; gap: .7rem; }
.lb-como ol { margin: 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: .45rem; max-width: 60ch; }
.lb-como li::marker { font-family: var(--font-display); font-weight: 700; }
@media (max-width: 480px) {
  .lb-card { padding: 1.1rem 1rem 1.2rem; }
  .lb-form > button { flex: 1 1 100%; }
  .lb-fila { grid-template-columns: minmax(0, 1fr) auto; }
}

/* ---------- Barra de la sala ---------- */
.sala {
  display: flex; flex-direction: column; gap: .55rem; min-width: 0;
  padding: .65rem .8rem .75rem; border: 2px solid var(--block); background: var(--cell);
}
.sala-fila { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .9rem; font-size: .88rem; color: var(--ink-soft); }
.sala-tag { font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; }
.sala-tag b { font-family: var(--font-grid); font-size: 1.1rem; letter-spacing: .08em; color: var(--ink); margin-left: .3rem; }
.sala-num { font-family: var(--font-display); font-weight: 700; color: var(--ink); }
.sala-red { color: var(--bad); font-weight: 700; }
.jugadores { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.jug {
  display: inline-flex; align-items: center; gap: .4rem; max-width: 100%;
  padding: .15rem .55rem .15rem .45rem; border: 2px solid var(--jc); border-radius: 999px;
  font-size: .85rem; font-weight: 700; background: var(--paper);
}
.jug .punto { width: .7rem; height: .7rem; border-radius: 50%; background: var(--jc); flex: none; }
.jug .jn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.jug small { font-weight: 400; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.jug.fuera { opacity: .6; border-style: dashed; }
.jug.fuera .punto { background: transparent; box-shadow: inset 0 0 0 2px var(--jc); }
.jug-mas { font-size: .82rem; color: var(--ink-soft); align-self: center; }
.sala-acciones { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.sala-acciones .btn-ico svg { width: 1.05rem; height: 1.05rem; }
.sala .chip { border-width: 2px; }
.sin-red .board .grid { opacity: .85; }

/* Escritorio: la sala va entre el título y las pistas */
@media (min-width: 921px) {
  .puzzle {
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "board head" "board sala" "board clues";
  }
  .sala { grid-area: sala; }
}

/* ---------- Tablero compartido ---------- */
/* Quién escribió cada letra: una línea de su color al pie de la casilla */
.con-autoria .cell[data-autor] input { box-shadow: inset 0 calc(-1 * max(2px, calc(9cqi / var(--n)))) 0 var(--jc); }
.con-autoria .cell.active[data-autor] input { box-shadow: inset 0 0 0 2px var(--ink), inset 0 calc(-1 * max(3px, calc(12cqi / var(--n)))) 0 var(--jc); }

/* Dónde está cada uno: marco de su color y su nombre arriba */
.cell .otro {
  position: absolute; inset: -1px; z-index: 2; pointer-events: none;
  border: max(2px, calc(7.5cqi / var(--n))) solid var(--jc);
}
.cell .otro::before {
  content: attr(data-n);
  position: absolute; left: calc(-1 * max(2px, calc(7.5cqi / var(--n)))); bottom: 100%;
  max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--jc); color: var(--j-txt);
  font-family: var(--font-body); font-weight: 700; font-size: max(9px, calc(26cqi / var(--n))); line-height: 1.35;
  padding: 0 .3rem; border-radius: 2px 2px 0 0;
}
/* en la primera fila el nombre va abajo, y en la mitad derecha se alinea a la derecha: así no se sale del tablero */
.cell .otro.abajo::before { bottom: auto; top: 100%; border-radius: 0 0 2px 2px; }
.cell .otro.der::before { left: auto; right: calc(-1 * max(2px, calc(7.5cqi / var(--n)))); }
@media (prefers-reduced-motion: no-preference) {
  .cell .otro { animation: otro-in .18s ease-out both; }
  @keyframes otro-in { from { opacity: 0; transform: scale(1.25); } to { opacity: 1; transform: none; } }
}

/* ---------- Invitar ---------- */
.sh-link { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
.sh-link input { font-size: .9rem; }
.sh-extra { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; }
.sh-extra .ax-hint:empty { display: none; }
.sh-qr-box {
  display: grid; grid-template-columns: 10rem minmax(0, 1fr); gap: 1rem; align-items: center;
  border-top: 2px solid var(--rule); padding-top: 1rem;
}
.sh-qr-box p { margin: 0; }
.sh-qr svg { display: block; width: 100%; height: auto; border: 2px solid var(--block); }
.sh-codigo { display: inline-block; font-family: var(--font-grid); letter-spacing: .1em; font-size: 1.2rem; white-space: nowrap; }
@media (max-width: 420px) {
  .sh-link { grid-template-columns: minmax(0, 1fr); }
  .sh-qr-box { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; }
  .sh-qr { width: 13rem; }
}

/* ---------- Configuración: nombre ---------- */
.nombre-form { display: grid; grid-template-columns: minmax(0, 16rem) auto; gap: .35rem .6rem; align-items: end; justify-content: start; }
.nombre-form .ax-hint:empty { display: none; }

/* Avisos de lo que hacen los demás */
.toast.info { border-left-color: var(--accent); }

/* ---------- Ránking: lugar y medallas de oro, plata y bronce ---------- */
:root {
  --oro: #E2B13C; --oro-borde: #9A7414; --oro-txt: #2B2008;
  --plata: #C9D1D9; --plata-borde: #7D8894; --plata-txt: #1E252C;
  --bronce: #DB935C; --bronce-borde: #8E5326; --bronce-txt: #2A1608;
}
.lugar {
  display: inline-grid; place-items: center; flex: none; min-width: 1.4rem; height: 1.4rem; padding: 0 .3rem;
  border-radius: 999px; border: 1.5px solid var(--rule); background: var(--cell); color: var(--ink-soft);
  font-family: var(--font-grid); font-weight: 700; font-size: .78rem; line-height: 1; font-variant-numeric: tabular-nums;
}
.oro > .lugar { background: var(--oro); border-color: var(--oro-borde); color: var(--oro-txt); }
.plata > .lugar { background: var(--plata); border-color: var(--plata-borde); color: var(--plata-txt); }
.bronce > .lugar { background: var(--bronce); border-color: var(--bronce-borde); color: var(--bronce-txt); }
.jug.oro { background: color-mix(in srgb, var(--oro) 22%, var(--paper)); }
.jug.plata { background: color-mix(in srgb, var(--plata) 26%, var(--paper)); }
.jug.bronce { background: color-mix(in srgb, var(--bronce) 22%, var(--paper)); }
.jug { padding-left: .25rem; }
.jug small { font-weight: 700; color: var(--ink); }

.rk { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.rk-fila {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .6rem;
  padding: .4rem .6rem; border-left: 5px solid var(--jc); background: var(--cell); border-radius: 0 3px 3px 0;
}
.rk-n { font-weight: 700; overflow-wrap: anywhere; }
.rk-p { font-size: .85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; text-align: right; }
.rk-fila.oro { background: color-mix(in srgb, var(--oro) 24%, var(--cell)); }
.rk-fila.plata { background: color-mix(in srgb, var(--plata) 30%, var(--cell)); }
.rk-fila.bronce { background: color-mix(in srgb, var(--bronce) 24%, var(--cell)); }
.info-puntos { display: flex; flex-direction: column; gap: .5rem; }
.info-puntos h3 { margin: 0; font-family: var(--font-display); font-size: 1.15rem; }
.cheer-ranking { width: 100%; margin: .2rem 0 .1rem; }
.cheer .rk-fila { background: var(--paper); }
@media (max-width: 420px) { .rk-fila { grid-template-columns: auto minmax(0, 1fr); } .rk-p { grid-column: 2; text-align: left; } }

/* Pista ganada: una franja del color de quien llenó más de la mitad de sus letras */
.clue[data-autor] { box-shadow: inset 4px 0 0 var(--jc); }
.clue[data-autor] .n { color: var(--jc); }

/* ---------- Votación para revelar todo ---------- */
.voto {
  position: fixed; z-index: 44; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  width: min(25rem, calc(100vw - 2rem)); display: flex; flex-direction: column; gap: .45rem;
  background: var(--cell); color: var(--ink); border: 3px solid var(--block); border-left: 8px solid var(--accent);
  padding: .8rem 1rem .9rem; box-shadow: 0 14px 40px rgba(0, 0, 0, .3);
}
.voto p { margin: 0; }
.voto-titulo { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
.voto-estado { font-size: .88rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.voto-acciones { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.voto-acciones button[aria-pressed="true"]::before { content: "✓ "; }
.voto-acciones button[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .voto:not([hidden]) { animation: voto-in .25s ease-out both; }
}
/* su propia animación: la del aviso temporal lo corre a la izquierda (translateX(-50%)) */
@keyframes voto-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
/* en pantallas medianas el aviso temporal (centrado) chocaría con la votación: sube por encima */
@media (min-width: 601px) and (max-width: 1300px) {
  .voto:not([hidden]) ~ .toast { bottom: calc(12rem + env(safe-area-inset-bottom, 0px)); }
}
/* en el teléfono, arriba (abajo están el aviso temporal y el teclado) */
@media (max-width: 600px) {
  .voto { top: calc(.6rem + env(safe-area-inset-top, 0px)); bottom: auto; left: .6rem; right: .6rem; width: auto; }
}

/* ---------- Reglas ---------- */
.lb-reglas { font-size: .9rem; color: var(--ink-soft); }
.lb-reglas .linkish { font-size: .9rem; margin-left: .2rem; }
.seg input:disabled + label { opacity: .55; cursor: not-allowed; }
.seg input:disabled + label:hover { background: var(--cell); }
.seg input:disabled:checked + label:hover { background: var(--ink); }

/* Tableros grandes a todo el ancho: la barra de la sala va entre el título y el tablero */
@media (min-width: 921px) {
  :root[data-ancho] .puzzle { grid-template-rows: none; grid-template-areas: "head" "sala" "board" "clues"; }
}

@media print {
  .sala, .lobby, .cell .otro { display: none !important; }
  .con-autoria .cell[data-autor] input { box-shadow: none; }
}
