/* ==========================================================================
   动效层：克制。只有页面转场、轻微入场、阅读进度。
   ========================================================================== */

@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: vt-out 200ms var(--ease-soft) both;
}

::view-transition-new(root) {
  animation: vt-in 300ms var(--ease) both;
}

/* 过渡进行中：锁住吸顶页头的样式，避免透明/模糊背景在快照之间跳变 */
html:active-view-transition .site-header {
  background: var(--bg);
  backdrop-filter: none;
  box-shadow: 0 1px 0 var(--line);
  transition: none;
}

/* 开关关闭时：不做任何过渡，回到瞬间切换 */
html[data-vt="off"]::view-transition-old(root),
html[data-vt="off"]::view-transition-new(root) {
  animation: none !important;
}

/* 关闭过渡时才需要隐藏恢复；开启时由 View Transition 负责遮罩 */
html[data-vt="off"].is-restoring::view-transition-old(root),
html[data-vt="off"].is-restoring::view-transition-new(root) {
  animation: none !important;
}

@keyframes vt-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* 首屏文字：轻微上浮 */
.hero__title,
.hero__sub,
.hero__actions,
.hero__meta {
  animation: rise 700ms var(--ease) both;
}

.hero__sub {
  animation-delay: 90ms;
}

.hero__actions {
  animation-delay: 150ms;
}

.hero__meta {
  animation-delay: 210ms;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* 滚动入场：只做透明度，不做位移 */
@supports (animation-timeline: view()) {
  .reveal {
    animation: reveal linear both;
    animation-timeline: view();
    animation-range: entry 10% cover 24%;
  }
}

@keyframes reveal {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.js-reveal {
  opacity: 0;
  transition: opacity 600ms var(--ease);
}

.js-reveal.is-in {
  opacity: 1;
}

/* 阅读进度：1px 细线 */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: calc(var(--z-nav) + 1);
  background: var(--ink);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

@supports (animation-timeline: scroll()) {
  .reading-progress {
    animation: reading-progress linear both;
    animation-timeline: scroll(root block);
  }
}

@keyframes reading-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

/* 灯箱图片 */
.lightbox__stage img {
  animation: lb-in 220ms var(--ease) both;
}

@keyframes lb-in {
  from {
    opacity: 0;
  }
}

/* 主题切换过渡 */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition: background-color 220ms var(--ease-soft), color 220ms var(--ease-soft),
    border-color 220ms var(--ease-soft) !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .js-reveal {
    opacity: 1;
  }

  /* 长按抖动是功能反馈，不能被全局降级规则压成 0.01ms */
  .side-check.is-holding,
  .lib-tag.is-holding,
  .lib-chip.is-holding {
    animation-duration: 130ms !important;
    animation-iteration-count: infinite !important;
  }

  ::view-transition-old(root) {
    animation: vt-fade-out 160ms linear both !important;
  }

  ::view-transition-new(root) {
    animation: vt-fade-in 220ms linear both !important;
  }
}


/* 低动效偏好：只淡入淡出，不位移 */
@keyframes vt-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-fade-in {
  from {
    opacity: 0;
  }
}
