/* Both decorative stacks share full-size cards and coordinated hover motion. */
@property --app-hero-float-strength {
    syntax: '<number>';
    inherits: false;
    initial-value: 1;
}

@property --app-hero-float-offset {
    syntax: '<length>';
    inherits: false;
    initial-value: 0px;
}

@keyframes appHeroFloat {
    0%, 100% { --app-hero-float-offset: 0px; }
    50% { --app-hero-float-offset: -4px; }
}

.hero-shell-ambience {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
}

.screenshot-stack {
    --stack-gap: 12px;
    --stack-easing: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (hover: hover) and (pointer: fine) {
    /* Clip the decorative glow separately so cards can cross the hero's
       border without leaking its background or interrupting the return. */
    .hero-shell {
        overflow: visible;
    }

    .screenshot-stack {
        --stack-one-width: clamp(170px, 24vw, 250px);
        --stack-two-width: var(--stack-one-width);
        --stack-three-width: var(--stack-two-width);
        --stack-frame-inset: calc(1.3rem + 2px);
        --stack-row-height: calc((var(--stack-one-width) - var(--stack-frame-inset)) * 2868 / 1320 + var(--stack-frame-inset));
        --stack-row-top: 50%;
        --stack-row-width: calc(var(--stack-one-width) + var(--stack-two-width) + var(--stack-three-width) + 2 * var(--stack-gap));
        --stack-row-start: 0px;
        z-index: 2;
    }

    .hero-stage.screenshot-stack {
        /* Lift the full-height cards further at narrower two-column widths,
           where the shorter headline brings the download actions upward. */
        --stack-row-top: calc(50% - clamp(56px, calc(488px - 30vw), 136px));
        /* At two-column widths, spread left over the copy rather than off
           the right side of the viewport. */
        --stack-row-start: calc(100% - var(--stack-row-width));
    }

    .spotlight-gallery.screenshot-stack {
        overflow: visible;
    }

    /* Matching frame padding preserves the same image and card dimensions
       in both stacks. Coarse-pointer devices keep the existing presentation. */
    .screenshot-stack .spotlight-phone {
        padding: 0.65rem;
    }

    .screenshot-stack > figure {
        --stack-shift-x: 0%;
        --stack-shift-y: 0%;
        left: var(--stack-left);
        top: var(--stack-top);
        right: auto;
        bottom: auto;
        width: var(--stack-width);
        transform: translate(var(--stack-shift-x), var(--stack-shift-y)) rotate(var(--stack-rotation));
        animation: none;
        transition:
            left 550ms var(--stack-easing),
            top 550ms var(--stack-easing),
            width 550ms var(--stack-easing),
            transform 550ms var(--stack-easing),
            box-shadow 550ms var(--stack-easing),
            --app-hero-float-strength 550ms var(--stack-easing);
        transition-delay: 0ms;
        /* Cards are decorative. The parent handles initial hover; the
           expanded hit area also covers the full-size row. */
        pointer-events: none;
    }

    /* Independent translate leaves the stack's positioning and rotation
       transitions free to run. Fade the drift out from its current phase
       on hover; bring it back only after the cards finish returning. */
    .hero-stage.screenshot-stack > figure {
        --app-hero-float-strength: 1;
        translate: 0 calc(var(--app-hero-float-offset) * var(--app-hero-float-strength));
        animation: appHeroFloat 7.5s ease-in-out infinite;
        transition-delay: 0ms, 0ms, 0ms, 0ms, 0ms, 550ms;
    }

    .hero-stage.screenshot-stack > figure:nth-of-type(2) {
        animation-duration: 8.5s;
        animation-delay: -2.5s;
    }

    .hero-stage.screenshot-stack > figure:nth-of-type(3) {
        animation-duration: 9.5s;
        animation-delay: -5s;
    }

    .hero-stage.screenshot-stack:hover > figure {
        --app-hero-float-strength: 0;
        animation-play-state: paused;
        transition-delay: 0ms;
    }

    .screenshot-stack .hero-shot--one {
        --stack-width: var(--stack-one-width);
        --stack-left: 100%;
        --stack-top: 0%;
        --stack-shift-x: -100%;
        --stack-rotation: 8deg;
    }

    .screenshot-stack .hero-shot--two {
        --stack-width: var(--stack-two-width);
        --stack-left: 2%;
        --stack-top: 88%;
        --stack-shift-y: -100%;
        --stack-rotation: -10deg;
    }

    .screenshot-stack .hero-shot--three {
        --stack-width: var(--stack-three-width);
        --stack-left: 82%;
        --stack-top: 102%;
        --stack-shift-x: -100%;
        --stack-shift-y: -100%;
        --stack-rotation: 4deg;
    }

    .screenshot-stack .spotlight-phone--primary {
        --stack-left: 9%;
        --stack-top: 10%;
        --stack-width: var(--stack-one-width);
        --stack-rotation: -5deg;
    }

    .screenshot-stack .spotlight-phone--secondary {
        --stack-left: 92%;
        --stack-top: 7%;
        --stack-width: var(--stack-two-width);
        --stack-shift-x: -100%;
        --stack-rotation: 8deg;
    }

    .screenshot-stack .spotlight-phone--tertiary {
        --stack-left: 88%;
        --stack-top: 93%;
        --stack-width: var(--stack-three-width);
        --stack-shift-x: -100%;
        --stack-shift-y: -100%;
        --stack-rotation: -2deg;
    }

    .screenshot-stack .hero-icon-core,
    .screenshot-stack .stage-note {
        pointer-events: none;
        transition: opacity 180ms ease;
        transition-delay: 250ms;
    }

    .screenshot-stack > .hero-stage-grid,
    .screenshot-stack > .hero-stage-ring {
        pointer-events: none;
    }

    .screenshot-stack:hover > figure {
        top: var(--stack-row-top);
        width: var(--stack-width);
        --stack-shift-x: -50%;
        --stack-shift-y: -50%;
        --stack-rotation: 0deg;
        box-shadow: 0 18px 38px rgba(1, 10, 17, 0.24);
    }

    .screenshot-stack:hover > figure:nth-of-type(1) {
        left: calc(var(--stack-row-start) + var(--stack-one-width) / 2);
    }

    .screenshot-stack:hover > figure:nth-of-type(2) {
        left: calc(var(--stack-row-start) + var(--stack-one-width) + var(--stack-gap) + var(--stack-two-width) / 2);
        transition-delay: 40ms;
    }

    .screenshot-stack:hover > figure:nth-of-type(3) {
        left: calc(var(--stack-row-start) + var(--stack-one-width) + var(--stack-two-width) + 2 * var(--stack-gap) + var(--stack-three-width) / 2);
        transition-delay: 80ms;
    }

    /* An invisible hit area spans the expanded row, including its gaps.
       It exists only while open, so covered copy does not trigger expansion
       from the collapsed state. */
    .screenshot-stack::after {
        content: '';
        position: absolute;
        left: var(--stack-row-start);
        top: var(--stack-row-top);
        width: var(--stack-row-width);
        height: var(--stack-row-height);
        transform: translateY(-50%);
        pointer-events: none;
        visibility: hidden;
    }

    .screenshot-stack:hover::after {
        pointer-events: auto;
        visibility: visible;
    }

    .screenshot-stack:hover .hero-icon-core,
    .screenshot-stack:hover .stage-note {
        opacity: 0;
        transition-delay: 0ms;
    }

    @media (max-width: 1080px) {
        .screenshot-stack,
        .hero-stage.screenshot-stack {
            --stack-row-start: calc(50% - var(--stack-row-width) / 2);
            --stack-row-top: 50%;
        }
    }

    @media (max-width: 768px) {
        .screenshot-stack {
            --stack-one-width: min(46vw, 200px);
            --stack-two-width: min(44vw, 190px);
        }

        .screenshot-stack .hero-shot--one {
            --stack-left: 101%;
        }

        .screenshot-stack .hero-shot--two {
            --stack-left: 1%;
        }

        .screenshot-stack .hero-shot--three {
            --stack-left: 90%;
        }

        .screenshot-stack .spotlight-phone--primary {
            --stack-left: 4%;
        }

        .screenshot-stack .spotlight-phone--secondary {
            --stack-left: 96%;
        }

        .screenshot-stack .spotlight-phone--tertiary {
            --stack-left: 93%;
        }
    }

    @media (max-width: 480px) {
        .screenshot-stack {
            --stack-frame-inset: calc(0.9rem + 2px);
        }

        .screenshot-stack .spotlight-phone {
            padding: 0.45rem;
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .screenshot-stack,
    .screenshot-stack::before,
    .screenshot-stack::after,
    .screenshot-stack *,
    .screenshot-stack *::before,
    .screenshot-stack *::after {
        animation: none !important;
        transition: none !important;
    }
}
