/* =========================================================
   styles.css — ธีมมินิมอล น่ารัก สดใส สำหรับเด็กอนุบาล
   ========================================================= */
:root {
  --bg: #FFF9F0;
  --bg2: #FFF1E4;
  --card: #FFFFFF;
  --ink: #4A4459;
  --ink-soft: #8A8199;
  --line: #F0E6DA;

  --pink: #FFB3C7;
  --peach: #FFD3A5;
  --mint: #A8E6CF;
  --sky: #A8D8FF;
  --lemon: #FFE9A8;
  --lav: #D9C7FF;
  --gold: #FFC93C;

  --r-lg: 30px;
  --r-md: 22px;
  --r-sm: 14px;
  --shadow: 0 10px 24px rgba(120, 100, 90, .10);
  --shadow-lift: 0 16px 32px rgba(120, 100, 90, .16);
  --font: "Baloo 2", "Comic Sans MS", "Leelawadee UI", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 12% -8%, #FFE9F0 0%, transparent 60%),
    radial-gradient(900px 460px at 100% 0%, #E4F4FF 0%, transparent 55%),
    radial-gradient(800px 500px at 50% 110%, #EAF9EF 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* ---------------- แถบบน ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 10px;
  background: linear-gradient(var(--bg) 72%, rgba(255, 249, 240, 0));
}

.icon-btn {
  flex: none;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s;
}
.icon-btn:active { transform: scale(.92); }
/* ซ่อนแต่ยังกันที่ไว้ เพื่อให้ชื่อหน้าอยู่ตรงกลางเสมอ */
.icon-btn[hidden] { display: block; visibility: hidden; }

.title {
  flex: 1;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  letter-spacing: .2px;
}

.stars-badge {
  flex: none;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 62px;
  height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: linear-gradient(160deg, #FFF0B8, var(--lemon));
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 17px;
}
.badge-star { color: var(--gold); font-size: 19px; }

/* ---------------- ส่วนกลาง ---------------- */
.screen { padding-top: 4px; animation: fadeUp .3s ease both; }

.lead {
  margin: 4px 2px 16px;
  color: var(--ink-soft);
  font-size: 16px;
  text-align: center;
}
.lead b { color: var(--ink); }

/* ---------------- หน้าแรก ---------------- */
.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  margin-bottom: 14px;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.hero-art { width: 76px; flex: none; }
.hero-text h1 { margin: 0 0 4px; font-size: 22px; }
.hero-text p { margin: 0; color: var(--ink-soft); font-size: 15px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  padding: 12px 6px;
  text-align: center;
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 24px; color: var(--ink); }
.stat span { font-size: 13px; color: var(--ink-soft); }

.tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }

.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  min-height: 108px;
  border: none;
  border-radius: var(--r-lg);
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  transition: transform .16s, box-shadow .16s;
}
.tile:active { transform: scale(.97); }
@media (hover: hover) { .tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); } }

.tile-art {
  flex: none;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--tone, var(--lemon));
}
.tile-art .art { width: 54px; }
.tone-mint  { --tone: var(--mint); }
.tone-sky   { --tone: var(--sky); }
.tone-pink  { --tone: var(--pink); }
.tone-lemon { --tone: var(--lemon); }

.tile-text b { display: block; font-size: 19px; }
.tile-text i { font-style: normal; font-size: 14px; color: var(--ink-soft); }

.link-btn {
  display: block;
  margin: 22px auto 0;
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 15px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------------- หมวดคำศัพท์ ---------------- */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (min-width: 620px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }

.cat-card {
  padding: 16px 10px 14px;
  border: none;
  border-radius: var(--r-lg);
  background: var(--card);
  box-shadow: var(--shadow);
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .16s;
}
.cat-card:active { transform: scale(.96); }
.cat-art {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin: 0 auto 8px;
  border-radius: 26px;
  background: var(--tone);
}
.cat-art .art { width: 64px; }
.cat-card b { display: block; font-size: 17px; }
.cat-card i { font-style: normal; font-size: 13px; color: var(--ink-soft); }

/* ---------------- การ์ดคำศัพท์ ---------------- */
.hint-ear { font-size: 18px; }

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.word-card {
  position: relative;
  padding: 14px 10px 12px;
  border: none;
  border-radius: var(--r-md);
  background: var(--card);
  box-shadow: var(--shadow);
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .16s;
}
.word-card:active { transform: scale(.95); }
.word-art { display: block; width: 88px; margin: 0 auto 6px; }
.word-card .en { display: block; font-size: 21px; letter-spacing: .3px; }
.word-card .read { display: block; font-style: normal; font-size: 15px; color: #E8657C; }
.word-card .th { display: block; font-style: normal; font-size: 14px; color: var(--ink-soft); }
.word-card .check {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 18px;
  color: var(--gold);
  opacity: 0;
  transform: scale(.4);
  transition: .25s;
}
.word-card.done .check { opacity: 1; transform: scale(1); }

/* ---------------- ส่วนหัวของเกม ---------------- */
.game-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.round-pill {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 700;
}
.bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: #F2E7DA;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--mint), var(--sky));
  transition: width .4s;
}

/* ---------------- เกมจับคู่ ---------------- */
.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mcol { display: grid; gap: 12px; align-content: start; }

.mcard {
  position: relative;
  display: grid;
  place-content: center;
  min-height: 96px;
  padding: 8px;
  border: 3px solid transparent;
  border-radius: var(--r-md);
  background: var(--card);
  box-shadow: var(--shadow);
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .16s, border-color .16s, background .25s;
}
.mcard:active { transform: scale(.96); }
.mcard .art { width: 76px; }
.mcard.word b { display: block; font-size: 24px; }
.mcard.word i { font-style: normal; font-size: 14px; color: #E8657C; }
.mcard .spk { position: absolute; top: 6px; right: 8px; font-size: 15px; opacity: .5; }

.mcard.picked {
  border-color: var(--sky);
  background: #F2F9FF;
  transform: translateY(-3px) scale(1.02);
}
.mcard.matched {
  border-color: var(--mint);
  background: #EFFBF4;
  cursor: default;
  animation: pop .4s;
}
.mcard.matched .spk { display: none; }
.mcard .tick {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 18px;
  color: var(--gold);
  opacity: 0;
  transform: scale(.4);
  transition: .25s;
}
.mcard.matched .tick { opacity: 1; transform: scale(1); }
.mcard.shake { animation: shake .45s; border-color: var(--pink); }

/* ---------------- เกมฝึกออกเสียง ---------------- */
.speak-card {
  padding: 20px 18px 22px;
  text-align: center;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.speak-art { width: 140px; margin: 0 auto 6px; }
.speak-card .en {
  display: block;
  font-size: 40px;
  line-height: 1.15;
  letter-spacing: .5px;
}
.speak-card.phrase .en { font-size: 28px; }
.speak-card .read { font-size: 20px; color: #E8657C; margin-top: 2px; }
.speak-card .th { font-size: 16px; color: var(--ink-soft); }

.listen-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 6px;
  flex-wrap: wrap;
}

.speak-action { min-height: 132px; display: grid; place-content: center; }

.mini { margin: 8px 0 0; font-size: 14px; color: var(--ink-soft); }
.big-mini { font-size: 20px; font-weight: 800; color: var(--ink); }

.count { display: grid; place-items: center; }
.ring {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(160deg, #FFF0B8, var(--peach));
  font-size: 40px;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.count.now .ring {
  background: linear-gradient(160deg, #FFD9E4, var(--pink));
  animation: pulse 1s infinite;
}

.rate-btns { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.rate-btn {
  display: grid;
  gap: 2px;
  min-width: 92px;
  padding: 12px 10px;
  border: none;
  border-radius: var(--r-md);
  background: #FFF6E3;
  box-shadow: var(--shadow);
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: transform .15s;
}
.rate-btn span { font-size: 20px; color: var(--gold); letter-spacing: -1px; }
.rate-btn:active { transform: scale(.94); }

/* ---------------- ปุ่มทั่วไป ---------------- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  min-height: 56px;
  background: linear-gradient(160deg, #FFD9E4, var(--pink));
  box-shadow: var(--shadow);
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: transform .15s;
}
.btn:active { transform: scale(.95); }
.btn.big { font-size: 21px; padding: 16px 34px; min-height: 66px; }
.btn.round { background: linear-gradient(160deg, #DFF1FF, var(--sky)); font-size: 17px; min-height: 52px; }
.btn.ghost { background: var(--card); color: var(--ink-soft); }
.btn.small { min-height: 46px; padding: 10px 16px; font-size: 15px; }
.btn.danger { background: linear-gradient(160deg, #FFDCDC, #FFB3B3); }
.btn.mic { background: linear-gradient(160deg, #FFE9A8, var(--peach)); }

/* ---------------- หน้าจบเกม ---------------- */
.finish {
  padding: 26px 20px 30px;
  text-align: center;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  animation: pop .45s;
}
.finish-art { width: 130px; margin: 0 auto; }
.finish h2 { margin: 8px 0 4px; font-size: 26px; }
.finish p { margin: 0; color: var(--ink-soft); }
.gained {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 18px;
  padding: 10px 20px;
  border-radius: 999px;
  background: linear-gradient(160deg, #FFF0B8, var(--lemon));
  font-size: 20px;
  font-weight: 800;
}
.finish-btns { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

/* ---------------- หน้าผู้ปกครอง ---------------- */
.panel {
  padding: 18px 20px;
  margin-bottom: 14px;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 10px; font-size: 19px; }
.panel p { margin: 0 0 10px; font-size: 15px; line-height: 1.7; }
.muted { color: var(--ink-soft); }
.warn {
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: #FFF3E0;
  color: #A2703B;
  font-size: 14px;
}
.tips { margin: 0; padding-left: 20px; font-size: 15px; line-height: 1.9; }
.tips li { margin-bottom: 4px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
}
.switch-row input { width: 26px; height: 26px; accent-color: #FF8FA8; }

.code-box {
  display: inline-block;
  padding: 12px 20px;
  border-radius: var(--r-sm);
  background: #F6F1E8;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 4px;
}
.row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.row input {
  flex: 1;
  min-width: 160px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 16px;
  text-transform: uppercase;
  color: var(--ink);
  background: #fff;
}
.row input:focus { outline: none; border-color: var(--sky); }

/* ---------------- เอฟเฟกต์ ---------------- */
#fx {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
}
.confetti {
  position: absolute;
  top: -24px;
  width: 11px;
  height: 15px;
  border-radius: 3px;
  animation: fall 1.7s cubic-bezier(.3, .6, .5, 1) forwards;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-lift);
  font-size: 17px;
  font-weight: 700;
  animation: pop .3s;
}
.toast.good { background: linear-gradient(160deg, #E6FBF0, var(--mint)); }
.toast.bad { background: linear-gradient(160deg, #FFE7EC, var(--pink)); }
.toast.out { opacity: 0; transition: opacity .45s; }

.art { display: block; width: 100%; height: auto; }
.pop { animation: pop .4s; }
.float { animation: float 3s ease-in-out infinite; }

@keyframes pop {
  0% { transform: scale(.86); }
  55% { transform: scale(1.07); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 143, 168, .55); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 18px rgba(255, 143, 168, 0); }
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(540deg); opacity: .2; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .confetti { display: none; }
}

@media (max-width: 380px) {
  .speak-card .en { font-size: 34px; }
  .mcard.word b { font-size: 20px; }
  .stat b { font-size: 20px; }
}
