:root {
    --cell-size: 30px; 
    --background-color: #f4f4f4;
    --board-color: #ccc;
    --unopened-color: #b0b0b0;
    --opened-color: #d7d7d7;
    --flag-color: #ff4500; 
    --mine-color: #000;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: var(--background-color);
    margin: 20px;
    color: #333;
}

h1 {
    color: #007bff; 
    margin-bottom: 15px;
}

#controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: min(90%, 800px);
    margin-bottom: 20px;
    padding: 10px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.stat {
    font-size: 1.2em;
    font-weight: bold;
}

#reset-button {
    padding: 10px 20px;
    font-size: 1em;
    cursor: pointer;
    background-color: #28a745; 
    color: white;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

#reset-button:hover {
    background-color: #218838;
}

/* --- Bàn Cờ --- */
#board {
    display: inline-grid;
    border: 5px solid var(--board-color);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 1px solid var(--board-color);
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    background-color: var(--unopened-color);
    user-select: none;
    transition: background-color 0.1s;
}

.cell.unopened:hover {
    background-color: #c0c0c0;
}

.cell.opened {
    background-color: var(--opened-color);
    border: 1px solid #999;
    cursor: default;
}

.cell.flag {
    color: var(--flag-color);
    font-size: 1.2em;
}

.cell.mine {
    background-color: var(--mine-color);
    color: white;
}

/* Các màu số */
.n1 { color: blue; }
.n2 { color: green; }
.n3 { color: red; }
.n4 { color: darkblue; }
.n5 { color: darkred; }
.n6 { color: teal; }
.n7 { color: black; }
.n8 { color: gray; }

#game-message {
    margin-top: 20px;
    font-size: 1.5em;
    font-weight: bold;
    text-align: center;
}

/* --- CSS Cho Modal Popup --- */
.modal {
    display: none; 
    position: fixed;
    z-index: 10;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6); 
}

.modal-content {
    background-color: #fff;
    margin: 15% auto; 
    padding: 30px;
    border: 1px solid #888;
    width: 80%;
    max-width: 400px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.5s;
}

h2 {
    color: #28a745; 
    font-size: 2em;
    margin-bottom: 10px;
}

.result-time {
    font-size: 1.5em;
    margin: 15px 0;
    font-weight: bold;
    color: #333;
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-button {
    padding: 10px 20px;
    font-size: 1.1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.primary {
    background-color: #28a745;
    color: white;
    border: none;
}

.secondary {
    background-color: #007bff;
    color: white;
    border: none;
}

.primary:hover { background-color: #218838; }
.secondary:hover { background-color: #0056b3; }

@keyframes fadeIn {
    from {opacity: 0;}
    to {opacity: 1;}
}


@media (max-width: 900px) {
    :root {
        --cell-size: 20px; 
    }
    
    #board-container {
        width: 100%;
        overflow-x: auto; 
    }

    #controls {
        flex-direction: column; 
        gap: 10px;
        width: 95%;
    }

    .stat, #reset-button {
        width: 100%;
        text-align: center;
    }

    .modal-content {
        margin: 5% auto;
        width: 90%;
    }
}