/* =====================================================
   Moments Gallery — 朋友圈九宫格相册
   ===================================================== */

/* 外层容器 */
.mg-gallery {
    display: grid;
    gap: 4px;
    max-width: 540px;          /* 与朋友圈宽度近似 */
    width: 100%;
    margin: 12px 0;
    box-sizing: border-box;
}

/* ---- 根据图片数量动态设置列数 ---- */

/* 1 张：单图居左，最大 420px 宽 */
.mg-gallery.mg-count-1 {
    grid-template-columns: 1fr;
    max-width: 280px;
}

/* 2 张：两列 */
.mg-gallery.mg-count-2 {
    grid-template-columns: repeat(2, 1fr);
    max-width: 280px;
}

/* 3 张：三列一行 */
.mg-gallery.mg-count-3 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* 4 张：2×2 */
.mg-gallery.mg-count-4 {
    grid-template-columns: repeat(2, 1fr);
    max-width: 280px;
}

/* 5 张：先排 3，后排 2（左对齐补齐） */
.mg-gallery.mg-count-5 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* 6 张：2行×3列 */
.mg-gallery.mg-count-6 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* 7 张：先 3 后 2 后 2 */
.mg-gallery.mg-count-7 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* 8 张：先 3 后 3 后 2 */
.mg-gallery.mg-count-8 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* 9 张：标准九宫格 3×3 */
.mg-gallery.mg-count-9 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* 超过9张同样用3列 */
.mg-gallery.mg-count-many {
    grid-template-columns: repeat(3, 1fr);
    max-width: 420px;
}

/* ---- 单图片格子 ---- */
.mg-item {
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
    cursor: zoom-in;
    border-radius: 4px;
    /* 正方形：padding-top hack */
    padding-top: 100%;
}

.mg-item img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: transform 0.25s ease;
}

.mg-item:hover img {
    transform: scale(1.06);
}

/* 1 张大图不使用正方形 */
.mg-gallery.mg-count-1 .mg-item {
    padding-top: 0;
}
.mg-gallery.mg-count-1 .mg-item img {
    position: static;
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: cover;
}

/* =====================================================
   灯箱 Lightbox
   ===================================================== */
.mg-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,.85);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    animation: mg-fade-in .2s ease;
}
.mg-lightbox.mg-open {
    display: flex;
}
@keyframes mg-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.mg-lightbox-img-wrap {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mg-lightbox-img-wrap img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
    display: block;
}

/* 导航箭头 */
.mg-lightbox-prev,
.mg-lightbox-next {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    font-size: 28px;
    width: 48px;
    height: 64px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
    user-select: none;
    z-index: 100001;
}
.mg-lightbox-prev { left: 12px; }
.mg-lightbox-next { right: 12px; }
.mg-lightbox-prev:hover,
.mg-lightbox-next:hover {
    background: rgba(255,255,255,.3);
}

/* 关闭按钮 */
.mg-lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    z-index: 100001;
    opacity: .8;
    transition: opacity .2s;
}
.mg-lightbox-close:hover { opacity: 1; }

/* 计数器 */
.mg-lightbox-counter {
    margin-top: 12px;
    color: rgba(255,255,255,.7);
    font-size: 14px;
    letter-spacing: 1px;
}

/* =====================================================
   响应式
   ===================================================== */
@media (max-width: 480px) {
    .mg-gallery {
        gap: 3px;
    }
    .mg-lightbox-prev { left: 4px; }
    .mg-lightbox-next { right: 4px; }
}
