/*
 * x.ai-style video lightbox
 * Full-viewport dim + blur backdrop, centered video stage,
 * invisible inset play/pause hit target (no chrome box).
 */

.xai-video-modal {
    --modal-backdrop-blur: 40px;
    --modal-backdrop-fade: 0.4s;
    --modal-backdrop-ease: cubic-bezier(0.22, 1, 0.36, 1);
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity var(--modal-backdrop-fade) var(--modal-backdrop-ease),
        visibility var(--modal-backdrop-fade) var(--modal-backdrop-ease);
}

.xai-video-modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Keep flex layout while closed so open/close transitions can run */
.xai-video-modal.hidden {
    display: flex !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Open state wins over .hidden during the enter transition (JS removes .hidden first) */
.xai-video-modal.is-open:not(.is-closing) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.xai-video-modal__backdrop {
    position: absolute;
    inset: 0;
    background-color: rgb(0 0 0 / 0);
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    cursor: pointer;
    transition:
        background-color var(--modal-backdrop-fade) var(--modal-backdrop-ease),
        -webkit-backdrop-filter var(--modal-backdrop-fade) var(--modal-backdrop-ease),
        backdrop-filter var(--modal-backdrop-fade) var(--modal-backdrop-ease);
    will-change: backdrop-filter, background-color;
}

.xai-video-modal.is-open .xai-video-modal__backdrop {
    background-color: rgb(0 0 0 / 0.6);
    -webkit-backdrop-filter: blur(var(--modal-backdrop-blur));
    backdrop-filter: blur(var(--modal-backdrop-blur));
}

.xai-video-modal__stage {
    position: relative;
    z-index: 1;
    width: min(1120px, calc(100vw - 3rem));
    max-height: calc(100vh - 3rem);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.98);
    transition:
        opacity calc(var(--modal-backdrop-fade) * 0.85) var(--modal-backdrop-ease),
        transform calc(var(--modal-backdrop-fade) * 0.85) var(--modal-backdrop-ease);
    transition-delay: 0.04s;
}

.xai-video-modal.is-open .xai-video-modal__stage {
    opacity: 1;
    transform: scale(1);
}

.xai-video-modal__frame {
    position: relative;
    width: 100%;
    border-radius: 0.75rem; /* rounded-xl */
    overflow: hidden;
    background-color: #000;
    box-shadow:
        0 0 0 1px rgb(255 255 255 / 0.06),
        0 25px 50px -12px rgb(0 0 0 / 0.5);
    aspect-ratio: 16 / 9;
    max-height: calc(100vh - 3rem);
}

.xai-video-modal__frame video,
.xai-video-modal #modalVideo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #000;
    border: 0;
    border-radius: 0;
    vertical-align: middle;
}

/*
 * x.ai: <button class="absolute inset-0 cursor-pointer" aria-label="Pause">
 * Full-area click target for play/pause — no visible chrome.
 */
.xai-video-modal__toggle {
    position: absolute;
    inset: 0;
    z-index: 2;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: inherit;
    background: transparent;
    background-image: none;
    cursor: pointer;
    -webkit-appearance: button;
    appearance: button;
    color: inherit;
    font: inherit;
}

.xai-video-modal__toggle:focus {
    outline: none;
}

.xai-video-modal__toggle:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* Centered play affordance only while paused */
.xai-video-modal__play-icon {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 3;
    width: 4rem;
    height: 4rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 9999px;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgb(0 0 0 / 0.45);
    color: #fff;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    box-shadow: 0 0 0 1px rgb(255 255 255 / 0.12);
}

.xai-video-modal__play-icon svg {
    width: 1.5rem;
    height: 1.5rem;
    margin-left: 2px; /* optical center for play triangle */
}

.xai-video-modal.is-paused .xai-video-modal__play-icon,
.xai-video-modal:not(.is-playing) .xai-video-modal__play-icon {
    opacity: 1;
}

.xai-video-modal.is-playing .xai-video-modal__play-icon {
    opacity: 0;
}

.xai-video-modal__close {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 4;
    transform: translate(30%, -30%);
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 9999px;
    background: rgb(0 0 0 / 0.55);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 0 0 1px rgb(255 255 255 / 0.12);
    transition: background-color 0.15s ease, filter 0.15s ease;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.xai-video-modal__close:hover {
    background: rgb(0 0 0 / 0.75);
    filter: brightness(1.05);
}

.xai-video-modal__close:focus {
    outline: none;
}

.xai-video-modal__close:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.xai-video-modal__close svg {
    width: 1.125rem;
    height: 1.125rem;
    display: block;
}

@media (max-width: 640px) {
    .xai-video-modal {
        padding: 0.75rem;
    }

    .xai-video-modal__stage {
        width: min(100%, calc(100vw - 1.5rem));
    }

    .xai-video-modal__close {
        transform: translate(10%, -40%);
    }

    .xai-video-modal__play-icon {
        width: 3.25rem;
        height: 3.25rem;
    }
}

/* Prefer reduced motion: skip fade / blur ramp */
@media (prefers-reduced-motion: reduce) {
    .xai-video-modal,
    .xai-video-modal__backdrop,
    .xai-video-modal__stage {
        transition: none;
    }

    .xai-video-modal__stage {
        transform: none;
    }
}
