/* Modular M3-expressive-style carousel — inherits host page palette via CSS variables. */

.gallery-carousel {
    --carousel-item-w: 240px;
    --carousel-item-aspect: 9 / 16;
    --carousel-gap: 14px;
    --carousel-radius-resting: 32px;
    --carousel-radius-active: 24px;
    --carousel-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 100%;
    margin-top: 8px;
}

.carousel-rail {
    position: relative;
    width: 100%;
}

.carousel-track {
    display: flex;
    gap: var(--carousel-gap);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    padding: 14px calc(50% - var(--carousel-item-w) / 2) 18px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-mask-image: linear-gradient(to right, transparent 0, black 5%, black 95%, transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, black 5%, black 95%, transparent 100%);
    outline: none;
}

.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track:focus-visible { outline: none; }

.carousel-item {
    appearance: none;
    -webkit-appearance: none;
    background: var(--card, #1a1a1a);
    color: inherit;
    border: none;
    padding: 0;
    margin: 0;
    flex: 0 0 auto;
    width: var(--carousel-item-w);
    aspect-ratio: var(--carousel-item-aspect);
    border-radius: var(--carousel-radius-resting);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    box-shadow: var(--shadow-sm, 0 2px 10px rgba(0, 0, 0, 0.08));
    transform: scale(0.84);
    filter: saturate(0.72) brightness(0.92);
    transition:
        transform 0.5s var(--carousel-ease-spring),
        border-radius 0.5s var(--carousel-ease-spring),
        box-shadow 0.4s ease,
        filter 0.4s ease;
    font-family: inherit;
}

.carousel-item:focus-visible {
    outline: 3px solid var(--accent, currentColor);
    outline-offset: 4px;
}

.carousel-item.is-active {
    transform: scale(1);
    border-radius: var(--carousel-radius-active);
    box-shadow: var(--shadow-lg, 0 16px 40px rgba(0, 0, 0, 0.22));
    filter: saturate(1) brightness(1);
    cursor: zoom-in;
}

.carousel-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.carousel-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 22px 20px 18px;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.45) 60%, rgba(0, 0, 0, 0) 100%);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

.carousel-item.is-active .carousel-caption {
    opacity: 1;
    transform: translateY(0);
}

/* CONTROLS */
.carousel-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
}

.carousel-btn {
    appearance: none;
    -webkit-appearance: none;
    background: var(--card, #fff);
    color: var(--text, inherit);
    border: 1.5px solid var(--border, rgba(0, 0, 0, 0.12));
    width: 40px;
    height: 40px;
    border-radius: 999px;
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    line-height: 1;
    font-family: inherit;
    padding: 0;
    transition: color 0.15s, border-color 0.15s, transform 0.2s, box-shadow 0.2s;
}

.carousel-btn:hover:not(:disabled),
.carousel-btn:focus-visible:not(:disabled) {
    color: var(--accent, currentColor);
    border-color: var(--accent, currentColor);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm, 0 4px 12px rgba(0, 0, 0, 0.08));
    outline: none;
}

.carousel-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* DOTS — morphing pill indicators */
.carousel-dots {
    display: flex;
    align-items: center;
    gap: 6px;
}

.carousel-dot {
    appearance: none;
    -webkit-appearance: none;
    width: 8px;
    height: 8px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: var(--border, rgba(0, 0, 0, 0.22));
    cursor: pointer;
    font-family: inherit;
    transition:
        width 0.45s cubic-bezier(0.34, 1.56, 0.64, 1),
        background 0.25s ease,
        opacity 0.2s ease;
}

.carousel-dot:hover { opacity: 0.7; }

.carousel-dot.is-active {
    width: 26px;
    background: var(--accent, currentColor);
}

.carousel-dot:focus-visible {
    outline: 2px solid var(--accent, currentColor);
    outline-offset: 3px;
}

.gallery-empty {
    text-align: center;
    color: var(--text-dim, #666);
    padding: 32px;
    font-style: italic;
}

/* RESPONSIVE */
@media (max-width: 600px) {
    .gallery-carousel {
        --carousel-item-w: 62vw;
        --carousel-gap: 10px;
        --carousel-radius-resting: 28px;
        --carousel-radius-active: 22px;
    }
    .carousel-btn { width: 36px; height: 36px; font-size: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
    .carousel-track { scroll-behavior: auto; }
    .carousel-item,
    .carousel-caption,
    .carousel-dot { transition: none; }
}

/* LIGHTBOX (unchanged behavior, still used when tapping the active item) */
.gallery-lightbox {
    border: none;
    padding: 0;
    margin: 0;
    background: transparent;
    color: inherit;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
}

.gallery-lightbox::backdrop {
    background: rgba(0, 0, 0, 0.84);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.gallery-lightbox[open] {
    display: grid;
    grid-template-columns: 56px 1fr 56px;
    align-items: center;
    gap: 16px;
    padding: 24px;
    box-sizing: border-box;
    position: relative;
}

.gallery-lb-figure {
    grid-column: 2;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    min-width: 0;
    max-height: 100%;
}

.gallery-lb-img {
    display: block;
    max-height: 78vh;
    max-width: 100%;
    object-fit: contain;
    border-radius: 18px;
    box-shadow: 0 24px 72px rgba(0, 0, 0, 0.55);
    background: #1a1a1a;
}

.gallery-lb-caption {
    color: #fff;
    font-size: 0.95rem;
    text-align: center;
    max-width: 720px;
    opacity: 0.92;
    line-height: 1.5;
}

.gallery-lb-caption:empty { display: none; }

.gallery-lb-close,
.gallery-lb-prev,
.gallery-lb-next {
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.35rem;
    font-weight: 600;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.15s ease, transform 0.15s ease;
    line-height: 1;
}

.gallery-lb-close:hover,
.gallery-lb-prev:hover,
.gallery-lb-next:hover,
.gallery-lb-close:focus-visible,
.gallery-lb-prev:focus-visible,
.gallery-lb-next:focus-visible {
    background: rgba(255, 255, 255, 0.24);
    outline: none;
}

.gallery-lb-close[hidden],
.gallery-lb-prev[hidden],
.gallery-lb-next[hidden] { display: none; }

.gallery-lb-prev { grid-column: 1; justify-self: center; }
.gallery-lb-next { grid-column: 3; justify-self: center; }

.gallery-lb-close {
    position: absolute;
    top: 18px;
    right: 18px;
}

@media (max-width: 600px) {
    .gallery-lightbox[open] { grid-template-columns: 44px 1fr 44px; padding: 12px; gap: 8px; }
    .gallery-lb-img { max-height: 72vh; border-radius: 14px; }
    .gallery-lb-close,
    .gallery-lb-prev,
    .gallery-lb-next { width: 40px; height: 40px; font-size: 1.2rem; }
}
