/* --- CONTENEDOR PRINCIPAL --- */
.pardos-board {
    width: 320px;
    margin: 0 auto;
    background-color: #A1887F; /* Café medio */
    border-radius: 12px;
    padding: 15px;
    position: relative;
    box-shadow: 0 10px 25px rgba(62, 39, 35, 0.3);
    user-select: none; /* Evita seleccionar texto al jugar */
}

/* --- HEADER (Score y Reset) --- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.score-box {
    background: #5D4037;
    color: #fff;
    padding: 5px 15px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.score-box span {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #D7CCC8;
}

.score-box strong {
    font-size: 1.4rem;
}

.reset-btn {
    background: #8D6E63;
    border: none;
    color: white;
    width: 40px; height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
}
.reset-btn:hover { background: #6D4C41; }

/* --- EL TABLERO DE JUEGO --- */
.grid-container {
    width: 290px;
    height: 290px;
    background: #8D6E63;
    border-radius: 8px;
    position: relative;
    padding: 10px;
    
    /* Grid estático para el fondo */
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    
    /* Touch actions para evitar scroll del navegador */
    touch-action: none;
}

/* Celdas vacías (fondo) */
.grid-cell {
    width: 100%;
    height: 100%;
    background: rgba(239, 235, 233, 0.2);
    border-radius: 6px;
}

/* --- CAPA DE FICHAS (TILES) --- */
.tile-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    padding: 10px; /* Mismo padding que grid-container */
    box-sizing: border-box;
    pointer-events: none; /* Dejar pasar los clics al fondo */
}

.tile {
    position: absolute;
    width: 57.5px; /* (290 - 20padding - 30gap) / 4 */
    height: 57.5px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: bold;
    transition: transform 0.15s ease-in-out;
    z-index: 10;
}

/* Animación al aparecer */
.tile-new {
    animation: pop 0.2s ease;
}
@keyframes pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* --- CÁLCULO DE POSICIONES (Matemáticas CSS) --- */
/* Cada celda mide aprox 57.5px + 10px de gap = 67.5px de paso */
/* Fila 0 */
.tile-position-0-0 { transform: translate(0px, 0px); }
.tile-position-0-1 { transform: translate(67.5px, 0px); }
.tile-position-0-2 { transform: translate(135px, 0px); }
.tile-position-0-3 { transform: translate(202.5px, 0px); }

/* Fila 1 */
.tile-position-1-0 { transform: translate(0px, 67.5px); }
.tile-position-1-1 { transform: translate(67.5px, 67.5px); }
.tile-position-1-2 { transform: translate(135px, 67.5px); }
.tile-position-1-3 { transform: translate(202.5px, 67.5px); }

/* Fila 2 */
.tile-position-2-0 { transform: translate(0px, 135px); }
.tile-position-2-1 { transform: translate(67.5px, 135px); }
.tile-position-2-2 { transform: translate(135px, 135px); }
.tile-position-2-3 { transform: translate(202.5px, 135px); }

/* Fila 3 */
.tile-position-3-0 { transform: translate(0px, 202.5px); }
.tile-position-3-1 { transform: translate(67.5px, 202.5px); }
.tile-position-3-2 { transform: translate(135px, 202.5px); }
.tile-position-3-3 { transform: translate(202.5px, 202.5px); }


/* --- GAME OVER OVERLAY --- */
.game-over-overlay {
    display: none; /* Oculto por defecto */
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
    border-radius: 8px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.5s;
    pointer-events: auto; /* Reactivar clicks aquí */
}

.game-over-overlay h3 {
    color: #3E2723;
    font-size: 1.8rem;
    margin-bottom: 20px;
}

.try-again-btn {
    background: #3E2723;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 30px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.try-again-btn:hover { background: #5D4037; }

/* Responsive móvil */
@media (max-width: 400px) {
    .pardos-board { width: 280px; padding: 10px; }
    .grid-container { width: 260px; height: 260px; gap: 8px; }
    /* Ajustar cálculos para móvil si es necesario, o usar transform scale en el padre */
    .tile { width: 51px; height: 51px; font-size: 1.4rem; }
    
    /* Recalcular positions para grid 260px (gap 8) -> celda ~59px paso */
    .tile-position-0-1 { transform: translate(59px, 0); }
    /* ... etc (Una solución mejor en móvil es usar vw/vh o scale) */
}