/* =================================================================
   AGGRESSIVE MOBILE OPTIMIZATION FOR GAME PAGE
   Maximize board visibility by minimizing UI chrome
   ================================================================= */

/* ============== MOBILE PORTRAIT - GAME PAGE ============== */
@media (max-width: 768px) and (orientation: portrait) {
    
    /* ========== HIDE LARGE GAME TITLE ========== */
    /* The big "vs Player AI Mini" heading that wastes space */
    body[data-page="game"] > h1,
    body[data-page="game"] > h2,
    .container > h1,
    .container > h2 {
        display: none !important;
    }
    
    /* Keep only the game-status section visible */
    .game-area ~ h1,
    .game-area ~ h2,
    h1:not(.header h1):not(.game-status h1),
    h2:not(.header h2):not(.game-status h2) {
        font-size: 0 !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }
    
    /* ========== HEADER: Compact but readable ========== */
    body[data-page="game"] .header,
    .header {
        padding: 8px 12px !important;
        min-height: 48px;
    }
    
    body[data-page="game"] .header h1,
    .header h1 {
        font-size: 16px !important;
        margin: 0 !important;
        line-height: 1.3;
    }
    
    body[data-page="game"] .header .user-info,
    .header .user-info {
        font-size: 12px !important;
        gap: 6px !important;
    }
    
    body[data-page="game"] .header .user-info .btn,
    .header .user-info .btn {
        padding: 6px 10px !important;
        font-size: 12px !important;
        min-height: 32px !important;
    }
    
    /* ========== GAME AREA: Vertical stack ========== */
    .game-area {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        height: auto !important;
        min-height: 100vh !important;
    }
    
    /* ========== SIDEBAR: Compact controls at top with flex wrap ========== */
    .game-sidebar {
        width: 100% !important;
        order: 1 !important;
        padding: 8px !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
        background: rgba(255, 255, 255, 0.05) !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    /* Status section on left - narrower */
    .game-status {
        flex: 0 0 calc(40% - 4px) !important;
        padding: 6px 8px !important;
        margin: 0 !important;
        text-align: left !important;
        background: rgba(255, 255, 255, 0.08) !important;
        border-radius: 6px;
        box-sizing: border-box;
    }
    
    /* Hide or minimize the large game title */
    .game-status h2 {
        font-size: 15px !important;
        margin: 0 0 4px 0 !important;
        padding: 0 !important;
        line-height: 1.2 !important;
        font-weight: 600 !important;
    }
    
    .game-status h3 {
        font-size: 14px !important;
        margin: 0 0 3px 0 !important;
        padding: 0 !important;
        line-height: 1.3 !important;
    }
    
    .game-status p {
        font-size: 13px !important;
        margin: 2px 0 !important;
        line-height: 1.4 !important;
    }
    
    /* ========== PLAYER LIST: On right side - wider ========== */
    .player-list {
        flex: 0 0 calc(60% - 4px) !important;
        margin: 0 !important;
        padding: 6px 8px !important;
        background: rgba(255, 255, 255, 0.08) !important;
        border-radius: 6px;
        box-sizing: border-box;
    }
    
    .player-list h3 {
        font-size: 13px !important;
        margin: 0 0 4px 0 !important;
        padding: 0 !important;
        font-weight: 600 !important;
    }
    
    .player-item {
        padding: 4px 8px !important;
        margin-bottom: 3px !important;
        font-size: 13px !important;
        line-height: 1.4 !important;
        border-radius: 4px;
    }
    
    .player-item.current {
        background: rgba(76, 175, 80, 0.2) !important;
        border-left: 3px solid #4CAF50;
    }
    
    /* ========== CONTROLS: Full width below, single row ========== */
    .game-controls {
        flex: 0 0 100% !important;
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
        margin: 0 !important;
    }
    
    .game-controls .btn {
        flex: 1 !important;
        padding: 10px 6px !important;
        font-size: 12px !important;
        min-height: 44px !important;
        white-space: nowrap !important;
        border-radius: 6px;
    }
    
    /* ========== BOARD: Maximize space ========== */
    .game-main {
        order: 2 !important;
        width: 100% !important;
        flex: 1 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: flex-start !important;
        padding: 8px 0 !important;
        overflow: visible !important;
    }
    
    .hex-board {
        margin: 0 auto !important;
        transform-origin: top center;
    }
    
    /* ========== RESPONSIVE BOARD SIZING ========== */
    /* Small phones (iPhone SE) */
    @media (max-width: 375px) {
        .hex-board {
            transform: scale(0.58) !important;
        }
    }
    
    /* Standard phones (iPhone 12/13/14) */
    @media (min-width: 376px) and (max-width: 414px) {
        .hex-board {
            transform: scale(0.65) !important;
        }
    }
    
    /* Large phones (iPhone Plus) */
    @media (min-width: 415px) and (max-width: 768px) {
        .hex-board {
            transform: scale(0.72) !important;
        }
    }
}

/* ============== MOBILE LANDSCAPE - GAME PAGE ============== */
@media (max-width: 768px) and (orientation: landscape) {
    
    /* Side-by-side layout */
    .game-area {
        display: flex !important;
        flex-direction: row !important;
        height: 100vh !important;
        overflow: hidden !important;
    }
    
    /* Narrow sidebar on left */
    .game-sidebar {
        width: 160px !important;
        min-width: 160px !important;
        max-width: 160px !important;
        order: 1 !important;
        padding: 4px 6px !important;
        gap: 3px !important;
        border-right: 1px solid rgba(255, 255, 255, 0.2) !important;
        border-bottom: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }
    
    .game-status {
        padding: 3px 6px !important;
        margin-bottom: 2px !important;
    }
    
    .game-status h2,
    .game-status h3 {
        font-size: 10px !important;
        margin: 0 0 1px 0 !important;
    }
    
    .game-status p {
        font-size: 9px !important;
        margin: 0 !important;
    }
    
    .player-list h3 {
        font-size: 10px !important;
        margin: 0 0 2px 0 !important;
    }
    
    .player-item {
        padding: 2px 4px !important;
        margin-bottom: 1px !important;
        font-size: 9px !important;
    }
    
    .game-controls {
        flex-direction: column !important;
        gap: 2px !important;
    }
    
    .game-controls .btn {
        padding: 6px 4px !important;
        font-size: 9px !important;
        min-height: 32px !important;
    }
    
    /* Board takes remaining space */
    .game-main {
        order: 2 !important;
        flex: 1 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 8px !important;
        overflow: auto !important;
    }
    
    .hex-board {
        transform: scale(0.62) !important;
        margin: 10px auto !important;
    }
    
    /* Extra small landscape screens */
    @media (max-height: 450px) {
        .game-sidebar {
            width: 140px !important;
            min-width: 140px !important;
        }
        
        .hex-board {
            transform: scale(0.52) !important;
        }
    }
}

/* ============== TOUCH IMPROVEMENTS ============== */
@media (max-width: 768px) {
    
    /* Better tap targets */
    .hex-cell {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    }
    
    .hex-cell:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    /* Prevent text selection during gameplay */
    .game-area .hex-cell,
    .game-area .piece,
    .game-area .hex-content {
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
    }
    
    /* Smooth scrolling */
    .game-sidebar {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Button active states */
    .btn:active {
        transform: scale(0.97);
        transition: transform 0.1s ease;
    }
}