:root {
  --bg: #f7f3ed;
  --card: #ffffff;
  --text: #1f1f1f;
  --muted: #666666;
  --border: #e8e1d8;
  --accent: #1f1f1f;
  --green-bg: #e7f3e7;
  --green-text: #1f6b35;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 16px) 16px calc(16px + env(safe-area-inset-bottom));
  padding-top: max(16px, env(safe-area-inset-top));
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

/* ── Home screen ── */
.home-header {
  padding: 28px 0 12px;
  margin-bottom: 4px;
}

.home-flag {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 10px;
}

.home-header h1 {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.home-header p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

/* ── Progress bar ── */
.progress-wrap {
  margin-bottom: 20px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #1f1f1f;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ── Module section headers ── */
.module-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 24px 0 10px;
}

.module-header:first-of-type {
  margin-top: 4px;
}

.module-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
}

.module-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

/* ── Completed card dim ── */
.lesson-done {
  opacity: 0.6;
}

.lesson-card {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}

.lesson-card:active {
  transform: scale(0.985);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.lesson-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.day-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.done-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--green-bg);
  color: var(--green-text);
  font-size: 12px;
  font-weight: 600;
}

.lesson-card h2 {
  margin: 0 0 2px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.lesson-card .subtitle {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
}

.lesson-card .task-text {
  font-size: 14px;
  color: var(--text);
  margin: 0 0 14px;
  line-height: 1.5;
}

.audio-status {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px;
  line-height: 1.5;
}

/* ── Cover image ── */
.cover-img,
.cover-placeholder {
  width: 100%;
  height: 180px;
  border-radius: 16px;
  margin-bottom: 18px;
  display: block;
}

.cover-img {
  object-fit: cover;
  background: var(--border);
}

/* ── Lesson page ── */
.lesson-header {
  padding-bottom: 4px;
}

.lesson-audio-status {
  margin-bottom: 12px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  padding: 10px 12px 10px 0;
  margin-bottom: 8px;
  margin-left: -4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.back-btn:active {
  opacity: 0.6;
}

.lesson-day {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 4px;
}

.lesson-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0 0 2px;
}

.lesson-subtitle {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 12px;
}

.lesson-task {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 7px;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ── Section titles ── */
.section-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 12px;
}

/* ── Audio buttons ── */
.audio-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sr-audio {
  display: none;
}

.apple-mobile-audio .audio-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.apple-mobile-audio .listen-first-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.apple-mobile-audio .audio-btn {
  background: linear-gradient(180deg, #fbf7ef 0%, #f4ecdf 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  color: var(--text);
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  min-height: 56px;
}

.apple-mobile-audio .listen-first-row .audio-btn {
  flex-direction: row;
  justify-content: center;
  text-align: center;
  gap: 4px;
  padding: 12px 6px;
  min-height: 56px;
}

.apple-mobile-audio .audio-btn.secondary {
  background: linear-gradient(180deg, #f7f3eb 0%, #efe6d8 100%);
}

.apple-mobile-audio .sentence-card {
  align-items: flex-start;
  gap: 10px;
}

.apple-mobile-audio .btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.apple-mobile-audio .audio-btn.secondary .btn-icon {
  background: #7f7463;
}

.apple-mobile-audio .audio-btn.playing .btn-icon,
.apple-mobile-audio .mobile-play-btn.playing {
  background: #3a3a3a;
}

.apple-mobile-audio .btn-text {
  font-size: 15px;
  font-weight: 650;
}

.apple-mobile-audio .listen-first-row .btn-text {
  font-size: 13px;
  line-height: 1.2;
}

.apple-mobile-audio .listen-first-row .btn-icon {
  width: auto;
  height: auto;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  display: inline;
  flex-shrink: 1;
  font-size: 13px;
}

.apple-mobile-audio .listen-first-row .audio-btn.secondary .btn-icon {
  background: transparent;
  color: #7f7463;
}

.apple-mobile-audio .listen-first-row .audio-btn.playing .btn-icon {
  background: transparent;
  color: var(--text);
}

.apple-mobile-audio .mobile-play-btn {
  background: var(--bg);
}

.apple-mobile-audio .mobile-play-btn.playing {
  color: #fff;
}

.audio-btn {
  flex: 1;
  min-width: 90px;
  padding: 12px 8px;
  border: none;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s;
  touch-action: manipulation;
  min-height: 48px;
}

.audio-btn:active {
  opacity: 0.75;
}

.audio-btn:disabled,
.play-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.audio-btn.playing {
  background: #3a3a3a;
  opacity: 0.85;
}

.audio-btn.secondary {
  background: #eeeeee;
  color: var(--text);
}

/* ── Sentence cards ── */
.sentence-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.sentence-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.sentence-card:first-child {
  padding-top: 0;
}

.speaker-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 2px;
}

.sentence-text {
  flex: 1;
  min-width: 0;
}

.fr {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.2px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.zh {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}

.tr-line {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
}

.tr-lang {
  font-size: 10px;
  font-weight: 700;
  color: #b0a898;
  min-width: 16px;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

.play-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background 0.15s;
  margin-top: 0;
}

.play-btn:active {
  background: var(--border);
}

.play-btn.playing {
  background: var(--accent);
  color: #fff;
}

@media (max-width: 640px) {
  .sentence-card {
    flex-wrap: wrap;
  }

  .apple-mobile-audio .listen-first-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .apple-mobile-audio .mobile-play-btn {
    margin-left: 40px;
  }
}

/* ── Pattern practice ── */
.pattern-item {
  margin-bottom: 16px;
}

.pattern-item:last-child {
  margin-bottom: 0;
}

.pattern-fr {
  font-size: 19px;
  font-weight: 650;
  line-height: 1.4;
}

.pattern-zh {
  font-size: 13px;
  color: var(--muted);
  margin: 3px 0 8px;
}

.pattern-examples {
  padding-left: 12px;
  border-left: 3px solid var(--border);
}

.pattern-example {
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.5;
}

.pattern-example:last-child {
  margin-bottom: 0;
}

.pattern-example .ex-fr {
  font-weight: 600;
}

.pattern-example .ex-zh {
  color: var(--muted);
  font-size: 13px;
}

/* ── Pronunciation notes ── */
.pron-item {
  margin-bottom: 14px;
}

.pron-item:last-child {
  margin-bottom: 0;
}

.pron-word {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.pron-note {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
}

/* ── Grammar note ── */
.grammar-note {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
  white-space: pre-line;
}

.grammar-notes-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.grammar-note-item {
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 12px;
  border-left: 3px solid var(--accent);
}

.grammar-note-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.grammar-note-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.grammar-note-level {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  background: var(--border);
  padding: 2px 7px;
  border-radius: 999px;
}

.grammar-note-explanation {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}

/* ── Output task ── */
.output-instruction {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-line;
}

/* ── Mark as done / done state ── */
.done-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  background: var(--accent);
  color: #fff;
  transition: opacity 0.15s;
  min-height: 54px;
}

.done-btn:active {
  opacity: 0.75;
}

.done-btn.completed {
  background: var(--green-bg);
  color: var(--green-text);
  cursor: default;
}

/* ── Animation #1: card entrance ── */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.lesson-card {
  animation: cardIn 0.35s ease both;
}

/* ── Animation #3: audio playing pulse ── */
@keyframes playPulse {
  0%   { box-shadow: 0 0 0 0   rgba(31,31,31,0.35); }
  60%  { box-shadow: 0 0 0 8px rgba(31,31,31,0); }
  100% { box-shadow: 0 0 0 0   rgba(31,31,31,0); }
}
.audio-btn.playing,
.play-btn.playing {
  animation: playPulse 1.1s ease infinite;
}

/* ── Animation #4: done feedback ── */
@keyframes donePop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.18); }
  65%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}
.done-btn.done-pop {
  animation: donePop 0.45s ease forwards;
}

/* confetti overlay */
.confetti-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}
@keyframes confettiFall {
  0%   { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(60vh)  rotate(360deg); opacity: 0; }
}
.confetti-dot {
  position: absolute;
  top: 35%;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}
