/* Reset & Global (Reused from Timeline) */
@font-face {
    font-family: 'RosmarinusText';
    src: url('../../asset/fonts/textFonts.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Navigation (Reused from Timeline) */
.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(20, 15, 10, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(139, 115, 85, 0.3);
    z-index: 1000;
    padding: 0; /* Let container handle padding */
    transition: all 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem; /* Vertical padding here */
}

.main-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    /* Assuming fonts are loaded in html or inherited */
    font-family: 'Old English Text MT regular', serif; /* Use custom title font */
    font-size: 2rem;
    color: #d4af37;
    letter-spacing: 0.1em;
    text-decoration: none;
    /* font-weight: bold; */
}

.nav-links {
    display: flex;
    gap: 2rem;
    list-style: none;
}

.nav-links a {
    font-family: 'RosmarinusText', serif; /* Use custom text font */
    font-size: 1.6rem;
    color: #c9b896;
    text-decoration: none;
    position: relative;
    transition: color 0.3s ease;
}

.nav-links a::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 1px;
    background: #d4af37;
    transition: width 0.3s ease;
}

.nav-links a:hover, .nav-links a.active {
    color: #d4af37;
}

.nav-links a:hover::after, .nav-links a.active::after {
    width: 100%;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #c9b896;
    font-size: 1.5rem;
    cursor: pointer;
}

@media (max-width: 830px) {
    .nav-links {
        display: none;
    }
    
    .mobile-menu-toggle {
        display: block;
        z-index: 1001;
    }

    .nav-links {
        display: flex;
        position: fixed;
        top: 0;
        right: -100%;
        width: 250px;
        height: 100vh;
        background: rgba(20, 15, 10, 0.98);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        transition: right 0.3s ease;
        z-index: 1000;
        box-shadow: -5px 0 15px rgba(0,0,0,0.5);
        padding-top: 60px;
    }

    .nav-links.active {
        right: 0;
    }
    
    .nav-links li {
        margin: 1.5rem 0;
    }
}

/* 画廊页面特定样式 */

body {
    /* 覆盖默认背景 */
    background-image: url('../../asset/img/PaperTextureSeamless/galleryBg.webp');
    background-attachment: fixed;
    background-size: cover;
    background-position: center;
    /* 继承 timeline 的基础字体设置 */
    color: #c9b896;
    font-family: 'Crimson Text', serif;
    line-height: 1.6;
    overflow-x: hidden;
}

.gallery-page {
    padding-top: 80px; /* 为固定导航栏留出空间 */
    min-height: 100vh;
}

/* Header & Filter */
.gallery-header {
    text-align: center;
    padding: 2rem 1rem;
    margin-bottom: 2rem;
}

.gallery-title {
    font-family: serif;
    font-size: clamp(3rem, 8vw, 5rem);
    font-weight: bold;
    color: var(--color-text-gold);
    margin-bottom: 1.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.story-filter {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    max-width: 1000px;
    margin: 0 auto;
}

.filter-badge {
    background: rgba(30, 25, 20, 0.8);
    border: 1px solid var(--color-border);
    color: var(--color-text-pale);
    padding: 0.6rem 1.5rem;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.filter-badge:hover {
    background: rgba(30, 25, 20, 0.9);
    border-color: #a0896d;
    transform: translateY(-2px);
}

.filter-badge.active {
    background: linear-gradient(135deg, rgba(139, 115, 85, 0.4) 0%, rgba(61, 47, 31, 0.9) 100%);
    color: var(--color-text-gold);
    border-color: var(--color-text-gold);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.4), inset 0 0 10px rgba(212, 175, 55, 0.1);
    font-weight: bold;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.filter-badge.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--color-text-gold), transparent);
}

/* Gallery Grid & Items */
.gallery-grid {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem 4rem;
}

/* Masonry Sizing */
.gallery-sizer,
.gallery-item {
    width: calc(25% - 30px); /* 4列，减去间隙 */
    margin-bottom: 40px;
}

/* 响应式列数 */
@media (max-width: 1200px) {
    .gallery-sizer,
    .gallery-item {
        width: calc(33.333% - 27px); /* 3列 */
    }
}

@media (max-width: 768px) {
    .gallery-sizer,
    .gallery-item {
        width: calc(50% - 20px); /* 2列 */
        margin-bottom: 20px;
    }
    
    .gallery-grid {
        padding: 0 1rem 4rem;
    }
}

@media (max-width: 480px) {
    .gallery-sizer,
    .gallery-item {
        width: 100%; /* 1列 */
    }
}

.gallery-item {
    position: relative;
    padding: 10px; /* 类似拍立得的留白 */
    transition: transform 0.3s ease, filter 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
    /* 移除 overflow: hidden 以允许阴影和覆盖层正确显示，如果需要裁切，在内部容器处理 */
}

.gallery-item-bg {
    position: absolute;
    inset: 0;
    /* 不规则边缘与羊皮纸背景 */
    background-color: var(--color-parchment);
    background-image: url('../../asset/img/PaperTextureSeamless/parchment.webp');
    background-size: cover;
    background-blend-mode: multiply;
    filter: url(#parchment-filter) drop-shadow(2px 4px 6px rgba(0,0,0,0.3));
    z-index: 0;
}

.gallery-image-container {
    position: relative;
    width: 100%;
    z-index: 1;
    /* 使用不规则边缘裁剪图片，参考角色简介的处理方式 */
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.2));
}

.gallery-image-bg {
    /* 移除或保留作为备用 */
    display: none; 
}

.gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    position: relative;
    z-index: 2;
    object-fit: cover;
    clip-path: polygon(
        5% 0%, 95% 2%, 100% 10%, 98% 90%,
        90% 100%, 10% 98%, 0% 90%, 2% 10%
    );
    /* 确保图片本身不被扭曲，只裁剪边缘 */
    filter: none;
    transition: transform 0.5s ease;
}

.gallery-item:hover {
    z-index: 10;
    /* 悬停效果由 JS 控制 scale 和 translate 复原 */
    /* 移除可能导致页面上浮的全局变换，transform 仅在 JS 中控制 */
}

/* 确保 hover 时父容器不发生位移 */
.gallery-grid {
    position: relative;
    z-index: 1;
}

.gallery-item:hover .gallery-item-bg {
    filter: url(#parchment-filter) drop-shadow(5px 10px 12px rgba(0,0,0,0.4));
}

.image-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%; /* 覆盖整个 item */
    padding: 2rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: linear-gradient(to top, rgba(20, 15, 10, 0.9) 0%, rgba(20, 15, 10, 0.4) 50%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 5;
    clip-path: polygon(
        5% 0%, 95% 2%, 100% 10%, 98% 90%,
        90% 100%, 10% 98%, 0% 90%, 2% 10%
    );
}

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

.image-title {
    font-family: var(--font-serif);
    color: var(--color-text-gold);
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.story-tag {
    font-family: var(--font-serif);
    color: var(--color-text-pale);
    font-size: 0.9rem;
    font-style: italic;
}

/* 墨水褪去效果 */
.gallery-item.faded {
    opacity: 0.3;
    pointer-events: none;
    /* 避免对容器使用 filter: url(...) 以免扭曲图片 */
}

.gallery-item.faded .gallery-item-bg {
    filter: grayscale(100%) url(#parchment-filter);
}

.gallery-item.faded .gallery-image-container {
    filter: grayscale(100%);
}

/* Modal */
.exhibit-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    /* 移除可能的 overflow 导致滚动条闪烁 */
}

body.modal-open {
    overflow: hidden; /* 防止背景滚动 */
}

.exhibit-modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
}

.modal-content {
    /* 复用 parchment-card 样式，但需要覆盖一些属性 */
    position: relative;
    z-index: 2001;
    width: 90%;
    max-width: 1000px;
    max-height: 90vh; /* 默认桌面端限制最大高度 */
    display: flex;
    gap: 2rem;
    overflow-y: auto; /* 允许内容滚动 */
    padding: 2.5rem; /* Ensure sufficient padding */
}

@media (max-width: 768px) {
    .exhibit-modal {
        /* Allow modal container to scroll if content is taller than screen */
        overflow-y: auto;
        padding: 20px 0; /* Add some vertical spacing */
        align-items: flex-start; /* Start from top */
    }

    .modal-content {
        flex-direction: column;
        padding: 1.5rem;
        width: 95%;
        max-height: none; /* Remove height limit for natural scrolling */
        height: auto;
        overflow-y: visible; /* Let body scroll */
        margin: 20px auto; /* Center with margin */
    }

    .modal-image-container {
        height: auto;
        /* Remove fixed height constraints to let image size naturally or cap it slightly */
        max-height: 50vh; 
    }
    
    .modal-image {
        position: relative;
        width: 100%;
        height: auto;
        object-fit: contain;
    }
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--color-text-brown);
    cursor: pointer;
    z-index: 10;
}

.modal-image-section {
    flex: 1.5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-image-container {
    position: relative;
    display: inline-block;
    padding: 5px;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.3));
    clip-path: polygon(
        5% 0%, 95% 2%, 100% 10%, 98% 90%,
        90% 100%, 10% 98%, 0% 90%, 2% 10%
    );
}

.modal-image-bg {
    position: absolute;
    inset: 0;
    background-color: #f3dcad;
    background-image: url('../../asset/img/PaperTextureSeamless/parchment.webp');
    background-size: cover;
    background-blend-mode: multiply;
    z-index: 0;
}

.modal-image {
    position: relative;
    z-index: 1;
    display: block;
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    clip-path: polygon(
        5% 0%, 95% 2%, 100% 10%, 98% 90%,
        90% 100%, 10% 98%, 0% 90%, 2% 10%
    );
    filter: none !important;
}

.modal-info-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: var(--color-text-brown);
}

.exhibit-title {
    font-family: 'RosmarinusText', serif;
    font-size: 4rem;
    margin-bottom: 0.5rem;
    color: #271e14;
}

.exhibit-story-tag {
    display: inline-block;
    background: rgba(139, 115, 85, 0.2);
    padding: 0.2rem 0.8rem;
    border-radius: 4px;
    font-family: var(--font-serif);
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    align-self: flex-start;
}

.exhibit-description {
    font-family: var(--font-serif);
    font-size: 1.7rem;
    font-weight: bold;
    line-height: 1.8;
    margin-bottom: 2rem;
}

.exhibit-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.exhibit-links a {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-text-brown);
    color: var(--color-text-brown);
    text-decoration: none;
    font-family: var(--font-serif);
    transition: all 0.3s ease;
}

.exhibit-links a:hover {
    background: var(--color-text-brown);
    color: var(--color-parchment);
}

.hidden {
    display: none !important;
}
