/* Layout styles */
body {
  font-family: "Roboto", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  transition: background-color 0.3s, color 0.3s;
  /* 100vh 在移动端地址栏收起/展开时跳动；dvh 跟随动态视口，老浏览器吃上一行兜底 */
  min-height: 100vh; /* Ensures footer is at the bottom */
  min-height: 100dvh;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0); /* iOS Safari */
  -webkit-touch-callout: none; /* Disable callout, image save panel (iOS Safari) */
  /* 不再全局禁用 user-select：story 正文、alt 文案、页脚链接需要能被选中复制。
     图片长按保存菜单仍由 -webkit-touch-callout 抑制，图片本身的选中在 gallery.css 单独处理 */
  -ms-touch-action: manipulation; /* IE 10 */
  touch-action: manipulation; /* Non-prefixed version, currently supported by Chrome, Edge, and Firefox */
  color: var(--text-color);
}

header {
  width: 100%;
  background-color: var(--primary-color);
  color: white;
  padding: 15px 20px;
  /* 刘海屏安全区：顶部吃刘海、左右吃圆角（padding 前缀属性叠加，老浏览器忽略） */
  padding-top: calc(15px + env(safe-area-inset-top, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  box-shadow: 0 2px 4px var(--shadow-color);
  z-index: 1000;
  transition: transform 0.3s ease-in-out, height 0.3s ease-in-out,
    padding 0.3s ease-in-out;
  /* content-box + padding 会让 header 实际渲染宽 = width + padding，
     在 1280 视口下实测到 1340，导致右端按钮被切 60px。强制 border-box
     让 width:100% 包含 padding */
  box-sizing: border-box;
}

header h1 {
  margin: 0;
  font-size: 2em;
  transition: font-size 0.3s ease-in-out;
  min-width: 0; /* flex 子项需显式允许收缩，否则长标题不触发 ellipsis */
  overflow: hidden;
}

/* 标题链接继承 h1 的响应式字号：否则会被下面 header a 的固定 24px 覆盖，
   导致移动端无法靠缩字号把长标题压进一行 */
header h1 a {
  display: block;
  font-size: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 默认显示完整站名；<=600px 切短站名，腾出横向空间给投稿按钮 */
.brand-short {
  display: none;
}

.header-buttons {
  display: flex;
  align-items: center;
  transition: font-size 0.3s ease-in-out;
}

header a {
  color: white;
  font-size: 1.5em;
  margin-right: 20px;
  text-decoration: none;
  transition: font-size 0.3s ease-in-out;
}

header button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  transition: font-size 0.3s ease-in-out;
  display: flex;
}

header button img {
  width: 26px;
  height: 26px;
  transition: font-size 0.3s ease-in-out;
  margin-right: 0.1em;
}

header a img {
  width: 26px;
  height: 26px;
  transition: font-size 0.3s ease-in-out;
  margin-right: 0.1em;
}

/* 页头投稿按钮。独立成按钮而不是塞进语言菜单：地球图标是「语言」语义，
   用户不会想到点它找投稿——藏在那儿等于没有入口 */
.contribute-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s;
}

.contribute-btn:hover,
.contribute-btn:focus {
  background: rgba(255, 255, 255, 0.32);
  color: #fff;
}

body.dark .contribute-btn {
  background: rgba(255, 255, 255, 0.14);
}

body.dark .contribute-btn:hover,
body.dark .contribute-btn:focus {
  background: rgba(255, 255, 255, 0.24);
}

/* 语言切换器（locale.js 动态插入 .header-buttons 首位） */
.lang-switch {
  position: relative;
  margin-right: 14px;
}

.lang-switch > button {
  padding: 4px;
  border-radius: 6px;
}

.lang-switch > button svg {
  width: 24px;
  height: 24px;
  display: block;
}

.lang-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.18);
  overflow: hidden;
  min-width: 128px;
  z-index: 1200;
}

.lang-switch.open .lang-menu {
  display: block;
}

/* 语言项用 button，反馈入口用 a（可中键/右键新开），两者共用一套行样式 */
.lang-menu button,
.lang-menu .lang-menu-action {
  display: block;
  width: 100%;
  padding: 10px 18px;
  color: #333;
  font-size: 0.9rem;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
}

.lang-menu button:hover,
.lang-menu .lang-menu-action:hover {
  background: #eef1ff;
}

.lang-menu button.active {
  color: #4d6bfe;
  font-weight: 600;
}

/* 语言项与反馈入口之间的分隔线 */
.lang-sep {
  height: 1px;
  margin: 4px 0;
  background: rgba(0, 0, 0, 0.08);
}

/* 深色模式：语言菜单默认是白底黑字，需整体反色，否则在深色页面上是一块突兀的白 */
body.dark .lang-menu {
  background: #1e1e1e;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

body.dark .lang-menu button,
body.dark .lang-menu .lang-menu-action {
  color: #e0e0e0;
}

body.dark .lang-menu button:hover,
body.dark .lang-menu .lang-menu-action:hover {
  background: #2a2a2a;
}

body.dark .lang-menu button.active {
  color: #8fa6ff; /* 品牌蓝在深底上偏暗，提亮一档保证对比度 */
}

body.dark .lang-sep {
  background: rgba(255, 255, 255, 0.12);
}

footer {
  width: 100%;
  background-color: var(--primary-color);
  color: white;
  text-align: center;
  padding: 10px 0;
  margin-top: auto; /* Pushes footer to the bottom */
  opacity: 0; /* Start hidden */
  transition: opacity 1s; /* Fade-in effect */
}

footer a {
  color: white;
  text-decoration: none;
}

.load-more {
  padding: 10px 20px;
  margin: 20px 0;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s, opacity 1s; /* Fade-in effect for the button */
  opacity: 0; /* Start hidden */
  display: flex;
  align-items: center;
  justify-content: center;
}

.load-more.loading {
  background-color: #a0a0a0; /* 灰色 */
  cursor: not-allowed;
}

.load-more.loading::after {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  content: "";
  border: 2px solid #fff;
  border-top: 2px solid transparent;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  margin-left: 10px;
  animation: spin 1s linear infinite;
}

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

/* Dark theme styles */
body.dark {
  background-color: #2d2d2d;
  color: #e0e0e0;
  --primary-color: #3d3d3d;
  --text-color: #e0e0e0;
  --bg-color: #121212;
  --shadow-color: rgba(0, 0, 0, 0.6);
}

body.dark header,
body.dark footer {
  background-color: #3d3d3d;
  border-bottom: 1px solid #4d4d4d;
}

body.dark .tag {
  background-color: #4d4d4d;
  color: #e0e0e0;
}

body.dark .modal {
  background-color: rgba(61, 61, 61, 0.9);
}

body.dark .modal-content {
  background-color: #4d4d4d;
}

/* 加载原图按钮：已收进弹层操作条 #meme-actions（meme-actions.js），不再 fixed 悬浮——
   原右下角 bottom:20 与自动滚动球重叠是历史遗留（见 MEMORY 多 fixed 重叠条目）。
   条内布局由 .meme-action-btn 提供，这里保留配色、状态与加载动画 */
.load-original-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.load-original-btn:hover {
  background-color: var(--primary-color-dark);
}

.load-original-btn:active {
  opacity: 0.85;
}

/* 按钮加载状态 */
.load-original-btn.loading {
  cursor: not-allowed;
  pointer-events: none;
}

.load-original-btn .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
  display: block;
}

.load-original-btn span {
  display: block;
  line-height: 1;
  white-space: nowrap;
}

/* 深色主题下的按钮样式 */
body.dark .load-original-btn {
  background-color: var(--primary-color);
  color: white;
}

body.dark .load-original-btn:hover {
  background-color: var(--primary-color-dark);
}

/* ========== 弹层操作条（meme-actions.js）========== */
/* 跟在弹层大图/story 之后普通流内布局，不悬浮——替代旧的两个右下 fixed 球。
   移动端单列全宽，按钮等分；桌面与 story 卡片同宽居中 */
.meme-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 90%;
  max-width: 700px;
  margin: 14px auto 0;
  justify-content: center;
}

.meme-actions[hidden] {
  display: none;
}

.meme-action-btn {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  background: var(--primary-color);
  color: #fff;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.meme-action-btn:hover {
  background: var(--primary-color-dark);
}

.meme-action-btn:active {
  opacity: 0.85;
}

.meme-action-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* 「生成分享图」在操作条里做次级视觉：主色实心留给下载/复制这两个保存路径 */
#share-card-btn.meme-action-btn {
  background: rgba(128, 128, 128, 0.25);
  color: #fff;
}

#share-card-btn.meme-action-btn:hover {
  background: rgba(128, 128, 128, 0.4);
}

body.dark #share-card-btn.meme-action-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #f0f0f0;
}

body.dark #share-card-btn.meme-action-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

@media (max-width: 600px) {
  .meme-actions {
    width: 92%;
  }
}

/* ========== 弹层操作条（meme-actions.js）========== */
/* 跟在弹层大图/story 之后普通流内布局，不悬浮——替代旧的两个右下 fixed 球。
   移动端单列全宽，按钮等分；桌面与 story 卡片同宽居中 */
.meme-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 90%;
  max-width: 700px;
  margin: 14px auto 0;
  justify-content: center;
}

.meme-actions[hidden] {
  display: none;
}

.meme-action-btn {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  background: var(--primary-color);
  color: #fff;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.meme-action-btn:hover {
  background: var(--primary-color-dark);
}

.meme-action-btn:active {
  opacity: 0.85;
}

.meme-action-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* 「生成分享图」在操作条里做次级视觉：主色实心留给下载/复制这两个保存路径 */
#share-card-btn.meme-action-btn {
  background: rgba(128, 128, 128, 0.25);
  color: #fff;
}

#share-card-btn.meme-action-btn:hover {
  background: rgba(128, 128, 128, 0.4);
}

body.dark #share-card-btn.meme-action-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #f0f0f0;
}

body.dark #share-card-btn.meme-action-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

@media (max-width: 600px) {
  .meme-actions {
    width: 92%;
  }
}

/* 搜索条 / 排序切换 / 回到顶部 */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 80%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 10px 10px;
}

body.has-role-chips .search-bar {
  /* 有 chips 时搜索条贴 header 下缘，chips 跟在它下面 */
  margin-top: 0;
}

.search-bar input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--shadow-color, rgba(0, 0, 0, 0.12));
  border-radius: 20px;
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 14px;
  outline: none;
}

.search-bar input:focus {
  border-color: var(--primary-color);
}

.sort-toggle {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--primary-color);
  border-radius: 20px;
  background: var(--bg-color);
  color: var(--primary-color);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.sort-toggle:hover {
  background: var(--primary-color);
  color: #fff;
}

.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 86px; /* 右下还有 50px 自动滚动球(bottom:20)，回顶球叠它上方 */
  z-index: 900;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.back-to-top[hidden] {
  display: none;
}

.back-to-top svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.back-to-top:active {
  transform: scale(0.94);
}

/* Loading animation */
#loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading::after {
  content: "";
  border: 4px solid var(--primary-color);
  border-top: 4px solid transparent;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  will-change: transform; /* 优化动画性能 */
}

#loading.hidden {
  display: none;
}

/* 断点高度与 h1 字号一一对应：header 用固定 height，内容必须能单行放下 */
@media (max-width: 600px) {
  header {
    height: 2.07em;
    padding: 10px 15px;
  }
  header h1 {
    font-size: 1.15em; /* 24px 时长标题会换行撑爆 header，移动端压到 ~18px 单行 */
  }
  header button {
    margin-right: 4px; /* 移动端省出横向空间给标题 */
  }
  /* 只留「梗鲸」两个字，把空间让给投稿按钮（完整站名仍在 DOM，不影响 SEO） */
  .brand-full {
    display: none;
  }
  .brand-short {
    display: inline;
  }
}

@media (min-width: 600px) and (max-width: 1200px) {
  header {
    height: 2.085em;
    padding: 15px 20px;
  }
  header h1 {
    font-size: 1.75em;
  }
  header button {
    margin-right: 40px;
  }
}

@media (min-width: 1200px) {
  header {
    height: 2.1em;
    padding: 20px 30px;
  }
  header h1 {
    font-size: 2em;
  }
  header button {
    margin-right: 50px;
  }
}

/* 1280 视口（13 寸笔记本常见宽度）下完整站名+投稿按钮会被切右侧，
   切短站名「梗鲸」让出空间。完整站名仍在 DOM，SEO 不受影响 */
@media (max-width: 1280px) {
  .brand-full {
    display: none;
  }
  .brand-short {
    display: inline;
  }
}

/* 浅色模式（--bg-color / --shadow-color 必须在 :root 定义：
   这两个变量被本文件开头的 body、header 直接使用，原先只在 .dark 里定义，
   导致浅色模式下 body 背景透明、header 阴影失效） */
:root {
  --primary-color: #4d6bfe; /* DeepSeek 品牌蓝主题色 */
  --primary-color-dark: #3a65c2; /* hover 加深 */
  --bg-color: #ffffff;
  --text-color: #1e232c;
  --shadow-color: rgba(0, 0, 0, 0.12);
}

/* 深色变量：合并到下面的 body.dark 块里（原 .dark 选择器特异性低，
   被 body.dark 覆盖，纯属冗余，删了省得误导后人） */

/* 使用变量替换原有颜色值 */
header, footer, .load-more {
    background-color: var(--primary-color);
}

/* 加载指示器样式 */
#temp-loading-msg {
    text-align: center;
    margin: 20px 0;
    padding: 10px;
    color: rgba(0, 0, 0, 0.65);
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 5px;
    animation: fadeInOut 1.5s infinite alternate;
}

@keyframes fadeInOut {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

/* 适配深色模式 */
body.dark #temp-loading-msg {
    color: #aaa;
    background-color: rgba(255, 255, 255, 0.05);
}

/* 通知系统样式 */
.notification-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  max-width: 300px;
}

.notification {
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateX(50px);
  transition: opacity 0.3s, transform 0.3s, top 0.3s;
  position: relative;
  word-wrap: break-word;
  max-width: 100%;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.notification.show {
  opacity: 1;
  transform: translateX(0);
}

.notification.fade-out {
  opacity: 0;
  transform: translateY(-10px);
}

/* 带加载图标的通知 */
.notification.with-spinner {
  padding-left: 16px; /* 减小左侧内边距，与普通通知一致 */
}

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

/* 深色模式下的通知样式 */
body.dark .notification {
  background-color: #1e1e1e; /* 改为不透明背景 */
  color: #f0f0f0;
  border: 1px solid rgba(80, 80, 80, 0.5); /* 添加边框 */
}

/* ========== 广告位 ========== */
#ad-banner-bottom {
  margin: 24px auto 12px;
  text-align: center;
  min-height: 50px;
}


/* Native Banner 穿插容器 */
.ad-native-wrap {
  margin: 12px 0;
  padding: 8px;
  border-radius: 8px;
  background: rgba(128,128,128,.06);
  overflow: hidden;
}
.ad-native-wrap > div[id^="container-"] { min-height: 120px; }

/* ========== 分享卡片 ========== */
/* 入口按钮 #share-card-btn 已收进弹层操作条（见上方 .meme-actions），旧 fixed 样式删除 */
.share-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  z-index: 20000;
  overflow: auto;
  padding: 20px;
}
.share-overlay.show { display: flex; align-items: center; justify-content: center; }
.share-box {
  position: relative;
  max-width: 92vw;
  text-align: center;
}
.share-box canvas {
  max-width: 100%;
  max-height: 76vh;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
/* 展示用的导出图：移动端长按它弹出「存储图像」 */
.share-box .share-img {
  max-width: 100%;
  max-height: 76vh;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  -webkit-touch-callout: default; /* 覆盖 body 的全局禁用，允许 iOS 长按保存 */
  -webkit-user-select: auto;
  user-select: auto;
}
.share-tip {
  color: rgba(255,255,255,.85);
  font-size: 13px;
  margin: 14px 0 10px;
}
.share-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.share-btn {
  display: inline-block;
  background: #4d6bfe;
  color: #fff;
  border: none;
  padding: 9px 26px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
}
.share-btn:active { opacity: .85; }
.share-close {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: none;
  padding: 8px 26px;
  border-radius: 18px;
  font-size: 13px;
  cursor: pointer;
}
