/*
 * 文件: gallery.css
 * 描述: 图片画廊样式表
 * 作者: Kaylon
 * 最后更新: 2025-05-01
 * 功能: 定义图片画廊布局、灯箱效果和交互动画
 */

/* ===== 图集页面特有变量 ===== */
:root {
    /* 图集页面配色 */
    --gallery-primary: #1976d2;
    --gallery-primary-light: #64b5f6;
    --gallery-primary-dark: #0d47a1;
    --gallery-accent: #ffd97b;
    --gallery-accent-dark: #f4be49;
    --gallery-text: #0a4b82;
    --gallery-light-text: #f7fbff;
    --gallery-border: #e0e0e0;
    --gallery-bg: #f7fbff;
    --gallery-card-bg: rgba(255, 255, 255, 0.8);

    /* 尺寸和间距 */
    --gallery-radius: 12px;
    --gallery-panel-radius: 8px;
    --gallery-btn-radius: 6px;
    --gallery-padding: 20px;
    --gallery-gap: 40px;
    --gallery-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    --gallery-shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.16);

    /* 动画时间 */
    --gallery-transition: 0.3s ease;
    --gallery-animation: 0.4s ease;
}

/* ===== 图集页面基础样式 ===== */
.gallery-page {
    background: linear-gradient(135deg, #e3f2fd 0%, #ffffff 100%);
    color: var(--gallery-text);
}

/* ===== 主容器 ===== */
.gallery-container {
    max-width: 1200px;
    margin: 100px auto 60px;
    padding: var(--gallery-padding);
    position: relative;
}

/* ===== 页面标题区域 ===== */
.page-header {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
}

.gallery-title {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--gallery-primary);
    position: relative;
    display: inline-block;
}

.gallery-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 3px;
    background: var(--gallery-accent);
    border-radius: 3px;
}

.gallery-subtitle {
    font-size: 1.1rem;
    color: var(--gallery-text);
    margin-bottom: 10px;
}

.gallery-update-time {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* ===== 图集控制面板 ===== */
.gallery-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

/* 筛选控制 */
.filter-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--gallery-border);
    color: var(--gallery-text);
    border-radius: var(--gallery-btn-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--gallery-transition);
}

.filter-btn:hover, .filter-btn.active {
    background: var(--gallery-primary);
    color: white;
    border-color: var(--gallery-primary);
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
}

/* 视图控制 */
.view-controls {
    display: flex;
    gap: 8px;
}

.view-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--gallery-btn-radius);
    border: 1px solid var(--gallery-border);
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--gallery-transition);
}

.view-btn svg {
    fill: var(--gallery-text);
    transition: fill var(--gallery-transition);
}

.view-btn:hover, .view-btn.active {
    background: var(--gallery-primary);
    border-color: var(--gallery-primary);
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
}

.view-btn:hover svg, .view-btn.active svg {
    fill: white;
}

/* ===== 加载指示器 ===== */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 50px 0;
    width: 100%;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(25, 118, 210, 0.2);
    border-top-color: var(--gallery-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--gallery-text);
}

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

/* ===== 图片网格布局 ===== */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--gallery-gap);
    margin-bottom: 40px;
}

/* 瀑布流布局 */
.gallery-grid.masonry {
    display: block;
    column-count: 3;
    column-gap: var(--gallery-gap);
}

.gallery-grid.masonry .gallery-item {
    break-inside: avoid;
    margin-bottom: var(--gallery-gap);
}

/* ===== 图片项样式 ===== */
.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--gallery-radius);
    box-shadow: var(--gallery-shadow);
    background: white;
    transition: all var(--gallery-transition);
    cursor: pointer;
    opacity: 1; /* 默认可见 */
    transform: translateY(0); /* 默认不位移 */
    animation: fadeInUp 0.5s forwards;
    height: 100%;
}

.gallery-item:hover {
    transform: translateY(-8px);
    box-shadow: var(--gallery-shadow-hover);
}

/* 图片容器 */
.image-container {
    position: relative;
    overflow: hidden;
    aspect-ratio: 4/3;
    background: #f0f0f0; /* 浅色背景 */
}

.gallery-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--gallery-radius) var(--gallery-radius) 0 0;
    transition: transform var(--gallery-transition);
    transform-origin: center;
    position: relative;
    z-index: 1;
    opacity: 1; /* 默认显示图片 */
}

.gallery-item:hover .gallery-img {
    transform: scale(1.05);
}

/* 图片框架 */
.image-frame {
    padding: 5px;
    background: white;
    border: 2px solid var(--gallery-border);
    border-radius: var(--gallery-radius);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    z-index: 1;
}

/* 图片信息 */
.image-info {
    padding: 15px;
    background: white; /* 纯白背景 */
    border-radius: 0 0 var(--gallery-radius) var(--gallery-radius);
    border-top: 1px solid #eee;
}

.image-title {
    font-size: 1rem;
    margin: 0 0 5px;
    color: #333; /* 深色文字 */
    font-weight: 600;
}

.image-category {
    font-size: 0.8rem;
    color: white;
    background: var(--gallery-primary); /* 使用主色调 */
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    margin-bottom: 5px;
}

.image-actions {
    margin-top: 10px;
    display: flex;
    gap: 10px;
}

.image-action {
    background: none;
    border: none;
    font-size: 0.9rem;
    color: var(--gallery-text);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color var(--gallery-transition);
}

.image-action:hover {
    color: var(--gallery-primary);
}

/* 图片叠加层 */
.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3); /* 降低不透明度 */
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--gallery-transition);
    z-index: 2;
}

.gallery-item:hover .image-overlay {
    opacity: 1;
}

.overlay-icon {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0.8);
    transition: transform var(--gallery-transition);
}

.gallery-item:hover .overlay-icon {
    transform: scale(1);
}

/* 加载更多区域 */
.load-more-container {
    text-align: center;
    padding: 30px 0;
    opacity: 0;
    transition: opacity var(--gallery-transition);
}

.load-more-container.visible {
    opacity: 1;
}

.load-more-indicator {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--gallery-text);
    font-size: 0.9rem;
}

.load-more-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(25, 118, 210, 0.2);
    border-top-color: var(--gallery-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ===== 灯箱样式 ===== */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity var(--gallery-animation);
}

.lightbox.active {
    display: flex;
    opacity: 1;
}

.lightbox-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--gallery-transition);
    z-index: 1005;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.4);
}

.lightbox-close svg {
    fill: white;
}

.lightbox-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.lightbox-image-container {
    position: relative;
    max-width: 90%;
    max-height: 80vh;
    margin: 0 auto;
}

.lightbox-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity var(--gallery-animation);
    animation: zoomIn var(--gallery-animation);
}

.lightbox-img.loaded {
    opacity: 1;
}

/* 导航按钮 */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--gallery-transition);
    z-index: 1001;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-nav svg {
    fill: white;
}

.lightbox-nav.prev {
    left: 20px;
}

.lightbox-nav.next {
    right: 20px;
}

/* 灯箱底部信息 */
.lightbox-details {
    padding: 15px;
    text-align: center;
    color: white;
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    z-index: 1002;
}

.lightbox-counter {
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.lightbox-caption {
    font-size: 1rem;
    margin-bottom: 10px;
}

.lightbox-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.lightbox-action {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background var(--gallery-transition);
}

.lightbox-action:hover {
    background: rgba(255, 255, 255, 0.4);
}

.lightbox-action svg {
    fill: white;
}

/* 图片加载指示器 */
.image-loading-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    opacity: 1;
    transition: opacity var(--gallery-transition);
}

.image-loading-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ===== 图片懒加载骨架效果 ===== */
.skeleton {
    animation-duration: 1.5s;
    animation-fill-mode: forwards;
    animation-iteration-count: infinite;
    animation-name: shimmer;
    animation-timing-function: linear;
    background: linear-gradient(to right, #f6f7f8 0%, #edeef1 20%, #f6f7f8 40%, #f6f7f8 100%);
    background-size: 800px 104px;
    position: relative;
    display: none; /* 默认隐藏骨架效果 */
}

.skeleton-image {
    width: 100%;
    height: 100%;
    border-radius: var(--gallery-radius) var(--gallery-radius) 0 0;
}

/* ===== 图片加载错误状态 ===== */
.image-error {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8); /* 更明显的背景 */
    color: #e74c3c;
    font-size: 0.9rem;
    text-align: center;
    padding: 20px;
}

.error-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.retry-button {
    background: var(--gallery-primary);
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    margin-top: 10px;
    cursor: pointer;
    transition: background var(--gallery-transition);
}

.retry-button:hover {
    background: var(--gallery-primary-dark);
}

/* ===== 无图片状态 ===== */
.no-images {
    text-align: center;
    padding: 50px 20px;
    background: white;
    border-radius: var(--gallery-radius);
    margin: 40px 0;
    box-shadow: var(--gallery-shadow);
    border: 1px solid #eee;
}

.no-images-icon {
    font-size: 3rem;
    color: #ccc;
    margin-bottom: 20px;
}

.no-images-text {
    font-size: 1.2rem;
    color: var(--gallery-text);
    margin-bottom: 15px;
}

.no-images-subtext {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== 动画定义 ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes zoomIn {
    0% {
        transform: scale(0.8);
        opacity: 0.3;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shimmer {
    0% {
        background-position: -468px 0;
    }
    100% {
        background-position: 468px 0;
    }
}

/* ===== 响应式布局 ===== */
@media (max-width: 1024px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 30px;
    }

    .gallery-grid.masonry {
        column-count: 2;
    }

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

    .lightbox-nav.prev {
        left: 10px;
    }

    .lightbox-nav.next {
        right: 10px;
    }
}

@media (max-width: 768px) {
    .gallery-container {
        margin-top: 80px;
        padding: 15px;
    }

    .gallery-title {
        font-size: 2rem;
    }

    .gallery-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .view-controls {
        align-self: flex-end;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 25px;
    }

    .gallery-grid.masonry {
        column-count: 1;
    }

    .image-info {
        padding: 10px;
    }

    .lightbox-actions {
        flex-wrap: wrap;
    }
}

/* ===== 深色模式支持 ===== */
@media (prefers-color-scheme: dark) {
    .gallery-item {
        background: #1e293b;
    }

    .image-info {
        background: #1e293b;
        border-top: 1px solid #2c3e50;
    }

    .image-title {
        color: #e2e8f0;
    }

    .no-images {
        background: #1e293b;
        border-color: #2c3e50;
    }

    .image-container {
        background: #2c3e50;
    }

    .image-error {
        background: rgba(30, 41, 59, 0.8);
    }

    .skeleton {
        background: linear-gradient(to right, #1a2030 0%, #2a3548 20%, #1a2030 40%, #1a2030 100%);
    }
}

/* ===== 打印优化 ===== */
@media print {
    .gallery-container {
        margin: 0;
        padding: 20px;
    }

    .gallery-controls,
    .load-more-container,
    .lightbox,
    .page-loader,
    #particles-js,
    .back-to-top {
        display: none !important;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .gallery-grid.masonry {
        column-count: 2;
        column-gap: 20px;
    }

    .gallery-item {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    .image-overlay {
        display: none;
    }

    .image-info {
        background: white;
        color: black;
    }
}

/* ===== 键盘导航增强 ===== */
.gallery-item:focus-visible,
.filter-btn:focus-visible,
.view-btn:focus-visible,
.lightbox-nav:focus-visible,
.lightbox-action:focus-visible {
    outline: 3px solid var(--gallery-primary);
    outline-offset: 2px;
}

/* 可访问性隐藏类 */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}