/* GoCMS 主题 Token —— 白天/夜间模式通过 [data-theme] 切换
 * 前台使用 GoManga 设计变量（--bg/--card/--brand 等），夜间模式覆盖为深色；
 * 后台继续使用 --color-* Token。禁止在组件中散落硬编码颜色。
 * 首访跟随系统 prefers-color-scheme，用户选择持久化于 localStorage（见 js/theme.js）。
 */
:root {
  color-scheme: light;

  /* GoManga 前台设计变量（白天：浅色 + 珊瑚红品牌色） */
  --bg: #f7f8fb;
  --card: #ffffff;
  --text: #222222;
  --muted: #737987;
  --line: #e9ecf2;
  --brand: #f45b69;
  --brand2: #ffb199;
  --hot: #e63946;
  --shadow: 0 8px 24px rgba(31, 41, 55, 0.07);

  /* 后台通用 Token（与前台品牌色同步） */
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-surface-alt: #eef0f3;
  --color-text: #202124;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-primary: #f45b69;
  --color-primary-contrast: #ffffff;
  --color-primary-hover: #e04856;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;

  /* GoManga 前台设计变量（夜间：柔和深蓝灰，GitHub Dark 风格；
   * 背景与卡片拉开一档层次，文本用柔和灰白降低刺眼对比） */
  --bg: #0d1117;
  --card: #161b22;
  --text: #e6edf3;
  --muted: #8b949e;
  --line: #2d333b;
  --brand: #ff7b72;
  --brand2: #ff9b8a;
  --hot: #f85149;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);

  /* 后台通用 Token（夜间） */
  --color-bg: #0d1117;
  --color-surface: #161b22;
  --color-surface-alt: #21262d;
  --color-text: #e6edf3;
  --color-text-muted: #8b949e;
  --color-border: #2d333b;
  --color-primary: #ff7b72;
  --color-primary-contrast: #ffffff;
  --color-primary-hover: #ff938a;
  --color-success: #3fb950;
  --color-warning: #d29922;
  --color-danger: #f85149;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* 前台 header 工具区：垂直居中（修复“我的/退出”漂移） */
.tools {
  align-items: center;
}

.tools a,
.logout-form button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 4px;
  line-height: 1;
}

/* 主题切换按钮（前台 header.tools 内，SVG 图标） */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.theme-toggle:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* 退出按钮（header.tools 内的 form） */
.logout-form { display: inline; }
.logout-form button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0 4px;
}
.logout-form button:hover { color: var(--brand); }

/* 尊重用户减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========== 夜间模式：覆盖 GoManga style.css 中的硬编码浅色 ========== */
[data-theme="dark"] .top {
  background: rgba(22, 27, 34, 0.92);
}

[data-theme="dark"] :is(.section, .filter, .catalog, .comic-profile, .chapters a,
  .rank, .rank-board, .rising-board, .rank-more .rank, .rank-mobile-tabs, .chapter-end, .search-box,
  .auth-box, .player-box, .eps-box, .user-card, .fav-grid .fav-card, .push,
  .slider .slide, .chapter-drawer aside) {
  background: var(--card);
}

[data-theme="dark"] :is(.filter-options a, .pager a, .pager span, .chapter-sort button,
  .sort-tab, .fav-tool, .eps-grid a, .line-tabs button) {
  background: var(--card);
  color: var(--text);
}

[data-theme="dark"] :is(input, select, textarea) {
  background: var(--card);
  color: var(--text);
  border-color: var(--line);
}

[data-theme="dark"] .search input {
  background: var(--bg);
  color: var(--text);
}

/* 夜间残留浅色背景覆盖：style.css 中的硬编码浅色在深色主题下会刺眼，
 * 统一替换为卡片/背景色或对应深色调，保证明暗层次柔和 */
[data-theme="dark"] .search {
  background: var(--bg);
}

[data-theme="dark"] :is(.chips a, .zone a, .profile-tags a, .profile-latest, .pager-input) {
  background: var(--card);
}

[data-theme="dark"] :is(.car-btn:hover, .outline, .profile-title span) {
  background: var(--card);
  color: var(--brand);
}

[data-theme="dark"] .chapter-more button {
  background: var(--card);
  color: var(--text);
}

[data-theme="dark"] .num {
  background: #3a2e1c;
  color: #e8a33d;
}

[data-theme="dark"] .chips a:hover {
  background: #14261d;
  border-color: #2f6b4f;
}

[data-theme="dark"] :is(.tab-nav button:hover, .tab-nav button.active) {
  background: #3b1d24;
}

[data-theme="dark"] .slider {
  background: linear-gradient(120deg, #16201b, #1e1a14 55%, #23161a);
}

[data-theme="dark"] :is(.page-img, .chapter-canvas .page-img) {
  background: linear-gradient(180deg, #161b22, #0d1117);
}

[data-theme="dark"] :is(.chapter-info, .page-buttons a, .doc) {
  background: var(--card);
}

[data-theme="dark"] .drawer-head button {
  background: var(--card);
  color: var(--text);
}

[data-theme="dark"] .foot {
  background: var(--card);
  border-top: 1px solid var(--line);
}

[data-theme="dark"] .bottom-nav {
  background: var(--card);
  border-top: 1px solid var(--line);
}

[data-theme="dark"] .crumb a,
[data-theme="dark"] .foot a,
[data-theme="dark"] .bottom-nav a,
[data-theme="dark"] .profile-desc,
[data-theme="dark"] .profile-meta,
[data-theme="dark"] .block-title {
  color: var(--text);
}

[data-theme="dark"] .profile-meta b,
[data-theme="dark"] .filter-title span,
[data-theme="dark"] .empty-state,
[data-theme="dark"] .result-count {
  color: var(--muted);
}

[data-theme="dark"] .filter-row .fold-btn,
[data-theme="dark"] .section-head .more {
  color: var(--brand);
}

[data-theme="dark"] :is(.rank-board h2, .work strong, .rising-list strong,
  .rank-more .rank h2, .rank-card h3, .rank-row.head) {
  color: var(--text);
}

[data-theme="dark"] :is(.rank-board, .rising-board, .rank-more .rank, .rank-mobile-tabs) {
  border-color: var(--line);
}

/* 用户中心顶部 tab 导航 */
.user-tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  margin: 20px auto;
  max-width: 560px;
}

.user-card {
  width: 100%;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.user-form {
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}
.user-tabs a {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: all .2s;
}
.user-tabs a.active,
.user-tabs a:hover {
  background: var(--brand);
  color: #fff;
}

/* 影片卡片角标（最新章节）：覆盖 GoManga 原 .badge 的 display:none（书架角标样式），
 * 定位到封面右上角；不影响底部导航等其他 .badge 用途 */
.book .badge {
  display: block;
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  padding: 2px 8px;
  min-width: 0;
  max-width: calc(100% - 12px);
  height: auto;
  line-height: 1.4;
  border-radius: 4px;
  /* 限制单行显示，超长省略 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 去掉影片卡片封面底部黑半透明标题条（GoManga .thumb:after 伪元素） */
.book .thumb:after {
  display: none;
}

/* header "我的" 下拉菜单 */
.user-menu { position: relative; }
.user-menu-trigger {
  background: none; border: none; cursor: pointer;
  color: var(--text); font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 6px;
}
.user-menu-trigger:hover { color: var(--brand); }
.user-menu-panel {
  display: none;
  position: absolute; right: 0; top: 100%; z-index: 50;
  min-width: 160px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow-md);
}
.user-menu:hover .user-menu-panel,
.user-menu:focus-within .user-menu-panel { display: block; }
.user-menu-panel a,
.user-menu-panel button {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: none; background: none; cursor: pointer;
  color: var(--text); font: inherit; font-size: 14px; border-radius: 6px;
}
.user-menu-panel a:hover,
.user-menu-panel button:hover { background: var(--bg); color: var(--brand); }

/* 屏幕阅读器/SEO 隐藏类：视觉隐藏但保留给爬虫与辅助技术 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* 详情页封面 <img>（SEO：图片可被搜索引擎索引）适配 .cover 布局 */
img.cover {
  display: block;
  object-fit: cover;
  object-position: center;
}
