/* =========================================================================
   Watch Next  —  every viewer.
   1) A translucent "Up next" panel pinned to the right of the player, shown
      while the video is idle/paused and sliding out to the right once playback
      starts.
   2) End-of-video autoplay overlay with a 5s closing progress ring.
   Both live inside .wn-layer, which watch-next.js attaches to the Video.js
   player element so everything also renders when the player is fullscreen.
   Brand tokens: #d20000 (primary), #231f20 (ink), #a6988a (muted).
   ========================================================================= */

.videobox {
    position: relative;
    overflow: hidden;
    /* contain .wn-layer's stacking context so it can't rise above page chrome */
    isolation: isolate;
}

/* Wrapper attached to player.el(); .video-js is position:relative + overflow
   :hidden already, so this just scopes our bits and lets clicks fall through
   to the player everywhere except on our own controls. */
.wn-layer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 30;
    /* size the overlay against the player itself (cqmin), so the ring/counter
       scale the same way inline and in fullscreen. Old browsers ignore this and
       fall back to the fixed px values below. */
    container-type: size;
}

/* the overlay takes clicks (backdrop / ring); the side panel manages its own
   pointer-events so the player controls stay reachable beneath it */
.wn-layer > .wn-overlay {
    pointer-events: auto;
}

/* ---------- Idle "Up next" side panel --------------------------------- */
.wn-side {
    position: absolute;
    top: 0;
    right: 0;
    /* clear the control bar so fullscreen / settings stay usable and visible */
    bottom: calc(3.5em + 10px);
    /* above .wn-overlay so the countdown never blurs or dims the panel */
    z-index: 2;
    width: min(300px, 42%);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(to left, rgba(35, 31, 32, 0.85), rgba(35, 31, 32, 0.5));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 6px 0 0 6px;
    color: #fff;
    /* full height, but let clicks fall through to the player controls where the
       panel has no content of its own (only the card + button are interactive) */
    pointer-events: none;
    /* hidden by default: parked off the right edge, clipped by the layer.
       watch-next.js adds .is-shown only after the video has played and paused. */
    transform: translateX(calc(100% + 2px));
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.wn-side.is-shown {
    transform: none;
}

.wn-side__card,
.wn-side__btn {
    pointer-events: auto;
}

.wn-side__label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #a6988a;
}

.wn-side__card {
    display: block;
    text-decoration: none;
    color: inherit;
}

.wn-side__thumb {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    border-radius: 4px;
    overflow: hidden;
    background: #231f20;
}

.wn-side__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* old TV browsers (Chromium < 88) ignore aspect-ratio: let the image set the
   box height itself instead of collapsing to zero */
@supports not (aspect-ratio: 16 / 9) {
    .wn-side__thumb img { height: auto; }
}

.wn-side__thumb::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 0 8px 14px;
    border-color: transparent transparent transparent #fff;
    transform: translate(-40%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.wn-side__card:hover .wn-side__thumb::after {
    opacity: 0.9;
}

.wn-side__title {
    display: -webkit-box;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wn-side__btn {
    margin: 0 !important;      /* override global .btn-primary auto-centering */
    max-width: none !important;
    min-width: 0;
    width: 100%;
}

/* Phones: swap the full-height rail for a small card tucked into the
   lower-right corner - title + Watch Next only, no thumbnail. */
@media (max-width: 575.98px) {
    .wn-side {
        top: auto;
        bottom: calc(3.2em + 6px);
        width: min(160px, 52%);
        padding: 8px 10px 9px;
        gap: 4px;
        border-radius: 6px;
        background: rgba(35, 31, 32, 0.9);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    .wn-side__thumb {
        display: none;
    }
    .wn-side__label {
        font-size: 9px;
        letter-spacing: 0.08em;
    }
    .wn-side__title {
        margin-top: 0;
        font-size: 11px;
        line-height: 1.3;
        -webkit-line-clamp: 1;
    }
    .wn-side__btn {
        padding: 8px 6px !important;
        font-size: 11px !important;
        letter-spacing: 0.02em;
    }
}

@media (prefers-reduced-motion: reduce) {
    .wn-side {
        transition: none;
    }
}

/* ---------- End-of-video autoplay overlay ---------------------------- */
.wn-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    background: rgba(35, 31, 32, 0.86);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: wn-fade 0.25s ease both;
}

@keyframes wn-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.wn-overlay__inner {
    max-width: 460px;
    max-width: clamp(420px, 62cqmin, 760px);
    width: 100%;
    color: #fff;
}

.wn-overlay__eyebrow {
    font-size: 12px;
    font-size: clamp(12px, 1.5cqmin, 17px);
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #a6988a;
    margin: 0 0 0.5rem;
}

.wn-overlay__title {
    font-size: clamp(15px, 2.4vw, 20px);
    font-size: clamp(17px, 3.2cqmin, 38px);
    font-weight: 600;
    line-height: 1.35;
    margin: 0 0 clamp(1rem, 2.6cqmin, 2.4rem);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Circular dial = cancel button.
   Selector is doubled (.wn-overlay .wn-overlay__dial) so it outweighs Video.js'
   `.video-js button { width: 40px; display: inline-block }` reset once the panel
   lives inside the player element. */
.wn-overlay .wn-overlay__dial {
    position: relative;
    width: 104px;
    height: 104px;
    width: clamp(110px, 18cqmin, 230px);
    height: clamp(110px, 18cqmin, 230px);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wn-overlay__dial svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.wn-overlay__dial circle {
    fill: rgba(255, 255, 255, 0.08);
    stroke-width: 6;
}

.wn-overlay__track {
    stroke: rgba(255, 255, 255, 0.25);
}

.wn-overlay__progress {
    fill: none;
    stroke: #d20000;
    stroke-linecap: round;
    /* --wn-circ is set inline by JS (2·π·r). Ring starts empty, fills to full. */
    stroke-dasharray: var(--wn-circ, 289);
    stroke-dashoffset: var(--wn-circ, 289);
}

.wn-overlay.is-running .wn-overlay__progress {
    animation: wn-fill var(--wn-duration, 5s) linear forwards;
}

@keyframes wn-fill {
    to { stroke-dashoffset: 0; }
}

.wn-overlay__count {
    position: relative;
    font-size: 30px;
    font-size: clamp(32px, 6cqmin, 66px);
    font-weight: 600;
    line-height: 1;
    color: #fff;
}

.wn-overlay__cancel {
    position: absolute;
    left: 50%;
    bottom: -1.9em;
    transform: translateX(-50%);
    font-size: 11px;
    font-size: clamp(11px, 1.4cqmin, 16px);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #a6988a;
    white-space: nowrap;
}

.wn-overlay__dial:hover .wn-overlay__cancel,
.wn-overlay__dial:focus-visible .wn-overlay__cancel {
    color: #fff;
}

/* Overlay sizing (dial / counter / title) is driven by cqmin against .wn-layer,
   so it already scales up in fullscreen - no separate fullscreen block needed.
   The side panel still gets a wider footprint on a fullscreen-sized player. */
.vjs-fullscreen .wn-side {
    width: clamp(300px, 24vw, 420px);
}

/* Playlist mode: the queue rail (blocks/watch/playlist-queue.php) already
   shows "up next" beside the player, so this card would be a duplicate -
   except in fullscreen, where the rail (outside the player element) isn't
   visible at all and this becomes the only "up next" UI available. */
.wn-side--playlist {
    display: none;
}

.vjs-fullscreen .wn-side--playlist {
    display: flex;
}

.vjs-fullscreen .wn-side__title {
    font-size: clamp(15px, 1.6vmin, 21px);
}

@media (max-width: 575.98px) {
    .wn-overlay .wn-overlay__dial { width: 92px; height: 92px; }
    .wn-overlay__count { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
    .wn-overlay,
    .wn-overlay.is-running .wn-overlay__progress {
        animation: none;
    }
}
