/* ═══════════════════════════════════════════════════════════
   English Practice PWA — Styles
   Color palette:
     Primary  : #6C63FF (purple)
     Accent   : #FF6B6B (coral)
     Success  : #43D98E (green)
     Dark bg  : #1a1a2e
     Card bg  : #16213e
     Surface  : #0f3460
   ═══════════════════════════════════════════════════════════ */

/* ─── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #6C63FF;
  --primary-light: #8b84ff;
  --accent:    #FF6B6B;
  --success:   #43D98E;
  --warning:   #FFB347;
  --danger:    #FF4757;
  --bg:        #1a1a2e;
  --card:      #16213e;
  --surface:   #0f3460;
  --text:      #e8e8f0;
  --text-dim:  #8888aa;
  --border:    rgba(108,99,255,0.25);
  --radius:    16px;
  --radius-sm: 10px;
  --shadow:    0 8px 32px rgba(0,0,0,0.4);
  --nav-h:     68px;
  --header-h:  60px;
}

html { font-size: 16px; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ─── App Shell ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

.top-bar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar-title {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.install-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  color: white;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: var(--nav-h);
}

/* ─── Tab Contents ──────────────────────────────────────── */
.tab-content {
  display: none;
  padding: 20px 16px;
  min-height: calc(100svh - var(--header-h) - var(--nav-h));
  animation: fadeIn 0.25s ease;
}
.tab-content.active { display: block; }

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

/* ─── Bottom Nav ────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 200;
  backdrop-filter: blur(10px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px 4px 10px;
  transition: all 0.2s;
  border: none;
  background: none;
  color: var(--text-dim);
}

.nav-item .nav-icon { font-size: 1.4rem; transition: transform 0.2s; }
.nav-item .nav-label { font-size: 0.7rem; font-weight: 500; }

.nav-item.active {
  color: var(--primary-light);
}
.nav-item.active .nav-icon {
  transform: translateY(-2px);
}

/* ─── ─── HOME TAB ─── ─── */

/* Greeting */
.home-greeting {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.home-greeting h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.home-greeting p  { font-size: 0.85rem; color: var(--text-dim); }
.greeting-date    { font-size: 0.8rem; color: var(--text-dim); text-align: right; }

/* Streak Card */
.streak-card {
  background: linear-gradient(135deg, #ff6b35, #ff2d55);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.streak-card::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 120px; height: 120px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
}
.streak-fire { font-size: 2.8rem; }
.streak-info { flex: 1; }
.streak-count { font-size: 2.5rem; font-weight: 800; line-height: 1; }
.streak-label { font-size: 0.85rem; opacity: 0.9; margin-top: 2px; }
.streak-badge {
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

/* XP / Level Card */
.xp-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.xp-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.xp-label { font-size: 0.85rem; color: var(--text-dim); }
.xp-value { font-size: 1.5rem; font-weight: 800; color: var(--primary-light); }
.level-name {
  font-size: 0.9rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.progress-track {
  background: rgba(108,99,255,0.15);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width 0.6s ease;
}
.xp-next { font-size: 0.75rem; color: var(--text-dim); text-align: right; }

/* Daily Goal Card */
.daily-goal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.daily-goal-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}
.daily-goal-title { font-weight: 600; font-size: 0.95rem; }
.daily-goal-count { font-size: 0.85rem; color: var(--success); font-weight: 600; }
.daily-progress-bar-wrap {
  background: rgba(67,217,142,0.12);
  border-radius: 99px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}
.daily-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #00e5a0);
  border-radius: 99px;
  transition: width 0.5s ease;
}
.daily-progress-label { font-size: 0.78rem; color: var(--text-dim); }

/* Quick Start buttons */
.quick-start {
  margin-bottom: 20px;
}
.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.quick-btn-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.quick-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.2s;
}
.quick-btn:active { transform: scale(0.96); background: var(--surface); }
.quick-btn .qb-icon { font-size: 1.6rem; }

/* Calendar */
.calendar-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.calendar-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 14px;
}
.calendar-week-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.calendar-week-labels span {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 2px;
}
.calendar-cells {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--text-dim);
  background: rgba(255,255,255,0.03);
  cursor: default;
  transition: all 0.15s;
}
.cal-day.blank { background: transparent; }
.cal-day.checked-in {
  background: linear-gradient(135deg, var(--primary), #9b59b6);
  color: white;
  font-weight: 700;
}
.cal-day.today {
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
}
.cal-day.checked-in.today {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  color: white;
}

/* ─── ─── PRACTICE TAB ─── ─── */
#tab-practice { padding: 0; }

/* Mode Select */
.mode-select-screen {
  padding: 20px 16px;
}
.practice-title h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 6px; }
.today-progress-hint { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 20px; }
.today-progress-hint b { color: var(--success); }

.category-select { margin-bottom: 20px; }
.select-label { font-size: 0.82rem; color: var(--text-dim); font-weight: 600; margin-bottom: 10px; display: block; }
.cat-select-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cat-select-chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-dim);
}
.cat-select-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}

.mode-cards { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-card:active { transform: scale(0.98); border-color: var(--primary); }
.mode-icon { font-size: 2rem; }
.mode-name { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.mode-desc { font-size: 0.82rem; color: var(--text-dim); }

/* Session Wrapper */
.session-wrapper { display: flex; flex-direction: column; min-height: calc(100svh - var(--header-h) - var(--nav-h)); }

.session-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.btn-back-session {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  cursor: pointer;
}
.session-mode-label { font-weight: 600; font-size: 0.95rem; }
.session-score-badge {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
}
.session-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.session-progress-track {
  flex: 1;
  height: 6px;
  background: rgba(108,99,255,0.15);
  border-radius: 99px;
  overflow: hidden;
}
.session-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width 0.4s ease;
}
.session-counter { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; }

/* Card Area */
#card-area  { flex: 1; padding: 16px; display: flex; flex-direction: column; justify-content: center; }
#action-area { padding: 0 16px 20px; }

/* ─── Flashcard ──────────────────────────────────────────── */
.flashcard-scene {
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
}
.flashcard {
  position: relative;
  width: 100%;
  padding-top: 65%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius);
}
.flashcard.flipped { transform: rotateY(180deg); }

.flashcard-front,
.flashcard-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flashcard-front {
  background: linear-gradient(135deg, var(--card), var(--surface));
  border: 1px solid var(--border);
}
.flashcard-back {
  background: linear-gradient(135deg, #1a0a3a, #2d1b69);
  border: 1px solid rgba(108,99,255,0.5);
  transform: rotateY(180deg);
}

.fc-category { font-size: 0.8rem; font-weight: 600; margin-bottom: 12px; }
.fc-english { font-size: 1.6rem; font-weight: 800; text-align: center; margin-bottom: 8px; line-height: 1.2; }
.fc-phonetic { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 12px; }
.fc-hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 12px; }
.fc-speak-btn {
  background: rgba(108,99,255,0.2);
  border: none;
  color: var(--primary-light);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: 4px;
}
.fc-chinese { font-size: 1.8rem; font-weight: 800; color: white; text-align: center; margin-bottom: 8px; }
.fc-english-small { font-size: 0.95rem; color: rgba(255,255,255,0.6); margin-bottom: 10px; }
.fc-example { font-size: 0.8rem; color: rgba(255,255,255,0.5); text-align: center; font-style: italic; }

.flashcard-actions {
  display: none;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.fc-btn {
  flex: 1;
  min-width: 90px;
  padding: 12px 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.fc-btn:active { transform: scale(0.96); }
.fc-btn-hard { background: rgba(255,71,87,0.2); color: #ff6b7a; border: 1px solid rgba(255,71,87,0.3); }
.fc-btn-good { background: rgba(108,99,255,0.2); color: var(--primary-light); border: 1px solid rgba(108,99,255,0.3); }
.fc-btn-easy { background: rgba(67,217,142,0.2); color: var(--success); border: 1px solid rgba(67,217,142,0.3); }

.fc-flip-prompt { text-align: center; font-size: 0.82rem; color: var(--text-dim); padding: 12px; }

/* ─── Quiz ───────────────────────────────────────────────── */
.quiz-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
}
.quiz-category { font-size: 0.82rem; font-weight: 600; margin-bottom: 10px; }
.quiz-english { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; line-height: 1.2; }
.quiz-phonetic { font-size: 0.88rem; color: var(--text-dim); margin-bottom: 12px; }
.quiz-speak {
  background: rgba(108,99,255,0.15);
  border: none;
  color: var(--primary-light);
  padding: 7px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  margin-bottom: 18px;
}
.quiz-prompt { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 14px; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  transition: all 0.15s;
}
.quiz-option:active:not(:disabled) { transform: scale(0.99); }
.quiz-option.correct { background: rgba(67,217,142,0.2); border-color: var(--success); color: var(--success); }
.quiz-option.wrong   { background: rgba(255,71,87,0.2);  border-color: var(--danger);  color: var(--danger);  }
.opt-letter {
  width: 28px; height: 28px;
  background: rgba(108,99,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: var(--primary-light);
  flex-shrink: 0;
}
.quiz-result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 12px;
  font-weight: 600;
}
.quiz-result-bar.correct { background: rgba(67,217,142,0.15); color: var(--success); }
.quiz-result-bar.wrong   { background: rgba(255,71,87,0.15);  color: var(--danger);  }
.btn-next-quiz {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
}

/* ─── Listen Mode ────────────────────────────────────────── */
.listen-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.listen-category { font-size: 0.82rem; font-weight: 600; align-self: flex-start; }
.listen-wave-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}
.listen-play-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--primary), #9b59b6);
  border: none;
  color: white;
  padding: 16px 32px;
  border-radius: 40px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(108,99,255,0.4);
  transition: all 0.2s;
}
.listen-play-btn:active { transform: scale(0.96); }
.listen-play-icon { font-size: 1.2rem; }

.listen-wave {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  opacity: 0;
  transition: opacity 0.3s;
}
.listen-wave.playing { opacity: 1; }
.listen-wave span {
  display: block;
  width: 4px;
  background: var(--primary-light);
  border-radius: 2px;
  animation: wave-bar 1.2s ease-in-out infinite;
}
.listen-wave span:nth-child(1) { height: 10px; animation-delay: 0s;    }
.listen-wave span:nth-child(2) { height: 20px; animation-delay: 0.1s;  }
.listen-wave span:nth-child(3) { height: 30px; animation-delay: 0.2s;  }
.listen-wave span:nth-child(4) { height: 20px; animation-delay: 0.3s;  }
.listen-wave span:nth-child(5) { height: 10px; animation-delay: 0.4s;  }
@keyframes wave-bar {
  0%, 100% { transform: scaleY(1); }
  50%       { transform: scaleY(2); }
}

.listen-answer-area { width: 100%; text-align: center; }
.listen-hidden {
  font-size: 2rem;
  letter-spacing: 8px;
  color: var(--text-dim);
  padding: 20px;
}
.listen-revealed { padding: 8px 0; }
.listen-english { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; }
.listen-phonetic { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 8px; }
.listen-chinese { font-size: 1.3rem; font-weight: 700; color: var(--primary-light); margin-bottom: 10px; }
.listen-example { font-size: 0.82rem; color: var(--text-dim); font-style: italic; }

.listen-actions { display: flex; flex-direction: column; gap: 10px; }
.btn-reveal {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary), #9b59b6);
  border: none;
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-reveal:active { transform: scale(0.98); }
.listen-rate { display: flex; gap: 10px; }

/* ─── Session Complete ───────────────────────────────────── */
.session-complete {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px;
  gap: 20px;
}
.complete-emoji { font-size: 4rem; }
.complete-title { font-size: 1.4rem; font-weight: 800; text-align: center; }
.complete-stats {
  display: flex;
  gap: 16px;
  width: 100%;
}
.complete-stat {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}
.complete-num { font-size: 1.8rem; font-weight: 800; color: var(--primary-light); }
.complete-label { font-size: 0.75rem; color: var(--text-dim); margin-top: 4px; }

.complete-ring { position: relative; width: 140px; height: 140px; }
.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg   { fill: none; stroke: rgba(108,99,255,0.15); stroke-width: 8; }
.ring-fill { fill: none; stroke: url(#ring-gradient); stroke-width: 8; stroke-linecap: round; transition: stroke-dasharray 1s ease; }
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.3;
}
.ring-label small { font-size: 0.72rem; color: var(--text-dim); font-weight: 400; }

.today-checkin-status { width: 100%; }
.checkin-done {
  background: rgba(67,217,142,0.15);
  border: 1px solid rgba(67,217,142,0.3);
  color: var(--success);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-align: center;
}
.checkin-pending {
  background: rgba(108,99,255,0.1);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.88rem;
}
.complete-actions { display: flex; gap: 10px; width: 100%; }
.btn-practice-again,
.btn-change-mode {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-practice-again { background: linear-gradient(135deg, var(--primary), var(--accent)); color: white; }
.btn-change-mode    { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-practice-again:active, .btn-change-mode:active { transform: scale(0.97); }

/* ─── ─── LIBRARY TAB ─── ─── */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.filter-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}

.category-section { margin-bottom: 4px; }
.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 8px;
}
.category-header:active { background: var(--surface); }
.cat-icon { font-size: 1.3rem; }
.cat-label { flex: 1; font-weight: 600; font-size: 0.95rem; }
.cat-count { font-size: 0.8rem; color: var(--text-dim); }
.cat-arrow { color: var(--text-dim); font-size: 1.2rem; }

.word-list { display: flex; flex-direction: column; gap: 8px; }
.word-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.word-card:active { transform: scale(0.99); }
.word-card.learned { border-color: rgba(67,217,142,0.3); }
.word-main { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.word-english { font-size: 1rem; font-weight: 700; }
.learned-badge {
  background: rgba(67,217,142,0.2);
  color: var(--success);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
}
.word-chinese { font-size: 0.88rem; color: var(--text-dim); margin-bottom: 3px; }
.word-phonetic { font-size: 0.78rem; color: rgba(108,99,255,0.7); }

/* Word Modal */
#word-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: flex-end;
  backdrop-filter: blur(4px);
}
#word-modal.show { display: flex; }
#word-modal-content {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 28px 24px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  animation: slideUp 0.3s cubic-bezier(0.4,0,0.2,1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0);    }
}
.modal-word-header {
  border-left: 4px solid var(--primary);
  padding-left: 16px;
  margin-bottom: 20px;
}
.modal-category { font-size: 0.82rem; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.modal-english { font-size: 1.6rem; font-weight: 800; margin-bottom: 6px; }
.modal-phonetic { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 8px; }
.modal-chinese { font-size: 1.2rem; font-weight: 700; }
.modal-example { background: rgba(255,255,255,0.04); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 20px; }
.example-label { font-size: 0.75rem; color: var(--text-dim); font-weight: 600; margin-bottom: 6px; }
.example-text { font-size: 0.88rem; line-height: 1.5; color: var(--text); }
.modal-actions { display: flex; gap: 10px; }
.btn-listen, .btn-practice-word {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-listen       { background: rgba(108,99,255,0.2); color: var(--primary-light); border: 1px solid rgba(108,99,255,0.3); }
.btn-practice-word{ background: linear-gradient(135deg, var(--primary), var(--accent)); color: white; }

/* ─── ─── PROFILE TAB ─── ─── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.avatar {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}
.profile-level { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.profile-xp { font-size: 0.85rem; color: var(--text-dim); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}
.stat-num { font-size: 1.8rem; font-weight: 800; color: var(--primary-light); }
.stat-label { font-size: 0.75rem; color: var(--text-dim); margin-top: 4px; }

.level-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.level-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.level-header span:first-child { font-weight: 600; }
.level-header span:last-child  { color: var(--text-dim); }
.level-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 6px;
}

.achievements-section { margin-bottom: 16px; }
.achievements-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 12px; }
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.achievement {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.achievement.earned { background: rgba(108,99,255,0.15); border-color: rgba(108,99,255,0.4); }
.achievement.locked { opacity: 0.35; filter: grayscale(1); }
.ach-icon { font-size: 1.6rem; }
.ach-name { font-size: 0.65rem; color: var(--text-dim); text-align: center; font-weight: 500; }

.profile-actions { padding-top: 8px; }
.btn-reset {
  width: 100%;
  padding: 13px;
  background: rgba(255,71,87,0.1);
  border: 1px solid rgba(255,71,87,0.3);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-reset:active { background: rgba(255,71,87,0.2); }

/* ─── Toast Notifications ────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-12px);
  transition: all 0.35s cubic-bezier(0.4,0,0.2,1);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: rgba(67,217,142,0.15); border-color: rgba(67,217,142,0.4); color: var(--success); }
.toast-error   { background: rgba(255,71,87,0.15);  border-color: rgba(255,71,87,0.4);  color: var(--danger);  }
.toast-info    { background: rgba(108,99,255,0.15); border-color: rgba(108,99,255,0.4); color: var(--primary-light); }
.toast-level-up {
  background: linear-gradient(135deg, rgba(108,99,255,0.3), rgba(255,107,107,0.3));
  border-color: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 1rem;
}

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(108,99,255,0.3); border-radius: 2px; }

/* ─── Safe Area for iPhone ───────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .main-content { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}

/* ─── Utility ────────────────────────────────────────────── */
.text-center { text-align: center; }
.mt-8  { margin-top: 8px;  }
.mt-16 { margin-top: 16px; }

/* ─── Mastery Dot (Library) ─────────────────────────────── */
.mastery-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}
.word-badges { display: flex; align-items: center; gap: 4px; }
.modal-mastery {
  font-size: 0.78rem;
  margin-top: 4px;
  font-weight: 600;
}

/* ─── Mastery Section (Profile) ─────────────────────────── */
.mastery-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.mastery-section h3 {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.mastery-bars { display: flex; flex-direction: column; gap: 8px; }
.mastery-bar-row { display: flex; align-items: center; gap: 8px; }
.mastery-bar-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 52px;
  flex-shrink: 0;
}
.mastery-bar-track {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  overflow: hidden;
}
.mastery-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.mastery-bar-count {
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}

/* ─── Daily Goal Section (Profile) ─────────────────────── */
.goal-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.goal-section h3 {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.goal-options { display: flex; gap: 10px; }
.goal-btn {
  flex: 1;
  padding: 10px 0;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.goal-btn.active {
  border-color: var(--primary);
  background: rgba(108,99,255,0.15);
  color: var(--primary-light);
}
.goal-btn:hover:not(.active) {
  border-color: rgba(108,99,255,0.5);
  color: var(--text);
}

/* ─── Spelling Mode ─────────────────────────────────────── */
.mode-card-spell {
  background: linear-gradient(135deg, rgba(67,217,142,0.12), rgba(108,99,255,0.12));
  border-color: rgba(67,217,142,0.3);
}
.spell-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  margin: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border: 1px solid var(--border);
}
.spell-category {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.spell-question { text-align: center; }
.spell-chinese {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.spell-phonetic {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.spell-speak {
  background: rgba(108,99,255,0.15);
  border: 1px solid var(--border);
  color: var(--primary-light);
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.spell-speak:hover { background: rgba(108,99,255,0.3); }

.spell-input-wrap {
  display: flex;
  gap: 10px;
}
.spell-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.spell-input:focus { border-color: var(--primary); }
.spell-input.spell-correct { border-color: var(--success); background: rgba(67,217,142,0.08); }
.spell-input.spell-wrong   { border-color: var(--danger);  background: rgba(255,71,87,0.08);  }
.spell-input:disabled { opacity: 0.9; cursor: default; }

.spell-submit {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.spell-submit:hover { opacity: 0.85; }

.spell-feedback { min-height: 60px; }
.spell-result {
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.spell-result.correct {
  background: rgba(67,217,142,0.12);
  color: var(--success);
}
.spell-result.wrong {
  background: rgba(255,71,87,0.12);
  color: var(--danger);
}
.spell-xp {
  font-size: 0.85rem;
  margin-left: 8px;
  opacity: 0.8;
}
.spell-diff {
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.spell-diff-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}
.spell-char { padding: 2px 1px; border-radius: 3px; }
.spell-char.ok  { color: var(--success); }
.spell-char.bad { color: var(--danger); text-decoration: underline; }

.btn-next-spell {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-next-spell:hover { opacity: 0.85; }
