/* Cards block */

.block-cards {
    --card-gap: 20px;
    /* Smaller than the cases frame, so it reads the same on a smaller box */
    --card-inset: 16px;
    /* Landscape while the cards are full width; portrait once they sit three up */
    --card-ratio: 16 / 9;
    --card-transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.block-cards__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--card-gap);
}

/* Card
   --card-bg is the solid colour behind the image and the colour of the frame
   that opens on hover. It cycles every three cards, see below. */
.block-cards__card {
    --card-bg: var(--wp--preset--color--helder-blauw);
    --card-color: var(--wp--preset--color--warm-zwart);
    --card-hover: var(--wp--preset--color--helder-blauw);

    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: var(--card-ratio);
    padding: var(--card-gap);
    border-radius: var(--radius-06);
    background-color: var(--card-bg);
    color: var(--card-color);
    text-decoration: none;
    overflow: hidden;
    transition: color var(--card-transition);
}

/* Colour cycle, repeating every three cards. */
.block-cards__card:nth-of-type(3n + 1) {
    --card-bg: var(--wp--preset--color--helder-blauw);
}

.block-cards__card:nth-of-type(3n + 2) {
    --card-bg: var(--wp--preset--color--helder-groen);
}

.block-cards__card:nth-of-type(3n + 3) {
    --card-bg: var(--wp--preset--color--helder-geel);
}

/* Media — fills the whole card */

.block-cards__media {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.block-cards__media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity var(--card-transition);
}

/* Scrim over the photo, so the centred title stays readable once it shows */
.block-cards__media::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.08) 10%, rgba(0, 0, 0, 0.32) 45%, rgba(0, 0, 0, 0.08) 90%);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--card-transition);
}

/* The element is the hole; the box-shadow paints the frame around it in the
   card colour, so the image appears to open out from 30px inside. */
.block-cards__media-inset {
    position: absolute;
    z-index: 1;
    top: var(--card-inset);
    right: var(--card-inset);
    bottom: var(--card-inset);
    left: var(--card-inset);
    border-radius: var(--radius-06);
    box-shadow: 0 0 0 100vmax var(--card-bg);
    pointer-events: none;
    transition: top var(--card-transition), right var(--card-transition),
                bottom var(--card-transition), left var(--card-transition);
}

/* Content — centred over the image */

.block-cards__content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--card-gap);
    text-align: center;
    /* Fills the card through flex rather than height: 100%. A percentage height
       on a flex item resolves against the padding box in Safari, which pushed
       the icon past the card's padding and onto the bottom edge. */
    flex: 1;
    align-self: stretch;
    min-height: 0;
}

.block-cards__text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: auto;
}

/* White on the solid card, switching to the card colour once the image shows. */
.block-cards__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-04);
    background-color: var(--wp--preset--color--white);
    color: var(--card-color);
    transition: background-color var(--card-transition);
}

.block-cards__icon svg {
    display: block;
}

.block-cards__title {
    margin: 0;
    text-wrap: balance;
}

.block-cards__link {
    margin: 0;
}

/* Desktop */

@media (min-width: 782px) {
    .block-cards {
        --card-ratio: 4 / 5;
    }

    .block-cards__grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    /* Everything below is hover only, so it is desktop only — on a touch screen
       the card stays exactly as it starts. */

    /* Text and icon square both go to the hover colour, on every card. */
    .block-cards__card:hover,
    .block-cards__card:focus-visible {
        color: var(--card-hover);
    }

    .block-cards__card:hover .block-cards__icon,
    .block-cards__card:focus-visible .block-cards__icon {
        background-color: var(--card-hover);
        color: var(--card-color);
    }

    .block-cards__card:hover .block-cards__media img,
    .block-cards__card:focus-visible .block-cards__media img {
        opacity: 1;
    }

    .block-cards__card:hover .block-cards__media::after,
    .block-cards__card:focus-visible .block-cards__media::after {
        opacity: 1;
    }

    .block-cards__card:hover .block-cards__media-inset,
    .block-cards__card:focus-visible .block-cards__media-inset {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
    }
}
