/* Responsive Design for Mobile Minesweeper - Refactored */

/* CSS Custom Properties for Cell Sizes */
:root {
    /* Default cell sizes */
    --cell-size-8x8: 44px;
    --cell-size-10x10: 35px;
    --cell-size-12x12: 28px;
    
    /* Font sizes */
    --font-size-8x8: 1.2rem;
    --font-size-10x10: 1rem;
    --font-size-12x12: 0.9rem;
    
    /* Game board settings */
    --board-padding: 8px;
    --board-gap: 2px;
    --board-radius: 16px;
}

/* =================================
   BASE GRID STYLES - EDGE TO EDGE FOR ALL DEVICES
   ================================= */

/* Grid-specific cell sizes - applies to all screen sizes */
.game-board[style*="--grid-cols: 8"] .cell {
    min-width: var(--cell-size-8x8);
    min-height: var(--cell-size-8x8);
    font-size: var(--font-size-8x8);
}

.game-board[style*="--grid-cols: 10"] .cell {
    min-width: var(--cell-size-10x10);
    min-height: var(--cell-size-10x10);
    font-size: var(--font-size-10x10);
}

.game-board[style*="--grid-cols: 12"] .cell {
    min-width: var(--cell-size-12x12);
    min-height: var(--cell-size-12x12);
    font-size: var(--font-size-12x12);
}

/* Game board container base styles - EDGE TO EDGE FOR ALL */
.game-board {
    padding: 0;
    border-radius: 0;
    gap: 1px;
    width: 100%;
    max-width: 100%;
}

/* All containers edge to edge */
.container {
    width: 100%;
    margin: 0;
    padding: 20px 0;
    border-radius: 0;
}

.game-board-container {
    padding: 0 5px;
}

/* =================================
   MOBILE PORTRAIT (iPhone 15 Pro optimized)
   ================================= */

@media screen and (min-width: 390px) and (max-width: 430px) and (min-height: 844px) and (max-height: 932px) {
    .container {
        padding: 8px 0;
        border-radius: 0;
        min-height: calc(100vh - 32px);
    }
    
    .game-title {
        font-size: 1.8rem;
        margin-bottom: 8px;
    }
    
    .game-header {
        margin-bottom: 16px;
    }
    
    .stats-row {
        margin-bottom: 16px;
        padding: 0 8px;
    }
    
    .mine-counter, .timer {
        font-size: 1.3rem;
        padding: 8px 12px;
        min-width: 52px;
        border-radius: 12px;
    }
    
    .new-game-btn {
        width: 56px;
        height: 56px;
        border-radius: 28px;
    }
    
    .game-face {
        font-size: 1.6rem;
    }
    
    .controls-row {
        gap: 12px;
        margin-bottom: 4px;
    }
    
    .difficulty-btn {
        padding: 12px 8px;
        font-size: 0.9rem;
        min-height: 48px;
        border-radius: 12px;
        font-weight: 700;
    }
    
    .flag-mode-btn {
        padding: 12px 16px;
        border-radius: 12px;
        min-height: 48px;
        gap: 8px;
    }
    
    .flag-icon {
        font-size: 1.1rem;
    }
    
    .flag-mode-text {
        font-size: 0.9rem;
        font-weight: 600;
    }
    
    .game-board-container {
        margin-bottom: 20px;
    }
    
    .game-board {
        max-height: calc(100vh - 220px);
        min-height: 400px;
        width: 100%;
        max-width: 100%;
    }
    
    .cell {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.1rem;
        font-weight: 700;
        border-radius: 6px;
        transition: all 0.15s ease;
    }
    
    .help-btn {
        width: 26px;
        height: 26px;
        font-size: 1rem;
    }
    
    .version-info {
        bottom: 20px;
        left: 20px;
        font-size: 0.75rem;
    }
    
    .message-content {
        padding: 40px 24px;
        border-radius: 20px;
        max-width: 320px;
    }
    
    .message-text {
        font-size: 1.4rem;
        margin-bottom: 20px;
    }
    
    .message-btn {
        padding: 14px 28px;
        font-size: 1rem;
        border-radius: 14px;
        min-height: 48px;
    }
    
    .modal-content {
        margin: 60px 20px;
        border-radius: 20px;
        max-height: calc(100vh - 120px);
    }
    
    .modal-header {
        padding: 24px 24px 16px;
    }
    
    .modal-body {
        padding: 0 24px 24px;
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    .modal-close {
        width: 36px;
        height: 36px;
        font-size: 1.8rem;
        border-radius: 18px;
    }
}

/* =================================
   SMALL MOBILE DEVICES
   ================================= */

@media screen and (max-width: 480px) {
    :root {
        --cell-size-8x8: 40px;
        --cell-size-10x10: 32px;
        --cell-size-12x12: 26px;
        --font-size-8x8: 1rem;
        --font-size-10x10: 0.9rem;
        --font-size-12x12: 0.8rem;
    }
    
    .container {
        padding: 15px;
        border-radius: 15px;
        min-height: calc(100vh - 30px);
    }
    
    .game-title {
        font-size: 1.5rem;
    }
    
    .stats-row {
        margin-bottom: 12px;
    }
    
    .mine-counter, .timer {
        font-size: 1.2rem;
        padding: 6px 10px;
        min-width: 45px;
    }
    
    .new-game-btn {
        width: 50px;
        height: 50px;
    }
    
    .game-face {
        font-size: 1.5rem;
    }
    
    .difficulty-btn {
        padding: 8px 6px;
        font-size: 0.8rem;
    }
    
    .flag-mode-btn {
        padding: 8px 12px;
    }
    
    .flag-mode-text {
        font-size: 0.8rem;
    }
    
    .cell {
        min-width: 38px;
        min-height: 38px;
        font-size: 0.9rem;
    }
    
    .help-btn {
        width: 22px;
        height: 22px;
        font-size: 0.8rem;
    }
    
    .message-content {
        padding: 30px 20px;
    }
    
    .message-text {
        font-size: 1.3rem;
    }
}

/* =================================
   EXTRA SMALL DEVICES
   ================================= */

@media screen and (max-width: 360px) {
    :root {
        --cell-size-8x8: 35px;
        --cell-size-10x10: 28px;
        --cell-size-12x12: 23px;
        --font-size-8x8: 0.9rem;
        --font-size-10x10: 0.8rem;
        --font-size-12x12: 0.7rem;
    }
    
    .container {
        padding: 10px;
    }
    
    .game-title {
        font-size: 1.3rem;
    }
    
    .mine-counter, .timer {
        font-size: 1.1rem;
        padding: 5px 8px;
    }
    
    .new-game-btn {
        width: 45px;
        height: 45px;
    }
    
    .game-face {
        font-size: 1.3rem;
    }
    
    .difficulty-btn {
        padding: 6px 4px;
        font-size: 0.75rem;
    }
    
    .flag-mode-btn {
        padding: 6px 10px;
    }
    
    .flag-icon {
        font-size: 1rem;
    }
    
    .flag-mode-text {
        font-size: 0.75rem;
    }
    
    .cell {
        min-width: 35px;
        min-height: 35px;
        font-size: 0.8rem;
    }
    
    .game-board {
        padding: 8px;
        gap: 1px;
    }
}

/* =================================
   TABLET AND LARGER SCREENS
   ================================= */

@media screen and (min-width: 481px) and (max-width: 768px) {
    .container {
        max-width: 500px;
        padding: 25px;
    }
    
    .cell {
        min-width: 45px;
        min-height: 45px;
        font-size: 1.1rem;
    }
    
    .game-board {
        max-height: 60vh;
    }
}

@media screen and (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 600px;
    }
    
    .cell {
        min-width: 50px;
        min-height: 50px;
        font-size: 1.2rem;
    }
    
    .game-board {
        max-height: 65vh;
    }
}

/* =================================
   PORTRAIT ORIENTATION
   ================================= */

@media screen and (orientation: portrait) {
    .game-board {
        max-height: 70vh;
    }
    
    @media screen and (min-height: 800px) {
        .game-board {
            max-height: 65vh;
        }
    }
}

/* =================================
   GRID SIZE CONSTRAINTS - ALL EDGE TO EDGE
   ================================= */

.game-board[style*="--grid-cols: 8"] {
    max-width: 100%;
}

.game-board[style*="--grid-cols: 10"] {
    max-width: 100%;
}

.game-board[style*="--grid-cols: 12"] {
    max-width: 100%;
}

/* =================================
   DEVICE SPECIFIC OPTIMIZATIONS
   ================================= */

/* High DPI displays */
@media screen and (-webkit-min-device-pixel-ratio: 2), 
       screen and (min-resolution: 192dpi) {
    .cell {
        border-width: 1px;
    }
    
    .new-game-btn {
        border-width: 2px;
    }
    
    .difficulty-btn,
    .flag-mode-btn {
        border-width: 1px;
    }
}

/* Dynamic viewport units for better mobile support */
@supports (height: 100dvh) {
    body {
        min-height: 100dvh;
    }
    
    .container {
        min-height: calc(100dvh - 40px);
    }
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
    .container {
        padding-left: 0;
        padding-right: 0;
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* =================================
   ACCESSIBILITY & PREFERENCES
   ================================= */

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .cell.touched {
        transform: none;
    }
    
    .new-game-btn:hover {
        transform: none;
    }
    
    .help-btn:hover {
        transform: none;
    }
    
    .message-btn:hover {
        transform: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .container {
        border: 2px solid var(--black);
    }
    
    .game-board {
        border: 2px solid var(--black);
    }
    
    .cell {
        border-width: 2px;
    }
    
    .difficulty-btn,
    .flag-mode-btn,
    .new-game-btn {
        border-width: 2px;
    }
}

 