/* Modern Video Player Styles */

.video-player-wrapper {
    position: relative;
    width: 100%;
    background: #000000;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    contain: content;

    /* Enforce Dark Mode CSS Variables */
    --color-surface: #09090b;
    --color-surface-hover: #27272a; /* Make hover slightly lighter than #18181b for contrast */
    --color-border: #27272a;
    --color-text: #ffffff;
    --color-text-muted: #a1a1aa;
    --color-text-dim: #52525b;

    /* Enforce Aspect Ratio (Default 1:1) */
    aspect-ratio: 1 / 1;
    max-height: 85vh;

    display: flex;
    justify-content: center;
    align-items: center;
}

/* Aspect Ratio Variants */
.video-player-wrapper.aspect-1-1 {
    aspect-ratio: 1 / 1;
    width: 100%;
}

.video-player-wrapper.aspect-9-16 {
    aspect-ratio: 9 / 16 !important;
    height: 100% !important;
    width: auto !important;
    max-height: none !important;
}

.video-player-wrapper.aspect-16-9 {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
}

/* Specific overrides for full-screen Video Feed */
.video-feed-media .video-player-wrapper.aspect-9-16 {
    width: 100% !important;
    height: 100% !important;
}

/* Video Element - General Styles */
.video-player-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    position: relative;
    z-index: 1;
}

/* Bottom gradient inside player strictly for vertical feed style */
.video-player-wrapper.aspect-9-16::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 150px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    pointer-events: none;
    z-index: 2;
}

/* In 9:16 mode, video should always be contained to avoid cutting */
.video-player-wrapper.aspect-9-16 video {
    object-fit: contain;
}

/* 1. Center Overlay: Play/Pause/Loading State */
.vp-center-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    pointer-events: none;
    transition: all 0.2s ease;
}

.vp-play-icon {
    width: 64px;
    height: 64px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.video-player-wrapper.is-paused .vp-play-icon {
    opacity: 1;
    transform: scale(1);
}

.video-player-wrapper.is-loading .vp-play-icon {
    opacity: 0 !important;
    pointer-events: none;
}

/* New Video Loader (Sound Wave) */
.vp-video-loader {
    display: none;
    width: 40px;
    height: 30px;
    justify-content: center;
    align-items: center;
    gap: 4px;
}

.video-player-wrapper.is-loading .vp-video-loader {
    display: flex;
}

.vp-video-loader span {
    display: block;
    width: 4px;
    height: 100%;
    background-color: white;
    border-radius: 2px;
    animation: vp-wave 1.2s ease-in-out infinite;
}

.vp-video-loader span:nth-child(1) {
    animation-delay: -0.4s;
    background: rgba(255, 255, 255, 0.8);
}

.vp-video-loader span:nth-child(2) {
    animation-delay: -0.2s;
    background: rgba(255, 255, 255, 1);
}

.vp-video-loader span:nth-child(3) {
    animation-delay: 0s;
    background: rgba(255, 255, 255, 0.8);
}

@keyframes vp-wave {

    0%,
    100% {
        height: 20%;
        opacity: 0.5;
    }

    50% {
        height: 70%;
        opacity: 1;
    }
}

/* 2. Controls Overlay (Gradient + Row) */
.vp-controls-overlay {
    position: absolute;
    left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 30;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

/* Default: Bottom */
.video-player-wrapper.controls-bottom .vp-controls-overlay {
    bottom: 0;
    padding: 40px 12px 14px 12px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 50%, transparent 100%);
}

.video-player-wrapper.controls-top .vp-controls-overlay {
    top: 0;
    bottom: auto;
    padding: 15px 12px 40px 12px;
    /* Moved up for desktop (was 35px) */
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.4) 60%, transparent 100%);
}


.video-player-wrapper:hover .vp-controls-overlay,
.video-player-wrapper.is-paused .vp-controls-overlay,
.video-player-wrapper.is-scrubbing .vp-controls-overlay {
    opacity: 1;
}

/* Auto-hide behavior for Tube */
.video-player-wrapper.controls-hidden .vp-controls-overlay,
.video-player-wrapper.controls-hidden .vp-progress-container,
.video-player-wrapper.controls-hidden .vp-music-info {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Row of icons */
.vp-controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.vp-controls-left,
.vp-controls-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vp-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vp-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.vp-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2px;
}

/* Speed Badge & Quality Badge */
.vp-badge {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    border: 1px solid var(--color-glass-border);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.vp-badge:hover {
    background: rgba(255, 255, 255, 0.15);
}

.vp-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    margin-inline-start: 4px;
}

/* 3. Progress Bar (Absolute Position) */
.vp-progress-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20px;
    /* Increased hit area for easier control */
    cursor: pointer;
    z-index: 1000 !important;
    display: flex;
    align-items: flex-end;
}

/* Default: Bottom */
.video-player-wrapper.controls-bottom .vp-progress-container {
    bottom: 0;
}

/* Variant: Top (Vertical Feed Layout) */
.video-player-wrapper.controls-top .vp-progress-container {
    bottom: 0;
    /* Keep at bottom as requested */
    top: auto;
}

/* Bottom shadow for info area when controls are at top */
.video-player-wrapper.controls-top::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 150px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    pointer-events: none;
    z-index: 5;
}

.vp-progress-background {
    width: 100%;
    height: 4px;
    /* Keep the bar thin visually */
    background: rgba(255, 255, 255, 0.2);
    position: relative;
    transition: height 0.1s ease;
}

.vp-progress-container:hover .vp-progress-background,
.video-player-wrapper.is-scrubbing .vp-progress-background {
    height: 6px;
}

.vp-progress-fill {
    height: 100%;
    background: #fff;
    width: 0%;
    position: relative;
    border-start-end-radius: 2px;
    border-end-end-radius: 2px;
}

.vp-progress-thumb {
    position: absolute;
    inset-inline-end: -6px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.1s;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

.vp-progress-container:hover .vp-progress-thumb,
.video-player-wrapper.is-scrubbing .vp-progress-thumb {
    transform: translateY(-50%) scale(1);
}

/* Tiny Centered Minimalist Status (Higher Up) */
.vp-autoplay-status-pill {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
    pointer-events: none;
}

.vp-autoplay-banner {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    padding: 3px 3px 3px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.vp-autoplay-title {
    color: #ffffff;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vp-autoplay-action-btn {
    background: #ffffff;
    color: #000000;
    border: none;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 8px;
    font-weight: 900;
    text-transform: uppercase;
    cursor: pointer;
}

.vp-autoplay-hint {
    color: rgba(255, 255, 255, 0.5);
    font-size: 7.5px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.vp-autoplay-action-btn:hover {
    background: #e0e0e0;
    transform: scale(1.05);
}

@keyframes vp-banner-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Tweaks */
@media (max-width: 640px) {
    .vp-autoplay-status-pill {
        max-width: 320px;
    }

    .vp-autoplay-banner {
        padding: 10px 10px 10px 14px;
        gap: 10px;
    }

    .vp-autoplay-title {
        font-size: 12px;
    }
}

/* Mobile Tweaks */
@media (max-width: 640px) {
    .vp-controls-overlay {
        opacity: 1 !important;
        padding-bottom: 20px;
    }

    .vp-progress-container {
        height: 3px;
    }
}

/* Sensitive Content Blurring */
.vp-sensitive video {
    filter: blur(50px);
    transition: filter 0.5s ease;
    pointer-events: none;
}

.video-player-wrapper.is-revealed video {
    filter: blur(0);
    pointer-events: auto;
}

.vp-sensitive-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    /* Above everything */
    cursor: pointer;
    transition: opacity 0.4s ease, visibility 0.4s;
}

.video-player-wrapper.is-revealed .vp-sensitive-overlay {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.vp-sensitive-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 80%;
}

/* 5. Speed Boost Indicator */
.vp-speed-indicator {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 12px;
    border-radius: 100px;
    z-index: 45;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.vp-speed-text {
    color: white;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* RTL Helpers */
[dir="rtl"] .rtl\:mirror {
    transform: scaleX(-1);
}

/* Speed Indicator Transitions */
.vp-speed-enter {
    transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
}
.vp-speed-enter-start {
    opacity: 0;
    transform: translateX(-50%) scale(0.9);
    filter: blur(4px);
}
.vp-speed-enter-end {
    opacity: 1;
    transform: translateX(-50%) scale(1);
    filter: blur(0);
}
.vp-speed-leave {
    transition: all 0.15s ease-out;
}
.vp-speed-leave-start {
    opacity: 1;
    transform: translateX(-50%) scale(1);
    filter: blur(0);
}
.vp-speed-leave-end {
    opacity: 0;
    transform: translateX(-50%) scale(1.05);
    filter: blur(4px);
}

/* 4. Music Info Pill - Layout Aware & RTL Support */
.vp-music-info {
    position: absolute;
    inset-inline-start: 12px;
    z-index: 40;
    pointer-events: none;
    transition: all 0.3s ease;
    opacity: 0.8;
}

/* Default Bottom-Start (Standard Posts) */
.video-player-wrapper.controls-bottom .vp-music-info {
    bottom: 12px;
}

@media (max-width: 640px) {
    .video-player-wrapper.controls-bottom .vp-music-info {
        bottom: 52px;
        /* Always shift up on mobile since bottom controls are always visible */
    }
}

/* Top-Start (Video Feed) */
.video-player-wrapper.controls-top .vp-music-info {
    top: 10px;
    /* Reduced from 12px */
}

.vp-music-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 3px 8px;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.9);
    pointer-events: auto;
}

.vp-music-text {
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    letter-spacing: 0.1px;
}

.video-player-wrapper:hover .vp-music-info {
    opacity: 1;
}

/* Interaction: Shift when controls appear */
.video-player-wrapper.controls-bottom:hover .vp-music-info,
.video-player-wrapper.controls-bottom.is-paused .vp-music-info {
    bottom: 52px;
}

.video-player-wrapper.controls-top:hover .vp-music-info,
.video-player-wrapper.controls-top.is-paused .vp-music-info {
    top: 60px;
    /* Raised from 75px for desktop */
    /* Shift below top controls */
}

}

/* Hide when sensitive */
.video-player-wrapper.vp-sensitive:not(.is-revealed) .vp-music-info {
    display: none;
}

/* ── Fullscreen Button ─────────────────────────────────────────────────────── */
.vp-btn--fullscreen {
    padding: 6px;
}

/* Icon is 18px — visually matches skip/mute siblings */
.vp-fs-icon {
    width: 18px !important;
    height: 18px !important;
    display: block;
}

/* Disable scrollbar while any player is in fullscreen to remove the right-side gap */
html[data-vp-fullscreen],
:root:has(.video-player-wrapper:fullscreen) {
    overflow: hidden !important;
    scrollbar-width: none !important; /* Firefox */
}
html[data-vp-fullscreen]::-webkit-scrollbar,
:root:has(.video-player-wrapper:fullscreen)::-webkit-scrollbar {
    display: none !important; /* Chrome/Safari/Edge */
}

/* When the player itself is fullscreen, fill the entire screen */
.video-player-wrapper:fullscreen,
.video-player-wrapper:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    aspect-ratio: unset !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    left: 0 !important;
    top: 0 !important;
}

/* Neutralise the browser's fullscreen backdrop tint/spacing */
.video-player-wrapper::backdrop {
    background: var(--color-surface);
}

.video-player-wrapper:fullscreen video,
.video-player-wrapper:-webkit-full-screen video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

/* Keep controls always visible in fullscreen (no auto-hide risk on mobile) */
.video-player-wrapper:fullscreen .vp-controls-overlay,
.video-player-wrapper:-webkit-full-screen .vp-controls-overlay {
    opacity: 1;
}

/* Bigger touch targets in fullscreen for mobile comfort */
@media (max-width: 1024px) {
    .video-player-wrapper:fullscreen .vp-btn,
    .video-player-wrapper:-webkit-full-screen .vp-btn {
        padding: 10px;
    }

    .video-player-wrapper:fullscreen .vp-btn svg,
    .video-player-wrapper:-webkit-full-screen .vp-btn svg {
        width: 22px;
        height: 22px;
    }

    /* Keep fullscreen icon proportional on mobile too */
    .video-player-wrapper:fullscreen .vp-fs-icon,
    .video-player-wrapper:-webkit-full-screen .vp-fs-icon {
        width: 22px !important;
        height: 22px !important;
    }

    .video-player-wrapper:fullscreen .vp-progress-container,
    .video-player-wrapper:-webkit-full-screen .vp-progress-container {
        height: 28px;
    }
}