/* ============================================================
 * theme-toggle.css —— 主题系统：根底色 + 深/浅切换按钮
 * ============================================================
 * 职责（就三件事，别往里塞别的）：
 *   1. `html` 自身的底色 —— 兜住 overscroll / 橡皮筋区
 *      · 深色那支在这里定义；浅色那支在 theme-light.css（成对，别拆）
 *   2. 切换按钮 `.theme-toggle` 的外观 + 太阳/月亮交叉动画
 *   3. 浅色态下按钮的配色
 *
 * 加载位置：所有基础样式之后、theme-light.css 之前/之后皆可
 *          （本文件与主题覆盖层没有选择器重叠，顺序不影响结果）。
 *
 * 🔴 约束：
 *   · 尺寸一律 px（`html{font-size:14px}` 会把 rem 算错）
 *   · 按钮放进 `.header`，所以**不能**带 padding/margin —— 否则顶栏高度被撑高
 *   · 本项目深度依赖「JS 写过的 style 属性要用 !important 才能覆盖」这条规律；
 *     本文件不写任何内联 style，无需 !important
 * ============================================================ */

/* ------------------------------------------------------------
 * §1 根底色
 * ------------------------------------------------------------
 * 只写 body 的话，手机端下拉（iOS 橡皮筋）和桌面端「拉到顶/底」会露出
 * html 的默认白底 —— 深色主题下就是一条刺眼的白边。
 * color-scheme 一并声明，让滚动条 / 表单控件 / 浏览器 UI 跟着走。
 * 浅色对应规则在 theme-light.css 的 §0。
 * ---------------------------------------------------------- */
html {
  background: #0f0f1a;
  color-scheme: dark;
}

/* ------------------------------------------------------------
 * §2 切换按钮
 * ---------------------------------------------------------- */
.theme-toggle {
  /* 与 .header-right 完全同尺寸，保证顶栏 52px 不变 */
  width: 32px;
  height: 32px;
  flex-shrink: 0;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;

  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  border-radius: 50%;

  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s ease, color .2s ease, transform .12s ease;
}
.theme-toggle:active { transform: scale(.88); }

/* 两个图标叠在同一位置，靠 opacity + rotate 做交叉切换 */
.theme-toggle .tt-ico {
  position: absolute;
  width: 18px;
  height: 18px;
  display: block;
  transition: opacity .28s ease, transform .5s cubic-bezier(.2, 0, 0, 1);
  will-change: opacity, transform;
}

/* 默认（深色）：显示太阳 —— 点一下「变亮」，是符合直觉的方向 */
.theme-toggle .tt-sun  { opacity: 1; transform: rotate(0deg)   scale(1); }
.theme-toggle .tt-moon { opacity: 0; transform: rotate(-75deg) scale(.45); }

/* 浅色：翻过来 */
html.theme-light body .theme-toggle .tt-sun  { opacity: 0; transform: rotate(75deg) scale(.45); }
html.theme-light body .theme-toggle .tt-moon { opacity: 1; transform: rotate(0deg) scale(1); }

/* 浅色态的按钮配色（跟着顶栏文字走，不抢视线） */
html.theme-light body .theme-toggle { color: #6f7d88; }

/* 指针设备 hover 反馈 */
@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover {
    background: rgba(255, 255, 255, .10);
    color: #fff;
  }
  html.theme-light body .theme-toggle:hover {
    background: rgba(23, 33, 43, .07);
    color: #17212b;
  }
}

/* 键盘可达性：焦点环。深色那支在这里，浅色那支已在 theme-light.css 收口 */
.theme-toggle:focus-visible {
  outline: 2px solid rgba(99, 102, 241, .85);
  outline-offset: 2px;
}

/* 子页面顶栏里略微小一号，避免比 🏠/📋 抢眼 */
.subpage-topbar .theme-toggle { font-size: 17px; }

/* PC 断点下 style.css 把 .header-right 放大到 36×36，按钮要跟上才齐
   （实测：1440 下 .header-right = 36×36，按钮若还是 32 会显得矮一截）
   子页面顶栏的 .header-right 仍是 32，所以第二条把它压回来 ——
   两条特异性相同，靠「后写者胜」生效，不要调换顺序。 */
@media (min-width: 1024px) {
  .header .theme-toggle { width: 36px; height: 36px; }
  .subpage-topbar .theme-toggle { width: 32px; height: 32px; }
}

/* 尊重系统的「减少动效」偏好 —— 关掉旋转，只留淡入淡出 */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle .tt-ico { transition: opacity .15s linear; }
  .theme-toggle .tt-sun,
  .theme-toggle .tt-moon { transform: none !important; }
  .theme-toggle:active { transform: none; }
}

/* ------------------------------------------------------------
 * §3 切换动画（View Transitions，渐进增强）
 * ------------------------------------------------------------
 * theme.js 会用 clip-path 做一个「从按钮扩散的圆」，像开灯一样把新主题铺满。
 * 但浏览器对 ::view-transition 默认还会给旧/新快照各加一段交叉淡入，
 * 和我们的圆形擦除叠在一起会糊成一片灰。所以这里把默认动画关掉，
 * 把控制权整个交给 JS 的 animate()。
 *
 * 不支持 View Transitions 的浏览器会直接忽略这几条 → 瞬间切换，功能不受影响。
 * ---------------------------------------------------------- */
::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）让根底色自己平滑一点 */
@media (prefers-reduced-motion: no-preference) {
  html { transition: background-color .3s ease; }
}
