/* ==========================================
   Little Sprouts 小苗苗 — Global Styles
   ========================================== */

:root {
  --bg: #F8F5FF;
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --accent: #FDCB6E;
  --success: #00B894;
  --danger: #E17055;
  --text: #2D3436;
  --text-light: #636E72;
  --radius: 16px;
  --shadow: 0 4px 15px rgba(108,92,231,0.15);
}

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

body {
  font-family: 'Nunito', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

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

/* ---- Screens ---- */
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
  animation: fadeIn 0.35s ease;
}
.screen.active { display: flex; flex-direction: column; }

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

/* ---- Splash ---- */
#splash-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  background: linear-gradient(135deg, #6C5CE7, #A29BFE);
  color: #fff;
}
.splash-icon { font-size: 80px; margin-bottom: 12px; animation: bounce 2s infinite; }
.splash-title { font-size: 36px; font-weight: 900; }
.splash-subtitle { font-size: 24px; font-weight: 700; margin-bottom: 32px; opacity: 0.9; }
.btn-start {
  background: var(--accent);
  color: var(--text);
  border: none;
  padding: 16px 40px;
  border-radius: 50px;
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  transition: transform 0.2s;
}
.btn-start:active { transform: scale(0.95); }

@keyframes bounce {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

/* ---- Top Bar ---- */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  margin-bottom: 8px;
}
.btn-back {
  background: var(--primary-light);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.screen-title { font-size: 18px; font-weight: 700; }
.lang-toggle {
  background: var(--accent);
  color: var(--text);
  border: none;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

/* ---- Home ---- */
.home-greeting {
  text-align: center;
  margin: 24px 0;
}
.greeting-icon { font-size: 48px; margin-bottom: 8px; }
.home-greeting h2 { font-size: 22px; }

.module-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
}
.module-card {
  background: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.module-card:active { transform: scale(0.96); }
.module-icon { font-size: 42px; }
.module-name { font-size: 16px; font-weight: 700; color: var(--primary); }

/* ---- Flashcards ---- */
.flashcard-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1000px;
  min-height: 280px;
}
.flashcard {
  width: 100%;
  max-width: 300px;
  height: 300px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s;
  cursor: pointer;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.flashcard-back { transform: rotateY(180deg); background: linear-gradient(135deg, #6C5CE7, #A29BFE); color: #fff; }
.flashcard-emoji { font-size: 72px; }
.flashcard-word { font-size: 28px; font-weight: 900; }
.flashcard-hint { font-size: 13px; color: var(--text-light); }
.flashcard-phonetic { font-size: 18px; opacity: 0.9; }

.flashcard-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px 0;
}
.btn-nav {
  background: var(--primary);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}
#fc-progress { font-size: 16px; font-weight: 700; }

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 16px;
  -webkit-overflow-scrolling: touch;
}
.cat-tab {
  background: #fff;
  border: 2px solid var(--primary-light);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.cat-tab.active { background: var(--primary); color: #fff; }

/* ---- Numbers ---- */
.number-display {
  text-align: center;
  padding: 20px 0;
}
.big-number {
  font-size: 96px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
}
.number-word { font-size: 24px; font-weight: 700; margin-top: 8px; }
.number-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}
.dot { font-size: 32px; animation: popIn 0.3s ease; }
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 12px 0;
}
.num-btn {
  background: #fff;
  border: 2px solid var(--primary-light);
  border-radius: 12px;
  padding: 14px;
  font-size: 22px;
  font-weight: 900;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.2s;
}
.num-btn.active-num { background: var(--primary); color: #fff; }
.num-btn:active { transform: scale(0.93); }

.counting-game { padding: 12px 0; }
.count-emoji-row { font-size: 36px; text-align: center; letter-spacing: 8px; margin: 12px 0; }
.count-question { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 12px; }

/* ---- Colors ---- */
.color-display { text-align: center; padding: 16px 0; }
.big-color-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin: 0 auto 12px;
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  transition: background 0.3s;
}
.color-name { font-size: 24px; font-weight: 700; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 12px 0;
}
.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}
.color-swatch:active { transform: scale(0.93); }

.color-game-area { padding: 8px 0; }

/* ---- Animals ---- */
.animal-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 8px 0;
}
.animal-grid.hidden { display: none; }
.animal-card {
  background: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: transform 0.2s;
}
.animal-card:active { transform: scale(0.93); }
.animal-emoji { font-size: 32px; }
.animal-name { font-size: 12px; font-weight: 700; color: var(--primary); }

.animal-detail {
  text-align: center;
  padding: 20px 0;
}
.animal-detail.hidden { display: none; }
.animal-big-emoji { font-size: 100px; margin-bottom: 12px; animation: bounce 2s infinite; }
.animal-detail .animal-name { font-size: 28px; font-weight: 900; }
.animal-sound { font-size: 20px; color: var(--text-light); margin: 12px 0; }

/* ---- Shapes ---- */
.shape-display { text-align: center; padding: 16px 0; }
.big-shape { margin-bottom: 12px; }
.shape-name { font-size: 24px; font-weight: 700; }

.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 12px 0;
}
.shape-btn {
  background: #fff;
  border: 2px solid var(--primary-light);
  border-radius: 12px;
  padding: 10px 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}
.shape-btn small { font-weight: 700; color: var(--primary); }
.shape-btn:active { transform: scale(0.93); }

/* ---- Quiz ---- */
.quiz-area { text-align: center; padding: 12px 0; }
.quiz-area.hidden { display: none; }
.quiz-score { font-size: 24px; font-weight: 900; margin-bottom: 16px; }
.quiz-question { font-size: 20px; font-weight: 700; margin-bottom: 12px; }
.quiz-emoji-hint {
  font-size: 40px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.quiz-opt {
  background: #fff;
  border: 2px solid var(--primary-light);
  border-radius: 12px;
  padding: 14px;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.2s;
}
.quiz-opt:active { transform: scale(0.95); }
.quiz-opt.correct-opt { background: var(--success); color: #fff; border-color: var(--success); }
.quiz-opt.wrong-opt { background: var(--danger); color: #fff; border-color: var(--danger); }

.quiz-feedback {
  margin-top: 12px;
  font-size: 18px;
  font-weight: 700;
}
.quiz-feedback.hidden { display: none; }

.quiz-complete {
  text-align: center;
  padding: 40px 0;
}
.quiz-complete.hidden { display: none; }
.complete-emoji { font-size: 72px; margin-bottom: 12px; }

/* ---- Buttons shared ---- */
.btn-game {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 14px 28px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
  margin: 8px auto;
  display: block;
  transition: transform 0.2s;
}
.btn-game:active { transform: scale(0.96); }

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (min-width: 481px) {
  #app {
    margin-top: 20px;
    border-radius: 24px;
    box-shadow: 0 0 40px rgba(108,92,231,0.15);
    min-height: calc(100vh - 40px);
    overflow: hidden;
  }
  .screen { min-height: calc(100vh - 40px); }
}

/* ---- Storybook ---- */
.story-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 12px 0;
}
.story-list.hidden { display: none; }

.story-card {
  background: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.story-card:active { transform: scale(0.96); }
.story-cover-emoji { font-size: 52px; }
.story-title { font-size: 15px; font-weight: 700; color: var(--text); line-height: 1.4; text-align: center; }
.story-pages-info { font-size: 12px; color: var(--text-light); }

.story-reader { padding: 0; }
.story-reader.hidden { display: none; }

.story-page {
  flex: 1;
  border-radius: var(--radius);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  min-height: 340px;
  box-shadow: var(--shadow);
}
.story-illustration {
  font-size: 48px;
  letter-spacing: 6px;
  line-height: 1.6;
  max-width: 100%;
  overflow: hidden;
}
.story-illustration svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}
.story-text {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.8;
  max-width: 360px;
}
.story-speaker {
  font-size: 14px;
  color: var(--text-light);
  font-style: italic;
}

.story-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 14px 0;
}
#story-progress { font-size: 16px; font-weight: 700; }
#story-prev:disabled, #story-next:disabled {
  opacity: 0.3;
  cursor: default;
}
.story-back-btn {
  margin-bottom: 16px;
}

/* ---- Story TTS Controls ---- */
.story-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 8px 0;
}
.btn-tts {
  background: #fff;
  border: 2px solid var(--primary-light);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--primary);
  transition: all 0.2s;
}
.btn-tts:active { transform: scale(0.95); }
.btn-tts-stop { background: #fff3f3; border-color: var(--danger); color: var(--danger); }
.btn-tts-stop:disabled { opacity: 0.3; cursor: default; }

/* ---- Audiobook ---- */
.audiobook-info {
  text-align: center;
  padding: 16px 0 8px;
}
.ab-cover { font-size: 72px; margin-bottom: 8px; }
.ab-title { font-size: 22px; font-weight: 900; color: var(--primary); }
.ab-author { font-size: 14px; color: var(--text-light); margin-top: 4px; }

.audiobook-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
}
.btn-ab {
  background: var(--primary-light);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}
.btn-ab:active { transform: scale(0.92); }
.btn-ab-play {
  width: 64px;
  height: 64px;
  font-size: 28px;
  background: var(--primary);
}

.ab-progress-bar {
  width: 80%;
  height: 6px;
  background: #E0E0E0;
  border-radius: 3px;
  margin: 0 auto;
  overflow: hidden;
}
.ab-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}
.ab-page-info {
  text-align: center;
  font-size: 13px;
  color: var(--text-light);
  margin-top: 6px;
}

.ab-text-display {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px 20px;
  margin: 12px 0;
  min-height: 120px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ab-text-content {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.8;
  text-align: center;
  color: var(--text);
}

.ab-book-select {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  -webkit-overflow-scrolling: touch;
}
.ab-book-btn {
  background: #fff;
  border: 2px solid var(--primary-light);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.ab-book-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Safe area for notch phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .screen { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}
