.gallery {
    /* Sub-fractions of --gallery-height; must sum to 1:
         top + bottom + 3 * item + 2 * row-gap = 1 */
    --gallery-top-inset: 0.05;
    --gallery-bottom-inset: 0.05;
    --gallery-row-gap: 0.03;
    --gallery-item-height: 0.28;
    --gallery-item-gap: 0.02;

    /* Per-row marquee knobs: duration sets speed, direction is
       `normal` (leftward) or `reverse` (rightward). */
    --row-1-duration: 40s;
    --row-1-direction: normal;
    --row-2-duration: 90s;
    --row-2-direction: reverse;
    --row-3-duration: 90s;
    --row-3-direction: normal;

    --splash-wallpaper: url("../images/macos-wallpapers/10-14-Day.jpg");
    --splash-wallpaper-blur: 32px;
    --splash-wallpaper-saturate: 1.4;
    --splash-wallpaper-brightness: 1;

    width: min(1820px, 100% - 2 * clamp(var(--space-4), 4vw, var(--space-12)));
    margin-inline: auto;
    position: relative;
    isolation: isolate;
    flex: 0 0 var(--gallery-height);
    height: var(--gallery-height);
    padding-top: calc(var(--gallery-height) * var(--gallery-top-inset));
    padding-bottom: calc(var(--gallery-height) * var(--gallery-bottom-inset));
    display: flex;
    flex-direction: column;
    gap: calc(var(--gallery-height) * var(--gallery-row-gap));
    overflow: hidden;
    border: 1px solid #00000038;
    border-radius: var(--radius-2xl);
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 4px 12px rgba(0, 0, 0, 0.06),
        0 12px 32px rgba(0, 0, 0, 0.1),
        0 32px 80px rgba(0, 0, 0, 0.14);
}

.gallery::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--splash-wallpaper) center / cover no-repeat;
    filter: blur(var(--splash-wallpaper-blur))
        saturate(var(--splash-wallpaper-saturate))
        brightness(var(--splash-wallpaper-brightness));
    -webkit-filter: blur(var(--splash-wallpaper-blur))
        saturate(var(--splash-wallpaper-saturate))
        brightness(var(--splash-wallpaper-brightness));
    /* 20% scale gives ~10% buffer on each side so the blurred edge
       (driven by --splash-wallpaper-blur, currently 32px) is well
       outside the visible area on both Chrome and Safari. */
    transform: scale(1.2);
}

.gallery-row {
    position: relative;
    height: calc(var(--gallery-height) * var(--gallery-item-height));
    flex: 0 0 auto;
    overflow: visible;
}

.gallery-track {
    display: flex;
    gap: calc(var(--gallery-height) * var(--gallery-item-gap));
    height: 100%;
    width: max-content;
    animation: gallery-scroll linear infinite;
    will-change: transform;
}

.gallery-row:nth-child(1) .gallery-track {
    animation-duration: var(--row-1-duration);
    animation-direction: var(--row-1-direction);
}

.gallery-row:nth-child(2) .gallery-track {
    animation-duration: var(--row-2-duration);
    animation-direction: var(--row-2-direction);
}

.gallery-row:nth-child(3) .gallery-track {
    animation-duration: var(--row-3-duration);
    animation-direction: var(--row-3-direction);
}

.gallery-item {
    flex: 0 0 auto;
    height: 100%;
    width: auto;
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 1px solid;
    border-color: color-mix(
        in srgb,
        var(--color-text-primary) 10%,
        transparent
    );
    background: var(--color-bg-elevated);
    box-shadow: var(--shadow-sm);
    /* Padding-free wrapper so the img drives width — figure's defaults
       are already zeroed by the global reset. */
    line-height: 0;
}

.gallery-item img {
    display: block;
    height: 100%;
    width: auto;
    max-width: none;
}

@keyframes gallery-scroll {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-50%);
    }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-track {
        animation: none;
    }
}
