:root {
    /* El tablero se escala dinámicamente entre el ancho y alto del dispositivo */
    --board-size: min(90vw, 62vh, 560px);
    --coord-size: clamp(16px, 3vw, 30px);
}

/* ==========================================================================
   1. ESTILOS GENERALES Y RESETS GLOBALES DEL CSS
   ========================================================================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background: #1e1e1e;
    color: white;
    font-family: Arial, sans-serif;
    min-height: 100vh;
}

select,
input[type="number"],
input[type="text"],
input[type="password"],
input[type="email"],
button {
    padding: 6px 10px;
    background: #444;
    border: 1px solid #555;
    color: white;
    border-radius: 4px;
}

button {
    background: #28a745;
    cursor: pointer;
    font-weight: bold;
    border: none;
}

button:hover {
    background: #218838;
}

/* ==========================================================================
   2. PÁGINA PRINCIPAL / TABLERO DE JUEGO (index.html)
   ========================================================================== */
body.game-page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    position: relative;
}

.game-layout {
    display: flex;
    align-items: center;
    gap: 30px;
}

.center-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0px !important;
}

/* BARRAS DE JUGADORES FLUIDAS */
.player-bar {
    width: 100%;
    max-width: calc(var(--board-size) + (var(--coord-size) * 2));
    background: #252525;
    padding: 8px 16px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
    border-left: 2px solid #3e2723;
    border-right: 2px solid #3e2723;
}

.player-bar.top {
    border-top: 2px solid #3e2723;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.player-bar.bottom {
    border-bottom: 2px solid #3e2723;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}

.player input {
    background: transparent;
    border: none;
    color: white;
    font-weight: bold;
    font-size: 16px;
    width: 200px;
}

.player input:focus {
    outline: none;
}

.turn {
    outline: 2px solid gold;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
    z-index: 10;
}

.player-timer {
    background: #111;
    color: #00ffcc;
    font-family: 'Courier New', Courier, monospace;
    font-size: 18px;
    font-weight: bold;
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid #333;
    letter-spacing: 1px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.8);
}

/* TABLERO FLUIDO Y AUTO-AJUSTABLE */
.board-wrapper {
    width: calc(var(--board-size) + (var(--coord-size) * 2));
    height: calc(var(--board-size) + (var(--coord-size) * 2));
    display: grid;
    grid-template-columns: var(--coord-size) 1fr var(--coord-size);
    grid-template-rows: var(--coord-size) 1fr var(--coord-size);
    background: #3e2723;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
    align-items: center;
    justify-items: center;
    transition: transform 0.3s ease;
    margin: 0;
    padding: 0;
}

.coord-h,
.coord-v {
    display: flex;
    font-weight: bold;
    color: #d7ccc8;
    font-size: 14px;
    justify-content: space-around;
}

.coord-h {
    width: 100%;
}

.coord-v {
    flex-direction: column;
    height: 100%;
}

.board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 2px solid #271512;
}

.cell {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    user-select: none;
}

.light {
    background: #f0d9b5;
}

.dark {
    background: #b58863;
}

.cell-number,
.square-number {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 11px;
    color: #bfa38a;
    font-weight: bold;
    z-index: 1;
    transition: transform 0.3s ease;
}

/* FICHAS AUTO-PROPORCIONALES */
.piece {
    width: 76%;
    height: 76%;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(14px, 3.5vw, 28px);
    font-weight: bold;
    transition: transform .2s, box-shadow .2s;
    z-index: 2;
    position: relative;
    user-select: none;
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    border-bottom: 1px solid rgba(0, 0, 0, 0.6);
}

.red-piece {
    background: radial-gradient(circle at 35% 35%, #ff4d6d 10%, #dc143c 60%, #80001d 100%);
    box-shadow: 0 2px 0 #9a0f28, 0 4px 0 #780a1e, 0 5px 0 #560513, 0 6px 8px rgba(0, 0, 0, 0.6);
}

.black-piece {
    background: radial-gradient(circle at 35% 35%, #444 10%, #151515 60%, #050505 100%);
    box-shadow: 0 2px 0 #0d0d0d, 0 4px 0 #080808, 0 5px 0 #030303, 0 6px 8px rgba(0, 0, 0, 0.7);
}

.king {
    color: #fff3a8;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    border: none !important;
}

.piece::before {
    content: "";
    position: absolute;
    width: 65%;
    height: 65%;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.15);
    pointer-events: none;
}

.selected {
    transform: scale(1.05) translateY(-3px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 4px 0 rgba(0, 0, 0, 0.4), 0 8px 15px rgba(255, 238, 85, 0.7);
}

.forced {
    outline: 3px solid #00ffcc;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 4px 0 rgba(0, 0, 0, 0.4), 0 0 5px #00ffcc;
    }

    50% {
        box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 4px 0 rgba(0, 0, 0, 0.4), 0 0 20px #00ffcc;
    }

    100% {
        box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 4px 0 rgba(0, 0, 0, 0.4), 0 0 5px #00ffcc;
    }
}

/* PANEL LATERAL Y CONTROLES */
.history-panel {
    width: 220px;
    height: 620px;
    background: #252525;
    border-radius: 6px;
    border: 2px solid #444;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
}

.history-info {
    text-align: center;
    font-size: 13px;
    color: #aaa;
    line-height: 1.4;
}

.btn-history {
    background: #007bff;
    text-decoration: none;
    color: white;
    text-align: center;
    padding: 10px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 14px;
}

.btn-history:hover {
    background: #0056b3;
}

/* ROTACIÓN DE TABLERO */
.board-wrapper.flipped-board {
    transform: rotate(180deg) !important;
}

.board-wrapper.flipped-board .piece,
.board-wrapper.flipped-board .cell-number,
.board-wrapper.flipped-board .square-number,
.board-wrapper.flipped-board .coord-h span,
.board-wrapper.flipped-board .coord-v span {
    transform: rotate(180deg) !important;
}

/* MENÚ DESPLEGABLE SUPERIOR IZQUIERDO */
.top-left-menu-container {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 100;
}

.menu-icon-btn {
    background: #2b2b2b;
    color: gold;
    border: 1px solid #444;
    font-size: 20px;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.menu-icon-btn:hover {
    background: #3a3a3a;
}

.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.menu-dropdown.show {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.menu-dropdown-title {
    color: gold;
    font-weight: bold;
    font-size: 13px;
    text-align: center;
    padding-bottom: 6px;
    border-bottom: 1px solid #333;
    margin-bottom: 4px;
}

.btn-action-item {
    background: #333;
    color: white;
    border: 1px solid #444;
    padding: 9px 12px;
    border-radius: 5px;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    width: 100%;
    transition: background 0.2s;
}

.btn-action-item:hover {
    background: #444;
}

.btn-action-item.logout {
    background: #8b0000;
}

.btn-action-item.logout:hover {
    background: #a50000;
}

/* ==========================================================================
   MEDIA QUERIES RESPONSIVAS LIMPIAS (SIN ESCALADO FORZADO)
   ========================================================================== */
@media (max-width: 1024px) {
    .game-layout {
        flex-direction: column;
        gap: 15px;
    }

    .history-panel {
        width: 100%;
        max-width: calc(var(--board-size) + (var(--coord-size) * 2));
        height: auto;
        max-height: 150px;
    }
}

@media (max-width: 600px) {
    body.game-page {
        padding: 5px;
        gap: 5px;
    }

    .top-left-menu-container {
        position: static;
        margin-bottom: 5px;
    }

    .player input {
        width: 100px;
        font-size: 13px;
    }

    .player-timer {
        font-size: 14px;
        padding: 2px 6px;
    }
}

/* ==========================================================================
   3. PÁGINA DE SALAS DE ESPERA (salas.html)
   ========================================================================== */
.header {
    width: 100%;
    background: #111;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #333;
}

.logo {
    color: gold;
    font-size: 24px;
    font-weight: bold;
}

.user-info {
    color: #ddd;
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-logout {
    background: #dc3545;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: background 0.2s ease;
}

.btn-logout:hover {
    background: #bd2130;
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: auto;
    padding: 20px;
}

.create-room {
    background: #2b2b2b;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 25px;
}

.create-room h2 {
    color: gold;
    margin-bottom: 15px;
    margin-top: 0;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn-public {
    background: #28a745;
    color: white;
}

.btn-private {
    background: #007bff;
    color: white;
}

.section-title {
    color: gold;
    margin-bottom: 15px;
}

.rooms {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.room-card {
    background: #2b2b2b;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #444;
}

.room-title {
    font-size: 20px;
    margin-bottom: 10px;
    color: gold;
}

.room-info {
    color: #ccc;
    margin-bottom: 8px;
}

.room-actions {
    margin-top: 15px;
}

.join-btn {
    background: #ffc107;
    color: black;
    width: 100%;
}

.join-btn:disabled {
    background: #555 !important;
    color: #aaa !important;
    cursor: not-allowed;
}

/* ==========================================================================
   4. PÁGINA DE HISTORIAL Y REPETICIONES (historial.html) OK
   ========================================================================== */
body.history-page {
    background: #151515;
    font-family: 'Courier New', Courier, monospace;
    padding: 20px;
}

.history-header {
    text-align: center;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.history-title {
    color: #28a745;
    margin: 0;
    font-size: 24px;
}

.subtitle {
    color: #888;
    font-size: 13px;
    margin-top: 5px;
    text-align: center;
}

.history-table {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 40px auto;
    border-collapse: collapse;
    background: #1e1e1e;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: hidden;
}

.history-table th,
.history-table td {
    padding: 12px 15px;
    text-align: left;
}

.history-table th {
    background: #2a2a2a;
    color: gold;
    font-size: 16px;
    text-transform: uppercase;
    border-bottom: 2px solid #444;
}

.history-table tr {
    border-bottom: 1px solid #2a2a2a;
}

.history-table tr:nth-child(even) {
    background: #232323;
}

.historial-controls {
    position: relative;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin: 15px 0;
}

.btn-nav {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 44px;
    padding: 8px 16px;
    cursor: pointer;
}

.move-number {
    color: #888;
    font-weight: bold;
    width: 15%;
}

.red-move {
    color: #ff5252;
    font-weight: bold;
    width: 42.5%;
}

.black-move {
    color: #e0e0e0;
    font-weight: bold;
    width: 42.5%;
}

.viewer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.viewer-controls {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

#moveInfo {
    font-weight: bold;
    color: gold;
    min-width: 100px;
    text-align: center;
}

/* CONTENEDOR DEL TABLERO DE HISTORIAL */
.history-board,
.viewer-container .board {
    width: min(85vw, 420px) !important;
    height: min(85vw, 420px) !important;
    margin: 15px auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr) !important;
    grid-template-rows: repeat(8, 1fr) !important;
    gap: 0 !important;
    padding: 0 !important;
    border: 3px solid #271512;
    background: #3e2723;
    border-radius: 4px;
    box-sizing: border-box;
}

/* CASILLAS DEL TABLERO UNIDAS */
.square {
    width: 100% !important;
    height: 100% !important;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.square.light {
    background: #f0d9b5;
}

.square.dark {
    background: #b58863;
}

.history-piece,
.square .piece {
    width: 75% !important;
    height: 75% !important;
    font-size: clamp(14px, 4vw, 24px) !important;
}

.history-piece.red,
.square .piece.red {
    background: radial-gradient(circle at 35% 35%, #ff4d6d 10%, #dc143c 60%, #80001d 100%);
    box-shadow: 0 2px 0 #9a0f28, 0 3px 0 #780a1e, 0 4px 5px rgba(0, 0, 0, 0.6);
}

.history-piece.black,
.square .piece.black {
    background: radial-gradient(circle at 35% 35%, #444 10%, #151515 60%, #050505 100%);
    box-shadow: 0 2px 0 #0d0d0d, 0 3px 0 #080808, 0 4px 5px rgba(0, 0, 0, 0.7);
}

.empty-state {
    text-align: center;
    color: #777;
    padding: 40px;
    font-style: italic;
}

/* ==========================================================================
   5. PÁGINA DE INICIO DE SESIÓN (login.html)
   ========================================================================== */
body.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
    background: #2b2b2b;
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 0 25px rgba(0, 0, 0, .5);
}

.login-container .logo {
    text-align: center;
    font-size: 42px;
    color: gold;
    margin-bottom: 10px;
}

.login-container h1 {
    text-align: center;
    color: white;
    margin-bottom: 10px;
}

.input-group {
    margin-bottom: 18px;
}

.input-group label {
    display: block;
    color: #ddd;
    margin-bottom: 6px;
    font-size: 14px;
}

.input-group input {
    width: 100%;
    padding: 12px;
    background: #1a1a1a;
    color: white;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 15px;
}

.input-group input:focus {
    outline: none;
    border-color: gold;
}

.remember {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ccc;
    margin-bottom: 20px;
    font-size: 14px;
}

.btn-login {
    width: 100%;
    padding: 12px;
    border: none;
    background: #007bff;
    color: white;
    font-size: 16px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: .3s;
}

.btn-login:hover {
    background: #0056b3;
}

.btn-login:disabled {
    background: #555;
    cursor: not-allowed;
}

.links {
    margin-top: 20px;
    text-align: center;
    color: #ccc;
    font-size: 14px;
}

.links a {
    color: gold;
    text-decoration: none;
    font-weight: bold;
}

.links a:hover {
    text-decoration: underline;
}

.footer {
    margin-top: 25px;
    text-align: center;
    color: #777;
    font-size: 12px;
}

@media(max-width: 500px) {
    .login-container {
        padding: 25px;
    }

    .login-container h1 {
        font-size: 24px;
    }
}

/* ==========================================================================
   6. PÁGINA DE REGISTRO DE USUARIOS (register.html)
   ========================================================================== */
body.register-page {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.register-container {
    width: 100%;
    max-width: 450px;
    background: #2b2b2b;
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 0 25px rgba(0, 0, 0, .5);
}

.register-container .logo {
    text-align: center;
    color: gold;
    font-size: 32px;
    margin-bottom: 10px;
}

.register-container h1 {
    text-align: center;
    color: white;
    margin-bottom: 25px;
    font-size: 28px;
}

.btn-register {
    width: 100%;
    padding: 12px;
    border: none;
    background: #28a745;
    color: white;
    font-size: 16px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: .3s;
}

.btn-register:hover {
    background: #218838;
}

.btn-register:disabled {
    background: #555;
    cursor: not-allowed;
}

.login-link {
    margin-top: 20px;
    text-align: center;
    color: #ccc;
}

.login-link a {
    color: gold;
    text-decoration: none;
    font-weight: bold;
}

.login-link a:hover {
    text-decoration: underline;
}

@media(max-width: 500px) {
    .register-container {
        padding: 25px;
    }

    .register-container h1 {
        font-size: 24px;
    }
}