/*
 * Fullscreen event album viewer — mobile-first (iOS safe areas, swipe, playback).
 * Paired with static/js/events/album_viewer.js and templates/events/gallery.html.
 */

.album-viewer {
    --av-ink: #f4f7f6;
    --av-jade: #2ea08f;
    --av-chrome: rgba(10, 20, 19, 0.62);
    --av-chrome-strong: rgba(8, 17, 16, 0.86);
    --av-edge: rgba(255, 255, 255, 0.16);
    --av-safe-top: env(safe-area-inset-top, 0px);
    --av-safe-bottom: env(safe-area-inset-bottom, 0px);
    /* Landscape notches eat horizontal space instead of vertical. */
    --av-safe-left: env(safe-area-inset-left, 0px);
    --av-safe-right: env(safe-area-inset-right, 0px);
    position: fixed;
    inset: 0;
    z-index: 2147483646;
    display: flex;
    flex-direction: column;
    color: var(--av-ink);
    isolation: isolate;
    overscroll-behavior: contain;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

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

/*
 * Small-screen global CSS sets `.grid { position: relative !important }`, which creates
 * stacking contexts that can paint thumbnails over a fixed overlay — so hide the page
 * while the viewer owns the screen.
 */
html.album-viewer-open main {
    visibility: hidden !important;
    pointer-events: none !important;
}

html.album-viewer-open {
    overflow: hidden;
}

.album-viewer__backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 18% 12%, rgba(46, 160, 143, 0.28), transparent 32rem),
        radial-gradient(circle at 82% 88%, rgba(196, 151, 73, 0.18), transparent 30rem),
        #070f0e;
    opacity: 0;
    transition: opacity 260ms ease;
}

.album-viewer.is-open .album-viewer__backdrop {
    opacity: 1;
}

/* ---------- Slide stage ---------- */

.album-viewer__stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
}

.album-viewer__track {
    display: flex;
    height: 100%;
    will-change: transform;
}

.album-viewer__slide {
    position: relative;
    display: flex;
    flex: 0 0 100%;
    align-items: center;
    justify-content: center;
    padding:
        calc(4.9rem + var(--av-safe-top))
        calc(0.75rem + var(--av-safe-right))
        calc(8.5rem + var(--av-safe-bottom))
        calc(0.75rem + var(--av-safe-left));
}

.album-viewer__frame {
    position: relative;
    display: flex;
    max-width: 100%;
    max-height: 100%;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
}

.album-viewer__frame img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 0.9rem;
    object-fit: contain;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.55);
}

/* Blur-up: thumbnail holds the layout until the full-size file decodes. */
.album-viewer__frame .album-viewer__thumb {
    filter: blur(14px) saturate(120%);
    transform: scale(1.02);
}

.album-viewer__frame .album-viewer__full {
    position: absolute;
    inset: 0;
    margin: auto;
    opacity: 0;
    transition: opacity 240ms ease;
}

.album-viewer__frame.is-loaded .album-viewer__full {
    opacity: 1;
}

.album-viewer__spinner {
    position: absolute;
    width: 2.2rem;
    height: 2.2rem;
    border: 2px solid rgba(255, 255, 255, 0.22);
    border-top-color: var(--av-jade);
    border-radius: 50%;
    animation: album-viewer-spin 720ms linear infinite;
}

.album-viewer__frame.is-loaded .album-viewer__spinner {
    display: none;
}

@keyframes album-viewer-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Chrome (top bar / controls / filmstrip) ---------- */

.album-viewer__chrome {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 3;
    transition: opacity 220ms ease, transform 220ms ease;
}

.album-viewer.is-idle .album-viewer__chrome {
    opacity: 0;
    pointer-events: none;
}

.album-viewer.is-idle .album-viewer__top {
    transform: translateY(-0.5rem);
}

.album-viewer.is-idle .album-viewer__bottom {
    transform: translateY(0.75rem);
}

.album-viewer__top {
    top: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding:
        calc(0.7rem + var(--av-safe-top))
        calc(0.85rem + var(--av-safe-right))
        1.6rem
        calc(0.85rem + var(--av-safe-left));
    background: linear-gradient(180deg, rgba(4, 12, 11, 0.82) 0%, rgba(4, 12, 11, 0) 100%);
}

.album-viewer__meta {
    min-width: 0;
    flex: 1 1 auto;
}

.album-viewer__counter {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: rgba(244, 247, 246, 0.72);
}

.album-viewer__counter i {
    font-style: normal;
    opacity: 0.5;
}

.album-viewer__title {
    margin: 0.15rem 0 0;
    overflow: hidden;
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.album-viewer__actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 0 0 auto;
}

.album-viewer__views {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.32rem 0.6rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: #0f172a;
    /* !important beats the global `span { color: var(--text-secondary) !important }` in custom.css. */
    color: #f8fafc !important;
    font-size: 0.72rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.album-viewer__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.6rem;
    height: 2.6rem;
    border: 1px solid var(--av-edge);
    border-radius: 999px;
    background: var(--av-chrome);
    color: var(--av-ink);
    backdrop-filter: blur(10px);
    transition: background 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.album-viewer__icon:hover {
    background: rgba(23, 107, 98, 0.55);
    border-color: rgba(46, 160, 143, 0.6);
}

.album-viewer__icon:active {
    transform: scale(0.94);
}

.album-viewer__icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.album-viewer__progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0.9rem;
    height: 2px;
    background: rgba(255, 255, 255, 0.14);
}

.album-viewer__progress span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--av-jade), #c49749);
    transition: width 120ms linear;
}

.album-viewer:not(.is-playing) .album-viewer__progress {
    opacity: 0;
}

.album-viewer__bottom {
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding:
        1.7rem
        calc(0.6rem + var(--av-safe-right))
        calc(0.7rem + var(--av-safe-bottom))
        calc(0.6rem + var(--av-safe-left));
    background: linear-gradient(0deg, rgba(4, 12, 11, 0.88) 0%, rgba(4, 12, 11, 0) 100%);
}

.album-viewer__controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
}

.album-viewer__play {
    width: 3.5rem;
    height: 3.5rem;
    border-color: rgba(46, 160, 143, 0.55);
    background: linear-gradient(145deg, rgba(23, 107, 98, 0.92), rgba(13, 79, 73, 0.92));
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.album-viewer__play svg {
    width: 1.5rem;
    height: 1.5rem;
}

.album-viewer__play [data-av-icon="pause"],
.album-viewer.is-playing .album-viewer__play [data-av-icon="play"] {
    display: none;
}

.album-viewer.is-playing .album-viewer__play [data-av-icon="pause"] {
    display: block;
}

/* Filmstrip */

.album-viewer__filmstrip {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    padding: 0.15rem 0.3rem 0.35rem;
    scroll-behavior: smooth;
    scrollbar-width: none;
}

.album-viewer__filmstrip::-webkit-scrollbar {
    display: none;
}

.album-viewer__thumb-btn {
    position: relative;
    flex: 0 0 auto;
    width: 3.1rem;
    height: 3.1rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 0.6rem;
    opacity: 0.55;
    transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.album-viewer__thumb-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.album-viewer__thumb-btn.is-current {
    opacity: 1;
    border-color: var(--av-jade);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

/* Desktop side arrows */

.album-viewer__arrow {
    position: absolute;
    top: 50%;
    z-index: 3;
    display: none;
    transform: translateY(-50%);
    width: 3.2rem;
    height: 3.2rem;
}

.album-viewer__arrow--prev { left: calc(1.1rem + var(--av-safe-left)); }
.album-viewer__arrow--next { right: calc(1.1rem + var(--av-safe-right)); }

.album-viewer__hint {
    position: absolute;
    left: 50%;
    bottom: calc(9.5rem + var(--av-safe-bottom));
    z-index: 3;
    transform: translateX(-50%);
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--av-edge);
    border-radius: 999px;
    background: var(--av-chrome-strong);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 300ms ease;
}

.album-viewer.is-hinting .album-viewer__hint {
    opacity: 1;
}

@media (min-width: 768px) {
    .album-viewer__arrow {
        display: inline-flex;
    }
}

/*
 * Roomy viewports only: a landscape phone is wide but short, so the generous
 * vertical chrome below would leave almost no room for the photo.
 */
@media (min-width: 768px) and (min-height: 620px) {
    .album-viewer__slide {
        padding:
            5.6rem
            calc(5.5rem + var(--av-safe-right))
            8.5rem
            calc(5.5rem + var(--av-safe-left));
    }

    .album-viewer__title {
        font-size: 1.1rem;
    }

    .album-viewer__thumb-btn {
        width: 3.8rem;
        height: 3.8rem;
    }
}

/* ---------- Short viewports (landscape phones) ---------- */

@media (max-height: 620px) and (orientation: landscape) {
    .album-viewer__slide {
        padding:
            calc(3rem + var(--av-safe-top))
            calc(3.9rem + var(--av-safe-right))
            calc(3.5rem + var(--av-safe-bottom))
            calc(3.9rem + var(--av-safe-left));
    }

    .album-viewer__frame img {
        border-radius: 0.6rem;
    }

    .album-viewer__top {
        align-items: center;
        gap: 0.5rem;
        padding:
            calc(0.45rem + var(--av-safe-top))
            calc(0.7rem + var(--av-safe-right))
            1rem
            calc(0.7rem + var(--av-safe-left));
    }

    .album-viewer__title {
        font-size: 0.86rem;
    }

    .album-viewer__counter {
        font-size: 0.7rem;
    }

    .album-viewer__progress {
        bottom: 0.45rem;
    }

    /* One compact row: playback controls beside a slim filmstrip. */
    .album-viewer__bottom {
        flex-direction: row;
        align-items: center;
        gap: 0.6rem;
        padding:
            1rem
            calc(0.6rem + var(--av-safe-right))
            calc(0.4rem + var(--av-safe-bottom))
            calc(0.6rem + var(--av-safe-left));
    }

    .album-viewer__controls {
        flex: 0 0 auto;
        gap: 0.5rem;
    }

    .album-viewer__filmstrip {
        flex: 1 1 auto;
        min-width: 0;
        padding: 0.1rem 0.2rem 0.2rem;
    }

    .album-viewer__icon {
        width: 2.2rem;
        height: 2.2rem;
    }

    .album-viewer__icon svg {
        width: 1.05rem;
        height: 1.05rem;
    }

    .album-viewer__play {
        width: 2.6rem;
        height: 2.6rem;
    }

    .album-viewer__play svg {
        width: 1.15rem;
        height: 1.15rem;
    }

    .album-viewer__thumb-btn {
        width: 2.1rem;
        height: 2.1rem;
        border-radius: 0.4rem;
    }

    .album-viewer__arrow {
        width: 2.6rem;
        height: 2.6rem;
    }

    .album-viewer__hint {
        bottom: calc(4.2rem + var(--av-safe-bottom));
        font-size: 0.66rem;
    }
}

/* Very short (e.g. small phone in landscape): drop the filmstrip, keep controls. */
@media (max-height: 420px) and (orientation: landscape) {
    .album-viewer__slide {
        padding:
            calc(2.6rem + var(--av-safe-top))
            calc(3.6rem + var(--av-safe-right))
            calc(3rem + var(--av-safe-bottom))
            calc(3.6rem + var(--av-safe-left));
    }

    .album-viewer__filmstrip {
        display: none;
    }

    .album-viewer__controls {
        flex: 1 1 auto;
    }

    .album-viewer__hint {
        display: none;
    }
}

/* ---------- Album grid tiles ---------- */

.album-tile {
    position: relative;
    display: block;
    width: 100%;
    overflow: hidden;
    border-radius: 1rem;
    background: rgba(23, 63, 59, 0.06);
    box-shadow: 0 10px 26px rgba(23, 63, 59, 0.1);
    transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 260ms ease;
}

.album-tile::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
    pointer-events: none;
}

.album-tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.album-tile:active {
    transform: scale(0.985);
}

@media (hover: hover) {
    .album-tile:hover {
        transform: translateY(-4px);
        box-shadow: 0 20px 40px rgba(23, 63, 59, 0.18);
    }

    .album-tile:hover img {
        transform: scale(1.06);
    }
}

.album-tile:focus-visible {
    outline: 3px solid rgba(46, 160, 143, 0.55);
    outline-offset: 3px;
}

.album-tile__badge,
.album-tile__views,
.album-tile__seq {
    position: absolute;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
}

.album-tile__badge {
    top: 0.45rem;
    left: 0.45rem;
    background: linear-gradient(135deg, #c49749, #a97c2f);
    color: #fffdf6;
    box-shadow: 0 4px 12px rgba(120, 82, 20, 0.35);
}

.album-tile__views {
    top: 0.45rem;
    right: 0.45rem;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: #0f172a;
    /* !important beats the global `span { color: var(--text-secondary) !important }` in custom.css. */
    color: #f8fafc !important;
    /* Light text on a dark chip reads heavier than it measures. */
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.35);
}

.album-tile__views span {
    color: inherit !important;
}

/* Bottom-left: clear of 精选 (top-left) and views (top-right). */
.album-tile__seq {
    left: 0.45rem;
    bottom: 0.45rem;
    min-width: 1.35rem;
    justify-content: center;
    padding: 0.18rem 0.42rem;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(15, 23, 42, 0.72);
    color: #f8fafc !important;
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.28);
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.album-tile:has(.album-tile__caption) .album-tile__seq {
    /* Sit above the caption gradient so the number stays readable. */
    bottom: 2.35rem;
}

.album-tile__caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 1.4rem 0.6rem 0.55rem;
    background: linear-gradient(0deg, rgba(6, 26, 24, 0.9) 0%, rgba(6, 26, 24, 0) 100%);
    color: #fff;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
}

.album-tile__caption span {
    display: block;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

@media (prefers-reduced-motion: reduce) {
    .album-viewer *,
    .album-tile,
    .album-tile img {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
