/* ═══════════════════════════════════════════════════
   研途 · 昼夜主题
   [data-theme="light"] 白天（默认，沿用 workspace 浅色）
   [data-theme="dark"]  夜间：深蓝黑底 / 浅字 / 蓝辅
   ═══════════════════════════════════════════════════ */

/* ── 白天令牌（显式声明，避免依赖加载顺序）──────────── */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fb; --bg-2: #eef2f8;
  --paper: #ffffff; --paper-solid: #ffffff; --paper-2: #f3f6fb;
  --ink: #111827; --ink-2: #4b5563; --ink-3: #5c6b80; --ink-4: #5c6b80;
  --line: #e3e8f0; --line-2: #eef1f5;
  --blue: #2563eb; --blue-ink: #1d4ed8;
  --blue-soft: #edf3ff; --blue-line: #c7d8fd;
  --red: #dc2626; --red-soft: #fff1f2; --red-line: #fecdd3;
  --sh-1: 0 2px 4px rgba(23,42,73,.03);
  --sh-2: 0 8px 24px rgba(23,42,73,.06);
  --sh-3: 0 20px 70px rgba(23,42,73,.16);
}

/* ── 夜间令牌 ─────────────────────────────────────── */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080b12; --bg-2: #0d111a;
  --paper: #111723; --paper-solid: #111723; --paper-2: #171e2b;
  --ink: #eef2f8; --ink-2: #b9c3d1; --ink-3: #8c98a9; --ink-4: #8995a6;
  --line: #242e3d; --line-2: #1b2330;
  --blue: #3b82f6; --blue-ink: #93b8ff;
  --blue-soft: rgba(59,130,246,.16); --blue-line: rgba(96,150,246,.38);
  --red: #f87171; --red-soft: rgba(248,113,113,.13); --red-line: rgba(248,113,113,.32);
  --sh-1: 0 2px 4px rgba(0,0,0,.4);
  --sh-2: 0 8px 24px rgba(0,0,0,.5);
  --sh-3: 0 20px 70px rgba(0,0,0,.65);
}

/* ── 全站色彩过渡（切换时的形变主体）────────────────── */
html[data-theme] body,
html[data-theme] .workspace-sidebar,
html[data-theme] .topbar,
html[data-theme] .card,
html[data-theme] .panel,
html[data-theme] .data-block,
html[data-theme] .wh-hero,
html[data-theme] .wh-panel,
html[data-theme] .wh-tool,
html[data-theme] .wh-resume,
html[data-theme] .wh-search,
html[data-theme] .workspace-search,
html[data-theme] .cmd-box,
html[data-theme] .filters,
html[data-theme] .table-wrap,
html[data-theme] .me-card,
html[data-theme] .ft-card,
html[data-theme] .kv,
html[data-theme] .today,
html[data-theme] .tl-bar,
html[data-theme] .btn,
html[data-theme] .tag,
html[data-theme] .season-chip {
  transition: background-color .42s var(--ease-io, ease),
              color .42s var(--ease-io, ease),
              border-color .42s var(--ease-io, ease),
              box-shadow .42s var(--ease-io, ease);
}

/* 白天：底部动态网格关掉（浅色底不需要） */
html[data-theme="light"] .grid-bg,
html[data-theme="light"] .grid-glow { opacity: 0; }

/* 夜间：把动态网格与微光请回来，压低亮度 */
html[data-theme="dark"] .grid-bg { opacity: 1; }
html[data-theme="dark"] .grid-bg::before {
  background-image:
    linear-gradient(rgba(120,160,220,.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,160,220,.055) 1px, transparent 1px);
}
html[data-theme="dark"] .grid-glow { opacity: .65; }
html[data-theme="dark"] body { background: var(--bg); }

/* ── 切换按钮 ─────────────────────────────────────── */
.theme-toggle {
  position: relative; display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper); color: var(--ink-2);
  font: inherit; font-size: 12px; font-weight: 500; letter-spacing: 0;
  cursor: pointer; overflow: hidden;
  transition: background-color 180ms, border-color 180ms, color 180ms, transform 160ms;
}
.theme-toggle:hover { border-color: var(--blue-line); color: var(--blue-ink); transform: translateY(-1px); }
.theme-toggle:active { transform: scale(.96); }
.theme-toggle:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.theme-toggle .ic {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform .5s var(--spring, ease), opacity .32s ease, position .32s ease;
}
/* 白天显示太阳（点它变夜间），夜间显示月亮 */
.theme-ic-moon { display: none; }
html[data-theme="dark"] .theme-ic-sun { display: none; }
html[data-theme="dark"] .theme-ic-moon { display: block; }
.theme-toggle:hover .ic { transform: rotate(35deg) scale(1.08); }

/* ── 夜间：覆盖 workspace 的硬编码浅色 ─────────────── */
html[data-theme="dark"] .workspace-sidebar { background: var(--paper); }
html[data-theme="dark"] .workspace-nav .nav-group a { color: var(--ink-3); }
html[data-theme="dark"] .workspace-nav .nav-group a:hover { background: var(--paper-2); color: var(--ink); }
html[data-theme="dark"] .workspace-nav .nav-group a.on { background: var(--blue-soft); color: var(--blue-ink); }
html[data-theme="dark"] .sidebar-guide { background: var(--paper-2); }
html[data-theme="dark"] .sidebar-guide:hover { background: var(--blue-soft); }
html[data-theme="dark"] .topbar { background: rgba(13,17,26,.92); }
html[data-theme="dark"] .topbar.scrolled { box-shadow: 0 3px 16px rgba(0,0,0,.45); }
html[data-theme="dark"] .workspace-search { background: var(--paper-2); color: var(--ink-3); }
html[data-theme="dark"] .workspace-search:hover { background: var(--paper); border-color: var(--blue-line); }
html[data-theme="dark"] .workspace-search kbd { border-color: var(--line); color: var(--ink-4); }
html[data-theme="dark"] .season-chip { background: transparent; color: var(--ink-3); }
html[data-theme="dark"] .season-chip:hover { background: var(--blue-soft); color: var(--blue-ink); }
html[data-theme="dark"] .topbar-act .mm-free { background: var(--paper); color: var(--ink); }
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .tag { background: var(--paper); color: var(--ink-2); }
html[data-theme="dark"] .btn-dark { background: #2a3648; color: #fff; }
html[data-theme="dark"] .card,
html[data-theme="dark"] .filters,
html[data-theme="dark"] .table-wrap { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .table-wrap th { background: var(--paper-2); }
html[data-theme="dark"] .mark-ink { background: var(--blue); color: #fff; }
html[data-theme="dark"] .cmd-box { background: var(--paper); border-color: var(--line); color: var(--ink); }
html[data-theme="dark"] .yt-toast { color: #fff; background: #26354b; border-color: #26354b; }
html[data-theme="dark"] .mobile-dock { background: rgba(13,17,26,.96); border-color: var(--line); }
html[data-theme="dark"] .workspace-noscript { background: var(--paper); border-color: var(--line); color: var(--ink); }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { color-scheme: dark; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--ink-4); }

/* ── 夜间：首页工作台硬编码色 ─────────────────────── */
html[data-theme="dark"] .wh-hero,
html[data-theme="dark"] .wh-panel,
html[data-theme="dark"] .wh-tool,
html[data-theme="dark"] .wh-resume { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .wh-search { background: var(--paper-2); border-color: var(--line); }
html[data-theme="dark"] .wh-search:focus-within { border-color: var(--blue-line); }
html[data-theme="dark"] .wh-task-check,
html[data-theme="dark"] .wh-agenda-dot { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .wh-task { background: var(--paper-2); border-color: transparent; }
html[data-theme="dark"] .wh-task:hover { background: #1d2635; border-color: var(--blue-line); }
html[data-theme="dark"] .wh-task-check { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .wh-task-text { color: var(--ink-2); }
html[data-theme="dark"] .wh-task.is-done { background: var(--blue-soft); }
html[data-theme="dark"] .wh-agenda-dot { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .wh-agenda-item a:hover { background: var(--paper-2); }
html[data-theme="dark"] .wh-panel-foot,
html[data-theme="dark"] .wh-agenda-note { color: var(--ink-4); }
html[data-theme="dark"] .wh-route-node.is-past i { background: var(--blue); border-color: var(--blue); color: #fff; }
html[data-theme="dark"] .wh-countdown { background: linear-gradient(135deg, #1d4ed8, #2563eb); }
html[data-theme="dark"] .wh-route-line { background: var(--line); }
html[data-theme="dark"] .wh-route-node.is-past span,
html[data-theme="dark"] .wh-route-node.is-next span { color: var(--ink-2); }
html[data-theme="dark"] .wh-panel-head h3,
html[data-theme="dark"] .wh-tool b { color: var(--ink); }
html[data-theme="dark"] .wh-tool small,
html[data-theme="dark"] .wh-panel-head small { color: var(--ink-3); }

/* ── 夜间：通用模块里的浅色面 ─────────────────────── */
html[data-theme="dark"] .data-block { background: linear-gradient(180deg, rgba(59,130,246,.10), rgba(255,255,255,.012)); border-color: var(--blue-line); }
html[data-theme="dark"] .data-block-none { background: var(--paper-2); border-color: var(--line); }
html[data-theme="dark"] .data-row:hover { background: rgba(255,255,255,.05); }
html[data-theme="dark"] .data-src { color: var(--ink-4); }
html[data-theme="dark"] .data-src.is-ocr { color: var(--red); border-color: var(--red-line); background: var(--red-soft); }
html[data-theme="dark"] .kv { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .kv-none { color: var(--ink-4) !important; }
html[data-theme="dark"] .today { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .ft-card,
html[data-theme="dark"] .me-card { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .ft-real { background: var(--blue-soft); color: var(--blue-ink); }
html[data-theme="dark"] .ft-lock { background: var(--paper-2); border-color: var(--line); }
html[data-theme="dark"] .ft-warn { background: var(--red-soft); border-color: var(--red-line); }
html[data-theme="dark"] .ft-verdict { background: var(--paper); border-color: var(--line); }
html[data-theme="dark"] .cmd { background: rgba(4,6,10,.72); }
html[data-theme="dark"] .cmd-head { border-color: var(--line); }
html[data-theme="dark"] .modal,
html[data-theme="dark"] .mm-modal { background: var(--paper); color: var(--ink); }

/* ── 原生 View Transition：让新旧两层叠着扩散，不要默认交叉淡入 ── */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* 不支持 View Transitions 时的柔和淡入 */
@keyframes themeFade { from { opacity: .55; } to { opacity: 1; } }
html.theme-fallback body { animation: themeFade .42s ease both; }

/* 尊重系统「减少动态效果」 */
@media (prefers-reduced-motion: reduce) {
  html[data-theme] body,
  html[data-theme] .workspace-sidebar,
  html[data-theme] .topbar,
  html[data-theme] .card,
  html[data-theme] .panel,
  html[data-theme] .btn,
  html[data-theme] .tag { transition: none !important; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none !important; }
}
