/*
 * Features block, "Photo carousel" layout
 * (templates/public/includes/hub_features_carousel.html).
 *
 * A photo band with the feature cards overlapping its bottom edge.
 *   - Narrow (phones, half-width containers): one card in focus, neighbours
 *     peek in, native scroll-snap swiping.
 *   - Wide (720px+ of block width): up to four cards side by side; more than
 *     four scroll with the arrows.
 * Sized with container queries so the block adapts to its column, not the
 * viewport. Colours come only from the hub theme variables.
 */

.hub-fc {
    --hub-fc-accent: var(--hub-accent, var(--hub-emerald, var(--slms-accent)));
    /* Outlines and inactive dots: derived from the text colour so they read on
       light and dark hub themes alike. */
    --hub-fc-line: color-mix(in srgb, var(--hub-text) 20%, transparent);
    --hub-fc-gap: 12px;
    /* Photo band shape. The cards overlap its bottom edge by a fixed share of
       the width, so a taller band shows more of the photo. */
    --hub-fc-stage-ratio: 1 / 1;
    --hub-fc-stage-ratio-wide: 16 / 9;
    --hub-fc-radius: 16px;
    container-type: inline-size;
    position: relative;
    padding-bottom: 0.25rem;
}

/* ── Photo band ─────────────────────────────────────────────── */

.hub-fc__stage {
    position: relative;
    aspect-ratio: var(--hub-fc-stage-ratio);
    /* Never taller than most of the screen, e.g. on short laptop displays. */
    max-height: 80vh;
    max-width: 100%;
    overflow: hidden;
    border-radius: var(--hub-fc-radius);
    background: var(--hub-surface-alt);
}

.hub-fc__slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    transform: scale(1.04);
    transition: opacity 0.5s ease, transform 1.4s ease;
}

.hub-fc__slide.is-active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.hub-fc__slide img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: var(--hub-fc-mobile-fit, cover);
    object-position: var(--hub-fc-mobile-focus, 50% 50%);
    transform: scale(var(--hub-fc-mobile-zoom, 1));
    transform-origin: var(--hub-fc-mobile-focus, 50% 50%);
}

.hub-fc__slide[data-image-state='error'] img { opacity: 0; }

/* A linked card's photo goes where its title goes (see the template). */
.hub-fc__photo {
    display: block;
    width: 100%;
    height: 100%;
    color: inherit;
}
.hub-fc__image-feedback { position: absolute; inset: 1rem 1rem auto; padding: .75rem; background: var(--hub-surface); color: var(--hub-text); border-radius: var(--hub-fc-radius); }
.hub-fc__image-feedback button { display: block; min-height: 44px; margin-top: .5rem; padding: .5rem 1rem; color: var(--hub-text); background: var(--hub-surface-alt); border: 1px solid var(--hub-fc-line); border-radius: var(--hub-fc-radius); }
.hub-fc__image-feedback[hidden], .hub-fc__image-feedback button[hidden] { display: none; }

@container (min-width: 720px) {
    .hub-fc__slide img {
        object-fit: var(--hub-fc-fit, cover);
        object-position: var(--hub-fc-focus, 50% 50%);
        transform: scale(var(--hub-fc-zoom, 1));
        transform-origin: var(--hub-fc-focus, 50% 50%);
    }
}

.hub-fc__fallback {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    background:
        linear-gradient(135deg,
            var(--hub-fc-accent) 0%,
            color-mix(in srgb, var(--hub-fc-accent) 62%, var(--hub-text)) 100%);
}

.hub-fc__fallback i {
    font-size: clamp(3rem, 14cqi, 6rem);
    color: var(--hub-surface);
    opacity: 0.9;
}

/* ── Card track ─────────────────────────────────────────────── */

.hub-fc__track {
    position: relative;
    z-index: 1;
    display: flex;
    gap: var(--hub-fc-gap);
    margin-top: -16%;
    /* The side padding is where the neighbouring cards peek in. */
    padding: 4px 12% 12px;
    scroll-padding-inline: 12%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

.hub-fc__track::-webkit-scrollbar {
    display: none;
}

.hub-fc__card {
    position: relative;
    flex: 0 0 100%;
    min-width: 0;
    scroll-snap-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1.5rem 1.25rem 1.25rem;
    background: var(--hub-surface);
    color: var(--hub-text);
    border: 3px solid var(--hub-fc-line);
    border-radius: var(--hub-fc-radius);
    box-shadow: var(--hub-shadow-md);
    transition: border-color var(--transition-smooth, 0.25s ease);
}

.hub-fc__card.is-active {
    border-color: var(--hub-fc-accent);
}

.hub-fc--single .hub-fc__track {
    padding-inline: 6%;
}

.hub-fc__eyebrow {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--hub-text);
}

.hub-fc__title {
    margin: 0;
    font-size: clamp(1.4rem, 7cqi, 1.9rem);
    font-weight: 800;
    line-height: 1.1;
    color: var(--hub-text);
    text-wrap: balance;
    overflow-wrap: anywhere;
}

.hub-fc__title a {
    color: inherit;
    text-decoration: none;
}

/* The whole card is one link: the title's link covers it. On phones only the
   card in focus does, so tapping a neighbour that peeks in brings it into
   focus first instead of leaving the page. The button sits above the cover
   and goes to the same place. */
.hub-fc__card.is-active .hub-fc__title a::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
}

.hub-fc__btn {
    position: relative;
    z-index: 2;
}

.hub-fc__title a:hover,
.hub-fc__card:hover .hub-fc__title a,
.hub-fc:has(.hub-fc__slide.is-active .hub-fc__photo:hover) .hub-fc__card.is-active .hub-fc__title a {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

/* Pointing at a linked card or its photo nudges the photo in. */
.hub-fc__slide img {
    transition: scale 0.45s ease;
}

.hub-fc:has(.hub-fc__card.is-active:hover .hub-fc__title a, .hub-fc__slide.is-active .hub-fc__photo:hover) .hub-fc__slide.is-active img {
    scale: 1.03;
}

.hub-fc__desc {
    flex: 1;
    margin: 0;
    color: var(--hub-text-muted);
    font-size: 1rem;
    line-height: 1.55;
}

.hub-fc__btn {
    display: block;
    margin-top: 0.4rem;
    padding: 0.7rem 0.75rem;
    text-align: center;
    font-weight: 700;
    color: var(--hub-text);
    text-decoration: none;
    background: var(--hub-surface);
    border: 2px solid var(--hub-fc-line);
    border-radius: calc(var(--hub-fc-radius) - 6px);
    transition: border-color var(--transition-smooth, 0.25s ease), background var(--transition-smooth, 0.25s ease);
}

.hub-fc__card.is-active .hub-fc__btn {
    border-color: var(--hub-fc-accent);
}

a.hub-fc__btn:hover {
    color: var(--hub-text);
    background: color-mix(in srgb, var(--hub-fc-accent) 12%, var(--hub-surface));
}

.hub-fc__title a:focus-visible,
.hub-fc__btn:focus-visible,
.hub-fc__arrow:focus-visible,
.hub-fc__dot:focus-visible {
    outline: 3px solid var(--hub-fc-accent);
    outline-offset: 2px;
}

/* ── Arrows, dots, counter ──────────────────────────────────── */

.hub-fc__nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    padding-top: 0.5rem;
}

.hub-fc__arrow {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--hub-fc-line);
    border-radius: 50%;
    background: var(--hub-surface);
    color: var(--hub-text);
    font-size: 1.1rem;
    cursor: pointer;
}

.hub-fc__arrow[aria-disabled="true"] {
    opacity: 0.35;
    cursor: default;
}

.hub-fc__dots {
    display: flex;
    gap: 6px;
}

.hub-fc__dot {
    width: 9px;
    height: 9px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--hub-fc-line);
    cursor: pointer;
    transition: width var(--transition-smooth, 0.25s ease), background var(--transition-smooth, 0.25s ease);
}

.hub-fc__dot[aria-current="true"] {
    width: 24px;
    background: var(--hub-fc-accent);
}

.hub-fc__count {
    min-width: 3.2em;
    text-align: center;
    font-size: 0.8rem;
    color: var(--hub-text-muted);
    font-variant-numeric: tabular-nums;
}

/* Read out by screen readers when an arrow, dot or key changes the card. */
.hub-fc__status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ── Wide: cards side by side, the photo follows the mouse ─── */

@container (min-width: 720px) {
    .hub-fc__stage {
        aspect-ratio: var(--hub-fc-stage-ratio-wide);
    }

    /* Every card is in view, so each one is a link as a whole. */
    .hub-fc__title a::after {
        content: "";
        position: absolute;
        inset: 0;
        z-index: 1;
    }

    .hub-fc__track {
        --hub-fc-visible: clamp(3, var(--hub-fc-count), 4);
        --hub-fc-gap: 16px;
        margin-top: -9%;
        padding: 4px 24px 12px;
        scroll-padding-inline: 24px;
    }

    .hub-fc__card {
        flex-basis: calc((100% - (var(--hub-fc-visible) - 1) * var(--hub-fc-gap)) / var(--hub-fc-visible));
        scroll-snap-align: start;
        padding: 1.4rem 1.1rem 1.1rem;
    }

    .hub-fc__title {
        font-size: 1.55rem;
    }

    .hub-fc__desc {
        font-size: 0.97rem;
    }

    .hub-fc[data-count="2"] .hub-fc__track {
        justify-content: center;
    }

    .hub-fc--single .hub-fc__track {
        justify-content: center;
    }

    .hub-fc--single .hub-fc__card {
        flex-basis: min(100%, 420px);
    }

    /* Every card fits, so the mouse needs no arrows. They stay in the tab
       order for keyboard users and appear over the photo once focused. */
    .hub-fc[data-fits-desktop] .hub-fc__nav:not(:focus-within) {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .hub-fc[data-fits-desktop] .hub-fc__nav:focus-within {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
        z-index: 2;
        padding: 0.35rem 0.5rem;
        background: var(--hub-surface);
        border-radius: 999px;
        box-shadow: var(--hub-shadow-md);
    }
}

@media (prefers-reduced-motion: reduce) {
    .hub-fc__slide,
    .hub-fc__card,
    .hub-fc__btn,
    .hub-fc__dot {
        transition: none;
    }

    .hub-fc__slide {
        transform: none;
    }

    .hub-fc__slide img {
        transition: none;
    }

    .hub-fc .hub-fc__slide.is-active img {
        scale: none !important;
    }
}

