/* Mobile Overlay for Opponent Grid */

@media (max-width: 768px) {
    /* Hide opponent grid by default in mobile view */
    #opponent-grid {
        display: none !important; /* Use !important to override any other styles */
        height: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    /* Only when opponent grid is shown as overlay */
    #opponent-grid.show-overlay {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background-color: rgba(30, 30, 46, 0.9);
        z-index: 1000;
        padding: 10px !important;
        border-top: 2px solid var(--primary-color) !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
        flex-wrap: wrap;
        justify-content: center;
        transition: transform 0.3s ease;
        max-height: 40vh;
        min-height: auto !important;
        height: auto !important;
        overflow-y: auto !important;
        flex-direction: row;
        transform: translateY(0);
    }

    /* Canvas within opponent grid */
    #opponent-grid canvas {
        margin: 5px;
        border: 2px solid transparent;
        transition: all 0.2s ease;
    }

    #opponent-grid canvas:hover {
        transform: scale(1.05);
        border-color: var(--primary-color);
    }

    /* Close button for opponent grid overlay */
    #close-opponent-overlay {
        position: absolute;
        top: 5px;
        right: 5px;
        background-color: rgba(231, 76, 60, 0.8);
        color: white;
        border: none;
        border-radius: 50%;
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 1001;
    }

    /* Target selection indicator */
    .target-selection-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        background-color: rgba(108, 92, 231, 0.2);
        color: white;
        padding: 10px;
        text-align: center;
        z-index: 999;
        font-weight: bold;
    }

    /* Self-target button */
    #self-target-button {
        width: 100%;
        padding: 8px;
        margin: 5px 0;
        background-color: var(--secondary-color);
        color: white;
        border: none;
        border-radius: 5px;
        font-weight: bold;
        cursor: pointer;
    }

    /* Cancel button */
    #cancel-powerup-button {
        width: 100%;
        padding: 8px;
        margin: 5px 0;
        background-color: var(--error-color);
        color: white;
        border: none;
        border-radius: 5px;
        font-weight: bold;
        cursor: pointer;
    }

    /* Buttons container */
    .overlay-buttons {
        display: flex;
        width: 100%;
        justify-content: space-between;
        padding: 5px;
    }

    .overlay-buttons button {
        flex: 1;
        margin: 0 5px;
    }

    /* Show game info div with a more compact layout */
    .game-info {
        display: flex !important;
        flex-direction: column !important;
        font-size: 12px !important;
        margin: 0 8px !important;
    }
    
    /* Make game info more compact on mobile */
    .game-room-code {
        font-size: 14px !important;
        margin-bottom: 2px !important;
    }
    
    .game-details {
        font-size: 10px !important;
        display: flex !important;
        flex-wrap: wrap !important;
    }
    
    .game-details span {
        margin-right: 8px !important;
    }
    
    /* Make spectate button more compact on mobile */
    .spectate-game-btn {
        padding: 8px !important;
        min-width: 36px !important;
    }
    
    /* Hide the "Spectate" text on mobile, showing only the icon */
    .spectate-text {
        display: none !important;
    }
    
    /* Adjust join button size for mobile */
    .join-game-btn {
        padding: 8px 12px !important;
        font-size: 12px !important;
    }

    /* Optimize layout for mobile */
    #player-section {
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Take direct control of next-piece-canvas */
    #next-piece-canvas {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: fixed !important;
        top: 60px !important; /* Position at top, next to bonus pile */
        right: 10px !important;
        width: 60px !important;
        height: 60px !important;
        z-index: 1000 !important; /* Very high to ensure visibility */
        background-color: rgba(45, 45, 58, 0.95) !important;
        border-radius: 6px !important;
        box-shadow: 0 0 8px rgba(0, 0, 0, 0.8) !important;
        border: 2px solid var(--primary-color) !important;
    }

    /* Hide the left info panel container */
    .left-info-panel {
        display: none !important;
    }
    
    /* Position the main game area to take up full available space */
    .main-game-area {
        width: 100% !important;
        max-width: none !important;
        padding: 0 !important;
        margin: 0 0 70px 0 !important; /* Add bottom margin for controls */
        min-height: calc(100vh - 100px) !important;
        position: relative !important;
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
    }

    /* Position player canvas at the bottom of the screen for better mobile ergonomics */
    #player-canvas {
        position: fixed !important;
        bottom: 20px !important; /* Position above mobile controls */
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 5 !important;
        margin-top: auto !important;
        max-height: 95vh !important; /* Limit height to ensure visibility of other elements */
    }

    /* Create a controls bar at the top with flex layout (moved from bottom) */
    #bonus-pile {
        position: fixed !important;
        top: 60px !important; /* Position below header */
        left: 0 !important;
        width: 100% !important;
        padding: 8px 5px !important;
        background-color: rgba(30, 30, 46, 0.9) !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
        z-index: 10 !important;
        display: flex !important;
        align-items: center !important;
        flex-wrap: wrap !important;
    }

    /* Make the heading smaller and inline */
    #bonus-pile strong {
        font-size: 12px !important;
        margin-right: 5px !important;
        white-space: nowrap !important;
    }

    /* Make specials container inline */
    #specials-container {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        gap: 3px !important;
        padding: 0 !important;
        flex: 1 !important;
    }

    /* Make special items more compact */
    .special-item {
        width: 32px !important;
        height: 32px !important;
        flex-shrink: 0 !important;
    }

    /* Hide powerup info on mobile */
    #powerup-info {
        display: none !important;
    }

    /* Mobile Controls Overlay */
    /* ----------------------- */
    #mobile-controls {
        position: fixed !important;
        width: 100% !important;
        height: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        z-index: 900 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 20px !important;
        pointer-events: none !important;
    }

    #joystick-zone {
        position: relative !important;
        pointer-events: auto !important;
    }

    #mobile-drop-btn {
        pointer-events: auto !important;
        -webkit-tap-highlight-color: transparent !important;
        touch-action: manipulation !important;
    }

    #mobile-drop-btn:active {
        background-color: rgba(108, 92, 231, 0.9) !important;
        transform: scale(0.95) !important;
        opacity: 0.9 !important;
    }

    /* Common button styles */
    .mobile-control-btn {
        position: absolute !important;
        background-color: rgba(108, 92, 231, 0.6) !important;
        border: 2px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 50% !important;
        color: white !important;
        width: 50px !important;
        height: 50px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 24px !important;
        pointer-events: auto !important; /* Make buttons clickable */
        -webkit-tap-highlight-color: transparent !important; /* Remove tap highlight on iOS */
        user-select: none !important; /* Prevent text selection */
        touch-action: manipulation !important; /* Optimize for touch */
    }

    .mobile-control-btn:active {
        background-color: rgba(108, 92, 231, 0.9) !important;
        transform: scale(0.95) !important;
        opacity: 0.2;
    }

    /* Arrow buttons positioning */
    #mobile-left-btn {
        bottom: 100px !important;
        left: 20px !important;
    }

    #mobile-right-btn {
        bottom: 100px !important;
        left: 180px !important;
    }

    #mobile-down-btn {
        bottom: 50px !important;
        left: 100px !important;
    }

    /* Action buttons positioning - right side */
    #mobile-rotate-btn {
        bottom: 150px !important;
        right: 50px !important;
    }

    #mobile-drop-btn {
        bottom: 50px !important;
        right: 50px !important;
    }
}
