/* 微交互样式：与 js/core/motion.js 一一对应。
 *
 * 只有 motion.js 会给元素加 m-down / m-pop / run / has-ink 这些类，
 * 也就是说：JS 没跑起来（或用户开了「减少动态效果」）时，界面回到
 * 原来的静态样式，不会出现「按下缩不回来」这种卡住的中间态。
 *
 * 动画参数取自设计口径：
 *   按压     压缩 0.89x，回弹过冲 +12%，曲线 cubic-bezier(.34,1.56,.64,1)
 *   分段滑块 宽度 100% → 164% → 100%（改 width，不是 scaleX）
 *   描边接力 外环 0→50%，对勾 50→82%，总时长 620ms
 */

/* 滑块进度用 --p 表示；注册成 <percentage> 后，即使将来加 transition
   也能按数值插值，而不是被当成字符串硬切。
   inherits 必须是 true：--p 写在 input 上，真正吃它的是
   ::-webkit-slider-runnable-track 这个伪元素 —— 设成 false 会让伪元素
   拿不到值，轨道退回全灰（金色填充整段消失，但数值还是对的）。 */
@property --p {
  syntax: '<percentage>';
  inherits: true;
  initial-value: 0%;
}

/* ── 1. 按压回弹 Spring ──────────────────────────────────
   双类名是为了压过页面里原有的 :active（.ov-cta:active / .ob-ai:active
   都是 transform: scale(.99)，单类名会被它们顶掉）。 */
.m-down.m-down {
  transform: scale(.89);
  transition: transform 110ms cubic-bezier(.22,.8,.3,1);
  will-change: transform;
}

.m-pop.m-pop {
  animation: m-spring 340ms cubic-bezier(.34,1.56,.64,1) both;
  will-change: transform;
}

/* 0.89 起手 → 1.12 过冲（+12%）→ 两次收敛，不让它像弹簧一样抖个不停 */
@keyframes m-spring {
  0%   { transform: scale(.89); }
  38%  { transform: scale(1.12); }
  62%  { transform: scale(.965); }
  82%  { transform: scale(1.012); }
  100% { transform: scale(1); }
}

/* ── 2. 弹性开关 Squash & Stretch ────────────────────────
   .seg-ink 是选中块本体；文字仍在 b 上（z-index 抬高），
   所以滑块拉宽到 164% 时压到邻居格子上，文字也不会跟着变形。 */
.seg { position: relative; }
.seg > b { position: relative; z-index: 1; }

.seg-ink {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-radius: 7px;
  background: var(--surface2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  pointer-events: none;
  will-change: left, width;
}

.seg.big .seg-ink,
.seg.w .seg-ink { border-radius: 8px; }

/* 墨块接管背景后，原来的 .on 底色要摘掉，否则两层灰叠在一起发亮 */
.seg.has-ink > b.on {
  background: transparent;
  box-shadow: none;
}

/* ── 3. 描边接力 Draw & Morph ────────────────────────────
   两条路径都写了 pathLength="100"，dasharray 定死 100 100，
   进度就只由 dashoffset 表达：100 = 一笔没画，0 = 画完。 */
.dmark {
  display: inline-flex;
  width: var(--dm, 26px);
  height: var(--dm, 26px);
  color: currentColor;
}

.dmark svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dm-ring,
.dm-tick {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100 100;
  stroke-dashoffset: 100;
}

.dm-ring { stroke-width: 1.7; }
.dm-tick { stroke-width: 2.2; }

.dmark.run { animation: dm-morph 620ms cubic-bezier(.34,1.56,.64,1) both; }
.dmark.run .dm-ring { animation: dm-ring 620ms cubic-bezier(.22,.8,.25,1) both; }
.dmark.run .dm-tick { animation: dm-tick 620ms cubic-bezier(.22,.8,.25,1) both; }

/* 外环：0→50% 画完；描边粗细同时由 1.3 涨到 2.6 再回 1.7，
   让「环合拢」有一个收束的形变，而不是一条匀速的线在跑 */
@keyframes dm-ring {
  0%   { stroke-dashoffset: 100; stroke-width: 1.3; }
  38%  { stroke-width: 2.6; }
  50%  { stroke-dashoffset: 0; stroke-width: 2.2; }
  100% { stroke-dashoffset: 0; stroke-width: 1.7; }
}

/* 对勾：从 50% 接棒，82% 画完，剩下 18% 留白让整体落定 */
@keyframes dm-tick {
  0%, 50% { stroke-dashoffset: 100; }
  82%     { stroke-dashoffset: 0; }
  100%    { stroke-dashoffset: 0; }
}

/* 整体一次轻微鼓起，与两条路径的进度合成一个动作 */
@keyframes dm-morph {
  0%   { transform: scale(.92); }
  46%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ── 4/5. 数字：等宽、稳定 ──────────────────────────────
   滚动时每一帧字符宽度必须一致，否则数字会左右跳；
   容器不加固定宽度（不同币种位数不同），靠 tabular-nums 对齐。 */
.settle {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-variant-east-asian: initial;
}

/* ── 降级 ──────────────────────────────────────────────
   系统开了「减少动态效果」：不压缩、不过冲、不滚动，直接给最终态。
   对勾要显式置为画完，否则会停在「一笔没画」的初始 dashoffset 上。 */
@media (prefers-reduced-motion: reduce) {
  .m-down.m-down,
  .m-pop.m-pop {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }

  .dmark.run,
  .dmark.run .dm-ring,
  .dmark.run .dm-tick {
    animation: none !important;
  }

  .dmark.run .dm-ring,
  .dmark.run .dm-tick { stroke-dashoffset: 0; }
}

/* ── 重叠卡堆：一组模块收成一叠，点开散成列表 ──────────────
   收起：每张只露自身高度的 1/3（后一张压住前一张的 2/3），
   末位一张是「+N 查看全部」，完整显示。
   展开：卡片按 --i 依次落位，间距 --gap；高度由 JS 量出来的 --ch 决定，
   所以文案换行变高也不会错位。--peek / --ch / --n / --layers 都由
   core/stack.js 下发，这里的默认值只防「JS 还没跑」时塌成一团。 */
.stk-group {
  --ch: 60px;
  --peek: 20px;
  --gap: 10px;
  --n: 3;
  --layers: 3;
}

.stk-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 10px;
}
.stk-head .cap { font-weight: 700; letter-spacing: .5px; }

.stk-fold {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 2px;
  border: 0;
  background: none;
  color: var(--dim);
  font-family: inherit;
  font-size: 11px;
  -webkit-tap-highlight-color: transparent;
}
.stk-fold i {
  width: 14px;
  height: 14px;
  color: var(--dim);
  transition: transform 260ms cubic-bezier(.22, .8, .28, 1);
}
.stk-group[data-open="1"] .stk-fold i { transform: rotate(180deg); }

.stk-deck {
  position: relative;
  height: calc((var(--layers) - 1) * var(--peek) + var(--ch));
  transition: height 320ms cubic-bezier(.22, .8, .28, 1);
}
.stk-group[data-open="1"] .stk-deck {
  height: calc(var(--n) * (var(--ch) + var(--gap)) - var(--gap));
}

/* 绝对定位 + 递增 z-index：后一张压住前一张的下部，最上面那张才完整。
   top 与 z-index 都由 --i 推出来，顺序与视觉顺序永远一致。 */
.stk {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--i) * var(--peek));
  z-index: calc(var(--i) + 1);
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, 0)), var(--surface);
  color: var(--text);
  text-decoration: none;
  text-align: left;
  font-family: inherit;
  will-change: top;
  transition: top 320ms cubic-bezier(.22, .8, .28, 1);
}
.stk-group[data-open="1"] .stk {
  top: calc(var(--i) * (var(--ch) + var(--gap)));
}

.stk > div { flex: 1; min-width: 0; }
.stk b { display: block; font-size: 13.5px; font-weight: 700; }
.stk > div > span {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stk > i { width: 16px; height: 16px; flex: none; color: var(--dim); }

/* 收起态标题：绝对定位在卡片顶部那条 1/3 带里，只写模块名。
   必须绝对定位 —— 它不能参与卡片的高度计算：--ch 是按「完整内容」量出来的，
   行内布局一变，量出的卡高就偏小，展开时每张都会挤在一起。 */
.stk-mini {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 0;
  display: flex;
  align-items: center;
  height: var(--peek);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .2px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
}

/* 末位：剩余数量。它是最上层且完全露出的一张，所以「+N」一眼可见。 */
.stk-more {
  /* 高度必须与真实卡一致：它占了最后一层，矮一截就会在整叠底部露缝 */
  height: var(--ch);
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  border-color: rgba(245, 185, 64, .3);
  background: linear-gradient(180deg, rgba(245, 185, 64, .12), rgba(245, 185, 64, .03));
}
.stk-more[hidden] { display: none; }
.stk-more b {
  font-family: var(--fn);
  font-size: 21px;
  font-weight: 600;
  line-height: 1.05;
  color: var(--gold);
}
.stk-more > span {
  margin: 0;
  font-size: 10.5px;
  color: rgba(245, 185, 64, .68);
}

@media (prefers-reduced-motion: reduce) {
  .stk,
  .stk-deck,
  .stk-fold i { transition: none !important; }
}

/* 收起态只留两张「封面」与末位数量牌。
   第 3 张及以后必须退场：它们的 --i 与数量牌同层（i=2），
   留着就会在同一位置跟「+N」叠字（第一版实测确实叠在一起）。 */
.stk-group[data-open="0"] .stk-deck > .stk:nth-child(n+3):not(.stk-more) {
  opacity: 0;
  visibility: hidden;
}

/* 收起态只留顶部那条标题（.stk-mini），图标 / 说明 / 箭头隐去；展开后反过来。
   用 opacity 而不是 display：卡高要按完整内容量出来，display:none 会让
   --ch 量成 0，整叠塌掉。.stk-mini 必须排除在「全部隐藏」之外 ——
   否则收起态又变回几条空白条，用户看不出这叠里装的是什么。 */
.stk > * { transition: opacity 180ms linear; }
.stk-group[data-open="0"] .stk:not(.stk-more) > *:not(.stk-mini) { opacity: 0; }
.stk-group[data-open="0"] .stk-mini { opacity: 1; }
.stk-group[data-open="1"] .stk > * { opacity: 1; }
.stk-group[data-open="1"] .stk-mini { opacity: 0; }

/* 数量牌永远在最上层：它要和前两张的图层分开，否则边框会被压掉一条。 */
.stk-more { z-index: 99; }
