/* ============================================
   MOBILE PLAY SCREEN - CHESS.COM STYLE REDESIGN
   ============================================ */

/* Only apply on mobile devices */
@media (max-width: 768px) {
    
    /* ============================================
       GAME SCREEN CONTAINER
       ============================================ */
    
    #game-screen.active {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 50%, #1a1a1a 100%) !important;
        box-sizing: border-box !important;
    }
    
    /* ============================================
       TOP NAVIGATION BAR (Play/Archive/User)
       ============================================ */
    
    #game-screen .menu-sidebar {
        width: 100vw !important;
        height: auto !important;
        min-height: 50px !important;
        max-height: none !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: auto !important;
        flex-direction: row !important;
        padding: 0.75rem 1rem !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        z-index: 99999 !important;
        background: rgba(20, 20, 20, 0.98) !important;
        backdrop-filter: blur(10px) !important;
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        transform: none !important;
        pointer-events: auto !important;
        align-items: center !important;
        gap: 0.5rem !important;
    }
    
    #game-screen .menu-sidebar > a {
        flex-shrink: 0 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        white-space: nowrap !important;
        border-left: none !important;
        text-align: center !important;
        width: auto !important;
        min-width: auto !important;
    }
    
    #game-screen .menu-sidebar > div {
        margin-top: 0 !important;
        padding: 0 !important;
        border-top: none !important;
        display: flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
        margin-left: auto !important;
        flex-shrink: 0 !important;
        width: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    #game-screen .menu-sidebar > div > div {
        margin-bottom: 0 !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        color: white !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    #game-screen .menu-sidebar > div > button {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        width: auto !important;
        min-width: auto !important;
    }
    
    /* ============================================
       GAME WRAPPER - MAIN CONTENT AREA
       ============================================ */
    
    #game-screen .game-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100vh - 50px) !important;
        max-height: calc(100vh - 50px) !important;
        padding: 0 !important;
        margin: 0 !important;
        margin-top: 50px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: transparent !important;
    }
    
    #game-screen .game-header-top {
        display: none !important;
    }
    
    /* ============================================
       GAME CONTENT WRAPPER - NO SCROLLING
       ============================================ */
    
    #game-screen .game-content-wrapper {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow: hidden !important; /* NO SCROLLING */
        display: flex !important;
        flex-direction: column !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        background: transparent !important;
    }
    
    /* ============================================
       GAME CONTENT - FLEX CONTAINER - NO SCROLLING
       ============================================ */
    
    #game-screen .game-content {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow: hidden !important; /* NO SCROLLING */
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        position: relative !important;
        background: transparent !important;
    }
    
    /* Hide evaluation bar on mobile */
    #game-screen .evaluation-bar-container {
        display: none !important;
    }
    
    /* ============================================
       MOVE LIST - AT THE TOP, HORIZONTALLY SCROLLABLE
       ============================================ */
    
    /* Override board.css move-list-container height */
    #game-screen .move-list-container,
    #game-screen .game-content .move-list-container {
        order: 1 !important;
        flex: 0 0 auto !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important; /* Override board.css 350px */
        min-height: 0 !important; /* Override board.css 350px */
        max-height: none !important; /* Override board.css */
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        background: rgba(38, 36, 33, 0.95) !important; /* Dark gray matching TechChess */
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        overflow: visible !important; /* Allow content to be visible */
        position: relative !important;
        display: flex !important;
        flex-direction: column !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* HIDE "MOVES" HEADER TEXT */
    #game-screen .move-list-header {
        display: none !important;
    }
    
    /* Move list - horizontally scrollable line */
    /* Override ALL conflicting styles from board.css and main.css */
    #game-screen .move-list-container .move-list,
    #game-screen #move-list,
    #game-screen .move-list {
        flex: 0 0 auto !important;
        min-height: 0 !important;
        height: 55px !important; /* Increased height to prevent text cutoff */
        max-height: 55px !important; /* Override board.css */
        padding: 1rem 1rem 0.75rem 1rem !important; /* More top padding to move text down */
        overflow-y: hidden !important; /* NO vertical scrolling - override board.css */
        overflow-x: auto !important; /* HORIZONTAL scrolling */
        width: 100% !important;
        box-sizing: border-box !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 0 !important;
        white-space: nowrap !important; /* NO WRAPPING - override board.css normal */
        word-wrap: normal !important;
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
        color: rgba(255, 255, 255, 0.9) !important;
        background: rgba(38, 36, 33, 0.95) !important;
        display: block !important; /* Changed from flex to block for proper horizontal scrolling */
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Move notation styling - horizontal layout, no wrapping */
    /* Override board.css conflicting rules */
    #game-screen .move-list .move-row,
    #game-screen .move-row {
        display: inline-block !important;
        white-space: nowrap !important; /* Override board.css normal */
        margin-right: 0.5rem !important;
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
    }
    
    #game-screen .move-list .move-number,
    #game-screen .move-number {
        display: inline !important;
        white-space: nowrap !important;
        margin-right: 0.25rem !important;
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
        color: rgba(255, 255, 255, 0.7) !important;
    }
    
    #game-screen .move-list .move-item,
    #game-screen .move-item {
        padding: 0 !important;
        min-height: auto !important;
        font-size: 0.75rem !important;
        display: inline !important;
        width: auto !important;
        box-sizing: border-box !important;
        margin: 0 0.25rem 0 0 !important;
        text-align: left !important;
        white-space: nowrap !important; /* NO WRAPPING - override board.css */
        line-height: 1.4 !important;
        color: rgba(255, 255, 255, 0.9) !important;
    }
    
    #game-screen .move-item .piece-symbol {
        display: inline !important;
        white-space: nowrap !important;
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
    }
    
    #game-screen .move-item .move-notation {
        display: inline !important;
        white-space: nowrap !important;
        padding: 0 !important;
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
    }
    
    /* Hide best move and current player info on mobile */
    #game-screen .best-move-display,
    #game-screen .current-player-info {
        display: none !important;
    }
    
    /* ============================================
       CHESS BOARD - IN THE MIDDLE, SPACED FROM MOVES
       ============================================ */
    
    /* Override all conflicting board styles */
    #game-screen .game-content .game-board-container,
    #game-screen .game-board-container {
        order: 2 !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.25rem !important; /* Reduced padding */
        margin: 0 !important;
        margin-top: 0 !important; /* NO gap - board touches moves box */
        margin-bottom: 0.5rem !important; /* Small space before material count */
        box-sizing: border-box !important;
        display: flex !important;
        justify-content: center !important;
        align-items: flex-start !important; /* Align to top to raise board */
        background: transparent !important;
        overflow: visible !important; /* Allow board to be visible */
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Override board.css chess-board styles */
    /* CRITICAL: Board must use display: grid for squares to show */
    /* Size board to fill available space - account for reduced padding */
    #game-screen .game-board-container .chess-board,
    #game-screen .game-content .chess-board,
    #game-screen #chess-board,
    #game-screen .chess-board {
        /* Size to the smaller of: container width or available height */
        /* Account for: sidebar (50px) + moves (50px) + buttons (140px) + margins (1rem) */
        width: min(calc(100vw - 0.5rem), calc(100vh - 50px - 50px - 140px - 1rem)) !important;
        max-width: min(calc(100vw - 0.5rem), calc(100vh - 50px - 50px - 140px - 1rem)) !important;
        height: min(calc(100vw - 0.5rem), calc(100vh - 50px - 50px - 140px - 1rem)) !important;
        max-height: min(calc(100vw - 0.5rem), calc(100vh - 50px - 50px - 140px - 1rem)) !important;
        /* Make it square */
        aspect-ratio: 1 / 1 !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: 0 auto !important;
        padding: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        box-sizing: border-box !important;
        display: grid !important; /* MUST be grid for squares to display */
        grid-template-columns: repeat(8, 1fr) !important;
        grid-template-rows: repeat(8, 1fr) !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Ensure chess squares are visible */
    #game-screen .chess-board .chess-square {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* ============================================
       MATERIAL COUNT AND BUTTONS - AT THE BOTTOM
       ============================================ */
    
    /* Material count and buttons container - positioned fixed at bottom */
    #game-screen .move-list-container .captured-pieces-container {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 100 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0.75rem 1rem !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        background: rgba(38, 36, 33, 0.95) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        margin: 0 !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Also target it directly */
    #game-screen .captured-pieces-container {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 100 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0.75rem 1rem !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        background: rgba(38, 36, 33, 0.95) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        margin: 0 !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Material count wrapper - both black and white on same line */
    #game-screen .captured-pieces-container {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
    
    /* Material counts - both on same line (order: 1) */
    #game-screen .captured-pieces-container .captured-pieces {
        order: 1 !important;
        flex: 0 0 auto !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0.5rem !important;
        min-width: 0 !important;
        max-width: 50% !important;
        overflow: hidden !important;
    }
    
    #game-screen .captured-pieces-container .captured-pieces.captured-black {
        order: 1 !important;
    }
    
    #game-screen .captured-pieces-container .captured-pieces.captured-white {
        order: 1 !important;
        margin-left: 1rem !important;
    }
    
    #game-screen .captured-pieces-list {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 2px !important;
        flex-wrap: wrap !important;
    }
    
    #game-screen .captured-piece-img {
        width: 16px !important;
        height: 16px !important;
        flex-shrink: 0 !important;
    }
    
    #game-screen .captured-count {
        font-size: 0.8rem !important;
        margin: 0 0.25rem !important;
        color: rgba(255, 255, 255, 0.9) !important;
        font-weight: 500 !important;
    }
    
    /* Action buttons - below material count (hint, resign, flip, takeback) */
    #game-screen .captured-pieces-container .game-action-buttons {
        order: 2 !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 0.75rem !important;
        width: 100% !important;
        flex-shrink: 0 !important;
        padding: 0.5rem 0 !important;
    }
    
    /* SHOW takeback button on mobile */
    #game-screen #takeback-btn {
        display: flex !important;
    }
    
    /* Action button styling */
    #game-screen .action-btn {
        min-width: 50px !important;
        min-height: 50px !important;
        width: 50px !important;
        height: 50px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255, 255, 255, 0.1) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        border-radius: 8px !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        flex-shrink: 0 !important;
        touch-action: manipulation !important;
    }
    
    #game-screen .action-btn:hover {
        background: rgba(255, 255, 255, 0.15) !important;
        border-color: rgba(255, 255, 255, 0.3) !important;
    }
    
    #game-screen .action-btn:active {
        background: rgba(255, 255, 255, 0.2) !important;
        transform: scale(0.95) !important;
    }
    
    #game-screen .action-btn:disabled {
        opacity: 0.5 !important;
        cursor: not-allowed !important;
    }
    
    #game-screen .action-btn svg,
    #game-screen .action-btn img {
        width: 24px !important;
        height: 24px !important;
        color: rgba(255, 255, 255, 0.9) !important;
    }
    
    /* Resign button - red tint */
    #game-screen #resign-btn {
        background: rgba(255, 0, 0, 0.15) !important;
        border-color: rgba(255, 0, 0, 0.3) !important;
    }
    
    #game-screen #resign-btn:hover {
        background: rgba(255, 0, 0, 0.25) !important;
        border-color: rgba(255, 0, 0, 0.4) !important;
    }
    
    /* ============================================
       GAME STATUS - HIDDEN ON MOBILE
       ============================================ */
    
    #game-screen .game-status {
        display: none !important;
    }
    
    /* ============================================
       SCROLLING BEHAVIOR - ONLY HORIZONTAL FOR MOVES
       ============================================ */
    
    /* Horizontal scrollbar styling for move list */
    #game-screen .move-list::-webkit-scrollbar {
        height: 4px !important;
        width: auto !important;
    }
    
    #game-screen .move-list::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.1) !important;
    }
    
    #game-screen .move-list::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2) !important;
        border-radius: 2px !important;
    }
    
    #game-screen .move-list::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.3) !important;
    }
    
}

/* ============================================
   SMALLER MOBILE DEVICES (480px and below)
   ============================================ */

@media (max-width: 480px) {
    
    /* Smaller padding and font sizes */
    #game-screen .move-list-header {
        display: none !important; /* Still hidden */
    }
    
    #game-screen .move-list {
        padding: 0.6rem 0.75rem !important;
        font-size: 0.7rem !important;
        height: 45px !important; /* Fixed height */
    }
    
    #game-screen .move-row,
    #game-screen .move-number,
    #game-screen .move-item,
    #game-screen .move-item .piece-symbol,
    #game-screen .move-item .move-notation {
        font-size: 0.7rem !important;
    }
    
    #game-screen .captured-pieces-container {
        padding: 0.6rem 0.75rem !important;
        gap: 0.6rem !important;
    }
    
    #game-screen .captured-piece-img {
        width: 14px !important;
        height: 14px !important;
    }
    
    #game-screen .captured-count {
        font-size: 0.75rem !important;
    }
    
    #game-screen .action-btn {
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
    }
    
    #game-screen .action-btn svg,
    #game-screen .action-btn img {
        width: 20px !important;
        height: 20px !important;
    }
    
    #game-screen .game-board-container {
        padding: 0.25rem !important;
    }
}

