/* =============================================
   DRAGGABLE -> MODAL VIDEO PLAYER
   Matches Ariro Toys 1:1
   ============================================= */

/* ── Container / Backdrop ────────────────────── */
#xp-draggable-video {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 999999;
    display: none;
    pointer-events: none; /* Let clicks pass through when mini */
    transition: background 0.3s ease;
}
#xp-draggable-video.xp-open {
    display: block;
}

/* When expanded, the container becomes a dark backdrop */
#xp-draggable-video.xp-is-expanded {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── Video Card (Mini & Expanded) ───────────── */
.xp-video-card {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: 150px;           /* Smaller mini size, like Ariro */
    aspect-ratio: 9 / 16;   /* Perfect vertical video ratio */
    height: auto;           /* Let aspect ratio drive height */
    max-height: 80vh;
    border-radius: 12px;
    background: #000;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    overflow: hidden;
    pointer-events: auto; /* Catch clicks */
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

/* Mini Open Animation */
@keyframes xp-slideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.9); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
#xp-draggable-video.xp-open:not(.xp-is-expanded) .xp-video-card {
    animation: xp-slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Dragging state */
.xp-video-card.is-dragging {
    transition: none !important;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    cursor: grabbing !important;
}

/* Expanded state (Centered Modal) */
#xp-draggable-video.xp-is-expanded .xp-video-card {
    /* Reset left/top/right/bottom inline styles injected by dragging */
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    
    width: 90vw;
    max-width: 400px;       /* Expanded modal width */
    aspect-ratio: 9 / 16;
    height: auto;
    max-height: 90vh;       /* Prevents vertical overflow on short screens */
    
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    cursor: default;
}

/* ── Video Frame & Iframe ────────────────────── */
.xp-video-frame {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
}
.xp-video-frame iframe {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    border: none;
    display: block;
}

/* ── Click/Drag Overlay (Mini Mode) ────────────
   Covers iframe so user can drag OR click-to-expand.
   Hidden when expanded so user can use YouTube player. */
#xp-click-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    cursor: grab;
}
.is-dragging #xp-click-overlay {
    cursor: grabbing;
}
#xp-draggable-video.xp-is-expanded #xp-click-overlay {
    display: none;
    pointer-events: none;
}

/* ── Mini Controls & Gradient ────────────────── */
.xp-mini-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 70px;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 6;
    pointer-events: none; /* Let clicks pass to overlay */
}
#xp-draggable-video.xp-is-expanded .xp-mini-controls {
    display: none;
}

/* Play/Pause inside mini controls */
.xp-play-pause-btn {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.45);
    color: #fff;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto; /* Catch clicks */
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    cursor: pointer;
    margin-right: 10px;
    padding: 0;
}
.xp-play-pause-btn svg {
    display: block !important;
    fill: #ffffff !important;
    width: 14px !important;
    height: 14px !important;
    opacity: 1 !important;
    visibility: visible !important;
}
.xp-video-label {
    color: #fff;
    font-size: 11px;
    font-family: -apple-system, sans-serif;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* ── Close Buttons ───────────────────────────── */
.xp-mini-close-btn {
    position: absolute;
    top: 12px; left: 12px;
    width: 28px; height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.45);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    z-index: 10;
    cursor: pointer;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}
#xp-draggable-video.xp-is-expanded .xp-mini-close-btn {
    display: none;
}

.xp-modal-close-btn {
    position: absolute;
    top: 14px; right: 14px;
    width: 34px; height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    z-index: 20;
    cursor: pointer;
    display: none;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: background 0.2s, transform 0.2s;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}
.xp-modal-close-btn:hover {
    background: #e63946;
    transform: scale(1.1);
}
#xp-draggable-video.xp-is-expanded .xp-modal-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Spinner ─────────────────────────────────── */
.xp-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    z-index: 4;
}
@keyframes xp-spin { to { transform: rotate(360deg); } }
.xp-loader svg { animation: xp-spin 0.75s linear infinite; }

/* ── Mobile Tweaks ───────────────────────────── */
@media (max-width: 480px) {
    .xp-video-card {
        width: 125px;           /* Even smaller on mobile */
        aspect-ratio: 9 / 16;
        height: auto;
        bottom: 14px; right: 14px;
    }
    #xp-draggable-video.xp-is-expanded .xp-video-card {
        width: 92vw;
        aspect-ratio: 9 / 16;
        height: auto;
        max-height: 85vh;
        border-radius: 12px;
    }
}
