/* ============================================================
   朝圣仙门 · 昼夜天时 / DayNight 视觉层 v1.1.0
   与 daynight.js 配合：所有 --dn-* 由 JS 按北京时间连续写入。
   设计基准：CSS Color 4 OKLCH；白昼纸白 L*≈96，灰阶 L*≈60，玄夜 L*≈5；
   入夜后纸面 UI 通过 --dn-surface-filter 整块反相，组件不各自重写夜间颜色。
   ============================================================ */

html {
  background: var(--dn-page, #f7f3e9);
  color-scheme: light;
}
body,
body.sect {
  background: transparent !important;
  background-attachment: initial !important;
}
body.sect::before {
  opacity: var(--dn-texture, 0.5);
  transition: opacity 2s linear;
}
body.sect::after {
  opacity: var(--dn-vignette, 0.95);
  transition: opacity 2s linear;
}

/* ---------------- 天幕 ---------------- */
#dn-sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--dn-page, #f7f3e9);
  contain: strict;
}
#dn-sky::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 36%, transparent 38%, rgba(0, 0, 0, .58) 100%);
  opacity: calc(var(--dn-night, 0) * 0.55);
}
.dn-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
/* 日轮/月轮按 --dn-sun-x/-y 绝对定位；缺了这条会落在天幕左上角 */
.dn-orb {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
}

/* 天空底色：白昼纸白 -> 中灰 -> 玄夜 */
.dn-base {
  background:
    radial-gradient(1200px 720px at 84% -12%, rgba(255, 246, 224, .20), transparent 62%),
    radial-gradient(900px 620px at 6% 108%, rgba(120, 146, 132, .08), transparent 60%),
    linear-gradient(180deg,
      var(--dn-sky-top, #f8f4ea) 0%,
      var(--dn-sky-mid, #f4efe3) 50%,
      var(--dn-sky-bottom, #efe8da) 100%);
}
/* 缓慢漂移的明暗层，让底色始终在动 */
.dn-drift {
  opacity: calc(1 - var(--dn-night, 0));
  background:
    radial-gradient(760px 520px at 78% -6%, rgba(212, 178, 118, .16), transparent 66%),
    radial-gradient(680px 480px at 12% 108%, rgba(118, 142, 128, .10), transparent 62%);
  animation: dn-drift 84s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes dn-drift {
  0%   { transform: translate3d(-1.2%, 0, 0) scale(1.04); }
  100% { transform: translate3d(1.4%, -0.8%, 0) scale(1.07); }
}

/* 地平线的晨昏暖光 */
.dn-twilight {
  background:
    radial-gradient(120% 48% at var(--dn-horizon-x, 50%) 102%,
      var(--dn-horizon, #d8b98a) 0%,
      rgba(255, 255, 255, 0) 68%);
  opacity: var(--dn-horizon-a, 0.1);
  filter: blur(10px);
  transition: opacity 2.2s linear;
  will-change: opacity;
}

/* 星野：夜度越高越亮，缓慢呼吸 */
.dn-stars {
  opacity: var(--dn-star-a, 0);
  background-image:
    radial-gradient(1.4px 1.4px at 18% 22%, rgba(255, 250, 232, .95) 50%, transparent 54%),
    radial-gradient(1.1px 1.1px at 62% 14%, rgba(255, 248, 226, .82) 50%, transparent 54%),
    radial-gradient(1.2px 1.2px at 84% 38%, rgba(255, 252, 240, .78) 50%, transparent 54%),
    radial-gradient(1.5px 1.5px at 36% 58%, rgba(255, 249, 231, .66) 50%, transparent 54%),
    radial-gradient(1px 1px at 72% 72%, rgba(240, 244, 255, .72) 50%, transparent 54%),
    radial-gradient(1.1px 1.1px at 9% 78%, rgba(255, 246, 224, .55) 50%, transparent 54%),
    radial-gradient(1.8px 1.8px at 48% 32%, rgba(255, 252, 244, .55) 50%, transparent 56%),
    radial-gradient(1.2px 1.2px at 92% 62%, rgba(236, 242, 255, .5) 50%, transparent 54%);
  background-size: 211px 193px, 317px 271px, 157px 223px, 263px 229px, 349px 307px, 191px 173px, 421px 367px, 283px 251px;
  background-position: 0 0, 43px 97px, 121px 31px, 67px 151px, 191px 79px, 13px 47px, 233px 199px, 311px 133px;
  animation: dn-twinkle 7.5s ease-in-out infinite alternate;
  transition: opacity 2.4s linear;
  will-change: opacity;
}
@keyframes dn-twinkle {
  0%   { opacity: calc(var(--dn-star-a, 0) * 0.62); }
  55%  { opacity: calc(var(--dn-star-a, 0) * 0.96); }
  100% { opacity: calc(var(--dn-star-a, 0) * 0.74); }
}

/* 日轮 */
.dn-sun {
  left: var(--dn-sun-x, 50%);
  top: var(--dn-sun-y, 20%);
  width: clamp(150px, 20vw, 280px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  opacity: var(--dn-sun-a, 1);
  background:
    radial-gradient(circle,
      rgba(255, 252, 242, .98) 0 4.5%,
      rgba(255, 242, 204, .86) 7%,
      rgba(255, 226, 168, .42) 16%,
      rgba(255, 212, 146, .16) 30%,
      rgba(255, 208, 140, .04) 46%,
      rgba(255, 205, 135, 0) 64%);
  filter: blur(0.6px);
  animation: dn-sun-breathe 13s ease-in-out infinite alternate;
  transition: opacity 2s linear;
  will-change: opacity, transform;
}
@keyframes dn-sun-breathe {
  0%   { transform: translate(-50%, -50%) scale(.98); }
  100% { transform: translate(-50%, -50%) scale(1.05); }
}

/* 月轮 */
.dn-moon {
  left: 78%;
  top: 13%;
  width: clamp(58px, 6.6vw, 88px);
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: var(--dn-moon-a, 0);
  background:
    radial-gradient(circle at 39% 34%, rgba(198, 188, 158, .30) 0 7%, transparent 9%),
    radial-gradient(circle at 61% 56%, rgba(198, 188, 158, .24) 0 5.5%, transparent 7.5%),
    radial-gradient(circle at 48% 68%, rgba(198, 188, 158, .18) 0 4%, transparent 6%),
    radial-gradient(circle at 42% 38%, #f8f2df 0 52%, #eee4c9 64%, #ddcfaa 70%, rgba(221, 207, 170, 0) 72%);
  box-shadow:
    0 0 42px 12px rgba(241, 233, 208, .20),
    0 0 120px 42px rgba(220, 214, 190, .09);
  animation: dn-moon-float 22s ease-in-out infinite alternate;
  transition: opacity 2.6s linear;
  will-change: opacity, transform;
}
@keyframes dn-moon-float {
  0%   { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(-7px, 9px, 0); }
}

/* 云气 */
.dn-cloud {
  background-repeat: no-repeat;
  filter: blur(20px);
  opacity: var(--dn-cloud-a, 0.2);
  transition: opacity 2.6s linear;
  will-change: transform, opacity;
}
.dn-cloud-a {
  background:
    radial-gradient(46% 12% at 24% 26%, rgba(255, 255, 255, .72), transparent 72%),
    radial-gradient(38% 10% at 52% 21%, rgba(255, 255, 255, .50), transparent 72%),
    radial-gradient(44% 11% at 79% 30%, rgba(255, 255, 255, .42), transparent 74%);
  animation: dn-cloud-a 150s linear infinite alternate;
}
.dn-cloud-b {
  background:
    radial-gradient(50% 12% at 68% 15%, rgba(255, 255, 255, .34), transparent 72%),
    radial-gradient(34% 9% at 35% 12%, rgba(255, 255, 255, .28), transparent 72%);
  animation: dn-cloud-b 190s linear infinite alternate;
}
@keyframes dn-cloud-a {
  0%   { transform: translate3d(-3%, 0, 0); }
  100% { transform: translate3d(4%, 1.2%, 0); }
}
@keyframes dn-cloud-b {
  0%   { transform: translate3d(2%, -0.8%, 0); }
  100% { transform: translate3d(-3.5%, 0.6%, 0); }
}

/* 远山剪影（只从卡片间隙露出，保持克制） */
.dn-ridge {
  inset: auto 0 0 0;
  height: 24vh;
  transition: background 2s linear;
}
.dn-ridge-far {
  background: var(--dn-ridge-far, rgba(72, 68, 56, .1));
  clip-path: polygon(0 76%, 7% 63%, 14% 68%, 21% 52%, 28% 61%, 35% 47%, 43% 58%, 51% 44%, 59% 55%, 67% 48%, 74% 60%, 82% 52%, 90% 64%, 96% 57%, 100% 66%, 100% 100%, 0 100%);
}
.dn-ridge-near {
  height: 17vh;
  background: var(--dn-ridge-near, rgba(52, 49, 40, .14));
  clip-path: polygon(0 82%, 6% 70%, 13% 78%, 22% 63%, 31% 74%, 39% 60%, 48% 72%, 57% 58%, 65% 69%, 74% 61%, 83% 73%, 91% 66%, 100% 76%, 100% 100%, 0 100%);
}

/* 一道极淡的流光，强调“渐变是活的” */
.dn-sheen {
  background: linear-gradient(112deg,
    transparent 36%,
    rgba(255, 255, 255, .16) 46%,
    rgba(255, 252, 240, .26) 50%,
    rgba(255, 255, 255, .06) 55%,
    transparent 64%);
  opacity: calc(1 - var(--dn-night, 0) * 0.85);
  animation: dn-sheen 46s ease-in-out infinite;
  will-change: transform;
}
@keyframes dn-sheen {
  0%   { transform: translate3d(-18%, 0, 0) skewX(-2deg); }
  55%  { transform: translate3d(18%, -1%, 0) skewX(1deg); }
  100% { transform: translate3d(-18%, 0, 0) skewX(-2deg); }
}

/* ---------------- 白日/夜间整体光比 ---------------- */
/* 不逐组件改色：仅对 UI 主体做连续压暗 + 提对比，保留深色文字可读性；
   CSS filter 不会影响元素后方的天幕，卡片间隙仍是真实天空。 */
body.sect .sidebar,
body.sect .stage-wrap,
body.sect .toast,
body.sect .drawer,
body.sect .levelup-card,
body.sect .div-modal-card,
body.sect .lib-modal-box,
body.sect .pomo-scroll,
body.sect .mu-dock,
body.sect .xp-float,
body.sect .auth-gate,
body.sect .ink-loader,
body.sect #menuToggle {
  filter: var(--dn-surface-filter, none);
  transition: filter 1.6s linear;
}

/* 夜间 UI 与纸白 UI 切换：先淡出、换滤镜、再淡回；避免反相中途的低对比灰洗 */
html.dn-ui-swapping body.sect .sidebar,
html.dn-ui-swapping body.sect .stage-wrap,
html.dn-ui-swapping body.sect .toast,
html.dn-ui-swapping body.sect .drawer,
html.dn-ui-swapping body.sect .levelup-card,
html.dn-ui-swapping body.sect .div-modal-card,
html.dn-ui-swapping body.sect .lib-modal-box,
html.dn-ui-swapping body.sect .pomo-scroll,
html.dn-ui-swapping body.sect .mu-dock,
html.dn-ui-swapping body.sect .xp-float,
html.dn-ui-swapping body.sect .auth-gate,
html.dn-ui-swapping body.sect .ink-loader,
html.dn-ui-swapping body.sect #menuToggle {
  transition: opacity .34s ease !important;
}
html.dn-ui-fading body.sect .sidebar,
html.dn-ui-fading body.sect .stage-wrap,
html.dn-ui-fading body.sect .toast,
html.dn-ui-fading body.sect .drawer,
html.dn-ui-fading body.sect .levelup-card,
html.dn-ui-fading body.sect .div-modal-card,
html.dn-ui-fading body.sect .lib-modal-box,
html.dn-ui-fading body.sect .pomo-scroll,
html.dn-ui-fading body.sect .mu-dock,
html.dn-ui-fading body.sect .xp-float,
html.dn-ui-fading body.sect .auth-gate,
html.dn-ui-fading body.sect .ink-loader,
html.dn-ui-fading body.sect #menuToggle {
  opacity: .03 !important;
}

/* 夜间：遮罩、抽屉、弹层再加深一层 */
html.dn-dark .drawer-mask {
  background: rgba(3, 5, 9, .52);
}
html.dn-dark .levelup-layer {
  background: rgba(3, 5, 9, .58);
}
html.dn-dark .div-modal,
html.dn-dark .lib-modal {
  background: rgba(3, 5, 9, .74);
}
html.dn-dark .toast {
  box-shadow: 0 12px 34px -18px rgba(0, 0, 0, .9);
}
html.dn-dark body.sect .topbar {
  box-shadow: 0 10px 30px -30px rgba(0, 0, 0, .9);
}

/* 夜间：主殿山门图在反相前先提亮，反相后即沉成深墨（反相会把它再压暗一档） */
html.dn-night-ui body.sect .sect-map-bg {
  filter: saturate(.88) contrast(1.04) brightness(1.32);
  transition: filter 1.2s ease;
}

/* 状态钩子：给需要按昼夜切换的行为留接口 */
html.dn-dark body.sect .sidebar::after,
html.dn-dark body.sect .topbar::after {
  opacity: .65;
}

/* ---------------- 移动端与无障碍 ---------------- */
@media (max-width: 720px) {
  .dn-sun { width: clamp(112px, 30vw, 170px); }
  /* 移动端天幕几乎被内容盖住，月轮只会在顶栏与山门图之间露出一条，显脏，直接隐藏 */
  .dn-moon { display: none; }
  .dn-ridge { height: 17vh; }
  .dn-ridge-near { height: 12vh; }
  .dn-sheen { display: none; }
  .dn-cloud { filter: blur(14px); }
  body.sect .sidebar,
  body.sect .stage-wrap,
  body.sect .toast,
  body.sect .drawer,
  body.sect .levelup-card,
  body.sect .div-modal-card,
  body.sect .lib-modal-box,
  body.sect .pomo-scroll,
  body.sect .mu-dock,
  body.sect .xp-float,
  body.sect .auth-gate,
  body.sect .ink-loader,
  body.sect #menuToggle {
    will-change: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dn-drift,
  .dn-stars,
  .dn-sun,
  .dn-moon,
  .dn-cloud,
  .dn-sheen {
    animation: none !important;
  }
  body.sect .sidebar,
  body.sect .stage-wrap,
  body.sect .toast,
  body.sect .drawer,
  body.sect .levelup-card,
  body.sect .div-modal-card,
  body.sect .lib-modal-box,
  body.sect .pomo-scroll,
  body.sect .mu-dock,
  body.sect .xp-float,
  body.sect .auth-gate,
  body.sect .ink-loader,
  body.sect #menuToggle,
  body.sect::before,
  body.sect::after,
  .dn-twilight,
  .dn-stars,
  .dn-sun,
  .dn-moon,
  .dn-cloud {
    transition: none !important;
  }
}
