/**
 * Steam 媒体画廊样式（全自动版）
 * ---------------------------------------------------------------
 * 自动在「游戏截图」H3 下方原地输出：主图 + 缩略图 + 箭头 + 计数器
 * 点击主图调用子比主题灯箱
 * 激活色调：#d10f45 玫红系
 *
 * @package xd_badges_gallery
 */

.xd-image-gallery {
    --gallery-accent: #d10f45;
    --gallery-radius: 8px;
    --gallery-thumb-radius: 7px;
    --gallery-gap: 6px;
    --gallery-thumb-w: 80px;
    --gallery-thumb-h: 45px;

    width: 100%;
    max-width: 100%;
    margin: 4px 0 10px;
    box-sizing: border-box;
    /* 兜底：画廊任何内容都不允许撑破页面产生横向滚动 */
    overflow: hidden;
}

.xd-image-gallery *,
.xd-image-gallery *::before,
.xd-image-gallery *::after {
    box-sizing: border-box;
}

/* === 主图视口（高度由 JS 按当前图片宽高比自适应，不再固定，避免两侧黑边） === */
.xd-image-gallery-viewport {
    position: relative;
    width: 100%;
    border-radius: var(--gallery-radius);
    overflow: hidden;
    /* 固定深色底，不使用主题 --main-bg-color：浅色模式下该变量为白色，
       图片切换高度过渡的瞬间会闪白边。深色底与 Steam 画廊观感一致。 */
    background: #0e1116;
    border: 1px solid var(--main-border-color, rgba(50, 50, 50, 0.08));
    transition: height 0.3s ease;
}

/* === 主图容器 === */
.xd-image-gallery-main {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.xd-image-gallery-main img {
    max-width: 100%;
    max-height: 75vh;
    width: auto;
    height: auto;
    margin: 0 auto;
    object-fit: contain;
    display: none;
}

.xd-image-gallery-main img.active {
    display: block;
    cursor: zoom-in;
}

/* === 点击查看大图提示（hover） === */
.xd-gallery-zoomhint {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;

    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 11px;

    font-size: 12px;
    color: #fff;
    border-radius: 999px;
    background: rgba(17, 19, 24, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);

    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.xd-image-gallery-viewport:hover .xd-gallery-zoomhint {
    opacity: 1;
}

/* === 左右箭头 === */
.xd-image-gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);

    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 20px;
    font-family: Arial, sans-serif;
    line-height: 1;

    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 2;

    opacity: 0;
    transition: background 0.2s ease, opacity 0.25s ease;
    -webkit-user-select: none;
    user-select: none;
}

/* 鼠标悬停主图区域 / 键盘聚焦时才显示箭头 */
.xd-image-gallery-viewport:hover .xd-image-gallery-arrow,
.xd-image-gallery-viewport:focus-within .xd-image-gallery-arrow {
    opacity: 1;
}

.xd-image-gallery-arrow:hover {
    background: rgba(0, 0, 0, 0.75);
}

/* 触屏设备没有 hover，箭头保持常显 */
@media (hover: none) {
    .xd-image-gallery-arrow {
        opacity: 1;
    }
}

.xd-image-gallery-arrow:focus-visible {
    outline: 2px solid var(--gallery-accent);
    outline-offset: 2px;
}

.xd-image-gallery-arrow--prev {
    left: 10px;
}

.xd-image-gallery-arrow--next {
    right: 10px;
}

/* === 计数器 === */
.xd-image-gallery-counter {
    position: absolute;
    top: 10px;
    right: 10px;

    padding: 4px 11px;
    background: rgba(17, 19, 24, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);

    color: #fff;
    font-size: 12px;
    line-height: 1.5;
    border-radius: 999px;
    z-index: 2;
    pointer-events: none;
}

/* === 缩略图条 === */
.xd-image-gallery-thumbs {
    display: flex;
    gap: var(--gallery-gap);
    /* margin-top 由 8 减为 5，叠加 3px 上内边距，视觉间距不变；
       上内边距为悬停 translateY(-2px) 留出空间——容器 overflow-y:hidden
       会裁掉越过边界的部分，上移的缩略图（含高亮边框）必须留在内部。 */
    margin-top: 5px;
    padding-top: 3px;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.xd-image-gallery-thumbs::-webkit-scrollbar {
    height: 6px;
}

.xd-image-gallery-thumbs::-webkit-scrollbar-thumb {
    background: var(--main-border-color, rgba(50, 50, 50, 0.15));
    border-radius: 3px;
}

/* === 单个缩略图 === */
.xd-image-gallery-thumb {
    flex-shrink: 0;
    width: var(--gallery-thumb-w);
    height: var(--gallery-thumb-h);
    border-radius: var(--gallery-thumb-radius);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, transform 0.2s ease;
    background: #0e1116;
}

.xd-image-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.xd-image-gallery-thumb:hover {
    transform: translateY(-2px);
}

.xd-image-gallery-thumb.active {
    border-color: var(--gallery-accent);
}

.xd-image-gallery-thumb:focus-visible {
    outline: 2px solid var(--gallery-accent);
    outline-offset: 2px;
}

/* === 响应式 === */
@media (max-width: 768px) {
    .xd-image-gallery {
        --gallery-thumb-w: 64px;
        --gallery-thumb-h: 36px;
        --gallery-gap: 4px;
    }

    .xd-image-gallery-arrow {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }

    .xd-image-gallery-arrow--prev {
        left: 6px;
    }

    .xd-image-gallery-arrow--next {
        right: 6px;
    }

    .xd-image-gallery-counter {
        font-size: 11px;
        padding: 3px 9px;
        top: 6px;
        right: 6px;
    }

    .xd-gallery-zoomhint {
        display: none;
    }
}

/* === 减少动画偏好 === */
@media (prefers-reduced-motion: reduce) {
    .xd-image-gallery-arrow,
    .xd-image-gallery-thumb,
    .xd-image-gallery-viewport,
    .xd-gallery-zoomhint {
        transition: none;
    }

    .xd-image-gallery-thumb:hover {
        transform: none;
    }
}
