/* ============================================================
   motion-1113 · 克制的纯 CSS 动效增强
   只以长属性覆盖动效参数；不占用已有滚动 transform，不新增脚本。
   原选择器与时间轴记录见 deliverables/motion-1113/baseline/selectors.md。
   ============================================================ */

/* ---------- 首页：仅按钮与卡片入口的细腻反馈 ---------- */
.cap-link,
.decode-card,
.re-explore {
  transition-property: background-color, border-color, color, transform;
  transition-duration: 210ms;
  transition-timing-function: cubic-bezier(.22, 1, .36, 1);
}

.cap-link:hover,
.cap-link:focus-visible,
.decode-card:hover,
.decode-card:focus-visible,
.re-explore:hover,
.re-explore:focus-visible {
  transform: translateY(-2px);
}

.cap-link:hover,
.cap-link:focus-visible {
  background-color: rgba(214, 173, 111, .9);
  border-color: rgba(240, 228, 205, .9);
  color: #142c30;
}

.decode-card:hover,
.decode-card:focus-visible {
  background-color: #241410;
  border-color: rgba(176, 141, 79, .6);
}

.re-explore:hover,
.re-explore:focus-visible {
  background-color: var(--gold);
  color: var(--ink);
}

.cap-link:focus-visible,
.decode-card:focus-visible,
.re-explore:focus-visible {
  outline: 2px solid #d6ad6f;
  outline-offset: 3px;
}

/* ---------- 定位开场：原 WebP 云雾从两侧退开 ---------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* 远层 34%，近层 30%：同一时间轴错开 4%，远层更慢。 */
    .focus-intro .fi-clouds::before {
      animation-name: motion-fi-cloud-back;
      animation-range: contain 0% contain 34%;
      animation-timing-function: ease-in-out;
    }
    .focus-intro .fi-clouds::after {
      animation-name: motion-fi-cloud-front;
      animation-range: contain 0% contain 30%;
      animation-timing-function: ease-in-out;
    }

    /* 故事章沿用 --chapter；远层 100%，近层 96%，不用秒数 delay。 */
    .chapter .cloud-back {
      animation-name: motion-chapter-cloud-back;
      animation-range: contain 0% contain 100%;
      animation-timing-function: ease-in-out;
    }
    .chapter .cloud-front {
      animation-name: motion-chapter-cloud-front;
      animation-range: contain 0% contain 96%;
      animation-timing-function: ease-in-out;
    }
    .chapter .threshold-shadow {
      animation-name: motion-threshold-clear;
      animation-range: contain 0% contain 100%;
      animation-timing-function: ease-in-out;
    }
  }
}

/* 首尾各 10% 稳定；中段仅平移、轻微缩放与透明度变化。 */
@keyframes motion-fi-cloud-back {
  0%, 10% {
    opacity: .46;
    transform: translate(-12%, 2%) scale(1.06);
  }
  55% { opacity: .28; }
  90%, 100% {
    opacity: 0;
    transform: translate(-52%, -4%) scale(1.12);
  }
}

@keyframes motion-fi-cloud-front {
  0%, 10% {
    opacity: .34;
    transform: translate(14%, 3%) scale(1.04);
  }
  55% { opacity: .20; }
  90%, 100% {
    opacity: 0;
    transform: translate(54%, -5%) scale(1.12);
  }
}

@keyframes motion-chapter-cloud-back {
  0%, 10% {
    opacity: .16;
    transform: translate(-12%, 6%) scale(1.06);
  }
  60% { opacity: .10; }
  90%, 100% {
    opacity: 0;
    transform: translate(-52%, -12%) scale(1.16);
  }
}

@keyframes motion-chapter-cloud-front {
  0%, 10% {
    opacity: .14;
    transform: translate(14%, 8%) scale(1.02);
  }
  60% { opacity: .10; }
  90%, 100% {
    opacity: 0;
    transform: translate(52%, -10%) scale(1.14);
  }
}

/* 尾段暗化只作短暂景深，最后 10% 完全移除，不残留压暗文字。 */
@keyframes motion-threshold-clear {
  0%, 50% { opacity: 0; }
  70% { opacity: .32; }
  82% { opacity: .18; }
  90%, 100% { opacity: 0; }
}

/* ---------- 贴画：保留 translate 叠加层与横向跟随 ---------- */
@media (prefers-reduced-motion: no-preference) {
  body.standalone .chapter .scene {
    animation-duration: 7.2s, 6.4s;
  }

  body.standalone .chapter .scene :is(.layer, .foreground, .curtain, .passing-cloud, .shore) {
    --across: .75px;
    --lift: 1px;
  }

  /* 远层与静物：峰值 1.1px / 1.6px，避免静物跳跃。 */
  body.standalone .chapter .scene :is(.roof, .dragons, .canopy, .shore, .cloud-back) {
    --across: -.55px;
    --lift: .8px;
  }

  /* 巨人与承托物完全同幅同相；--travel 仍沿用原 4px 横向跟随。 */
  body.standalone .chapter .scene :is(.earth, .giant) {
    --travel: 4px;
    --across: -.65px;
    --lift: .8px;
  }

  /* 日与鸟、月与蟾兔分别包含在各自同一 WebP 中，仅移动整个 layer。 */
  body.standalone .chapter .scene .sun {
    --across: -.55px;
    --lift: .75px;
  }
  body.standalone .chapter .scene .moon {
    --across: .55px;
    --lift: -.75px;
  }

  /* 近层峰值 3px / 3px，低于 4px 上限；反相避免全层同步摆动。 */
  body.standalone .chapter .scene :is(.fish, .rider-left, .rider-right, .human-bird, .envoys, .deity, .foreground, .curtain, .cloud-front) {
    --across: 1.5px;
    --lift: -1.5px;
  }
}

/* ---------- 尾声：支持时进入视口播放，不支持时默认全文可见 ---------- */
@supports (animation-trigger: --read play-once) and (timeline-trigger: --read view() entry 5%) {
  @media (prefers-reduced-motion: no-preference) {
    .realm-end.coda .coda-q span,
    .realm-end.coda .coda-p {
      animation-name: motion-reading-arrives;
      animation-duration: .82s;
      animation-timing-function: cubic-bezier(.22, 1, .36, 1);
      animation-fill-mode: both;
    }
    .realm-end.coda .coda-q span { animation-delay: 0s; }
    .realm-end.coda .coda-q span + span { animation-delay: .2s; }
    .realm-end.coda .coda-p:nth-of-type(1) { animation-delay: .4s; }
    .realm-end.coda .coda-p:nth-of-type(2) { animation-delay: .6s; }
    .realm-end.coda .coda-p:nth-of-type(3) { animation-delay: .8s; }
    .realm-end.coda .coda-p:nth-of-type(4) { animation-delay: 1s; }
  }
}

@keyframes motion-reading-arrives {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 减少动态：正文、图片与导航保持完整可见 ---------- */
@media (prefers-reduced-motion: reduce) {
  .cap-link,
  .decode-card,
  .re-explore {
    transition: none;
    transform: none;
  }

  .realm-end.coda .coda-q span,
  .realm-end.coda .coda-p {
    animation: none !important;
    opacity: 1;
    transform: none;
  }

  .chapter .cloud-back,
  .chapter .cloud-front,
  .chapter .threshold-shadow {
    opacity: 0;
  }
}
