#gallery {
    position: relative; /* For absolute positioning of items */
    width: 100%;
    transition: height 0.5s ease; /* Animate height changes */
}

.gallery-item {
    position: absolute; /* Each item is positioned by JS */
    /* width is now set by JS */
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    overflow: hidden; /* 确保图片圆角生效 */
    transition: top 0.5s ease, left 0.5s ease, transform 0.5s ease, opacity 0.5s ease;
    opacity: 0;
    transform: scale(0.95); /* Start slightly smaller for entry animation */
}

.gallery-item.hiding {
    opacity: 0 !important;
    transform: scale(0.8) !important;
    pointer-events: none; /* Prevent interaction during removal */
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.image-container {
    width: 100%;
    background-color: #e9ecef; /* A light grey placeholder color */
    overflow: hidden;
}

.image-container.loading {
    position: relative;
    min-height: 150px; /* A minimum height for the loading state */
}

.image-container.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: loading-shimmer 1.5s infinite;
}

.image-container.error {
    position: relative; /* Needed for absolute positioning of the error message */
    background-color: #e9ecef; /* Keep the original placeholder color */
}

/* Retain the shimmer effect even on error */
.image-container.error::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: loading-shimmer 1.5s infinite;
}

.error-message {
    display: none; /* Hidden by default */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.9em;
    color: #6c757d; /* A dark grey color for better readability on light background */
    background-color: transparent; /* Remove the overlay */
    text-align: center;
    z-index: 1; /* Ensure it's above the shimmer effect */
}

.image-container.error .error-message {
    display: flex; /* Shown when error class is present */
}

.error-message::before {
    content: '\26A0'; /* Warning sign emoji */
    font-size: 2em;
    margin-bottom: 8px;
    color: #dc3545;
}

@keyframes loading-shimmer {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(200%);
    }
}

.gallery-item img {
    width: 100%;
    height: auto; /* Allow image to define its own height */
    display: block;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.spoiler {
    background-color: #2c2c2c;
    color: #2c2c2c;
    cursor: pointer;
    transition: color 0.2s, background-color 0.2s;
    border-radius: 3px;
    padding: 0 0.3em;
    display: inline;
    vertical-align: baseline;
    line-height: 1.4;
}

.spoiler:hover, .spoiler.revealed {
    color: #fff;
    background-color: #444;
}

.image-container:not(.loading) img, .image-container.loading img.loaded {
    opacity: 1;
}

.image-container.loading img:not(.loaded) {
     display: none; /* Hide the (not yet loaded) image */
}

.gallery-item.no-image .info-container {
    padding-top: 25px; /* Add more padding to the top if there's no image */
}

.info-container {
    padding: 15px;
    position: relative;
}

.gallery-item h3 {
    margin: 0 0 10px 0;
    font-size: 1.25em;
    color: #333;
}

.gallery-item p {
    margin: 0 0 8px 0;
    font-size: 0.9em;
    line-height: 1.5;
    color: #666;
}

.gallery-item .description {
    color: #555;
    overflow: hidden;
    max-height: 2.7em; /* Limit to 2 lines, hide overflow */
}

.gallery-item .description:empty {
    margin: 0; /* Remove margin if description is empty */
}

.gallery-item .rating {
    font-weight: bold;
    color: #e67e22;
}

.gallery-item .safety,
.modal-content .safety {
    font-size: 0.9em;
    font-weight: bold;
}

/* Specific color rules to override default paragraph colors */
p.safety.safety-sfw {
    color: #28a745; /* 更柔和、标准的绿色 */
}

p.safety.safety-nsfw {
    color: #dc3545; /* 更醒目的警告红色 */
}

.gallery-item .release-date {
    font-size: 0.8em;
    color: #888;
}

.category-info {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-info p {
    margin: 0 0 4px 0;
    font-size: 0.85em;
}

/* 响应式调整 - 卡片宽度现在由JS控制 */
/* The media queries for width are no longer needed. */

/* Series Tag Styles */
.series-tag {
    background-color: #e7f3ff;
    color: #005a9e;
    border: 1px solid #b8d6f3;
    border-radius: 12px;
    padding: 3px 10px;
    font-size: 0.8em;
    font-weight: 600;
}

/* --- 移动端优化 --- */
@media (max-width: 600px) {
    .info-container {
        padding: 10px;
    }

    .gallery-item h3 {
        font-size: 1.05em; /* 减小标题字体 */
        margin-bottom: 6px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        max-height: 2.5em; /* 约2行 */
    }

    .gallery-item .description {
        -webkit-line-clamp: 1; /* 简介限制为1行 */
        line-clamp: 1;
        max-height: 1.5em;
        margin-bottom: 6px;
    }

    .gallery-item .rating, .gallery-item .safety {
        font-size: 0.85em;
    }
    
    /* 将评分和安全等级放在一行 */
    .rating-safety-container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px; /* 在它们之间添加一些间隙 */
        margin-bottom: 8px;
    }
}