* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-dark: #1a3a5c;
  --blue-mid: #1e4d7b;
  --blue-light: #00aaff;
  --blue-pale: #e8f4fd;
  --green: #27ae60;
  --red: #e74c3c;
  --yellow: #f39c12;
  --white: #ffffff;
  --gray-light: #f5f7fa;
  --gray-mid: #e0e8f0;
  --text-dark: #1a3a5c;
  --text-mid: #4a6080;
  --text-light: #8a9ab0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.2);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--blue-dark);
  color: var(--white);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ── SCREENS ── */
.screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ── HOME SCREEN ── */
#homeScreen {
  background: var(--blue-dark);
  padding: 32px 20px 40px;
  align-items: center;
}

.home-logo {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 4px;
}
.home-logo span { color: var(--blue-light); }

.home-tagline {
  font-size: 0.85rem;
  opacity: 0.55;
  margin-bottom: 40px;
  letter-spacing: 0.5px;
}

.lessons-grid {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lesson-card {
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
}
.lesson-card:active { transform: scale(0.97); background: rgba(255,255,255,0.12); }
.lesson-card.locked { opacity: 0.4; cursor: default; }
.lesson-card.completed { border-color: var(--green); }

.lesson-num {
  width: 44px;
  height: 44px;
  background: var(--blue-light);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.lesson-card.completed .lesson-num { background: var(--green); }
.lesson-card.locked .lesson-num { background: rgba(255,255,255,0.15); }

.lesson-info { flex: 1; }
.lesson-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 3px; }
.lesson-subtitle { font-size: 0.75rem; opacity: 0.6; }

.lesson-status { font-size: 1.1rem; }

/* ── LESSON SCREEN ── */
#lessonScreen {
  background: var(--blue-dark);
  flex-direction: column;
}

.lesson-header {
  padding: 16px 20px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.back-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lesson-progress-wrap { flex: 1; }
.lesson-progress-label {
  font-size: 0.7rem;
  opacity: 0.5;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}
.lesson-progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}
.lesson-progress-fill {
  height: 100%;
  background: var(--blue-light);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ── EXERCISE CARD ── */
.exercise-wrap {
  flex: 1;
  padding: 8px 16px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.exercise-card {
  background: var(--white);
  color: var(--text-dark);
  border-radius: 20px;
  padding: 24px 20px;
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}

.ex-type-label {
  font-size: 0.68rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.ex-instruction {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 20px;
  line-height: 1.4;
}

/* ── CHARACTER + BUBBLE ── */
.character-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 24px;
}
.character-row.right { flex-direction: row-reverse; }

.char-avatar {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  background: var(--blue-pale);
  overflow: hidden;
}
.char-avatar img { width: 100%; height: 100%; object-fit: cover; }

.speech-bubble {
  background: var(--blue-pale);
  border: 1.5px solid #c5ddf4;
  border-radius: 16px 16px 16px 4px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.4;
  position: relative;
  flex: 1;
}
.character-row.right .speech-bubble {
  border-radius: 16px 16px 4px 16px;
  background: #f0fff4;
  border-color: #a8d5b5;
}

.audio-play-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 4px;
  opacity: 0.7;
  margin-left: 6px;
  vertical-align: middle;
}
.audio-play-btn:active { opacity: 1; }

/* ── OPTIONS ── */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}

.option-btn {
  width: 100%;
  padding: 14px 18px;
  background: var(--gray-light);
  border: 2px solid var(--gray-mid);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-dark);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}
.option-btn:active { transform: scale(0.98); }
.option-btn.selected { border-color: var(--blue-light); background: #e0f4ff; }
.option-btn.correct { border-color: var(--green); background: #e8f8f0; color: #1a6b3a; }
.option-btn.wrong { border-color: var(--red); background: #fdf2f2; color: #a93226; }

/* ── COMPLETE PHRASE ── */
.complete-phrase-display {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 16px;
  line-height: 1.6;
  text-align: center;
  padding: 12px;
  background: var(--gray-light);
  border-radius: var(--radius-sm);
}
.blank {
  display: inline-block;
  min-width: 70px;
  border-bottom: 3px solid var(--blue-light);
  text-align: center;
  color: var(--blue-light);
  font-weight: 700;
}

/* ── WORD ORDER ── */
.hint-text {
  font-size: 0.85rem;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 12px;
  font-style: italic;
}

.answer-area {
  min-height: 52px;
  background: var(--blue-pale);
  border: 2px dashed #c5ddf4;
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.answer-area.has-words { border-style: solid; border-color: var(--blue-light); }

.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  padding: 9px 16px;
  background: var(--white);
  border: 2px solid var(--gray-mid);
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.chip:active { transform: scale(0.95); }
.chip.used { opacity: 0.3; cursor: default; }
.chip.answer-chip {
  background: var(--blue-pale);
  border-color: var(--blue-light);
  color: var(--blue-mid);
}
.chip.answer-chip:active { background: #d0eeff; }

/* ── PRONUNCIATION ── */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 44px;
  margin: 8px 0 16px;
  opacity: 0;
  transition: opacity 0.3s;
}
.waveform.active { opacity: 1; }
.wave-bar {
  width: 4px;
  background: var(--blue-light);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite;
}
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; }
.wave-bar:nth-child(6) { animation-delay: 0.3s; }
.wave-bar:nth-child(7) { animation-delay: 0.2s; }
.wave-bar:nth-child(8) { animation-delay: 0.1s; }
@keyframes wave {
  0%, 100% { height: 8px; }
  50% { height: 34px; }
}

/* ── IMAGE MATCH ── */
.image-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: auto;
}
.image-option {
  aspect-ratio: 1;
  background: var(--gray-light);
  border: 2.5px solid var(--gray-mid);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.image-option:active { transform: scale(0.96); }
.image-option .img-emoji { font-size: 2.4rem; }
.image-option .img-label { font-size: 0.72rem; font-weight: 600; color: var(--text-mid); text-align: center; padding: 0 6px; }
.image-option.selected { border-color: var(--blue-light); background: #e0f4ff; }
.image-option.correct { border-color: var(--green); background: #e8f8f0; }
.image-option.wrong { border-color: var(--red); background: #fdf2f2; }

/* ── PAIR MATCH ── */
.pair-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.pair-item {
  padding: 12px 10px;
  background: var(--gray-light);
  border: 2px solid var(--gray-mid);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dark);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.3;
}
.pair-item:active { transform: scale(0.96); }
.pair-item.selected { border-color: var(--blue-light); background: #e0f4ff; }
.pair-item.matched { border-color: var(--green); background: #e8f8f0; color: #1a6b3a; cursor: default; }
.pair-item.wrong-match { border-color: var(--red); background: #fdf2f2; }

/* ── ACTION BUTTONS ── */
.action-row {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  background: var(--blue-light);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:active { transform: scale(0.98); background: #0090dd; }
.btn-primary:disabled { background: var(--gray-mid); color: var(--text-light); cursor: default; }
.btn-primary.recording {
  background: var(--red);
  animation: pulse 1s ease-in-out infinite;
}
.btn-primary.btn-green { background: var(--green); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); }
  50% { box-shadow: 0 0 0 10px rgba(231,76,60,0); }
}

/* ── FEEDBACK ── */
.feedback-bar {
  display: none;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin-top: 10px;
}
.feedback-bar.show { display: block; }
.feedback-bar.pass { background: #e8f8f0; border: 1.5px solid var(--green); color: #1a6b3a; }
.feedback-bar.fail { background: #fdf2f2; border: 1.5px solid var(--red); color: #a93226; }
.feedback-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 2px; }
.feedback-sub { font-size: 0.82rem; opacity: 0.8; }

/* ── COMPLETE SCREEN ── */
#completeScreen {
  background: var(--blue-dark);
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
}
.complete-icon { font-size: 4rem; margin-bottom: 16px; }
.complete-title { font-size: 1.8rem; font-weight: 900; margin-bottom: 8px; }
.complete-sub { opacity: 0.7; margin-bottom: 32px; line-height: 1.5; }
.complete-score {
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 20px 32px;
  margin-bottom: 32px;
  font-size: 3rem;
  font-weight: 900;
  color: var(--blue-light);
}
.complete-score small { display: block; font-size: 0.85rem; opacity: 0.6; font-weight: 400; margin-top: 4px; }
