/* ===== 全局重置与基础样式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

:root {
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --primary-dark: #5A4BD1;
  --accent: #FDCB6E;
  --success: #00B894;
  --danger: #FF7675;
  --warning: #FDCB6E;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-bg: #ffffff;
  --text-main: #2D3436;
  --text-light: #636E72;
  --shadow: 0 4px 15px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.15);
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-main);
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* ===== 页面容器 ===== */
.page {
  display: none;
  min-height: 100vh;
  padding: 16px;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

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

@keyframes correctPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); box-shadow: 0 0 20px var(--success); }
  100% { transform: scale(1); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-2deg); }
  75% { transform: translateX(6px) rotate(2deg); }
}

@keyframes starPop {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes confetti {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(400px) rotate(720deg); opacity: 0; }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px var(--accent); }
  50% { box-shadow: 0 0 20px var(--accent), 0 0 30px var(--accent); }
}

/* ===== 首页样式 ===== */
.home-header {
  text-align: center;
  padding: 30px 16px 20px;
  color: #fff;
}

.home-title {
  font-size: 28px;
  font-weight: 800;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
  margin-bottom: 6px;
}

.home-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 4px;
}

.home-mascot {
  font-size: 60px;
  animation: float 3s ease-in-out infinite;
  margin: 10px 0;
}

/* 游戏模式选择 */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.mode-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.mode-card:active {
  transform: scale(0.95);
}

.mode-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--mode-color, var(--primary));
}

.mode-icon {
  font-size: 40px;
  margin-bottom: 8px;
  display: block;
}

.mode-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.mode-desc {
  font-size: 12px;
  color: var(--text-light);
}

/* 模块选择 */
.section-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin: 16px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.module-chip {
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.module-chip.active {
  background: #fff;
  color: var(--primary);
  border-color: #fff;
  transform: scale(1.05);
}

.module-chip-icon {
  font-size: 22px;
  display: block;
  margin-bottom: 2px;
}

/* 统计卡片 */
.stats-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.stat-card {
  flex: 1;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  color: #fff;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
}

.stat-label {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
}

/* ===== 通用游戏页面 ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  color: #fff;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.back-btn:active {
  transform: scale(0.9);
  background: rgba(255,255,255,0.3);
}

.game-title {
  font-size: 18px;
  font-weight: 700;
}

.game-score {
  font-size: 16px;
  font-weight: 700;
  background: rgba(255,255,255,0.2);
  padding: 6px 14px;
  border-radius: 20px;
  color: #fff;
}

/* 进度条 */
.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
  box-shadow: 0 0 8px var(--accent);
}

/* 题目卡片 */
.question-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  margin-bottom: 16px;
  position: relative;
}

.question-emoji {
  font-size: 56px;
  margin-bottom: 12px;
  display: block;
  animation: float 2s ease-in-out infinite;
}

.question-word {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.question-cn {
  font-size: 18px;
  color: var(--text-light);
}

.question-hint {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 8px;
  opacity: 0.7;
}

/* ===== 答题选项 ===== */
.options-grid {
  display: grid;
  gap: 10px;
}

.options-grid.cols-2 {
  grid-template-columns: 1fr 1fr;
}

.option-btn {
  background: var(--card-bg);
  border: 2px solid #E9EEF2;
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.option-btn:active {
  transform: scale(0.96);
}

.option-btn.correct {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
  animation: correctPulse 0.5s ease;
}

.option-btn.wrong {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  animation: wrongShake 0.4s ease;
}

.option-btn.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.option-emoji {
  font-size: 22px;
}

/* ===== 拼写游戏 ===== */
.spell-display {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.letter-box {
  width: 42px;
  height: 50px;
  border: 3px solid var(--primary-light);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  background: #F8F7FF;
  transition: all 0.3s;
}

.letter-box.filled {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  animation: pop 0.3s ease;
}

.letter-box.hint {
  background: var(--accent);
  color: var(--text-main);
  border-color: var(--accent);
}

.letter-tiles {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.letter-tile {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 3px 8px rgba(108,92,231,0.3);
  text-transform: uppercase;
}

.letter-tile:active {
  transform: scale(0.9);
}

.letter-tile.used {
  opacity: 0.3;
  pointer-events: none;
  transform: scale(0.85);
}

.spell-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.spell-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.spell-btn:active {
  transform: scale(0.96);
}

.btn-speak {
  background: var(--accent);
  color: var(--text-main);
}

.btn-clear {
  background: #E9EEF2;
  color: var(--text-light);
}

/* ===== 消消乐 ===== */
.match-game {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.match-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  border: 3px solid transparent;
  position: relative;
}

.match-card:active {
  transform: scale(0.95);
}

.match-card.selected {
  border-color: var(--primary);
  background: #F0EDFF;
  animation: pop 0.3s ease;
}

.match-card.matched {
  opacity: 0.3;
  pointer-events: none;
  background: var(--success);
  color: #fff;
}

.match-card.wrong {
  border-color: var(--danger);
  background: #FFF0F0;
  animation: shake 0.4s ease;
}

.match-card .emoji {
  font-size: 24px;
  margin-right: 4px;
}

/* ===== 反馈层 ===== */
.feedback-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  pointer-events: none;
}

.feedback-overlay.show {
  display: flex;
}

.feedback-icon {
  font-size: 80px;
  animation: pop 0.4s ease;
}

.feedback-correct {
  color: var(--success);
}

.feedback-wrong {
  color: var(--danger);
}

/* ===== 结果页 ===== */
.result-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 30px 24px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  margin-top: 60px;
}

.result-emoji {
  font-size: 64px;
  margin-bottom: 12px;
  display: block;
  animation: bounce 1s ease infinite;
}

.result-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 8px;
}

.result-score {
  font-size: 48px;
  font-weight: 900;
  color: var(--primary);
  margin: 16px 0;
}

.result-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
}

.result-star {
  font-size: 36px;
  opacity: 0.2;
  transition: all 0.3s;
}

.result-star.earned {
  opacity: 1;
  animation: starPop 0.5s ease;
}

.result-detail {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  gap: 10px;
}

.btn-primary {
  flex: 1;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:active {
  transform: scale(0.96);
  background: var(--primary-dark);
}

.btn-secondary {
  flex: 1;
  padding: 14px;
  background: #E9EEF2;
  color: var(--text-main);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:active {
  transform: scale(0.96);
}

/* ===== 彩纸特效 ===== */
.confetti-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 998;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  animation: confetti 2s ease-out forwards;
}

/* ===== 听音按钮 ===== */
.speak-btn-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  color: #fff;
  font-size: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  box-shadow: 0 6px 20px rgba(108,92,231,0.4);
  transition: all 0.2s;
  animation: glow 2s ease-in-out infinite;
}

.speak-btn-large:active {
  transform: scale(0.9);
}

/* ===== 连续答对提示 ===== */
.streak-badge {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #FF6B6B, #FF8E53);
  color: #fff;
  padding: 6px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 15px rgba(255,107,107,0.4);
  animation: pop 0.3s ease;
}

.streak-badge.show {
  display: block;
}

/* ===== 响应式 ===== */
@media (max-width: 360px) {
  .home-title { font-size: 24px; }
  .mode-icon { font-size: 34px; }
  .question-emoji { font-size: 48px; }
  .question-word { font-size: 28px; }
  .letter-box { width: 36px; height: 42px; font-size: 20px; }
  .letter-tile { width: 42px; height: 42px; font-size: 19px; }
}

/* loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s;
}

.loading-overlay.hide {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  font-size: 48px;
  animation: float 1s ease-in-out infinite;
}
