/* Photo viewer (static/js/viewer.js), loaded through the layout.head hook.
   See src/innosoft_app/viewer.py. Always dark, whatever the page's skin:
   photos read best on black. */

.pv {
    --pv-fade: 1;
    --pv-accent: var(--brand-accent, #eaa903);
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    /* A long activity name must not widen the viewer past the screen. */
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
    background: rgb(5 7 11 / var(--pv-fade));
    color: #fff;
    overscroll-behavior: contain;
    outline: none;
    animation: pv-in .2s ease-out;
    -webkit-touch-callout: none;
}

/* The current photo, blurred, behind everything: a coloured glow instead
   of a flat black wall. */
.pv__backdrop {
    position: absolute;
    inset: -10%;
    background: center / cover no-repeat;
    filter: blur(48px) saturate(1.3);
    opacity: calc(.32 * var(--pv-fade));
    pointer-events: none;
}

/* Bars */
.pv__top,
.pv__bottom {
    position: relative;
    z-index: 2;
    transition: opacity .25s ease;
}

.pv__top {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: calc(max(.375rem, env(safe-area-inset-top)) + .75rem) max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left));
    background: linear-gradient(rgb(0 0 0 / .55), transparent);
}

/* Stories mode: the activity's name, and under it the edition and the
   count (viewer.js, updateMeta). */
.pv__meta {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: .1rem;
    min-width: 0;
    margin-right: auto;
    padding-left: .25rem;
}

.pv__group {
    display: none;
    overflow: hidden;
    font-size: .95rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.pv--stories .pv__group:not(:empty) { display: block; }

.pv__counter {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: .9rem;
    font-variant-numeric: tabular-nums;
    color: rgb(255 255 255 / .85);
}

.pv__tools {
    display: flex;
    flex: none;
    gap: .25rem;
}

.pv__bottom {
    display: grid;
    justify-items: center;
    gap: .5rem;
    min-width: 0;
    padding: .5rem max(.75rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
    background: linear-gradient(transparent, rgb(0 0 0 / .6));
}

.pv__caption {
    max-width: 70ch;
    margin: 0;
    text-align: center;
    font-size: .95rem;
    line-height: 1.45;
    color: rgb(255 255 255 / .9);
}

/* Buttons */
.pv__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgb(255 255 255 / .08);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}
.pv__btn svg { width: 1.3rem; height: 1.3rem; }
.pv__btn:hover { background: rgb(255 255 255 / .2); color: #fff; }
.pv__btn:focus-visible,
.pv__thumb:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
.pv__btn:disabled { opacity: .35; cursor: default; background: rgb(255 255 255 / .08); }
.pv__play[aria-pressed="true"] { background: rgb(255 255 255 / .25); }

.pv__nav {
    position: absolute;
    top: 50%;
    z-index: 3;
    width: 3.25rem;
    height: 3.25rem;
    margin-top: -1.625rem;
    background: rgb(0 0 0 / .4);
    transition: opacity .25s ease, background .15s ease;
}
.pv__nav--prev { left: max(.75rem, env(safe-area-inset-left)); }
.pv__nav--next { right: max(.75rem, env(safe-area-inset-right)); }

/* The photo */
.pv__stage {
    position: relative;
    z-index: 1;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: zoom-out;
}

.pv__img {
    position: absolute;
    inset: .25rem 4.75rem;
    width: calc(100% - 9.5rem);
    height: calc(100% - .5rem);
    object-fit: contain;
    transform-origin: center;
    -webkit-user-drag: none;
    transition: opacity .2s ease;
}
.pv__img:not([src]) { visibility: hidden; }
.pv--loading .pv__img { opacity: .4; }

.pv__spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2.5rem;
    height: 2.5rem;
    margin: -1.25rem 0 0 -1.25rem;
    border: 3px solid rgb(255 255 255 / .25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: pv-spin .8s linear infinite;
}
.pv__spinner[hidden] { display: none; }

/* Thumbnails */
.pv__thumbs {
    position: relative;
    display: flex;
    gap: .375rem;
    max-width: 100%;
    padding: .25rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.pv__thumbs::-webkit-scrollbar { display: none; }
.pv__thumbs:empty { display: none; }

.pv__thumb {
    flex: none;
    width: 3.5rem;
    height: 3.5rem;
    padding: 0;
    border: 0;
    border-radius: .375rem;
    overflow: hidden;
    background: rgb(255 255 255 / .08);
    opacity: .5;
    cursor: pointer;
    transition: opacity .15s ease;
}
.pv__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.pv__thumb:hover { opacity: .85; }
.pv__thumb[aria-current="true"] {
    opacity: 1;
    box-shadow: 0 0 0 2px var(--pv-accent);
}

/* Slideshow progress along the top edge: one segment per photo, the
   ones seen full, the current one filling over its time. */
.pv__progress {
    position: absolute;
    top: max(.375rem, env(safe-area-inset-top));
    left: max(.75rem, env(safe-area-inset-left));
    right: max(.75rem, env(safe-area-inset-right));
    z-index: 4;
    display: flex;
    gap: 2px; /* SEGMENT_GAP in viewer.js */
    height: 3px;
    pointer-events: none;
    transition: opacity .2s ease;
}
.pv__seg {
    flex: 1;
    min-width: 0;
    border-radius: 2px;
    overflow: hidden;
    background: rgb(255 255 255 / .3);
}
.pv__seg i {
    display: block;
    height: 100%;
    background: #fff;
    transform: scaleX(0);
    transform-origin: left;
}
.pv__seg.is-done i { transform: none; }

/* Screen-reader-only live region */
.pv__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* States */
.pv--single .pv__nav,
.pv--single .pv__play,
.pv--single .pv__counter { display: none; }

/* Mouse still for a while: just the photo and the progress. */
.pv--bare { cursor: none; }
.pv--bare .pv__top,
.pv--bare .pv__bottom,
.pv--bare .pv__nav,
/* Pressed and held: the photo alone. */
.pv--held .pv__top,
.pv--held .pv__bottom,
.pv--held .pv__nav,
.pv--held .pv__progress,
.pv--zoomed .pv__bottom,
.pv--zoomed .pv__nav {
    opacity: 0;
    pointer-events: none;
}
.pv--bare .pv__stage { cursor: none; }

/* Thumbnails are for browsing: out of the way while it plays. Hidden, not
   removed, so the photo does not resize when it pauses. */
.pv--playing .pv__thumbs {
    visibility: hidden;
}

@media (max-width: 640px) {
    .pv__img { inset: 0; width: 100%; height: 100%; }
    .pv__nav { width: 2.5rem; height: 2.5rem; margin-top: -1.25rem; }
    .pv__nav--prev { left: .25rem; }
    .pv__nav--next { right: .25rem; }
    .pv__thumb { width: 2.75rem; height: 2.75rem; }
    /* Pinch and double tap zoom; the buttons only take room. */
    .pv__zoom-in,
    .pv__zoom-out { display: none; }
}

@keyframes pv-in { from { opacity: 0; } }
@keyframes pv-spin { to { transform: rotate(360deg); } }
@keyframes pv-progress { to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
    .pv { animation: none; }
}
