/*
 * LITU Animation Library v0.1
 * 
 * 六大核心動畫
 * 風格：溫暖、輕快、學習感、收藏感
 * 色彩：橘色/金色/白色為主，答對綠色，答錯柔和紅
 * easing：ease-out, cubic-bezier(0.2, 0.8, 0.2, 1)
 * 支援 prefers-reduced-motion
 */

/* ============================================
   全局變數
   ============================================ */
:root {
  /* 色彩 */
  --litu-orange: #FF8C42;
  --litu-gold: #FFD700;
  --litu-white: #FFF8F0;
  --litu-green: #4CAF50;
  --litu-red-soft: #E57373;
  --litu-bg: #FFFDF9;
  
  /* 動畫時長 */
  --litu-fast: 0.16s;
  --litu-normal: 0.4s;
  --litu-medium: 0.8s;
  --litu-slow: 1.2s;
  
  /* easing */
  --litu-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ============================================
   1. 答對動畫（Correct Answer）
   觸發：學生選到正確答案
   效果：選項亮綠、輕微放大、XP 小跳出
   時長：0.4-0.7s
   ============================================ */

.litu-option {
  transition: all var(--litu-normal) var(--litu-ease);
  border-radius: 12px;
  padding: 16px 20px;
  border: 2px solid #E0E0E0;
  background: white;
}

.litu-option.correct {
  border-color: var(--litu-green);
  background: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 100%);
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
}

.litu-option.correct .option-text {
  animation: litu-correct-text-pop var(--litu-normal) var(--litu-ease);
}

@keyframes litu-correct-text-pop {
  0% { transform: translateY(0); opacity: 1; }
  30% { transform: translateY(-4px); opacity: 0.8; }
  100% { transform: translateY(0); opacity: 1; }
}

/* XP 小跳出 */
.litu-xp-popup {
  position: absolute;
  top: -30px;
  right: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--litu-green);
  opacity: 0;
  pointer-events: none;
}

.litu-xp-popup.show {
  animation: litu-xp-rise var(--litu-medium) var(--litu-ease) forwards;
}

@keyframes litu-xp-rise {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
  }
  20% {
    opacity: 1;
    transform: translateY(0) scale(1.1);
  }
  80% {
    opacity: 1;
    transform: translateY(-10px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(0.9);
  }
}

/* 綠色光芒掃過 */
.litu-option.correct::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  animation: litu-shine-sweep var(--litu-normal) var(--litu-ease) forwards;
  pointer-events: none;
}

@keyframes litu-shine-sweep {
  0% { left: -100%; }
  100% { left: 200%; }
}


/* ============================================
   2. 答錯動畫（Wrong Answer）
   觸發：學生選錯
   效果：選項輕微左右晃、紅心扣除
   時長：0.35-0.6s
   ============================================ */

.litu-option.wrong {
  border-color: var(--litu-red-soft);
  background: linear-gradient(135deg, #FFEBEE 0%, #FFCDD2 100%);
  animation: litu-wrong-shake var(--litu-normal) var(--litu-ease);
}

@keyframes litu-wrong-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

/* 紅心扣除 */
.litu-heart {
  display: inline-block;
  transition: transform var(--litu-fast) var(--litu-ease);
}

.litu-heart.deduct {
  animation: litu-heart-pulse var(--litu-normal) var(--litu-ease);
}

@keyframes litu-heart-pulse {
  0% { transform: scale(1); opacity: 1; }
  30% { transform: scale(1.3); opacity: 1; }
  60% { transform: scale(0.85); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

/* 紅心耗盡彈窗 */
.litu-heart-empty-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--litu-normal) var(--litu-ease);
}

.litu-heart-empty-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.litu-heart-empty-modal .modal-content {
  background: white;
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 320px;
  transform: scale(0.9);
  transition: transform var(--litu-normal) var(--litu-ease);
}

.litu-heart-empty-modal.show .modal-content {
  transform: scale(1);
}


/* ============================================
   3. 悟幣獲得動畫（Coin Earned）
   觸發：完成任務、完美答題
   效果：悟幣從題卡飛到資產區
   時長：0.8-1.2s
   ============================================ */

.litu-coin-fly {
  position: fixed;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF176, var(--litu-gold));
  border: 3px solid #F9A825;
  box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
  z-index: 9999;
  pointer-events: none;
  opacity: 1;
}

.litu-coin-fly.fly {
  animation: litu-coin-travel var(--litu-slow) var(--litu-ease) forwards;
}

@keyframes litu-coin-travel {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  60% {
    transform: scale(1.2) rotate(360deg);
    opacity: 1;
  }
  100% {
    transform: scale(0.6) rotate(720deg);
    opacity: 0;
  }
}

/* 資產區悟幣數字跳動 */
.litu-coin-display {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.litu-coin-display .coin-count {
  display: inline-block;
  transition: transform var(--litu-fast) var(--litu-ease);
}

.litu-coin-display.bump .coin-count {
  animation: litu-coin-bump var(--litu-medium) var(--litu-ease);
}

@keyframes litu-coin-bump {
  0% { transform: scale(1); }
  30% { transform: scale(1.4); color: var(--litu-gold); }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* 悟幣旋轉 */
.litu-coin-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  background: radial-gradient(circle at 35% 35%, #FFF176, var(--litu-gold));
  border-radius: 50%;
  border: 2px solid #F9A825;
  vertical-align: middle;
}

.litu-coin-icon.spin {
  animation: litu-coin-spin var(--litu-normal) var(--litu-ease);
}

@keyframes litu-coin-spin {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(720deg); }
}


/* ============================================
   4. 連勝成功動畫（Streak Success）
   觸發：今日任務完成
   效果：火焰變亮、天數跳動
   時長：0.8-1.4s
   ============================================ */

.litu-streak-flame {
  display: inline-block;
  font-size: 32px;
  line-height: 1;
  filter: brightness(0.8);
  transition: filter var(--litu-medium) var(--litu-ease), transform var(--litu-normal) var(--litu-ease);
}

.litu-streak-flame.active {
  filter: brightness(1.3) drop-shadow(0 0 8px rgba(255, 140, 66, 0.8));
  animation: litu-streak-flame-pulse var(--litu-medium) var(--litu-ease);
}

@keyframes litu-streak-flame-pulse {
  0% { transform: scale(1); }
  25% { transform: scale(1.3); }
  50% { transform: scale(0.95); }
  75% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* 天數數字跳動 */
.litu-streak-day {
  display: inline-block;
  font-size: 24px;
  font-weight: 700;
  color: var(--litu-orange);
  transition: transform var(--litu-normal) var(--litu-ease);
}

.litu-streak-day.jump {
  animation: litu-streak-jump var(--litu-medium) var(--litu-ease);
}

@keyframes litu-streak-jump {
  0% { transform: translateY(0) scale(1); }
  20% { transform: translateY(-12px) scale(1.2); }
  50% { transform: translateY(0) scale(0.9); }
  70% { transform: translateY(-4px) scale(1.05); }
  100% { transform: translateY(0) scale(1); }
}

/* 火焰粒子效果（純 CSS） */
.litu-streak-container {
  position: relative;
  display: inline-block;
}

.litu-streak-container::before,
.litu-streak-container::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--litu-orange);
  opacity: 0;
}

.litu-streak-container.active::before {
  animation: litu-streak-particle1 var(--litu-slow) var(--litu-ease) forwards;
}

.litu-streak-container.active::after {
  animation: litu-streak-particle2 var(--litu-slow) var(--litu-ease) forwards;
}

@keyframes litu-streak-particle1 {
  0% { opacity: 1; bottom: 0; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; bottom: 30px; transform: translateX(-80%) scale(0); }
}

@keyframes litu-streak-particle2 {
  0% { opacity: 1; bottom: 0; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; bottom: 25px; transform: translateX(-20%) scale(0); }
}


/* ============================================
   5. 徽章解鎖動畫（Badge Unlocked）
   觸發：新徽章取得
   效果：徽章從小放大，金光掃過
   時長：1.0-1.5s
   ============================================ */

.litu-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FFF8E1, #FFECB3);
  border: 3px solid var(--litu-gold);
  overflow: hidden;
  transition: transform var(--litu-normal) var(--litu-ease);
}

.litu-badge.unlocked {
  animation: litu-badge-unlock var(--litu-slow) var(--litu-ease);
}

@keyframes litu-badge-unlock {
  0% {
    transform: scale(0.5) rotate(-10deg);
    opacity: 0;
  }
  40% {
    transform: scale(1.2) rotate(5deg);
    opacity: 1;
  }
  60% {
    transform: scale(0.95) rotate(-2deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

/* 金光掃過效果 */
.litu-badge::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 215, 0, 0.6), transparent, transparent);
  opacity: 0;
  pointer-events: none;
}

.litu-badge.unlocked::after {
  animation: litu-badge-shine var(--litu-slow) var(--litu-ease) forwards;
}

@keyframes litu-badge-shine {
  0% { opacity: 0; transform: rotate(0deg); }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { opacity: 0; transform: rotate(360deg); }
}

/* 徽章文字標籤 */
.litu-badge-label {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--litu-orange);
  opacity: 0;
  transform: translateY(8px);
  transition: all var(--litu-normal) var(--litu-ease);
}

.litu-badge.unlocked + .litu-badge-label {
  opacity: 1;
  transform: translateY(0);
}

/* 多個徽章彈出序列 */
.litu-badge:nth-child(1).unlocked { animation-delay: 0s; }
.litu-badge:nth-child(2).unlocked { animation-delay: 0.15s; }
.litu-badge:nth-child(3).unlocked { animation-delay: 0.3s; }
.litu-badge:nth-child(4).unlocked { animation-delay: 0.45s; }
.litu-badge:nth-child(5).unlocked { animation-delay: 0.6s; }


/* ============================================
   6. 角色待機動畫（Idle Character）
   觸發：首頁、學習路徑
   效果：眨眼、微微浮動、偶爾揮手
   時長：2-4s loop
   ============================================ */

.litu-character {
  position: relative;
  display: inline-block;
  animation: litu-character-float 3s ease-in-out infinite;
}

@keyframes litu-character-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* 眨眼效果 */
.litu-character .eye {
  display: inline-block;
  animation: litu-character-blink 4s ease-in-out infinite;
}

@keyframes litu-character-blink {
  0%, 42%, 48%, 100% { transform: scaleY(1); }
  45% { transform: scaleY(0.1); }
}

/* 揮手效果 */
.litu-character .wave-hand {
  position: absolute;
  right: -12px;
  top: 10px;
  transform-origin: bottom center;
  animation: litu-character-wave 3s ease-in-out infinite;
  animation-delay: 2s;
}

@keyframes litu-character-wave {
  0%, 60%, 100% { transform: rotate(0deg); }
  65% { transform: rotate(20deg); }
  70% { transform: rotate(-15deg); }
  75% { transform: rotate(20deg); }
  80% { transform: rotate(-10deg); }
  85% { transform: rotate(10deg); }
  90% { transform: rotate(0deg); }
}

/* 角色呼吸效果 */
.litu-character .body {
  animation: litu-character-breathe 2.5s ease-in-out infinite;
}

@keyframes litu-character-breathe {
  0%, 100% { transform: scaleX(1) scaleY(1); }
  50% { transform: scaleX(1.03) scaleY(0.97); }
}


/* ============================================
   減少動畫偏好（Accessibility）
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .litu-option.correct {
    transform: scale(1.01);
  }
  
  .litu-option.wrong {
    animation: none;
    transform: translateX(-2px);
  }
}


/* ============================================
   載入動畫（Loading Spinner）
   小火焰呼吸動畫
   ============================================ */

.litu-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.litu-loading .loading-flame {
  font-size: 20px;
  animation: litu-loading-breathe 1.5s ease-in-out infinite;
}

@keyframes litu-loading-breathe {
  0%, 100% { 
    transform: scale(1);
    filter: brightness(0.8);
  }
  50% { 
    transform: scale(1.2);
    filter: brightness(1.3) drop-shadow(0 0 4px rgba(255, 140, 66, 0.6));
  }
}

.litu-loading .loading-text {
  font-size: 14px;
  color: #666;
}


/* ============================================
   解析展開動畫（Explanation Reveal）
   觸發：答題後顯示解析
   效果：從下方淡入
   時長：0.2-0.3s
   ============================================ */

.litu-explanation {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height var(--litu-normal) var(--litu-ease),
              opacity var(--litu-normal) var(--litu-ease),
              margin-top var(--litu-normal) var(--litu-ease);
  margin-top: 0;
}

.litu-explanation.revealed {
  max-height: 800px;
  opacity: 1;
  margin-top: 16px;
}

.litu-explanation .explanation-content {
  transform: translateY(10px);
  transition: transform var(--litu-normal) var(--litu-ease);
}

.litu-explanation.revealed .explanation-content {
  transform: translateY(0);
}


/* ============================================
   點擊回饋（Click Feedback）
   ============================================ */

.litu-clickable {
  transition: transform var(--litu-fast) var(--litu-ease);
  cursor: pointer;
}

.litu-clickable:active {
  transform: scale(0.96);
}


/* ============================================
   頁面轉場（Page Transition）
   ============================================ */

.litu-page-enter {
  animation: litu-page-enter var(--litu-medium) var(--litu-ease) forwards;
}

@keyframes litu-page-enter {
  0% {
    opacity: 0;
    transform: translateY(16px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.litu-page-exit {
  animation: litu-page-exit var(--litu-medium) var(--litu-ease) forwards;
}

@keyframes litu-page-exit {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-20px);
  }
}


/* ============================================
   難度升級動畫（Difficulty Upgrade）
   觸發：學生表現穩定
   效果：難度標籤從初級升到中級/高級
   時長：0.6-1.0s
   ============================================ */

.litu-difficulty-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--litu-normal) var(--litu-ease);
}

.litu-difficulty-tag.upgrade {
  animation: litu-difficulty-upgrade var(--litu-medium) var(--litu-ease);
}

@keyframes litu-difficulty-upgrade {
  0% { transform: scale(1); }
  20% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* 難度等級色彩 */
.litu-difficulty-tag.beginner { background: #E8F5E9; color: #2E7D32; }
.litu-difficulty-tag.intermediate { background: #FFF3E0; color: #EF6C00; }
.litu-difficulty-tag.advanced { background: #FCE4EC; color: #C62828; }


/* ============================================
   每日任務完成動畫（Daily Task Complete）
   觸發：今日目標完成
   效果：任務卡片蓋章、悟幣跳出
   時長：1.0-1.5s
   ============================================ */

.litu-task-card {
  position: relative;
  overflow: hidden;
}

.litu-task-card .stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--litu-green), #388E3C);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 28px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
}

.litu-task-card.complete .stamp {
  animation: litu-task-stamp var(--litu-medium) var(--litu-ease) forwards;
}

@keyframes litu-task-stamp {
  0% {
    transform: translate(-50%, -50%) scale(0) rotate(-30deg);
    opacity: 0;
  }
  40% {
    transform: translate(-50%, -50%) scale(1.3) rotate(5deg);
    opacity: 1;
  }
  70% {
    transform: translate(-50%, -50%) scale(0.9) rotate(-2deg);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
    opacity: 1;
  }
}


/* ============================================
   排行榜名次變化（Rank Change）
   觸發：名次上升
   效果：名次列短暫高亮，上升箭頭
   時長：0.5-0.9s
   ============================================ */

.litu-rank-item {
  transition: background var(--litu-normal) var(--litu-ease);
}

.litu-rank-item.rising {
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.15), transparent);
  animation: litu-rank-rise var(--litu-normal) var(--litu-ease);
}

@keyframes litu-rank-rise {
  0% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  60% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

.litu-rank-arrow {
  display: inline-block;
  color: var(--litu-green);
  font-size: 16px;
  opacity: 0;
  transition: opacity var(--litu-fast) var(--litu-ease);
}

.litu-rank-item.rising .litu-rank-arrow {
  animation: litu-rank-arrow-show var(--litu-medium) var(--litu-ease) forwards;
}

@keyframes litu-rank-arrow-show {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}


/* ============================================
   單元解鎖動畫（Unit Unlock）
   觸發：新單元可練
   效果：鎖頭打開、路徑節點亮起
   時長：0.8-1.3s
   ============================================ */

.litu-unit-node {
  position: relative;
  transition: all var(--litu-normal) var(--litu-ease);
}

.litu-unit-node.locked {
  opacity: 0.4;
  filter: grayscale(1);
}

.litu-unit-node.unlocking {
  animation: litu-unit-unlock var(--litu-medium) var(--litu-ease);
}

@keyframes litu-unit-unlock {
  0% {
    opacity: 0.4;
    filter: grayscale(1);
    transform: scale(0.9);
  }
  40% {
    opacity: 1;
    filter: grayscale(0);
    transform: scale(1.1);
  }
  70% {
    transform: scale(0.95);
  }
  100% {
    opacity: 1;
    filter: grayscale(0);
    transform: scale(1);
  }
}

/* 鎖頭打開效果 */
.litu-unit-node .lock-icon {
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 16px;
  transition: all var(--litu-normal) var(--litu-ease);
}

.litu-unit-node.unlocked .lock-icon {
  animation: litu-lock-open var(--litu-normal) var(--litu-ease) forwards;
}

@keyframes litu-lock-open {
  0% { transform: rotate(0deg) scale(1); opacity: 1; }
  50% { transform: rotate(-20deg) scale(1.2); opacity: 0.8; }
  100% { transform: rotate(-40deg) scale(0); opacity: 0; }
}


/* ============================================
   稱號解鎖動畫（Title Unlocked）
   觸發：新稱號取得
   效果：稱號牌滑入、短暫發光
   時長：0.8-1.2s
   ============================================ */

.litu-title-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, #FFF8E1, #FFE082);
  border: 2px solid var(--litu-gold);
  font-size: 14px;
  font-weight: 600;
  color: #5D4037;
  opacity: 0;
  transform: translateX(-20px);
  transition: all var(--litu-normal) var(--litu-ease);
}

.litu-title-badge.revealed {
  opacity: 1;
  transform: translateX(0);
}

.litu-title-badge.new {
  animation: litu-title-glow var(--litu-slow) var(--litu-ease);
}

@keyframes litu-title-glow {
  0% { box-shadow: 0 0 0 rgba(255, 215, 0, 0); }
  30% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.6); }
  60% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.3); }
  100% { box-shadow: 0 0 0 rgba(255, 215, 0, 0); }
}
