/* ===== 数学大冒险 - 移动端样式 ===== */

:root {
  --primary: #4A90D9;
  --primary-dark: #3578C0;
  --primary-light: #E8F2FC;
  --success: #52C41A;
  --success-light: #F6FFED;
  --danger: #FF4D4F;
  --danger-light: #FFF2F0;
  --warning: #FAAD14;
  --warning-light: #FFFBE6;
  --purple: #722ED1;
  --purple-light: #F9F0FF;
  --orange: #FA8C16;
  --orange-light: #FFF7E6;
  --teal: #13C2C2;
  --teal-light: #E6FFFB;
  --bg: #F0F4F8;
  --card: #FFFFFF;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --border: #E8E8E8;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.12);
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

/* ===== 通用动画 ===== */
@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

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

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes popIn {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes starPop {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  50% { transform: scale(1.3) rotate(0deg); }
  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; }
}

.page {
  animation: slideIn 0.3s ease-out;
  padding-bottom: 20px;
}

/* ===== 顶部导航栏 ===== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(74,144,217,0.3);
}

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

.navbar .back-btn:active {
  background: rgba(255,255,255,0.35);
}

.navbar .nav-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbar .nav-stars {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ===== 首页 ===== */
.home-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 40px 20px 30px;
  text-align: center;
  border-radius: 0 0 30px 30px;
  position: relative;
  overflow: hidden;
}

.home-header::after {
  content: '';
  position: absolute;
  top: -20px;
  right: -30px;
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.home-header::before {
  content: '';
  position: absolute;
  bottom: -40px;
  left: -20px;
  width: 80px;
  height: 80px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
}

.home-header h1 {
  font-size: 28px;
  margin-bottom: 6px;
  position: relative;
  z-index: 1;
}

.home-header p {
  font-size: 14px;
  opacity: 0.9;
  position: relative;
  z-index: 1;
}

.home-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 16px;
  position: relative;
  z-index: 1;
}

.home-stat {
  text-align: center;
}

.home-stat .num {
  font-size: 22px;
  font-weight: 700;
}

.home-stat .label {
  font-size: 12px;
  opacity: 0.8;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  padding: 20px 16px 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .emoji {
  font-size: 22px;
}

/* ===== 教材选择卡片 ===== */
.textbook-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 16px;
}

.textbook-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border-left: 5px solid var(--primary);
  animation: slideUp 0.4s ease-out;
}

.textbook-card:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-lg);
}

.textbook-card .tb-icon {
  font-size: 40px;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.textbook-card .tb-info {
  flex: 1;
}

.textbook-card .tb-name {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.textbook-card .tb-desc {
  font-size: 13px;
  color: var(--text-light);
}

.textbook-card .tb-arrow {
  font-size: 20px;
  color: var(--text-light);
  flex-shrink: 0;
}

.textbook-card .tb-progress {
  margin-top: 8px;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.textbook-card .tb-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 3px;
  transition: width 0.5s;
}

/* 不同教材卡片颜色 */
.textbook-card[data-color="orange"] {
  border-left-color: var(--orange);
}
.textbook-card[data-color="orange"] .tb-icon {
  background: var(--orange-light);
}

/* ===== 单元列表 ===== */
.unit-list {
  padding: 0 16px;
}

.unit-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: slideUp 0.4s ease-out;
}

.unit-card:active {
  transform: scale(0.97);
}

.unit-card .unit-icon {
  font-size: 32px;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  border-radius: 12px;
  flex-shrink: 0;
}

.unit-card .unit-info {
  flex: 1;
}

.unit-card .unit-name {
  font-size: 16px;
  font-weight: 600;
}

.unit-card .unit-meta {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 2px;
}

.unit-card .unit-stars {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.unit-card .unit-stars .star {
  font-size: 16px;
}

.unit-card .unit-stars .star.earned {
  color: var(--warning);
}

.unit-card .unit-stars .star.empty {
  color: var(--border);
}

/* ===== 游戏列表 ===== */
.game-list {
  padding: 0 16px;
}

.game-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: slideUp 0.4s ease-out;
  position: relative;
  overflow: hidden;
}

.game-card:active {
  transform: scale(0.97);
}

.game-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--primary);
}

.game-card[data-type="choice"]::before { background: var(--primary); }
.game-card[data-type="input"]::before { background: var(--orange); }
.game-card[data-type="judge"]::before { background: var(--purple); }
.game-card[data-type="compare"]::before { background: var(--teal); }
.game-card[data-type="sort"]::before { background: var(--success); }

.game-card .game-info {
  flex: 1;
}

.game-card .game-name {
  font-size: 16px;
  font-weight: 600;
}

.game-card .game-desc {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 2px;
}

.game-card .game-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 4px;
}

.game-card[data-type="choice"] .game-badge { background: var(--primary-light); color: var(--primary); }
.game-card[data-type="input"] .game-badge { background: var(--orange-light); color: var(--orange); }
.game-card[data-type="judge"] .game-badge { background: var(--purple-light); color: var(--purple); }
.game-card[data-type="compare"] .game-badge { background: var(--teal-light); color: var(--teal); }
.game-card[data-type="sort"] .game-badge { background: var(--success-light); color: var(--success); }

.game-card .game-stars {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.game-card .game-stars .stars-row {
  display: flex;
  gap: 2px;
}

.game-card .game-stars .star {
  font-size: 18px;
}

.game-card .game-stars .star.earned {
  color: var(--warning);
}

.game-card .game-stars .star.empty {
  color: var(--border);
}

.game-card .game-stars .game-count {
  font-size: 11px;
  color: var(--text-light);
}

/* ===== 游戏页面 ===== */
.game-container {
  padding: 16px;
}

.game-progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 16px;
}

.game-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 4px;
  transition: width 0.3s;
}

.game-question-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.game-question-info .q-num {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 500;
}

.game-question-info .q-score {
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
}

.question-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  animation: slideUp 0.4s ease-out;
}

.question-text {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  margin-bottom: 20px;
}

.question-hint {
  font-size: 14px;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 16px;
}

/* 选项 */
.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 17px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-family: inherit;
  color: var(--text);
}

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

.option-btn .option-label {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  color: var(--text-light);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  animation: bounce 0.4s;
}

.option-btn.correct .option-label {
  background: var(--success);
  color: #fff;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  animation: shake 0.4s;
}

.option-btn.wrong .option-label {
  background: var(--danger);
  color: #fff;
}

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

/* 填空输入 */
.input-area {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.input-area input {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 20px;
  text-align: center;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: var(--card);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}

.input-area input:focus {
  border-color: var(--primary);
}

.input-area input.correct {
  border-color: var(--success);
  background: var(--success-light);
  color: var(--success);
}

.input-area input.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  color: var(--danger);
  animation: shake 0.4s;
}

.submit-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
  flex-shrink: 0;
}

.submit-btn:active {
  background: var(--primary-dark);
}

/* 判断题 */
.judge-area {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.judge-btn {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  background: var(--card);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.judge-btn .judge-icon {
  font-size: 32px;
}

.judge-btn:active {
  transform: scale(0.95);
}

.judge-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  color: var(--success);
  animation: bounce 0.4s;
}

.judge-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  color: var(--danger);
  animation: shake 0.4s;
}

.judge-btn.disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* 比大小 */
.compare-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

.compare-num {
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  min-width: 100px;
  text-align: center;
}

.compare-btn {
  width: 60px;
  height: 60px;
  border: 2px solid var(--border);
  border-radius: 50%;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compare-btn:active {
  transform: scale(0.92);
}

.compare-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  color: var(--success);
  animation: bounce 0.4s;
}

.compare-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  color: var(--danger);
  animation: shake 0.4s;
}

.compare-btn.disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* ===== 反馈区 ===== */
.feedback {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.6;
  animation: slideUp 0.3s;
}

.feedback.correct {
  background: var(--success-light);
  color: var(--success);
  border-left: 4px solid var(--success);
}

.feedback.wrong {
  background: var(--danger-light);
  color: var(--danger);
  border-left: 4px solid var(--danger);
}

.feedback .feedback-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.next-btn {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin-top: 12px;
  transition: background 0.2s;
}

.next-btn:active {
  background: var(--primary-dark);
}

/* ===== 结果页 ===== */
.result-container {
  padding: 24px 16px;
  text-align: center;
  min-height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.result-emoji {
  font-size: 72px;
  animation: popIn 0.6s;
  margin-bottom: 16px;
}

.result-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

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

.result-stars {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  justify-content: center;
}

.result-stars .star {
  font-size: 48px;
  color: var(--border);
}

.result-stars .star.earned {
  color: var(--warning);
  animation: starPop 0.6s;
}

.result-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
  width: 100%;
  max-width: 320px;
}

.result-stat {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
}

.result-stat .stat-num {
  font-size: 24px;
  font-weight: 700;
}

.result-stat .stat-label {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

.result-stat.correct .stat-num { color: var(--success); }
.result-stat.wrong .stat-num { color: var(--danger); }
.result-stat.accuracy .stat-num { color: var(--primary); }

.result-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.result-actions button {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-retry {
  background: var(--card);
  color: var(--primary);
  border: 2px solid var(--primary) !important;
}

.btn-retry:active {
  background: var(--primary-light);
}

.btn-back {
  background: var(--primary);
  color: #fff;
}

.btn-back:active {
  background: var(--primary-dark);
}

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

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

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

/* ===== 响应式 ===== */
@media (min-width: 481px) {
  #app {
    box-shadow: 0 0 40px rgba(0,0,0,0.1);
  }
}

/* 防止移动端点击高亮 */
button, .option-btn, .judge-btn, .compare-btn, .unit-card, .game-card, .textbook-card {
  -webkit-tap-highlight-color: transparent;
}

/* 输入框允许选择文本 */
input {
  -webkit-user-select: text;
  user-select: text;
}
