/* ==========================================================================
   Modal

   One shared dialog. The markup is built by assets/js/modal.js the first
   time something opens it, so there is nothing here for a visitor without
   JavaScript.
   ========================================================================== */

.ssc-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
}

/*
 * Written with the class attached so it always outranks the base rule,
 * whatever order the stylesheets end up in.
 */
.ssc-modal[hidden] {
    display: none;
}

.ssc-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .7);
    opacity: 0;
    transition: opacity var(--transition-fast, .2s ease);
}

.ssc-modal.is-open .ssc-modal__backdrop {
    opacity: 1;
}

.ssc-modal__panel {
    position: relative;
    box-sizing: border-box;
    width: min(100%, 680px);
    max-height: 85vh;
    overflow-y: auto;
    padding: var(--space-xl);
    background: var(--color-light);
    opacity: 0;
    transform: translateY(12px);
    transition:
        opacity var(--transition-fast, .2s ease),
        transform var(--transition-fast, .2s ease);
}

.ssc-modal.is-open .ssc-modal__panel {
    opacity: 1;
    transform: translateY(0);
}

.ssc-modal__panel:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -4px;
}

.ssc-modal__close {
    position: absolute;
    top: var(--space-xs);
    right: var(--space-xs);
    z-index: 1;
    box-sizing: border-box;

    /* 44px, so it clears the WCAG 2.5.8 target size on touch. */
    width: 44px;
    height: 44px;

    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: 0;
    font-size: 1.75rem;
    line-height: 1;
    color: var(--color-text);
    cursor: pointer;
}

.ssc-modal__close:hover,
.ssc-modal__close:focus-visible {
    color: var(--color-primary);
}

.ssc-modal__title {
    margin: 0 0 var(--space-sm);

    /* Clear of the close button. */
    padding-right: var(--space-xl);
}

.ssc-modal__title[hidden] {
    display: none;
}

.ssc-modal__body > :first-child {
    margin-top: 0;
}

.ssc-modal__body > :last-child {
    margin-bottom: 0;
}

/* Stops the page scrolling behind the dialog. */
body.ssc-modal-open {
    overflow: hidden;
}


/* Video
   --------------------------------------------------------------------------
   Wider, unpadded and dark, so the player fills the panel and the frame
   does not show a white edge while it loads.
   ========================================================================== */

.ssc-modal--video .ssc-modal__panel {
    width: min(100%, 1100px);
    max-height: none;
    overflow: visible;
    padding: 0;
    background: var(--color-dark, #000);
}

/*
 * Outside the panel, so it does not sit on top of the video, and light
 * because it is now against the page backdrop.
 */
.ssc-modal--video .ssc-modal__close {
    top: -48px;
    right: 0;
    color: var(--color-light);
}

.ssc-modal--video .ssc-modal__close:hover,
.ssc-modal--video .ssc-modal__close:focus-visible {
    color: var(--color-light);
    opacity: .7;
}

.ssc-video {
    position: relative;
    aspect-ratio: 16 / 9;
    width: 100%;
    background: #000;
}

.ssc-video__frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/*
 * On a short window the close button would sit off the top of the screen,
 * so it comes back inside.
 */
@media (max-height: 520px) {

    .ssc-modal--video .ssc-modal__close {
        top: var(--space-xs);
        right: var(--space-xs);
    }

}

/* Image
   --------------------------------------------------------------------------
   Sized by the picture rather than by the panel, so an enlarged image is
   not a small photograph adrift in a white box. The panel shrink-wraps
   whatever it is given and the picture is capped against the viewport, so
   a tall one does not run off the bottom of the screen.

   The caption stays on a dark bar under the image rather than over it:
   over a photograph there is no telling what it would land on.
   ========================================================================== */

.ssc-modal--image .ssc-modal__panel {
    width: auto;
    max-width: min(100%, 1400px);
    max-height: none;
    padding: 0;
    background: var(--color-dark, #000);
    color: var(--color-light, #fff);
}

.ssc-modal--image .ssc-modal__body img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100vh - 10rem);
    margin-inline: auto;
}

.ssc-modal--image .ssc-modal__title {
    padding: var(--space-sm) var(--space-md);
    font-size: 1rem;
    color: var(--color-light, #fff);
}

/*
 * Outside the panel, like the video variant, so it is not sitting on the
 * picture — and light, because it is now against the backdrop.
 */
.ssc-modal--image .ssc-modal__close {
    top: -48px;
    right: 0;
    color: var(--color-light, #fff);
}

.ssc-modal--image .ssc-modal__close:hover,
.ssc-modal--image .ssc-modal__close:focus-visible {
    color: var(--color-light, #fff);
    opacity: .7;
}


@media (max-width: 768px) {

    .ssc-modal__panel {
        padding: var(--space-lg) var(--space-md);
        max-height: 90vh;
    }

    .ssc-modal--video .ssc-modal__panel,
    .ssc-modal--image .ssc-modal__panel {
        padding: 0;
    }

}

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

    .ssc-modal__backdrop,
    .ssc-modal__panel {
        transition: none;
    }

}
