@property --Tilt {
    syntax: "<angle>";
    inherits: true;
    initial-value: 0deg;
}

.Gallery {
    --CardRadius: calc(var(--CardWidth) * 0.013);
    --CardSurface: #0d0d11;
    --CardTint: #050a14;
    --CardShadow: 0 0.125rem 0.25rem rgb(6 24 52 / 0.14), 0 1.5rem 3rem -1rem rgb(6 24 52 / 0.42), 0 3rem 6rem -2rem rgb(6 24 52 / 0.3);
    --StackStep: calc(var(--CardWidth) * 0.1);
    --StackDepth: calc(var(--CardWidth) * -0.16);
    --TimerState: paused;
    z-index: 1;
    display: grid;
    grid-row: 2;
    grid-column: 1;
    justify-self: center;
    justify-items: center;
    padding-bottom: 1.25rem;
}

.Gallery[data-playing="true"] {
    --TimerState: running;
}

.GalleryStage {
    --Pitch: 9deg;
    display: grid;
    width: var(--CardWidth);
    height: var(--CardHeight);
    perspective: calc(var(--CardWidth) * 2.2);
    cursor: pointer;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.GalleryStage[data-dragging="true"] {
    cursor: grabbing;
}

.GalleryCard {
    --Offset: 0;
    --Depth: max(0, var(--Offset));
    --Lead: max(0, var(--Offset) * -1);
    display: grid;
    grid-area: 1 / 1;
    width: var(--CardWidth);
    aspect-ratio: 1160 / 680;
    overflow: hidden;
    border-radius: var(--CardRadius);
    background: var(--CardSurface);
    box-shadow: var(--CardShadow);
    opacity: clamp(0, min(1 - var(--Lead) * 1.9, (2.45 - var(--Offset)) * 2.2), 1);
    filter: blur(calc(min(var(--Depth) + var(--Lead) * 8, 4) * 0.75px));
    transform: translateX(calc(var(--StackStep) * var(--Offset))) translateZ(calc(var(--StackDepth) * var(--Offset))) rotateX(calc(var(--Pitch) + var(--Tilt))) rotateY(calc(min(1, var(--Depth)) * 8deg));
    z-index: calc(30 - var(--Offset) * 4);
    will-change: transform, opacity, filter;
}

.GalleryCard:nth-child(2) {
    --Offset: 1;
}

.GalleryCard:nth-child(3) {
    --Offset: 2;
}

.GalleryCard:nth-child(4) {
    --Offset: -2;
}

.GalleryCard:nth-child(5) {
    --Offset: -1;
}

.GalleryCard::after {
    content: "";
    grid-area: 1 / 1;
    background: var(--CardTint);
    opacity: min(0.6, var(--Depth) * 0.24);
    pointer-events: none;
}

.GalleryCard img {
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-user-drag: none;
}

.GalleryControls {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    margin-top: var(--SpaceMedium);
    padding: 0.1875rem;
    border: 1px solid var(--LightBorder);
    border-radius: var(--RadiusRound);
    color: var(--LightMuted);
    background: rgb(255 255 255 / 0.82);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.9), 0 1px 2px rgb(16 24 40 / 0.06), 0 0.5rem 1.25rem -0.75rem rgb(16 24 40 / 0.2);
    backdrop-filter: blur(1rem) saturate(1.4);
}

.GalleryButton {
    display: grid;
    place-items: center;
    width: var(--ControlSmall);
    height: var(--ControlSmall);
    border-radius: var(--RadiusRound);
    color: var(--LightMuted);
    transition:
        color var(--DurationBase) var(--EaseOut),
        background-color var(--DurationBase) var(--EaseOut),
        scale var(--DurationFast) var(--EaseOut);
}

.GalleryButton:hover {
    color: var(--LightInk);
    background-color: rgb(16 34 58 / 0.06);
}

.GalleryButton:active {
    scale: 0.9;
    transition-duration: var(--DurationInstant);
}

.GalleryIcon {
    width: 0.3125rem;
    height: 0.5rem;
    transition: translate var(--DurationBase) var(--EaseOut);
}

[data-gallery-previous]:hover .GalleryIcon {
    translate: -0.125rem 0;
}

[data-gallery-next]:hover .GalleryIcon {
    translate: 0.125rem 0;
}

.GalleryTabs {
    display: flex;
    width: 8.75rem;
    height: var(--ControlSmall);
}

.GalleryTab {
    display: grid;
    flex: 1 1 0;
    align-items: center;
    min-width: 0;
    border-radius: var(--RadiusRound);
    transition: flex-grow var(--DurationSlow) var(--EaseSmooth);
}

.GalleryTab:focus-visible {
    outline-offset: -0.125rem;
}

.GalleryTab::before,
.GalleryTab::after {
    content: "";
    grid-area: 1 / 1;
    height: 0.375rem;
    margin-inline: 0.4375rem;
    border-radius: var(--RadiusRound);
}

.GalleryTab::before {
    background: rgb(31 39 49 / 0.2);
    transition: background-color var(--DurationBase) var(--EaseOut);
}

.GalleryTab:hover::before {
    background: rgb(31 39 49 / 0.42);
}

.GalleryTab::after {
    background: var(--LightInk);
    clip-path: inset(0 100% 0 0 round var(--RadiusRound));
}

.GalleryTab[aria-selected="true"] {
    flex-grow: 3;
}

.GalleryTab[aria-selected="true"]::before {
    background: rgb(31 39 49 / 0.28);
}

.GalleryTab[aria-selected="true"]::after {
    animation: GalleryProgress 7s linear both;
    animation-play-state: var(--TimerState);
}

@keyframes GalleryProgress {
    from {
        clip-path: inset(0 100% 0 0 round var(--RadiusRound));
    }

    to {
        clip-path: inset(0 0 0 0 round var(--RadiusRound));
    }
}

@keyframes GalleryRise {
    from {
        opacity: 0;
        translate: 0 1.25rem;
        --Tilt: 4deg;
    }
}

.MotionReady .Gallery {
    animation: GalleryRise 1.1s var(--EaseOut) 0.5s backwards;
    animation-play-state: var(--HeroPlay);
}

@media (width < 48rem) {
    .Gallery {
        --StackStep: calc(var(--CardWidth) * 0.075);
        --StackDepth: calc(var(--CardWidth) * -0.14);
    }

    .GalleryStage {
        translate: calc(var(--CardWidth) * -0.04) 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .MotionReady .Gallery {
        animation-name: FadeIn;
        animation-duration: var(--DurationSlow);
        animation-delay: 0ms;
    }

    .GalleryTab {
        transition: none;
    }

    .GalleryTab[aria-selected="true"]::after {
        animation: none;
        clip-path: none;
    }
}
