/* Enhanced Video Player Styles for VieOn 2025 Theme */

/* ===== PLAYER CONTAINER CONSTRAINTS ===== */
.video-player-wrapper {
    position: relative;
    background: #000;
    border-radius: 0.5rem;
    overflow: visible; /* Changed from hidden to visible to prevent clipping */
    aspect-ratio: 16/9;
    max-width: 100%;
    max-height: 80vh; /* Prevent video from being too tall */
}

/* JWPlayer Container Constraints */
.jwplayer-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    max-height: 80vh; /* Prevent oversized video */
    aspect-ratio: 16/9;
    background: #000;
    overflow: visible; /* Changed from hidden to visible */
}

/* Aspect Video Utility Class Override */
.aspect-video {
    aspect-ratio: 16/9;
    max-width: 100%;
    max-height: 80vh; /* Critical: prevent video from growing too large */
    width: 100%;
    height: auto;
    overflow: hidden; /* Keep overflow hidden for video area only */
    border-radius: 0; /* No border radius for video itself */
    background: #000; /* Black background for video area */
}

/* Enhanced Video Player Element */
.enhanced-video-player {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ===== PLAYER INFO SECTION ===== */
.player-info {
    position: relative;
    z-index: 5;
    background: var(--theme-secondary) !important; /* Match container background */
    border-top: 1px solid var(--theme-tertiary);
    padding: 1rem;
    margin-top: 0;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    border-radius: 0 0 0.5rem 0.5rem; /* Round bottom corners */
    color: var(--text-primary);
}

/* Enhanced Video Player Container */
.enhanced-video-player-container {
    overflow: visible !important; /* Ensure player-info is not clipped */
    background: transparent !important; /* Remove background to prevent conflict */
    border-radius: 0.5rem;
    border: 1px solid var(--theme-tertiary);
}

/* Player Header */
.player-header {
    border-radius: 0.5rem 0.5rem 0 0; /* Round top corners */
    background: var(--theme-primary) !important;
}

/* ===== JWPLAYER INSTANCE CONSTRAINTS ===== */
/* JWPlayer div elements */
div[id^="jwplayer-"] {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 80vh !important;
    aspect-ratio: 16/9 !important;
    position: relative !important;
    position: relative !important;
}

/* JWPlayer video element */
div[id^="jwplayer-"] video {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
}

/* JWPlayer iframe (for embed sources) */
div[id^="jwplayer-"] iframe {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border: none !important;
}

/* JWPlayer wrapper elements */
.jwplayer {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 80vh !important;
    aspect-ratio: 16/9 !important;
}

.jwplayer .jw-media {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
}

.jwplayer .jw-video {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
}

/* Controls Overlay */
.video-controls-overlay {
    background: transparent;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.video-controls-overlay.opacity-100 {
    pointer-events: auto;
}

.video-controls-overlay.opacity-0 {
    pointer-events: none;
}

.video-controls-overlay.opacity-0 .video-top-controls,
.video-controls-overlay.opacity-0 .video-bottom-controls {
    pointer-events: none;
}

/* Top Controls */
.video-top-controls {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
}

.video-title {
    font-size: 1.1rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.settings-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    transition: all 0.3s ease;
}

.settings-btn:hover {
    background: rgba(0, 255, 102, 0.2);
    transform: scale(1.1);
}

/* Center Controls */
.video-center-controls {
    flex: 1;
}

.play-pause-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.play-pause-btn:hover {
    background: rgba(0, 255, 102, 0.3);
    border-color: rgba(0, 255, 102, 0.5);
    transform: scale(1.1);
}

.play-pause-btn:active {
    transform: scale(0.95);
}

/* Bottom Controls */
.video-bottom-controls {
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
}

/* Progress Bar */
.progress-container {
    position: relative;
}

.progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    cursor: pointer;
    transition: height 0.2s ease;
}

.progress-bar:hover {
    height: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--main-color, #00ff66);
    border-radius: 3px;
    position: relative;
    transition: width 0.1s ease;
}

.progress-fill::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    background: var(--main-color, #00ff66);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.progress-bar:hover .progress-fill::after {
    opacity: 1;
}

/* Control Buttons */
.controls-row button {
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    color: inherit;
}

.controls-row button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--main-color, #00ff66);
}

.controls-row button:active {
    transform: scale(0.95);
}

/* Volume Control */
.volume-container {
    position: relative;
}

.volume-slider {
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    border-radius: 3px;
    height: 4px;
    transition: all 0.2s ease;
}

.volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--main-color, #00ff66);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--main-color, #00ff66);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.volume-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

/* Speed and Quality Buttons */
.speed-btn,
.quality-btn {
    min-width: 50px;
    text-align: center;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 4px !important;
}

.speed-btn:hover,
.quality-btn:hover {
    border-color: var(--main-color, #00ff66) !important;
    background: rgba(0, 255, 102, 0.1) !important;
}

/* Time Display */
.time-display {
    font-family: 'Courier New', monospace;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    min-width: 100px;
}

/* Error Overlay */
.error-overlay {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(4px);
    z-index: 20;
}

.error-overlay button {
    background: var(--main-color, #00ff66);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.error-overlay button:hover {
    background: #00cc52;
    transform: translateY(-1px);
}

/* Loading States */
.video-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    z-index: 15;
}

.video-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top: 3px solid var(--main-color, #00ff66);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Fullscreen Styles */
.video-player-wrapper:fullscreen {
    border-radius: 0;
}

.video-player-wrapper:fullscreen .video-controls-overlay {
    padding: 20px;
}

.video-player-wrapper:fullscreen .video-top-controls,
.video-player-wrapper:fullscreen .video-bottom-controls {
    padding: 20px;
}

/* Picture-in-Picture Styles */
.video-player-wrapper:picture-in-picture {
    border-radius: 8px;
}

/* ===== RESPONSIVE VIDEO PLAYER CONSTRAINTS ===== */

/* Large screens - limit video height */
@media (min-width: 1200px) {
    .jwplayer-container,
    .aspect-video,
    div[id^="jwplayer-"],
    .jwplayer {
        max-height: 70vh !important;
    }
}

/* Medium screens */
@media (max-width: 1024px) {
    .jwplayer-container,
    .aspect-video,
    div[id^="jwplayer-"],
    .jwplayer {
        max-height: 60vh !important;
    }
}

/* Tablets */
@media (max-width: 768px) {
    .jwplayer-container,
    .aspect-video,
    div[id^="jwplayer-"],
    .jwplayer {
        max-height: 50vh !important;
    }

    .play-pause-btn {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }

    .video-title {
        font-size: 1rem;
    }

    .controls-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .left-controls,
    .right-controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    .volume-slider {
        width: 60px;
    }

    .time-display {
        font-size: 0.75rem;
        min-width: 80px;
    }

    .speed-btn,
    .quality-btn {
        min-width: 40px;
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    .video-top-controls,
    .video-bottom-controls {
        padding: 12px;
    }

    .progress-bar {
        height: 8px;
    }

    .progress-bar:hover {
        height: 10px;
    }

    /* Hide keyboard shortcuts info on mobile devices */
    .keyboard-shortcuts-info {
        display: none !important;
    }

    /* Optimize player info layout for mobile */
    .player-info {
        padding: 1rem !important;
    }

    .player-info .flex {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    /* Ensure player features remain visible and touch-friendly */
    .player-features {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
        justify-content: center !important;
    }

    .player-feature {
        min-height: 44px !important; /* WCAG touch target minimum */
        padding: 0.5rem 0.75rem !important;
        font-size: 0.875rem !important;
        border-radius: 0.5rem !important;
        background: rgba(255, 255, 255, 0.05) !important;
        transition: all 0.2s ease !important;
    }

    .player-feature:hover,
    .player-feature:focus {
        background: rgba(255, 255, 255, 0.1) !important;
        transform: translateY(-1px) !important;
    }
}

/* Mobile devices */
@media (max-width: 640px) {
    .jwplayer-container,
    .aspect-video,
    div[id^="jwplayer-"],
    .jwplayer {
        max-height: 40vh !important;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .jwplayer-container,
    .aspect-video,
    div[id^="jwplayer-"],
    .jwplayer {
        max-height: 35vh !important;
    }

    .play-pause-btn {
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .left-controls,
    .right-controls {
        justify-content: center;
    }

    .volume-container {
        justify-content: center;
    }

    .time-display {
        text-align: center;
    }

    /* Ultra-mobile optimizations for player info */
    .player-info {
        padding: 0.75rem !important;
    }

    .player-features {
        gap: 0.5rem !important;
    }

    .player-feature {
        font-size: 0.75rem !important;
        padding: 0.375rem 0.5rem !important;
        min-height: 40px !important;
    }

    /* Ensure keyboard shortcuts remain hidden */
    .keyboard-shortcuts-info {
        display: none !important;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .video-controls-overlay,
    .play-pause-btn,
    .progress-fill,
    .volume-slider::-webkit-slider-thumb,
    .volume-slider::-moz-range-thumb {
        transition: none;
    }

    .play-pause-btn:hover,
    .settings-btn:hover {
        transform: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: more) {
    .video-controls-overlay {
        background: rgba(0, 0, 0, 0.9);
    }

    .progress-bar {
        background: rgba(255, 255, 255, 0.5);
    }

    .progress-fill {
        background: #ffffff;
    }

    .controls-row button:hover {
        background: rgba(255, 255, 255, 0.3);
    }
}

/* Focus styles for keyboard navigation */
.video-controls-overlay button:focus,
.volume-slider:focus,
.player-feature:focus {
    outline: 2px solid var(--main-color, #00ff66);
    outline-offset: 2px;
}

/* Desktop-only keyboard shortcuts styling */
@media (min-width: 769px) {
    .keyboard-shortcuts-info {
        display: flex !important;
    }

    .keyboard-shortcuts-info kbd {
        font-family: 'Courier New', monospace;
        font-weight: 600;
        border: 1px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }

    .keyboard-shortcuts-info kbd:hover {
        background: rgba(255, 255, 255, 0.1);
        border-color: var(--main-color, #00ff66);
    }
}

/* Mobile-specific player info optimizations */
@media (max-width: 768px) {
    /* Ensure smooth transitions on mobile */
    .player-info,
    .player-features,
    .player-feature {
        transition: all 0.2s ease;
    }

    /* Improve touch feedback */
    .player-feature:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.15) !important;
    }
}

/* Custom scrollbar for settings menus (if added later) */
.player-menu::-webkit-scrollbar {
    width: 6px;
}

.player-menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.player-menu::-webkit-scrollbar-thumb {
    background: var(--main-color, #00ff66);
    border-radius: 3px;
}

.player-menu::-webkit-scrollbar-thumb:hover {
    background: #00cc52;
}

/* Enhanced Error State Styles */
.no-source-error,
.jwplayer-error,
.jwplayer-error-102630,
.video-error {
    backdrop-filter: blur(10px);
    animation: fadeInError 0.3s ease-out;
    border-radius: 0.5rem;
}

@keyframes fadeInError {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.no-source-error .fas,
.jwplayer-error .fas,
.jwplayer-error-102630 .fas,
.video-error .fas {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Debug info styling */
.no-source-error .bg-gray-800,
.jwplayer-error-102630 .bg-gray-800 {
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-family: 'Courier New', monospace;
    line-height: 1.4;
}

/* Button hover effects in error states */
.no-source-error button,
.jwplayer-error button,
.jwplayer-error-102630 button,
.video-error button {
    transition: all 0.2s ease;
    transform: translateY(0);
    border: none;
    outline: none;
}

.no-source-error button:hover,
.jwplayer-error button:hover,
.jwplayer-error-102630 button:hover,
.video-error button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.no-source-error button:focus,
.jwplayer-error button:focus,
.jwplayer-error-102630 button:focus,
.video-error button:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Loading overlay improvements */
.jwplayer-loading {
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
}

.jwplayer-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== FULLSCREEN MODE HANDLING ===== */
/* When in fullscreen, remove all constraints */
.jwplayer-container:fullscreen,
.jwplayer-container:-webkit-full-screen,
.jwplayer-container:-moz-full-screen,
.jwplayer-container:-ms-fullscreen {
    max-height: 100vh !important;
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100vh !important;
}

.jwplayer-container:fullscreen div[id^="jwplayer-"],
.jwplayer-container:-webkit-full-screen div[id^="jwplayer-"],
.jwplayer-container:-moz-full-screen div[id^="jwplayer-"],
.jwplayer-container:-ms-fullscreen div[id^="jwplayer-"] {
    max-height: 100vh !important;
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100vh !important;
}

/* Enhanced container styles */
.enhanced-video-player-container {
    position: relative;
    background: var(--bg-secondary, #1a1a1a);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    max-width: 100%;
    max-height: 80vh;
}

/* Highlight effect for server selector and episode list */
.highlight-section {
    transition: box-shadow 0.3s ease;
}

.highlight-section.highlighted {
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.5) !important;
}
