/**
 * Playback - Pure Cinematic Memory Viewer
 * True dual-buffer crossfade transitions, soft atmospheric vignette,
 * subtle minimalist close control, auto-shuffle slideshow, and mobile swipe.
 */

/* ========================================================
   FULLSCREEN CINEMATIC OVERLAY
   ======================================================== */
#playbackModal,
.playback-overlay,
.flashback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    z-index: 2000000 !important; /* On top of everything, including mobile FAB */
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    background: #000000 !important;
    background-color: #000000 !important;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    will-change: opacity;
}

#playbackModal[aria-hidden="false"],
.playback-overlay[aria-hidden="false"],
.flashback-overlay[aria-hidden="false"] {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    background: #000000 !important;
    background-color: #000000 !important;
}

/* Smooth crossfade out state */
#playbackModal.is-closing,
.playback-overlay.is-closing,
.flashback-overlay.is-closing {
    display: flex !important;
    opacity: 0 !important;
    visibility: visible !important;
    pointer-events: none !important;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

#playbackModal[aria-hidden="true"]:not(.is-closing),
.playback-overlay[aria-hidden="true"]:not(.is-closing),
.playback-overlay:not([aria-hidden="false"]):not(.is-closing),
.flashback-overlay[aria-hidden="true"]:not(.is-closing),
.flashback-overlay:not([aria-hidden="false"]):not(.is-closing) {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Hide mobile menu FAB below the dark overlay when slideshow is active */
body.playback-open .mobile-menu-fab,
body.playback-open #mobileMenuFab,
html.playback-open #mobileMenuFab,
html.mobile-device body.playback-open #mobileMenuFab,
html.mobile-device body:not(.listen-page):not(.reflections-page).playback-open #mobileMenuFab,
.playback-overlay[aria-hidden="false"] ~ .mobile-menu-fab,
.playback-overlay[aria-hidden="false"] ~ #mobileMenuFab,
.flashback-overlay[aria-hidden="false"] ~ .mobile-menu-fab,
.flashback-overlay[aria-hidden="false"] ~ #mobileMenuFab {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    z-index: -1 !important;
}

/* Soft Ambient Viewport Vignette */
.playback-vignette,
.flashback-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 35%, rgba(0, 0, 0, 0.6) 75%, rgba(0, 0, 0, 0.95) 100%);
    z-index: 5;
}

/* Subtle, Minimalist Close Button */
.playback-close,
.flashback-close {
    position: absolute;
    top: max(20px, calc(env(safe-area-inset-top, 0px) + 12px));
    right: max(24px, calc(env(safe-area-inset-right, 0px) + 14px));
    width: 48px;
    height: 48px;
    min-width: 44px; /* Apple Human Interface Guideline minimum touch target */
    min-height: 44px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 28px;
    font-weight: 200;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.25s ease, transform 0.2s ease, opacity 0.25s ease;
    z-index: 500;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.playback-close:hover,
.flashback-close:hover {
    color: rgba(255, 255, 255, 0.95);
    transform: scale(1.15);
}

.playback-close:active,
.flashback-close:active {
    transform: scale(0.95);
}

/* Main Cinematic Stage */
.playback-stage,
.flashback-stage {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 36px;
    box-sizing: border-box;
    z-index: 10;
}

/* Centered Image Container with Dual-Layer Stacking */
.playback-image-wrap,
.flashback-image-wrap {
    position: relative;
    max-width: 82vw;
    max-height: 80vh;
    display: grid;
    place-items: center;
    border-radius: 12px;
    cursor: pointer;
    background: transparent !important;
}

/* Childhood Memory Image Layers (Simple Pure Crossfade) */
.playback-img,
.flashback-img {
    grid-area: 1 / 1;
    max-width: 82vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    border-radius: 12px;
    opacity: 0;
    transition: opacity 1.2s ease-in-out;
    will-change: opacity;
    pointer-events: none;
    background: transparent !important;
}

.playback-img.active,
.flashback-img.active {
    opacity: 1;
    pointer-events: auto;
}

/* ========================================================
   MOBILE & TABLET RESPONSIVENESS (iOS, iPadOS, Android)
   ======================================================== */
@media (max-width: 1024px) {
    .playback-stage,
    .flashback-stage {
        padding: 20px 16px;
    }
    .playback-image-wrap,
    .flashback-image-wrap {
        max-width: 88vw;
        max-height: 82vh;
        max-height: calc(100dvh - 80px);
        border-radius: 12px;
    }
    .playback-img,
    .flashback-img {
        max-width: 88vw;
        max-height: 82vh;
        max-height: calc(100dvh - 80px);
        border-radius: 12px;
    }
}

@media (max-width: 640px) {
    .playback-stage,
    .flashback-stage {
        padding: 10px 8px;
    }
    .playback-close,
    .flashback-close {
        top: max(14px, calc(env(safe-area-inset-top, 0px) + 8px));
        right: max(14px, calc(env(safe-area-inset-right, 0px) + 10px));
        width: 44px;
        height: 44px;
        font-size: 26px;
        color: rgba(255, 255, 255, 0.85);
        z-index: 500;
    }
    .playback-image-wrap,
    .flashback-image-wrap {
        max-width: 94vw;
        max-height: 82vh;
        max-height: calc(100dvh - 88px);
        border-radius: 10px;
    }
    .playback-img,
    .flashback-img {
        max-width: 94vw;
        max-height: 82vh;
        max-height: calc(100dvh - 88px);
        border-radius: 10px;
    }
}

/* Mobile & Tablet Landscape */
@media (max-height: 520px) and (orientation: landscape) {
    .playback-stage,
    .flashback-stage {
        padding: 6px 16px;
    }
    .playback-close,
    .flashback-close {
        top: max(8px, env(safe-area-inset-top, 0px));
        right: max(12px, env(safe-area-inset-right, 0px));
        width: 38px;
        height: 38px;
        font-size: 22px;
    }
    .playback-image-wrap,
    .flashback-image-wrap,
    .playback-img,
    .flashback-img {
        max-width: calc(100dvw - 72px);
        max-height: calc(100dvh - 20px);
        border-radius: 8px;
    }
}
