/* 宿也 · 房源相册
   - 手机：独立相册页全屏浏览，只通过返回键退出（避免触控误触空白关闭）
   - PC（≥1024）：详情页内以弹窗打开；直接访问相册页时同样呈现为遮罩上的面板，点击遮罩关闭
   - 主图保持原比例（contain），缩略图任何宽度都是单行横向滚动 */

body[data-page="gallery"] {
    min-height: 100svh;
    padding-bottom: 0;
    background: var(--night);
    color: var(--paper);
}

body[data-page="gallery"] :focus-visible,
.gallery-dialog :focus-visible {
    outline-color: var(--paper);
}

/* ---------- 面板外壳 ---------- */
.gallery-shell,
.gallery-dialog-panel {
    display: flex;
    flex-direction: column;
    background: var(--night);
    color: var(--paper);
}

.gallery-shell {
    min-height: 100svh;
}

.gallery-shell:focus {
    outline: none;
}

/* ---------- 顶部栏 ---------- */
.gallery-header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 8px var(--page-pad);
    background: rgba(31, 42, 38, .94);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.gallery-back,
.gallery-close {
    display: grid;
    flex: 0 0 44px;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--paper);
    transition: background var(--motion-fast);
}

.gallery-back:hover,
.gallery-close:hover {
    background: rgba(255, 255, 255, .1);
}

.gallery-back-icon,
.gallery-close .icon {
    width: 22px;
    height: 22px;
}

.gallery-heading {
    flex: 1 1 auto;
    min-width: 0;
}

.gallery-heading h1,
.gallery-heading h2 {
    font-size: 17px;
    line-height: 1.3;
}

.gallery-caption {
    overflow: hidden;
    font-size: 12px;
    color: var(--night-text);
    white-space: nowrap;
    text-overflow: ellipsis;
}

.gallery-count {
    flex: 0 0 auto;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    color: var(--night-text);
}

/* ---------- 内容 ---------- */
.gallery-content {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: var(--space-4);
    min-height: 0;
    padding: var(--space-3) 0 calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
}

.gallery-categories {
    padding: 0 var(--page-pad);
}

.gallery-categories .chip {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 var(--space-3);
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: var(--radius-pill);
    font-size: 13px;
    color: var(--paper);
}

.gallery-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.gallery-stage:focus-visible {
    outline: 2px solid var(--paper);
    outline-offset: -4px;
}

.gallery-main-frame {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0;
}

.gallery-main {
    display: block;
    width: 100%;
    height: min(62svh, 720px);
    object-fit: contain;
    background: #18211E;
    -webkit-user-drag: none;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-top: -24px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 50%;
    background: rgba(31, 42, 38, .72);
    color: var(--paper);
    transition: background var(--motion-fast);
}

.gallery-nav:hover {
    background: rgba(31, 42, 38, .92);
}

.gallery-nav .icon {
    width: 24px;
    height: 24px;
}

.gallery-prev {
    left: var(--page-pad);
}

.gallery-next {
    right: var(--page-pad);
}

.gallery-main-frame figcaption {
    position: absolute;
    left: var(--page-pad);
    bottom: var(--space-3);
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: rgba(31, 42, 38, .78);
    color: var(--paper);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.gallery-bottom {
    padding: 0 var(--page-pad);
}

.gallery-bottom > p {
    margin-bottom: var(--space-3);
    font-size: 14px;
}

.gallery-bottom > p span {
    font-size: 12px;
    color: var(--night-text);
}

/* 缩略图：所有宽度都是单行横向滚动 */
.gallery-thumbs {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--space-2);
    margin-inline: calc(var(--page-pad) * -1);
    padding: 4px var(--page-pad) 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}

.gallery-thumbs::-webkit-scrollbar {
    display: none;
}

.gallery-thumbs > button {
    flex: 0 0 88px;
    aspect-ratio: 4 / 3;
    padding: 0;
    overflow: hidden;
    border: 2px solid transparent;
    border-radius: var(--radius-m);
    background: #18211E;
    transition: border-color var(--motion-fast);
}

.gallery-thumbs img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: .6;
    transition: opacity var(--motion-fast);
}

.gallery-thumbs > button:hover img {
    opacity: .85;
}

.gallery-thumbs > button.active {
    border-color: var(--paper);
}

.gallery-thumbs > button.active img {
    opacity: 1;
}

.gallery-empty {
    display: grid;
    justify-items: center;
    gap: var(--space-4);
    min-height: 45svh;
    padding: var(--space-8) var(--page-pad);
    align-content: center;
    color: var(--night-text);
    text-align: center;
}

.gallery-empty .button-secondary {
    border-color: var(--paper);
    color: var(--paper);
}

.gallery-empty .button-secondary:hover {
    background: var(--paper);
    color: var(--ink);
}

/* ---------- 详情页内的相册弹窗（只在 ≥1024 打开） ---------- */
.gallery-dialog {
    width: min(1200px, calc(100vw - 96px));
    max-width: none;
    height: min(880px, calc(100svh - 64px));
    max-height: none;
    margin: auto;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-l);
    background: var(--night);
    color: var(--paper);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
}

.gallery-dialog::backdrop {
    background: rgba(14, 20, 18, .78);
}

.gallery-dialog-panel {
    height: 100%;
}

html:has(.gallery-dialog[open]) {
    overflow: hidden;
}

/* ---------- PC：面板布局（弹窗与直接访问的相册页共用） ---------- */
@media (min-width: 1024px) {
    /* 直接访问相册页时，页面本身就是遮罩，面板居中 */
    body[data-page="gallery"] {
        display: grid;
        place-items: center;
        min-height: 100svh;
        padding: 32px 48px;
        background: rgba(14, 20, 18, .96);
        cursor: zoom-out;
    }

    body[data-page="gallery"] .gallery-shell {
        width: min(1200px, 100%);
        height: min(880px, calc(100svh - 64px));
        min-height: 0;
        overflow: hidden;
        border-radius: var(--radius-l);
        box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
        cursor: auto;
    }

    .gallery-header {
        position: static;
        padding: 12px var(--space-5);
    }

    .gallery-heading h1,
    .gallery-heading h2 {
        font-size: 19px;
    }

    .gallery-content {
        padding-bottom: var(--space-4);
    }

    .gallery-stage {
        flex: 1 1 auto;
        min-height: 0;
    }

    .gallery-main-frame {
        height: 100%;
    }

    .gallery-main {
        height: 100%;
    }

    .gallery-prev {
        left: var(--space-5);
    }

    .gallery-next {
        right: var(--space-5);
    }

    .gallery-main-frame figcaption {
        left: var(--space-5);
    }

    .gallery-categories,
    .gallery-bottom {
        padding-inline: var(--space-5);
    }

    .gallery-thumbs {
        margin-inline: calc(var(--space-5) * -1);
        padding-inline: var(--space-5);
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, .28) transparent;
    }

    .gallery-thumbs::-webkit-scrollbar {
        display: block;
        height: 6px;
    }

    .gallery-thumbs::-webkit-scrollbar-thumb {
        border-radius: 3px;
        background: rgba(255, 255, 255, .28);
    }

    .gallery-thumbs > button {
        flex-basis: 108px;
    }
}
