/* Shared day/night controls and full-page transition. */
html,
body,
#app,
#main,
#sidebar,
#content,
#topbar,
#theme-toggle,
#avatar-slot,
.panel-frame-wrap {
  transition-property: background-color, background, border-color, color, box-shadow;
  transition-duration: 760ms;
  transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

#theme-toggle.theme-switch-control {
  width: 48px;
  height: 48px;
  min-width: 48px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.theme-icon-stack {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
}

.theme-icon,
.theme-stage-icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 420ms ease, transform 760ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sun-core,
.moon-core {
  position: relative;
  display: block;
  width: 15px;
  height: 15px;
}

.sun-core {
  border-radius: 50%;
  color: #f7b928;
  background: currentColor;
  box-shadow: 0 0 12px rgba(247, 185, 40, 0.48);
}

.sun-core::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, currentColor 0deg 7deg, transparent 7deg 45deg);
  -webkit-mask: radial-gradient(circle, transparent 0 56%, #000 58% 72%, transparent 74%);
  mask: radial-gradient(circle, transparent 0 56%, #000 58% 72%, transparent 74%);
}

.moon-core {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #c4b5fd;
  box-shadow: -7px 5px 0 0 currentColor, -9px 7px 15px rgba(196, 181, 253, 0.34);
  transform: translate(3px, -3px);
}

.theme-sun { opacity: 0; transform: rotate(-90deg) scale(0.35); }
.theme-moon { opacity: 1; transform: rotate(0deg) scale(1); }
html[data-theme="light"] .theme-sun { opacity: 1; transform: rotate(0deg) scale(1); }
html[data-theme="light"] .theme-moon { opacity: 0; transform: rotate(90deg) scale(0.35); }

#theme-toggle.theme-switching {
  animation: themeControlPulse 900ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes themeControlPulse {
  0%, 100% { transform: scale(1); }
  38% { transform: scale(1.16) rotate(8deg); }
}

.theme-transition-visual {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
  transition: opacity 260ms ease;
}

.theme-transition-visual[hidden] { display: none; }
.theme-transition-visual.show { opacity: 1; }

.theme-transition-visual::before {
  content: "";
  position: absolute;
  width: min(160vmax, 2200px);
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.04);
  transition: transform 1050ms cubic-bezier(0.16, 1, 0.3, 1), opacity 220ms ease;
}

.theme-transition-visual[data-target="light"]::before {
  background: radial-gradient(circle, rgba(255, 244, 190, 0.72) 0, rgba(239, 244, 255, 0.50) 44%, rgba(226, 231, 245, 0.20) 72%, transparent 73%);
}

.theme-transition-visual[data-target="dark"]::before {
  background: radial-gradient(circle, rgba(67, 53, 111, 0.62) 0, rgba(15, 10, 28, 0.52) 48%, rgba(3, 7, 18, 0.16) 72%, transparent 73%);
}

.theme-transition-visual.show::before {
  opacity: 1;
  transform: scale(1);
}

.theme-stage-symbols {
  position: relative;
  z-index: 1;
  width: 144px;
  height: 144px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  box-shadow: 0 24px 70px rgba(3, 7, 18, 0.22), inset 0 0 34px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  transform: scale(0.72) rotate(-18deg);
  transition: transform 920ms cubic-bezier(0.16, 1, 0.3, 1), opacity 280ms ease;
}

.theme-transition-visual.show .theme-stage-symbols {
  transform: scale(1) rotate(0deg);
}

.theme-stage-icon {
  opacity: 0;
  transform: rotate(-100deg) scale(0.34);
}

.theme-transition-visual[data-target="light"] .theme-stage-sun,
.theme-transition-visual[data-target="dark"] .theme-stage-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-stage-icon .sun-core {
  width: 48px;
  height: 48px;
  box-shadow: 0 0 34px rgba(247, 185, 40, 0.65);
}

.theme-stage-icon .sun-core::before { inset: -24px; }

.theme-stage-icon .moon-core {
  width: 60px;
  height: 60px;
  box-shadow: -23px 17px 0 0 currentColor, -28px 22px 34px rgba(196, 181, 253, 0.42);
  transform: translate(12px, -10px);
}

@media (prefers-reduced-motion: reduce) {
  .theme-transition-visual,
  .theme-transition-visual::before,
  .theme-stage-symbols,
  .theme-stage-icon,
  .theme-icon {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

html {
  isolation: isolate;
}

#custom-background-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

#settings-stars-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

html[data-theme="dark"][data-background-dynamic="off"] #stars-bg {
  display: none !important;
}

/* ⚠️ 浅色模式的根底色必须是**与画布首帧一致**的冷调浅灰 (#eef2fc)，
   不能是纯白 #ffffff。

   为什么：本文件在每个页面都被最先加载，而下面这条带 !important 的规则
   优先级高于各页自己写的兜底底色（那些没有 !important），因此它才是
   实际生效的那一条。原来写纯白，于是：
     · 页面 body 多为 transparent，真正的底色由 stars-bg.js 的 canvas 异步绘制；
     · HTML 解析完成到 canvas 画上来之间存在一个窗口期，
       此时露出的就是这条规则给的**纯白**；
     · canvas 画上来后底色变成 #eef2fc 冷调浅灰 —— 中间就闪一下白。
   #eef2fc 正是 stars-bg.js 浅色模式**渐变中心**的颜色
   （mixedRgb([16,18,42],[238,242,252],1) = rgb(238,242,252) = #eef2fc），
   边缘略深为 #e2e7f5；两者衔接时看不出切换。

   注意：这里必须同时覆盖 html 与 body，因为 body 也是 transparent，
   根节点底色才是最终可见的兜底色。 */
html[data-theme="light"],
html[data-theme="light"] body {
  background: #eef2fc !important;
}

/* ⚠️ 与浅色对称：深色模式也要有与星河首帧同色系的不透明兜底。
   否则刷新时（canvas 尚未挂载/绘制的窗口期）露出的 html 兜底底 #10122a
   会比星河首帧（#10122A ~ #030712）更显「纯黑」，表现为「先黑一下」。
   #10122a 落在星河暗色渐变区间内，衔接处看不出切换。 */
html[data-theme="dark"],
html[data-theme="dark"] body {
  background: #10122a !important;
}

html[data-theme="light"] #custom-background-layer,
html[data-theme="light"] #settings-custom-background {
  display: none !important;
}

/* Keep the floating navigation controls consistent across all service pages. */
:is(.home-link, .portal-home, .task-home-link, #theme-toggle) {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  font-family: "Segoe UI Symbol", "Microsoft YaHei", sans-serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 250ms, border-color 250ms, background 300ms;
}

:is(.home-link, .portal-home, .task-home-link, #theme-toggle):hover {
  transform: translateY(-3px) scale(1.06);
  border-color: rgba(109, 139, 255, 0.68);
  box-shadow: 0 0 0 2px rgba(109, 139, 255, 0.34), 0 8px 22px rgba(3, 7, 18, 0.20);
}

.theme-mode-notice {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  z-index: 10000;
  width: max-content;
  max-width: min(760px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid rgba(37, 99, 235, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #1f2440;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.theme-mode-notice.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

:root {
  --dialog-close-color: #b91c1c;
}

html[data-theme="dark"],
.image-viewer {
  --dialog-close-color: #ff6969;
}

/* Keep close icons red over page-specific button and hover colors. */
.portal-settings-close,
.avatar-crop-close,
.app-dialog .app-dialog-close,
dialog .dialog-header button[aria-label="关闭"],
.key-dialog-close,
.service-drawer-close,
.sheet-close,
.upload-close,
#bookmarkSidebarClose,
.lx-scope .lx-close,
.lx-scope .lx-pv-close,
button.ib[data-close][aria-label],
button.ib[data-dismiss][aria-label],
.bak-close,
#lookClose,
.mm-json-close,
.pip-mode-x,
.pip-fallback-close,
.mm-hint-close,
.ol-close,
.outline-close,
#findCloseBtn,
.toc-close,
.rd-search-x,
.todo-delivery-head button > svg,
.modal-head > button.close,
#jsonClose > [aria-hidden="true"],
.dialog-backdrop .dialog-close,
.image-viewer .viewer-close {
  color: var(--dialog-close-color) !important;
}
