* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

:root {
    --primary: #3a86ff;
    --primary-dark: #2667cc;
    --secondary: #8338ec;
    --danger: #ff006e;
    --success: #06d6a0;
    --light: #f8f9fa;
    --dark: #212529;
    --cell-bg: #e9ecef;
    --cell-revealed: #f8f9fa;
    --board-bg: #adb5bd;
    --text: #212529;
}

body {
    background-color: var(--light);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease;
    color: var(--text);
}

h1 {
    margin: 20px 0;
    color: var(--primary);
    font-size: 2.5rem;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    background: white;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.1);
}

.controls {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    gap: 15px;
}

.difficulty {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background-color: var(--primary);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

button:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

button:active {
    transform: translateY(0);
}

button.active {
    background-color: var(--secondary);
}

.stats {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary);
}

.board {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: 2px;
    width: 100%;
    max-width: 100%;
    background-color: var(--board-bg);
    border: 3px solid var(--board-bg);
    border-radius: 8px;
    margin-bottom: 25px;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.1);
    overflow: auto;
}

.cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--cell-bg);
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
    border-radius: 3px;
    min-width: 24px;
    min-height: 24px;
}

.cell:hover {
    filter: brightness(0.95);
}

.cell:active {
    transform: scale(0.95);
}

.cell.revealed {
    background-color: var(--cell-revealed);
    cursor: default;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.05);
}

.cell.mine.revealed {
    background-color: var(--danger);
    animation: pulse 0.5s ease;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.cell.flagged::after {
    content: '🚩';
    position: absolute;
    font-size: 1.1rem;
    animation: flagIn 0.3s ease;
}

@keyframes flagIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.cell.mine.flagged.revealed::after {
    content: '💣';
    animation: none;
}

.cell.mine.flagged:not(.revealed)::after {
    content: '🚩';
}

.cell.mine:not(.flagged)::after {
    content: '💣';
    position: absolute;
}

.cell-1 { color: #3a86ff; }
.cell-2 { color: #06d6a0; }
.cell-3 { color: #ff006e; }
.cell-4 { color: #8338ec; }
.cell-5 { color: #ffbe0b; }
.cell-6 { color: #fb5607; }
.cell-7 { color: #212529; }
.cell-8 { color: #6c757d; }

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: white;
    font-size: 2rem;
    text-align: center;
    backdrop-filter: blur(5px);
}

.game-over h2 {
    font-size: 3rem;
    margin-bottom: 20px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.game-over button {
    margin-top: 20px;
    padding: 12px 24px;
    font-size: 1.2rem;
    background: var(--primary);
    border-radius: 12px;
}

.game-over button:hover {
    background: var(--primary-dark);
}

.hidden {
    display: none;
}

.instructions {
    margin-top: 25px;
    padding: 20px;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-width: 500px;
    border: 1px solid rgba(0,0,0,0.05);
}

.instructions h2 {
    margin-bottom: 15px;
    color: var(--primary);
    font-size: 1.5rem;
}

.instructions p {
    margin-bottom: 10px;
    color: var(--text);
    line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --light: #212529;
        --dark: #f8f9fa;
        --cell-bg: #343a40;
        --cell-revealed: #495057;
        --board-bg: #6c757d;
        --text: #f8f9fa;
    }

    body {
        background-color: #121212;
    }

    .game-container, .instructions {
        background-color: #2b2b2b;
        box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    }
}

@media (min-width: 600px) {
    .cell {
        font-size: 1.2rem;
        min-width: 28px;
        min-height: 28px;
    }
    
    .game-container {
        padding: 20px;
        max-width: 90vw;
    }
}

@media (min-width: 768px) {
    .cell {
        font-size: 1.3rem;
        min-width: 32px;
        min-height: 32px;
    }
}

@media (max-width: 400px) {
    .controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .difficulty {
        justify-content: space-between;
        width: 100%;
    }
    
    button {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .stats {
        font-size: 1rem;
    }
}
