/**
 * YouPosts Plyr Custom Styles
 * Maps plugin player settings to Plyr CSS variables
 */

/* Map plugin CSS variables to Plyr variables */
.youposts-plyr-container {
    --plyr-color-main: var(--youposts-player-color, #8bc34a);
    --plyr-video-control-color: var(--youposts-controls-color, #fff);
    --plyr-video-control-color-hover: var(--youposts-player-color, #8bc34a);
    --plyr-control-radius: var(--youposts-play-button-radius, 12px);
    --plyr-video-background: #000;

    /* Progress bar */
    --plyr-range-fill-background: var(--youposts-player-color, #8bc34a);
    --plyr-video-range-track-background: rgba(255, 255, 255, 0.25);

    /* Control spacing */
    --plyr-control-spacing: 10px;
}

/* Container styling */
.youposts-plyr-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--youposts-player-radius, 8px);
    background: #000;
}

/* Fallback for browsers without aspect-ratio */
@supports not (aspect-ratio: 16 / 9) {
    .youposts-plyr-container {
        padding-bottom: 56.25%; /* 16:9 */
        height: 0;
    }
}

/* Aspect ratio wrapper */
.youposts-plyr-container .plyr {
    --plyr-video-controls-background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

/* Custom poster/thumbnail overlay */
.youposts-plyr-poster {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    cursor: pointer;
}

.youposts-plyr-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Custom play overlay button (matches hero play button styling) */
.youposts-plyr-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--youposts-play-button-width, 80px);
    height: var(--youposts-play-button-height, calc(var(--youposts-play-button-width, 80px) * 0.5625));
    background: var(--youposts-player-color, #8bc34a);
    border: none;
    border-radius: var(--youposts-play-button-radius, 12px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: var(--youposts-controls-opacity, 0.9);
    color: var(--youposts-play-triangle-color, #ffffff);
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 11;
}

.youposts-plyr-play-overlay:hover {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 1;
}

.youposts-plyr-play-overlay svg {
    display: block;
    fill: currentColor;
    width: 40%;
    height: 40%;
}

/* Embed target - hidden until playing */
.youposts-plyr-embed-target {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Show embed target when playing */
.youposts-plyr-container.is-playing .youposts-plyr-embed-target {
    display: block;
}

/* Plyr fills container */
.youposts-plyr-container .plyr {
    width: 100%;
    height: 100%;
}

/* Hide poster when video is playing */
.youposts-plyr-container.is-playing .youposts-plyr-poster {
    display: none;
}

/* Hide custom play overlay when disabled */
.youposts-hide-play-overlay .youposts-plyr-play-overlay {
    display: none;
}

/* Hide poster overlay when thumbnails are disabled */
.youposts-hide-poster .youposts-plyr-poster {
    display: none;
}

/* Plyr overrides to hide YouTube branding */
.youposts-plyr-container .plyr__poster {
    display: none;
}

/* ============================================
   YOUTUBE UI HIDING - IFRAME CROPPING TECHNIQUE
   Matches Presto Player's exact approach
   ============================================ */

/* Fixed ratio required for crop hack */
.youposts-plyr-container .plyr__video-embed,
.youposts-plyr-container .plyr__video-wrapper--fixed-ratio {
    aspect-ratio: 16 / 9;
}

@supports not (aspect-ratio: 16 / 9) {
    .youposts-plyr-container .plyr__video-embed,
    .youposts-plyr-container .plyr__video-wrapper--fixed-ratio {
        height: 0;
        padding-bottom: 56.25%;
        position: relative;
    }
}

/* Base iframe sizing */
.youposts-plyr-container .plyr__video-embed iframe,
.youposts-plyr-container .plyr__video-wrapper--fixed-ratio video {
    border: 0;
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
}

/* YouTube UI crop (tuned to avoid excessive zoom) */
.youposts-plyr-container {
    --youposts-youtube-crop-top: 7%;
    --youposts-youtube-crop-height: 114%;
}

/* When paused/idle (YouTube overlays appear), crop slightly more */
.youposts-plyr-container .plyr:not(.plyr--playing) {
    --youposts-youtube-crop-top: 9%;
    --youposts-youtube-crop-height: 118%;
}

.youposts-plyr-container.youposts-hide-youtube-ui .plyr__video-embed iframe {
    top: calc(-1 * var(--youposts-youtube-crop-top, 15%));
    height: var(--youposts-youtube-crop-height, 130%);
}

.youposts-plyr-container .plyr__video-wrapper {
    overflow: hidden;
}

.youposts-plyr-container .plyr__video-embed {
    overflow: hidden;
}

/* Fullscreen correction when hide-YouTube crop is active */
@media (min-aspect-ratio: 16/9) {
    .youposts-plyr-container.youposts-hide-youtube-ui .plyr:fullscreen .plyr__video-wrapper {
        width: 177.7777777778vh;
    }
}

/* Large play button styling (Plyr's default overlay button) */
.youposts-plyr-container .plyr__control--overlaid {
    background: var(--youposts-player-color, #8bc34a);
    border-radius: var(--youposts-play-button-radius, 12px);
    padding: 20px 25px;
    opacity: var(--youposts-controls-opacity, 0.9);
}

.youposts-plyr-container .plyr__control--overlaid:hover {
    background: var(--youposts-player-color, #8bc34a);
    opacity: 1;
}

.youposts-plyr-container .plyr__control--overlaid svg {
    fill: var(--youposts-play-triangle-color, #ffffff);
}

/* Control bar styling */
.youposts-plyr-container .plyr__controls {
    padding: 10px;
    background: var(--youposts-player-color, #8bc34a);
    opacity: var(--youposts-controls-opacity, 0.9);
    transition: opacity 0.3s ease;
}

/* Progress bar styling */
.youposts-plyr-container .plyr__progress input[type="range"] {
    height: 6px;
}

.youposts-plyr-container .plyr__progress__buffer {
    background: rgba(255, 255, 255, 0.2);
}

/* Volume slider */
.youposts-plyr-container .plyr__volume input[type="range"] {
    height: 4px;
}

/* Control buttons */
.youposts-plyr-container .plyr__control svg {
    fill: var(--youposts-controls-color, #fff);
}

.youposts-plyr-container .plyr__control:hover svg {
    fill: var(--youposts-player-color, #8bc34a);
}

/* Time display */
.youposts-plyr-container .plyr__time {
    color: var(--youposts-controls-color, #fff);
    font-size: 14px;
}

/* Fullscreen button */
.youposts-plyr-container .plyr__control[data-plyr="fullscreen"] svg {
    fill: currentColor;
}

/* Settings menu */
.youposts-plyr-container .plyr__menu__container {
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px;
}

.youposts-plyr-container .plyr__menu__container [role="menuitemradio"][aria-checked="true"]::before {
    background: var(--youposts-player-color, #8bc34a);
}

/* Tooltips */
.youposts-plyr-container .plyr__tooltip {
    background: rgba(0, 0, 0, 0.9);
    color: var(--youposts-controls-color, #fff);
    border-radius: 4px;
    font-size: 12px;
}

/* Loading indicator */
.youposts-plyr-container .plyr__progress__buffer,
.youposts-plyr-container .plyr__volume {
    background: rgba(255, 255, 255, 0.15);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .youposts-plyr-play-overlay {
        width: calc(var(--youposts-play-button-width, 80px) * 0.8);
        height: calc(var(--youposts-play-button-height, calc(var(--youposts-play-button-width, 80px) * 0.5625)) * 0.8);
    }

    .youposts-plyr-container .plyr__controls {
        padding: 5px;
    }

    .youposts-plyr-container .plyr__control--overlaid {
        padding: 15px 20px;
    }

    .youposts-plyr-container .plyr__time {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .youposts-plyr-play-overlay {
        width: calc(var(--youposts-play-button-width, 80px) * 0.6);
        height: calc(var(--youposts-play-button-width, 80px) * 0.6 * 0.5625);
    }

    .youposts-plyr-container .plyr__control--overlaid {
        padding: 12px 15px;
    }

    .youposts-plyr-container .plyr__time {
        font-size: 11px;
    }

    .youposts-plyr-container .plyr__controls {
        padding: 3px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .youposts-plyr-container {
        --plyr-video-range-track-background: rgba(255, 255, 255, 0.3);
    }

    .youposts-plyr-container .plyr__menu__container {
        background: rgba(20, 20, 20, 0.95);
    }
}

/* Accessibility enhancements */
.youposts-plyr-container .plyr__control:focus {
    outline: 2px solid var(--youposts-player-color, #8bc34a);
    outline-offset: 2px;
}

.youposts-plyr-play-overlay:focus {
    outline: 3px solid var(--youposts-player-color, #8bc34a);
    outline-offset: 3px;
}

/* Prevent text selection on controls */
.youposts-plyr-container .plyr__controls,
.youposts-plyr-play-overlay {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Smooth transitions for all interactive elements */
.youposts-plyr-container .plyr__control,
.youposts-plyr-container .plyr__progress input[type="range"],
.youposts-plyr-container .plyr__volume input[type="range"] {
    transition: all 0.2s ease;
}

/* ============================================
   LOGO OVERLAY
   Branding logo positioned on video player
   ============================================ */

.youposts-player-logo {
    position: absolute;
    z-index: 20;
    pointer-events: none;
    padding: 8px;
}

/* Logo positioning variants */
.youposts-player-logo.position-top-left {
    top: 0;
    left: 0;
}

.youposts-player-logo.position-top-right {
    top: 0;
    right: 0;
}

.youposts-player-logo.position-bottom-left {
    bottom: 0;
    left: 0;
}

.youposts-player-logo.position-bottom-right {
    bottom: 0;
    right: 0;
}

/* Logo image styling */
.youposts-player-logo img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Responsive adjustments for logo */
@media (max-width: 768px) {
    .youposts-player-logo {
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .youposts-player-logo {
        padding: 4px;
    }
}

/* ============================================
   STICKY PLAYER
   Floating mini-player when scrolled out of view
   ============================================ */

/* Sticky player positioning */
.youposts-simple-hero.youposts-sticky-active {
    position: fixed;
    z-index: 9999;
    transition: all 0.3s ease-in-out;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Position variants */
.youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-left"] {
    top: 20px;
    left: 20px;
}

.youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-right"] {
    top: 20px;
    right: 20px;
}

.youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-left"] {
    bottom: 20px;
    left: 20px;
}


/* ============================================
   STICKY PLAYER
   Floating mini-player when scrolled out of view
   ============================================ */

/* Sticky player positioning */
.youposts-simple-hero.youposts-sticky-active {
    position: fixed;
    z-index: 9999;
    transition: all 0.3s ease-in-out;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Position variants */
.youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-left"] {
    top: 20px;
    left: 20px;
}

.youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-right"] {
    top: 20px;
    right: 20px;
}

.youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-left"] {
    bottom: 20px;
    left: 20px;
}

.youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-right"] {
    bottom: 20px;
    right: 20px;
}

/* Sticky player width - uses CSS custom property set by JS */
.youposts-simple-hero.youposts-sticky-active {
    width: var(--youposts-sticky-width, 30vw);
    max-width: 500px;
    min-width: 250px;
}

/* Hide info section when sticky */
.youposts-simple-hero.youposts-sticky-active .youposts-simple-hero-info {
    display: none;
}

/* Close button - only visible when sticky */
.youposts-sticky-close {
    display: none;
}

.youposts-simple-hero.youposts-sticky-active .youposts-sticky-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    z-index: 10000;
    transition: background 0.2s ease, transform 0.2s ease;
}

.youposts-simple-hero.youposts-sticky-active .youposts-sticky-close:hover {
    background: rgba(0, 0, 0, 1);
    transform: scale(1.1);
}

.youposts-simple-hero.youposts-sticky-active .youposts-sticky-close:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Responsive adjustments for sticky player */
@media (max-width: 768px) {
    .youposts-simple-hero.youposts-sticky-active {
        width: calc(var(--youposts-sticky-width, 30vw) + 10vw);
        max-width: 400px;
    }

    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-left"],
    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-right"] {
        top: 10px;
    }

    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-left"],
    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-right"] {
        bottom: 10px;
    }

    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-left"],
    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-left"] {
        left: 10px;
    }

    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="top-right"],
    .youposts-simple-hero.youposts-sticky-active[data-sticky-position="bottom-right"] {
        right: 10px;
    }
}

@media (max-width: 480px) {
    .youposts-simple-hero.youposts-sticky-active {
        width: calc(var(--youposts-sticky-width, 30vw) + 15vw);
        max-width: 300px;
    }

    .youposts-sticky-close {
        width: 28px;
        height: 28px;
        font-size: 20px;
    }
}

/* Prevent sticky on very small screens */
@media (max-width: 320px) {
    .youposts-simple-hero.youposts-sticky-active {
        position: static;
        width: 100%;
    }

    .youposts-sticky-close {
        display: none !important;
    }
}

/* ============================================
   AUTO-HIDE CONTROLS
   Controls fade out after inactivity
   ============================================ */

/* Auto-hide controls - fade out after inactivity */
.youposts-auto-hide-controls .plyr__controls {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Show controls on hover (desktop) */
.youposts-auto-hide-controls:hover .plyr__controls {
    opacity: var(--youposts-controls-opacity, 0.9);
}

/* Show controls when focused (keyboard navigation) */
.youposts-auto-hide-controls:focus-within .plyr__controls {
    opacity: var(--youposts-controls-opacity, 0.9);
}

/* Show controls when manually triggered via JS (for touch devices) */
.youposts-auto-hide-controls.youposts-controls-visible .plyr__controls {
    opacity: var(--youposts-controls-opacity, 0.9);
}

/* Keep controls visible when interacting with them */
.youposts-auto-hide-controls .plyr__controls:hover {
    opacity: var(--youposts-controls-opacity, 0.9);
}
