/* Figma 25:28 / 37:65 / 37:78 — full-viewport ritual stage. */
.ritual-stage {
  /* This stage predates the token export. Keep its names locally mapped to
     the current Light Website aliases rather than relying on deleted globals. */
  --figma-background: var(--figma-background-fill);
  --figma-text: var(--figma-text-p-normal-colour-normal);
  --figma-line: var(--figma-base-colours-white-01);
  --figma-muted-surface: var(--figma-gua-yao-fill-still);
  --figma-accent: var(--figma-gua-yao-fill-move);
  --figma-pixel: var(--figma-text-button-action-font-family);
  --figma-ease-out: cubic-bezier(.16, 1, .3, 1);
  --figma-ease-in-out: cubic-bezier(.65, 0, .35, 1);
  position: fixed;
  z-index: 20;
  inset: 0;
  overflow: visible;
  background: var(--figma-background);
  color: var(--figma-text);
  isolation: isolate;
}
.ritual-stage[hidden] { display: none; }
.ritual-stage:focus { outline: none; }
body.ritual-active .header,
body.ritual-active .question-section {
  opacity: 0;
  transform: translateY(-18vh);
  pointer-events: none;
}
.ritual-context {
  position: absolute;
  z-index: 6;
  left: 24px;
  right: 24px;
  top: 106px;
  text-align: center;
  opacity: 0;
  transform: translateY(16px);
}
.ritual-ready .ritual-context { animation: ritual-context-in 540ms var(--figma-ease-out) 120ms both; }
.ritual-category { margin: 0 0 16px; color: var(--figma-text-title-supplementary-colour-supp-passive); font-family: var(--figma-text-title-supplementary-font-family); font-size: var(--figma-text-title-supplementary-font-size-normal); font-weight: var(--figma-text-title-supplementary-font-weight); letter-spacing: var(--figma-text-title-supplementary-letter-spacing); line-height: normal; text-box-edge: cap alphabetic; text-box-trim: trim-both; }
.ritual-question { margin: 0; color: var(--figma-text-p-normal-colour-normal); font-family: var(--figma-text-p-normal-font-family); font-size: var(--figma-text-p-normal-font-size); font-weight: 400; line-height: var(--figma-text-p-normal-line-height-normal); overflow-wrap: anywhere; text-box-edge: cap alphabetic; text-box-trim: trim-both; }
.ritual-shell-zone { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transform: scale(1.08); }
.ritual-ready .ritual-shell-zone { animation: ritual-shell-arrive 700ms var(--figma-ease-out) both; }
.ritual-coin-canvas {
  position: absolute;
  /* 圈是甲壳下的装饰，铜钱在其上方，避免白描边切过钱面。 */
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.ritual-ring { position: absolute; z-index: 1; width: 480px; height: 480px; border: 3px solid var(--figma-line); border-radius: 50%; opacity: 0; transform: scale(.94); transform-origin: center; pointer-events: none; transition: transform 160ms var(--figma-ease-out), opacity 120ms var(--figma-ease-out); }
.ritual-ready .ritual-ring { opacity: 1; transform: scale(1); animation: ritual-ring-breathe 3.6s var(--figma-ease-in-out) infinite; }
/* position 跟其余的 .ritual-shell-zone 子元素(白圈/canvas/文字)统一用 absolute，
   都靠 place-items:center 在整个 zone 里居中；原本这里是 relative，会走 grid
   正常流单独分配一行，不吃同一套居中逻辑——.ritual-shell-zone 加 padding-top
   把龟甲往下推时，只有白圈等跟着移，龟甲本体没动，两者就错开了。 */
.ritual-shell { position: absolute; z-index: 3; width: 324px; height: 405px; border: 0; padding: 0; background: transparent; cursor: pointer; transform-origin: center; -webkit-tap-highlight-color: transparent; transition: transform 160ms var(--figma-ease-out); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.ritual-shell:focus-visible { outline: 2px solid var(--figma-line); outline-offset: 10px; border-radius: 50%; }
.ritual-shell:disabled { cursor: wait; }
.ritual-shell img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* 俯视图不使用外投影；避免透明 PNG 边缘产生阴影裁切错觉。 */
  filter: none;
  /* 龟甲图只是按钮的外观，命中测试一律交给 .ritual-shell 本身：图片自己不接
     指针事件，浏览器就不会把「按住龟甲拖一下」判成原生图片拖拽手势（那会吞掉
     这次 click，个别情况下还让后续点击一起失效）。-webkit-user-drag 是 Safari
     等 WebKit 的额外保险，index.html 的 draggable="false" 是第三道。 */
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}
.ritual-shell:active { transform: scale(.97); }
.ritual-completion-seal {
  position: absolute;
  z-index: 7;
  display: grid;
  place-items: center;
  width: 76px;
  height: 52px;
  border: 1px solid var(--figma-text);
  border-radius: 4px;
  background: color-mix(in srgb, var(--figma-background) 96%, transparent);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--figma-text) 18%, transparent), inset 0 0 0 3px var(--figma-background), inset 0 0 0 4px color-mix(in srgb, var(--figma-accent) 72%, transparent);
  color: var(--figma-text);
  font: 400 24px/1 var(--figma-pixel);
  letter-spacing: 2px;
  opacity: 0;
  pointer-events: none;
  transform: scale(.88);
}
.ritual-complete .ritual-completion-seal {
  animation: ritual-completion-seal-in 500ms steps(4, end) 280ms both;
}
.ritual-instruction { position: absolute; z-index: 5; margin: 0; color: var(--figma-line); font: 48px/1 var(--figma-pixel); text-shadow: 0 2px 0 rgba(75,61,41,.28); pointer-events: none; opacity: 0; }
.ritual-ready .ritual-instruction { animation: ritual-instruction-in 180ms var(--figma-ease-out) 2s both, ritual-nudge 1.6s var(--figma-ease-in-out) 2.18s infinite; }
.ritual-instruction[hidden] { display: none; }
/* 六爻是最底层的全舞台背景，桌面/移动共用一套 vh 数字，不再分断点各写一份：
   16vh 间距、40vh 偏移(=2.5×间距，让 6 条爻以视口垂直中心对称展开)、9.77vh
   厚度——Figma 稿的 1440×1024 viewport 只是参考，不是要死板复刻的像素值，
   用 vh 无论窗口多高都保持同样比例。 */
.ritual-yao-stack { position: absolute; z-index: 0; inset: 0; pointer-events: none; }
.ritual-yao { position: absolute; top: calc(50% + 40vh - var(--ritual-yao-index) * 16vh); left: 0; display: flex; justify-content: center; gap: min(480px, 33.333vw); width: 100%; height: 9.77vh; transform: translateY(-50%); animation: ritual-yao-in 300ms var(--figma-ease-out) both; }
.ritual-yao span { display: block; width: 100%; height: 100%; background: var(--figma-muted-surface); box-shadow: none; }
.ritual-yao.yin span { width: calc((100% - min(480px, 33.333vw)) / 2); }
.ritual-yao.changing span { background: var(--figma-accent); }
.ritual-complete .ritual-yao-stack {
  animation: ritual-hexagram-lock 560ms var(--figma-ease-out) both;
  transform-origin: center;
}
.ritual-complete .ritual-yao span {
  animation: ritual-yao-confirm 560ms var(--figma-ease-out) both;
}
.ritual-decoding .ritual-ring {
  animation-play-state: paused;
  opacity: .56;
  transform: scale(.97);
}
.ritual-decoding .ritual-coin-canvas {
  opacity: .42;
  transition: opacity 180ms var(--figma-ease-in-out);
}
.ritual-decoding .ritual-context { opacity: .46; transition: opacity 180ms var(--figma-ease-in-out); }
.ritual-exit { animation: ritual-stage-out 320ms var(--figma-ease-in-out) both; }
.ritual-exit .ritual-shell-zone,
.ritual-exit .ritual-coin-canvas,
.ritual-exit .ritual-context,
.ritual-exit .ritual-status {
  transition: opacity 220ms var(--figma-ease-in-out), transform 220ms var(--figma-ease-in-out);
  opacity: 0;
}
.ritual-exit .ritual-shell-zone { transform: scale(.96); }
/* Y2K 视觉确认后接入：落定钱缘的持续像素 0/1，js/digit-drift.js 生成、挂在
   .ritual-ring 上（ring 的圆形范围才是视觉上的钱缘），短距离上浮后自行淡出
   并移除；只在 js/main.js 传 floatingDigits: true 时才会被调用。 */
.y2k-digit-drift {
  position: absolute; z-index: 6; pointer-events: none; transform: translate(-50%, -50%);
  font: 700 15px/1 var(--figma-pixel); color: rgba(255, 255, 255, .95);
  text-shadow: 0 0 6px rgba(255, 255, 255, .8), 0 0 1px rgba(40, 40, 40, .5);
  animation: y2k-digit-rise 2.2s ease-out forwards;
}
@keyframes y2k-digit-rise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.85); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  /* 电子占卦字符化阶段一：贴近钱缘短暂显露一段时间，再衔接原有上浮淡出，
     不是新建一层 emitter，只是同一个字符生命周期里插入一段静止保持。 */
  45% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, calc(-50% - 34px)) scale(1); }
}
@keyframes ritual-context-in { to { opacity: 1; transform: translateY(0); } }
@keyframes ritual-shell-arrive { from { opacity: 0; transform: translateY(8vh) scale(1.08); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes ritual-instruction-in { to { opacity: 1; } }
@keyframes ritual-nudge { 0%,100% { opacity: .58; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-5px); } }
/* 待击时几乎察觉不到的呼吸，只让仪式保持活性，不提示或催促操作。 */
@keyframes ritual-ring-breathe { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .8; transform: scale(1.025); } }
@keyframes ritual-yao-in { from { opacity: 0; transform: translateY(-50%) scaleX(.94); } to { opacity: 1; transform: translateY(-50%) scaleX(1); } }
@keyframes ritual-stage-out { to { opacity: 0; transform: scale(1.03); } }
@media (max-width: 640px) {
  .ritual-context { top: 68px; }
  .ritual-category { font-size: 14px; }
  .ritual-question { font-size: 16px; }
  /* 龟甲整体往下挪，让拇指单手操作更容易够到。之前用 padding-top 缩小
     place-items:center 的居中范围，实测不可靠——绝对定位子元素的包含块是
     "padding box"，边界不受 padding 值影响，实测下来中心点根本没挪动。
     改成直接收缩 .ritual-shell-zone 自己的 inset（把 top 从 0 改成正数，
     不再用 inset:0 的简写），这样容器本身的盒子真的变矮了，
     place-items:center 在这个变矮的盒子里居中，中心点才会真的往下移。
     六爻背景条已经从 HTML 里挪到这个 zone 外面（见 index.html），是舞台级
     的独立背景层，不会再跟着这里的 inset 收缩一起往下挪/被裁切。 */
  .ritual-shell-zone { inset: 13.74vh 0 0 0; }
  /* Figma zhan6yao-drafts node 131:37（ritual_mobile，390×844）：龟甲比之前
     的稿子小了一圈，圆环 390px 宽参考帧下是 340px、龟甲是 240×300（比例从
     792:1109 换成更方正的 240:300=4:5），换算成 vw 比例、按参考帧尺寸封顶，
     不再比 Figma 定的目标尺寸更大。 */
  .ritual-ring { width: min(87.18vw, 340px); height: min(87.18vw, 340px); }
  .ritual-shell { width: min(61.54vw, 240px); height: auto; aspect-ratio: 4 / 5; }
  /* 铜钱由 Three.js 按 canvas 像素尺寸渲染，相机 fov/z 是固定常量，不随
     视口变化重新取景——直接用 CSS transform 把整个 canvas 放大，不用去
     改 js/coin-scene.js 里的相机参数。canvas 本身是覆盖整个舞台的
     position:absolute; inset:0，从中心放大不会挪动铜钱在页面上的落点。
     --ritual-coin-mobile-scale 是用户看移动端实机后确认的固定审美系数，
     跟相机 fov/z、跟 .ritual-shell/.ritual-ring 的移动端尺寸都没有换算
     关系（ca3138d 引入放大 20%，da1c16a 把龟甲改回原尺寸时特意确认铜钱
     缩放不用跟着改）——不是从别处派生出来的数字，改动前请先用真机验证
     新值观感是否仍然合适，不要假设它该跟着哪个尺寸联动。 */
  .ritual-coin-canvas { --ritual-coin-mobile-scale: 1.2; transform: scale(var(--ritual-coin-mobile-scale)); transform-origin: center; }
  /* node 131:79：同一份 node 131:37 参考帧里"点击开始"字号是 72px，字体沿用
     现有 --figma-pixel token（用户确认这次不改字体，Figma 那边会反过来跟代码同步）。 */
  .ritual-instruction { font-size: 72px; }
  /* 阴爻中间断开的空隙(不是上面爻与爻之间的垂直间距)：桌面版 gap 是
     min(480px, 33.333vw)，在手机宽度下算出来接近 130px，跟每段实心条一样宽，
     看着太空。移动端单独收到一半 min(480px, 16.667vw)；.yin span 的宽度公式
     引用的是同一个 gap 值，必须跟着改，否则两段宽度还是按旧 gap 算的，加上
     新的实际 gap 之后总宽度就凑不满整行了。 */
  .ritual-yao { gap: min(480px, 16.667vw); }
  .ritual-yao.yin span { width: calc((100% - min(480px, 16.667vw)) / 2); }
}
@media (prefers-reduced-motion: reduce) {
  body.ritual-active .header, body.ritual-active .question-section { transform: none; }
  .ritual-ready .ritual-ring { animation: none; }
  .ritual-ready .ritual-context, .ritual-ready .ritual-shell-zone, .ritual-yao, .ritual-complete .ritual-yao-stack, .ritual-complete .ritual-yao span, .ritual-complete .ritual-completion-seal, .ritual-exit { animation-duration: 160ms; animation-delay: 0ms; }
  .ritual-complete .ritual-yao-stack { animation-name: ritual-hexagram-lock-reduced; }
  .ritual-complete .ritual-yao span { animation: none; }
  .ritual-complete .ritual-completion-seal { animation-name: ritual-completion-seal-reduced; animation-duration: 160ms; animation-delay: 0ms; }
  .ritual-exit .ritual-shell-zone { transform: none; }
  .ritual-ready .ritual-instruction { animation: ritual-instruction-in 160ms var(--figma-ease-out) 2s both; }
  .y2k-digit-drift { display: none; }
}
@media (forced-colors: active) {
  .y2k-digit-drift { display: none; }
}

@keyframes ritual-hexagram-lock {
  0%   { transform: scaleY(1); filter: brightness(1); }
  42%  { transform: scaleY(1.018); filter: brightness(1.28); }
  100% { transform: scaleY(1); filter: brightness(1.08); }
}
@keyframes ritual-yao-confirm {
  0%   { box-shadow: none; }
  42%  { box-shadow: 0 0 20px color-mix(in srgb, var(--figma-accent) 38%, transparent); }
  100% { box-shadow: 0 0 6px color-mix(in srgb, var(--figma-accent) 14%, transparent); }
}
@keyframes ritual-hexagram-lock-reduced {
  0%   { opacity: 1; }
  50%  { opacity: .72; }
  100% { opacity: 1; }
}
@keyframes ritual-completion-seal-in {
  0%   { opacity: 0; transform: scale(.88); clip-path: inset(0 50%); }
  28%  { opacity: 1; transform: scale(1.04); clip-path: inset(0); }
  52%, 100% { opacity: 1; transform: scale(1); clip-path: inset(0); }
}
@keyframes ritual-completion-seal-reduced {
  from { opacity: 0; }
  to   { opacity: 1; }
}
