:root {
  --bg: #f0f4ff;
  --card: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3b57d9;
  --accent: #ff9f43;
  --success: #2ecc71;
  --danger: #e74c3c;
  --text: #2d3436;
  --muted: #636e72;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(79, 110, 247, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #eef2ff 0%, #fdf2f8 100%);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.brand-icon { font-size: 24px; }

.user-stats { display: flex; gap: 8px; }

.stat-pill {
  background: var(--card);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 12px 12px;
}

.tab {
  border: none;
  background: rgba(255,255,255,0.7);
  border-radius: 14px;
  padding: 10px 4px;
  font-size: 12px;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.main {
  flex: 1;
  padding: 0 16px 24px;
}

.page { display: none; }
.page.active { display: block; }

.page-title {
  font-size: 22px;
  margin-bottom: 6px;
}

.page-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.page-header h2 { flex: 1; font-size: 20px; }

.step-badge {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.module-grid {
  display: grid;
  gap: 14px;
}

.module-grid.compact .module-card { padding: 14px; }

.module-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s;
}

.module-card:active { transform: scale(0.98); }

.module-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.module-icon { font-size: 32px; }

.module-name { font-size: 18px; font-weight: 700; }

.module-desc {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.module-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.stars-row { color: #f39c12; }

.flashcard, .quiz-card, .result-card, .story-stage {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.flashcard-image, .quiz-image, .story-image {
  width: 100%;
  max-width: 220px;
  height: 160px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, #dfe6ff, #fce7f3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  overflow: hidden;
}

.flashcard-image.icon-mode img, .quiz-image.icon-mode img, .story-image.icon-mode img {
  width: 88px;
  height: 88px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(79, 110, 247, 0.15));
}

.flashcard-image.icon-mode, .quiz-image.icon-mode, .story-image.icon-mode {
  background: linear-gradient(135deg, #eef2ff, #f3e8ff);
}

.flashcard-image.photo-mode, .quiz-image.photo-mode, .story-image.photo-mode {
  background: #fff;
  border: 1px solid #e8ecf8;
}

.flashcard-image.photo-mode img, .quiz-image.photo-mode img, .story-image.photo-mode img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 12px;
}

.flashcard-image img, .quiz-image img, .story-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flashcard-pos, .quiz-pos, .wrong-pos {
  display: inline-block;
  background: #eef2ff;
  color: #4f6ef7;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.quiz-pos { margin-bottom: 6px; }

.wrong-pos {
  font-size: 11px;
  padding: 2px 8px;
  margin-right: 6px;
  vertical-align: middle;
}

.flashcard-word {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.flashcard-phonetic {
  font-size: 18px;
  color: #6c5ce7;
  font-family: "Lucida Sans Unicode", "Arial Unicode MS", "Segoe UI", sans-serif;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.flashcard-meaning {
  font-size: 18px;
  color: var(--muted);
  margin-bottom: 16px;
}

.btn, .btn-audio, .btn-back {
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-size: 15px;
}

.btn {
  padding: 12px 20px;
  font-weight: 600;
}

.btn-block { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-secondary {
  background: #edf2ff;
  color: var(--primary);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-audio {
  background: #eef2ff;
  color: var(--primary);
  padding: 10px 18px;
  margin-bottom: 12px;
}

.btn-back {
  background: transparent;
  color: var(--muted);
  padding: 6px 0;
}

.flashcard-actions, .story-actions {
  display: flex;
  gap: 10px;
  margin: 16px 0;
}

.flashcard-actions .btn, .story-actions .btn { flex: 1; }

.story-sentence {
  font-size: 20px;
  line-height: 1.5;
  margin-bottom: 8px;
  min-height: 60px;
}

.story-sentence-zh {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 16px;
}

.story-progress {
  height: 8px;
  background: #edf2ff;
  border-radius: 999px;
  overflow: hidden;
}

.story-progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0;
  transition: width .3s;
}

.quiz-hint {
  font-size: 28px;
  letter-spacing: 4px;
  font-weight: 700;
  margin: 12px 0 4px;
  color: var(--primary);
}

.quiz-phonetic {
  font-size: 16px;
  color: #6c5ce7;
  margin-bottom: 12px;
  font-family: "Lucida Sans Unicode", "Arial Unicode MS", "Segoe UI", sans-serif;
}

.quiz-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #dfe6ff;
  border-radius: 14px;
  font-size: 18px;
  text-align: center;
  margin-bottom: 12px;
  outline: none;
}

.quiz-input:focus { border-color: var(--primary); }

.quiz-feedback {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
}

.quiz-feedback.correct { background: #e9f9ef; color: var(--success); }
.quiz-feedback.wrong { background: #fdecea; color: var(--danger); }

.result-card { margin-top: 40px; }

.result-stars { font-size: 40px; margin-bottom: 12px; }

.wrong-list, .rank-list { display: grid; gap: 10px; }

.wrong-item, .rank-item {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}

.wrong-word { font-weight: 700; font-size: 18px; flex: 1; }
.wrong-phonetic { color: #6c5ce7; font-size: 13px; margin-top: 2px; }
.wrong-meaning { color: var(--muted); font-size: 13px; }

.rank-pos {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #edf2ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.rank-pos.top { background: #ffeaa7; }

.rank-info { flex: 1; }
.rank-name { font-weight: 600; }
.rank-meta { font-size: 12px; color: var(--muted); }

.rank-stars { font-weight: 700; color: #f39c12; }

.pk-panel { margin-top: 16px; }

.pk-vs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.pk-player { text-align: center; flex: 1; }
.pk-avatar { font-size: 36px; margin-bottom: 4px; }
.pk-score { font-size: 24px; font-weight: 800; color: var(--primary); }
.pk-vs-text { font-weight: 800; color: var(--muted); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

.hidden { display: none !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  background: rgba(45, 52, 54, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
}

@media (min-width: 768px) {
  #app { max-width: 640px; }
}
