/**
 * Mobile Button Enhancements
 * Improves touch targets, feedback, and reliability for mobile game buttons
 * 
 * Add this to your mobile.css or include separately
 */

/* =================================================================
   MOBILE BUTTON FIXES
   ================================================================= */

/* Ensure buttons are not blocked by other elements */
@media (max-width: 768px) {
    .btn,
    button {
        position: relative;
        z-index: 10; /* Ensure buttons are above other elements */
        cursor: pointer;
        
        /* Improve touch target size */
        min-height: 44px; /* iOS recommended minimum touch target */
        min-width: 44px;
        
        /* Better touch interaction */
        touch-action: manipulation; /* Disable double-tap zoom */
        -webkit-tap-highlight-color: transparent; /* Remove iOS tap highlight */
        user-select: none; /* Prevent text selection on press */
        -webkit-user-select: none;
        
        /* Ensure button remains interactive */
        pointer-events: auto !important;
    }
    
    /* Active state for visual feedback */
    .btn:active,
    button:active,
    .btn.btn-active,
    button.btn-active {
        transform: scale(0.96);
        opacity: 0.8;
        transition: all 0.1s ease;
    }
    
    /* Specific game control buttons */
    .game-controls {
        position: relative;
        z-index: 10;
        
        /* Ensure flexbox doesn't break touch */
        display: flex;
        flex-direction: row;
        gap: 8px;
    }
    
    .game-controls .btn {
        flex: 1;
        padding: 12px 8px;
        font-size: 12px;
        white-space: nowrap;
        
        /* Ensure no overflow issues */
        overflow: visible;
        
        /* Better spacing for touch */
        margin: 2px;
    }
    
    /* Resign button - make it very clear */
    .btn-danger {
        background: #dc3545;
        border-color: #dc3545;
        font-weight: bold;
    }
    
    .btn-danger:active,
    .btn-danger.btn-active {
        background: #c82333;
        border-color: #bd2130;
    }
    
    /* Secondary buttons (Demo, Back to Lobby) */
    .btn-secondary {
        background: #6c757d;
        border-color: #6c757d;
    }
    
    .btn-secondary:active,
    .btn-secondary.btn-active {
        background: #5a6268;
        border-color: #545b62;
    }
    
    /* Disabled state - clear visual indication */
    .btn:disabled,
    button:disabled {
        opacity: 0.5;
        cursor: not-allowed;
        pointer-events: none;
    }
    
    /* Prevent sidebar from blocking buttons */
    .game-sidebar {
        position: relative;
        z-index: 5; /* Lower than buttons */
        overflow: visible; /* Don't clip buttons */
    }
    
    /* Ensure button container doesn't clip */
    .game-controls,
    .player-list {
        overflow: visible;
    }
}

/* Portrait-specific button adjustments */
@media (max-width: 768px) and (orientation: portrait) {
    .game-controls .btn {
        padding: 14px 10px; /* Slightly larger for portrait */
        font-size: 13px;
    }
}

/* Landscape-specific button adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .game-controls .btn {
        padding: 10px 6px; /* More compact for landscape */
        font-size: 11px;
    }
    
    /* Tighter spacing in landscape */
    .game-controls {
        gap: 4px;
    }
}

/* Fix for iOS Safari specific issues */
@supports (-webkit-touch-callout: none) {
    /* iOS-specific fixes */
    @media (max-width: 768px) {
        .btn,
        button {
            -webkit-appearance: none; /* Remove iOS button styling */
            -webkit-touch-callout: none; /* Disable callout on long press */
        }
        
        /* Fix iOS button padding */
        .btn::-moz-focus-inner,
        button::-moz-focus-inner {
            border: 0;
            padding: 0;
        }
    }
}

/* Hover state for devices that support it (not touch-only) */
@media (hover: hover) and (max-width: 768px) {
    .btn:hover,
    button:hover {
        opacity: 0.9;
        transform: scale(1.02);
        transition: all 0.2s ease;
    }
}

/* Focus state for accessibility */
@media (max-width: 768px) {
    .btn:focus,
    button:focus {
        outline: 2px solid rgba(255, 255, 255, 0.5);
        outline-offset: 2px;
    }
    
    /* Remove focus outline when using touch */
    .btn:focus:not(:focus-visible),
    button:focus:not(:focus-visible) {
        outline: none;
    }
}

/* Loading state */
@media (max-width: 768px) {
    .btn.loading,
    button.loading {
        position: relative;
        color: transparent;
        pointer-events: none;
    }
    
    .btn.loading::after,
    button.loading::after {
        content: "...";
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        color: white;
        font-size: 18px;
        animation: loadingDots 1.4s infinite;
    }
}

@keyframes loadingDots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

/* Ripple effect for touch feedback */
@media (max-width: 768px) {
    .btn {
        overflow: hidden;
        position: relative;
    }
    
    .btn::before {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.3);
        transform: translate(-50%, -50%);
        transition: width 0.6s, height 0.6s;
    }
    
    .btn:active::before,
    .btn.btn-active::before {
        width: 300px;
        height: 300px;
    }
}

/* Prevent accidental text selection around buttons */
@media (max-width: 768px) {
    .game-controls,
    .game-sidebar {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Fix for button text wrapping */
@media (max-width: 768px) {
    .btn,
    button {
        text-overflow: ellipsis;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
}

/* Ensure buttons are visible on all backgrounds */
@media (max-width: 768px) {
    .btn,
    button {
        border: 1px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
    
    .btn:active,
    button:active,
    .btn.btn-active,
    button.btn-active {
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }
}