/* 自然拼读小游戏 — 大按钮、触屏友好、手机/平板/电脑都可用 */
:root {
  --bg1: #d9f3ff;
  --bg2: #fff4d6;
  --card: #ffffff;
  --ink: #243044;
  --muted: #5b6b80;
  --line: #e6eef6;
  --g: #2fa36b;
  --h: #f4a227;
  --i: #6b7bf0;
  --pink: #ff6fa3;
  --star: #ffc53d;
  --good: #24b36b;
  --soft: #fff7e0;
  --shadow: 0 10px 28px rgba(40, 70, 110, 0.12);
  --press: 0 3px 0 rgba(0, 0, 0, 0.12);
  --radius: 24px;
  --tap: 72px;
  --font: "Fredoka", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", ui-rounded, system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 500px at 10% -10%, #fff7c8 0%, transparent 50%),
    radial-gradient(800px 500px at 110% 0%, #cfe9ff 0%, transparent 50%),
    linear-gradient(180deg, var(--bg1), var(--bg2) 70%, #ffe8f0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  height: 100%;
}
body {
  min-height: 100dvh;
  min-height: 100svh;
  height: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
}
img { max-width: 100%; height: auto; display: block; pointer-events: none; user-select: none; }
button, a, .choice, .word-card, .mode-card, .lesson-card, .letter-chip {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { cursor: default; }

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}
.home-layout, .lesson-layout, .learn-layout, .quiz-layout, .match-layout, .sentences-layout {
  flex: 1 1 auto;
  min-height: 0;
}
.word-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  margin-bottom: 8px;
}
.topbar h1, .topbar .title {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  text-align: center;
  line-height: 1.25;
}
.icon-btn, .back-btn {
  flex: 0 0 auto;
  min-width: 52px;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 1.35rem;
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 0 10px;
}
.icon-btn:active, .back-btn:active, .btn:active, .choice:active, .word-card:active, .mode-card:active, .lesson-card:active, .letter-chip:active {
  transform: translateY(2px);
}
.star-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 52px;
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  color: #b8860b;
}
.star-pill .star { font-size: 1.25rem; }

/* Common typography */
.hero-title {
  margin: 8px 0 4px;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  text-align: center;
  letter-spacing: 0.02em;
}
.hero-sub {
  margin: 0 0 20px;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
}
.hint {
  text-align: center;
  color: var(--muted);
  margin: 8px 0 16px;
  font-size: 1rem;
}

/* Cards / buttons */
.btn {
  appearance: none;
  border: 0;
  border-radius: 18px;
  min-height: var(--tap);
  padding: 12px 22px;
  font-size: 1.15rem;
  font-weight: 650;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow), var(--press);
}
.btn-primary {
  background: linear-gradient(180deg, #5db7ff, #3b8fff);
  color: #fff;
}
.btn-good {
  background: linear-gradient(180deg, #5ad38e, #2fa36b);
  color: #fff;
}
.btn-warm {
  background: linear-gradient(180deg, #ffd56a, #f4a227);
  color: #3b2a00;
}
.btn-pink {
  background: linear-gradient(180deg, #ff9fc0, #ff6fa3);
  color: #fff;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
}

.lesson-grid, .mode-grid, .word-grid, .choice-grid, .letter-row {
  display: grid;
  gap: 14px;
}
.lesson-grid { grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .lesson-grid { grid-template-columns: 1fr 1fr; }
}

.lesson-card, .mode-card, .word-card, .choice, .letter-chip, .sight-chip, .sentence-card {
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.lesson-card {
  padding: 22px 18px 20px;
  width: 100%;
  color: inherit;
  position: relative;
  overflow: hidden;
}
.lesson-card .badge {
  display: inline-block;
  background: #eef6ff;
  color: #3b6fb0;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 650;
  margin-bottom: 8px;
}
.lesson-card h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}
.lesson-card p { margin: 0; color: var(--muted); }
.lesson-letters {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.big-letter {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
}

.letter-row {
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  margin: 8px 0 18px;
}
.letter-chip {
  min-height: 88px;
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  position: relative;
}
.letter-chip small {
  display: block;
  font-size: 0.85rem;
  font-weight: 550;
  opacity: 0.95;
}
.letter-chip[aria-pressed="true"], .letter-chip.active {
  outline: 4px solid #fff;
  box-shadow: 0 0 0 6px currentColor, var(--shadow);
}
.letter-chip.all {
  background: linear-gradient(180deg, #7a8cff, #5866e6);
  color: #fff;
}

.mode-grid { grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .mode-grid { grid-template-columns: 1fr 1fr; }
}
.mode-card {
  padding: 20px 16px;
  min-height: 120px;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.mode-card .emoji { font-size: 2.2rem; line-height: 1; }
.mode-card h3 { margin: 0; font-size: 1.25rem; }
.mode-card p { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* Learn */
.learn-stage {
  background: var(--card);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 22px 16px 26px;
  text-align: center;
  margin-bottom: 16px;
}
.letter-hero {
  font-size: clamp(5.5rem, 22vw, 8.5rem);
  font-weight: 700;
  line-height: 0.95;
  margin: 0 0 8px;
  letter-spacing: 0.02em;
}
.sound-tag {
  display: inline-block;
  background: var(--soft);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 1.3rem;
  font-weight: 650;
  margin-bottom: 12px;
}
.phrase {
  font-size: 1.25rem;
  margin: 10px 0 16px;
  line-height: 1.4;
}
.phrase .adj { color: var(--pink); font-weight: 700; }
.mascot {
  width: min(220px, 50vw);
  margin: 0 auto 8px;
}
.word-grid {
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 720px) {
  .word-grid { grid-template-columns: repeat(4, 1fr); }
}
.word-card {
  padding: 12px 10px 14px;
  color: inherit;
  min-height: 160px;
}
.word-card .pic {
  height: 110px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}
.word-card img { max-height: 110px; width: auto; margin: 0 auto; }
.word-card .en {
  font-size: 1.25rem;
  font-weight: 700;
}
.word-card .zh { color: var(--muted); font-size: 0.9rem; }

/* Quiz */
.prompt-card {
  background: var(--card);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 18px 16px 20px;
  text-align: center;
  margin-bottom: 16px;
}
.prompt-card .listen-btn {
  width: min(180px, 70%);
  min-height: 88px;
  border-radius: 28px;
  font-size: 1.4rem;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.progress {
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 8px;
}
.prompt-text { font-size: 1.2rem; margin: 0; }
.prompt-en { color: var(--muted); margin: 4px 0 0; }

.choice-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.choice {
  min-height: 140px;
  padding: 12px 8px;
  color: inherit;
  font-size: clamp(3.2rem, 12vw, 5rem);
  font-weight: 700;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.choice.pic-choice {
  font-size: 1rem;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.choice.pic-choice img { max-height: 120px; width: auto; margin: 0 auto; }
.choice.correct {
  background: #e5ffe8;
  box-shadow: 0 0 0 4px var(--good), var(--shadow);
}
.choice.wrong {
  background: #fff3f0;
  animation: wobble 0.5s ease;
}
.choice.dim { opacity: 0.45; }
@keyframes wobble {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

/* Memory match */
.match-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
}
.match-card {
  aspect-ratio: 1;
  border: 0;
  border-radius: 22px;
  background: linear-gradient(180deg, #7ec8ff, #4aa3ff);
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 0;
  position: relative;
  transform-style: preserve-3d;
}
.match-card .face, .match-card .back {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 22px;
  backface-visibility: hidden;
}
.match-card .back { font-size: 2.4rem; }
.match-card .face {
  background: #fff;
  color: var(--ink);
  font-size: clamp(3rem, 14vw, 4.6rem);
  font-weight: 700;
  transform: rotateY(180deg);
}
.match-card.flipped, .match-card.matched {
  background: #fff;
}
.match-card.flipped .face, .match-card.matched .face { transform: none; }
.match-card.flipped .back, .match-card.matched .back { display: none; }
.match-card.matched {
  box-shadow: 0 0 0 4px var(--good), var(--shadow);
  background: #e5ffe8;
}
.match-card.matched .face { background: #e5ffe8; }

/* Sentences */
.sight-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 0 0 16px;
}
.sight-chip {
  min-height: 64px;
  padding: 8px 18px;
  font-size: 1.6rem;
  font-weight: 700;
  color: #2b6bff;
}
.sight-chip small { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.sentence-card {
  padding: 18px 14px 20px;
  margin-bottom: 14px;
  width: 100%;
  color: inherit;
  font-size: 1.45rem;
  line-height: 1.6;
  font-weight: 550;
}
.sentence-card .sight {
  color: #2b6bff;
  font-weight: 800;
}
.sentence-card .pic-inline {
  display: inline-flex;
  vertical-align: middle;
  height: 64px;
  width: 88px;
  margin: 0 4px;
  align-items: center;
  justify-content: center;
}
.sentence-card .pic-inline img { max-height: 62px; width: auto; margin: 0 auto; }
.blank-choices { margin-top: 10px; }

/* Feedback / result */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #243044;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 1.15rem;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 20;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { background: var(--good); }
.toast.soft { background: #5b6b80; }

.result {
  text-align: center;
  padding: 28px 12px;
}
.result .big-stars { font-size: 3rem; letter-spacing: 6px; margin: 8px 0 12px; }
.result h2 { font-size: 2rem; margin: 0 0 8px; }
.result p { color: var(--muted); font-size: 1.15rem; }

.burst {
  position: fixed;
  pointer-events: none;
  z-index: 30;
  font-size: 1.6rem;
  animation: popfly 0.9s ease-out forwards;
}
@keyframes popfly {
  0% { transform: translate(0, 0) scale(0.6); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.2); opacity: 0; }
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

footer.note {
  padding: 0 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 28px;
  line-height: 1.5;
}

@media (max-width: 420px) {
  .choice-grid { gap: 8px; }
  .choice { min-height: 120px; }
  .choice.pic-choice img { max-height: 88px; }
}
@media (max-height: 520px) and (orientation: landscape) and (max-width: 899px) {
  /* phone landscape: compact, still scrollable */
  .letter-hero { font-size: 4.2rem; }
  .mascot { width: 120px; }
  #app { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .learn-stage { padding: 12px; }
  .prompt-card { padding: 12px; }
}

/* iPad / tablet landscape: 1024x768, 1180x820, 1366x1024 — no long vertical scroll */
@media (orientation: landscape) and (min-width: 1000px) {
  html, body {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  #app {
    height: 100dvh;
    max-height: 100dvh;
    max-width: 1400px;
    overflow: hidden;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
  }
  .topbar {
    flex: 0 0 auto;
    min-height: 48px;
    margin-bottom: 6px;
  }
  .topbar .title { font-size: 1.15rem; }
  .back-btn, .icon-btn, .star-pill { min-height: 48px; min-width: 48px; }

  /* Home */
  .home-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .hero-title { font-size: clamp(1.6rem, 3.2vw, 2.2rem); margin: 2px 0 2px; }
  .hero-sub { margin-bottom: 12px; }
  .home-layout .lesson-grid {
    grid-template-columns: 1fr 1fr;
    flex: 1;
    min-height: 0;
    align-content: stretch;
  }
  .home-layout .lesson-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 0;
    padding: 18px 16px;
  }
  .home-layout .big-letter { width: 68px; height: 68px; font-size: 1.8rem; }
  footer.note { margin-top: 10px; margin-bottom: 0; }

  /* Lesson menu */
  .lesson-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .lesson-layout .hint { margin: 0 0 8px; }
  .lesson-layout .letter-row {
    flex: 0 0 auto;
    margin: 0 0 10px;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  }
  .lesson-layout .letter-chip { min-height: 72px; font-size: 1.7rem; }
  .lesson-layout .mode-grid {
    flex: 1;
    min-height: 0;
    grid-template-columns: 1fr 1fr;
    align-content: stretch;
  }
  .lesson-layout .mode-card {
    min-height: 0;
    height: 100%;
    padding: 12px 14px;
  }
  .lesson-layout .mode-card .emoji { font-size: 1.8rem; }

  /* Learn: hero left, controls + words right */
  .learn-layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.85fr) minmax(360px, 1.2fr);
    gap: 14px;
    align-items: stretch;
  }
  .learn-stage {
    margin: 0;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    height: auto;
  }
  .learn-stage .mascot {
    width: min(220px, 32vh);
    max-height: 34vh;
    object-fit: contain;
    margin-bottom: 4px;
  }
  .learn-stage .letter-hero {
    font-size: clamp(4.2rem, 16vh, 7.5rem);
    margin: 0;
  }
  .learn-stage .sound-tag { margin: 4px 0 0; font-size: 1.15rem; }
  .learn-side {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  .learn-side .phrase {
    font-size: 1.15rem;
    margin: 0 0 8px;
    text-align: center;
    flex: 0 0 auto;
  }
  .learn-side .learn-controls {
    margin: 0 0 6px;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .learn-side .learn-controls .btn {
    min-height: 52px;
    margin: 0;
    font-size: 1.05rem;
    padding: 8px 12px;
  }
  .learn-side .hint { margin: 2px 0 6px; flex: 0 0 auto; }
  .learn-side .word-grid {
    grid-template-columns: 1fr 1fr;
    flex: 1 1 auto;
    min-height: 0;
    gap: 10px;
  }
  .learn-side .word-card {
    min-height: 0;
    height: 100%;
    padding: 8px 8px 10px;
  }
  .learn-side .word-card .pic {
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 4px;
  }
  .learn-side .word-card img {
    max-height: min(16vh, 120px);
  }
  .learn-side .word-card .en { font-size: 1.15rem; }
  .learn-side .btn-row:not(.learn-controls) {
    flex: 0 0 auto;
    margin-top: 8px;
  }
  .learn-side .btn-row:not(.learn-controls) .btn {
    min-height: 48px;
    font-size: 1rem;
  }

  /* Quizzes: prompt left, answers in one row */
  .quiz-layout {
    display: grid;
    grid-template-columns: minmax(240px, 0.72fr) minmax(380px, 1.3fr);
    gap: 14px;
    align-items: stretch;
  }
  .quiz-layout .prompt-card {
    margin: 0;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 0;
  }
  .quiz-layout .listen-btn {
    width: 100%;
    min-height: 64px;
    margin-top: 12px;
    font-size: 1.25rem;
  }
  .quiz-layout .choice-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    min-height: 0;
    height: 100%;
    align-content: stretch;
  }
  .quiz-layout .choice {
    min-height: 0;
    height: 100%;
    font-size: clamp(3.4rem, 16vh, 6.2rem);
  }
  .quiz-layout .choice.pic-choice img {
    max-height: min(36vh, 260px);
  }

  /* Matching: board fills remaining height, no page scroll */
  .match-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .match-layout .prompt-card {
    flex: 0 0 auto;
    margin: 0 0 10px;
    padding: 10px 16px;
  }
  .match-layout .prompt-card .prompt-text { margin: 0; }
  .match-layout .prompt-card .prompt-en, .match-layout .progress { margin: 2px 0 0; }
  .match-board {
    flex: 1 1 auto;
    min-height: 0;
    max-width: none;
    width: 100%;
    gap: 12px;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
  }
  .match-board.match-cols-2 { grid-template-columns: repeat(2, 1fr); max-width: 720px; margin-left: auto; margin-right: auto; }
  .match-card {
    aspect-ratio: auto;
    min-height: 0;
    height: 100%;
  }
  .match-card .face { font-size: clamp(3.2rem, 12vh, 5.5rem); }

  /* Sentences: two-column list fits the screen */
  .sentences-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .sentences-layout .hint { margin: 0 0 6px; flex: 0 0 auto; }
  .sentences-layout .sight-row { margin: 0 0 8px; flex: 0 0 auto; }
  .sentences-layout .sight-chip { min-height: 52px; font-size: 1.35rem; padding: 6px 16px; }
  .sentence-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  .sentence-list .sentence-card {
    margin: 0;
    padding: 8px 12px;
    font-size: 1.2rem;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
  .sentence-list .sentence-inner {
    display: block;
    text-align: center;
    line-height: 1.45;
  }
  .sentence-list .sentence-inner .sight { padding: 0 0.06em; }
  .sentence-list .pic-inline { height: 48px; width: 68px; }
  .sentence-list .pic-inline img { max-height: 46px; }
  .sentences-layout .btn-row { flex: 0 0 auto; margin-top: 8px; }
  .sentences-layout .btn { min-height: 52px; }

  /* Result stays centered in remaining space */
  .result { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 12px; }
}

/* Slightly shorter 4:3 iPads (1024x768) — tighten vertical rhythm */
@media (orientation: landscape) and (min-width: 1000px) and (max-height: 800px) {
  .learn-stage .mascot { width: min(170px, 28vh); max-height: 28vh; }
  .learn-stage .letter-hero { font-size: clamp(3.6rem, 14vh, 6rem); }
  .learn-side .word-card img { max-height: min(13vh, 96px); }
  .learn-side .learn-controls .btn { min-height: 46px; font-size: 1rem; }
  .quiz-layout .listen-btn { min-height: 56px; }
  .quiz-layout .choice.pic-choice img { max-height: min(32vh, 200px); }
  .sentence-list .sentence-card { font-size: 1.1rem; padding: 6px 10px; }
}
