/* ============================================================
   亮色主题 —— 最后引入，覆盖所有 :root 变量
   站点默认是深色；亮色只在「系统偏好为亮」或用户手动切换时生效。
   手动切换由 ui.js 的页脚按钮写 localStorage('sd_theme')，
   页面 head 里的内联脚本在渲染前把 data-theme 设到 <html> 上，避免闪烁。
   ============================================================ */

/* 亮色变量集（dark 值 → light 值）。
   --pv2-* 是 public-v2.css 的卡片渐变/阴影，深色下靠黑影撑立体感，
   亮底上要换成浅灰渐变 + 更淡的影子，否则卡片会糊成一团。 */
html[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #eef2f7;
  --line: #e2e8f0;
  --line-2: #d3dce6;
  --text: #1c2532;
  --text-2: #101826;
  --muted: #5c6675;
  --dim: #78828f;
  --faint: #9aa3b0;
  --accent: #557d0a;
  --accent-dim: #456607;
  --accent-ink: #ffffff;
  --accent-rgb: 85, 125, 10;
  --shadow: 0 12px 32px rgba(16, 24, 40, 0.10);
  --ring: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.12);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.16);
  --pv2-edge: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --pv2-card: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  --pv2-card-2: linear-gradient(180deg, #f7f9fc 0%, #f2f5f9 100%);
  --pv2-shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06);
  --pv2-shadow-2: 0 12px 30px -16px rgba(16, 24, 40, 0.22), 0 2px 6px rgba(16, 24, 40, 0.08);
  --pv2-shadow-3: 0 26px 56px -26px rgba(16, 24, 40, 0.28), 0 4px 12px rgba(16, 24, 40, 0.10);
}

/* 跟随系统：系统偏好亮色、且用户没有明确选深色时生效 */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    --bg: #f5f7fa;
    --bg-elev: #ffffff;
    --card: #ffffff;
    --card-2: #eef2f7;
    --line: #e2e8f0;
    --line-2: #d3dce6;
    --text: #1c2532;
    --text-2: #101826;
    --muted: #5c6675;
    --dim: #78828f;
    --faint: #9aa3b0;
    --accent: #557d0a;
    --accent-dim: #456607;
    --accent-ink: #ffffff;
    --accent-rgb: 85, 125, 10;
    --shadow: 0 12px 32px rgba(16, 24, 40, 0.10);
    --ring: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.08);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.12);
    --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.16);
    --pv2-edge: inset 0 1px 0 rgba(255, 255, 255, 0.9);
    --pv2-card: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
    --pv2-card-2: linear-gradient(180deg, #f7f9fc 0%, #f2f5f9 100%);
    --pv2-shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06);
    --pv2-shadow-2: 0 12px 30px -16px rgba(16, 24, 40, 0.22), 0 2px 6px rgba(16, 24, 40, 0.08);
    --pv2-shadow-3: 0 26px 56px -26px rgba(16, 24, 40, 0.28), 0 4px 12px rgba(16, 24, 40, 0.10);
  }
}

/* 深色下个别组件的硬编码底色，亮色主题下会刺眼，这里定点校正 */
html[data-theme="light"] .match-item,
html[data-theme="light"] code.match-item {
  background: #f1f4f9;
}

/* 深色页面里「代码块」普遍是更深的黑底；亮色下换浅灰 */
html[data-theme="light"] pre,
html[data-theme="light"] .code-block,
html[data-theme="light"] .match-item code {
  background: #f1f4f9;
  color: #1c2532;
}

/* 顶栏/页脚若直接用了半透明白叠加（深色下提亮），亮色下反转成暗字 */
html[data-theme="light"] .topbar,
html[data-theme="light"] .footer {
  background: color-mix(in srgb, #ffffff 86%, transparent);
}

/* sniffer 面板等 shadow-DOM 组件读不到页面变量，亮色下维持深色即可（无需处理） */

/* ---- public-v2.css 里的硬编码深色，亮色下定点校正 ---- */
/* 首页大搜索框：深色玻璃拟态在白底上会糊成一坨 */
html[data-theme="light"] body:not(.admin-body) .search-hero {
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 30px -14px rgba(16, 24, 40, 0.18);
}
/* 标题渐变字：浅绿 → 深绿，保证白底上读得清 */
html[data-theme="light"] body:not(.admin-body) .hero h1 em {
  background: linear-gradient(100deg, #7fb01c 0%, var(--accent) 45%, #3f5c08 100%);
  -webkit-background-clip: text;
  background-clip: text;
}
/* 首页顶部柔光在白底上加重一点，否则 hero 显得空 */
html[data-theme="light"] body:not(.admin-body) .hero::before {
  background: radial-gradient(closest-side, rgba(var(--accent-rgb), 0.10), transparent 72%);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) body:not(.admin-body) .search-hero {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 30px -14px rgba(16, 24, 40, 0.18);
  }
  html:not([data-theme="dark"]) body:not(.admin-body) .hero h1 em {
    background: linear-gradient(100deg, #7fb01c 0%, var(--accent) 45%, #3f5c08 100%);
    -webkit-background-clip: text;
    background-clip: text;
  }
  html:not([data-theme="dark"]) body:not(.admin-body) .hero::before {
    background: radial-gradient(closest-side, rgba(var(--accent-rgb), 0.10), transparent 72%);
  }
}

/* ---------- P3：通知条 / 同步条 / 看板条形图 / 开发者卡片 ---------- */
html[data-theme="light"] body:not(.admin-body) .notice {
  background: #f2f7ec; border-color: #d7e3c4; color: #55702f;
}
html[data-theme="light"] body:not(.admin-body) .notice.warn {
  background: #faf4e6; border-color: #e6d9b8; color: #8a6d1f;
}
html[data-theme="light"] body:not(.admin-body) .notice.bad {
  background: #faeeee; border-color: #e5c4c4; color: #9c4444;
}
html[data-theme="light"] body:not(.admin-body) .sync-box {
  background: #f3f7ee; border-color: #cfe0bd;
}
html[data-theme="light"] body:not(.admin-body) .bar-track {
  background: #edf1ec; border: 1px solid #e0e6de;
}
html[data-theme="light"] body:not(.admin-body) .bar-label { color: #2a3138; }
html[data-theme="light"] body:not(.admin-body) .tk-once,
html[data-theme="light"] body:not(.admin-body) .wh-secret {
  background: #f6f9f0; border-color: #dbe7c9;
}
html[data-theme="light"] body:not(.admin-body) .tk-box code {
  background: #ffffff; border-color: #dfe5da; color: #4d6b1f;
}
html[data-theme="light"] body:not(.admin-body) .dev-doc pre,
html[data-theme="light"] body:not(.admin-body) .doc pre {
  background: #f6f8f5; border-color: #e2e6e0; color: #445062;
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) body:not(.admin-body) .notice { background: #f2f7ec; border-color: #d7e3c4; color: #55702f; }
  html:not([data-theme="dark"]) body:not(.admin-body) .notice.warn { background: #faf4e6; border-color: #e6d9b8; color: #8a6d1f; }
  html:not([data-theme="dark"]) body:not(.admin-body) .notice.bad { background: #faeeee; border-color: #e5c4c4; color: #9c4444; }
  html:not([data-theme="dark"]) body:not(.admin-body) .sync-box { background: #f3f7ee; border-color: #cfe0bd; }
  html:not([data-theme="dark"]) body:not(.admin-body) .bar-track { background: #edf1ec; border: 1px solid #e0e6de; }
  html:not([data-theme="dark"]) body:not(.admin-body) .bar-label { color: #2a3138; }
  html:not([data-theme="dark"]) body:not(.admin-body) .tk-once,
  html:not([data-theme="dark"]) body:not(.admin-body) .wh-secret { background: #f6f9f0; border-color: #dbe7c9; }
  html:not([data-theme="dark"]) body:not(.admin-body) .tk-box code { background: #ffffff; border-color: #dfe5da; color: #4d6b1f; }
  html:not([data-theme="dark"]) body:not(.admin-body) .dev-doc pre,
  html:not([data-theme="dark"]) body:not(.admin-body) .doc pre { background: #f6f8f5; border-color: #e2e6e0; color: #445062; }
}
