/* ==========================================================
   Mobile Canvas / Mobile Device Showcase - Structure
   1) Local Tokens
   2) Device Shell + Screen
   3) Hint
   4) Phone Carousel Controls
   5) Mobile Gallery Behaviour + Responsive
   ========================================================== */

/* ==========================================================
   Local Tokens
   ========================================================== */
/* Base tokens for mobile-like devices used in project showcases */
:is(.canvas-showcase, .mobile-showcase) {
    /* Device dimensions */
    --canvas-showcase-phone-width: 420px;
    --canvas-showcase-phone-height: 800px;
    --canvas-showcase-phone-width-mobile: 360px;
    --canvas-showcase-phone-height-mobile: 650px;

    /* Device shell */
    --canvas-showcase-shell-radius: 44px;
    --canvas-showcase-screen-radius: 34px;
    --canvas-showcase-frame-padding: 12px;
    --mobile-showcase-frame-padding-mobile: 10px;

    /* Mobile uniform phone sizing */
    --mobile-showcase-uniform-width-mobile: min(100%, 360px);
    --mobile-showcase-uniform-ratio-mobile: 9 / 16;

    /* Hint typography + interaction */
    --canvas-showcase-hint-weight: 400;
    --canvas-showcase-hint-scroll-distance: 260px;
    --canvas-showcase-hint-scroll-duration: 700ms;
    --canvas-showcase-hint-hover-delay: 300ms;
}

/* Dedicated dimensions for mobile-gallery variants (Disney-like image galleries) */
:is(.canvas-showcase, .mobile-showcase).media-mobile-gallery {
    --mobile-gallery-phone-width: 440px;
    --mobile-gallery-phone-height: 800px;
    --mobile-gallery-phone-width-mobile: 380px;
    --mobile-gallery-phone-height-mobile: 657px;

    --canvas-showcase-phone-width: var(--mobile-gallery-phone-width);
    --canvas-showcase-phone-height: var(--mobile-gallery-phone-height);
    --canvas-showcase-phone-width-mobile: var(--mobile-gallery-phone-width-mobile);
    --canvas-showcase-phone-height-mobile: var(--mobile-gallery-phone-height-mobile);
}

/* Disney interstitial video uses a specific 640x1136 ratio (desktop only) */
body[data-project-slug="disney-multi"] section[aria-labelledby="disney-showcase-title"].media-mobile-gallery {
    --canvas-showcase-phone-width: 461px;
    --canvas-showcase-phone-height: 800px;

    /* Match Slot desktop CTA size */
    --project-cta-width: auto;
    --project-cta-height: 46px;
    --project-cta-padding-y: 10px;
    --project-cta-padding-x: 26px;
    --project-cta-font-size: 24px;
}

/* Carousel control tokens shared by phone + landscape carousels */
:is(.media-carousel-dots, .media-carousel-mobile-controls) {
    --media-carousel-control-size: 12px;
    --media-carousel-toggle-circle-size: 50px;
}

/* ==========================================================
   Device Shell + Screen
   ========================================================== */
:is(.canvas-showcase-phone, .mobile-showcase-device) {
    position: relative;
    width: var(--canvas-showcase-phone-width);
    max-width: 100%;
    height: var(--canvas-showcase-phone-height);
    margin: 0;
    padding: var(--canvas-showcase-frame-padding);
    border-radius: var(--canvas-showcase-shell-radius);
    background: var(--bg-dark);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-on-dark) 24%, transparent);
}

:is(.canvas-showcase-phone-screen, .mobile-showcase-device-screen) {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--canvas-showcase-screen-radius);
    overflow: hidden;
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    mask-image: radial-gradient(circle, white 99%, black 100%);
    isolation: isolate;
    background: var(--bg-light);
}

:is(.canvas-showcase-frame, .mobile-showcase-frame) {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: var(--bg-light);
}

@media (hover: hover) and (pointer: fine) {
    body[data-project-slug="dim-canvas"] :is(.canvas-showcase-frame, .mobile-showcase-frame) {
        cursor: pointer;
    }
}

:is(.canvas-showcase-phone-notch, .mobile-showcase-device-notch) {
    display: none;
}

:is(.canvas-showcase-phone-side-button, .mobile-showcase-device-side-button) {
    position: absolute;
    right: -2px;
    top: 28%;
    width: 3px;
    height: 72px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-dark) 82%, var(--text-on-dark));
    pointer-events: none;
}

/* ==========================================================
   Hint
   ========================================================== */
:is(.canvas-showcase-hint, .media-scroll-hint) {
    display: inline-block;
    width: fit-content;
    margin: var(--title-text-space) 0 0;
    color: var(--text-grey);
    font-size: var(--text-hint-size);
    font-weight: var(--canvas-showcase-hint-weight);
    line-height: var(--body-leading);
}

@media (min-width: 901px) {
    :is(.canvas-showcase-hint, .media-scroll-hint) {
        cursor: pointer;
        transition: color 180ms ease-out;
    }

    :is(.canvas-showcase-hint, .media-scroll-hint):hover {
        color: var(--text-on-light);
    }
}

:is(.canvas-showcase, .mobile-showcase) .mobile-device-video {
    position: relative;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: inherit;
    overflow: hidden;
    background: var(--bg-dark);
}

:is(.canvas-showcase, .mobile-showcase) .mobile-device-video :is(.canvas-showcase-frame, .mobile-showcase-frame) {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: inherit;
}

/* ==========================================================
   Phone Carousel Controls
   ========================================================== */
.mobile-image-carousel {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    overflow: hidden;
    background: var(--bg-light);
}

.mobile-image-carousel-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: inherit;
    opacity: 0;
    transition: opacity 220ms ease-out;
    pointer-events: none;
}

.mobile-image-carousel-image.is-active {
    opacity: 1;
}

.media-carousel-dots {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin-top: var(--title-text-space);
}

.media-carousel-dots-anchor {
    display: none;
}

.media-carousel-mobile-controls {
    display: none;
    width: 100%;
}

.media-carousel-dot {
    --dot-progress: 0;
    --dot-height: var(--media-carousel-control-size);
    --dot-idle-width: var(--media-carousel-control-size);
    --dot-active-width: calc(var(--media-carousel-control-size) * 4.4);
    width: var(--dot-idle-width);
    height: var(--dot-height);
    border-radius: 999px;
    border: 0;
    padding: 0;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    background: var(--grey);
    transition: width 200ms ease-out, background-color 180ms ease-out, transform 180ms ease-out;
}

.media-carousel-dot::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--bg-dark);
    transform-origin: left center;
    transform: scaleX(var(--dot-progress));
    transition: transform 80ms linear;
}

.media-carousel-dot:hover,
.media-carousel-dot:focus-visible {
    background: var(--bg-dark);
}

.media-carousel-dot.is-active {
    width: var(--dot-active-width);
    background: var(--grey);
}

.media-carousel-dots.is-paused .media-carousel-dot.is-active {
    width: var(--dot-idle-width);
    background: var(--bg-dark);
}

.media-carousel-dots.is-paused .media-carousel-dot.is-active::after {
    transform: scaleX(0);
}

.media-carousel-dots.is-mobile-no-progress .media-carousel-dot {
    width: var(--dot-idle-width);
}

.media-carousel-dots.is-mobile-no-progress .media-carousel-dot::after {
    transform: scaleX(0);
}

.media-carousel-dots.is-mobile-no-progress .media-carousel-dot.is-active {
    background: var(--bg-dark);
}

.media-carousel-toggle {
    width: var(--media-carousel-toggle-circle-size);
    height: var(--media-carousel-toggle-circle-size);
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    flex-shrink: 0;
    border: 1px solid var(--grey);
    border-radius: 999px;
    padding: 0;
    margin-right: 10px;
    background: transparent;
    color: var(--grey);
    opacity: 0.9;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 180ms ease-out;
}

.media-carousel-toggle-icon {
    display: block;
    width: calc(var(--media-carousel-toggle-circle-size) * 0.34);
    height: calc(var(--media-carousel-toggle-circle-size) * 0.34);
    position: relative;
    background: transparent;
}

.media-carousel-toggle-icon::before,
.media-carousel-toggle-icon::after {
    content: "";
    position: absolute;
    top: 0;
    width: calc(var(--media-carousel-toggle-circle-size) * 0.08);
    height: 100%;
    border-radius: 999px;
    background: currentColor;
}

.media-carousel-toggle-icon::before {
    left: calc(var(--media-carousel-toggle-circle-size) * 0.07);
}

.media-carousel-toggle-icon::after {
    right: calc(var(--media-carousel-toggle-circle-size) * 0.07);
}

.media-carousel-toggle.is-paused .media-carousel-toggle-icon::before,
.media-carousel-toggle.is-paused .media-carousel-toggle-icon::after {
    display: none;
}

.media-carousel-toggle.is-paused .media-carousel-toggle-icon {
    width: calc(var(--media-carousel-toggle-circle-size) * 0.40);
    height: calc(var(--media-carousel-toggle-circle-size) * 0.44);
    margin-left: calc(var(--media-carousel-toggle-circle-size) * 0.045);
    background: currentColor;
    clip-path: polygon(16% 8%, 16% 92%, 90% 50%);
    border-radius: 1px;
}

.media-carousel-toggle:hover,
.media-carousel-toggle:focus-visible {
    color: var(--bg-dark);
}

/* ==========================================================
   Mobile Gallery Behaviour + Responsive
   ========================================================== */
@media (max-width: 900px) {
    body[data-project-slug="disney-multi"] .disney-mobile-video-desktop-controls {
        display: none;
    }

    :is(.canvas-showcase, .mobile-showcase).media-mobile-gallery :is(.canvas-showcase-phone, .mobile-showcase-device) {
        height: auto;
    }

    :is(.canvas-showcase, .mobile-showcase).media-mobile-gallery :is(.canvas-showcase-phone-screen, .mobile-showcase-device-screen) {
        height: auto;
        aspect-ratio: 9 / 16;
        border-radius: var(--canvas-showcase-screen-radius);
        -webkit-mask-image: -webkit-radial-gradient(white, black);
        mask-image: radial-gradient(circle, white 99%, black 100%);
    }

    :is(.canvas-showcase, .mobile-showcase).media-mobile-gallery :is(.canvas-showcase-phone-col, .mobile-showcase-device-col) {
        flex-direction: column;
        align-items: center;
    }

    :is(.canvas-showcase, .mobile-showcase).media-mobile-gallery :is(.canvas-showcase-copy, .mobile-showcase-copy) > .media-carousel-dots {
        display: none;
    }

    .media-carousel-mobile-controls {
        display: flex;
        justify-content: center;
        margin-top: var(--project-media-controls-gap-mobile, 20px);
    }

    .media-carousel-mobile-controls .media-carousel-dots {
        margin-top: 0;
        justify-content: center;
        flex-wrap: nowrap;
    }

    .media-carousel-mobile-controls .media-carousel-toggle {
        display: none;
    }

    .media-carousel-dots {
        justify-content: center;
    }

    body[data-project-slug="dim-canvas"] :is(.canvas-showcase-hint, .media-scroll-hint) {
        display: block;
        width: fit-content;
        margin-left: auto;
        margin-right: auto;
        text-align: center;
    }
}

@media (min-width: 901px) {
    body[data-project-slug="disney-multi"] .disney-mobile-video-desktop-controls {
        display: flex;
        width: 100%;
        justify-content: flex-end;
        margin-top: var(--title-text-space, 10px);
    }

    body[data-project-slug="disney-multi"] .disney-mobile-video-desktop-controls .js-mobile-video-desktop-toggle:not(.is-active) {
        border-color: var(--bg-dark);
        color: var(--text-on-light);
        opacity: 1;
    }

    body[data-project-slug="disney-multi"] .disney-mobile-video-desktop-controls .js-mobile-video-desktop-toggle:not(.is-active):hover {
        border-color: var(--grey);
        color: var(--text-grey);
        opacity: 1;
    }

    body[data-project-slug="disney-multi"] section[aria-labelledby="disney-showcase-title"] .project-media-switcher-play {
        display: none;
    }
}

@media (max-width: 640px) {
    body[data-project-slug="dim-canvas"] :is(.canvas-showcase, .mobile-showcase),
    body[data-project-slug="disney-multi"] :is(.canvas-showcase, .mobile-showcase) {
        --mobile-showcase-uniform-width-mobile: calc(100dvw - (2 * (var(--page-gutter) + 20px)));
        --mobile-showcase-frame-padding-mobile: 8px;
    }

    body[data-project-slug="disney-multi"] section[aria-labelledby="disney-showcase-title"].media-mobile-gallery {
        --mobile-showcase-uniform-width-mobile: calc(100dvw - (2 * (var(--page-gutter) + 20px)));
        --mobile-showcase-uniform-ratio-mobile: 640 / 1136;
        --canvas-showcase-phone-width: var(--mobile-showcase-uniform-width-mobile);
        --canvas-showcase-phone-height: auto;
        --canvas-showcase-frame-padding: var(--mobile-showcase-frame-padding-mobile);
    }

    body[data-project-slug="disney-multi"] section[aria-labelledby="disney-gallery-title"].media-mobile-gallery {
        --mobile-showcase-uniform-ratio-mobile: 9 / 16;
    }

    :is(.canvas-showcase, .mobile-showcase) {
        --canvas-showcase-phone-width: var(--mobile-showcase-uniform-width-mobile);
        --canvas-showcase-phone-height: auto;
        --canvas-showcase-shell-radius: 34px;
        --canvas-showcase-screen-radius: 26px;
        --canvas-showcase-frame-padding: var(--mobile-showcase-frame-padding-mobile);
    }

    :is(.canvas-showcase, .mobile-showcase).media-mobile-gallery {
        --canvas-showcase-phone-width: var(--mobile-showcase-uniform-width-mobile);
        --canvas-showcase-phone-height: auto;
        --canvas-showcase-frame-padding: var(--mobile-showcase-frame-padding-mobile);
    }

    :is(.canvas-showcase-phone, .mobile-showcase-device) {
        height: auto;
        aspect-ratio: var(--mobile-showcase-uniform-ratio-mobile);
    }

    :is(.canvas-showcase-phone-screen, .mobile-showcase-device-screen) {
        height: 100%;
        aspect-ratio: auto;
    }

    :is(.canvas-showcase, .mobile-showcase).media-mobile-gallery :is(.canvas-showcase-phone-screen, .mobile-showcase-device-screen) {
        height: 100%;
        aspect-ratio: auto;
    }

    /* Disney mobile hardening: prevent iOS media bleed outside rounded shell */
    body[data-project-slug="disney-multi"] :is(.canvas-showcase-phone, .mobile-showcase-device) {
        overflow: hidden;
    }

    body[data-project-slug="disney-multi"] :is(.canvas-showcase-phone-side-button, .mobile-showcase-device-side-button) {
        display: none;
    }

    body[data-project-slug="disney-multi"] :is(.canvas-showcase-phone-screen, .mobile-showcase-device-screen) {
        position: relative;
        overflow: hidden;
        background: var(--bg-dark);
    }

    body[data-project-slug="disney-multi"] :is(.mobile-device-video, .mobile-image-carousel) {
        /* iOS anti-bleed: tiny inset keeps media safely inside rounded shell */
        position: absolute;
        inset: 0.75px;
        border-radius: calc(var(--canvas-showcase-screen-radius) - 0.75px);
        overflow: hidden;
        -webkit-mask-image: -webkit-radial-gradient(white, black);
        mask-image: radial-gradient(circle, white 99%, black 100%);
    }

    body[data-project-slug="disney-multi"] :is(.canvas-showcase-phone, .mobile-showcase-device)::after {
        /* Draw bezel on top to hide sub-pixel compositing leaks at edges */
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
        box-shadow: inset 0 0 0 var(--canvas-showcase-frame-padding) var(--bg-dark);
        pointer-events: none;
        z-index: 4;
    }

    body[data-project-slug="disney-multi"] .mobile-device-video :is(.canvas-showcase-frame, .mobile-showcase-frame),
    body[data-project-slug="disney-multi"] .mobile-image-carousel-image {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
    }

    /* Exact size lock for Disney interstitial video phone: W -> H by 640/1136 */
    body[data-project-slug="disney-multi"] section[aria-labelledby="disney-showcase-title"] :is(.canvas-showcase-phone, .mobile-showcase-device) {
        width: var(--mobile-showcase-uniform-width-mobile);
        height: calc(var(--mobile-showcase-uniform-width-mobile) * 1136 / 640);
        aspect-ratio: auto;
    }

}

