/* Reseteo básico o normalize.css iría en css/reset.css */

/* Variables CSS para colores (Modo Claro por defecto) */
:root {
    --bg-color: #f0f0f0;
    --text-color: #333;
    --header-footer-bg: #eee;
    --main-bg: #fff;
    --border-color: #ccc;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --modal-bg: #fefefe;
    --modal-border: #888;
    --input-border: #ccc;
    --input-bg: #f9f9f9;
    --button-bg: #007bff;
    --button-hover-bg: #0056b3;
    --cell-unrevealed-bg: #ccc;
    --cell-unrevealed-hover-bg: #b3b3b3;
    --cell-revealed-bg: #eee;
    --cell-revealed-border: #ddd;
    --cell-border-unrevealed: #999;
    --cell-border-revealed: #ddd;
    --table-header-bg: #eee;
    --table-border: #ddd;
    --error-color: #ff0000;
    --board-cols: 8;
    --board-rows: 8;
}

/* Modo Oscuro */
body.dark-mode {
    --bg-color: #1a1a1a;
    --text-color: #f0f0f0;
    --header-footer-bg: #2a2a2a;
    --main-bg: #3a3a3a;
    --border-color: #555;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --modal-bg: #4a4a4a;
    --modal-border: #666;
    --input-border: #666;
    --input-bg: #333;
    --button-bg: #0056b3;
    --button-hover-bg: #003d80;
    --cell-unrevealed-bg: #555;
    --cell-unrevealed-hover-bg: #666;
    --cell-revealed-bg: #444;
    --cell-revealed-border: #555;
    --cell-border-unrevealed: #333;
    --cell-border-revealed: #555;
    --table-header-bg: #4a4a4a;
    --table-border: #555;
    --error-color: #ff6666;
}


/* Selectores de Elementos */
body {
    font-family: "Silkscreen", sans-serif;
    font-weight: 400;
    font-style: normal;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: var(--bg-color); 
    color: var(--text-color); 
    transition: background-color 0.3s ease, color 0.3s ease; 
}

header {
    width: 100%;
    text-align: center;
    padding: 20px 0;
    background-color: var(--header-footer-bg); 
    position: relative; 
    transition: background-color 0.3s ease;
    display: flex; 
    flex-direction: column; 
    align-items: center;
    justify-content: center;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background-color: var(--main-bg); 
    border-radius: 8px;
    box-shadow: 0 0 10px var(--shadow-color); 
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    width: 100%;
    max-width: 900px;
    box-sizing: border-box;
}

footer {
    width: 100%;
    text-align: center;
    padding: 15px 0;
    margin-top: 30px;
    background-color: var(--header-footer-bg); 
    font-size: 0.9rem;
    transition: background-color 0.3s ease;
}

nav ul {
    list-style: none;
    padding: 0;
    display: flex;
    justify-content: center;
    gap: 20px;
}

nav a {
    text-decoration: none;
    color: var(--button-bg); 
    transition: color 0.3s ease;
}
nav a:hover {
    color: var(--button-hover-bg); 
}


/* Selectores de Clases */
.modal {
    display: flex;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--shadow-color); 
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--modal-bg); 
    padding: 20px;
    border: 1px solid var(--modal-border); 
    color: var(--text-color);
    width: 80%;
    max-width: 400px;
    text-align: center;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* ESTILO CLAVE PARA LOS RADIO BUTTONS Y SUS ETIQUETAS */
#difficulty-selection label,
#scoreboard-difficulty-selection label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
    margin-bottom: 5px;
    padding: 5px 0;
}

#difficulty-selection input[type="radio"],
#scoreboard-difficulty-selection input[type="radio"] {
    -webkit-appearance: radio;
    -moz-appearance: radio;
    appearance: radio;
    width: 18px;
    height: 18px;
    margin-right: 8px;
    vertical-align: middle;
    cursor: pointer;
}


.modal-content input[type="text"] {
    padding: 8px;
    border: 1px solid var(--input-border); 
    border-radius: 4px;
    width: 80%;
    margin: 0 auto;
    background-color: var(--input-bg); 
    color: var(--text-color); 
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.modal-content button,
#dark-mode-toggle {
    background-color: var(--button-bg); 
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.modal-content button:hover,
#dark-mode-toggle:hover {
    background-color: var(--button-hover-bg); 
}

.error-message {
    color: var(--error-color); 
    margin-top: 10px;
}

/* Selectores de ID */
#game-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 0;
    border-bottom: 1px solid var(--header-footer-bg); 
    color: var(--text-color); 
    transition: border-color 0.3s ease, color 0.3s ease;
}

#mine-counter,
#timer {
    font-size: 1.2rem;
    font-weight: bold;
}

#new-game-button {
    font-size: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    color: var(--text-color); 
    transition: color 0.3s ease;
}

/* CAMBIO: Se reeemplaza GRID por FLEXBOX para el tablero */
#board-container {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1 / 1;
    box-shadow: inset 0 0 5px var(--shadow-color);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
    border: 1px solid var(--text-color);
}

/* Estilos para la selección de dificultad (para el juego) */
#difficulty-selection {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
    padding: 10px;
    border: 1px solid var(--border-color); 
    border-radius: 5px;
    background-color: var(--input-bg); 
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

#difficulty-selection p {
    font-weight: bold;
    margin-bottom: 5px;
    text-align: center;
}


/* CAMBIO: Se ajusta el estilo de las celdas para que funcionen con flexbox y tengan borde */
.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--cell-unrevealed-bg);
    cursor: pointer;
    font-weight: bold;
    font-size: clamp(0.8rem, 3vw, 1.2rem);
    transition: background-color 0.1s ease, border-color 0.1s ease;
    
    border: 1px solid var(--cell-border-unrevealed);
    
    width: calc(100% / var(--board-cols));
    height: calc(100% / var(--board-rows));
    box-sizing: border-box;
}

.cell:hover:not(.revealed) {
    background-color: var(--cell-unrevealed-hover-bg); 
}

.cell.revealed {
    background-color: var(--cell-revealed-bg);
    cursor: default;
    border-color: var(--cell-border-revealed);
}

/* Nuevos estilos para los iconos */
.cell.mine::before {
    content: "💥";
}

.cell.flagged::before {
    content: "🚩";
}


/* Números de minas vecinas con colores (estos colores suelen ser fijos por convención) */
.cell.number-1 { color: blue; }
.cell.number-2 { color: green; }
.cell.number-3 { color: red; }
.cell.number-4 { color: darkblue; }
.cell.number-5 { color: darkred; }
.cell.number-6 { color: teal; }
.cell.number-7 { color: black; }
.cell.number-8 { color: gray; }

/* Posicionamiento del botón de modo oscuro en header */
header #dark-mode-toggle {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    padding: 8px 12px;
    font-size: 0.9rem;
}


/* Media Queries al final */
@media (max-width: 768px) {
    h1 {
        font-size: 2rem;
    }


    .modal-content {
        width: 90%;
    }

    /* En pantallas pequeñas, apilar el juego y el scoreboard */
    #game-and-scoreboard-wrapper {
        flex-direction: column;
        align-items: center;
    }

    #game-content,
    #scoreboard-container {
        max-width: 100%;
        flex: none;
    }
    /* En pantallas pequeñas, el botón de modo oscuro se vuelve estático */
    header #dark-mode-toggle {
        position: static; 
        transform: none; 
        margin-top: 10px; 
        margin-bottom: 10px;
    }
}


/*SCOREBOARD*/
#game-and-scoreboard-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    width: 100%;
    flex-wrap: wrap;
}

/* Contenedor del juego para que tome ancho adecuado dentro del wrapper */
#game-content {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 300px;
    box-sizing: border-box;
}


#scoreboard-container {
    flex: 1;
    padding: 15px;
    border: 1px solid var(--border-color); 
    border-radius: 8px;
    background-color: var(--main-bg); 
    min-width: 200px;
    max-width: 300px;
    box-shadow: 0 2px 5px var(--shadow-color); 
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}


/* Estilos para la nueva selección de dificultad del scoreboard */
#scoreboard-difficulty-selection {
    display: flex;
    justify-content: center;
    flex-direction: row;
    gap: 5px;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px solid var(--border-color); 
    border-radius: 5px;
    background-color: var(--input-bg); 
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

#scores-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#scores-table th,
#scores-table td {
    border: 1px solid var(--table-border); 
    padding: 8px;
    text-align: left;
    transition: border-color 0.3s ease;
}

#scores-table th {
    background-color: var(--table-header-bg); 
    transition: background-color 0.3s ease;
}