/* ==========================================================================
   Event Slider

   One slide is visible at a time. The slide that is showing carries
   .is-active and every other slide carries the [hidden] attribute, which
   keeps them out of the tab order and out of the accessibility tree.

   Without JavaScript the first slide renders as a static hero: the markup
   ships with slide one already active, and the controls are hidden until
   view.js adds .is-enhanced.
   ========================================================================== */

.granada-event-slider {
    --granada-slider-height: clamp(520px, 56vw, 720px);
    --granada-nav-space: 150px;
    --granada-scrim: .75;

    /*
     * Ink and scrim move together. --granada-ink is the text, the arrows,
     * the navigation and every focus ring; --granada-scrim-rgb is what the
     * shading over the picture is made of. White type gets black shading,
     * black type gets white shading, and because one control sets both
     * there is no way to end up with black type over a darkened picture.
     */
    --granada-ink: var(--color-light, #fff);
    --granada-ink-rgb: 255, 255, 255;
    --granada-scrim-rgb: 0, 0, 0;
    --granada-chip: rgba(0, 0, 0, .25);

    position: relative;
    background-color: var(--color-dark);
    color: var(--granada-ink);
}

/* Height options
   ========================================================================== */

.granada-event-slider--height-tall {
    --granada-slider-height: clamp(600px, 68vw, 860px);
}

.granada-event-slider--height-full {
    --granada-slider-height: calc(100vh - var(--header-height, 0px));
    --granada-slider-height: calc(100svh - var(--header-height, 0px));
}

/* Text color
   --------------------------------------------------------------------------
   Per slide, because the right answer depends on the picture and a slider
   holds several.

   The slide sets the tokens for its own content. The arrows and the
   navigation sit outside the slide but on top of it, so the root picks the
   tokens up from whichever slide is showing -- :has() rather than a class
   view.js has to remember to move, which is one fewer thing to keep in
   step. A browser without :has() keeps the white chrome, which is what it
   had before this existed.

   White is not written out as a variant: it is what the root already
   declares, so a slide that does not ask for anything gets it.
   ========================================================================== */

.granada-event-slider__slide--ink-black,
.granada-event-slider:has(.granada-event-slider__slide.is-active.granada-event-slider__slide--ink-black) {
    --granada-ink: var(--color-text, #231f20);
    --granada-ink-rgb: 35, 31, 32;
    --granada-scrim-rgb: 255, 255, 255;
    --granada-chip: rgba(255, 255, 255, .45);

    /*
     * The plate behind the slides, seen while an image loads or where one
     * is missing, follows the ink too -- otherwise a slide set for black
     * type flashes charcoal before its picture arrives. Harmless on the
     * slide itself, which the picture covers.
     */
    background-color: var(--color-light, #fff);
}

/*
 * The second button is white by default, for a dark slide. On a light one
 * the render swaps it to .btn--secondary and it is colored here: the
 * design system gives that button the page's text color, which on a
 * photograph is not reliably readable, so it is given the charcoal and
 * the white explicitly.
 */
.granada-event-slider__slide--ink-black .granada-event-slider__button--secondary {
    background: var(--color-text, #231f20);
    color: var(--color-light, #fff);
    border-color: var(--color-text, #231f20);
}

.granada-event-slider__slide--ink-black .granada-event-slider__button--secondary:hover,
.granada-event-slider__slide--ink-black .granada-event-slider__button--secondary:focus-visible {
    background: var(--color-text, #231f20);
    color: var(--color-light, #fff);
    opacity: .9;
}


/* Scrim strength
   ========================================================================== */

/*
 * None. The scrim still renders, at nothing -- the gradients are built
 * from this token, so zero is a transparent one and there is no separate
 * code path to keep in step.
 *
 * It is a real choice and not a safe one: the words are white or black
 * directly on the picture, and whether they can be read depends entirely
 * on what is behind them. Worth looking at on a phone, where the text
 * covers most of the frame rather than one column of it.
 */
.granada-event-slider--overlay-none {
    --granada-scrim: 0;
}

.granada-event-slider--overlay-light {
    --granada-scrim: .55;
}

.granada-event-slider--overlay-dark {
    --granada-scrim: .9;
}

/*
 * One slide asking for something other than the slider's setting.
 *
 * No specificity contest to win: the slider declares --granada-scrim on
 * the root and the slide inherits it, so a declaration on the slide
 * itself is simply nearer and takes over for everything inside it. The
 * class is only printed when a slide was given a strength of its own,
 * so a slide that was not goes on inheriting.
 *
 * Only the scrim moves. --granada-scrim-rgb -- whether the shading is
 * black or white -- stays tied to the Text Color above, so turning a
 * slide's shading up cannot leave it shading the wrong way.
 */
.granada-event-slider__slide--overlay-none {
    --granada-scrim: 0;
}

.granada-event-slider__slide--overlay-light {
    --granada-scrim: .55;
}

.granada-event-slider__slide--overlay-medium {
    --granada-scrim: .75;
}

.granada-event-slider__slide--overlay-dark {
    --granada-scrim: .9;
}

/* Editor preview width
   --------------------------------------------------------------------------
   The slider is full-bleed on the page. In the editor it was drawn at the
   content width with the rest of the page around it, which is not what it
   is going to look like, and the pictures were cropped to a frame two
   thirds the width they will really have.

   What holds it there is a max-width on the block wrapper the editor puts
   around the preview -- measured at 1040px inside a 1728px canvas, with
   the margins either side being `auto` taking up the slack. Releasing the
   max-width is enough on its own: auto margins have nothing left to
   absorb once the box fills its parent.

   The attribute is repeated to carry the selector over whatever the
   editor declares that max-width with, the same transform the child
   themes use on a block class. It matches exactly the same element. Both
   shapes are written out because the canvas is wrapped in
   .editor-styles-wrapper on some setups and not others.

   None of this reaches the front end: ACF prints the block markup there
   with no wrapper, so there is no [data-type] for either selector to
   find.
   ========================================================================== */

.wp-block[data-type="acf/granada-event-slider"][data-type],
.editor-styles-wrapper .wp-block[data-type="acf/granada-event-slider"][data-type] {
    max-width: none;
}


/* Viewport
   ========================================================================== */

.granada-event-slider__viewport {
    position: relative;
    overflow: hidden;
}

/* Slides
   --------------------------------------------------------------------------
   The [hidden] rule is written out with a class attached so it always
   outranks the base rule, whatever order the stylesheets end up in.
   ========================================================================== */

.granada-event-slider__slide {
    position: relative;
    display: flex;
    align-items: flex-end;
    min-height: var(--granada-slider-height);
}

/*
 * Two ways of saying the same thing, because one of them does not always
 * arrive. The attribute is stripped out of the markup on its way into the
 * block editor, which left all five slides drawing one under the other in
 * a preview while the front end showed one. The class comes through.
 *
 * Both are written with the block's class attached so they outrank the
 * base rule above whatever order the stylesheets end up in.
 */
.granada-event-slider__slide[hidden],
.granada-event-slider__slide.is-hidden {
    display: none;
}

.granada-event-slider.is-enhanced .granada-event-slider__slide.is-active {
    animation: granada-slider-fade var(--transition-slow, .5s) both;
}

@keyframes granada-slider-fade {

    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }

}

/* Image and scrim
   ========================================================================== */

.granada-event-slider__media {
    position: absolute;
    inset: 0;
}

/*
 * <picture> is inline by default, which would leave the image sitting on
 * a text baseline instead of filling the slide.
 */
.granada-event-slider__picture {
    display: block;
    width: 100%;
    height: 100%;
}

.granada-event-slider__image {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    object-position: center;
}

.granada-event-slider__scrim {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(
            to top,
            rgba(var(--granada-scrim-rgb), var(--granada-scrim)) 0%,
            rgba(var(--granada-scrim-rgb), calc(var(--granada-scrim) * .55)) 40%,
            rgba(var(--granada-scrim-rgb), 0) 75%
        ),
        linear-gradient(
            to right,
            rgba(var(--granada-scrim-rgb), calc(var(--granada-scrim) * .5)) 0%,
            rgba(var(--granada-scrim-rgb), 0) 60%
        );
}

/* Content
   ========================================================================== */

.granada-event-slider__inner {
    position: relative;
    z-index: 1;
    width: 100%;
    padding-top: var(--space-2xl);
    padding-bottom: var(--granada-nav-space);
}

.granada-event-slider__content {
    max-width: 40rem;
}

.granada-event-slider__eyebrow {
    margin: 0 0 var(--space-xs);
    color: var(--granada-ink);
}

.granada-event-slider__title {
    margin: 0 0 var(--space-sm);
    font-size: clamp(2.5rem, 5.5vw, 4.25rem);
    line-height: 1.02;
    color: var(--granada-ink);
    text-wrap: balance;
}

.granada-event-slider__subtitle {
    margin: 0 0 4px;
    font-size: var(--font-size-md);
    font-weight: 700;
    line-height: 1.3;
    color: var(--granada-ink);
}

.granada-event-slider__date {
    margin: 0;
    font-size: var(--font-size-sm);
    line-height: 1.4;
    color: var(--granada-ink);
}

.granada-event-slider__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-md);
}

/*
 * The buttons sit on a photograph, so they keep their own color rather
 * than picking up any link color inherited from the section.
 */
.granada-event-slider__actions .btn {
    margin: 0;
}

/* Arrows
   --------------------------------------------------------------------------
   44px minimum so they clear the WCAG 2.5.8 target size on touch.
   ========================================================================== */

.granada-event-slider__arrow {
    box-sizing: border-box;
    position: absolute;
    top: calc(50% - var(--granada-nav-space) / 2);
    z-index: 2;
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background-color: var(--granada-chip);
    border: 1px solid rgba(var(--granada-ink-rgb), .6);
    color: var(--granada-ink);
    cursor: pointer;
    transform: translateY(-50%);
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast);
}

.granada-event-slider.is-enhanced .granada-event-slider__arrow {
    display: flex;
}

.granada-event-slider__arrow:hover,
.granada-event-slider__arrow:focus-visible {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.granada-event-slider__arrow:focus-visible {
    outline: 2px solid var(--granada-ink);
    outline-offset: 2px;
}

.granada-event-slider__arrow--prev {
    left: var(--space-sm);
}

.granada-event-slider__arrow--next {
    right: var(--space-sm);
}

.granada-event-slider__arrow-icon {
    display: block;
    width: 10px;
    height: 10px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
}

.granada-event-slider__arrow--prev .granada-event-slider__arrow-icon {
    margin-left: 3px;
    transform: rotate(-135deg);
}

.granada-event-slider__arrow--next .granada-event-slider__arrow-icon {
    margin-right: 3px;
    transform: rotate(45deg);
}

/* Bottom navigation
   ========================================================================== */

.granada-event-slider__nav {
    position: absolute;
    right: 0;
    bottom: var(--space-lg);
    left: 0;
    z-index: 2;
}

.granada-event-slider__nav-container {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.granada-event-slider__nav-list {
    display: flex;
    flex: 1 1 auto;
    gap: var(--space-md);
    list-style: none;
    margin: 0;
    padding: 0;
}

.granada-event-slider__nav-item {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
}

.granada-event-slider__nav-button {
    box-sizing: border-box;
    display: block;
    width: 100%;
    padding: 0 0 var(--space-xs);
    background: none;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.granada-event-slider__nav-button:focus-visible {
    outline: 2px solid var(--granada-ink);
    outline-offset: 4px;
}

/* Progress line
   ========================================================================== */

.granada-event-slider__nav-line {
    position: relative;
    display: block;
    width: 100%;
    height: 2px;
    margin-bottom: var(--space-xs);
    background-color: rgba(var(--granada-ink-rgb), .35);
    overflow: hidden;
}

.granada-event-slider__nav-fill {
    position: absolute;
    inset: 0;
    display: block;
    background-color: var(--granada-ink);
    transform: scaleX(0);
    transform-origin: left center;
}

/*
 * The fill drives the slideshow: view.js advances on its animationend,
 * so pausing the animation pauses the slideshow too and the two can
 * never drift apart.
 */
.granada-event-slider__nav-button.is-active .granada-event-slider__nav-fill {
    animation: granada-slider-progress var(--granada-slide-duration, 4s) linear forwards;
}

.granada-event-slider.is-paused .granada-event-slider__nav-button.is-active .granada-event-slider__nav-fill {
    animation-play-state: paused;
}

/*
 * Autoplay off, or the visitor has taken control: the current line just
 * reads as full.
 */
.granada-event-slider.is-stopped .granada-event-slider__nav-button.is-active .granada-event-slider__nav-fill {
    animation: none;
    transform: scaleX(1);
}

@keyframes granada-slider-progress {

    from {
        transform: scaleX(0);
    }

    to {
        transform: scaleX(1);
    }

}

/* Navigation labels
   ========================================================================== */

.granada-event-slider__nav-text {
    display: block;
    color: rgba(var(--granada-ink-rgb), .7);
    transition: color var(--transition-fast);
}

.granada-event-slider__nav-button.is-active .granada-event-slider__nav-text,
.granada-event-slider__nav-button:hover .granada-event-slider__nav-text,
.granada-event-slider__nav-button:focus-visible .granada-event-slider__nav-text {
    color: var(--granada-ink);
}

.granada-event-slider__nav-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    font-size: .9375rem;
    font-weight: 700;
    line-height: 1.3;
}

.granada-event-slider__nav-subtitle {
    display: block;
    margin-top: 2px;
    font-size: .8125rem;
    line-height: 1.3;
}

/* Pause and play
   ========================================================================== */

.granada-event-slider__playpause {
    box-sizing: border-box;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-top: -12px;
    padding: 0;
    background: none;
    border: 1px solid rgba(var(--granada-ink-rgb), .5);
    color: var(--granada-ink);
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast);
}

.granada-event-slider__playpause:hover,
.granada-event-slider__playpause:focus-visible {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.granada-event-slider__playpause:focus-visible {
    outline: 2px solid var(--granada-ink);
    outline-offset: 2px;
}

/* Two bars: the pause symbol. */
.granada-event-slider__playpause-icon {
    display: block;
    width: 10px;
    height: 12px;
    border-left: 3px solid currentColor;
    border-right: 3px solid currentColor;
}

/* A triangle: the play symbol. */
.granada-event-slider.is-stopped .granada-event-slider__playpause-icon,
.granada-event-slider.is-paused .granada-event-slider__playpause-icon {
    width: 0;
    height: 0;
    margin-left: 3px;
    border-top: 6px solid transparent;
    border-right: 0;
    border-bottom: 6px solid transparent;
    border-left: 10px solid currentColor;
}

/* Single slide
   ========================================================================== */

.granada-event-slider--single {
    --granada-nav-space: var(--space-2xl);
}

/* Lines-only navigation
   ========================================================================== */

.granada-event-slider--nav-lines {
    --granada-nav-space: 90px;
}

/* Editor
   ========================================================================== */

.granada-event-slider-placeholder {
    padding: var(--space-lg);
    background-color: var(--color-cream, #f5f0eb);
    border: 1px dashed var(--color-line, #e5e0d8);
    text-align: center;
}

.granada-event-slider-placeholder p {
    margin: 0;
}

.granada-event-slider__editor-note {
    display: inline-block;
    margin: 0 0 var(--space-xs);
    padding: 4px 10px;
    background-color: var(--color-primary);
    font-family: var(--font-condensed);
    font-size: .75rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--granada-ink);
}

/* Tablet and below
   ========================================================================== */

@media (max-width: 1024px) {

    .granada-event-slider__nav-list {
        gap: var(--space-sm);
    }

    .granada-event-slider__nav-subtitle {
        display: none;
    }

}

@media (max-width: 767px) {

    .granada-event-slider {
        --granada-slider-height: clamp(480px, 110vw, 620px);
        --granada-nav-space: 110px;
    }

    .granada-event-slider--height-tall {
        --granada-slider-height: clamp(540px, 125vw, 700px);
    }

    .granada-event-slider__inner {
        padding-top: var(--space-xl);
    }

    .granada-event-slider__title {
        font-size: clamp(2rem, 9vw, 2.75rem);
    }

    /*
     * The lines stay as the position indicator; the titles are dropped
     * because four of them will not read at this width. Each button keeps
     * its aria-label, so the slide it goes to is still announced.
     */
    .granada-event-slider__nav-text {
        display: none;
    }

    /*
     * The line itself is 2px, so the button is padded out to a 44px
     * target (WCAG 2.5.8). The extra height is empty space below the
     * line, which is why the navigation does not look any taller.
     */
    .granada-event-slider__nav-button {
        padding-bottom: 42px;
    }

    .granada-event-slider__nav-line {
        margin-bottom: 0;
    }

    .granada-event-slider__playpause {
        margin-top: -21px;
    }

    /*
     * The arrows are dropped at this width: sitting halfway up they land
     * on top of the title, and there is nowhere else for them to go.
     * Swiping works, and the lines along the bottom are both a position
     * indicator and a way to jump between slides.
     */
    .granada-event-slider__arrow {
        display: none;
    }

    .granada-event-slider.is-enhanced .granada-event-slider__arrow {
        display: none;
    }

}

/* Reduced motion
   --------------------------------------------------------------------------
   No auto-advance at all: the progress animation is what drives it, so
   switching the animation off stops the slideshow moving on its own.
   ========================================================================== */

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

    .granada-event-slider .granada-event-slider__slide.is-active {
        animation: none;
    }

    .granada-event-slider .granada-event-slider__nav-button.is-active .granada-event-slider__nav-fill {
        animation: none;
        transform: scaleX(1);
    }

    .granada-event-slider__arrow,
    .granada-event-slider__playpause,
    .granada-event-slider__nav-text {
        transition: none;
    }

}
