/**
 * 站点公用样式：三个前台页面共享的变量、reset、页头、导航、搜索框、页脚。
 * 页面专有样式（首页 hero/卡片、列表页侧栏/行、文章页正文等）仍留在各页 <style> 内。
 * 本文件由 <link> 引入，加载顺序在页面内联样式之前，页面可覆盖此处规则。
 */

:root {
  --bg: #0d1117;
  --card: #161b22;
  --border: #21262d;
  --text: #e6edf3;
  --text-bright: #f0f6fc;
  --text-muted: #8b949e;
  --accent: #2f81f7;
  --accent-light: #58a6ff;
  --accent-grad: linear-gradient(135deg, #1e6ff0 0%, #38bdf8 100%);
  --rank-1: #f85149;
  --rank-2: #f0883e;
  --rank-3: #d29922;
  --tag-bg: rgba(47, 129, 247, 0.12);
  --tag-border: rgba(56, 139, 253, 0.35);
  /* 主题相关补充变量（明暗两套都要定义） */
  --bg-grad: linear-gradient(180deg, #0d1117 0%, #10151d 100%);
  --header-bg: rgba(13, 17, 23, 0.85);
  --overlay-soft: rgba(1, 4, 9, 0.55);
  --shadow-drawer: 0 -12px 40px rgba(0, 0, 0, 0.5), 0 0 0 9999px var(--overlay-soft);
  --hero-grad: linear-gradient(90deg, rgba(8,12,24,0.92) 0%, rgba(8,12,24,0.72) 38%, rgba(8,12,24,0.1) 70%, rgba(8,12,24,0) 100%);
  --cat-chip-bg: rgba(13, 17, 23, 0.78);
  --hover-bg: rgba(177, 186, 196, 0.08);
  --hover-strong: rgba(177, 186, 196, 0.1);
  --input-bg: var(--bg);
  --body-text-2: #b6c2cf;
  --body-text-3: #c3d1e0;
  --faint: #6e7681;
  --focus-ring: rgba(47, 129, 247, 0.15);
  --link-soft: #a5c8ff;      /* 标签/软链接文字（深底浅蓝） */
  --link-soft-hover: #dbeaff;
  --chip-text: #cde4ff;      /* 角标/徽章文字（深底浅蓝） */
}

/* ===== 浅色主题：html[data-theme="light"] ===== */
html[data-theme="light"] {
  --bg: #f6f8fa;
  --card: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --text-bright: #0969da;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-light: #0969da;
  --accent-grad: linear-gradient(135deg, #0969da 0%, #218bff 100%);
  --rank-1: #cf222e;
  --rank-2: #bc4c00;
  --rank-3: #9a6700;
  --tag-bg: rgba(9, 105, 218, 0.08);
  --tag-border: rgba(9, 105, 218, 0.35);
  --bg-grad: linear-gradient(180deg, #ffffff 0%, #f6f8fa 100%);
  --header-bg: rgba(255, 255, 255, 0.88);
  --overlay-soft: rgba(31, 35, 40, 0.45);
  --shadow-drawer: 0 -12px 40px rgba(31, 35, 40, 0.18), 0 0 0 9999px var(--overlay-soft);
  --hero-grad: linear-gradient(90deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.78) 38%, rgba(255,255,255,0.15) 70%, rgba(255,255,255,0) 100%);
  --cat-chip-bg: rgba(255, 255, 255, 0.85);
  --hover-bg: rgba(31, 35, 40, 0.05);
  --hover-strong: rgba(31, 35, 40, 0.07);
  --input-bg: #ffffff;
  --body-text-2: #424a53;
  --body-text-3: #57606a;
  --faint: #8c959f;
  --focus-ring: rgba(9, 105, 218, 0.18);
  --link-soft: #0969da;
  --link-soft-hover: #0757ba;
  --chip-text: #0a5bd3;
  color-scheme: light;
}
html[data-theme="dark"], html:not([data-theme]) { color-scheme: dark; }

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    background-image: var(--bg-grad);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.25s ease, color 0.25s ease;
  }
a { text-decoration: none; color: inherit; }
img { display: block; }
button { font-family: inherit; }
.header {
    position: sticky; top: 0; z-index: 100;
    background: var(--header-bg);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
.header-inner {
    max-width: 1280px; margin: 0 auto; padding: 0 24px;
    height: 64px; display: flex; align-items: center; gap: 20px;
  }
.logo {
    display: flex; align-items: center; gap: 10px;
    font-size: 20px; font-weight: 700; color: var(--text-bright); white-space: nowrap;
  }
.logo-icon {
    width: 34px; height: 34px; border-radius: 9px;
    background: var(--accent-grad);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 16px rgba(47, 129, 247, 0.45);
  }
.logo-icon svg { width: 20px; height: 20px; }
.nav { display: flex; align-items: center; gap: 0; flex: 1; min-width: 0; overflow: hidden; }
.nav a {
    position: relative; padding: 8px 12px; font-size: 15px;
    color: var(--text-muted); border-radius: 8px;
    white-space: nowrap; flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
  }
.nav a:hover { color: var(--text-bright); background: var(--hover-bg); }
.nav a.active { color: var(--accent-light); font-weight: 600; }
.nav a.active::after {
    content: ""; position: absolute; left: 14px; right: 14px; bottom: -14px;
    height: 3px; border-radius: 3px 3px 0 0; background: var(--accent-grad);
  }
.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.search-box {
    display: flex; align-items: center; gap: 8px;
    width: 260px; min-width: 140px; height: 38px; padding: 0 14px;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    color: var(--text-muted);
    transition: border-color 0.2s, box-shadow 0.2s;
  }
.search-box:focus-within {
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring);
  }
.search-box input {
    flex: 1; background: transparent; border: none; outline: none;
    color: var(--text); font-size: 13px; min-width: 0;
  }
.search-box input::placeholder { color: var(--faint); }
.icon-btn {
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; border-radius: 8px;
    color: var(--text-muted); cursor: pointer;
    transition: color 0.2s, background 0.2s;
  }
.icon-btn:hover { color: var(--text-bright); background: var(--hover-strong); }
/* 语言切换按钮：桌面与抽屉共用 .lang-btn */
.lang-btn {
    min-width: 38px; height: 38px; padding: 0 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; letter-spacing: 0.3px;
  }
.mobile-drawer .drawer-lang {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 10px 12px; margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }
.mobile-drawer .drawer-lang-label { font-size: 13px; color: var(--text-muted); }
.mobile-drawer .drawer-lang-btn {
    width: auto; height: 34px; padding: 0 14px;
    background: var(--tag-bg); border: 1px solid var(--tag-border); border-radius: 999px;
    color: var(--accent-light);
  }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent-grad);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  }
.main { max-width: 1280px; margin: 0 auto; padding: 24px 24px 60px; }
.footer { border-top: 1px solid var(--border); padding: 28px 24px; text-align: center; font-size: 13px; color: var(--faint); }

/* ===== 移动端导航（右下角悬浮 FAB + 底部抽屉）=====
   桌面端 .menu-btn 隐藏；≤860px 显示悬浮按钮，菜单从底部滑出。
   注意：按钮/抽屉必须放 body 层——.header 的 backdrop-filter 会使
   内部 position:fixed 相对 header 定位，FAB 会被困在头部。 */
.menu-btn {
    display: none;
    position: fixed; right: 18px; bottom: 22px; z-index: 300;
    width: 52px; height: 52px;
    align-items: center; justify-content: center;
    background: var(--accent-grad);
    border: none; border-radius: 50%;
    color: #fff; cursor: pointer;
    box-shadow: 0 6px 22px rgba(47, 129, 247, 0.5), 0 2px 8px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
  }
.menu-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(47, 129, 247, 0.6), 0 2px 8px rgba(0, 0, 0, 0.35); }
.menu-btn:active { transform: scale(0.94); }
.menu-btn svg { width: 22px; height: 22px; pointer-events: none; }
/* 图标随开合切换：汉堡 ↔ 关闭 */
.menu-btn .ico-close { display: none; }
.menu-btn[aria-expanded="true"] .ico-open { display: none; }
.menu-btn[aria-expanded="true"] .ico-close { display: block; }
.mobile-drawer {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 299;
    background: var(--bg);
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow-drawer);
    max-height: 72vh; overflow-y: auto;
    padding: 10px 16px calc(22px + env(safe-area-inset-bottom, 0px));
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.28s ease, visibility 0.28s;
  }
.mobile-drawer.open { transform: translateY(0); visibility: visible; }
/* 顶部抓手 */
.mobile-drawer::before {
    content: ""; display: block;
    width: 40px; height: 4px; border-radius: 2px;
    background: #30363d; margin: 4px auto 10px;
  }
.mobile-drawer .drawer-search {
    display: flex; align-items: center; gap: 8px;
    width: 100%; height: 42px; padding: 0 14px; margin: 2px 0 12px;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  }
.mobile-drawer .drawer-search input {
    flex: 1; background: transparent; border: none; outline: none;
    color: var(--text); font-size: 14px; min-width: 0;
  }
.mobile-drawer .drawer-search input::placeholder { color: var(--faint); }
.mobile-drawer .drawer-search svg { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.mobile-drawer nav { display: flex; flex-direction: column; gap: 2px; padding-bottom: 8px; }
.mobile-drawer nav a {
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 10px; font-size: 15px; color: var(--text);
    border-radius: 10px;
    transition: background 0.2s, color 0.2s;
  }
.mobile-drawer nav a:hover, .mobile-drawer nav a:active { background: var(--hover-bg); color: var(--text-bright); }
.mobile-drawer nav a.active { color: var(--accent-light); font-weight: 600; background: var(--tag-bg); }
.mobile-drawer nav a.active::after { display: none; }

/* ===== 图片防溢出兜底：任何图片都不许把布局撑破 ===== */
.card-cover img, .row-cover img, .rank-thumb img, .rel-thumb img,
.hero-bg, .promo-bg, .promo-brain { max-width: 100%; }
.art-cover {
    display: block; width: 100%; height: auto;
    max-width: 100%; border-radius: 12px; margin-bottom: 28px;
    border: 1px solid rgba(56, 139, 253, 0.25);
  }

/* ===== 窄屏适配策略 =====
   桌面导航（logo+8项+搜索框+按钮组）中英文全宽需要 ~1140px，
   1240px 以下先压缩搜索框与内边距；1080px 以下不再硬塞——
   整体收进右下角 FAB + 底部抽屉（中英文统一断点，避免省略号截断）。 */
@media (max-width: 1240px) {
  .header-inner { gap: 14px; }
  .search-box { width: 190px; }
  .nav a { padding: 8px 9px; font-size: 14px; }
}
/* 英文界面：搜索框收窄给导航让路 */
html[data-i18n="en"] .search-box { width: 200px; }
@media (max-width: 1240px) {
  html[data-i18n="en"] .search-box { width: 150px; }
}
/* ≤1080px：导航/搜索框/头部按钮全部收进抽屉 */
@media (max-width: 1080px) {
  .nav, .search-box, .header-right .icon-btn, .header-right .avatar { display: none; }
  .menu-btn { display: flex; }
}
@media (max-width: 860px) {
  /* 布局保险：杜绝任何子内容把页面撑出横向滚动 */
  html, body { overflow-x: hidden; }
  .main { padding-left: 16px; padding-right: 16px; }
}
@media (min-width: 1081px) {
  .mobile-drawer { display: none; }
}

/* ===== 广告位（server/ads.js 渲染，空位不输出容器）===== */
.ad-slot { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
.side-col .ad-slot, .sidebar .ad-slot { margin: 0 0 18px; }
.ad-item { position: relative; overflow: hidden; border-radius: 12px; border: 1px solid var(--border); background: var(--card); }
.ad-item:not(.ad-code) > a { display: block; color: inherit; text-decoration: none; }
.ad-item:not(.ad-code) img { display: block; width: 100%; height: auto; }
.ad-caption { display: block; padding: 8px 12px; font-size: 13px; color: var(--text-muted); }
.ad-label {
  position: absolute; top: 6px; right: 6px; z-index: 2; padding: 1px 6px;
  font-size: 11px; line-height: 16px; color: #fff; background: rgba(0, 0, 0, 0.45); border-radius: 4px;
  pointer-events: none;
}

/* 原生卡片代码保留自身边框、配色与角标。 */
.ad-item.ad-code { overflow:visible; border:0; background:transparent; border-radius:0; }
.ad-code:has(.ad-tag) > .ad-label { display:none; }
@media (min-width:1001px) {
  .side-col .ad-article-sidebar { position:sticky; top:88px; }
  .ad-article-sidebar .ad-side { position:static; }
}
