/* 曙光學習 v4 — Motion System
 * 原則：
 * 1. 只動 transform / opacity（走 GPU 合成，不觸發重排重繪）
 * 2. 時長與曲線全站統一，不再各頁各自發明
 * 3. 尊重 prefers-reduced-motion
 * (--ease-out 已定義於 tokens.css，這裡沿用)
 */
:root {
  --dur-instant: 100ms;
  --dur-fast: 160ms;
  --dur-base: 240ms;
  --dur-slow: 400ms;
  --dur-slower: 640ms;
  --dur-spring: 550ms;
  --ease-spring: cubic-bezier(0.34, 1.3, 0.5, 1);   /* 輕微回彈：出現/強調 */
  /* 真・彈簧（阻尼諧振子 k=170 c=16，過衝 1.086）：iOS 式回彈 */
  --ease-spring-hard: linear(0.000, 0.029 3.6%, 0.105 7.1%, 0.211 10.7%, 0.332 14.3%, 0.458 17.9%, 0.580 21.4%, 0.693 25.0%, 0.793 28.6%, 0.877 32.1%, 0.945 35.7%, 0.998 39.3%, 1.037 42.9%, 1.064 46.4%, 1.079 50.0%, 1.086 53.6%, 1.086 57.1%, 1.082 60.7%, 1.074 64.3%, 1.064 67.9%, 1.053 71.4%, 1.042 75.0%, 1.032 78.6%, 1.023 82.1%, 1.014 85.7%, 1.008 89.3%, 1.002 92.9%, 0.998 96.4%, 0.996);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);     /* 往返：進度/循環 */
}

/* 跨文件頁面轉場（Chrome 126+）：換頁不再是硬切 */
@view-transition { navigation: auto; }

html { scroll-behavior: smooth; }

/* 觸控即時反饋：去掉點擊高亮與手勢延遲 */
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* ---------- 頁面進場 ---------- */
@keyframes page-enter {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
main { animation: page-enter var(--dur-slow) var(--ease-out) both; }

/* ---------- 列表 stagger 進場（容器加 .stagger） ---------- */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.stagger > * { animation: rise-in var(--dur-base) var(--ease-out) both; }
.stagger > *:nth-child(1)  { animation-delay: 0ms; }
.stagger > *:nth-child(2)  { animation-delay: 45ms; }
.stagger > *:nth-child(3)  { animation-delay: 90ms; }
.stagger > *:nth-child(4)  { animation-delay: 135ms; }
.stagger > *:nth-child(5)  { animation-delay: 180ms; }
.stagger > *:nth-child(6)  { animation-delay: 225ms; }
.stagger > *:nth-child(7)  { animation-delay: 270ms; }
.stagger > *:nth-child(8)  { animation-delay: 315ms; }
.stagger > *:nth-child(9)  { animation-delay: 360ms; }
.stagger > *:nth-child(10) { animation-delay: 405ms; }
.stagger > *:nth-child(11) { animation-delay: 450ms; }
.stagger > *:nth-child(12) { animation-delay: 495ms; }

/* ---------- 彈出（對話框/結算卡）：真彈簧 ---------- */
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.pop-in { animation: pop-in var(--dur-spring) var(--ease-spring-hard) both; }

/* ---------- 全站按鈕：按壓回饋（取代各頁零散的 transition） ---------- */
button {
  transition: transform var(--dur-spring) var(--ease-spring-hard),
              background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out);
}
button:active:not(:disabled) { transform: scale(0.94); transition-duration: var(--dur-instant); }
button:disabled { cursor: default; }

/* ---------- 卡片浮起：離開時彈簧回位 ---------- */
.lift { transition: transform var(--dur-spring) var(--ease-spring-hard), box-shadow var(--dur-base) var(--ease-out); }
.lift:hover { transform: translateY(-3px); }

/* ---------- 懸浮對話窗開合：彈簧 ---------- */
#fc-panel { transform-origin: bottom right; }
#fc-panel.open { animation: pop-in var(--dur-spring) var(--ease-spring-hard) both; }

/* ---------- 骨架載入 ---------- */
@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position: 200% 0; }
}
.shimmer {
  background: linear-gradient(90deg, var(--wash-04) 25%, var(--wash-10) 50%, var(--wash-04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s var(--ease-in-out) infinite;
  border-radius: 8px;
  color: transparent !important;
}

/* ---------- 進度條：一律用 scaleX（不觸發重排） ---------- */
.bar-fill {
  transform-origin: left center;
  transition: transform var(--dur-slow) var(--ease-in-out);
}

/* ---------- 減少動態偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
