@import url("ajedrez-game.css");

/* «Ajedrez», la partida entera (jsG_133_ajedrezpartida.js). Reutiliza las
   dos vistas de «Jaque mate», así que el tablero plano (.aje2d…) y lo común
   de los juegos 3D vienen de ajedrez-game.css (que a su vez trae
   juego3d.css). Aquí: el overlay, los relojes del marcador, el selector de
   coronación, la lista de jugadas y el menú «⋯ Más». Nada de atributos
   `style`: todo por clase (CSP). */

.ajedrezpartida-overlay {
    --j3-acento: #ecd5ac;
    --j3-fondo: radial-gradient(110% 90% at 50% 40%, #3a2a1c 0%, #14100c 72%);
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 4vmin;
    overflow: auto;
    background: rgba(20, 16, 12, 0.96);
    backdrop-filter: blur(8px);
}

.ajedrezpartida-overlay--visible { display: flex; animation: ajedrez-overlay-in 0.3s ease; }

.ajedrezpartida-overlay__content {
    width: min(1100px, 100%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.ajedrezpartida-overlay__header { text-align: center; }

.ajedrezpartida-overlay__title {
    margin: 0;
    font-size: clamp(1.3rem, 3.6vmin, 2rem);
    font-weight: 800;
    letter-spacing: 0.02em;
    background: linear-gradient(135deg, #f3ead8, #9a6a43);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.ajedrezpartida-overlay__subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 0.9rem; }

.ajedrezpartida-overlay .juego3d-escenario { aspect-ratio: 1 / 1; }

.ajedrezpartida-result {
    width: 100%;
    padding: 16px;
    text-align: center;
    background: var(--surface-soft);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 0 24px -8px rgba(236, 213, 172, 0.5);
}

.ajedrezpartida-result__title { margin: 0 0 6px; font-size: 1.3rem; font-weight: 700; color: var(--j3-acento); }
.ajedrezpartida-result__text { margin: 0 0 14px; color: var(--text); }

/* La partida, en una línea que se puede leer (y copiar) al final */
.ajp-result__partida {
    display: inline-block;
    max-height: 5.5em;
    margin-top: 8px;
    overflow-y: auto;
    font-size: 0.82em;
    opacity: 0.8;
    text-align: left;
    font-variant-numeric: tabular-nums;
    user-select: text;
}

/* El tablero plano no se mete debajo del HUD: en un móvil de lado el
   tablero es tan alto como la pantalla y el marcador le tapaba la fila 8. */
.ajedrezpartida-overlay.juego--pantalla .aje2d {
    padding-top: calc(var(--j3-hud, 0px) + 6px);
    padding-bottom: 8px;
}

/* ---- Los botones del HUD: en estrecho, solo el icono (rotular() en el JS) ---- */
.ajp-ico { display: inline-block; }
.ajp-txt { margin-left: 0.35em; }
@media (max-width: 760px), (max-height: 520px) {
    .ajedrezpartida-overlay .ajp-txt:not(.ajp-txt--siempre) { display: none; }
    .ajedrezpartida-overlay .juego3d-botones .juego3d-boton { min-width: 2.6em; }
}

/* ---- Marcador: los relojes (ocultos sin reloj) ---- */
.ajedrezpartida-overlay .juego3d-dato[hidden] { display: none; }
.ajp-dato--corre b { color: var(--j3-acento); text-shadow: 0 0 8px rgba(236, 213, 172, 0.45); }
.ajp-dato--apurado b { color: #ff8a7a; }
.ajedrezpartida-overlay #ajedrezpartida-blancas,
.ajedrezpartida-overlay #ajedrezpartida-negras { font-variant-numeric: tabular-nums; min-width: 3.2em; display: inline-block; }

/* ---- Chips ---- */
.ajp-chip--jaque { color: #ff9a8a; border-color: currentColor; }
.juego3d-chip.ajp-chip--ultima { text-transform: none; letter-spacing: 0.02em; font-size: 0.8rem; }

/* ---- Coronación: cuatro piezas a elegir, sobre el tablero ---- */
.ajp-corona {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    padding-top: calc(var(--j3-hud, 0px) + 16px);
    background: rgba(8, 6, 4, 0.62);
}
.ajp-corona[hidden] { display: none; }

.ajp-corona__titulo {
    margin: 0;
    font-size: clamp(1.1rem, 4vmin, 1.6rem);
    font-weight: 800;
    color: var(--j3-acento);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

.ajp-corona__piezas {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    width: min(460px, 100%);
}

.ajp-corona__pieza {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px 8px;
    border: 2px solid rgba(236, 213, 172, 0.5);
    border-radius: 14px;
    background: #f2eadb;
    color: #2a2521;
    cursor: pointer;
    font: inherit;
    transition: transform 0.12s ease, border-color 0.12s ease;
}
.ajp-corona__pieza:hover,
.ajp-corona__pieza:focus-visible { transform: translateY(-3px); border-color: #ffd23f; outline: none; }
.ajp-corona__pieza:disabled { opacity: 0.35; cursor: default; transform: none; }

.ajp-corona__glifo {
    font-size: clamp(2.4rem, 12vmin, 4rem);
    line-height: 1;
    color: #d4cdbf;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.95), 1px 0 0 rgba(0, 0, 0, 0.6), -1px 0 0 rgba(0, 0, 0, 0.6),
                 0 1px 0 rgba(0, 0, 0, 0.6), 0 -1px 0 rgba(0, 0, 0, 0.6);
}
.ajp-corona--negras .ajp-corona__glifo {
    color: #2a2521;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.85), 1px 0 0 rgba(255, 255, 255, 0.5), -1px 0 0 rgba(255, 255, 255, 0.5);
}
.ajp-corona__nombre { font-size: 0.85rem; font-weight: 700; }

/* Las piezas en 3D (games/ajedrez/coronaPiezas.js): un solo lienzo encima
   de la rejilla, que no recibe toques, pinta cada pieza en el hueco de su
   glifo. El glifo se queda (invisible) para guardar el sitio y por si el
   3D no llega. El fondo de los botones, de madera a media luz, para que se
   lean igual las piezas blancas que las negras. */
.ajp-corona__piezas { position: relative; }

.ajp-corona__lienzo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.ajp-corona--3d .ajp-corona__piezas { width: min(600px, 100%); }

.ajp-corona--3d .ajp-corona__pieza {
    background: radial-gradient(circle at 50% 40%, #8c6b49 0%, #5c4029 58%, #36261a 100%);
    color: #f2eadb;
}

.ajp-corona--3d .ajp-corona__glifo {
    display: block;
    width: 100%;
    height: clamp(5.5rem, 26vmin, 10rem);
    color: transparent;
    text-shadow: none;
}

.ajp-corona--3d .ajp-corona__nombre {
    position: relative;
    z-index: 2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.ajp-corona .ajp-panel__cerrar { align-self: center; background: rgba(20, 16, 12, 0.85); }

/* ---- Paneles: la lista de jugadas y el menú «⋯ Más» ---- */
.ajp-panel {
    position: absolute;
    z-index: 40;
    top: calc(var(--j3-hud, 0px) + 8px);
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(300px, calc(100% - 20px));
    max-height: calc(100% - var(--j3-hud, 0px) - 24px);
    padding: 12px;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: rgba(20, 16, 12, 0.94);
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.9);
}
.ajp-panel[hidden] { display: none; }

.ajp-panel__titulo { margin: 0; font-weight: 800; color: var(--j3-acento); }

.ajp-panel__cerrar {
    align-self: flex-end;
    padding: 6px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.ajp-lista__vacia { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.ajp-lista__vacia[hidden] { display: none; }

.ajp-lista__ol {
    margin: 0;
    padding: 0 0 0 2.4em;
    overflow-y: auto;
    font-variant-numeric: tabular-nums;
    line-height: 1.6;
}
.ajp-lista__jugada::marker { color: var(--text-muted); }
.ajp-lista__san { display: inline-block; min-width: 4.6em; font-weight: 600; }

.ajp-menu__op { width: 100%; text-align: left; }
.ajp-menu__op[hidden] { display: none; }

.juego3d-boton[hidden] { display: none; }

@media (max-height: 640px), (max-width: 480px) {
    .ajedrezpartida-overlay { padding: 2vmin; }
    .ajedrezpartida-overlay__subtitle { display: none; }
    .ajedrezpartida-overlay__title { font-size: 1.1rem; }
    .ajp-corona__piezas { gap: 6px; }
}

/* ---- «💾 Guardar o enviar la partida» (lista de jugadas y cartel final) ----
   Un <details>: plegado no le quita sitio a la lista. Lo monta
   montarGuardar() en jsG_133. */
.ajp-lista__guardar { flex: none; }
.ajp-lista__ol { flex: 1 1 auto; min-height: 3em; }
.ajp-panel.ajp-lista { overflow-y: auto; }

.ajp-guardar {
    border-top: 1px solid var(--border-strong);
    padding-top: 8px;
    text-align: left;
}
.ajp-guardar__resumen {
    cursor: pointer;
    font-weight: 700;
    color: var(--j3-acento);
}
.ajp-guardar[open] .ajp-guardar__resumen { margin-bottom: 8px; }

.ajp-guardar__formato {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}
.ajp-guardar__select {
    flex: 1;
    min-width: 0;
    padding: 4px 6px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font: inherit;
}
.ajp-guardar__select option { color: #1a1a1a; }

.ajp-guardar__pista { margin: 6px 0; color: var(--text-muted); font-size: 0.8rem; line-height: 1.35; }

.ajp-guardar__texto {
    box-sizing: border-box;
    width: 100%;
    resize: vertical;
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    font: 0.75rem/1.4 ui-monospace, "DejaVu Sans Mono", Menlo, monospace;
    white-space: pre;
}

.ajp-guardar__botones {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.ajp-guardar__botones .juego3d-boton { flex: 1 1 auto; font-size: 0.85rem; }

.ajp-guardar__estado { margin: 6px 0 0; min-height: 1.2em; font-size: 0.8rem; color: var(--text-muted); }

/* En el cartel final, centrado y no más ancho que la partida de arriba */
.ajp-result__guardar { max-width: 480px; margin: 10px auto 0; }

/* La apertura que se está jugando: chip discreto, que no tape el tablero.
   El nombre largo («Gambito de dama rehusado: defensa ortodoxa») se corta
   con puntos suspensivos; entero, en el title junto a la idea. */
/* Con la columna de la derecha más alta, el chip del turno no se estira */
.ajedrezpartida-overlay .juego3d-chips { align-items: flex-start; }
.ajp-chips__derecha {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    min-width: 0;
}
.juego3d-chip.ajp-chip--apertura {
    text-transform: none;
    letter-spacing: 0.02em;
    font-size: 0.8rem;
    max-width: min(26em, 60vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.9;
}
.ajp-chip--apertura[hidden] { display: none; }
.ajp-result__apertura { font-weight: 600; color: var(--j3-acento); }

/* ---- Las piezas de BATALLA (ajedrez/vistaBatalla.js, 10-oct-2026) ----
   La sala de public/_dev/batalla montada dentro del escenario: su lienzo
   ocupa la caja entera (lo mide su ResizeObserver), con el aviso de carga,
   «Saltar» el duelo y el cartel grande del jaque, que la escena maneja por
   sus ids del banco (tb-saltar, tb-cartel). Los colores, los del banco. */
.juego3d-escenario.ajb-host { background: #0a0806; }

.ajb-sala { position: absolute; inset: 0; overflow: hidden; }
.ajb-sala > canvas { display: block; touch-action: none; }

.ajb-cargando {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    margin: 0;
    padding: 16px;
    text-align: center;
    color: #d8b25a;
    font: italic 1.1rem/1.4 Georgia, serif;
    letter-spacing: 0.04em;
}

.ajb-saltar {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 2;
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid rgba(216, 178, 90, 0.6);
    background: rgba(14, 10, 7, 0.82);
    color: #d8b25a;
    font-size: 1rem;
    letter-spacing: 0.06em;
    cursor: pointer;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}
.ajb-saltar[hidden] { display: none; }
.ajb-saltar:hover,
.ajb-saltar:focus-visible { background: rgba(92, 64, 24, 0.85); outline: none; }

.ajb-cartel {
    position: absolute;
    left: 50%;
    top: 22%;
    z-index: 1;
    transform: translateX(-50%);
    pointer-events: none;
    font: 700 clamp(1.8rem, 7vmin, 4.4rem)/1 Georgia, serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    color: #ffd9c4;
    text-shadow: 0 0 2px #3a0a04, 0 0 24px rgba(255, 80, 40, 0.85), 0 0 60px rgba(255, 60, 20, 0.45);
}
.ajb-cartel[hidden] { display: none; }
.ajb-cartel.tb-sale { animation: ajb-cartel 0.2s ease-out both, ajb-cartel-fuera 0.6s ease-in 1.6s forwards; }
.ajb-cartel.tb-mate { color: #ffe7a8; text-shadow: 0 0 2px #3a2004, 0 0 26px rgba(255, 190, 60, 0.9), 0 0 70px rgba(255, 140, 20, 0.5); }
@keyframes ajb-cartel { from { opacity: 0; transform: translateX(-50%) scale(1.5); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes ajb-cartel-fuera { to { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(0.96); } }

/* ---- Partidas famosas (nivel «📚 Partidas famosas», 10-oct-2026) ----
   La lista con su buscador (un .ajp-panel algo más ancho) y, abajo, la
   barra del reproductor: la caja de la guía y las notas encima de los
   mandos ⏮ ◀ ⏯ ▶ ⏭. Los monta jsG_133 (ui, en crearPartida). */
.ajp-panel.ajp-famosas { width: min(380px, calc(100% - 20px)); }
.ajp-famosas__buscar {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    font: inherit;
}
.ajp-famosas__estado { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.ajp-famosas__lista {
    flex: 1 1 auto;
    min-height: 3em;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}
.ajp-famosas__partida {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
}
.ajp-famosas__partida:hover,
.ajp-famosas__partida:focus-visible { background: rgba(236, 213, 172, 0.12); outline: none; }
.ajp-famosas__partida small { color: var(--text-muted); }

.ajp-repro {
    position: absolute;
    z-index: 35;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: min(560px, calc(100% - 20px));
    pointer-events: none;
}
.ajp-repro[hidden] { display: none; }
.ajp-repro > * { pointer-events: auto; }
/* La caja de la guía: dentro de la barra, encima de los mandos (estrecho), o
   en la columna libre de la izquierda (ancho: --ajp-lado lo calcula
   colocarRepro, que la cambia de sitio). */
.ajp-repro__nota {
    box-sizing: border-box;
    max-height: 22vh;
    overflow-y: auto;
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: rgba(20, 16, 12, 0.9);
    color: var(--text);
    font-size: 0.92rem;
    line-height: 1.45;
}
.ajp-repro__nota[hidden] { display: none; }
.ajp-repro__nota--lado {
    position: absolute;
    z-index: 35;
    left: 10px;
    top: calc(var(--j3-hud, 0px) + 56px);
    width: var(--ajp-lado, 300px);
    max-height: calc(100% - var(--j3-hud, 0px) - 140px);
}
/* El tablero plano deja libre la franja de los mandos; de pie (estrecho),
   además se pega arriba para que la guía quepa debajo. */
.ajedrezpartida-overlay .juego3d-escenario.ajp-con-repro .aje2d { padding-bottom: 64px; }
@media (max-aspect-ratio: 1/1) {
    .ajedrezpartida-overlay .juego3d-escenario.ajp-con-repro .aje2d { align-items: flex-start; }
}
.ajp-repro__nota p { margin: 0 0 6px; white-space: pre-line; }
.ajp-repro__nota p:last-child { margin-bottom: 0; }
.ajp-repro__titulo { font-weight: 800; color: var(--j3-acento); }
.ajp-repro__sub { color: var(--text-muted); font-size: 0.85rem; }
.ajp-repro__jugada { font-style: italic; }
.ajp-repro__final { font-weight: 700; color: var(--j3-acento); }
.ajp-repro__mandos {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px;
    border-radius: 999px;
    background: rgba(20, 16, 12, 0.85);
}
.ajp-repro__boton { min-width: 2.6em; }
.ajp-repro__boton:disabled { opacity: 0.4; }
.ajp-repro__pos {
    min-width: 8.5em;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}
.ajp-lista__san--ir { cursor: pointer; border-radius: 6px; padding: 0 4px; }
.ajp-lista__san--ir:hover { background: rgba(236, 213, 172, 0.12); }
.ajp-lista__san--actual { background: rgba(236, 213, 172, 0.25); color: var(--j3-acento); }
/* Lo visto (chess_game_views) y las jugadas comentadas */
.ajp-famosas__visto { font-weight: 700; }
.ajp-famosas__partida--vista .ajp-famosas__visto { color: #8fd98f; }
.ajp-famosas__partida--empezada .ajp-famosas__visto { color: var(--j3-acento); }
.ajp-lista__san--nota { text-decoration: underline dotted; text-underline-offset: 3px; }
.ajp-repro__boton[hidden] { display: none; }
/* La lista de jugadas por ventanas de 20 (◀ Anteriores · Jugadas 11–30 de 56 · Siguientes ▶) */
.ajp-lista__paginas { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex: none; }
.ajp-lista__paginas[hidden] { display: none; }
.ajp-lista__paginas .ajp-panel__cerrar { align-self: auto; padding: 4px 10px; white-space: nowrap; font-size: 0.8rem; }
.ajp-lista__paginas .ajp-panel__cerrar:disabled { opacity: 0.35; cursor: default; }
.ajp-lista__rango { color: var(--text-muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; text-align: center; line-height: 1.2; }
/* La apertura, siempre bajo el título en la caja del reproductor */
.ajp-repro__apertura { color: var(--j3-acento); font-size: 0.85rem; }
