/* Gallery styles */
.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8em; /* Increase gap to prevent overlap */
  width: 80%;
  max-width: 1200px;
  margin: 150px auto 20px; /* Adjust for header and tag filter */
  padding: 10px;
  flex-grow: 1; /* Ensure gallery takes up available space */
  align-items: flex-start; /* Align items to the top */
  opacity: 0; /* Start hidden */
  transition: opacity 1s; /* Fade-in effect */
}

/* 淡入动画（替代 flyIn 位移动画：触屏逐批加载时图片不再「漂」进视口） */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Loading spinner animations */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Loading spinner styles */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: #fff;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 10px;
}

.loading-paused {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: #fff;
}

.spinner-paused {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid #fff;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
  margin-bottom: 10px;
}

/* Story 卡片（梗解释 + variants 语言标签，schema 见 docs/plan/data/story-schema.md） */
#story-info {
  margin: 10px auto 0;
  display: none; /* 有 story/variants 的图由 JS 打开 */
  width: 90%;
  max-width: 700px;
  text-align: left;
}

/* 浏览/点赞统计条（弹层大图下方，story 卡片上方；服务端未启用时 JS 整条隐藏） */
#meme-stats {
  margin: 10px auto 0;
  display: none;
  width: 90%;
  max-width: 700px;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

#meme-stats .stat-views {
  opacity: 0.9;
}

#meme-stats .stat-like {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
  padding: 2px 8px;
  border-radius: 6px;
}

#meme-stats .stat-like:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* 弹层浏览/点赞条与反馈行的层级关系：反馈行是散落的文字链接，统计条用同一字体层级
   贴齐左边（与反馈行的右对齐形成一条隐形的「操作栏」），移动端不再孤悬左缘 */
#meme-stats {
  font-size: 13px;
}

#meme-stats .stat-views {
  opacity: 0.9;
}
#meme-stats .stat-like .heart {
  font-size: 15px;
  line-height: 1;
}

#meme-stats .stat-like.liked {
  color: #ff5f7a;
}

/* 弹层内反馈行：紧跟浏览/点赞操作条，右对齐的小号链接。
   放在这里而不是页脚——页脚在瀑布流末尾，滚到底就补 15 张，永远够不到 */
#meme-feedback {
  display: flex;
  flex-wrap: wrap;
  width: 90%;
  max-width: 700px;
  margin: 6px auto 0;
  justify-content: flex-end;
  gap: 8px 16px; /* row-gap 8px: 极端窄屏换行后两行不贴一起；col-gap 16px: 单行内间距 */
  font-size: 13px;
}

#meme-feedback a {
  color: rgba(255, 255, 255, 0.65); /* 90% 黑底上约 8:1，满足 WCAG AA */
  text-decoration: none;
}

#meme-feedback a:hover,
#meme-feedback a:focus {
  color: #fff;
  text-decoration: underline;
}

/* 「不是 DeepSeek 图」一键标记：视觉与旁边两条链接同款（原生 button 需重置背景/边框/字号） */
#meme-feedback button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
}

#meme-feedback button:hover,
#meme-feedback button:focus {
  color: #fff;
  text-decoration: underline;
}

#meme-feedback button:disabled {
  color: rgba(125, 211, 160, 0.9);
  cursor: default;
  text-decoration: none;
}

.story-card {
  background: rgba(22, 25, 34, 0.97); /* 近实心：避免文字叠在遮罩透出的瀑布流上 */
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.story-card p {
  margin: 12px 0 0;
  color: #e6e9f0;
  font-size: 14px;
  line-height: 1.7;
}

.story-card p:first-child {
  margin-top: 0;
}

/* EN / 中文 语言标签：独立成行作小节头，避免和正文挤在一起 */
.story-lang {
  display: block;
  width: fit-content;
  white-space: nowrap;
  font-size: 11px;
  line-height: 1;
  padding: 3px 8px;
  margin: 0 0 6px;
  border-radius: 4px;
  color: #fff;
  background: #4d6bfe;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.story-card .story-lang-en {
  background: rgba(255, 255, 255, 0.14);
  color: #c9cdd6;
}

.story-card .story-en {
  color: #c3c9d6;
}

/* 出处 小节头 */
.story-label {
  display: block;
  width: fit-content;
  white-space: nowrap;
  font-size: 11px;
  line-height: 1;
  padding: 3px 8px;
  margin: 0 0 6px;
  border-radius: 4px;
  color: #cdd6ff;
  background: rgba(77, 107, 254, 0.22);
  font-weight: 600;
}

.story-card .story-origin {
  color: #b9bfca;
  font-size: 13px;
}

.story-card .story-contributor {
  color: #9aa3b5;
  font-size: 12px;
  text-align: right;
  margin-top: 14px;
}

.variant-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

.variant-tab {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #e0e0e0;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.variant-tab:hover {
  background: rgba(255, 255, 255, 0.18);
}

.variant-tab.active {
  background: #4d6bfe;
  border-color: #4d6bfe;
  color: #fff;
}

/* 移动端：压低大图高度让 story 卡片进首屏；底部留出悬浮按钮空间 */
@media (max-width: 600px) {
  .modal-content {
    max-height: 44vh;
    margin-top: 5vh;
  }

  /* 左下悬浮导航坞是 fixed，留白避免遮住最后一排图 */
  .gallery {
    padding-bottom: 200px;
  }

  #story-info {
    width: 92%;
    margin-top: 12px;
    padding-bottom: 16px; /* 原 96px 是给右下 fixed 按钮让位；按钮已收进操作条，留白收敛 */
  }

  .story-card {
    padding: 12px 14px;
  }

  .story-card p {
    font-size: 15px;
  }
}

.gallery .column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.8em;
  position: relative; /* 确保子元素的z-index正常工作 */
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.9);
  opacity: 1;
  transition: opacity 0.3s ease; /* 添加平滑过渡 */
}

.modal-content {
  margin: auto;
  margin-top: 100px; /* Top margin */
  display: block;
  max-width: 90%;
  max-height: 80%; /* Adjust to accommodate caption */
  width: auto;
  height: auto;
}

.close {
  /* 必须用 fixed：.modal 是 overflow:auto 的可滚动容器，absolute 会随内容一起滚动，
     长 story 场景下用户滚到底后关闭按钮被推到视口外（实测 top:-852px），只剩 ESC 能关。
     modal 自身已是 fixed 且创建了层叠上下文，这里的 fixed 仍相对视口 */
  position: fixed;
  top: 15px;
  right: 35px;
  z-index: 1001; /* 抬到弹层内容之上，避免被大图/卡片盖住 */
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
  /* 触控目标：纯字符没有点击区，补 padding 撑到 ≥44px 并把定位内收（刘海屏吃 safe-area） */
  padding: 6px 12px;
  line-height: 1;
  top: calc(15px + env(safe-area-inset-top, 0px));
  right: calc(23px + env(safe-area-inset-right, 0px));
}

.close:hover,
.close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

/* 原图加载中转圈 / 失败提示的宿主（顶替已删除的旧摄影站 EXIF 面板的布局位） */
#caption,
#modal-loading-note {
  margin: auto;
  display: block;
  width: 90%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
}

/* Disable scrolling */
.no-scroll {
  overflow: hidden;
}

/* Dark theme styles */
body.dark .gallery img {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6); /* Darker shadow for dark mode */
}

body.dark .gallery img.loaded:hover {
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.8); /* Darker shadow for hover in dark mode */
}

body.dark .close {
  color: #e0e0e0;
}

body.dark #caption,
body.dark #modal-loading-note {
  color: #e0e0e0;
}

/* 页面加载转圈（#loading）统一定义在 styles.css：原这里另有一份上游遗留的上游样式，
   两份互相覆盖（背景/内边距打架），已删除本文件中的重复块 */


/* 左下角悬浮导航坞（nav-pod.js）：档案馆 / 小游戏 / 鲸查重 / 社区共评 / 我要投稿 五入口。
   结构 pod(定位包装层) > fab(移动端悬浮球) + items(菜单面板)。
   桌面端常驻展开；移动端(<768px)收成悬浮球，点开弹出——单列瀑布流屏幕全是图，
   常驻面板会盖住近四分之一屏。淡入由 .show 类驱动，不等 window.load */
.nav-pod {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.nav-pod.show {
    opacity: 1;
}

/* 桌面端默认：悬浮球隐藏，菜单面板常驻 */
.nav-pod-fab {
    display: none;
}

.nav-pod-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background: rgba(250, 250, 250, 0.92);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.nav-pod-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    line-height: 1;
    transition: background 0.25s ease, color 0.25s ease;
}

.nav-pod-item:hover {
    background: #4d6bfe; /* 品牌蓝 */
    color: #fff;
}

.nav-pod-item svg {
    width: 18px;
    height: 18px;
    flex: none;
}

/* 移动端：收成悬浮球，菜单从球上方弹出 */
@media (max-width: 767.98px) {
    .nav-pod {
        bottom: 16px;
        left: 16px;
    }

    .nav-pod-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 46px;
        height: 46px;
        border: 0;
        border-radius: 50%;
        background: #4d6bfe;
        color: #fff;
        cursor: pointer;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
    }

    .nav-pod-fab svg {
        width: 20px;
        height: 20px;
    }

    .nav-pod-items {
        position: absolute;
        bottom: 56px;
        left: 0;
        /* .nav-pod 被悬浮球撑成 46px 宽，abspos 面板 shrink-to-fit 会被容器钳住，
           中文标签一字一行变竖排；按内容定宽 + nowrap（老 WebView 不认 max-content 的兜底） */
        width: max-content;
        opacity: 0;
        transform: translateY(6px) scale(0.97);
        transition: opacity 0.18s ease, transform 0.18s ease;
        pointer-events: none;
    }

    .nav-pod-item {
        white-space: nowrap;
    }

    .nav-pod.open .nav-pod-items {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }
}

/* 深色模式反色（与原侧栏同策略） */
body.dark .nav-pod-items {
    background: rgba(30, 30, 30, 0.92);
}

body.dark .nav-pod-item {
    color: #eee;
}

body.dark .nav-pod-item:hover {
    background: #3a65c2; /* 深色模式下的品牌蓝 */
    color: #fff;
}

/* 基础图片样式 */
.gallery img {
  width: 100%;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  /* body 已不再全局禁用 user-select，这里单独禁掉，避免拖拽时选中图片出现蓝色高亮 */
  -webkit-user-select: none;
  user-select: none;
  opacity: 0;
  transform: translateY(30px); /* 修改为与flyIn动画一致的值 */
  position: relative;
  z-index: 1;
}

/* 已加载图片的基本样式 */
.gallery img.loaded {
  /* 无位移动画（flyIn 的 translateY 在触屏逐批加载时会让图片「漂」进视口，
     用户截图反馈左右晃动影响体验）；纯 opacity 淡入，配合 will-change 限制在合成层 */
  animation: fadeIn 0.4s ease-out forwards;
  transition: box-shadow 0.3s cubic-bezier(0.19, 1, 0.22, 1),
              z-index 0.1s;
  will-change: opacity;
  opacity: 1; /* 确保图片可见，不依赖动画 */
}

/* 悬停样式 - 使用更长的动画时间 */
.gallery img.loaded:hover,
.gallery img.loaded.hover-active {
  transform: translate(1px, -2px) !important;
  box-shadow: -5px 12px 20px rgba(0, 0, 0, 0.5) !important;
  z-index: 10 !important;
}

/* 深色模式下的效果 */
body.dark .gallery img.loaded:hover,
body.dark .gallery img.loaded.hover-active {
  box-shadow: -5px 12px 20px rgba(0, 0, 0, 0.8) !important;
}

/* 添加悬停区域占位元素样式 */
.hover-guard {
  position: absolute;
  z-index: 9;
  pointer-events: none;
}

/* 当模态窗口打开时禁用悬停效果 */
body.modal-open .gallery img:hover,
body.modal-open .gallery img.hover-active {
  transform: none !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
  z-index: 1 !important;
  transition: none !important;
}

/* 改进悬停效果在模态关闭后的恢复 */
body:not(.modal-open) .gallery img.loaded:hover,
body:not(.modal-open) .gallery img.loaded.hover-active {
  transition: transform 2s cubic-bezier(0.19, 1, 0.22, 1), 
              box-shadow 2s cubic-bezier(0.19, 1, 0.22, 1) !important;
}

/* 触屏设备禁用悬停动效：mobile 上 tap 会触发 :hover 残留态（点过的图保持浮起），
   hover-active 体系（mouseenter/leave）在触屏上也是无效负载 */
@media (pointer: coarse) {
  .gallery img.loaded:hover,
  .gallery img.loaded.hover-active {
    transform: none !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
  }
}

/* 置底按钮样式 */
.scroll-to-bottom {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(250, 250, 250, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 100;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(100px);
}

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

.scroll-to-bottom:hover {
    background: rgba(240, 240, 240, 0.95);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.scroll-to-bottom:active {
    transform: scale(0.95);
}

.scroll-to-bottom svg {
    width: 24px;
    height: 24px;
    fill: rgba(0, 0, 0, 0.65);
    transition: fill 0.3s ease;
}

.scroll-to-bottom:hover svg {
    fill: #1e232c;
}

/* 深色模式样式 */
body.dark .scroll-to-bottom {
    background: rgba(50, 50, 50, 0.9);
}

body.dark .scroll-to-bottom:hover {
    background: rgba(60, 60, 60, 0.95);
}

body.dark .scroll-to-bottom svg {
    fill: #ccc;
}

body.dark .scroll-to-bottom:hover svg {
    fill: #fff;
}

/* 自动滚动指示器 */
.auto-scroll-indicator {
    position: fixed;
    bottom: 80px;
    right: 20px;
    padding: 8px 12px;
    background: rgba(250, 250, 250, 0.9);
    border-radius: 15px;
    font-size: 12px;
    color: rgba(0, 0, 0, 0.65);
    opacity: 0;
    transform: translateX(100px);
    transition: all 0.3s ease;
    z-index: 100;
    pointer-events: none;
}

.auto-scroll-indicator.visible {
    opacity: 1;
    transform: translateX(0);
}

body.dark .auto-scroll-indicator {
    background: rgba(50, 50, 50, 0.9);
    color: #ccc;
}

/* 画廊加载进度条（progress-bar.js，由 image-loader.js 驱动）：
   header 底缘全宽细条 + header 内计数标签。瀑布流按批串行加载，
   弱网下链条停摆或图片静默失败时，用户滚到底会误以为「图就这么多」，
   常驻 X/Y 计数把「还有更多在加载」显式化 */
.gp-strip {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.22);
    overflow: hidden;
    transition: opacity 0.8s ease;
}

.gp-fill {
    height: 100%;
    width: 0;
    background: rgba(255, 255, 255, 0.95);
    transition: width 0.4s ease;
}

.gp-strip.gp-done .gp-fill {
    background: #7ee787; /* 干净完成：绿 */
}

.gp-strip.gp-incomplete .gp-fill {
    background: #ffb84d; /* 完成但有图片静默失败：琥珀 */
}

/* header 内计数标签（h1 与按钮组之间，h1 有 ellipsis 会主动让位）。
   品牌蓝底上白字加粗全不透明，保证滚动途中也一眼可辨 */
.gp-label {
    flex: none;
    margin: 0 12px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: opacity 0.8s ease;
    cursor: default;
}

.gp-label.gp-incomplete {
    opacity: 1;
    color: #ffd9a0;
}

/* 干净完成后整体淡出，把 header 还给标题 */
.gp-fade {
    opacity: 0 !important;
}

/* 完成语下方的失败缺口提示 / 索引拉取失败提示（image-loader.js 注入） */
.gp-failed-note {
    text-align: center;
    margin: 10px 0 20px;
    padding: 10px;
    color: #b26a00;
    background: rgba(255, 184, 77, 0.15);
    border-radius: 5px;
    animation: fadeIn 1s;
}

body.dark .gp-failed-note {
    color: #ffd9a0;
    background: rgba(255, 184, 77, 0.12);
}

.gp-retry-btn {
    margin-left: 8px;
    padding: 4px 12px;
    border: none;
    border-radius: 6px;
    background: #ffb84d;
    color: #4d3600;
    font-size: 13px;
    cursor: pointer;
}

.gp-retry-btn:hover {
    background: #ffa726;
}

body.dark .gp-retry-btn {
    background: #b26a00;
    color: #fff;
}

/* ---------------- 角色筛选 chips（2026-09-19 角色分类体系） ---------------- */
/* 全 AI 角色单开分类后首页恢复筛选：横向可滑一行置于瀑布流上方。
   空分类（0 张预建行）不渲染；非空分类 <2 个时 gallery.js 直接保持 hidden。
   chips 常驻占位（含 hidden 态）+ 搜索条 margin 让位，消灭「header 与 chips 之间一大块空白」 */
.role-chips {
    display: flex;
    gap: 8px;
    width: 80%;
    max-width: 1200px;
    margin: 10px auto 0;
    padding: 0 10px 6px;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox 隐藏滚动条，靠手势横滑 */
}
.role-chips::-webkit-scrollbar { display: none; }
.role-chip {
    flex: 0 0 auto;
    border: 1px solid var(--primary-color);
    border-radius: 999px;
    padding: 4px 14px;
    font-size: 0.9em;
    cursor: pointer;
    background: var(--bg-color);
    color: var(--text-color);
    white-space: nowrap;
}
.role-chip:hover { border-color: var(--primary-color-dark); }
.role-chip.on {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    font-weight: 600;
}
body.has-role-chips .gallery { margin-top: 10px !important; } /* chips 承担了让位，gallery 只需紧跟 chips */
@media (max-width: 768px) {
    .role-chips { width: 94%; }
}
