/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary, #3498db);
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
    font-size: 14px;
    border-radius: 0 0 4px 0;
}
.skip-link:focus {
    top: 0;
}

:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --primary-light: #5dade2;
    --bg-dark: #0f0f23;
    --bg-darker: #0a0a16;
    --surface: #1a1a2e;
    --surface-light: #2d2d4a;
    --border: #404059;
    --text: #ffffff;
    --text-secondary: #b0b0cc;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;

    /* Number colors */
    --num-1: #3498db;
    --num-2: #27ae60;
    --num-3: #e74c3c;
    --num-4: #8e44ad;
    --num-5: #c0392b;
    --num-6: #16a085;
    --num-7: #2c3e50;
    --num-8: #7f8c8d;

    --transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
    --glass: rgba(255, 255, 255, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-light);
}

/* Selection */
::selection {
    background: var(--primary);
    color: var(--bg-dark);
}

/* Utilities */
.hidden {
    display: none !important;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

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

header h1 {
    font-size: clamp(28px, 8vw, 48px);
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Ad Containers */
.ad-container {
    margin: 20px auto;
    padding: 10px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-top {
    margin-top: 0;
}

.ad-bottom {
    margin-bottom: 20px;
}

/* Sound Toggle */
.sound-toggle {
    position: fixed;
    top: 20px;
    right: 80px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
    color: var(--primary);
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle:hover {
    background: var(--primary);
    color: var(--bg-dark);
    border-color: var(--primary);
}

.sound-toggle:active {
    transform: scale(0.95);
}

/* Language Selector */
.language-selector {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.lang-toggle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
    color: var(--primary);
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.lang-toggle:hover {
    background: var(--primary);
    color: var(--bg-dark);
    border-color: var(--primary);
}

.lang-toggle:active {
    transform: scale(0.95);
}

.lang-menu {
    position: absolute;
    top: 60px;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    min-width: 180px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.lang-menu.hidden {
    display: none;
}

.lang-option {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
}

.lang-option:hover {
    background: var(--primary);
    color: var(--bg-dark);
}

.lang-option.active {
    background: var(--primary);
    color: var(--bg-dark);
    font-weight: 600;
}

/* Difficulty Menu */
.difficulty-menu {
    text-align: center;
    margin-bottom: 40px;
}

.difficulty-menu h2 {
    font-size: 28px;
    margin-bottom: 30px;
    color: var(--text);
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.difficulty-btn {
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--surface), var(--surface-light));
    border: 2px solid var(--border);
    border-radius: 16px;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.difficulty-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary);
    opacity: 0.1;
    transition: var(--transition);
    z-index: -1;
}

.difficulty-btn:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: var(--shadow-sm);
}

.difficulty-btn:hover::before {
    left: 0;
}

.difficulty-btn:active {
    transform: translateY(-2px);
}

.difficulty-name {
    font-weight: 600;
    font-size: 18px;
    margin-bottom: 8px;
}

.difficulty-info {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Game Interface */
.game-interface {
    transition: opacity 0.3s ease;
}

.game-interface.hidden {
    display: none;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: var(--surface);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    font-family: 'Monaco', 'Courier New', monospace;
}

.new-game-btn {
    padding: 12px 30px;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: var(--bg-dark);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
}

.new-game-btn:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

.new-game-btn:active {
    transform: scale(0.98);
}

/* Game Board */
.game-board-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 40px;
}

.game-board {
    display: inline-grid;
    gap: 4px;
    padding: 20px;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

/* Game Cells */
.cell {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--surface-light), var(--surface));
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    transition: var(--transition);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--primary);
    opacity: 0;
    transition: var(--transition);
    z-index: -1;
}

.cell:not(.opened):not(.flagged):hover {
    border-color: var(--primary);
    transform: scale(1.05);
}

.cell:not(.opened):not(.flagged):active {
    transform: scale(0.98);
}

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

.cell.opened.empty {
    background: var(--bg-darker);
}

.cell.opened.num-1 { color: var(--num-1); }
.cell.opened.num-2 { color: var(--num-2); }
.cell.opened.num-3 { color: var(--num-3); }
.cell.opened.num-4 { color: var(--num-4); }
.cell.opened.num-5 { color: var(--num-5); }
.cell.opened.num-6 { color: var(--num-6); }
.cell.opened.num-7 { color: var(--num-7); }
.cell.opened.num-8 { color: var(--num-8); }

.cell.flagged {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: var(--text);
    font-size: 20px;
}

.cell.mine {
    background: #c0392b;
    color: var(--text);
    font-size: 20px;
}

.cell.mine.revealed {
    animation: explode 0.4s ease;
}

@keyframes explode {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@keyframes popIn {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.cell.opened {
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    padding: 40px;
    border-radius: 16px;
    border: 1px solid var(--border);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-content h2 {
    font-size: 28px;
    margin-bottom: 16px;
    text-align: center;
}

.modal-content p {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 16px;
}

.stats-display {
    background: var(--bg-dark);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    color: var(--text);
}

.stat-row:not(:last-child) {
    border-bottom: 1px solid var(--border);
}

.stat-row span:last-child {
    font-weight: 600;
    color: var(--primary);
    font-family: 'Monaco', 'Courier New', monospace;
}

/* Leaderboard */
.leaderboard-section {
    background: var(--bg-darker);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.leaderboard-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--text);
}

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--surface);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.difficulty-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    background: var(--primary);
    color: var(--bg-dark);
    border-radius: 12px;
}

.best-time {
    font-weight: 600;
    color: var(--primary);
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 18px;
}

/* Modal Buttons */
.modal-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
}

.btn-primary {
    background: var(--primary);
    color: var(--bg-dark);
}

.btn-primary:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--primary);
    color: var(--bg-dark);
    border-color: var(--primary);
}

.btn-secondary:active {
    transform: scale(0.98);
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.confetti {
    position: fixed;
    pointer-events: none;
}

@keyframes confettiFall {
    to {
        transform: translateY(100vh) rotateZ(360deg);
        opacity: 0;
    }
}

/* Accessibility */
button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.cell:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    header h1 {
        margin-bottom: 16px;
    }

    .game-header {
        gap: 12px;
        padding: 16px;
        flex-wrap: wrap;
    }

    .stat {
        flex: 1;
        min-width: 80px;
    }

    .new-game-btn {
        padding: 10px 20px;
        font-size: 14px;
        flex: 1;
    }

    .difficulty-buttons {
        gap: 12px;
        grid-template-columns: 1fr;
    }

    .cell {
        width: 40px;
        height: 40px;
        font-size: 14px;
        border-radius: 3px;
    }

    .game-board {
        gap: 3px;
        padding: 12px;
    }

    .modal-content {
        padding: 24px;
        width: 95%;
    }

    .modal-buttons {
        grid-template-columns: 1fr;
    }

    .sound-toggle {
        right: 70px;
        width: 40px;
        height: 40px;
    }

    .lang-toggle {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 12px;
    }

    header {
        margin-top: 60px;
        margin-bottom: 20px;
    }

    header h1 {
        font-size: 24px;
    }

    .subtitle {
        font-size: 14px;
    }

    .difficulty-menu h2 {
        font-size: 22px;
        margin-bottom: 20px;
    }

    .difficulty-btn {
        padding: 20px 12px;
    }

    .cell {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }

    .game-board {
        gap: 2px;
        padding: 8px;
    }

    .stat-value {
        font-size: 24px;
    }

    .modal-content {
        padding: 16px;
    }

    .modal-content h2 {
        font-size: 22px;
    }

    .modal-content p {
        font-size: 14px;
    }

    .sound-toggle,
    .lang-toggle {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .sound-toggle {
        right: 50px;
    }
}

/* Force dark mode regardless of system preference */
:root {
    color-scheme: dark;
}

/* App Loader */
.app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.app-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.app-loader::after {
    content: '💣';
    font-size: 48px;
    animation: loaderPulse 1s ease-in-out infinite;
}
@keyframes loaderPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* Light Mode */
[data-theme="light"] {
    --bg-dark: #f5f5fa;
    --bg-darker: #ffffff;
    --surface: #ffffff;
    --surface-light: #f8f8fc;
    --border: #e0e0e8;
    --text: #1a1a2e;
    --text-secondary: #5a5a70;
}

[data-theme="light"] body {
    background: linear-gradient(135deg, #f5f5fa 0%, #e8e8f0 100%);
}

[data-theme="light"] .app-loader {
    background: var(--bg-dark);
}

[data-theme="light"] .lang-menu {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .lang-option {
    color: var(--text);
}

[data-theme="light"] .lang-option:hover {
    background: rgba(52, 152, 219, 0.1);
}

[data-theme="light"] .difficulty-menu,
[data-theme="light"] .game-over-modal {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .difficulty-btn {
    background: rgba(52, 152, 219, 0.05);
    border-color: rgba(52, 152, 219, 0.15);
}

[data-theme="light"] .difficulty-btn:hover {
    background: rgba(52, 152, 219, 0.1);
}

[data-theme="light"] .cell {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .cell.revealed {
    background: var(--surface-light);
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 56px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

.theme-toggle:active {
    transform: scale(0.95);
}

[data-theme="light"] .theme-toggle {
    background: rgba(52, 152, 219, 0.1);
    border-color: rgba(52, 152, 219, 0.2);
    color: var(--text);
}

[data-theme="light"] .theme-toggle:hover {
    background: rgba(52, 152, 219, 0.15);
}

/* Keyboard focus indicator for cells */
.cell:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
    z-index: 1;
}

/* Keyboard shortcut hints */
.keyboard-hints {
    display: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 14px;
    margin-bottom: 12px;
    font-size: 11px;
    color: var(--text-secondary);
}
@media (min-width: 768px) {
    .keyboard-hints { display: flex; }
}
.kbd-hint { white-space: nowrap; }
.kbd-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--glass);
    font-family: inherit;
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-secondary);
}

/* Accessibility: reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
