/* Image viewer (assets/js/lightbox.js): click a picture to see it large in the middle of
   the screen over a blurred page. Arrows step through the page's pictures; the X at the
   top right, a click anywhere outside the picture, or Esc goes back. */

:root {
    --lightbox-fade: 0.25s;   /* the page blurring in and out */
    --lightbox-in: 0.22s;     /* a picture growing in (when opened, and after an arrow) */
    --lightbox-out: 0.12s;    /* a picture fading out when an arrow is clicked */
    --lightbox-arrow-size: 3.25rem;
}

.lightbox-trigger {
    cursor: zoom-in;
}

/* Each picture sits in a frame (lightbox.js) with a slight grey and a magnifying glass
   button over it. They're always there, see-through until the picture is pointed at.
   The frame is exactly the picture's box: the picture's space below it carries on
   outside the frame, as if the frame weren't there. */
.lightbox-frame {
    display: block;
    position: relative;
}
.lightbox-hint {
    --lightbox-hint-tint: rgba(var(--distinct-primary-accent-color), 0.25);
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: var(--image-border-radius);
    background: var(--lightbox-hint-tint);
    pointer-events: none; /* clicks go through to the picture */
    opacity: 0;
    transition: opacity 0.2s ease;
}
@media (hover: hover) {
    .lightbox-frame:hover .lightbox-hint {
        opacity: 1;
    }
}
.lightbox-trigger:focus-visible + .lightbox-hint,
a:focus-visible .lightbox-hint {
    opacity: 1;
}
.lightbox-hint-button {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.92);
    color: var(--primary-accent-color);
    box-shadow: 0 2px 14px rgba(var(--distinct-primary-accent-color), 0.3);
    transform: scale(0.85);
    transition: transform 0.2s ease;
}
.lightbox-frame:hover .lightbox-hint-button,
.lightbox-trigger:focus-visible + .lightbox-hint .lightbox-hint-button,
a:focus-visible .lightbox-hint-button {
    transform: scale(1);
}
.lightbox-hint-button svg {
    width: 1.6rem;
    height: 1.6rem;
    fill: currentColor;
}

/* A picture on the page that couldn't load (lightbox.js marks it when the browser gives up
   on it): it isn't drawn, because each browser draws a failed picture differently (and a
   lazy one can come out a screen tall). Its alt text sits in a small, quiet box instead.
   A picture that is still loading is left alone, so the page doesn't move when it arrives. */
body img.img-broken {
    display: none;
}
.img-broken-note {
    display: block;
    padding: 0.5rem 0.75rem;
    border: 1px dashed rgba(var(--distinct-primary-accent-color), 0.4);
    border-radius: 0.5rem;
    background: rgba(var(--distinct-primary-accent-color), 0.05);
    color: var(--text-color, var(--primary-accent-color));
    font-family: var(--font-family);
    font-size: 0.875rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

html.lightbox-open {
    overflow: hidden; /* the page's scrollbar space stays reserved (main.css: scrollbar-gutter), so nothing shifts */
}

/* The viewer covers the whole screen; the page behind it is blurred */
dialog.lightbox {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 4dvh 7rem;
    border: 0;
    inset: 0;
    overflow: auto; /* only used on a tiny screen: lightbox.js sizes the picture to fit */
    overscroll-behavior: contain;

    background: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
    backdrop-filter: blur(16px) saturate(1.1);
    color: var(--primary-accent-color);
    font-family: var(--font-family);
    cursor: zoom-out;
    touch-action: pan-y pinch-zoom; /* sideways swipes go to the viewer */

    opacity: 0;
    transition: opacity var(--lightbox-fade) ease;
}
dialog.lightbox[open] {
    display: flex;
    align-items: center;
    align-items: safe center; /* a tall picture and caption start at the top, never off it */
    justify-content: center;
}
dialog.lightbox.is-visible {
    opacity: 1;
}
/* The viewer itself holds the focus when it opens (lightbox.js): a place for the keyboard
   to start from, not something to draw a ring round */
dialog.lightbox:focus {
    outline: none;
}
dialog.lightbox::backdrop {
    background: transparent;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    dialog.lightbox {
        background: rgba(255, 255, 255, 0.95);
    }
}

/* The picture and its caption: they grow in slightly as they fade in. When an arrow is
   clicked they fade out quickly, then the next picture grows in the same way. */
.lightbox .lightbox-figure {
    width: auto;
    max-width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2dvh;
    transition: opacity var(--lightbox-in) ease-out, transform var(--lightbox-in) ease-out;
}
.lightbox .lightbox-figure.is-hidden {
    opacity: 0;
    transform: scale(0.97);
    transition-duration: var(--lightbox-out);
    transition-timing-function: ease-in;
}

/* lightbox.js sets the picture's width and height, so its box is full size even before it loads */
.lightbox img.lightbox-image {
    display: block;
    max-width: 100%;
    max-height: 80dvh;
    margin: 0;
    object-fit: contain;
    border-radius: var(--image-border-radius);
    box-shadow: var(--shadow-soft);
    cursor: default;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* A picture that hasn't loaded yet, in the viewer: a light box at the picture's size,
   with its alt text set in from the edges */
.lightbox img.lightbox-image.is-pending {
    padding: 1.5rem;
    background-color: rgba(var(--distinct-primary-accent-color), 0.08);
    color: var(--primary-accent-color);
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.4;
}

/* While the full picture loads: the page's own copy stretched to the same size, with no
   alt text box over it (lightbox.js) */
.lightbox img.lightbox-image.has-preview {
    padding: 0;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    color: transparent;
}

/* Caption under the picture, in the same style as the captions on the page. A long one
   wraps (even a very long word) and, past a quarter of the screen's height, scrolls
   inside its own box; lightbox.js leaves the picture whatever room is left. */
.lightbox-caption {
    max-width: min(40rem, 100%);
    max-height: 25dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    overflow-wrap: anywhere;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text-color, var(--primary-accent-color)); /* 4.9:1 on white (the accent grey is 4.1:1) */
}
.lightbox-caption:empty {
    display: none;
}

/* The round buttons: previous / next at the sides of the screen, close at the top right */
.lightbox-button {
    position: absolute;
    width: var(--lightbox-arrow-size);
    height: var(--lightbox-arrow-size);
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;

    background: rgba(255, 255, 255, 0);
    color: var(--primary-accent-color);
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
.lightbox-button[hidden] {
    display: none;
}
.lightbox-arrow {
    top: 50%;
    margin-top: calc(var(--lightbox-arrow-size) / -2);
}
.lightbox-prev { left: 2rem; }
.lightbox-next { right: 2rem; }
.lightbox-close {
    top: 1.5rem;
    right: 2rem;
}

.lightbox-button:hover {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 14px rgba(var(--distinct-primary-accent-color), 0.3);
}
.lightbox-button:focus-visible {
    outline: 2px solid var(--primary-accent-color);
    outline-offset: 3px;
}
.lightbox-button svg {
    width: 1.6rem;
    height: 1.6rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Phones: the picture uses the full width; the arrows sit over its edges (or swipe). The
   top of the screen is left clear for the close button, so it never covers the picture. */
@media (max-width: 768px) {
    dialog.lightbox {
        padding: max(3dvh, 3.75rem) 0.75rem 3dvh;
    }
    .lightbox img.lightbox-image {
        max-height: 75dvh;
    }
    .lightbox-caption {
        font-size: 0.85rem;
        padding-inline: 1rem;
    }
    .lightbox-button {
        --lightbox-arrow-size: 2.75rem;
        background: rgba(255, 255, 255, 0.85);
        box-shadow: 0 2px 10px rgba(var(--distinct-primary-accent-color), 0.25);
    }
    .lightbox-prev { left: 0.75rem; }
    .lightbox-next { right: 0.75rem; }
    .lightbox-close {
        top: 0.75rem;
        right: 0.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    dialog.lightbox,
    .lightbox .lightbox-figure,
    .lightbox-button,
    .lightbox-hint,
    .lightbox-hint-button {
        transition: none;
    }
    .lightbox .lightbox-figure.is-hidden {
        transform: none;
    }
}
