/* Responsive Fixes for Mobile and Desktop */

/* Override existing grid responsiveness */
@media (max-width: 1200px) {
    .drama-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)) !important;
        gap: 1.5rem !important;
        padding: 1rem !important;
    }
}

@media (max-width: 768px) {
    /* Player page body mobile - ensure proper layout */
    .player-page {
        display: flex !important;
        flex-direction: column !important;
        min-height: 100vh !important;
        overflow-x: hidden !important;
    }
    
    /* Header fixes for mobile */
    .header {
        padding: 0.8rem 1rem !important;
    }
    
    .header-content {
        flex-direction: row !important;
        gap: 1rem !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    .logo {
        font-size: 1.5rem !important;
    }
    
    .search-container {
        flex-direction: row !important;
        width: auto !important;
        flex: 1 !important;
        max-width: 300px !important;
    }
    
    .search-box {
        width: 100% !important;
        max-width: 300px !important;
        flex: 1 !important;
    }
    
    /* Banner ads mobile - UNIVERSAL MOBILE BANNER RULES */
    .banner-ads {
        padding: 0.5rem !important;
        margin-top: 80px !important; /* Spacing untuk header mobile */
    }
    
    /* ALL MOBILE BANNERS - 16:9 ratio enforcement */
    .mobile-banner {
        display: block !important;
        padding: 0.5rem !important;
    }
    
    .desktop-banner {
        display: none !important;
    }
    
    .mobile-banner .banner-image {
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100vw / 3.2) !important; /* 3.2:1 ratio */
        max-height: calc(100vw / 3.2) !important; /* Enforce max height */
        object-fit: cover !important;
        border-radius: 8px !important;
        display: block !important;
    }
    
    /* Banner ads in player page mobile - RELATIVE POSITION FOR MOBILE */
    .banner-ads-player {
        margin-top: 0 !important; /* No margin from top */
        position: relative !important; /* Change from fixed to relative for mobile */
        top: auto !important;
        left: auto !important;
        right: auto !important;
        width: 100% !important;
        height: auto !important; /* Let content determine height */
        z-index: 999 !important;
    }
    
    /* Player page mobile banner - enforce same 16:9 ratio */
    .banner-ads-player .mobile-banner .banner-image {
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100vw / 3.2) !important; /* 3.2:1 ratio */
        max-height: calc(100vw / 3.2) !important; /* Enforce max height */
        object-fit: cover !important;
        border-radius: 8px !important;
        display: block !important;
    }
    
    /* Back button mobile */
    .back-button-container {
        padding: 0.5rem !important;
        margin-top: 0 !important; /* No margin needed since banner is relative positioned */
    }
    
    .back-btn {
        padding: 0.4rem 0.8rem !important;
        font-size: 0.8rem !important;
    }
    
    /* Player container mobile - VERTICAL LAYOUT */
    .player-container {
        height: auto !important; /* Auto height for vertical layout */
        margin-top: 0 !important;
        min-height: 400px !important; /* Increased minimum height */
        display: flex !important;
        flex-direction: column !important; /* VERTICAL layout for mobile */
        position: relative !important;
        width: 100% !important;
    }
    
    /* Video container mobile - FIXED HEIGHT FOR MOBILE */
    .video-container {
        height: 52vh !important; /* Slightly taller to avoid empty gap */
        min-height: 360px !important; /* Minimum height fallback */
        max-height: 520px !important; /* Maximum height */
        width: 100% !important;
        position: relative !important;
        background: var(--black) !important; /* Black background */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-direction: column !important;
        flex-shrink: 0 !important; /* Prevent shrinking */
        order: 1 !important; /* Video container first */
        overflow: hidden !important; /* Ensure content doesn't overflow */
    }
    
    /* Video item mobile - ensure proper display */
    .video-item {
        width: 100% !important;
        height: 100% !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 1 !important; /* Ensure video item is above background */
        background: transparent !important; /* Transparent background */
    }
    
    /* Video element mobile - FORCE DISPLAY */
    .video-item video {
        object-fit: contain !important; /* Show full video without cropping */
        width: 100% !important;
        height: 100% !important;
        background: var(--black) !important; /* Black background for letterboxing */
        display: block !important; /* Force display */
        visibility: visible !important; /* Force visible */
        opacity: 1 !important; /* Force opacity */
        max-width: 100% !important;
        max-height: 100% !important;
        min-width: 200px !important; /* Minimum width for mobile */
        min-height: 200px !important; /* Minimum height for mobile */
        z-index: 1 !important; /* Ensure above background */
    }

    /* Ensure active video is visible on mobile regardless of base styles */
    .video-item { opacity: 0 !important; transform: translateY(100%) !important; }
    .video-item.active { opacity: 1 !important; transform: translateY(0) !important; z-index: 2 !important; }
    
    /* Side panel mobile - adjust for mobile layout */
    .side-panel {
        position: relative !important; /* Change from fixed/absolute */
        width: 100% !important;
        height: auto !important;
        max-height: 300px !important; /* Limit height on mobile */
        overflow-y: auto !important;
        background: rgba(0, 0, 0, 0.9) !important;
        z-index: 10 !important;
        order: 2 !important; /* Side panel after video container */
        flex-shrink: 0 !important; /* Prevent shrinking */
    }
    
    
    /* Main content mobile */
    .main-content {
        padding: 2rem 0 !important;
        margin-top: 0 !important;
    }
    
    /* Drama grid mobile - 2 columns */
    .drama-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.8rem !important;
        padding: 0 1rem !important;
    }
    
    /* Drama cards mobile */
    .drama-card {
        border-radius: 12px !important;
    }
    
    .drama-poster { height: auto !important; }
    
    .drama-info {
        padding: 1rem !important;
    }
    
    .drama-title {
        font-size: 0.9rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.5rem !important;
    }
    
    .drama-meta {
        font-size: 0.8rem !important;
        gap: 0.5rem !important;
    }
    
    .drama-description {
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }
    
    /* Play button mobile */
    .play-btn {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.2rem !important;
    }
    
    /* Filter buttons mobile */
    .filter-buttons {
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 0.5rem !important;
        padding: 0 1rem !important;
    }
    
    .filter-btn {
        padding: 0.6rem 1rem !important;
        font-size: 0.85rem !important;
    }
}

@media (max-width: 480px) {
    /* Very small mobile */
    .hero-text h2 {
        font-size: 2rem !important;
    }
    
    .drama-grid {
        gap: 0.75rem !important;
        padding: 0 0.5rem !important;
    }
    
    .drama-poster {
        height: 180px !important;
    }
    
    .drama-info {
        padding: 0.75rem !important;
    }
    
    .drama-title {
        font-size: 0.85rem !important;
    }
    
    .drama-meta {
        font-size: 0.75rem !important;
    }
    
    .drama-description {
        font-size: 0.7rem !important;
    }
    
    .play-btn {
        width: 45px !important;
        height: 45px !important;
        font-size: 1rem !important;
    }
}

/* Modal Responsive Fixes */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 1rem !important;
        align-items: flex-start !important;
        overflow-y: auto !important;
    }
}

/* Mobile-specific modal class */
.modal-overlay.mobile {
    padding: 0.5rem !important;
    align-items: flex-start !important;
    overflow-y: auto !important;
}

.modal-overlay.mobile .drama-modal {
    width: 100% !important;
    max-width: none !important;
    margin: 1rem 0 !important;
    border-radius: 16px !important;
}

@media (max-width: 768px) {
    
    .drama-modal {
        width: 100% !important;
        max-width: none !important;
        margin: 2rem 0 !important;
        max-height: none !important;
        border-radius: 16px !important;
    }
    
    .modal-content {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
        padding: 1.5rem !important;
    }
    
    .modal-poster {
        max-width: 200px !important;
        margin: 0 auto !important;
    }
    
    .modal-poster img {
        width: 100% !important;
        aspect-ratio: 2/3 !important;
    }
    
    .play-overlay {
        width: 60px !important;
        height: 60px !important;
        font-size: 1.2rem !important;
    }
    
    .modal-info h2 {
        font-size: 1.5rem !important;
        text-align: center !important;
    }
    
    .modal-meta {
        justify-content: center !important;
        text-align: center !important;
    }
    
    .action-buttons {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .watch-btn,
    .wishlist-btn,
    .share-btn {
        width: 100% !important;
        justify-content: center !important;
        padding: 1rem !important;
        font-size: 1rem !important;
    }
    
    .modal-close {
        top: 0.5rem !important;
        right: 0.5rem !important;
        width: 35px !important;
        height: 35px !important;
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 0.5rem !important;
    }
    
    .drama-modal {
        margin: 1rem 0 !important;
        border-radius: 12px !important;
    }
    
    .modal-content {
        padding: 1rem !important;
        gap: 1rem !important;
    }
    
    .modal-info h2 {
        font-size: 1.3rem !important;
    }
}

/* Touch Improvements */
@media (hover: none) and (pointer: coarse) {
    .drama-card {
        transition: transform 0.2s ease !important;
    }
    
    .drama-card:active {
        transform: scale(0.98) !important;
    }
    
    .play-btn:active {
        transform: scale(0.9) !important;
    }
    
    .watch-btn:active {
        transform: scale(0.98) !important;
    }
    
    /* Ensure modal buttons are easily touchable */
    .modal-close {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    .watch-btn,
    .wishlist-btn,
    .share-btn {
        min-height: 48px !important;
    }
}

/* Fix z-index issues */
.modal-overlay {
    z-index: 9999 !important;
}

.header {
    z-index: 1000 !important;
}

/* Ensure modal is properly centered on all devices */
.modal-overlay {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-start !important;
        padding-top: 2rem !important;
    }
}

/* Additional mobile touch targets */
.drama-card {
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Improve readability on mobile */
@media (max-width: 768px) {
    .drama-rating i {
        font-size: 0.8rem !important;
    }
    
    .episode-count {
        white-space: nowrap !important;
    }
}

/* Fix any overflow issues */
.homepage {
    overflow-x: hidden !important;
}

.main-content {
    overflow-x: hidden !important;
}

/* Mobile Video Overlay - Controlled by JavaScript */
@media (max-width: 768px) {
    .video-overlay {
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .play-pause-overlay {
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
}

/* Ensure proper spacing around grid */
@media (max-width: 768px) {
    .container {
        padding: 0 !important;
    }
    
    .section {
        padding: 2rem 1rem !important;
    }
    
    /* Footer responsive */
    .footer {
        margin-top: 2rem !important;
        padding: 1.5rem 0 !important;
    }
    
    .footer-content {
        padding: 0 1rem !important;
    }
    
    .footer-logo {
        font-size: 1.3rem !important;
    }
    
    .footer-logo i {
        font-size: 1.5rem !important;
    }
    
    .footer-text {
        font-size: 0.8rem !important;
    }
}
