/* ==========================================================================
   Services

   Card Style and Image Ratio have been in the editor for a while with
   nothing behind them: the classes were printed and no rule ever matched
   them, so picking 16:9 or Overlay changed the markup and nothing else.
   Both are implemented here for the first time, along with the spacing,
   text position and lightbox options.

   Everything a variant changes is a token, so the variants are short lists
   of overrides rather than second copies of the card.
   ========================================================================== */

.ssb-services {

    /* Standard is the 2rem the grid already used, so old blocks do not move. */
    --ssb-services-gap: 2rem;

    /* The crop. `auto` is Original: no crop at all. */
    --ssb-services-ratio: 4 / 3;

    /* Card chrome. Nothing by default — Standard is text under a picture. */
    --ssb-services-card-bg: transparent;
    --ssb-services-card-border: 0 solid transparent;
    --ssb-services-card-pad: 0;
    --ssb-services-content-pad: 1.5rem 0 0;

    --ssb-services-fg: var(--color-text);
    --ssb-services-heading: var(--color-heading, var(--color-text));

    padding: 0rem 0;
    color: var(--ssb-services-fg);
}

.ssb-services__eyebrow {
    margin-bottom: .5rem;
}

.ssb-services__title {
    margin-bottom: 1rem;
}

.ssb-services__description {
    margin-bottom: 3rem;
    max-width: 800px;
}


/* The header's optional button
   --------------------------------------------------------------------------
   Without one, .ssb-services__header and .ssb-services__header-text are
   plain divs and nothing here applies: the eyebrow, title and
   description stack exactly as they did before either existed.

   With one, the header becomes a row. The gap between the header and the
   grid moves from the description's own margin onto the header, because
   with two columns the description is no longer reliably the last thing
   in it -- a tall button would be, and the space below the section would
   come and go with the length of the text.
   ========================================================================== */

.ssb-services__header--with-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2.5rem;
    margin-bottom: 3rem;
}

.ssb-services__header--with-button .ssb-services__header-text {
    /* So a long unbroken word shrinks the column instead of pushing the
       button off the end of it. */
    min-width: 0;
}

.ssb-services__header--with-button .ssb-services__description {
    margin-bottom: 0;
}

.ssb-services__header-button {
    flex: 0 0 auto;
}

/*
 * Side by side needs room for both. Below this the button goes under the
 * text, left-aligned with it, which is where the eye is already.
 */
@media (max-width: 767px) {

    .ssb-services__header--with-button {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.75rem;
    }

}

/* Grid
   ========================================================================== */

.ssb-services__grid {
    display: grid;
    gap: var(--ssb-services-gap);
}

/*
 * Space between cards. Three steps rather than a number, so a client
 * cannot set the gap wider than the cards.
 */
.ssb-services--gap-tight {
    --ssb-services-gap: 1rem;
}

.ssb-services--gap-standard {
    --ssb-services-gap: 2rem;
}

.ssb-services--gap-loose {
    --ssb-services-gap: 3.5rem;
}

.ssb-services__grid--2 {
    grid-template-columns: repeat(2, 1fr);
}

.ssb-services__grid--3 {
    grid-template-columns: repeat(3, 1fr);
}

.ssb-services__grid--4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Card
   ========================================================================== */

.ssb-service-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--ssb-services-card-pad);
    background: var(--ssb-services-card-bg);
    border: var(--ssb-services-card-border);
}

/*
 * The crop.
 *
 * aspect-ratio on the frame with object-fit on the image, so every card in
 * the row is the same height whatever shape the files are. `width: 100%`
 * alone was doing neither — it stretched the image to the column and left
 * the height to the file, which is why the row never lined up.
 */
.ssb-service-card__image {
    position: relative;
    overflow: hidden;
    aspect-ratio: var(--ssb-services-ratio);
}

.ssb-service-card__image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/*
 * Original: no frame, no crop, the file's own shape.
 *
 * `height: auto` is the part that matters. WordPress writes width and
 * height attributes onto the img, and the browser treats them as a
 * presentational hint — so `width: 100%` on its own leaves the height
 * hint standing and the picture comes out stretched. With height auto the
 * browser uses the attributes for the aspect ratio instead, which is also
 * what stops the layout jumping as the image loads.
 */
.ssb-services--original .ssb-service-card__image {
    aspect-ratio: auto;
    overflow: visible;
}

.ssb-services--original .ssb-service-card__image img {
    height: auto;
    object-fit: fill;
}

.ssb-services--square {
    --ssb-services-ratio: 1 / 1;
}

.ssb-services--landscape {
    --ssb-services-ratio: 4 / 3;
}

.ssb-services--wide {
    --ssb-services-ratio: 16 / 9;
}

.ssb-services--portrait {
    --ssb-services-ratio: 3 / 4;
}

.ssb-service-card__content {
    padding: var(--ssb-services-content-pad);
}

/*
 * Text above the image.
 *
 * The swap itself happens in render.php, which prints the two halves in
 * whichever order the block asked for. Doing it here with `order` moved
 * the picture for the eye only — a screen reader, and the Tab key, both
 * stayed on source order, so the text on top meant tabbing down into the
 * picture and back up to the words. All this rule does is move the padding
 * to the side the gap is now on.
 */
.ssb-services--text-top .ssb-service-card__content {
    padding: 0 0 1.5rem;
}

.ssb-service-card__eyebrow {
    margin-bottom: .5rem;
}

.ssb-service-card__title {
    margin-bottom: 1rem;
}

.ssb-service-card__description {
    margin-bottom: 1.5rem;
}

/* Card styles
   --------------------------------------------------------------------------
   Neutral here on purpose. A client theme gives these their colors; what
   the plugin owns is the shape, and every value below has to look
   deliberate on a site with no child theme at all.
   ========================================================================== */

/* Standard: text under a picture, no chrome. The defaults above are it. */

/*
 * The card paints a surface of its own, so it says what the text on it
 * is. Without this a Boxed Services block inside a Secondary Section
 * drew three white cards and filled them with the band's white text.
 *
 * On the card rather than on the block root, which is where the white
 * is: the framework's [class*="--bg-base"] rule cannot reach a surface
 * painted one level in.
 */
.ssb-services--boxed {
    --ssb-services-card-bg: var(--color-surface, #ffffff);
    --ssb-services-card-border: 1px solid var(--color-border, #ddd);
    --ssb-services-content-pad: 1.5rem;
}

.ssb-services--boxed .ssb-service-card {
    --color-text: var(--color-on-surface);
    --color-heading: var(--color-on-surface);
    color: var(--color-on-surface);
}

/*
 * Boxed: the image has to reach the edges of the box, so it is pulled out
 * by the padding the card carries. Written from the one token, so the two
 * cannot drift apart.
 */
.ssb-services--boxed .ssb-service-card__image {
    margin: 0;
}

.ssb-services--boxed .ssb-service-card {
    overflow: hidden;
}

/* Overlay
   --------------------------------------------------------------------------
   The text sits on the image. Which means the image decides whether the
   text can be read, and no picked color can answer for a photograph — so
   the text is always light and always over a scrim, rather than letting an
   editor arrive at an unreadable pairing.
   ========================================================================== */

.ssb-services--overlay .ssb-service-card {
    position: relative;
    isolation: isolate;
    min-height: 320px;
    justify-content: flex-end;
    overflow: hidden;
    color: #ffffff;
}

.ssb-services--overlay .ssb-service-card__image {
    position: absolute;
    inset: 0;
    z-index: 0;
    aspect-ratio: auto;
}

/*
 * The scrim fades the picture from the bottom up, so the photograph is
 * still a photograph at the top of the card.
 *
 * It is not what makes the words readable. Its stops are percentages of
 * the card, and the text box is whatever height the text is — measured on
 * a white photograph, which is the worst case, the top of the content band
 * landed on rgb(164,164,164) and even white text there is 2.46:1. A card
 * with a longer description would have reached further up still. The
 * backing below is what answers for the text.
 */
.ssb-services--overlay .ssb-service-card__image::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, .85) 0%,
        rgba(0, 0, 0, .55) 45%,
        rgba(0, 0, 0, .15) 75%,
        rgba(0, 0, 0, 0) 100%
    );
}

/*
 * The backing that actually carries the text, drawn on the text box rather
 * than on a fraction of the card — so it is exactly as tall as the words
 * are, however many there are.
 *
 * .62 at its lightest, which is the number this is built around: over a
 * pure white photograph — the worst there is — that alone leaves rgb(97)
 * behind the words and white on it is 5.4:1, clear of the 4.5:1 small text
 * needs without the gradient above having to help. In practice the two
 * stack and it measures far better than that; the point is that the
 * backing carries it on its own, so changing the gradient later cannot
 * quietly take the guarantee away.
 *
 * Any lighter and this stops being true. It is not a taste setting.
 */
.ssb-services--overlay .ssb-service-card__content {
    position: relative;
    z-index: 1;
    padding: 1.5rem;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, .8) 0%,
        rgba(0, 0, 0, .68) 70%,
        rgba(0, 0, 0, .62) 100%
    );
}

.ssb-services--overlay .ssb-service-card__title,
.ssb-services--overlay .ssb-service-card__description,
.ssb-services--overlay .ssb-service-card__eyebrow {
    color: inherit;
}

/*
 * The link covering the whole card. Above the scrim, below the words, so
 * text can still be selected and a link inside the description still
 * works.
 */
.ssb-service-card__overlay-link {
    position: absolute;
    inset: 0;
    z-index: 2;
}

.ssb-services--overlay .ssb-service-card:hover .ssb-service-card__image img,
.ssb-services--overlay .ssb-service-card:focus-within .ssb-service-card__image img {
    transform: scale(1.05);
}

.ssb-services--overlay .ssb-service-card__image img {
    transition: transform .6s cubic-bezier(.22, .61, .36, 1);
}

.ssb-service-card__overlay-link:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: -3px;
}

/* Zoom
   --------------------------------------------------------------------------
   A real link to the full-size file, so it works with no JavaScript. The
   magnifier is drawn rather than loaded, so it follows currentColor and
   there is no icon font or SVG request for one glyph.
   ========================================================================== */

.ssb-service-card__zoom {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
}

.ssb-service-card__zoom-icon {
    position: absolute;
    right: .75rem;
    bottom: .75rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, .65);
    opacity: 0;
    transition: opacity var(--transition-fast, .2s);
}

/* The glass: a ring and a handle, both in currentColor. */
.ssb-service-card__zoom-icon::before {
    content: "";
    position: absolute;
    top: .55rem;
    left: .55rem;
    width: .75rem;
    height: .75rem;
    border: 2px solid #ffffff;
    border-radius: 50%;
}

.ssb-service-card__zoom-icon::after {
    content: "";
    position: absolute;
    right: .6rem;
    bottom: .6rem;
    width: .45rem;
    height: 2px;
    background: #ffffff;
    transform: rotate(45deg);
    transform-origin: right center;
}

/*
 * Shown on hover and on keyboard focus both. On a touch screen there is no
 * hover at all, so it is simply always visible there — an affordance that
 * only appears for mouse users is not one.
 */
.ssb-service-card__zoom:hover .ssb-service-card__zoom-icon,
.ssb-service-card__zoom:focus-visible .ssb-service-card__zoom-icon {
    opacity: 1;
}

@media (hover: none) {

    .ssb-service-card__zoom-icon {
        opacity: 1;
    }

}

.ssb-service-card__zoom:focus-visible {
    outline: 3px solid var(--color-primary, currentColor);
    outline-offset: 2px;
}

/*
 * The enlarged image inside the shared modal.
 *
 * The modal is appended to the body, outside this block, but this
 * stylesheet is a plain one and the class is ours, so the rule finds it
 * wherever the dialog ends up. Capped against the viewport rather than
 * given a size: the point of the lightbox is to show the file as large as
 * it will go without having to scroll to see it.
 */
.ssb-services__lightbox-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 75vh;
    margin-inline: auto;
}

@media (prefers-reduced-motion: reduce) {

    .ssb-services--overlay .ssb-service-card__image img,
    .ssb-service-card__zoom-icon {
        transition: none;
    }

    .ssb-services--overlay .ssb-service-card:hover .ssb-service-card__image img,
    .ssb-services--overlay .ssb-service-card:focus-within .ssb-service-card__image img {
        transform: none;
    }

}

@media (max-width: 991px) {

    .ssb-services__grid--4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .ssb-services__grid--3 {
        grid-template-columns: repeat(2, 1fr);
    }

}

@media (max-width: 767px) {

    .ssb-services__grid,
    .ssb-services__grid--2,
    .ssb-services__grid--3,
    .ssb-services__grid--4 {
        grid-template-columns: 1fr;
    }

}