/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3498db;
    --primary-hover: #2980b9;
    --danger-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --bg-color: #1a1a2e;
    --surface-color: #16213e;
    --text-color: #eaeaea;
    --text-muted: #a0a0a0;
    --border-color: #0f3460;
    --cell-unrevealed: #4a5568;
    --cell-revealed: #2d3748;
    --cell-hover: #5a6a7d;
    --cell-mine: #e74c3c;
    --cell-flag: #f39c12;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-color) 0%, var(--surface-color) 100%);
    color: var(--text-color);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--primary-color), #9b59b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 10px rgba(52, 152, 219, 0.3);
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Game Controls */
.game-controls {
    background: var(--surface-color);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 600px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.9rem;
}

select, input[type="number"] {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
}

select:focus, input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

input[type="number"] {
    width: 70px;
}

.custom-settings {
    display: none;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    width: 100%;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.custom-settings.visible {
    display: flex;
}

/* Buttons */
.btn {
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #2980b9);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-flag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    color: var(--text-color);
}

.btn-flag.active {
    background: var(--warning-color);
    border-color: var(--warning-color);
    color: #1a1a2e;
}

.btn-flag:hover {
    border-color: var(--warning-color);
}

.flag-icon {
    font-size: 1.1rem;
}

.flag-status {
    font-size: 0.75rem;
    font-weight: bold;
}

/* Game Info */
.game-info {
    display: flex;
    gap: 20px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-color);
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 1.2rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.info-icon {
    font-size: 1.3rem;
}

/* Game Status */
.game-status {
    font-size: 1.5rem;
    font-weight: bold;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-status.win {
    color: var(--success-color);
    animation: pulse 0.5s ease-in-out;
}

.game-status.lose {
    color: var(--danger-color);
    animation: shake 0.5s ease-in-out;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* Game Board */
.game-board-container {
    overflow-x: auto;
    max-width: 100%;
    padding: 10px;
}

.game-board {
    display: grid;
    gap: 2px;
    background: var(--border-color);
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.cell {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.cell.unrevealed {
    background: linear-gradient(145deg, #5a6a7d, #4a5568);
    box-shadow: inset 1px 1px 2px rgba(255,255,255,0.1),
                inset -1px -1px 2px rgba(0,0,0,0.2);
}

.cell.unrevealed:hover {
    background: linear-gradient(145deg, #6a7a8d, #5a6a78);
}

.cell.revealed {
    background: var(--cell-revealed);
}

.cell.mine {
    background: var(--cell-mine);
}

.cell.mine-clicked {
    background: #c0392b;
    animation: explode 0.3s ease-out;
}

@keyframes explode {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.cell.flagged {
    background: linear-gradient(145deg, #5a6a7d, #4a5568);
}

.cell.flagged::after {
    content: '🚩';
    font-size: 1rem;
}

/* Number colors */
.cell[data-number="1"] { color: #3498db; }
.cell[data-number="2"] { color: #27ae60; }
.cell[data-number="3"] { color: #e74c3c; }
.cell[data-number="4"] { color: #9b59b6; }
.cell[data-number="5"] { color: #e67e22; }
.cell[data-number="6"] { color: #1abc9c; }
.cell[data-number="7"] { color: #34495e; }
.cell[data-number="8"] { color: #7f8c8d; }

/* Instructions */
.instructions {
    background: var(--surface-color);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    max-width: 500px;
    width: 100%;
    margin-top: 10px;
}

.instructions h3 {
    color: var(--primary-color);
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.instructions ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.instructions li {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.instructions li strong {
    color: var(--text-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
    border-top: 1px solid var(--border-color);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

footer a:hover {
    color: #9b59b6;
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 2rem;
    }

    .game-controls {
        padding: 15px;
    }

    .control-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    select, input[type="number"] {
        width: 100%;
    }

    .cell {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }

    .info-item {
        padding: 8px 14px;
        font-size: 1rem;
    }

    .game-status {
        font-size: 1.2rem;
    }

    .instructions {
        padding: 15px;
    }

    .instructions h3 {
        font-size: 1rem;
    }

    .instructions li {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .cell {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }

    .game-info {
        gap: 10px;
    }

    .info-item {
        padding: 6px 10px;
        font-size: 0.9rem;
    }

    .btn-flag {
        padding: 6px 12px;
    }

    .flag-icon {
        font-size: 1rem;
    }
}

/* Touch device improvements */
@media (hover: none) {
    .cell.unrevealed:hover {
        background: linear-gradient(145deg, #5a6a7d, #4a5568);
    }

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