/* =============================================================
   Image zoom for the continuous view (js/image-zoom.js)
   — the frame and badge of a zoomable image, the full-screen
     viewer and the loupe.

   The script wraps an image that is shown smaller than its own
   pixels in span.image-zoom-frame; the frame takes over the
   image's alignment from continuous-view.css.
   ============================================================= */

/* ---- Frame of an image: the image margins and alignments of continuous-view.css ----
   The frame is as wide as the image, at most the column, as the image's max-width: 100% is: fit-content would also
   take a float's side margin off the column and shrink the image. */
.image-zoom-frame {
    position: relative;
    display: block;
    width: max-content;
    max-width: 100%;
    margin: 0.5rem 0;
    line-height: 0;
}

.image-zoom-frame.image-zoom-block {
    margin: 0 0 16px;
}

.image-zoom-frame.image-zoom-center {
    margin: 0 auto 16px;
}

.image-zoom-frame.image-zoom-left {
    float: left;
    margin: 0 16px 16px 0;
}

.image-zoom-frame.image-zoom-right {
    float: right;
    margin: 0 0 16px 16px;
}

/* Outranks the image rules of continuous-view.css whichever stylesheet loads first. */
span.image-zoom-frame > img.image-zoom-image {
    display: block;
    float: none;
    margin: 0;
}

span.image-zoom-frame > img.image-zoom-target {
    cursor: zoom-in;
}

span.image-zoom-frame > img.image-zoom-target:focus-visible {
    outline: 3px solid #1a56db;
    outline-offset: 3px;
}

/* A magnifier on the corner of a zoomable image: always on a touch screen, on hover or focus with a mouse. */
.image-zoom-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(17, 24, 39, 0.72) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cline x1='15.4' y1='15.4' x2='20.5' y2='20.5'/%3E%3Cline x1='10.5' y1='7.8' x2='10.5' y2='13.2'/%3E%3Cline x1='7.8' y1='10.5' x2='13.2' y2='10.5'/%3E%3C/svg%3E") center / 20px no-repeat;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.image-zoom-frame:not(.image-zoom-active) .image-zoom-badge {
    display: none;
}

@media (hover: none), (pointer: coarse) {
    .image-zoom-badge {
        opacity: 1;
    }
}

.image-zoom-frame:hover .image-zoom-badge,
.image-zoom-target:focus-visible + .image-zoom-badge {
    opacity: 1;
}

/* ---- Viewer ---- */
html.image-zoom-locked,
html.image-zoom-locked body {
    overflow: hidden;
}

.image-zoom-viewer {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: grid;
    grid-template-rows: 1fr auto auto;
    background: rgba(12, 15, 21, calc(0.97 * var(--image-zoom-fade, 1)));
    color: #f3f4f6;
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.image-zoom-viewer[hidden] {
    display: none;
}

.image-zoom-stage {
    position: relative;
    overflow: hidden;
    touch-action: none;
}

.image-zoom-picture {
    position: absolute;
    left: 0;
    top: 0;
    max-width: none;
    transform-origin: 0 0;
    background: #fff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.image-zoom-viewer.image-zoom-zoomed .image-zoom-picture {
    cursor: grab;
}

.image-zoom-viewer.image-zoom-zoomed .image-zoom-stage:active .image-zoom-picture {
    cursor: grabbing;
}

.image-zoom-viewer.image-zoom-animate .image-zoom-picture {
    transition: transform 0.2s ease-out;
}

.image-zoom-caption {
    margin: 0;
    padding: 6px 16px 0;
    text-align: center;
    color: #d1d5db;
}

.image-zoom-caption[hidden] {
    display: none;
}

.image-zoom-toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
}

.image-zoom-button {
    min-width: 48px;
    height: 48px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font: 600 20px/1 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    cursor: pointer;
}

.image-zoom-button.image-zoom-fit {
    font-size: 15px;
}

.image-zoom-button:hover {
    background: rgba(255, 255, 255, 0.22);
}

.image-zoom-button:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

.image-zoom-button[aria-disabled="true"] {
    opacity: 0.4;
    cursor: default;
}

.image-zoom-close {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: 10px;
    font-size: 26px;
}

.image-zoom-level {
    min-width: 64px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: #e5e7eb;
}

/* ---- Loupe: the ring is a shadow, so the centre of the box stays under the pointer ---- */
.image-zoom-lens {
    position: fixed;
    z-index: 2147482000;
    display: none;
    border-radius: 50%;
    background-color: #fff;
    background-repeat: no-repeat;
    box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(17, 24, 39, 0.25), 0 10px 28px rgba(17, 24, 39, 0.35);
    pointer-events: none;
}

.image-zoom-lens.image-zoom-lens-on {
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    .image-zoom-badge,
    .image-zoom-viewer.image-zoom-animate .image-zoom-picture {
        transition: none;
    }
}

@media print {
    .image-zoom-badge,
    .image-zoom-lens,
    .image-zoom-viewer {
        display: none !important;
    }
}
