/**
 * MOBILE ENHANCEMENTS
 * ===================
 * Progressive Enhancement für Phones & kleine Tablets
 * Desktop-Styles bleiben unverändert - nur Overrides für kleine Screens
 * 
 * Breakpoints:
 * - max-width: 768px = Phones & Portrait Tablets
 * - max-width: 480px = Sehr kleine Phones
 * - orientation: portrait = Portrait-spezifische Fixes
 */

/* ===== TOUCH OPTIMIZATION ===== */
@media (max-width: 768px) {
    /* Prevent iOS zoom on form focus */
    input, select, textarea, button {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100%;
    }
    
    /* Touch-friendly minimum sizes (Apple HIG: 44px, Android: 48px) */
    button, .btn, a.btn, .nav-link {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    /* Larger tap targets for interactive elements */
    .card-action, .modal-close, .dropdown-toggle {
        padding: 12px;
        min-width: 48px;
        min-height: 48px;
    }
    
    /* Remove hover states (meaningless on touch) */
    .hover-only {
        display: none !important;
    }
    
    /* Show touch-specific elements */
    .touch-only {
        display: block !important;
    }
}

/* ===== LAYOUT ADAPTATIONS ===== */
@media (max-width: 768px) {
    /* Container spacing */
    .container, .content-wrapper {
        padding: 16px;
        margin: 0 auto;
    }
    
    /* Full-width cards on mobile */
    .card, .game-card, .profile-card {
        width: 100% !important;
        max-width: 100%;
        margin: 8px 0;
    }
    
    /* Stack columns vertically */
    .row, .grid, .flex-container {
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
    }
    
    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Scrollable tables */
    .table-container, table {
        overflow-x: auto;
        display: block;
        white-space: nowrap;
    }
    
    /* Reduce vertical spacing */
    .section {
        padding: 24px 16px;
    }
    
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.3rem; }
}

/* ===== FORMS ===== */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group label {
        font-size: 14px;
        margin-bottom: 6px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
        padding: 12px;
        font-size: 16px; /* Prevent iOS zoom */
        border-radius: 8px;
    }
    
    /* Full-width buttons */
    .form-group button,
    .form-actions button {
        width: 100%;
        margin-bottom: 8px;
    }
    
    /* Stack form buttons vertically */
    .form-actions {
        flex-direction: column;
        gap: 8px;
    }
}

/* ===== MODALS & OVERLAYS ===== */
@media (max-width: 768px) {
    .modal, .popup, .dialog {
        width: 95vw !important;
        max-width: 95vw;
        margin: 16px auto;
        padding: 20px;
    }
    
    .modal-header {
        padding: 16px;
    }
    
    .modal-body {
        padding: 16px;
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 16px;
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer button {
        width: 100%;
    }
}

/* ===== GAME SPECIFIC ===== */
@media (max-width: 768px) {
    /* Game container takes full screen */
    .game-container {
        padding: 8px;
        width: 100vw;
        margin: 0;
    }
    
    /* Body and main containers: reset margins */
    html {
        overflow-y: scroll !important;
        overflow-x: hidden !important;
        height: 100% !important;
    }
    
    body {
        margin: 0 !important;
        padding: 0 !important;
        overflow-x: hidden !important;
        overflow-y: scroll !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
        min-height: 100vh !important;
        position: relative !important;
    }
    
    .main-content, .container {
        margin: 0 !important;
        padding: 0 !important;
        padding-top: 40px !important;
        width: 100vw !important;
        overflow: visible !important;
    }
    
    /* Game area spacing */
    .game-area, .game-container, #game-area {
        padding-top: 40px !important;
    }
    
    /* Cards in game */
    .playing-card {
        width: calc(100vw - 32px) !important;
        max-width: 420px !important;
        margin: 0 auto !important;
        min-height: 545px !important;
        position: static !important;
        left: auto !important;
        right: auto !important;
        transform: none !important;
    }
    
    /* Card wrapper centering */
    .card-wrapper {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        width: 100vw !important;
        padding: 0 16px !important;
        margin: 0 !important;
        margin-top: 40px !important;
        box-sizing: border-box !important;
    }
    
    /* Card header: reduce spacing */
    .card-header {
        margin-bottom: 4px !important;
        padding-bottom: 2px !important;
    }
    
    /* Card images: 16:9 aspect ratio for mobile - full width */
    .card-image {
        aspect-ratio: 16/9 !important;
        height: auto !important;
        width: 100% !important;
        max-height: none !important;
        min-height: 200px !important;
        margin-bottom: 6px !important;
        margin-top: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }
    
    .card-image img {
        object-fit: cover !important;
        object-position: center;
        width: 100%;
        height: 100%;
        border-radius: 8px;
    }
    
    /* Card content: ensure all 6 data fields are visible */
    .card-content {
        flex: 1;
        overflow: visible !important;
        min-height: 240px !important;
    }
    
    .card-stat {
        font-size: 13px !important;
        padding: 6px 8px !important;
        margin-bottom: 4px !important;
    }
    
    /* Card back logo: larger on mobile */
    .card-back-icon {
        width: 85% !important;
        height: 85% !important;
    }
    
    /* Navbar: fix to top on mobile */
    .navbar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    /* Game controls */
    .game-controls {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.98);
        padding: 12px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        z-index: 1000;
    }
    
    /* Stats overlay */
    .game-stats {
        font-size: 14px;
        padding: 8px;
    }
    
    /* Reduce animations on mobile for performance */
    * {
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }
}

/* ===== PROFILE & USER AREA ===== */
@media (max-width: 768px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-image {
        width: 120px;
        height: 120px;
        margin: 0 auto 16px;
    }
    
    .profile-stats {
        flex-direction: column;
        gap: 8px;
    }
    
    .stat-card {
        width: 100%;
        padding: 12px;
    }
}

/* ===== LEADERBOARD / RANGLISTE ===== */
@media (max-width: 768px) {
    .leaderboard-table {
        font-size: 14px;
    }
    
    .leaderboard-row {
        padding: 8px;
    }
    
    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Compact rank display */
    .rank-badge {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
}

/* ===== TEXT & TYPOGRAPHY ===== */
@media (max-width: 768px) {
    /* Prevent text from breaking layout */
    p, span, div {
        word-break: break-word;
        overflow-wrap: break-word;
    }
    
    /* Comfortable reading width */
    .text-content {
        max-width: 100%;
        line-height: 1.6;
    }
    
    /* Adjust font sizes for readability */
    body {
        font-size: 16px;
        line-height: 1.5;
    }
}

/* ===== UTILITIES ===== */
@media (max-width: 768px) {
    /* Spacing utilities */
    .mb-mobile { margin-bottom: 16px !important; }
    .mt-mobile { margin-top: 16px !important; }
    .p-mobile { padding: 16px !important; }
    
    /* Display utilities */
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    
    /* Text alignment */
    .text-center-mobile { text-align: center !important; }
    
    /* Full width utility */
    .full-width-mobile {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ===== SMALL PHONES (<= 480px) ===== */
@media (max-width: 480px) {
    /* Further reduce spacing */
    .container {
        padding: 12px;
    }
    
    /* Even larger touch targets */
    button, .btn {
        min-height: 48px;
        font-size: 16px;
    }
    
    /* Smaller headings */
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.1rem; }
    
    /* Compact navigation */
    .nav-brand {
        font-size: 1.2rem;
    }
    
    /* Reduce card padding */
    .card {
        padding: 12px;
    }
}

/* ===== PORTRAIT SPECIFIC ===== */
@media (max-width: 768px) and (orientation: portrait) {
    /* Maximize vertical space */
    .game-container {
        min-height: 100vh;
    }
    
    /* Stack game elements */
    .game-layout {
        flex-direction: column;
    }
    
    /* Compact header in portrait */
    .navbar {
        padding: 8px 16px;
    }
}

/* ===== LANDSCAPE PHONES ===== */
@media (max-width: 768px) and (orientation: landscape) {
    /* Use horizontal space efficiently */
    .game-controls {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 200px;
        flex-direction: column;
    }
    
    /* Side-by-side layout when possible */
    .form-group {
        display: inline-block;
        width: 48%;
        margin-right: 2%;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (max-width: 768px) {
    /* Ensure focus indicators are visible */
    button:focus,
    a:focus,
    input:focus {
        outline: 2px solid #1976d2;
        outline-offset: 2px;
    }
    
    /* Increase contrast for readability */
    .text-muted {
        opacity: 0.8;
        color: #555;
    }
}

/* ===== PERFORMANCE ===== */
@media (max-width: 768px) {
    /* Disable expensive effects */
    .blur-effect {
        backdrop-filter: none !important;
        background: rgba(255, 255, 255, 0.95) !important;
    }
    
    /* Simplify shadows */
    .card, .modal {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Reduce parallax/3D effects */
    .parallax,
    .transform-3d {
        transform: none !important;
    }
}

/* ===== SAFE AREA (iPhone Notch, etc.) ===== */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        body {
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
            padding-bottom: max(0px, env(safe-area-inset-bottom));
        }
        
        .navbar {
            padding-top: max(8px, env(safe-area-inset-top));
        }
        
        .game-controls {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}
