/**
 * Mirai Theme - Image Lightbox Styles
 * 高性能、响应式图片灯箱样式
 */

/* ========== 灯箱容器 ========== */
.mirai-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.mirai-lightbox.active {
    opacity: 1;
}

/* 防止背景滚动 */
body.lightbox-open {
    overflow: hidden;
    touch-action: none;
}

/* ========== 背景遮罩 ========== */
.lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: opacity 0.3s ease;
}

/* ========== 主容器 ========== */
.lightbox-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ========== 工具栏 ========== */
.lightbox-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), transparent);
    transition: opacity 0.3s ease, transform 0.3s ease;
    will-change: opacity, transform; /* 优化：GPU 加速 */
}

.lightbox-counter {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    letter-spacing: 0.05em;
}

.lightbox-actions {
    display: flex;
    gap: 0.5rem;
}

/* ========== 按钮样式 ========== */
.lightbox-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.lightbox-btn:active {
    transform: scale(0.95);
}

.lightbox-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.lightbox-btn i {
    font-size: 1.25rem;
    line-height: 1;
}

/* 计数器按钮特殊样式 */
.lightbox-counter {
    width: auto;
    padding: 0 1rem;
    border-radius: 20px;
    font-variant-numeric: tabular-nums;
}

/* ========== 舞台区域 ========== */
.lightbox-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    touch-action: none; /* 优化：禁用默认触摸行为，提升性能 */
}

/* ========== 视口 ========== */
.lightbox-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ========== 图片包装器 ========== */
.lightbox-image-wrapper {
    position: relative;
    max-width: 90%;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

.lightbox-image {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transition: opacity 0.3s ease;
    user-select: none;
    -webkit-user-drag: none;
}

/* ========== 加载动画 ========== */
.lightbox-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 1;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #fff;
    border-radius: 50%;
    animation: lightbox-spin 0.8s linear infinite;
}

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

/* ========== 导航按钮 ========== */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 5;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.lightbox-nav:hover {
    background: rgba(0, 0, 0, 0.5);
}

.lightbox-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.lightbox-nav i {
    font-size: 2rem;
}

.lightbox-prev {
    left: 0;
    border-radius: 0 8px 8px 0;
}

.lightbox-next {
    right: 0;
    border-radius: 8px 0 0 8px;
}

/* ========== 缩略图 ========== */
.lightbox-thumbnails {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 1rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.lightbox-thumbnails::-webkit-scrollbar {
    display: none;
}

.lightbox-thumb {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.lightbox-thumb:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.lightbox-thumb.active {
    border-color: var(--gt-main-color, #3253b4);
    opacity: 1;
}

.lightbox-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========== 标题 ========== */
.lightbox-caption {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80%;
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.875rem;
    text-align: center;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    line-height: 1.5;
    transition: opacity 0.3s ease;
    z-index: 5;
    will-change: opacity; /* 优化：GPU 加速 */
}

/* ========== 文章内图片光标样式 ========== */
.article-content img:not(.avatar):not(.gt-avatar):not(.no-lightbox),
.gt-lightbox-img,
.gt-lightbox-figure img {
    cursor: zoom-in;
    transition: opacity 0.2s ease;
}

.article-content img:not(.avatar):not(.gt-avatar):not(.no-lightbox):hover,
.gt-lightbox-img:hover,
.gt-lightbox-figure:hover img {
    opacity: 0.9;
}

/* 灯箱 figure 包装样式 */
.gt-lightbox-figure {
    margin: 1rem 0;
    text-align: center;
}

.gt-lightbox-figure picture,
.gt-lightbox-figure img {
    display: inline-block;
    max-width: 100%;
    height: auto; /* 优化：保持图片原始宽高比，防止变形 */
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
    .lightbox-toolbar {
        padding: 0.75rem 1rem;
    }

    .lightbox-btn {
        width: 36px;
        height: 36px;
    }

    .lightbox-btn i {
        font-size: 1.125rem;
    }

    .lightbox-nav {
        width: 40px;
        height: 60px;
    }

    .lightbox-nav i {
        font-size: 1.5rem;
    }

    .lightbox-image-wrapper {
        max-width: 95%;
        max-height: 80vh;
    }

    .lightbox-image {
        max-height: 80vh;
    }

    .lightbox-thumbnails {
        padding: 0.75rem;
        gap: 6px;
    }

    .lightbox-thumb {
        width: 50px;
        height: 50px;
    }

    .lightbox-caption {
        bottom: 80px;
        font-size: 0.8125rem;
        padding: 0.5rem 1rem;
        max-width: 90%;
    }

    /* 移动端隐藏缩放按钮 */
    .lightbox-zoom-in,
    .lightbox-zoom-out {
        display: none;
    }
}

@media (max-width: 480px) {
    .lightbox-toolbar {
        padding: 0.5rem 0.75rem;
    }

    .lightbox-counter {
        font-size: 0.8125rem;
        padding: 0 0.75rem;
    }

    .lightbox-nav {
        width: 36px;
        height: 50px;
    }

    .lightbox-thumb {
        width: 44px;
        height: 44px;
    }
}

/* ========== 动画效果 ========== */
@keyframes lightbox-scale-in {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.mirai-lightbox.active .lightbox-image-wrapper {
    animation: lightbox-scale-in 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ========== 深色模式适配 ========== */
[data-theme="dark"] .lightbox-backdrop {
    background: rgba(0, 0, 0, 0.95);
}

/* ========== 无障碍支持 ========== */
@media (prefers-reduced-motion: reduce) {
    .mirai-lightbox,
    .mirai-lightbox *,
    .lightbox-image-wrapper {
        transition: none !important;
        animation: none !important;
    }
}

/* 焦点样式 */
.lightbox-btn:focus-visible,
.lightbox-nav:focus-visible,
.lightbox-thumb:focus-visible {
    outline: 2px solid var(--gt-main-color, #3253b4);
    outline-offset: 2px;
}

/* 打印样式 */
@media print {
    .mirai-lightbox {
        display: none !important;
    }
}



/* ========== 性能优化 ========== */
.lightbox-image-wrapper {
    contain: layout style;
    touch-action: none; /* 禁用默认触摸行为，由 JS 处理 */
}

.lightbox-thumbnails {
    contain: layout;
}

/* GPU 加速 */
.mirai-lightbox,
.lightbox-image-wrapper,
.lightbox-nav,
.lightbox-btn {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 防止图片被选中 */
.lightbox-image {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
