/*
 * Video Player Styles
 * Video.js default UI theme aligned to site design tokens
 * Supports responsive aspect ratios from vm_video_ratio meta
 */

/* === Player Container === */
.player-wrapper {
    position: relative;
    width: 100%;
    background: #000;
    border-radius: var(--card-radius);
    overflow: hidden;
    margin-bottom: var(--space-xl);
    outline: none;
}

/* Requirement: show playlist next to player on desktop and stack on mobile.
   Approach: wrap player/sidebar in a responsive grid that collapses below desktop width.
   Assumption: playlist sidebar can appear for both player and membership-gate states.
   Side effect: player wrapper margin is handled by layout container when sidebar is present. */
.single-video-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
    align-items: start;
    margin-bottom: var(--space-xl);
}

.single-video-layout .player-wrapper {
    margin-bottom: 0;
}

/* Requirement: keep shared layout spacing consistent when the main column renders membership gate.
   Approach: remove gate bottom margin only when gate is inside the two-column media layout.
   Assumption: standalone gate rendering should retain its original margin behavior.
   Side effect: prevents duplicate vertical spacing under gated + playlist views. */
.single-video-layout .membership-gate {
    margin-bottom: 0;
}

.single-video-layout__main,
.single-video-layout__side {
    min-width: 0;
}

@media (min-width: 1200px) {
    .single-video-layout {
        grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    }
}

/* Aspect ratio container - padding-top set dynamically from vm_video_ratio */
/* Requirement: add min-height so the player never collapses to nothing on narrow screens
   before the aspect-ratio padding-top resolves (e.g. zero-width flex children). */
.player-aspect {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* Default 16:9, overridden inline by template */
    min-height: 200px;
    background: #000;
}

/* Requirement: use default Video.js controls without breaking existing responsive ratio behavior.
   Approach: pin the player box to the ratio container with absolute fill.
   Assumption: Video.js control bar layout handles desktop/mobile interactions.
   Side effect: legacy custom control selectors are removed from this stylesheet. */
.player-aspect .video-js {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-family: var(--font-family);
    background-color: #000;
    color: #fff;
}

.player-aspect .video-js .vjs-tech {
    object-fit: contain;
}

.player-aspect .video-js .vjs-poster {
    background-size: cover;
}

.player-aspect .video-js .vjs-control-bar {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
}

.player-aspect .video-js .vjs-big-play-button {
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    width: 2.4em;
    height: 2.4em;
    line-height: 2.4em;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.player-aspect .video-js:hover .vjs-big-play-button,
.player-aspect .video-js .vjs-big-play-button:focus {
    background: rgba(0, 0, 0, 0.75);
    border-color: rgba(255, 255, 255, 0.55);
}

.player-aspect .video-js .vjs-play-progress,
.player-aspect .video-js .vjs-volume-level,
.player-aspect .video-js .vjs-slider-bar {
    background-color: var(--color-accent);
}

.player-aspect .video-js .vjs-load-progress div {
    background: rgba(255, 255, 255, 0.22);
}

.player-aspect .video-js .vjs-slider {
    background-color: rgba(255, 255, 255, 0.24);
}

.player-aspect .video-js .vjs-time-control,
.player-aspect .video-js .vjs-menu-button,
.player-aspect .video-js .vjs-control {
    color: #fff;
}

.player-aspect .video-js .vjs-playback-rate .vjs-playback-rate-value {
    line-height: 3em;
}

/* === Playlist Sidebar === */
.playlist-sidebar {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--card-radius);
    overflow: hidden;
}

.playlist-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.playlist-sidebar__title-link {
    color: var(--color-text);
    min-width: 0;
}

.playlist-sidebar__title {
    font-size: var(--font-size-base);
    line-height: var(--line-height-tight);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-sidebar__count {
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    white-space: nowrap;
}

.playlist-sidebar__list {
    max-height: 560px;
    overflow-y: auto;
}

.playlist-sidebar__item {
    border-bottom: 1px solid var(--color-border);
}

.playlist-sidebar__item:last-child {
    border-bottom: none;
}

.playlist-sidebar__item.is-current {
    background: rgba(255, 77, 77, 0.12);
}

.playlist-sidebar__link {
    display: grid;
    grid-template-columns: 34px 72px minmax(0, 1fr);
    gap: var(--space-sm);
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text);
}

.playlist-sidebar__link:hover {
    background: var(--color-bg-hover);
}

.playlist-sidebar__order {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-align: right;
}

.playlist-sidebar__thumb {
    width: 72px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: #000;
}

.playlist-sidebar__meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.playlist-sidebar__item-title {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-tight);
    color: var(--color-text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.playlist-sidebar__item-sub {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Video Info Section === */
.video-info {
    margin-bottom: var(--space-xl);
}

.video-info__title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    line-height: var(--line-height-tight);
    margin-bottom: var(--space-md);
}

.video-info__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.video-info__categories a {
    color: var(--color-accent);
}

/* Post tags displayed as chip pills below video metadata */
.video-info__tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
}

.video-info__tag-chip {
    display: inline-block;
    padding: 3px 10px;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
}

.video-info__tag-chip:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
}

/* === Video Description / Gallery === */
.video-description {
    padding: var(--space-lg);
    background: var(--color-bg-elevated);
    border-radius: var(--card-radius);
    margin-bottom: var(--space-xl);
    line-height: var(--line-height);
    color: var(--color-text-secondary);
}

.video-description img {
    border-radius: var(--radius-sm);
    margin: var(--space-sm) 0;
}

/* Requirement: preview/free-watch playback must expose a clear intent control before source fetch.
   Approach: overlay a keyboard-focusable play button above the poster until JS starts loading the source.
   Side effect: preview quota is consumed only after a deliberate click/tap/keyboard action. */
.player-intent-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    background: rgba(0, 0, 0, 0.32);
}

.player-intent-overlay[hidden] {
    display: none;
}

.player-intent-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: 52px;
    padding: var(--space-sm) var(--space-lg);
    color: #fff;
    background: var(--color-accent);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: var(--radius-full);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: 700;
    line-height: 1;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.player-intent-button:hover,
.player-intent-button:focus-visible {
    transform: translateY(-1px);
    opacity: 0.92;
}

.player-intent-button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.player-intent-button__icon {
    display: inline-flex;
    width: 1em;
    height: 1em;
}
.player-intent-button__icon svg {
    width: 100%;
    height: 100%;
}

/* Requirement: resumed paid videos need a clear but unobtrusive restart affordance.
   Approach: place a compact notice above the control bar, using existing accent/button language.
   Side effect: notice remains hidden for completed videos because backend returns no resume point. */
.player-resume-notice {
    position: absolute;
    left: var(--space-md);
    right: var(--space-md);
    bottom: calc(var(--space-xl) + var(--space-lg));
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    max-width: 520px;
    padding: var(--space-xs) var(--space-sm);
    color: #fff;
    background: rgba(0, 0, 0, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-tight);
}

.player-resume-notice[hidden] {
    display: none;
}

.player-resume-notice__text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.player-resume-notice__restart {
    min-height: 34px;
    padding: 0 var(--space-sm);
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.36);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
}

.player-resume-notice__restart:hover,
.player-resume-notice__restart:focus-visible {
    border-color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* === Loading Overlay === */
/* Requirement: increase loading scrim opacity from 0.5 to 0.7 so spinner is readable over bright thumbnails.
   Approach: darken background to improve contrast without obscuring the spinner animation. */
.player-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    background: rgba(0, 0, 0, 0.7);
    z-index: 3;
}

.player-loading__status {
    color: #fff;
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-align: center;
}

/* === Error Overlay === */
.player-error {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.82);
    z-index: 4;
}

/* Requirement: keyboard-safe player retry must keep a visible focus target after playback errors.
   Approach: focus the retry button from JS while preserving an overlay ring if the alert itself receives focus. */
.player-error:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: -4px;
}

.player-error__content {
    text-align: center;
    padding: var(--space-lg);
    max-width: 320px;
}

.player-error__icon {
    width: 48px;
    height: 48px;
    color: var(--color-accent);
    margin-bottom: var(--space-md);
}

.player-error__msg {
    color: #fff;
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    margin-bottom: var(--space-lg);
}

.player-error__retry {
    display: inline-block;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.player-error__retry:hover {
    opacity: 0.85;
}

/* === Conversion Overlays: quota upsell + video-end screen ===
   Requirement: quota exhaustion and video end are conversion moments — show subscribe/next actions in-player.
   Approach: reuse the gate/player scrim language (dark overlay is an allowed gradient surface) with accent CTAs. */
.player-upsell,
.player-end-screen {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    background: rgba(0, 0, 0, 0.85);
    text-align: center;
}

.player-upsell__content,
.player-end-screen__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    max-width: 480px;
    width: 100%;
}

.player-upsell__title,
.player-end-screen__title {
    color: #fff;
    font-size: var(--font-size-lg);
    font-weight: 700;
    line-height: var(--line-height-tight);
    margin: 0;
}

.player-upsell__desc,
.player-end-screen__desc {
    color: rgba(255, 255, 255, 0.78);
    font-size: var(--font-size-sm);
    line-height: var(--line-height);
    margin: 0;
}

.player-upsell__actions,
.player-end-screen__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-xs);
}

/* Primary conversion CTA mirrors the intent-button emphasis. */
.player-upsell__cta,
.player-end-screen__play-now {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: var(--space-sm) var(--space-lg);
    color: #fff;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 700;
    text-decoration: none;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.player-upsell__cta:hover,
.player-upsell__cta:focus-visible,
.player-end-screen__play-now:hover,
.player-end-screen__play-now:focus-visible {
    transform: translateY(-1px);
    opacity: 0.92;
    color: #fff;
}

/* Secondary actions (login / cancel autoplay / replay) use the ghost outline language. */
.player-upsell__login,
.player-end-screen__cancel,
.player-end-screen__replay {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: var(--space-xs) var(--space-md);
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.36);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    text-decoration: none;
    cursor: pointer;
}

.player-upsell__login:hover,
.player-upsell__login:focus-visible,
.player-end-screen__cancel:hover,
.player-end-screen__cancel:focus-visible,
.player-end-screen__replay:hover,
.player-end-screen__replay:focus-visible {
    border-color: #fff;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.player-end-screen__close {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: var(--radius-full);
    cursor: pointer;
}

.player-end-screen__close svg {
    width: 18px;
    height: 18px;
}

.player-end-screen__close:hover,
.player-end-screen__close:focus-visible {
    background: rgba(255, 255, 255, 0.18);
}

.player-end-screen__kicker {
    color: rgba(255, 255, 255, 0.66);
    font-size: var(--font-size-xs);
    letter-spacing: 0.08em;
}

/* Up-next hero card: bounded poster keeps the overlay inside short/vertical players. */
.player-end-screen__next {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    text-decoration: none;
    min-width: 0;
}

.player-end-screen__next-poster {
    max-width: 280px;
    width: 100%;
    max-height: 32vh;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.player-end-screen__next-title {
    color: #fff;
    font-size: var(--font-size-base);
    line-height: var(--line-height-tight);
    overflow-wrap: anywhere;
}

.player-end-screen__countdown {
    color: rgba(255, 255, 255, 0.78);
    font-size: var(--font-size-sm);
    margin: 0;
}

/* Related picks: 3-up on desktop, single column stack on phones. */
.player-end-screen__cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-sm);
    width: 100%;
}

.player-end-screen__card {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    text-decoration: none;
    min-width: 0;
}

.player-end-screen__card-poster {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.player-end-screen__card-title {
    color: #fff;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-tight);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.player-end-screen__footer {
    margin-top: var(--space-xs);
}

/* Mobile: keep overlays scannable at 375px without horizontal overflow. */
@media (max-width: 640px) {
    .player-upsell,
    .player-end-screen {
        padding: var(--space-md);
        overflow-y: auto;
    }

    .player-end-screen__cards {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: var(--space-xs);
    }

    .player-end-screen__card-title {
        -webkit-line-clamp: 1;
    }

    .player-end-screen__next-poster {
        max-width: 220px;
        max-height: 26vh;
    }
}

/* === Mobile: tune default Video.js controls for touch === */
@media (max-width: 640px) {
    .single-video-layout {
        gap: var(--space-md);
    }

    .playlist-sidebar__list {
        max-height: none;
    }

    .player-aspect .video-js {
        font-size: 12px;
    }

    .player-aspect .video-js .vjs-control {
        width: 2.9em;
    }

    .player-aspect .video-js .vjs-time-control {
        min-width: 0;
        padding-left: 0.4em;
        padding-right: 0.4em;
    }

    .player-aspect .video-js .vjs-volume-panel {
        display: none;
    }
}

/* === Touch Target Minimums (WCAG 2.5.5) ===
   Requirement: touch targets must be at least 44px for mobile accessibility.
   Approach: increase video.js big play button on small screens for easier tapping. */
@media (max-width: 640px) {
    .video-js .vjs-big-play-button {
        width: 3em;
        height: 3em;
        line-height: 3em;
    }
}

/* Requirement: playlist sidebar links need a minimum tap height on mobile.
   Approach: enforce min-height 44px on the link element that spans the full row. */
.playlist-sidebar__link {
    min-height: 44px;
}

/* Requirement: playlist sidebar link needs a visible focus ring for keyboard navigation.
   Approach: use inset outline so the focus indicator stays within the row border. */
.playlist-sidebar__link:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: -2px;
}

/* === Playback Guards: viewer watermark + idle "still watching?" popup ===
   Requirement: playback shows a moving per-viewer watermark (screen-recording deterrent) and an
   idle pause popup after the admin-configured minutes; both are appended to the Video.js root
   (player.el()) by video-player.js so they remain visible in fullscreen.
   Note: watermark opacity is intentionally CSS-only (no admin setting) — retune the variable below. */
.player-wrapper {
    --yisekan-watermark-opacity: 0.35;
}

.player-watermark {
    position: absolute;
    top: 10%;
    left: 10%;
    z-index: 30; /* above the video surface; pointer-events:none keeps controls clickable under it */
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    color: #fff;
    opacity: var(--yisekan-watermark-opacity, 0.35);
    font-size: clamp(11px, 1.6vw, 15px);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    /* Slow drift instead of a hard jump when JS repositions it every ~30s. */
    transition: top 1s ease, left 1s ease;
}

.player-idle-overlay {
    position: absolute;
    inset: 0;
    z-index: 40; /* above the control bar — the popup is the only expected action while idle */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: rgba(0, 0, 0, 0.75);
}

.player-idle-overlay__content {
    max-width: 420px;
    text-align: center;
}

.player-idle-overlay__title {
    margin: 0 0 var(--space-xs);
    color: #fff;
    font-size: clamp(18px, 2.4vw, 24px);
    font-weight: 700;
}

.player-idle-overlay__desc {
    margin: 0 0 var(--space-md);
    color: rgba(255, 255, 255, 0.75);
    font-size: clamp(13px, 1.8vw, 15px);
}

/* Resume button reuses the intent-button visual language (accent pill). */
.player-idle-overlay__resume {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px; /* WCAG touch target on mobile */
    padding: var(--space-sm) var(--space-lg);
    color: #fff;
    background: var(--color-accent);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: var(--radius-full);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: 700;
    line-height: 1;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.player-idle-overlay__resume:hover,
.player-idle-overlay__resume:focus-visible {
    transform: translateY(-1px);
    opacity: 0.92;
}

.player-idle-overlay__resume:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

/* Portrait (9:16) and small players: tighten spacing so the dialog always fits the frame. */
@media (max-width: 640px) {
    .player-idle-overlay__content {
        max-width: 90%;
    }
}
