* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
input, textarea { user-select: text; }
/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 100;
}
.app-header h1 { font-size: 20px; font-weight: 700; }
.app-header .subtitle { font-size: 12px; opacity: 0.8; margin-top: 2px; }
/* Main Content */
.main-content {
  padding-top: 72px;
  padding-bottom: 70px;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.page { display: none; padding: 16px; }
.page.active { display: block; }
/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--card);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 10px;
  gap: 2px;
  position: relative;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 24px; height: 24px; }
.nav-item .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: white;
  font-size: 9px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.nav-item-wrapper { position: relative; }
/* Word List */
.cat-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-filter::-webkit-scrollbar { display: none; }
.cat-filter button {
  flex-shrink: 0;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.cat-filter button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.cat-filter .cat-num {
  font-size: 11px;
  opacity: 0.75;
  background: rgba(0,0,0,0.08);
  border-radius: 8px;
  padding: 0 6px;
  line-height: 16px;
}
.cat-filter button.active .cat-num { background: rgba(255,255,255,0.25); }
.word-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.word-list-header h2 { font-size: 18px; font-weight: 600; }
.word-count { font-size: 13px; color: var(--text-secondary); }
.search-bar {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 12px;
  background: var(--card);
  outline: none;
  transition: border-color 0.2s;
}
.search-bar:focus { border-color: var(--primary); }
.word-item {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.word-item:active { transform: scale(0.98); }
.word-item-left { flex: 1; }
.word-item .word { font-size: 16px; font-weight: 600; color: var(--text); }
.word-item .phonetic { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.word-item .meaning { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.word-item .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: 12px;
}
.status-dot.new { background: var(--border); }
.status-dot.learning { background: var(--warning); }
.status-dot.mastered { background: var(--success); }
/* Modal / Card */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: flex-end;
}
.modal-overlay.show { display: flex; }
.modal-content {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.card-word { font-size: 28px; font-weight: 700; text-align: center; }
.card-word-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.speak-btn {
  background: rgba(79,70,229,0.1);
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.speak-btn:active { transform: scale(0.9); background: rgba(79,70,229,0.2); }
.speak-btn.small { width: 28px; height: 28px; font-size: 14px; }
.fc-speak { background: rgba(255,255,255,0.18); margin-top: 10px; }
.exam-zh { padding: 10px 0 0; border-top: 1px dashed rgba(146,64,14,0.3); margin-top: 10px; }
.exam-zh .exam-zh-q { font-size: 13px; color: #92400E; line-height: 1.6; }
.exam-zh .exam-zh-opts { font-size: 12px; color: #78350F; line-height: 1.7; margin-top: 6px; }
.spelling-meaning-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}
.spelling-meaning { margin-bottom: 0; }
.word-item .speak-btn { margin-left: 8px; }
.word-item-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.cat-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  color: white;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: 2px;
}
.cat-tag.cat-exam { background: #b45309; }
.cat-tag.cat-computer { background: #0e7490; }
.cat-tag.cat-toefl { background: #7c3aed; }
.hidden-zh { display: none !important; }
.cat-stats { margin-bottom: 18px; }
.cat-stats h3 { font-size: 14px; margin-bottom: 10px; }
.cat-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.cat-stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.cat-stat-num { display: block; font-size: 20px; font-weight: 700; color: var(--primary); }
.cat-stat-label { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.card-phonetic { font-size: 16px; color: var(--text-secondary); text-align: center; margin-top: 4px; }
.card-meaning { font-size: 18px; color: var(--primary); text-align: center; margin-top: 12px; font-weight: 500; }
.card-section {
  margin-top: 20px;
  padding: 16px;
  background: #F1F5F9;
  border-radius: 12px;
}
.card-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-section-content { font-size: 14px; line-height: 1.6; color: var(--text); word-break: break-word; }
.card-section-content .highlight { color: var(--primary); font-weight: 600; }
.translation-toggle {
  background: none;
  border: 1px dashed var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--primary);
  font-size: 13px;
  width: 100%;
  margin-top: 8px;
  transition: all 0.2s;
}
.translation-toggle:hover { background: rgba(79,70,229,0.05); }
.translation-text { display: none; margin-top: 8px; font-size: 14px; color: var(--text); line-height: 1.6; }
.translation-text.show { display: block; }
.exam-source {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}
.exam-source-title {
  font-size: 13px;
  font-weight: 600;
  color: #92400E;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.exam-question { font-size: 14px; line-height: 1.6; color: #1E293B; margin-bottom: 8px; }
.exam-option { font-size: 13px; padding: 4px 0; color: #475569; }
.exam-option.correct { color: var(--success); font-weight: 600; }
.card-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.card-actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-know { background: #D1FAE5; color: #065F46; }
.btn-forget { background: #FEE2E2; color: #991B1B; }
.btn-know:active { background: #A7F3D0; }
.btn-forget:active { background: #FECACA; }
/* Flashcard Page */
.flashcard-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.flashcard-controls button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.flashcard-controls button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.flashcard-container {
  perspective: 1000px;
  height: 300px;
  margin-bottom: 20px;
}
.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  cursor: pointer;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.flashcard-front {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}
.flashcard-front .fc-word { font-size: 32px; font-weight: 700; }
.flashcard-front .fc-phonetic { font-size: 16px; opacity: 0.8; margin-top: 8px; }
.flashcard-front .fc-hint { font-size: 12px; opacity: 0.6; margin-top: 20px; }
.flashcard-back {
  background: var(--card);
  transform: rotateY(180deg);
}
.flashcard-back .fc-meaning { font-size: 22px; font-weight: 600; color: var(--primary); text-align: center; }
.flashcard-back .fc-example { font-size: 14px; color: var(--text-secondary); text-align: center; margin-top: 16px; line-height: 1.5; }
.flashcard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.flashcard-nav button {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.fc-prev, .fc-next { background: var(--primary); color: white; }
.fc-prev:disabled, .fc-next:disabled { opacity: 0.4; cursor: not-allowed; }
.flashcard-progress {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}
.flashcard-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.flashcard-actions button {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
/* Stats Page */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-number { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.stat-card.success .stat-number { color: var(--success); }
.stat-card.warning .stat-number { color: var(--warning); }
.stat-card.danger .stat-number { color: var(--danger); }
.progress-section {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.progress-section h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.progress-bar-container {
  height: 12px;
  background: #E2E8F0;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease;
}
.progress-bar.mastered { background: linear-gradient(90deg, var(--success), #34D399); }
.progress-bar.learning { background: linear-gradient(90deg, var(--warning), #FBBF24); }
.progress-legend {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}
.daily-chart {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.daily-chart h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 120px;
  padding-top: 10px;
}
.chart-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.chart-bar {
  width: 24px;
  background: linear-gradient(to top, var(--primary), var(--primary-light));
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.5s ease;
}
.chart-label { font-size: 10px; color: var(--text-secondary); }
.chart-value { font-size: 10px; color: var(--primary); font-weight: 600; }
/* Error Book */
.error-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.error-header h2 { font-size: 18px; font-weight: 600; }
.error-filter {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  background: var(--card);
  cursor: pointer;
}
.error-item {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.error-item-left { flex: 1; }
.error-item .word { font-size: 16px; font-weight: 600; }
.error-item .error-count {
  font-size: 12px;
  color: var(--danger);
  background: #FEE2E2;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 4px;
  display: inline-block;
}
.error-item .meaning { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.error-item .last-error { font-size: 11px; color: var(--text-secondary); }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.4; }
.empty-state p { font-size: 14px; }
/* Spelling Page */
.spelling-mode-select {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.spelling-mode-select button {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.spelling-mode-select button.active {
  border-color: var(--primary);
  background: rgba(79,70,229,0.05);
  color: var(--primary);
}
.spelling-card {
  background: var(--card);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
}
.spelling-hint {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.spelling-meaning {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 24px;
}
.spelling-input-area {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.letter-box {
  width: 36px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  text-transform: lowercase;
  background: var(--card);
  transition: all 0.2s;
}
.letter-box.filled { border-color: var(--primary); color: var(--primary); background: rgba(79,70,229,0.05); }
.letter-box.blank {
  border-color: var(--warning);
  border-style: dashed;
  color: var(--warning);
  cursor: pointer;
}
.letter-box.blank.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,0.2); }
.letter-box.correct { border-color: var(--success); color: var(--success); background: #D1FAE5; }
.letter-box.wrong { border-color: var(--danger); color: var(--danger); background: #FEE2E2; }
.spelling-full-input {
  width: 100%;
  padding: 14px 20px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 20px;
  text-align: center;
  letter-spacing: 4px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}
.spelling-full-input:focus { border-color: var(--primary); }
.spelling-full-input.correct { border-color: var(--success); background: #D1FAE5; }
.spelling-full-input.wrong { border-color: var(--danger); background: #FEE2E2; }
.keyboard {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-bottom: 16px;
}
.key-btn {
  width: 32px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.key-btn:active { background: var(--primary); color: white; transform: scale(0.95); }
.key-btn.wide { width: 56px; font-size: 12px; }
.spelling-result {
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 12px;
  display: none;
}
.spelling-result.correct { display: block; background: #D1FAE5; color: #065F46; }
.spelling-result.wrong { display: block; background: #FEE2E2; color: #991B1B; }
.spelling-actions {
  display: flex;
  gap: 12px;
}
.spelling-actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-check { background: var(--primary); color: white; }
.btn-skip { background: #E2E8F0; color: var(--text-secondary); }
.btn-next { background: var(--success); color: white; display: none; }
.spelling-score {
  background: var(--card);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-around;
  margin-bottom: 16px;
}
.spelling-score-item { text-align: center; }
.spelling-score-item .num { font-size: 24px; font-weight: 700; }
.spelling-score-item .label { font-size: 11px; color: var(--text-secondary); }
/* Scrollbar */
::-webkit-scrollbar { width: 0; }
/* Toast */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
