/* ============================
   英语2 H5闯关课件 - 动画与特效样式
   animations.css
   ============================ */

/* ====== 1. 角色定位样式 ====== */
.character-container {
  position: fixed;
  bottom: 120px;
  z-index: 50;
  pointer-events: none;
}

.character-lily {
  right: 16px;
  animation: character-float 3s ease-in-out infinite;
}

.character-tom {
  left: 16px;
  animation: character-float 3s ease-in-out infinite 0.5s;
}

.character-lily img,
.character-tom img {
  width: 90px;
  height: 90px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.15));
}

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

/* ====== 2. 对话气泡 ====== */
.speech-bubble {
  position: relative;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 220px;
  box-shadow: var(--shadow-sm);
  animation: bubble-appear 0.4s ease-out;
  pointer-events: auto;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
}

.speech-bubble-lily {
  background: var(--success-light);
  color: #166534;
  border: 1px solid #bbf7d0;
  margin-left: auto;
}

.speech-bubble-lily::after {
  right: 20px;
  border-top: 8px solid var(--success-light);
}

.speech-bubble-tom {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #bfdbfe;
  margin-right: auto;
}

.speech-bubble-tom::after {
  left: 20px;
  border-top: 8px solid var(--primary-light);
}

@keyframes bubble-appear {
  0% { opacity: 0; transform: scale(0.85) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ====== 3. 按钮呼吸动画 ====== */
.btn-breathe {
  animation: breathe 2.5s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ====== 4. 页面转场动画 ====== */
.view-enter {
  opacity: 0;
  transform: translateX(60px);
}

.view-enter-active {
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.view-exit {
  opacity: 1;
  transform: translateX(0);
}

.view-exit-active {
  opacity: 0;
  transform: translateX(-60px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

/* ====== 5. 粒子特效容器 ====== */
.particles-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.particle {
  position: absolute;
  bottom: -10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  opacity: 0;
  animation: particle-rise 1.5s ease-out forwards;
}

.particle-star {
  width: 12px;
  height: 12px;
  background: none;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: var(--warning);
}

.particle-heart {
  width: 12px;
  height: 12px;
  background: var(--danger);
  clip-path: polygon(50% 85%, 5% 40%, 5% 20%, 25% 0%, 50% 15%, 75% 0%, 95% 20%, 95% 40%);
  border-radius: 0;
}

.particle-firework {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  box-shadow: 0 0 6px 2px var(--warning);
}

@keyframes particle-rise {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-300px) scale(0.3); }
}

/* ====== 6. 徽章样式 ====== */
.badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--warning);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  background: linear-gradient(135deg, #fef3c7, #fff);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
  transition: all 0.3s ease;
}

.badge-locked {
  border-color: var(--gray-300);
  background: var(--gray-100);
  filter: grayscale(1);
  opacity: 0.6;
  box-shadow: none;
}

.badge-unlocked {
  animation: badge-unlock 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes badge-unlock {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.badge-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 16px;
  padding: 20px;
  justify-items: center;
}

/* ====== 7. 等级标签 ====== */
.level-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.level-up-animation {
  animation: level-up 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes level-up {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.3); filter: brightness(1.5); }
  60% { transform: scale(0.95); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* ====== 8. 成长报告页 ====== */
.report-card {
  background: #fffbf0;
  border: 2px solid var(--warning);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.report-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 20px,
    rgba(245, 158, 11, 0.03) 20px,
    rgba(245, 158, 11, 0.03) 40px
  );
  pointer-events: none;
}

.report-score {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  margin: 16px 0;
}

.report-score .score-animate {
  display: inline-block;
  animation: score-count 0.6s ease-out;
}

@keyframes score-count {
  0% { transform: translateY(20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.report-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 20px;
}

.report-stats .stat-item {
  text-align: center;
  padding: 12px 8px;
  background: #fff;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
}

.report-stats .stat-item span {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

.report-stats .stat-item label {
  font-size: 0.75rem;
  color: var(--gray-500);
}

/* ====== 9. 证书页 ====== */
.certificate {
  background: linear-gradient(135deg, #fffdf7, #fff9e6);
  border: 3px solid var(--warning);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  position: relative;
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.2);
}

.certificate::before,
.certificate::after {
  content: "";
  position: absolute;
  width: 60px;
  height: 60px;
  border: 2px solid var(--warning);
  opacity: 0.4;
}

.certificate::before {
  top: 12px;
  left: 12px;
  border-right: none;
  border-bottom: none;
}

.certificate::after {
  bottom: 12px;
  right: 12px;
  border-left: none;
  border-top: none;
}

.certificate-title {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(90deg, #d97706, #f59e0b, #d97706);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
}

.certificate-content {
  font-size: 1rem;
  color: var(--gray-700);
  line-height: 1.8;
  margin-bottom: 24px;
}

.certificate-decoration {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--warning);
  font-size: 1.2rem;
  margin-top: 20px;
}

.certificate-decoration::before,
.certificate-decoration::after {
  content: "";
  width: 60px;
  height: 1px;
  background: var(--warning);
}

/* ====== 10. 拖拽组件 ====== */
.drag-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px;
  min-height: 60px;
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
}

.drag-item {
  padding: 8px 16px;
  background: #fff;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: grab;
  transition: all 0.2s ease;
  user-select: none;
}

.drag-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.drag-item:active {
  cursor: grabbing;
}

.drag-item.dragging {
  opacity: 0.5;
  transform: scale(1.05) rotate(2deg);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.drop-zone {
  min-height: 80px;
  padding: 16px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  background: var(--gray-50);
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* ====== 11. 场景切换 ====== */
.scene-container {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  min-height: 300px;
}

.scene-slide {
  animation: scene-slide-in 0.5s ease-out;
}

@keyframes scene-slide-in {
  0% { opacity: 0; transform: translateX(100%); }
  100% { opacity: 1; transform: translateX(0); }
}

.scene-office {
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
}

.scene-workshop {
  background: linear-gradient(180deg, #f0fdf4, #dcfce7);
}

/* ====== 12. 答题反馈增强 ====== */
.feedback-correct {
  animation: correct-flash 0.5s ease;
  position: relative;
}

.feedback-correct::after {
  content: "\2605";
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 1.2rem;
  color: var(--warning);
  animation: star-pop 0.4s ease-out;
}

@keyframes correct-flash {
  0% { background-color: var(--success-light); }
  50% { background-color: #86efac; }
  100% { background-color: var(--success-light); }
}

@keyframes star-pop {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.feedback-wrong {
  animation: shake 0.4s ease;
}

.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ====== 13. 剧情导入页 ====== */
.story-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #1e293b, #334155);
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.story-dialogue {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
  width: 100%;
  padding: 24px 16px;
}

.story-dialogue-item {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: dialogue-slide-up 0.4s ease-out both;
}

.story-dialogue-item:nth-child(even) {
  flex-direction: row-reverse;
}

.story-dialogue-item .dialogue-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.story-dialogue-item .dialogue-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 75%;
}

.story-dialogue-item:nth-child(odd) .dialogue-bubble {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-bottom-left-radius: 4px;
}

.story-dialogue-item:nth-child(even) .dialogue-bubble {
  background: var(--success-light);
  color: #166534;
  border-bottom-right-radius: 4px;
}

@keyframes dialogue-slide-up {
  0% { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ====== 响应式适配 ====== */
@media (max-width: 768px) {
  .character-lily img,
  .character-tom img {
    width: 64px;
    height: 64px;
  }

  .character-container {
    bottom: 80px;
  }

  .speech-bubble {
    max-width: 160px;
    font-size: 0.8rem;
    padding: 8px 12px;
  }

  .badge {
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
  }

  .badge-gallery {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 12px;
    padding: 12px;
  }

  .report-stats {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .certificate {
    padding: 24px 16px;
  }

  .certificate-title {
    font-size: 1.2rem;
  }

  .story-dialogue {
    padding: 16px 8px;
  }

  .drag-item {
    padding: 6px 12px;
    font-size: 0.82rem;
  }
}

/* ====== 无障碍：减弱动画 ====== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .character-lily,
  .character-tom {
    animation: none;
  }

  .btn-breathe {
    animation: none;
  }

  .view-enter-active,
  .view-exit-active {
    transition: none;
  }

  .particle {
    animation: none;
    display: none;
  }
}
