// ==========================================================================
// Plyr variables
// ==========================================================================

// Settings
@plyr-border-box:                       true;
@plyr-touch-action:                     true;
@plyr-sr-only-important:                true;

// Colors
@plyr-color-main:                       @global-primary-background;

// Font
@plyr-font-family:                      @global-body-font-family;
@plyr-font-size-small:                  14px;
@plyr-font-size-base:                   @global-font-size;

// Captions
@plyr-captions-bg:                      fade(#000, 70%);
@plyr-captions-color:                   @global-contrast-color;
@plyr-font-size-captions-base:          @plyr-font-size-base;
@plyr-font-size-captions-medium:        ceil(@plyr-font-size-base * 1.5);
@plyr-font-size-captions-large:         (@plyr-font-size-base * 2);

// Controls
@plyr-control-icon-size:                18px;
@plyr-control-spacing:                  10px;
@plyr-control-padding:                  (@plyr-control-spacing * .7);
@plyr-video-controls-bg:                #000;
@plyr-video-control-color:              @global-contrast-color;
@plyr-video-control-color-hover:        @global-contrast-color;
@plyr-video-control-bg-hover:           @plyr-color-main;
@plyr-audio-controls-bg:                @global-contrast-color;
@plyr-audio-controls-border:            1px solid #dbe3e8;
@plyr-audio-control-color:              #565D64;
@plyr-audio-control-color-hover:        @global-contrast-color;
@plyr-audio-control-bg-hover:           @plyr-color-main;

// Tooltips
@plyr-tooltip-bg:                       fade(#000, 70%);
@plyr-tooltip-color:                    @global-contrast-color;
@plyr-tooltip-padding:                  (@plyr-control-spacing / 2);
@plyr-tooltip-arrow-size:               4px;
@plyr-tooltip-radius:                   3px;

// Progress
@plyr-progress-loading-size:            25px;
@plyr-progress-loading-bg:              fade(#000, 15%);
@plyr-video-progress-bg:                fade(@global-contrast-color, 25%);
@plyr-video-progress-buffered-bg:       @plyr-video-progress-bg;
@plyr-audio-progress-bg:                fade(#C6D6DB, 66%);
@plyr-audio-progress-buffered-bg:       @plyr-audio-progress-bg;

// Range sliders
@plyr-range-track-height:               8px;
@plyr-range-thumb-height:               floor(@plyr-range-track-height * 2);
@plyr-range-thumb-width:                floor(@plyr-range-track-height * 2);
@plyr-range-thumb-bg:                   @global-contrast-color;
@plyr-range-thumb-border:               2px solid transparent;
@plyr-range-thumb-shadow:               0 1px 1px fade(@plyr-video-controls-bg, 15%), 0 0 0 1px fade(#000, 15%);
@plyr-range-thumb-active-border-color:  @global-contrast-color;
@plyr-range-thumb-active-bg:            @plyr-video-control-bg-hover;
@plyr-range-thumb-active-scale:         1.25;
@plyr-video-range-track-bg:             @plyr-video-progress-buffered-bg;
@plyr-audio-range-track-bg:             @plyr-audio-progress-buffered-bg;
@plyr-range-selected-bg:                @plyr-color-main;

// Breakpoints
@plyr-bp-screen-sm:                     480px;
@plyr-bp-screen-md:                     768px;
@plyr-bp-screen-lg:                     1024px;

// 
// Mixins
// 

.plyr-range-track() {
    height: @plyr-range-track-height;
    background: transparent;
    border: 0;
    border-radius: (@plyr-range-track-height / 2);
    user-select: none;
}
.plyr-range-thumb() {
    position: relative;
    height: @plyr-range-thumb-height;
    width: @plyr-range-thumb-width;
    background: @plyr-range-thumb-bg;
    border: @plyr-range-thumb-border;
    border-radius: 100%;
    transition: @global-transition-background, @global-transition-border, @global-transition-transform;
    box-shadow: @plyr-range-thumb-shadow;
    box-sizing: border-box;
}
.plyr-range-thumb-active() {
    background: @plyr-range-thumb-active-bg;
    border-color: @plyr-range-thumb-active-border-color;
    transform: scale(@plyr-range-thumb-active-scale);
}

// Animation
// ---------------------------------------
@keyframes plyr-progress {
    to {
        background-position: @plyr-progress-loading-size 0;
    }
}

// Styles
// -------------------------------
// Base
.plyr {
    position: relative;
    max-width: 100%;
    min-width: 200px;
    font-family: @plyr-font-family;
    direction: ltr;

    & when (@plyr-border-box = true) {
        // border-box everything
        // http://paulirish.com/2012/box-sizing-border-box-ftw/
        &,
        *,
        *::after,
        *::before {
            box-sizing: border-box;
        }
    }

    & when (@plyr-touch-action = true) {
        // Fix 300ms delay
        a,
        button,
        input,
        label {
            touch-action: manipulation;
        }
    }

    // Focus
    &:focus {
        outline: 0;
    }

    // Media elements
    video,
    audio {
        width: 100%;
        height: auto;
        vertical-align: middle;
        border-radius: inherit;
    }

    // Range inputs
    // Specificity is for bootstrap compatibility
    input[type="range"] {
        display: block;
        height: (@plyr-range-thumb-height * @plyr-range-thumb-active-scale);
        width: 100%;
        margin: 0;
        padding: 0;
        vertical-align: middle;

        -webkit-appearance: none;
        appearance: none;
        cursor: pointer;
        border: none;
        background: transparent;

        // WebKit
        &::-webkit-slider-runnable-track {
            .plyr-range-track();
        }
        &::-webkit-slider-thumb {
            -webkit-appearance: none;
            margin-top: -((@plyr-range-thumb-height - @plyr-range-track-height) / 2);
            .plyr-range-thumb();
        }

        // Mozilla
        &::-moz-range-track {
            .plyr-range-track();
        }
        &::-moz-range-thumb {
            .plyr-range-thumb();
        }

        // Microsoft
        &::-ms-track {
            height: @plyr-range-track-height;
            background: transparent;
            border: 0;
            color: transparent;
        }
        &::-ms-fill-upper {
            .plyr-range-track();
        }
        &::-ms-fill-lower {
            .plyr-range-track();
            background: @plyr-range-selected-bg;
        }
        &::-ms-thumb {
            .plyr-range-thumb();
            // For some reason, Edge uses the -webkit margin above
            margin-top: 0;
        }
        &::-ms-tooltip {
            display: none;
        }

        // Focus styles
        &:focus {
            outline: 0;
        }
        &::-moz-focus-outer {
            border: 0;
        }
        &.tab-focus:focus {
            outline-offset: 3px;
        }

        // Pressed styles
        &:active {
            &::-webkit-slider-thumb {
                .plyr-range-thumb-active();
            }
            &::-moz-range-thumb {
                .plyr-range-thumb-active();
            }
            &::-ms-thumb {
                .plyr-range-thumb-active();
            }
        }
    }
}

// Video range inputs
.plyr--video input[type="range"].tab-focus:focus {
    outline: 1px dotted fade(@plyr-video-control-color, 50%);
}

// Audio range inputs
.plyr--audio input[type="range"].tab-focus:focus {
    outline: 1px dotted fade(@plyr-audio-control-color, 50%);
}

// Screen reader only elements
.plyr__sr-only {
    clip: rect(1px, 1px, 1px, 1px);
    overflow: hidden;

    // !important is not always needed
    & when (@plyr-sr-only-important = true) {
        position: absolute !important;
        padding: 0 !important;
        border: 0 !important;
        height: 1px !important;
        width: 1px !important;
    }
    & when (@plyr-sr-only-important = false) {
        position: absolute;
        padding: 0;
        border: 0;
        height: 1px;
        width: 1px;
    }
}

// Video
.plyr__video-wrapper {
    position: relative;
    background: #000;
    border-radius: inherit;
}

// Container for embeds
.plyr__video-embed {
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    border-radius: inherit;

    // Require overflow and z-index to force border-radius
    overflow: hidden;
    z-index: 0;

    iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border: 0;
        user-select: none;
    }

    // Vimeo hack
    > div {
        position: relative;
        padding-bottom: 200%;
        transform: translateY(-35.95%);
    }
}
// To allow mouse events to be captured if full support
.plyr .plyr__video-embed iframe {
    pointer-events: none;
}

// Captions
// --------------------------------------------------------------
// Hide default captions
.plyr video::-webkit-media-text-track-container {
    display: none;
}
.plyr__captions {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: (@plyr-control-spacing * 2);
    transform: translateY(-(@plyr-control-spacing * 4));
    transition: @global-transition-transform;
    color: @plyr-captions-color;
    font-size: @plyr-font-size-captions-base;
    text-align: center;
    font-weight: 400;

    span {
        border-radius: 2px;
        padding: floor(@plyr-control-spacing / 3) @plyr-control-spacing;
        background: @plyr-captions-bg;
        box-decoration-break: clone;
        line-height: 150%;
    }
    span:empty {
        display: none;
    }

    @media (min-width: @plyr-bp-screen-md) {
        font-size: @plyr-font-size-captions-medium;
    }
}
.plyr--captions-active .plyr__captions {
    display: block;
}
.plyr--hide-controls .plyr__captions {
    transform: translateY(-(@plyr-control-spacing * 1.5));
}
// Large captions in full screen on larger screens
@media (min-width: @plyr-bp-screen-lg) {
    .plyr--fullscreen-active .plyr__captions {
        font-size: @plyr-font-size-captions-large;
    }
}

// Controls
// --------------------------------------------------------------
// Hide native controls
.plyr ::-webkit-media-controls {
    display: none;
}

// Playback controls
.plyr__controls {
    display: flex;
    align-items: center;
    line-height: 1;
    text-align: center;

    // Spacing
    > button,
    .plyr__progress,
    .plyr__time {
        margin-left: (@plyr-control-spacing / 2);

        &:first-child {
            margin-left: 0;
        }
    }
    .plyr__volume {
        margin-left: (@plyr-control-spacing / 2);
    }
    [data-plyr="pause"] {
        margin-left: 0;
    }

    // Buttons
    button {
        position: relative;
        display: inline-block;
        flex-shrink: 0;
        overflow: visible; // IE11
        vertical-align: middle;
        padding: @plyr-control-padding;
        border: 0;
        background: transparent;
        border-radius: 3px;
        cursor: pointer;
        transition: @global-transition-background, @global-transition-color, @global-transition-opacity;
        color: inherit;

        svg {
            width: @plyr-control-icon-size;
            height: @plyr-control-icon-size;
            display: block;
            fill: currentColor;
        }

        // Default focus
        &:focus {
            outline: 0;
        }
    }

    // Hide toggle icons by default
    .icon--exit-fullscreen,
    .icon--muted,
    .icon--captions-on {
        display: none;
    }

    @media (min-width: @plyr-bp-screen-sm) {
        > button,
        .plyr__progress,
        .plyr__time {
            margin-left: @plyr-control-spacing;
        }
    }
}
// Hide controls
.plyr--hide-controls .plyr__controls {
    opacity: 0;
    pointer-events: none;
}

// Video controls
.plyr--video .plyr__controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: (@plyr-control-spacing * 5) @plyr-control-spacing @plyr-control-spacing;
    background: linear-gradient(fade(@plyr-video-controls-bg, 0%), fade(@plyr-video-controls-bg, 50%));
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
    color: @plyr-video-control-color;
    transition: @global-transition-opacity;

    button {
        // Hover and tab focus
        &.tab-focus:focus,
        &:hover {
            background: @plyr-video-control-bg-hover;
            color: @plyr-video-control-color-hover;
        }
    }
}

// Audio controls
.plyr--audio .plyr__controls {
    padding: @plyr-control-spacing;
    border-radius: inherit;
    background: @plyr-audio-controls-bg;
    border: @plyr-audio-controls-border;
    color: @plyr-audio-control-color;

    button {
        // Hover and tab focus
        &.tab-focus:focus,
        &:hover {
            background: @plyr-audio-control-bg-hover;
            color: @plyr-audio-control-color-hover;
        }
    }
}

// Large play button (video only)
.plyr__play-large {
    display: none;
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: @plyr-control-spacing;
    background: @plyr-video-control-bg-hover;
    border: 4px solid currentColor;
    border-radius: 100%;
    box-shadow: 0 1px 1px @global-darkest-shadow, inset 0 0 0 30px @global-darker-shadow, 0 0 0 10px @global-darker-shadow;
    color: @plyr-video-control-color;
    transition: @global-transition;

    svg {
        position: relative;
        left: 2px;
        width: 20px;
        height: 20px;
        display: block;
        fill: currentColor;
    }

    &:focus {
        outline: 1px dotted fade(@plyr-video-control-color, 50%);
    }
}
.plyr .plyr__play-large {
    display: inline-block;
}
.plyr--audio .plyr__play-large {
    display: none;
}
.plyr--playing .plyr__play-large {
    opacity: 0;
    visibility: hidden;
}

// States
.plyr__controls [data-plyr="pause"],
.plyr--playing .plyr__controls [data-plyr="play"] {
    display: none;
}
.plyr--playing .plyr__controls [data-plyr="pause"] {
    display: inline-block;
}

// Change icons on state change
.plyr--fullscreen-active .icon--exit-fullscreen,
.plyr--muted .plyr__controls .icon--muted,
.plyr--captions-active .plyr__controls .icon--captions-on {
    display: block;

    & + svg {
        display: none;
    }
}

// Some options are hidden by default
.plyr [data-plyr="captions"],
.plyr [data-plyr="fullscreen"] {
    display: none;
}
.plyr--captions-enabled [data-plyr="captions"],
.plyr--fullscreen-enabled [data-plyr="fullscreen"] {
    display: inline-block;
}

// Tooltips
// --------------------------------------------------------------
.plyr__tooltip {
    position: absolute;
    z-index: 2;
    bottom: 100%;
    margin-bottom: (@plyr-tooltip-padding * 2);
    padding: @plyr-tooltip-padding (@plyr-tooltip-padding * 1.5);
    pointer-events: none;

    opacity: 0;
    background: @plyr-tooltip-bg;
    border-radius: @plyr-tooltip-radius;

    color: @plyr-tooltip-color;
    font-size: @plyr-font-size-small;
    line-height: 1.3;

    transform: translate(-50%, 10px) scale(0.8);
    transform-origin: 50% 100%;
    transition: transform 0.2s 0.1s ease, opacity 0.2s 0.1s ease;

    &::before {
        // Arrows
        content: "";
        position: absolute;
        width: 0;
        height: 0;
        left: 50%;
        transform: translateX(-50%);

        // The background triangle
        bottom: -@plyr-tooltip-arrow-size;
        border-right: @plyr-tooltip-arrow-size solid transparent;
        border-top: @plyr-tooltip-arrow-size solid @plyr-tooltip-bg;
        border-left: @plyr-tooltip-arrow-size solid transparent;
        z-index: 2;
    }
}
.plyr button:hover .plyr__tooltip,
.plyr button.tab-focus:focus .plyr__tooltip,
.plyr__tooltip--visible {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}
.plyr button:hover .plyr__tooltip {
    z-index: 3;
}

// First tooltip
.plyr__controls button:first-child .plyr__tooltip {
    left: 0;
    transform: translate(0, 10px) scale(0.8);
    transform-origin: 0 100%;

    &::before {
        left: (@plyr-control-icon-size / 2) + @plyr-control-padding;
    }
}

// Last tooltip
.plyr__controls button:last-child .plyr__tooltip {
    right: 0;
    transform: translate(0, 10px) scale(0.8);
    transform-origin: 100% 100%;

    &::before {
        left: auto;
        right: (@plyr-control-icon-size / 2) + @plyr-control-padding;
        transform: translateX(50%);
    }
}

.plyr__controls button:first-child,
.plyr__controls button:last-child {
    &:hover .plyr__tooltip,
    &.tab-focus:focus .plyr__tooltip,
    .plyr__tooltip--visible {
        transform: translate(0, 0) scale(1);
    }
}

// Playback progress
// --------------------------------------------------------------
// <progress> element
.plyr__progress {
    position: relative;
    display: none;
    flex: 1;

    input[type="range"] {
        position: relative;
        z-index: 2;

        &::-webkit-slider-runnable-track {
            background: transparent;
        }
        &::-moz-range-track {
            background: transparent;
        }
        &::-ms-fill-upper {
            background: transparent;
        }
    }

    // Seek tooltip to show time
    .plyr__tooltip {
        left: 0;
    }
}
.plyr .plyr__progress {
    display: inline-block;
}

.plyr__progress--buffer,
.plyr__progress--played,
.plyr__volume--display {
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: @plyr-range-track-height;
    margin: -(@plyr-range-track-height / 2) 0 0;
    padding: 0;
    vertical-align: top;
    appearance: none;
    border: none;
    border-radius: 100px;

    &::-webkit-progress-bar {
        background: transparent;
    }
    &::-webkit-progress-value {
        background: currentColor;
        border-radius: 100px;
        min-width: @plyr-range-track-height;
    }
    &::-moz-progress-bar {
        background: currentColor;
        border-radius: 100px;
        min-width: @plyr-range-track-height;
    }
    &::-ms-fill {
        border-radius: 100px;
    }
}
.plyr__progress--played,
.plyr__volume--display {
    z-index: 1;
    color: @plyr-range-selected-bg;
    background: transparent;
    transition: none;

    &::-webkit-progress-value {
        min-width: @plyr-range-track-height;
        max-width: 99%;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        transition: none;
    }
    &::-moz-progress-bar {
        min-width: @plyr-range-track-height;
        max-width: 99%;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        transition: none;
    }
    &::-ms-fill {
        display: none;
    }
}
.plyr__progress--buffer {
    &::-webkit-progress-value {
        transition: @global-transition-width;
    }
    &::-moz-progress-bar {
        transition: @global-transition-width;
    }
    &::-ms-fill {
        transition: @global-transition-width;
    }
}
.plyr--video .plyr__progress--buffer,
.plyr--video .plyr__volume--display {
    background: @plyr-video-range-track-bg;
}
.plyr--video .plyr__progress--buffer {
    color: @plyr-video-progress-buffered-bg;
}
.plyr--audio .plyr__progress--buffer,
.plyr--audio .plyr__volume--display {
    background: @plyr-audio-range-track-bg;
}
.plyr--audio .plyr__progress--buffer {
    color: @plyr-audio-progress-buffered-bg;
}

// Loading state
.plyr--loading .plyr__progress--buffer {
    animation: plyr-progress 1s linear infinite;
    background-size: @plyr-progress-loading-size @plyr-progress-loading-size;
    background-repeat: repeat-x;
    background-image: linear-gradient(
        -45deg,
        @plyr-progress-loading-bg 25%,
        transparent 25%,
        transparent 50%,
        @plyr-progress-loading-bg 50%,
        @plyr-progress-loading-bg 75%,
        transparent 75%,
        transparent
    );
    color: transparent;
}
.plyr--video.plyr--loading .plyr__progress--buffer {
    background-color: @plyr-video-progress-buffered-bg;
}
.plyr--audio.plyr--loading .plyr__progress--buffer {
    background-color: @plyr-audio-progress-buffered-bg;
}

// Time
// --------------------------------------------------------------
.plyr__time {
    display: inline-block;
    vertical-align: middle;
    font-size: @plyr-font-size-small;
}
// Media duration hidden on small screens
.plyr__time + .plyr__time {
    display: none;

    @media (min-width: @plyr-bp-screen-md) {
        display: inline-block;
    }

    // Add a slash in before
    &::before {
        content: "\2044";
        margin-right: @plyr-control-spacing;
    }
}

// Volume
// --------------------------------------------------------------
.plyr__volume {
    display: none;
}
.plyr .plyr__volume {
    flex: 1;
    position: relative;

    input[type="range"] {
        position: relative;
        z-index: 2;
    }
    @media (min-width: @plyr-bp-screen-sm) {
        display: block;
        max-width: 60px;
    }
    @media (min-width: @plyr-bp-screen-md) {
        max-width: 100px;
    }
}

// Hide sound controls on iOS
// It's not supported to change volume using JavaScript:
// https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
.plyr--is-ios .plyr__volume,
.plyr--is-ios [data-plyr="mute"] {
    display: none !important;
}

// Fullscreen
// --------------------------------------------------------------
.plyr--fullscreen-active {
    height: 100%;
    width: 100%;
    background: #000;
    border-radius: 0 !important;

    video {
        height: 100%;
    }
    .plyr__video-wrapper {
        height: 100%;
        width: 100%;
    }
    .plyr__video-embed {
        // Revert overflow change
        overflow: visible;
    }

    // Vimeo requires some different styling
    &.plyr--vimeo .plyr__video-wrapper {
        height: 0;
        top: 50%;
        transform: translateY(-50%);
    }
}

// Fallback for unsupported browsers
.plyr--fullscreen-fallback.plyr--fullscreen-active {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000000;
}
