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

/* ===== Local Fonts (no CDN) ===== */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url('fonts/nunito-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url('fonts/nunito-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ===== Design Tokens ===== */
:root {
  /* color */
  --primary: #6C63FF;
  --primary-light: #A78BFA;
  --primary-pale: #EDE9FE;
  --secondary: #FF6584;
  --success: #059669;
  --success-bg: #D1FAE5;
  --danger: #DC2626;
  --danger-bg: #FEE2E2;
  --warn: #B45309;
  --warn-bg: #FEF3C7;
  --bg: #F5F3FF;
  --card: #FFFFFF;
  --text: #2D3436;
  --text-light: #636E72;
  --text-lighter: #6B7280;   /* >=4.5:1 on white */
  /* gradients */
  --grad-primary: linear-gradient(135deg, #6C63FF, #A78BFA);
  --grad-warm: linear-gradient(135deg, #FF6584, #FFB347);
  --grad-success: linear-gradient(135deg, #10B981, #34D399);
  --grad-pink: linear-gradient(135deg, #F093FB, #F5576C);
  --grad-deep-green: linear-gradient(135deg, #065F46, #047857);
  /* shadow */
  --shadow: 0 4px 20px rgba(108, 99, 255, 0.12);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 30px rgba(108, 99, 255, 0.1);
  /* radius scale: 8 / 12 / 16 / pill */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius: 16px;
  --radius-pill: 999px;
  /* spacing on 4pt grid handled inline: 4/8/12/16/20/24/32 */
  --nav-height: 72px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* type scale (12px hard floor) */
  --fs-xs: 0.75rem;   /* 12px */
  --fs-sm: 0.8125rem; /* 13px */
  --fs-base: 0.875rem;/* 14px */
  --fs-md: 1rem;      /* 16px */
  --fs-lg: 1.25rem;   /* 20px */
  --fs-xl: 1.5rem;    /* 24px */
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Nunito', 'PingFang SC', 'HarmonyOS Sans SC', 'MiSans', 'Noto Sans SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

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

button {
  font-family: inherit;
  touch-action: manipulation;
}

/* ===== Lucide Icon Base ===== */
[data-lucide], .lucide {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.icon-sm, .icon-sm svg { width: 16px; height: 16px; }
.icon-md, .icon-md svg { width: 20px; height: 20px; }
.icon-lg, .icon-lg svg { width: 28px; height: 28px; }
svg.icon-sm { width: 16px; height: 16px; }
svg.icon-md { width: 20px; height: 20px; }
svg.icon-lg { width: 28px; height: 28px; }

/* ===== Gradient utility classes ===== */
.grad-primary { background: var(--grad-primary); }
.grad-warm { background: var(--grad-warm); }
.grad-success { background: var(--grad-success); }
.grad-pink { background: var(--grad-pink); }

/* ===== Pages ===== */
.page {
  display: none;
  padding: 20px 16px calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 24px);
  animation: fadeIn 0.3s ease;
}
.page.active { display: block; }

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

/* ===== Home Header ===== */
.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 8px;
}
.home-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.logo-icon {
  width: 44px;
  height: 44px;
  background: var(--grad-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}
.home-title h1 {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--primary);
  white-space: nowrap;
}
.home-title small {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-light);
}
.header-badges { display: flex; gap: 8px; flex-shrink: 0; }
.star-chip, .streak-badge {
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  font-weight: 800;
  font-size: var(--fs-base);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  min-height: 40px;
  transition: var(--transition);
}
.star-chip { background: var(--grad-primary); box-shadow: 0 3px 12px rgba(108, 99, 255, 0.3); }
.streak-badge { background: linear-gradient(135deg, #E11D48, #F97316); box-shadow: 0 3px 12px rgba(225, 29, 72, 0.3); }
.streak-badge.unlit { background: #9CA3AF; box-shadow: none; }
.star-chip:active, .streak-badge:active { transform: scale(0.95); }

/* ===== Mascot Card ===== */
.mascot-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.mascot-emoji { font-size: 2.5rem; line-height: 1; flex-shrink: 0; }
.mascot-bubble { flex: 1; min-width: 140px; }
.mascot-bubble p {
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--text);
  line-height: 1.45;
}
.daily-goal { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.daily-goal-bar {
  flex: 1;
  height: 8px;
  background: var(--primary-pale);
  border-radius: 4px;
  overflow: hidden;
  max-width: 140px;
}
.daily-goal-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #F97316, #FBBF24);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.daily-goal-text { font-size: var(--fs-xs); font-weight: 700; color: var(--text-lighter); }
.cta-btn {
  border: none;
  background: var(--grad-primary);
  color: white;
  font-size: var(--fs-md);
  font-weight: 800;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.35);
  transition: var(--transition);
  min-height: 48px;
}
.cta-btn:active { transform: scale(0.96); }

/* ===== Progress Section ===== */
.progress-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: var(--fs-base);
  color: var(--text-light);
}
.progress-bar {
  height: 12px;
  background: var(--primary-pale);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #34D399);
  border-radius: 6px;
  transition: width 0.5s ease;
  position: relative;
}
.progress-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.stats-row { display: flex; justify-content: space-around; }
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.stat-icon { color: var(--primary); display: flex; }
.stat-value { font-size: 1.3rem; font-weight: 900; color: var(--primary); }
.stat-label { font-size: var(--fs-xs); color: var(--text-lighter); font-weight: 600; }

/* ===== Level Map (snake path) ===== */
.levelmap-section { margin-bottom: 24px; }
.section-sub { font-size: var(--fs-xs); font-weight: 700; color: var(--text-lighter); margin-left: 6px; }
.level-map {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  max-height: 460px;
  overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.level-trail {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
}
.zone-bands { position: absolute; inset: 0; }
.zone-band {
  position: absolute;
  left: 8px;
  right: 8px;
  border-radius: 24px;
}
.trail-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 2px rgba(108, 99, 255, 0.10));
}
.trail-deco {
  position: absolute;
  transform: translate(-50%, -50%) rotate(-4deg);
  font-size: 1.35rem;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.08));
}
.trail-deco:nth-child(even) { transform: translate(-50%, -50%) rotate(5deg); font-size: 1.15rem; }
.chapter-chip {
  position: absolute;
  z-index: 2;
}
.chapter-pill {
  color: white;
  font-size: var(--fs-xs);
  font-weight: 800;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  box-shadow: 0 3px 8px rgba(0,0,0,0.16);
  white-space: nowrap;
}
.trail-goal {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 2.4rem;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.18));
  z-index: 1;
}
.level-node {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 2;
  border: none;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: var(--fs-md);
  cursor: pointer;
  transition: box-shadow var(--transition), background var(--transition);
  color: white;
  /* pressed-button look: lifted face + darker rim at the bottom */
  box-shadow: 0 4px 10px rgba(0,0,0,0.16), inset 0 -4px 0 rgba(0,0,0,0.18), inset 0 2px 0 rgba(255,255,255,0.28);
}
.level-node:active { transform: translate(-50%, -50%) scale(0.92); }
.level-node .node-num { line-height: 1.1; text-shadow: 0 1px 2px rgba(0,0,0,0.18); }
.level-node .node-stars {
  font-size: 9px;
  letter-spacing: -0.5px;
  line-height: 1;
  color: #FFE38A;
  text-shadow: 0 1px 1px rgba(0,0,0,0.25);
}
.level-node .node-boss {
  position: absolute;
  top: -9px;
  right: -7px;
  font-size: 1rem;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}
.level-node.locked {
  background: #FFFFFF;
  color: #8B85B5;
  cursor: default;
  box-shadow: inset 0 0 0 3px #E9E4FA;
  width: 42px;
  height: 42px;
  font-size: var(--fs-sm);
}
.level-node.locked .node-num { text-shadow: none; }
.level-node.unlocked { animation: nodePulse 2s ease infinite; }
.level-node.current {
  width: 66px;
  height: 66px;
  font-size: 1.15rem;
  animation: nodePulse 2s ease infinite;
}
.level-node .node-fox {
  position: absolute;
  top: -26px;
  font-size: 1.5rem;
  animation: foxBounce 1.2s ease infinite;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
}
@keyframes foxBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes nodePulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.06); }
}
.level-node.done { opacity: 0.97; }
@media (prefers-reduced-motion: reduce) {
  .level-node.unlocked, .level-node.current { animation: none; }
  .level-node .node-fox { animation: none; }
  .level-map { scroll-behavior: auto; }
}

/* ===== Mode Grid ===== */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}
.mode-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
  min-height: 80px;
}
@media (hover: hover) {
  .mode-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--primary-light);
  }
}
.mode-card:active { transform: scale(0.97); }
.mode-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}
.mode-info h3 { font-size: var(--fs-md); font-weight: 800; }
.mode-info p { font-size: var(--fs-xs); color: var(--text-light); margin-top: 2px; }

/* ===== Section Title ===== */
.section-title {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
}

/* ===== Category List ===== */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.category-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  border: none;
}
@media (hover: hover) {
  .category-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
}
.category-card:active { transform: scale(0.98); }
.cat-icon-block {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
  position: relative;
}
.cat-crown {
  position: absolute;
  top: -10px;
  right: -6px;
  font-size: 1.1rem;
  transform: rotate(18deg);
}
.category-card .cat-info { flex: 1; min-width: 0; }
.category-card .cat-name {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.3;
}
.category-card .cat-name .cat-name-en { color: var(--text-lighter); font-weight: 600; font-size: var(--fs-sm); }
.category-card .cat-desc {
  font-size: var(--fs-sm);
  color: var(--text-light);
  margin-top: 3px;
  line-height: 1.4;
}
.category-card .cat-progress-mini {
  width: 48px; height: 48px; position: relative;
  flex-shrink: 0;
}
.category-card .cat-progress-mini svg { transform: rotate(-90deg); }
.category-card .cat-progress-mini .progress-text {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: var(--fs-xs); font-weight: 800; color: var(--text-light);
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.page-header h2 {
  font-size: 1.2rem;
  font-weight: 800;
  flex: 1;
}
.back-btn {
  background: none;
  border: none;
  font-size: var(--fs-base);
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  padding: 10px 12px;
  margin-left: -12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
}
@media (hover: hover) { .back-btn:hover { background: rgba(108, 99, 255, 0.1); } }

.counter-badge, .quiz-score, .category-progress-badge {
  background: var(--primary);
  color: white;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ===== Word Grid (Category Page) ===== */
.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.word-cell {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
  min-height: 64px;
}
@media (hover: hover) { .word-cell:hover { transform: scale(1.05); box-shadow: var(--shadow); } }
.word-cell.mastered {
  border-color: #34D399;
  background: linear-gradient(135deg, #D1FAE5, #ECFDF5);
}
.word-cell.mastered::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 24px 24px 0;
  border-color: transparent #34D399 transparent transparent;
}
.word-cell.learning {
  border-color: #FBBF24;
  background: linear-gradient(135deg, #FEF3C7, #FFFBEB);
}
.word-cell .word-en { font-size: 1rem; font-weight: 800; line-height: 1.2; word-break: break-word; }
.word-cell .word-zh { font-size: var(--fs-xs); color: var(--text-light); margin-top: 4px; }

/* ===== Flashcard ===== */
.flashcard-area { display: flex; flex-direction: column; align-items: center; gap: 20px; }

.flashcard-container {
  width: 100%;
  max-width: 320px;
  height: 380px;
  perspective: 1000px;
}
.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}
.flashcard.flipped { -webkit-transform: rotateY(180deg); transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  /* NOTE: must stay position:absolute — a later relative override once broke the whole mode */
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  /* -webkit- prefix required: mobile WebKit won't hide the back face without it,
     causing the front text to bleed through when flipped */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.flashcard-front {
  background: var(--grad-primary);
  color: white;
}
/* purchasable card themes */
.flashcard-front.theme-ocean { background: linear-gradient(135deg, #0EA5E9, #2563EB); }
.flashcard-front.theme-sunset { background: linear-gradient(135deg, #F97316, #DB2777); }
.flashcard-front.theme-space { background: linear-gradient(135deg, #1E1B4B, #6D28D9); }
.flashcard-front::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
  animation: cardShine 4s ease infinite;
}
@keyframes cardShine {
  0%, 100% { transform: translate(-30%, -30%); }
  50% { transform: translate(30%, 30%); }
}
.flashcard-back {
  background: var(--grad-deep-green); /* white text >= 4.5:1 */
  color: white;
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}
.flashcard-back::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, transparent 60%);
  animation: cardShine 4s ease infinite;
}
.flashcard-emoji {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 12px;
  z-index: 1;
  min-height: 0;
}
.flashcard-emoji:empty { display: none; }
.flashcard-word {
  font-size: 3rem;
  font-weight: 900;
  text-align: center;
  line-height: 1.2;
  position: relative;
  z-index: 1;
  word-break: break-word;
  max-width: 100%;
}
.flashcard-word.fc-long { font-size: 2rem; }
.flashcard-word-zh { font-size: 2.2rem; }
.flashcard-word-zh.fc-long { font-size: 1.5rem; }
.flashcard-hint {
  font-size: var(--fs-sm);
  opacity: 0.9;
  margin-top: 12px;
  z-index: 1;
}
.fc-speak {
  position: absolute;
  top: 16px; right: 16px;
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,0.22); border: none; color: white;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
  z-index: 2;
}
@media (hover: hover) { .fc-speak:hover { background: rgba(255,255,255,0.35); transform: scale(1.1); } }
.fc-speak:active { transform: scale(0.9); }
.flashcard-cat {
  font-size: var(--fs-sm);
  opacity: 0.9;
  margin-top: 8px;
  z-index: 1;
}

.flashcard-controls {
  display: flex;
  gap: 16px;
  width: 100%;
  max-width: 320px;
}
.fc-btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
}
.fc-btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.fc-btn:active { transform: scale(0.95); }
.fc-btn-no { background: var(--danger-bg); color: var(--danger); }
.fc-btn-yes { background: var(--success-bg); color: var(--success); }
@media (hover: hover) {
  .fc-btn-no:hover:not(:disabled) { background: #FECACA; }
  .fc-btn-yes:hover:not(:disabled) { background: #A7F3D0; }
}

.flashcard-settings {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 12px;
  background: var(--card);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  color: var(--text-light);
}
.flashcard-settings label { font-weight: 700; }
.flashcard-settings select {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--primary-pale);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  background: white;
  color: var(--text);
  outline: none;
  min-height: 44px;
}
.flashcard-settings select:focus { border-color: var(--primary); }

/* ===== Quiz ===== */
.quiz-area { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.quiz-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--primary-pale);
  border-radius: 4px;
  overflow: hidden;
}
.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 4px;
  transition: width 0.4s ease;
}
.quiz-question {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.quiz-prompt { font-size: 1.8rem; font-weight: 900; }
.quiz-prompt .quiz-sub { font-size: var(--fs-base); color: var(--text-light); font-weight: 700; }
.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}
.quiz-option {
  background: var(--card);
  border: 2px solid var(--primary-pale);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  color: var(--text);
  min-height: 56px;
}
@media (hover: hover) { .quiz-option:hover { border-color: var(--primary); background: #F5F3FF; } }
.quiz-option:active { transform: scale(0.97); }
.quiz-option.correct {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
  animation: correctPop 0.4s ease;
}
.quiz-option.wrong {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
  animation: shake 0.4s ease;
}
@keyframes correctPop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.continue-btn {
  border: none;
  background: var(--primary);
  color: white;
  font-size: var(--fs-md);
  font-weight: 800;
  padding: 14px 28px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: 52px;
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
  animation: fadeIn 0.3s ease;
}
.continue-btn:active { transform: scale(0.96); }

/* ===== Quiz / Game Result ===== */
.quiz-result, .memory-result {
  text-align: center;
  padding: 24px;
}
.result-mascot { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.result-icon {
  width: 80px; height: 80px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-icon.icon-success { background: var(--success-bg); color: var(--success); }
.result-icon.icon-good { background: var(--warn-bg); color: var(--warn); }
.result-icon.icon-encourage { background: var(--primary-pale); color: var(--primary); }
.result-title { font-size: 1.5rem; font-weight: 900; color: var(--primary); }
.result-detail { font-size: var(--fs-base); color: var(--text-light); margin-top: 8px; }
.result-stars {
  margin: 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.result-stars svg { width: 32px; height: 32px; }
.result-wrong-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 16px;
}
.result-wrong-words .rww {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: var(--fs-sm);
  font-weight: 700;
}
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.primary-btn {
  background: var(--grad-primary);
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
  min-height: 52px;
}
@media (hover: hover) { .primary-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(108, 99, 255, 0.4); } }
.primary-btn:active { transform: scale(0.97); }
.secondary-btn {
  background: var(--card);
  color: var(--primary);
  border: 2px solid var(--primary);
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  min-height: 52px;
}
.secondary-btn:active { transform: scale(0.97); }

/* ===== Spelling ===== */
.spelling-area { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.spelling-question {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.spelling-prompt { font-size: 1.6rem; font-weight: 900; color: var(--primary); }
.spelling-listen {
  border: none;
  background: var(--primary-pale);
  color: var(--primary);
  width: 56px; height: 56px;
  border-radius: 50%;
  margin-top: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.spelling-listen:active { transform: scale(0.92); }
.spelling-hint-text {
  font-size: var(--fs-md);
  color: var(--text-lighter);
  margin-top: 8px;
  letter-spacing: 2px;
  font-weight: 700;
  min-height: 22px;
}
.spelling-input-area {
  display: flex;
  gap: 8px;
  width: 100%;
}
.spelling-input-area input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border: 2px solid var(--primary-pale);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  text-align: center;
  min-height: 52px;
}
.spelling-input-area input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1); }
.spelling-submit {
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  min-height: 52px;
}
.spelling-submit:active { transform: scale(0.95); }

.spelling-feedback {
  width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: var(--fs-md);
  min-height: 28px;
}
.spelling-feedback.correct { color: var(--success); animation: bounceIn 0.4s ease; }
.spelling-feedback.wrong { color: var(--danger); }
@keyframes bounceIn {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.hint-btn {
  background: var(--warn-bg);
  color: var(--warn);
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-base);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
}
@media (hover: hover) { .hint-btn:hover { background: #FDE68A; } }

/* ===== Memory Game ===== */
.memory-stats {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-light);
}
.memory-board {
  display: grid;
  gap: 8px;
  padding: 4px;
  grid-template-columns: repeat(4, 1fr);
}
.memory-card {
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  cursor: pointer;
  perspective: 600px;
  position: relative;
}
.memory-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
  transform: rotateY(180deg);
}
.memory-card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  text-align: center;
  font-weight: 700;
  overflow: hidden;
}
.memory-card-front {
  background: var(--grad-primary);
  color: rgba(255,255,255,0.6);
}
.memory-card-back {
  transform: rotateY(180deg);
  background: var(--card);
  border: 2px solid var(--primary-pale);
  line-height: 1.25;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow-sm);
}
.memory-card-back .mem-en {
  color: var(--primary);
  font-weight: 800;
  font-size: var(--fs-sm);
  max-width: 100%;
  overflow-wrap: break-word;
}
.memory-card-back .mem-en.mem-long { font-size: 0.66rem; letter-spacing: -0.2px; }
.memory-card-back .mem-zh { color: var(--text-light); font-size: var(--fs-xs); max-width: 100%; overflow-wrap: break-word; }
.memory-card-back .mem-emoji { font-size: 1.6rem; line-height: 1; }
.memory-card.matched .memory-card-back {
  border-color: #34D399;
  background: var(--success-bg);
}
.memory-card.matched .memory-card-back .mem-en { color: var(--success); }
@keyframes matchPop {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.1); }
}
.memory-card.matched .memory-card-inner { animation: matchPop 0.4s ease; }

/* ===== Progress Page ===== */
.progress-page-content { padding-top: 4px; }
.big-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}
.big-stat {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.big-stat-number {
  font-size: 2rem;
  font-weight: 900;
  color: var(--primary);
}
.big-stat-label {
  font-size: var(--fs-xs);
  color: var(--text-light);
  font-weight: 600;
  margin-top: 4px;
}

/* 7-day chart */
.daily-chart {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px 12px 8px;
  margin-bottom: 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 6px;
  height: 140px;
}
.chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex: 1;
  height: 100%;
}
.chart-bar-wrap { flex: 1; display: flex; align-items: flex-end; width: 100%; justify-content: center; }
.chart-bar {
  width: 60%;
  max-width: 28px;
  min-height: 3px;
  background: var(--grad-primary);
  border-radius: 6px 6px 2px 2px;
  transition: height 0.5s ease;
}
.chart-bar.empty { background: var(--primary-pale); }
.chart-num { font-size: var(--fs-xs); font-weight: 800; color: var(--primary); }
.chart-day { font-size: var(--fs-xs); color: var(--text-lighter); font-weight: 600; }

/* weak words */
.weak-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.weak-word {
  background: var(--card);
  border: 2px solid var(--danger-bg);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
}
.weak-word .ww-zh { color: var(--text-light); font-weight: 600; font-size: var(--fs-xs); }
.weak-word .ww-count { color: var(--danger); font-size: var(--fs-xs); font-weight: 800; }
.weak-practice-btn {
  background: var(--danger-bg);
  color: var(--danger);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 800;
  font-size: var(--fs-sm);
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.category-progress-list { margin-bottom: 24px; }
.cat-prog-item {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
}
.cat-prog-icon-block {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}
.cat-prog-info { flex: 1; }
.cat-prog-name { font-weight: 700; font-size: var(--fs-base); }
.cat-prog-bar {
  height: 6px;
  background: var(--primary-pale);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.cat-prog-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.cat-prog-pct { font-size: var(--fs-sm); font-weight: 800; color: var(--primary); min-width: 40px; text-align: right; }

.recent-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 24px;
}
.recent-word {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-sm);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.recent-word .rw-zh { color: var(--text-light); font-weight: 600; margin-left: 4px; font-size: var(--fs-xs); }

/* empty state */
.empty-state {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 28px 16px;
  text-align: center;
}
.empty-state .es-emoji { font-size: 2.5rem; line-height: 1; }
.empty-state .es-text { font-size: var(--fs-base); color: var(--text-light); font-weight: 700; margin: 10px 0 14px; }

.parent-btn {
  background: var(--primary-pale);
  color: var(--primary);
  border: none;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
}

/* ===== Shop ===== */
.shop-intro { font-size: var(--fs-base); color: var(--text-light); font-weight: 700; margin-bottom: 16px; }
.shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.shop-item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.shop-item .si-preview {
  width: 64px; height: 64px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: white;
}
.shop-item .si-name { font-weight: 800; font-size: var(--fs-base); }
.shop-item .si-desc { font-size: var(--fs-xs); color: var(--text-light); min-height: 28px; }
.shop-item .si-btn {
  border: none;
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-weight: 800;
  font-size: var(--fs-sm);
  cursor: pointer;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--grad-primary);
  color: white;
}
.shop-item .si-btn:disabled { background: #E5E7EB; color: #9CA3AF; cursor: default; }
.shop-item .si-btn.owned { background: var(--success-bg); color: var(--success); }
.shop-item .si-btn.active-theme { background: var(--success); color: white; }

/* ===== Bottom Nav ===== */
.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: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 20px rgba(0,0,0,0.06);
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 14px;
  cursor: pointer;
  transition: var(--transition);
  border-radius: var(--radius-md);
  color: var(--text-lighter);
  min-height: 52px;
  min-width: 56px;
  background: none;
  border: none;
}
.nav-item.active { color: var(--primary); background: var(--primary-pale); }
.nav-item.active .nav-icon { transform: scale(1.1); }
.nav-item.active .nav-label { font-weight: 800; }
.nav-icon { transition: var(--transition); width: 22px; height: 22px; }
.nav-label { font-size: var(--fs-xs); font-weight: 700; }

/* ===== Confetti Canvas ===== */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

/* ===== Popups / Dialogs ===== */
.word-popup-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s ease;
  padding: 16px;
}
.word-popup {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: popIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 86vh;
  overflow-y: auto;
}
@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.word-popup .wp-emoji { font-size: 3rem; line-height: 1.1; }
.word-popup .wp-en {
  font-size: 2rem; font-weight: 900; color: var(--primary);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  word-break: break-word;
}
.wp-speak {
  background: var(--primary-pale); border: none;
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition); color: var(--primary);
  flex-shrink: 0;
}
@media (hover: hover) { .wp-speak:hover { background: #DDD6FE; transform: scale(1.1); } }
.wp-speak:active { transform: scale(0.95); }
.word-popup .wp-zh { font-size: 1.3rem; font-weight: 700; color: var(--text); margin-top: 8px; }
.word-popup .wp-status {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-sm); color: var(--text-lighter);
  margin-top: 8px; padding: 6px 12px; border-radius: var(--radius-md); background: #F5F3FF;
}
.word-popup .wp-close, .word-popup .primary-btn {
  margin-top: 16px;
}
.word-popup .wp-close {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}
.word-popup .dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}
.word-popup .danger-btn {
  background: var(--danger);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
}
.word-popup .cancel-btn {
  background: #F3F4F6;
  color: var(--text);
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}
.word-popup .gate-input {
  width: 90px;
  padding: 12px;
  border: 2px solid var(--primary-pale);
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
  outline: none;
  font-family: inherit;
}
.word-popup .gate-input:focus { border-color: var(--primary); }
.word-popup .parent-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-size: var(--fs-base);
  font-weight: 700;
  border-bottom: 1px solid #F3F4F6;
}
.word-popup .parent-row span:last-child { color: var(--primary); }

/* Certificate */
.certificate-canvas-wrap { margin: 12px 0; }
.certificate-canvas-wrap canvas {
  width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* ===== Storage banner ===== */
.storage-banner {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 440px;
  width: calc(100% - 24px);
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: var(--fs-sm);
  font-weight: 700;
  z-index: 300;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(45, 52, 54, 0.92);
  color: white;
  border-radius: var(--radius-pill);
  padding: 10px 20px;
  font-size: var(--fs-base);
  font-weight: 700;
  z-index: 400;
  animation: fadeIn 0.25s ease;
  max-width: 90%;
  text-align: center;
}

/* ===== Responsive ===== */
@media (min-width: 481px) {
  body { background: var(--primary-pale); }
  #app { background: var(--bg); box-shadow: 0 0 40px rgba(0,0,0,0.08); }
}
@media (max-width: 359px) {
  .level-map { grid-template-columns: repeat(4, 1fr); }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: #C4B5FD; border-radius: 2px; }

/* ===== Touch feedback ===== */
@media (hover: none) {
  .mode-card:active, .category-card:active, .word-cell:active {
    transform: scale(0.97);
    opacity: 0.85;
  }
}

/* Prevent text selection on game elements */
.flashcard-container, .memory-board, .quiz-options, .level-map, .bottom-nav {
  -webkit-user-select: none;
  user-select: none;
}
