/* ==========================================================================
   motion3d.css — V5.13 交互动画与 3D 体系
   --------------------------------------------------------------------------
   适用范围：首页（doc_home）/ 一起学（learn）/ 个人中心（me）三页。
   这三页走的是新前台外壳（dc_shell），只加载 variables / global / home / shell，
   不加载 style.css——所以本页所有类名都带 .dc3d- / .dcanim- 前缀，
   不会和旧外壳的同名类打架。

   做法：纯 CSS 透视（照搬 plaza.css 已验证的 .pr-scene 范式）+ CSS keyframes。
   不引框架、不引 JS 依赖、不做 WebGL。

   三档降级（与全站口径一致）：
     ① prefers-reduced-motion: reduce —— 系统级「减少动态效果」
     ② [data-motion="off"]          —— 用户在站内把动效关掉（localStorage arrive.motion）
     ③ html[data-flat3d]            —— 3D 总开关，连装饰层一起不渲染
   ========================================================================== */

:root {
  --dc3d-warm: 201 168 96;    /* 暖琥珀：夜灯的色 */
  --dc3d-deep: 38 52 88;     /* 深夜蓝：背景层 */
  --dc3d-ease: cubic-bezier(.22, .8, .3, 1);
  --dc3d-dur: 560ms;
}

/* --------------------------------------------------------------------------
   1. 3D 装饰层（永远在内容下面，不吃点击）
   -------------------------------------------------------------------------- */
.dc3d-scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  perspective: 900px;
  perspective-origin: 50% 32%;
  z-index: 0;
}

/* 呼吸的暖光晕 */
.dc3d-glow {
  position: absolute;
  left: 50%;
  top: -18%;
  width: 78%;
  aspect-ratio: 2 / 1;
  transform: translateX(-50%);
  background:
    radial-gradient(closest-side, rgba(var(--dc3d-warm), .22), rgba(var(--dc3d-warm), 0) 72%);
  filter: blur(6px);
  animation: dc3d-breathe 7.5s var(--dc3d-ease) infinite;
}

/* 斜切的地面：把内容从平面上「抬起来」，做出纵深 */
.dc3d-floor {
  position: absolute;
  left: -20%;
  right: -20%;
  bottom: -34%;
  height: 62%;
  transform: rotateX(68deg);
  transform-origin: 50% 0;
  background:
    linear-gradient(to bottom, rgba(var(--dc3d-deep), .16), rgba(var(--dc3d-deep), 0) 68%),
    repeating-linear-gradient(to right, rgba(var(--dc3d-warm), .10) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(to bottom, rgba(var(--dc3d-warm), .08) 0 1px, transparent 1px 46px);
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .9), transparent 78%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .9), transparent 78%);
  animation: dc3d-float 12s ease-in-out infinite;
}

/* 主体承载层永远压在装饰层上面 */
.dc3d-hero > *:not(.dc3d-scene) {
  position: relative;
  z-index: 1;
}

@keyframes dc3d-breathe {
  0%, 100% { opacity: .55; transform: translateX(-50%) scale(1); }
  50%      { opacity: .95; transform: translateX(-50%) scale(1.06); }
}

@keyframes dc3d-float {
  0%, 100% { transform: rotateX(68deg) translateY(0); }
  50%      { transform: rotateX(68deg) translateY(-10px); }
}

/* --------------------------------------------------------------------------
   2. 入场动效（一次性，不循环）
   -------------------------------------------------------------------------- */
.dcanim-in {
  animation: dcanim-in var(--dc3d-dur) var(--dc3d-ease) both;
  animation-delay: var(--dcanim-d, 0ms);
}

@keyframes dcanim-in {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(.985); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

/* 同级交错：给一排卡片用 nth-child 拉开节奏 */
.dcanim-stagger > * {
  animation: dcanim-in var(--dc3d-dur) var(--dc3d-ease) both;
}
.dcanim-stagger > *:nth-child(1) { animation-delay: 0ms; }
.dcanim-stagger > *:nth-child(2) { animation-delay: 70ms; }
.dcanim-stagger > *:nth-child(3) { animation-delay: 140ms; }
.dcanim-stagger > *:nth-child(4) { animation-delay: 210ms; }
.dcanim-stagger > *:nth-child(5) { animation-delay: 280ms; }
.dcanim-stagger > *:nth-child(6) { animation-delay: 350ms; }
.dcanim-stagger > *:nth-child(7) { animation-delay: 420ms; }
.dcanim-stagger > *:nth-child(8) { animation-delay: 490ms; }

/* --------------------------------------------------------------------------
   3. 悬停 / 按下反馈（键盘可达：focus-visible 走同一条线）
   -------------------------------------------------------------------------- */
.dc3d-lift {
  transition: transform .22s var(--dc3d-ease), box-shadow .22s var(--dc3d-ease);
  will-change: transform;
}
.dc3d-lift:hover,
.dc3d-lift:focus-visible {
  transform: translate3d(0, -3px, 0);
  box-shadow: 0 10px 26px -14px rgba(var(--dc3d-deep), .55);
}
.dc3d-lift:active {
  transform: translate3d(0, 0, 0) scale(.995);
}

/* 承载 3D 装饰层的容器必须是定位上下文，否则绝对定位会跑到整页上去 */
.do-hero { position: relative; }
.learn-wrap { position: relative; }
/* 装饰层在容器底部铺开，不遮内容 */
.learn-wrap > *:not(.dc3d-scene) { position: relative; z-index: 1; }
.learn-scene { height: 420px; inset: auto 0 0 0; }
.learn-scene .dc3d-floor { bottom: -46%; height: 78%; }

/* --------------------------------------------------------------------------
   3.5 壳级 3D（V5.25）
   --------------------------------------------------------------------------
   过去只有 doc_home / me / learn 三页加载本文件，其余新外壳页的
   .dcanim-* / .dc3d-* 类名全都没有样式，「交互没动画」就是这么来的。
   现在 motion3d.css 进外壳默认样式表，这里补上壳级场景与层级。 */

/* 正文容器：给一层透视，卡片才有纵深可谈 */
.dc-main.dc3d-stage {
  position: relative;
  isolation: isolate;
}
.dc-main.dc3d-stage > *:not(.dc-shell-scene) {
  position: relative;
  z-index: 1;
}
/* 壳级装饰层：铺在正文底下的一片地平线 */
.dc-shell-scene {
  position: absolute;
  inset: 0 0 auto 0;
  height: 460px;
  overflow: hidden;
  pointer-events: none;
  perspective: 900px;
  perspective-origin: 50% 26%;
  z-index: 0;
}
.dc-shell-scene .dc3d-floor { bottom: -52%; height: 96%; }
/* 深色底上暖光要压得更低，否则整页发白 */
.dc-shell-scene .dc3d-glow {
  background: radial-gradient(closest-side, rgba(var(--dc3d-warm), .16), rgba(var(--dc3d-warm), 0) 72%);
}

/* 壳级小引：跟首页的小引同一套暖色边框 */
.dc-shell-spirit {
  transform-style: preserve-3d;
}

/* 卡片与按钮的立体反馈：全站外壳页统一口径 */
.dc3d-stage .card,
.dc3d-stage .dc-scene,
.dc3d-stage .do-scene-card {
  transition: transform .26s var(--dc3d-ease), box-shadow .26s var(--dc3d-ease);
}
.dc3d-stage .card:hover,
.dc3d-stage .dc-scene:hover {
  transform: translate3d(0, -3px, 0);
  box-shadow: 0 18px 34px -20px rgba(0, 0, 0, .85);
}
.dc3d-stage .card:active,
.dc3d-stage .dc-scene:active {
  transform: translate3d(0, 0, 0) scale(.996);
}

/* --------------------------------------------------------------------------
   4. 首页：问候 / 小引 / 入口
   -------------------------------------------------------------------------- */
.do-hero-spirit {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin: 6px 0 10px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(var(--dc3d-warm), .22);
  background: linear-gradient(120deg, rgba(var(--dc3d-warm), .10), rgba(var(--dc3d-warm), .02));
  font-size: 15px;
  line-height: 1.7;
  color: inherit;
}
.do-spirit-text { flex: 1 1 240px; min-width: 0; }
.do-spirit-ops { display: inline-flex; gap: 12px; flex: 0 0 auto; }
.do-spirit-op {
  font-size: 12px;
  /* V5.25：深色底下不能再用黑字（rgba(0,0,0,.48) 几乎看不见） */
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--color-line-strong);
  padding-bottom: 1px;
  transition: color .2s ease, border-color .2s ease;
}
.do-spirit-op:hover { color: rgba(var(--dc3d-warm), .95); border-color: rgba(var(--dc3d-warm), .6); }
.do-spirit-op:focus-visible { outline: 2px solid rgba(var(--dc3d-warm), .7); outline-offset: 3px; border-radius: 4px; }

/* --------------------------------------------------------------------------
   5. 一起学：房间卡纵深分层
   -------------------------------------------------------------------------- */
.learn-rooms.dc3d-depth {
  perspective: 1000px;
  perspective-origin: 50% 24%;
}
.learn-rooms.dc3d-depth .learn-room {
  transform: translateZ(0);
  transition: transform .26s var(--dc3d-ease), box-shadow .26s var(--dc3d-ease);
}
.learn-rooms.dc3d-depth .learn-room:nth-child(1) { transform: translateZ(26px); }
.learn-rooms.dc3d-depth .learn-room:nth-child(2) { transform: translateZ(16px); }
.learn-rooms.dc3d-depth .learn-room:nth-child(3) { transform: translateZ(8px); }
.learn-rooms.dc3d-depth .learn-room:nth-child(n+4) { transform: translateZ(2px); }
.learn-rooms.dc3d-depth .learn-room:hover,
.learn-rooms.dc3d-depth .learn-room:focus-within {
  transform: translateZ(38px);
  box-shadow: 0 16px 30px -18px rgba(var(--dc3d-deep), .6);
}
/* 亮着灯的房间：呼吸的暖光 */
.learn-room .learn-lamp {
  animation: dc3d-lamp 3.4s ease-in-out infinite;
}
@keyframes dc3d-lamp {
  0%, 100% { opacity: .55; box-shadow: 0 0 0 0 rgba(var(--dc3d-warm), .35); }
  50%      { opacity: 1;   box-shadow: 0 0 0 5px rgba(var(--dc3d-warm), 0); }
}

/* --------------------------------------------------------------------------
   6. 个人中心：身份区浅景深 + 徽章点亮
   -------------------------------------------------------------------------- */
.me-id.dc3d-card {
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
  transition: transform .26s var(--dc3d-ease), box-shadow .26s var(--dc3d-ease);
}
.me-id.dc3d-card::before {
  content: '';
  position: absolute;
  inset: -40% -10% auto -10%;
  height: 150%;
  background: radial-gradient(60% 50% at 22% 18%, rgba(var(--dc3d-warm), .16), transparent 70%);
  pointer-events: none;
  z-index: 0;
}
/* 光晕在内容下面，不能糊在文字上 */
.me-id.dc3d-card > * { position: relative; z-index: 1; }
.me-id.dc3d-card:hover { transform: translate3d(0, -2px, 0); }

/* 徽章逐个点亮 */
.badge-grid.dc3d-badges .badge-cell {
  animation: dc3d-badge-in 620ms var(--dc3d-ease) both;
}
.badge-grid.dc3d-badges .badge-cell:nth-child(1) { animation-delay: 0ms; }
.badge-grid.dc3d-badges .badge-cell:nth-child(2) { animation-delay: 90ms; }
.badge-grid.dc3d-badges .badge-cell:nth-child(3) { animation-delay: 180ms; }
.badge-grid.dc3d-badges .badge-cell:nth-child(4) { animation-delay: 270ms; }
.badge-grid.dc3d-badges .badge-cell:nth-child(5) { animation-delay: 360ms; }
.badge-grid.dc3d-badges .badge-cell:nth-child(6) { animation-delay: 450ms; }
@keyframes dc3d-badge-in {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(.94); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
/* 已拿到的徽章：常亮一点 */
.badge-cell.got .badge-ico { color: rgba(var(--dc3d-warm), .95); }

/* --------------------------------------------------------------------------
   7. 降级三档
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .dcanim-in,
  .dcanim-stagger > *,
  .badge-grid.dc3d-badges .badge-cell,
  .learn-room .learn-lamp,
  .dc3d-glow,
  .dc3d-floor {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .dc3d-lift:hover,
  .dc3d-lift:focus-visible,
  .me-id.dc3d-card:hover {
    transform: none !important;
  }
}

html[data-motion="off"] .dcanim-in,
html[data-motion="off"] .dcanim-stagger > *,
html[data-motion="off"] .badge-grid.dc3d-badges .badge-cell,
html[data-motion="off"] .learn-room .learn-lamp,
html[data-motion="off"] .dc3d-glow,
html[data-motion="off"] .dc3d-floor {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}
html[data-motion="off"] .dc3d-lift:hover,
html[data-motion="off"] .dc3d-lift:focus-visible,
html[data-motion="off"] .me-id.dc3d-card:hover {
  transform: none !important;
}

/* 3D 总开关：装饰层与纵深一起关掉，页面回到平面的干净版 */
html[data-flat3d] .dc3d-scene,
html[data-flat3d] .dc-shell-scene { display: none !important; }
html[data-flat3d] .learn-rooms.dc3d-depth .learn-room,
html[data-flat3d] .learn-rooms.dc3d-depth .learn-room:nth-child(n) {
  transform: none !important;
}
html[data-flat3d] .me-id.dc3d-card::before { display: none !important; }
html[data-flat3d] .dc3d-stage .card:hover,
html[data-flat3d] .dc3d-stage .dc-scene:hover { transform: none !important; box-shadow: none; }

/* 窄屏：透视角度收窄，避免内容被压扁 */
@media (max-width: 480px) {
  .dc3d-scene { perspective: 700px; }
  .dc3d-floor { transform: rotateX(72deg); }
  .learn-rooms.dc3d-depth { perspective: 760px; }
  .learn-rooms.dc3d-depth .learn-room:nth-child(1) { transform: translateZ(14px); }
  .learn-rooms.dc3d-depth .learn-room:nth-child(2) { transform: translateZ(9px); }
  .learn-rooms.dc3d-depth .learn-room:nth-child(3) { transform: translateZ(5px); }
  .learn-rooms.dc3d-depth .learn-room:nth-child(n+4) { transform: translateZ(0); }
}
