:root {
  --bg: #FFF6E9;
  --card: #FFFFFF;
  --ink: #2F3542;
  --muted: #747D8C;
  --accent: #FF6B6B;
  --good: #2ED573;
  --bad: #FF4757;
  --shadow: 0 6px 0 rgba(0, 0, 0, .08), 0 10px 24px rgba(0, 0, 0, .08);
  --radius: 28px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }

.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: var(--bg);
}
.topbar h1 { flex: 1; margin: 0; font-size: 30px; }
.round-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 26px;
}
.round-btn:active { transform: translateY(3px); }
.stars {
  background: var(--card);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 22px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

main {
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 1100px;
  margin: 0 auto;
}

h2 { font-size: 24px; margin: 24px 4px 12px; }
.subtitle { color: var(--muted); margin: 0 4px 16px; font-size: 18px; }

/* Lưới thẻ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 18px;
}
.grid.small { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }

.tile {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 12px;
  text-align: center;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform .1s;
}
.tile:active { transform: scale(.96); }
.tile .emoji { font-size: 64px; line-height: 1.1; }
.tile .label { font-size: 22px; font-weight: 700; }
.tile .label-vi { font-size: 16px; color: var(--muted); }
.tile.letter { min-height: 110px; padding: 10px; }
.tile.letter .big { font-size: 48px; font-weight: 800; }

/* Thẻ học lớn */
.flash {
  background: var(--card);
  border-radius: 40px;
  box-shadow: var(--shadow);
  margin: 12px auto;
  max-width: 640px;
  min-height: 52vh;
  padding: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}
.flash .emoji { font-size: 160px; line-height: 1.1; }
.flash .letter-big { font-size: 140px; font-weight: 800; line-height: 1; }
.flash .word { font-size: 52px; font-weight: 800; }
.flash .word-vi { font-size: 26px; color: var(--muted); }
.flash .hint { font-size: 18px; color: var(--muted); }
.flash .swatch { width: 200px; height: 200px; border-radius: 50%; border: 6px solid #eee; }

.nav-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-top: 16px;
}
.big-btn {
  min-width: 96px; height: 96px;
  border-radius: 48px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 44px;
  padding: 0 24px;
}
.big-btn:active { transform: translateY(4px); }
.big-btn.primary { background: var(--accent); color: #fff; }
.counter { font-size: 20px; color: var(--muted); min-width: 80px; text-align: center; }

/* Trò chơi */
.question {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  margin: 8px 0 18px;
}
.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  max-width: 720px;
  margin: 0 auto;
}
.choice {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 180px;
  font-size: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.choice .txt { font-size: 64px; font-weight: 800; }
.choice.correct { background: #DFFFE9; animation: pop .4s; }
.choice.wrong { background: #FFE1E4; animation: shake .4s; }
.count-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 720px;
  margin: 0 auto 20px;
  padding: 20px;
  font-size: 64px;
  text-align: center;
  line-height: 1.3;
}

.memory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
}
.mcard {
  aspect-ratio: 1;
  border-radius: 24px;
  background: var(--accent);
  box-shadow: var(--shadow);
  font-size: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.mcard.open, .mcard.done { background: var(--card); color: var(--ink); }
.mcard.done { opacity: .45; }

.progress {
  height: 16px;
  background: #fff;
  border-radius: 999px;
  max-width: 720px;
  margin: 0 auto 16px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px #eee;
}
.progress > div { height: 100%; background: var(--good); transition: width .3s; }

.result { text-align: center; padding: 40px 0; }
.result .emoji { font-size: 140px; }
.result .msg { font-size: 34px; font-weight: 800; margin: 12px 0 24px; }

/* Cài đặt */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 18px;
  font-size: 20px;
}
.panel label { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; }
.panel input[type=range] { width: 50%; }
.panel input[type=checkbox] { width: 32px; height: 32px; }
.panel select, .panel input[type=text] { font-size: 18px; padding: 8px; border-radius: 12px; border: 2px solid #ddd; max-width: 60%; }
.panel p { margin: 8px 0; color: var(--muted); font-size: 17px; line-height: 1.5; }
.panel button.text-btn { background: var(--bg); padding: 10px 18px; border-radius: 14px; font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 30px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 14px 24px;
  border-radius: 999px;
  font-size: 20px;
  z-index: 10;
}

.parent-gate { text-align: center; }
.parent-gate .question { font-size: 30px; }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes shake {
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

@media (max-width: 600px) {
  .tile .emoji { font-size: 48px; }
  .flash .emoji { font-size: 110px; }
  .flash .word { font-size: 38px; }
  .choice { min-height: 130px; font-size: 64px; }
  .mcard { font-size: 36px; }
}

/* Chọn ngôn ngữ */
.lang-row { display: flex; gap: 12px; margin: 4px 0 8px; }
.lang-btn {
  flex: 1;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 12px 8px;
  font-size: 20px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 4px solid transparent;
}
.lang-btn .flag { font-size: 34px; }
.lang-btn.active { border-color: var(--accent); }

/* Tập đọc */
.reading-banner {
  width: 100%;
  margin-top: 18px;
  display: flex; align-items: center; gap: 18px;
  text-align: left;
  background: linear-gradient(135deg, #FFE0E0, #FFF3C4);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 24px;
}
.reading-banner .emoji { font-size: 64px; }
.reading-banner .label { font-size: 28px; font-weight: 800; }
.reading-banner .label-vi { font-size: 18px; color: var(--muted); }
.tile .big-letter { font-size: 40px; font-weight: 800; color: var(--accent); }
.tile .done-mark { font-size: 18px; min-height: 22px; }
.lesson-head { min-height: auto; padding: 24px; margin-bottom: 20px; }
.lesson-head .letter-big { font-size: 90px; color: var(--accent); }

.syl-grid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 16px;
  max-width: 820px; margin: 0 auto;
}
.syl-tile {
  min-width: 130px; height: 120px;
  padding: 0 20px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  font-size: 60px; font-weight: 800;
}
.syl-tile.small { min-width: 110px; height: 100px; font-size: 48px; color: var(--ink); }
.syl-tile.used { opacity: .25; }
.syl-tile.wrong { background: #FFE1E4; animation: shake .4s; }
.syl-tile.reading, .syl.reading { background: #FFF3C4; border-radius: 12px; }
.syl-tile:active { transform: translateY(3px); }

.reading-word { font-size: 72px; letter-spacing: 2px; }
.syl { display: inline-block; padding: 0 2px; cursor: pointer; }
.sentence { font-size: 54px; font-weight: 800; line-height: 1.5; }
.sword { display: inline-block; margin: 0 14px; }

.slots { display: flex; justify-content: center; gap: 12px; margin: 10px 0 28px; }
.slot {
  min-width: 120px; height: 100px;
  border: 4px dashed #ccc;
  border-radius: 20px;
  font-size: 52px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.build-emoji { font-size: 110px; }
.center { text-align: center; }
.plus { font-weight: 800; color: var(--accent); }

@media (max-width: 600px) {
  .lang-btn { font-size: 16px; }
  .syl-tile { min-width: 96px; height: 90px; font-size: 42px; }
  .reading-word { font-size: 48px; }
  .sentence { font-size: 34px; }
  .slot { min-width: 80px; height: 76px; font-size: 36px; }
}

/* ---------- Sửa sau soát giao diện (G9) ---------- */
.topbar h1 {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(20px, 5.5vw, 30px);
}
.stars { flex: none; white-space: nowrap; }
.round-btn { width: 64px; height: 64px; flex: none; }
.big-btn { font-weight: 800; }
.progress { background: #EFE6D8; box-shadow: none; }
.panel select { font: inherit; min-height: 48px; }

/* Nút tập đọc là hàng phụ; "Học tiếp" mới là việc chính */
.reading-banner { padding: 10px 20px; margin-top: 14px; }
.reading-banner .emoji { font-size: 40px; }
.reading-banner .label { font-size: 22px; }

/* Chip 🔊 nghe lại */
.question .say {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; margin-left: 12px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  vertical-align: middle;
}

/* Thẻ úp của trò lật thẻ: không dùng đỏ trên đỏ */
.mcard { background: #5B8DEF; }

/* Danh sách bài: chữ cái lớn không xuống dòng */
.tile .big-letter { white-space: nowrap; }
.tile .big-letter.long { font-size: 26px; }

/* Các mục trong một bài: chia hàng đều */
.lesson-acts { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 1000px) {
  .lesson-acts { grid-template-columns: repeat(6, 1fr); }
}
@media (orientation: landscape) and (max-height: 900px) {
  .lesson-head { padding: 12px; }
  .lesson-head .letter-big { font-size: 64px; }
}

@media (max-width: 600px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .stars { padding: 8px 12px; font-size: 18px; }
  .round-btn { width: 56px; height: 56px; }
  .grid, .lesson-acts { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .tile .label { font-size: 18px; }
  .lang-btn .flag { font-size: 26px; }
  .lang-btn { padding: 10px 4px; gap: 4px; }
}
