:root {
    --primary-color: #8b5cf6;
    /* Violet */
    --primary-glow: rgba(139, 92, 246, 0.5);
    --bg-dark: #000;
    --text-white: #fff;
    --glass-bg: rgba(20, 20, 20, 0.7);
    --font-main: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body.player-page {
    margin: 0;
    padding: 0;
    background-color: #000;
}

/* --- Container --- */
.player-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    background: #000;
    overflow: hidden;
    aspect-ratio: 16 / 9;
}

/* --- Video.js Engine Reset --- */
.video-js {
    width: 100% !important;
    height: 100% !important;
}

.video-js .vjs-control-bar,
.video-js .vjs-big-play-button,
.video-js .vjs-loading-spinner {
    display: none !important;
    /* Hide Default UI */
}

/* --- Custom UI Overlay --- */
.custom-ui {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    opacity: 1;
    /* Default to visible */
    visibility: visible;
    font-size: 16px !important;
    line-height: normal !important;
}

.custom-ui:not(.ui-hidden) {
    opacity: 1;
    visibility: visible;
}

.custom-ui.ui-hidden {
    opacity: 0;
    pointer-events: none;
}

/* --- Gesture Layer --- */
/* Must stay BELOW all controls (bottom bar z-20, settings z-30,
   resume modal z-200): it only handles taps on empty video area. */
.gesture-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Cover full screen to avoid dead zones */
    z-index: 1;
    pointer-events: auto;
    /* Catch clicks */
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight on mobile */
    touch-action: manipulation;
    /* Disable browser double-tap zoom for instant click response */
}

/* Layer order (bottom to top): video < gesture(1) < seek overlays(15) <
   bottom controls(20) < settings(30) < center controls(50) <
   error overlay(60) < resume modal(200). */

.custom-ui.ui-hidden {
    opacity: 0;
    pointer-events: none;
    /* Disables UI interaction, but we need gesture layer to be active */
}

/* --- Center Controls --- */
.center-controls {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    /* High Z-Index */
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 0 20px rgba(139, 92, 246, 0.4));
}

@keyframes pulse-ring {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 20px rgba(139, 92, 246, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0);
    }
}

.big-play-btn {
    background: rgba(109, 40, 217, 0.9);
    /* Solid Violet with slight transparency for glass feel */
    background: radial-gradient(circle at 30% 30%, #a78bfa, #7c3aed);
    border: none;
    border-radius: 50%;
    width: 90px;
    height: 90px;
    color: white;
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(255, 255, 255, 0.2);
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: pulse-ring 2s infinite;
    visibility: visible !important;
    opacity: 1 !important;
}

.big-play-btn i {
    font-size: 45px;
    margin-left: 5px;
    /* Visual optical adjustment */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.big-play-btn.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    animation: none;
}

.big-play-btn:hover {
    transform: scale(1.15);
    background: linear-gradient(135deg, #a78bfa, #7c3aed);
    box-shadow: 0 20px 50px rgba(109, 40, 217, 0.7);
}

.big-play-btn:active {
    transform: scale(0.95);
    animation: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: absolute;
}

.hidden {
    display: none !important;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Seek Overlays --- */
.seek-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 15;
    pointer-events: none;
}

.seek-overlay.left {
    left: 0;
    border-radius: 0 50% 50% 0;
}

.seek-overlay.right {
    right: 0;
    border-radius: 50% 0 0 50%;
}

.seek-overlay.active {
    opacity: 1;
}

.icon-box {
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border-radius: 50%;
    text-align: center;
    color: white;
}

.icon-box i {
    display: block;
    font-size: 24px;
    margin-bottom: 5px;
}

.icon-box span {
    font-size: 12px;
    font-weight: 600;
}


/* --- Bottom Controls Panel --- */
.bottom-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.6) 50%, rgba(0, 0, 0, 0));
    padding: 40px 20px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 20;
    pointer-events: auto;
    transition: transform 0.3s ease;
}

.custom-ui.ui-hidden .bottom-controls {
    transform: translateY(100%);
    pointer-events: none;
}

/* While hidden, only the gesture layer may receive taps. */

/* Row 1: Time */
.time-row {
    font-size: 13px;
    color: #ccc;
    font-weight: 500;
    display: flex;
    gap: 5px;
    user-select: none;
}

/* Row 2: Progress */
.progress-row {
    width: 100%;
    height: 20px;
    display: flex;
    align-items: center;
}

.progress-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
    transition: height 0.2s;
}

.progress-container:hover {
    height: 6px;
}

.progress-bar {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    border-radius: 2px;
    position: relative;
    z-index: 2;
}

.progress-handle {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    transition: transform 0.2s;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.progress-container:hover .progress-handle {
    transform: translateY(-50%) scale(1);
}

.buffered-bar {
    height: 100%;
    background: rgba(255, 255, 255, 0.3);
    width: 0%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    border-radius: 2px;
}

/* Row 3: Buttons */
.buttons-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.left-buttons,
.right-buttons {
    display: flex;
    align-items: center;
    gap: 15px;
}

.control-btn {
    background: none;
    border: none;
    color: white;
    font-size: 32px !important;
    /* Optimized Desktop Size */
    width: 45px !important;
    height: 45px !important;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: all 0.2s;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.control-btn i {
    font-size: 32px !important;
    /* Optimized Icon Size */
    line-height: 1 !important;
    display: block;
    width: 100%;
    height: auto;
}


.control-btn:hover {
    opacity: 1;
    color: var(--primary-color);
    transform: scale(1.15);
}

/* Volume */
.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

#volume-slider {
    width: 0;
    opacity: 0;
    transition: all 0.3s;
    appearance: none;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.volume-container:hover #volume-slider {
    width: 60px;
    opacity: 1;
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    cursor: pointer;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .bottom-controls {
        padding: 10px;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.8) 70%, rgba(0, 0, 0, 0));
    }

    .row.buttons-row {
        gap: 5px;
        justify-content: space-between;
    }

    .left-buttons, .right-buttons {
        gap: 5px;
    }

    .big-play-btn {
        width: 60px !important;
        height: 60px !important;
        font-size: 30px !important;
    }

    .big-play-btn i {
        font-size: 30px !important;
    }

    /* Keep the mute toggle; slider collapses and expands via .open below. */
    .volume-container {
        display: flex !important;
    }

    .volume-container #volume-slider {
        width: 0 !important;
        opacity: 0 !important;
    }

    .control-btn {
        width: 36px !important;
        height: 36px !important;
        padding: 5px !important;
    }

    .control-btn i {
        font-size: 22px !important;
    }

    /* Time display smaller on mobile */
    .time-row {
        font-size: 11px;
        margin-bottom: 5px;
    }

    .progress-row {
        margin-bottom: 5px;
    }
    
    .settings-menu {
        bottom: 50px;
        right: 5px;
        width: 140px;
    }
    
    /* Make seek overlays more visible/touchable */
    .seek-overlay {
        width: 30%;
    }
}

/* Very Small Screen Adjustments */
@media (max-width: 480px) {
    .control-btn {
        width: 32px !important;
        height: 32px !important;
    }
    
    .control-btn i {
        font-size: 18px !important;
    }
    
    /* Hide some controls if needed, or rearrange */
    #btn-pip { display: none; }
}


/* --- Settings Menu --- */
.settings-menu {
    position: absolute;
    bottom: 90px;
    right: 20px;
    background: rgba(20, 20, 20, 0.95);
    width: 180px;
    /* Reduced Width */
    border-radius: 12px;
    overflow: hidden;
    z-index: 30;
    pointer-events: auto;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    /* Reduced Padding */
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.settings-header span {
    font-weight: 600;
    font-size: 13px;
    /* Reduced Font */
    color: white;
}

.close-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 16px;
    /* Reduced Size */
    padding: 0;
    display: flex;
}

.close-btn:hover {
    color: white;
}

.speed-options {
    list-style: none;
    padding: 0;
    margin: 0;
}

.speed-options li {
    padding: 8px 12px;
    /* Reduced Padding */
    cursor: pointer;
    font-size: 12px;
    /* Reduced Font */
    color: #ddd;
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
}


.speed-options li:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.speed-options li.active {
    color: var(--primary-color);
    font-weight: 600;
}

.speed-options li.active::after {
    content: '✓';
}

/* Mobile Adjustments for Settings */
@media (max-width: 768px),
(max-height: 450px) {
    .settings-menu {
        bottom: 60px;
        /* Positioned above bottom controls */
        right: 10px;
        left: auto;
        transform: none;
        width: 160px;
        /* More compact width */
        max-height: 60%;
        /* Prevent overflowing height */
        overflow-y: auto;
        /* Scroll if needed */
        background: rgba(20, 20, 20, 0.85);
        /* Slightly transparent */
        backdrop-filter: blur(10px);
        /* Glassy feel */
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .settings-header {
        padding: 8px 10px;
    }

    .speed-options li {
        padding: 8px 10px;
        font-size: 13px;
    }
}

/* --- Resume Modal --- */
.resume-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    /* Darker overlay */
    backdrop-filter: blur(5px);
    /* Blur background behind modal */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    pointer-events: auto;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.resume-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.resume-content {
    background: rgba(30, 30, 30, 0.65);
    /* Glassy Background */
    backdrop-filter: blur(15px);
    /* Strong blur for premium feel */
    -webkit-backdrop-filter: blur(15px);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    /* Glow & Depth */
    border: 1px solid rgba(255, 255, 255, 0.15);
    /* Subtle border */
}

.resume-content h3 {
    margin: 0 0 8px 0;
    color: white;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.resume-content p {
    color: rgba(255, 255, 255, 0.8);
    margin: 0 0 25px 0;
    font-size: 14px;
    line-height: 1.5;
}

.resume-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.resume-btn {
    padding: 10px 24px;
    border-radius: 50px;
    /* Pill shape for premium look */
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-family: var(--font-main);
    letter-spacing: 0.5px;
}

.resume-btn.primary {
    background: linear-gradient(135deg, var(--primary-color), #7c3aed);
    border: none;
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.resume-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(139, 92, 246, 0.5);
    filter: brightness(1.1);
}

.resume-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #eee;
    backdrop-filter: blur(5px);
}

.resume-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
    transform: translateY(-2px);
}

/* Mobile & Small Screen Adjustments for Resume Modal */
@media (max-width: 768px),
(max-height: 450px) {
    .resume-content {
        padding: 20px 15px;
        width: 85%;
        max-width: 300px;
        border-radius: 12px;
    }

    .resume-content h3 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .resume-content p {
        font-size: 13px;
        margin-bottom: 15px;
    }

    .resume-btn {
        padding: 8px 16px;
        font-size: 13px;
        border-radius: 6px;
    }

    .resume-actions {
        gap: 10px;
    }
}
/* === FlixBD enterprise mobile-fit layer === */
.player-wrapper video,
.video-js video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    background: #000;
}

/* Error overlay */
.player-error-overlay {
    position: absolute; inset: 0; z-index: 60;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.72); backdrop-filter: blur(6px);
    pointer-events: auto; padding: 16px;
}
.player-error-card { text-align: center; max-width: 340px; }
.player-error-title { color: #fff; font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.player-error-sub { color: rgba(255,255,255,0.65); font-size: 13px; margin-bottom: 16px; }
.player-error-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.player-error-btn {
    min-height: 44px; padding: 10px 22px; border-radius: 999px;
    font-size: 14px; font-weight: 700; cursor: pointer;
    border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.08); color: #fff;
}
.player-error-btn.primary { background: #e50914; border-color: #e50914; }

/* Focus visibility for keyboard users */
.control-btn:focus-visible, .big-play-btn:focus-visible,
.player-error-btn:focus-visible, .resume-btn:focus-visible {
    outline: 2px solid #a78bfa; outline-offset: 2px;
}

/* Touch devices: 44px targets, fat progress hit-area, safe-area.
   Mobile-only: drop the black gradient so the video shows through and
   touch-seek on the progress bar works cleanly. */
@media (pointer: coarse) {
    .control-btn { width: 40px !important; height: 40px !important; }
    .control-btn i { font-size: 22px !important; }
    .progress-row { height: 20px; }
    .progress-container { height: 3px; }
    .progress-container:hover { height: 3px; }
    .progress-container::after {
        content: ''; position: absolute; left: 0; right: 0; top: -12px; bottom: -12px;
    }
    .progress-handle { transform: translateY(-50%) scale(1); width: 10px; height: 10px; }
    .bottom-controls {
        background: transparent;
        padding: 2px 10px 4px;
        padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
        gap: 0;
    }
    .time-row { font-size: 10px; margin-bottom: 0; line-height: 1; }
    .control-btn { filter: drop-shadow(0 1px 3px rgba(0,0,0,0.9)); }
    .time-row { text-shadow: 0 1px 3px rgba(0,0,0,0.9); }
    /* Keep the mute toggle; the slider collapses to 0 width and only
       expands via .open (see inline-volume block below). */
    .volume-container { display: flex !important; }
    .volume-container #volume-slider { width: 0 !important; opacity: 0 !important; }
}

/* Small phones */
@media (max-width: 640px) {
    .center-controls { filter: none; }
    .big-play-btn { width: 64px !important; height: 64px !important; }
    .big-play-btn i { font-size: 30px !important; margin-left: 3px; }
    .bottom-controls { padding: 28px 12px calc(10px + env(safe-area-inset-bottom, 0px)); gap: 6px; }
    .time-row { font-size: 11px; }
    .left-buttons, .right-buttons { gap: 2px; }
    #btn-pip { display: none; }
    .seek-overlay { width: 35%; }
    .resume-content { width: min(88vw, 320px); padding: 20px 16px; }
}

/* Landscape phones: compact chrome */
@media (max-height: 480px) and (orientation: landscape) {
    .bottom-controls { padding: 20px 12px 8px; gap: 4px; }
    .big-play-btn { width: 52px !important; height: 52px !important; }
    .big-play-btn i { font-size: 24px !important; }
    .time-row { display: none; }
    .settings-menu { bottom: 56px; }
}

/* === Fix: resume modal must sit above gesture layer (z-100) === */
.resume-modal { z-index: 200 !important; }
.resume-modal .resume-btn {
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    min-height: 44px;
}

/* === Seek preview tooltip (desktop enterprise touch) === */
.progress-tooltip {
    position: absolute; bottom: 18px; transform: translateX(-50%);
    background: rgba(10,10,10,0.92); color: #fff;
    font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
    pointer-events: none; white-space: nowrap; z-index: 25;
}
@media (pointer: coarse) { .progress-tooltip { display: none; } }

/* === YouTube-style inline volume: slider sits with mute, never floats up === */
#volume-slider { --vol: 100%; }
.volume-container.open #volume-slider,
.volume-container:hover #volume-slider,
.volume-container:focus-within #volume-slider {
    width: 72px !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}
#volume-slider::-webkit-slider-runnable-track {
    background: linear-gradient(90deg, #e50914 var(--vol, 100%), rgba(255,255,255,0.3) var(--vol, 100%)) !important;
}
#volume-slider::-moz-range-progress { background: #e50914 !important; }
@media (pointer: coarse) {
    .volume-container.open #volume-slider { width: 64px !important; }
    .volume-container #volume-slider::-webkit-slider-thumb { width: 16px; height: 16px; margin-top: -6px; }
    .volume-container #volume-slider::-moz-range-thumb { width: 16px; height: 16px; }
}

/* === Fit bottom buttons on narrow phones === */
@media (max-width: 640px) {
    .row.buttons-row { flex-wrap: nowrap; }
    .left-buttons, .right-buttons {
        flex-wrap: nowrap; min-width: 0; flex-shrink: 1;
    }
    .left-buttons .control-btn, .right-buttons .control-btn { flex-shrink: 0; }
}
@media (max-width: 380px) {
    .control-btn { width: 40px !important; height: 40px !important; }
    .control-btn i { font-size: 21px !important; }
    .left-buttons, .right-buttons { gap: 0; }
    .bottom-controls { padding-left: 8px; padding-right: 8px; }
}

/* === Auto-fit: landscape stays 16:9, vertical / mobile screen-record goes tall === */
.player-box { aspect-ratio: 16 / 9; }
.player-box.is-landscape { aspect-ratio: 16 / 9; max-width: 100%; }
.player-box.is-portrait {
    width: 100%;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    aspect-ratio: 9 / 16;
    max-height: 75vh;
}
.player-box.is-portrait .player-wrapper {
    aspect-ratio: auto;
    width: 100%;
    height: 100%;
}
/* Never constrain real fullscreen — portrait cap applies to inline page only */
.player-box.is-portrait:fullscreen,
.player-box.is-portrait:-webkit-full-screen {
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
}
.video-js.vjs-fullscreen,
.video-js.vjs-fullscreen .player-wrapper,
.video-js.vjs-fullscreen video {
    max-width: none !important;
    max-height: none !important;
    width: 100% !important;
    height: 100% !important;
}
