/* From Gutenberg to AGI (August 2026) - archival figure system + lightbox
   Depends on:
   - /writing/writing-design.css

   Every image here is a public domain archival object (a printed page, a
   woodcut, an engraving, a photograph). None of them is cropped to fit a
   layout: figures are balanced by capping display height, so the object is
   always shown whole.
*/

.gagi-page {
    --gagi-vellum: #d9c9a3;
    --gagi-frame: rgba(217, 201, 163, 0.22);
    --gagi-frame-strong: rgba(217, 201, 163, 0.40);
}

/* --- figure shell ------------------------------------------------------- */

.gagi-figure {
    margin: 2.75rem auto;
    text-align: center;
}

.gagi-figure:first-child {
    margin-top: 0;
}

/* The zoom trigger is a real button so the lightbox is keyboard reachable. */
.gagi-frame {
    display: inline-block;
    max-width: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    background: none;
    font: inherit;
    color: inherit;
    cursor: zoom-in;
    line-height: 0;
    border-radius: 12px;
}

.gagi-frame:focus-visible {
    outline: 2px solid var(--writing-accent-2);
    outline-offset: 4px;
}

.gagi-frame img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--gagi-frame);
    background: rgba(0, 0, 0, 0.22);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
    transition: transform 0.22s ease, border-color 0.22s ease;
}

.gagi-frame:hover img,
.gagi-frame:focus-visible img {
    transform: translateY(-2px);
    border-color: var(--gagi-frame-strong);
}

/* --- captions ----------------------------------------------------------- */

.gagi-caption {
    max-width: 54ch;
    margin: 0.95rem auto 0;
    font-family: 'DM Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
    text-align: left;
}

.gagi-caption-text {
    display: block;
    font-size: 0.95rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.74);
}

.gagi-credit {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.82rem;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.56);
}

.gagi-credit a {
    color: rgba(147, 197, 253, 0.92);
    text-decoration: none;
    border-bottom: 1px solid rgba(147, 197, 253, 0.32);
    white-space: nowrap;
}

.gagi-credit a:hover,
.gagi-credit a:focus-visible {
    color: #ffffff;
    border-bottom-color: rgba(147, 197, 253, 0.85);
}

/* --- size variants ------------------------------------------------------ */

/* Hero: the whole Gutenberg leaf, capped so the first paragraph stays close
   to the top of a phone screen. */
.gagi-hero .gagi-frame img {
    width: auto;
    max-width: 100%;
    max-height: min(64vh, 620px);
}

/* A single plate sitting inside its section. */
.gagi-single .gagi-frame img {
    width: auto;
    max-width: 100%;
    max-height: min(58vh, 540px);
}

/* Full-width landscape photograph. */
.gagi-wide .gagi-frame {
    width: 100%;
}

/* --- paired figures ----------------------------------------------------- */

.gagi-pair {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.75rem;
    margin: 2.75rem auto;
}

.gagi-pair .gagi-figure {
    margin: 0;
}

.gagi-pair .gagi-caption {
    max-width: none;
}

@media (min-width: 760px) {
    .gagi-pair {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
        align-items: start;
    }

    /* Side by side, the two plates are matched on height rather than cropped
       to a shared aspect ratio. */
    .gagi-pair .gagi-frame img {
        width: auto;
        max-width: 100%;
        max-height: 420px;
    }
}

/* --- lightbox ----------------------------------------------------------- */

.gagi-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.25rem;
    background: rgba(0, 6, 16, 0.94);
    cursor: zoom-out;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.gagi-lightbox.is-open {
    display: flex;
    opacity: 1;
}

/* The stage scrolls once the image is zoomed past the viewport. The centring
   is done with margin:auto rather than align-items, because a centred flex
   item that overflows cannot be scrolled back to its start edge. */
.gagi-lightbox-stage {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    display: flex;
    overflow: auto;
    overscroll-behavior: contain;
}

.gagi-lightbox-zoom {
    margin: auto;
    padding: 0;
    border: 0;
    background: none;
    line-height: 0;
    cursor: zoom-in;
}

.gagi-lightbox.is-zoomed .gagi-lightbox-zoom {
    cursor: zoom-out;
}

.gagi-lightbox-zoom:focus-visible {
    outline: 2px solid var(--writing-accent-2);
    outline-offset: 4px;
}

.gagi-lightbox-img {
    display: block;
    max-width: calc(100vw - 2.5rem);
    max-height: calc(100vh - 9rem);
    width: auto;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.7);
}

/* Actual pixels: on a phone this is the difference between seeing a page of
   type and being able to read it. */
.gagi-lightbox.is-zoomed .gagi-lightbox-img {
    max-width: none;
    max-height: none;
    border-radius: 0;
}

.gagi-lightbox-hint {
    margin: 0;
    font-family: 'DM Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.42);
}

.gagi-lightbox-caption {
    max-width: 70ch;
    margin: 0;
    font-family: 'DM Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: 0.85rem;
    line-height: 1.55;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
}

.gagi-lightbox-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    line-height: 1;
    color: #ffffff;
    /* Dark fill, not a translucent white one: when the image is zoomed this
       button sits directly on pale vellum. */
    background: rgba(0, 6, 16, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.30);
    border-radius: 50%;
    cursor: pointer;
}

.gagi-lightbox-close:hover,
.gagi-lightbox-close:focus-visible {
    background: rgba(0, 6, 16, 0.94);
    border-color: rgba(255, 255, 255, 0.6);
}

body.gagi-lightbox-open {
    overflow: hidden;
}

/* --- touch + motion ----------------------------------------------------- */

@media (pointer: coarse) {
    /* Caption source links are small targets; give them a real one. */
    .gagi-credit a {
        display: inline-block;
        min-width: 44px;
        min-height: 44px;
        padding: 0 4px;
        line-height: 44px;
        text-align: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gagi-frame img,
    .gagi-lightbox {
        transition: none;
    }

    .gagi-frame:hover img,
    .gagi-frame:focus-visible img {
        transform: none;
    }
}
