/* 卡片/画廊/滑块/收藏/置顶按钮/响应式（从 style.css 拆分） */
/* 滑块样式 */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 8px; /* 稍微加粗，配合新圆角更美观 */
    background: var(--card-background);
    border-radius: calc(var(--global-border-radius) / 4);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--text-color);
    border-radius: 50%;
}

.tabs {
    display: flex;
    background-color: var(--card-background);
    width: 100%; /* 拉伸到父级全宽（父级会被限制） */
    max-width: 400px; /* 设为与搜索区块相同的宽度 */
    border-radius: var(--global-border-radius);
}
.tabs .author-credit {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.tab-button {
    font-size: 15px;
    font-weight: 600;
    padding: 12px 24px;
    border: none;
    background-color: transparent;
    color: var(--secondary-text-color); /* 去掉内圆角 */
    border-radius: calc(var(--global-border-radius) - 4px); /* 比主圆角略小以体现嵌套 */
    cursor: pointer;
    transition: all 0.3s ease;
    flex-grow: 1; /* 让按钮均匀占据空间 */
    text-align: center; /* 让按钮内文字居中 */
    text-decoration: none; /* 去掉链接下划线 */
}

.tab-button.active {
    background-color: var(--border-color);
    border-radius: var(--global-border-radius); /* 应用统一圆角 */
    color: var(--text-color);
}

.gallery-grid.uniqueness-view .works-count {
    display: none;
}

/* 仅在“收藏”标签页隐藏作品计数和独特性排名 */
.gallery-grid.favorites-view .card .works-count, .gallery-grid.favorites-view .card .uniqueness-rank {
    display: none;
}

.uniqueness-rank {
    position: absolute;
    top: 12px;
    left: 12px;
    min-width: 36px; /* 最小宽度等于高度以保持圆形 */
    height: 36px;
    padding: 0 6px; /* 为文字添加两侧留白 */
    background-color: rgba(10, 132, 255, 0.6); /* 带透明度的强调色 */
    border-radius: var(--global-border-radius); /* 高度的一半以形成“胶囊”形状 */
    display: none; /* 默认隐藏 */
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    user-select: none;
}

.gallery-grid.uniqueness-view .uniqueness-rank {
    display: flex; /* 仅在按独特性排序模式下显示 */
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns, 5), 1fr);
    gap: 20px;
    /* CLS 优化：画廊卡片异步渲染，预留最小高度避免内容填充时整页跳动 */
    min-height: 70vh;
}

.card {
    background-color: var(--card-background);
    border-radius: var(--global-border-radius);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s ease-in-out;
    -webkit-tap-highlight-color: transparent; /* 去掉移动端点击时的蓝色高亮 */
}

.card:hover {
    transform: scale(1.03);
}

/* 选中卡片的样式 */
.card.selected {
    transform: scale(1.03); /* 保持放大状态 */
    box-shadow: 0 0 0 3px var(--accent-color), 0 5px 15px rgba(0,0,0,0.3);
    border-color: var(--accent-color);
}

.card__image {
    width: 100%;
    height: auto;
    aspect-ratio: 832 / 1216;
    object-fit: cover;
    display: block;
    background-color: var(--border-color);
}

.card__info {
    padding-top: 2px;
    padding-bottom: 2px;
    text-align: center;
}

.card__artist {
    font-size: 16px;
    font-weight: 600;
    color: var(--secondary-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.favorite-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background-color: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    /* 去掉文字符号，改用 SVG 背景 */
    font-size: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' fill='none' stroke='%23ffffff' stroke-width='32'%3E%3Cpath d='M352.92 80C288 80 256 144 256 144s-32-64-96.92-64c-52.76 0-94.54 44.14-95.08 96.81-1.1 109.33 86.73 187.08 183.67 277.65 6.19 5.89 13.73 8.54 21.33 8.54s15.14-2.65 21.33-8.54c96.94-90.57 184.77-168.32 183.67-277.65C447.46 124.14 405.68 80 352.92 80z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 55%;
    transition: background-color 0.2s, transform 0.2s;
}

.favorite-button:hover {
    background-color: rgba(0, 0, 0, 0.7);
    transform: scale(1.1);
}

.favorite-button.favorited {
    background-color: rgba(10, 132, 255, 0.2); /* 使用强调色 */
    /* 替换为带填充的 SVG */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' fill='%230a84ff'%3E%3Cpath d='M47.6 300.4L228.3 469.1c7.5 7 17.4 10.9 27.7 10.9s20.2-3.9 27.7-10.9L464.4 300.4c30.4-28.3 47.6-68 47.6-109.5v-5.8c0-69.9-50.5-129.5-119.4-141C347 36.5 300.6 51.4 268 84L256 96 244 84c-32.6-32.6-79-47.5-124.6-39.9C50.5 55.6 0 115.2 0 185.1v5.8c0 41.5 17.2 81.2 47.6 109.5z'/%3E%3C/svg%3E");
    background-size: 60%;
}

.favorite-button.remove-favorite {
    font-size: 26px; /* 把叉号稍微调大 */
    background-color: rgba(0, 0, 0, 0.5); /* 默认背景 */
    color: #fff; /* 白色叉号 */
    background-image: none; /* 去掉心形背景图 */
}

.works-count {
    position: absolute;
    top: 12px;
    left: 12px;
    min-width: 36px; /* 最小宽度等于高度以保持圆形 */
    height: 36px;
    padding: 0 6px; /* 为文字添加两侧留白 */
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: var(--global-border-radius); /* 高度的一半以形成“胶囊”形状 */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    /* 防止点击时选中文字 */
    user-select: none;
}

.loader-container {
    position: fixed; /* 相对浏览器窗口固定 */
    bottom: 30px; /* 底部留白 */
    left: 50%; /* 水平居中 */
    transform: translateX(-50%); /* 精确居中 */
    padding: 10px; /* 小幅内边距 */
    background-color: var(--card-background); /* 添加背景，使其在卡片上可见 */
    border-radius: 50%; /* 让背景为圆形 */
    z-index: 1001; /* 层级高于卡片但低于 toast */
}

.loader {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 14px 24px;
    border-radius: var(--global-border-radius);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    visibility: visible;
}

/* “回到顶部”按钮 */
.scroll-to-top-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    background-color: var(--card-background);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    line-height: 1;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
    z-index: 999;
}

/* 标题与画廊的容器 */
.gallery-wrapper {
    flex: 1; /* 该容器将占据所有可用空间 */
    display: flex;
    flex-direction: column;
}

/* 画廊上方的标题（用于显示文件夹名） */
.gallery-title {
    text-align: left;
    font-size: 22px;
    font-weight: 600; /* 把主字重调轻一点 */
    color: var(--text-color); /* 文件夹名称显示为亮色 */
    margin-bottom: 20px;
}

.gallery-title-label {
    font-weight: 500;
    color: var(--secondary-text-color); /* 标签对比度较低 */
    margin-right: 8px;
}

.scroll-to-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.scroll-to-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-to-top-btn:hover {
    background-color: var(--border-color);
}

/* 响应式适配 */
@media (max-width: 1200px) {
    .gallery-grid { --grid-columns: 4; }
}
@media (max-width: 992px) {
    .controls-container {
        flex-wrap: wrap; /* 允许控件换行 */
        justify-content: center; /* 内容居中 */
        gap: 15px; /* 缩小移动端区块之间的间距 */
    }
    .sort-jump-group {
        order: 2; /* 把筛选区块排在第二位 */
        flex-basis: 100%; /* 让区块占满全宽以便居中 */
        width: auto; /* 去掉固定宽度以便居中 */
        align-items: center; /* 让其内容居中 */
        gap: 15px; /* 在排序按钮和 TXT 之间添加间距 */
    }
    /* 移动端让 TXT 按钮居中 */
    #txt-export-container {
        justify-content: center;
    }
    /* 移动端恢复排序按钮居中 */
    .sort-controls {
        justify-content: center;
        width: auto; /* 去掉全宽拉伸 */
    }
    .sort-buttons-grid {
        flex: none; /* 取消按钮网格的拉伸 */
        width: 200px; /* 设置固定宽度以更紧凑 */
    }
    .search-input {
        text-align: center; /* 移动端文字居中 */
    }
    .search-wrapper {
        width: 90%; /* 用百分比宽度以适配 */
        max-width: 360px; /* 平板上让搜索区块比标签短以体现层级 */
    }
    .search-input-container { width: 100%; } /* 搜索框占满新父级的全宽 */
    .jump-controls {
        flex-basis: 100%;
        justify-content: center;
        display: flex; /* 添加 flex 以对齐 */
        justify-content: center; /* 内容居中（搜索框） */
    }
    /* 在平板和手机上隐藏滑块 */
    .grid-controls { display: none; }
    /* 移动端隐藏 “Sort by:” 文字，让按钮居中 */
    .sort-label {
        display: none;
    }
    /* 移动端隐藏新按钮 */
    .right-controls-group {
        display: none;
    }
    .search-and-import-wrapper {
        flex-direction: column;
        align-items: center;
        width: 100%; /* 占满全宽，但添加留白 */
        padding: 0 10px; /* 添加两侧留白 */
    }
    .header {
        width: 100%;
        /* 添加两侧留白并保留底部留白以放分隔线 */
        padding: 0 10px 20px; 
    }
    /* 移动端若容器为空则隐藏 */
    #txt-export-container:empty {
        display: none;
    }
    /* 移动端隐藏 swipe 模式提示 */
    #swipe-continue-hint { display: none !important; }

    /* 移动端隐藏文件夹切换按钮 */
    #toggle-folders-btn {
        display: none;
    }
}
@media (max-width: 768px) {
    body { padding: 10px; }
    .header { margin-bottom: 20px; }
    .gallery-grid { --grid-columns: 2; } /* 平板 2 列 */
    .scroll-to-top-btn {
        bottom: 70px; /* 移动端把按钮上移 */
        right: 20px;
        width: 56px;
        height: 56px;
    }
    .favorite-button {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }
    .works-count {
        min-width: 44px;
        height: 44px;
        border-radius: 22px; /* 高度的一半 */
        font-size: 15px;
        top: 10px;
        left: 10px;
    }
    .uniqueness-rank {
        min-width: 44px;
        height: 44px;
        border-radius: 22px;
        font-size: 15px;
        top: 10px;
        left: 10px;
    }
}
@media (max-width: 480px) {
    .gallery-grid { --grid-columns: 2; } /* 手机 2 列 */
    .favorite-button {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    .works-count {
        min-width: 32px;
        height: 32px;
        border-radius: 16px;
        font-size: 13px;
    }
    .uniqueness-rank {
        min-width: 32px;
        height: 32px;
        border-radius: 16px;
        font-size: 13px;
    }
    .favorite-button.remove-favorite {
        font-size: 22px; /* 调整叉号尺寸 */
    }
}

