/**
 * Section: feature-badges
 *
 * Extracted from template-parts/feature_badges.php.
 * Loaded via trunorth_enqueue_section('feature-badges').
 *
 * Per-instance CSS variables set on the wrapper:
 *   --fb-side-padding   : '0' when scroll mode, else 'calc(var(--vw) * 8)'
 *   --fb-badge-count    : count($badges)
 * Conditional layouts are gated on the modifier classes that PHP already
 * applies (FeatureBagdes-Container--scroll, FeatureBadges-Container-Wrapper--scroll),
 * so they live unconditionally in this stylesheet.
 */

.FeatureBadges-Section {
    display: flex;
    flex-direction: column;
    background-color: #f5f5f5;
    /* Equal top/bottom padding around the whole section so the row
       of badges sits with matching whitespace above and below. */
    padding: calc(var(--vw) * 3) var(--fb-side-padding, calc(var(--vw) * 8));

    .FeatureBadges-Caption {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        text-align: center;
    }

    .FeatureBadges-Content {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        height: 100%;
        /* Zero margin — the section padding above/below handles all
           the whitespace, keeping caption ⇄ row ⇄ bottom in balance. */
        margin: 0;
        /* 1.5× the previous 2vw = 3vw of breathing room between the
           caption and the row of icons, outer section padding untouched. */
        padding-top: calc(var(--vw) * 3);
        font-family: 'Montserrat', sans-serif;
    }

    .FeatureBadges-Container-Wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
    }

    .FeatureBagdes-Container {
        display: grid;
        width: 100%;
        height: 100%;
        /* Column count follows --fb-badge-count so 3 badges = 3 columns, 5 = 5,
           etc. Fixed max column width so partial rows stay centered instead of
           stretching. Falls back to 4 columns when --fb-badge-count is unset. */
        grid-template-columns: repeat(var(--fb-badge-count, 4), minmax(140px, 240px));
        justify-content: center;
        gap: 2rem;
        justify-items: center;
        align-items: start;
        position: relative;
    }

    .FeautreBadge {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        cursor: pointer;
        width: 100%;
        min-width: 0;
    }

    .Card {
        display: grid;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: calc((100% - 6rem) / 4);
        aspect-ratio: 3 / 4;
        background-color: white;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.5s ease, visibility 0.5s;
        pointer-events: none;
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        z-index: 10;
        border-radius: 0.5rem;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);

        div:first-child {
            overflow: hidden;
            min-height: 0;
            border-top-left-radius: 0.5rem;
            border-top-right-radius: 0.5rem;

            img {
                width: 100%;
                height: 100%;
                object-fit: contain;
            }
        }

        div:nth-child(2) {
            background-color: #c22127;
            color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: 400;
            border-bottom-right-radius: 0.5rem;
            border-bottom-left-radius: 0.5rem;
            font-size: 1.5rem;
            padding: calc(var(--vw) * 1);
            text-align: center;
        }
    }

    .FeautreBadge:hover + .Card,
    .Card:hover {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .IconContainer {
        background-color: #C22127;
        border-radius: 50%;
        padding: 1.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
        width: calc(var(--vw) * 8);
        height: calc(var(--vw) * 8);

        img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
    }

    .FeatureName {
        text-align: center;
        width: 100%;
        /* Let text wrap naturally; no forced clipping so long labels
           break to two lines on their own. */

        p {
            font-family: 'Montserrat', sans-serif;
            font-size: var(--font-body);
            font-weight: 400;
            color: #444;
            line-height: 1.25;
            margin: 0;
            word-break: normal;
            overflow-wrap: break-word;
        }
    }

    /* Scroll-mode layout (modifier classes are added by PHP when $enable_scroll is true) */
    .FeatureBadges-Container-Wrapper--scroll {
        overflow: hidden;
        width: 100%;
    }

    .FeatureBagdes-Container--scroll {
        display: flex;
        grid-template-columns: unset;
        width: max-content;
        flex-wrap: nowrap;
        gap: calc(var(--vw) * 4);
        animation: fb-scroll calc(var(--fb-badge-count, 1) * 4s) linear infinite;

        .FeautreBadge {
            width: calc(var(--vw) * 12);
            flex-shrink: 0;
        }
    }

    @media (max-width: 780px) {
        & {
            height: auto;
            padding: calc(var(--vw) * 4) calc(var(--vw) * 8);
        }

        .FeatureBagdes-Container:not(.FeatureBagdes-Container--scroll) {
            grid-template-columns: repeat(2, 1fr);
        }

        .IconContainer {
            width: calc(var(--vw) * 15);
            height: calc(var(--vw) * 15);
        }

        .FeatureName p {
            font-size: calc(var(--vw) * 2.5);
        }

        .Card {
            width: calc((100% - 2rem) / 2);

            div:nth-child(2) {
                font-size: calc(var(--vw) * 2.5);
                padding: calc(var(--vw) * 2);
            }
        }
    }
}

@keyframes fb-scroll {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-25%); }
}
