/* =========================================================
   สไตล์เกมทายรูปภาพสำหรับเด็ก 3 ขวบ
   - สีพาสเทลสดใส  - ปุ่มใหญ่ (อย่างน้อย 150x150px)
   - ไม่มีสีแดงหรือเอฟเฟกต์น่ากลัวเมื่อตอบผิด
   ========================================================= */

/* ---------- ตัวแปรสี (แก้ที่นี่ที่เดียว เปลี่ยนทั้งเกม) ---------- */
:root {
  --bg: #FFF6EC;            /* พื้นหลังครีมอ่อน */
  --ink: #5B4A6B;           /* สีตัวอักษร ม่วงเทาอ่อนโยน */
  --card: #FFFFFF;
  --pink: #FFD6E0;
  --yellow: #FFF1C1;
  --blue: #D4F1FF;
  --mint: #D5F5E3;
  --lavender: #E8DEFF;
  --good: #8EDDB0;          /* สีเขียวมิ้นต์เมื่อตอบถูก */
  --shadow: 0 8px 0 rgba(91, 74, 107, .12), 0 14px 28px rgba(91, 74, 107, .12);
  --radius: 32px;
  --choice-size: clamp(150px, 27vw, 250px);  /* ขนาดปุ่มตัวเลือก (ไม่ต่ำกว่า 150px) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Mitr", "Kanit", "Leelawadee UI", "Thonburi", "Tahoma", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, var(--pink) 0 90px, transparent 91px),
    radial-gradient(circle at 92% 18%, var(--blue) 0 70px, transparent 71px),
    radial-gradient(circle at 85% 92%, var(--yellow) 0 110px, transparent 111px),
    radial-gradient(circle at 6% 88%, var(--mint) 0 80px, transparent 81px),
    var(--bg);
  background-attachment: fixed;
  /* ป้องกันการเลือกข้อความ/เมนูค้างเมื่อเด็กกดนาน */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;  /* ลดดีเลย์การแตะบนมือถือ */
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; -webkit-user-drag: none; }

/* =========================================================
   หน้าแรก: เลือกหมวด
   ========================================================= */
.home-header { text-align: center; margin: 10px 0 24px; }
.home-mascot { font-size: 80px; animation: bob 2.4s ease-in-out infinite; }
.home-title  { font-size: clamp(32px, 6vw, 52px); margin: 6px 0 0; font-weight: 600; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
  flex: 1;
  align-content: start;
}

.category-card {
  background: var(--card-color, var(--card));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 220px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform .15s ease;
}
.category-card:hover  { transform: translateY(-4px) rotate(-1deg); }
.category-card:active { transform: scale(.95); }

.category-pic { font-size: 110px; line-height: 1; }
.category-pic img { width: 150px; height: 150px; object-fit: contain; }
.category-name { font-size: 32px; font-weight: 600; }

/* =========================================================
   หน้าเกม
   ========================================================= */
.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-color, var(--card));
  border-radius: 999px;
  padding: 10px;
  box-shadow: var(--shadow);
}

/* ปุ่มกลม (บ้าน / ลำโพง) */
.round-btn {
  width: 72px;
  height: 72px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--card);
  font-size: 38px;
  display: grid;
  place-items: center;
  box-shadow: 0 5px 0 rgba(91, 74, 107, .15);
  transition: transform .12s ease;
}
.round-btn:active { transform: scale(.9); }
.speak-btn { width: 88px; height: 88px; font-size: 46px; }
.speak-btn.speaking { animation: pulse .8s ease-in-out infinite; }

/* แถบดาว */
.star-bar { display: flex; gap: clamp(2px, 1.2vw, 10px); }
.star-slot {
  font-size: clamp(28px, 6vw, 48px);
  filter: grayscale(1) opacity(.3);
  transition: filter .3s ease;
}
.star-slot.filled { filter: none; }
.star-slot.pop    { animation: starPop .7s ease; }

/* คำถาม */
.prompt {
  text-align: center;
  font-size: clamp(26px, 5vw, 40px);
  margin: 28px 0 18px;
  min-height: 1.6em;
}
.prompt strong {
  background: var(--card);
  padding: 2px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(91, 74, 107, .12);
}

/* ตัวเลือก 3 รูป */
.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: clamp(14px, 3vw, 32px);
  flex: 1;
}

.choice {
  width: var(--choice-size);
  min-width: 150px;
  aspect-ratio: 1 / 1.12;
  border: 6px solid transparent;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  transition: transform .15s ease, opacity .3s ease, border-color .2s ease;
  animation: popIn .45s cubic-bezier(.34, 1.56, .64, 1) both;
}
.choice:nth-child(2) { animation-delay: .08s; }
.choice:nth-child(3) { animation-delay: .16s; }
.choice:active { transform: scale(.94); }

.choice-pic { font-size: calc(var(--choice-size) * .55); line-height: 1; }
.choice-pic img { width: calc(var(--choice-size) * .68); height: calc(var(--choice-size) * .68); object-fit: contain; }
.choice-word { font-size: clamp(20px, 3.4vw, 30px); font-weight: 600; }

/* ตอบถูก: ขอบเขียวมิ้นต์ + เด้งดีใจ */
.choice.is-correct {
  border-color: var(--good);
  background: #F1FFF7;
  animation: happyBounce .8s ease;
}
/* ตอบผิด: แค่ส่ายเบาๆ แล้วจางลงเล็กน้อย (ไม่มีสีแดง ไม่มีเสียงน่ากลัว) */
.choice.try-again {
  animation: gentleWobble .5s ease;
  opacity: .45;
}
/* ระหว่างรอ ไม่ให้กดซ้ำ */
.choices.locked .choice { pointer-events: none; }

/* ข้อความแนะนำผู้ปกครอง */
.voice-hint {
  text-align: center;
  font-size: 16px;
  opacity: .7;
  margin: 20px auto 0;
  max-width: 520px;
}

/* หน้าจอแตะเพื่อเริ่ม */
.start-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 246, 236, .92);
  display: grid;
  place-items: center;
  z-index: 50;
}
.start-overlay[hidden] { display: none; }
.start-btn {
  width: 220px;
  height: 220px;
  border: none;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: pulse 1.6s ease-in-out infinite;
}
.start-icon  { font-size: 90px; line-height: 1; margin-left: 12px; }
.start-label { font-size: 30px; font-weight: 600; }

/* =========================================================
   หน้าฉลอง
   ========================================================= */
.win-box {
  margin: auto;
  text-align: center;
  background: var(--card);
  border-radius: 48px;
  box-shadow: var(--shadow);
  padding: 32px 24px 36px;
  width: min(640px, 100%);
}
.win-trophy { font-size: clamp(110px, 22vw, 170px); line-height: 1; animation: bob 2s ease-in-out infinite; }
.win-title  { font-size: clamp(34px, 7vw, 56px); margin: 10px 0; }
.win-stars  { font-size: clamp(40px, 9vw, 64px); }
.win-stars span {
  display: inline-block;
  animation: starPop .7s ease both;
  animation-delay: calc(var(--i) * .15s + .2s);
}

.win-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  margin-top: 26px;
}
.big-btn {
  width: 160px;
  height: 160px;
  border: none;
  border-radius: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  line-height: 1.1;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.big-btn span { font-size: 24px; font-weight: 600; margin-top: 6px; }
.big-btn:active { transform: scale(.93); }
.big-btn.again { background: var(--mint); }
.big-btn.home  { background: var(--blue); }
.big-btn.sound { background: var(--lavender); }

/* =========================================================
   แอนิเมชันดาว / ลูกโป่งลอยขึ้น
   ========================================================= */
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}
.confetti span {
  position: absolute;
  bottom: -80px;
  font-size: var(--size, 48px);
  animation: floatUp var(--dur, 2.6s) ease-out forwards;
  animation-delay: var(--delay, 0s);
}

/* ---------- keyframes ---------- */
@keyframes popIn {
  from { transform: scale(.4); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}
@keyframes happyBounce {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.12) rotate(-3deg); }
  60% { transform: scale(.97) rotate(2deg); }
}
@keyframes gentleWobble {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
@keyframes starPop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes floatUp {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--drift, 0px), -115vh) rotate(var(--spin, 20deg)); opacity: .9; }
}

/* ---------- จอแคบ (มือถือแนวตั้ง) ---------- */
@media (max-width: 520px) {
  :root { --choice-size: 150px; }
  .round-btn { width: 60px; height: 60px; font-size: 30px; }
  .speak-btn { width: 72px; height: 72px; font-size: 38px; }
  .category-card { min-height: 180px; }
}

/* ---------- จอเตี้ย (แท็บเล็ต/มือถือแนวนอน) ---------- */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --choice-size: clamp(150px, 24vw, 200px); }
  .prompt { margin: 12px 0 10px; }
}

/* ---------- ผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* คำแปลตัวเล็กใต้คำศัพท์ (สำหรับผู้ปกครอง) */
.choice-hint {
  font-size: clamp(13px, 2vw, 17px);
  opacity: .55;
  margin-top: -4px;
}

/* Category selection and a clear start screen. */
.category-instructions{font-size:clamp(16px,3vw,21px);margin:8px 0 0;}
.category-count{font-size:16px;opacity:.8;}
.category-name{text-align:center;font-size:clamp(22px,4vw,30px);}
.start-overlay{overflow-y:auto;padding:24px 16px;}
.start-panel{display:flex;flex-direction:column;align-items:center;gap:28px;text-align:center;max-width:100%;}
.selected-category{font-size:clamp(26px,6vw,42px);margin:0;}
.change-category{display:inline-flex;align-items:center;justify-content:center;min-height:48px;padding:10px 20px;background:#fff;border:2px solid var(--ink);border-radius:16px;font-size:19px;}
.change-category:focus-visible,.category-card:focus-visible{outline:4px solid #2563eb;outline-offset:5px;}
.picture-credits{font:12px/1.6 system-ui,sans-serif;text-align:center;padding:12px 16px;color:#5B4A6B;}
.picture-credits a{text-decoration:underline;}
@media(max-height:560px){.start-panel{gap:14px}.start-btn{width:160px;height:160px}.start-icon{font-size:64px}.start-label{font-size:24px}}
