/* ธีมสีสดใส ตัวอักษรใหญ่ ปุ่มใหญ่ — ออกแบบให้เด็ก 3-6 ขวบมองเห็นจากระยะ 2 เมตร */

:root {
  --sky: #7FD4F5;
  --sky-deep: #3FB3E3;
  --grass: #8DD86B;
  --sun: #FFD34E;
  --giraffe: #F5C061;
  --giraffe-dark: #C77B2B;
  --ink: #3B2A16;
  --white: #FFFFFF;
  --pass: #45C96A;
  --fail: #FF8A5B;
  --shadow: 0 8px 0 rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Baloo Bhaijaan 2', 'Sarabun', sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, #BDEBFF 55%, var(--grass) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ก้อนเมฆลอยพื้นหลัง */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(closest-side, #fff 92%, transparent) 12% 18% / 160px 60px no-repeat,
    radial-gradient(closest-side, #fff 92%, transparent) 78% 12% / 200px 72px no-repeat,
    radial-gradient(closest-side, #fff 92%, transparent) 55% 28% / 120px 48px no-repeat;
  opacity: .75;
  pointer-events: none;
  animation: drift 40s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translateX(30px); } }

#app { position: relative; z-index: 1; }

/* ─── ระบบหน้าจอ ─── */
.screen {
  display: none;
  min-height: 100vh;
  padding: 24px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.screen.active { display: flex; }

h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); font-weight: 800; color: var(--giraffe-dark); }
h2 { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800; color: var(--giraffe-dark); text-align: center; }
.subtitle { font-size: clamp(1rem, 2.4vw, 1.4rem); line-height: 1.6; text-align: center; }
.screen-sub { font-size: 1.1rem; text-align: center; max-width: 640px; }
.hint { font-size: .95rem; opacity: .7; text-align: center; }

.title-card {
  background: rgba(255, 255, 255, .88);
  border: 6px solid var(--white);
  border-radius: 36px;
  padding: 36px 44px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 560px;
}

/* ─── ปุ่ม ─── */
.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--ink);
  background: var(--sun);
  border: none;
  border-radius: 999px;
  padding: 14px 32px;
  cursor: pointer;
  box-shadow: 0 6px 0 #D9A81E;
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #D9A81E; }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #D9A81E; }
.btn-big { font-size: 1.8rem; padding: 18px 48px; }

/* ─── มาสคอตยีราฟ ─── */
.giraffe { width: 100%; height: 100%; overflow: visible; }
.giraffe-hero { width: 180px; height: 216px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px); } }

.arm { transform-box: fill-box; transform-origin: 50% 8%; }
.arm-l { transform: rotate(18deg); }
.arm-r { transform: rotate(-18deg); }

/* ยีราฟสาธิต: ชูแขนขึ้นตามจังหวะ ให้เด็กทำตาม */
.giraffe-demo .arm-l { animation: raise-l 4s ease-in-out infinite; }
.giraffe-demo .arm-r { animation: raise-r 4s ease-in-out infinite; }
.giraffe-demo { animation: stretch 4s ease-in-out infinite; }
@keyframes raise-l { 0%,10% { transform: rotate(18deg);} 35%,80% { transform: rotate(168deg);} 100% { transform: rotate(18deg);} }
@keyframes raise-r { 0%,10% { transform: rotate(-18deg);} 35%,80% { transform: rotate(-168deg);} 100% { transform: rotate(-18deg);} }
@keyframes stretch { 0%,10% { transform: scaleY(1);} 35%,80% { transform: scaleY(1.06) translateY(-6px);} 100% { transform: scaleY(1);} }

/* ─── เวทีวิดีโอ ─── */
.stage {
  position: relative;
  width: min(72vw, 720px);
  aspect-ratio: 4 / 3;
  border: 8px solid var(--white);
  border-radius: 28px;
  overflow: hidden;
  background: #123;
  box-shadow: var(--shadow);
}
.stage-small { width: min(52vw, 480px); }
.stage canvas { width: 100%; height: 100%; display: block; }

.stage.pose-ok { border-color: var(--pass); box-shadow: 0 0 0 6px rgba(69, 201, 106, .35), var(--shadow); }

.stage-overlay {
  position: absolute; inset: auto 0 0 0;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  padding: 10px;
  text-align: center;
  font-size: 1.05rem;
}

/* ─── หน้าตรวจสอบร่างกาย ─── */
.check-layout { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; justify-content: center; }
.checklist { display: flex; flex-direction: column; gap: 12px; }
.check-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255, 255, 255, .9);
  border-radius: 999px;
  padding: 10px 22px 10px 12px;
  font-size: 1.25rem; font-weight: 700;
  min-width: 220px;
  box-shadow: var(--shadow);
  transition: background .2s;
}
.check-item .mark {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: #ddd; color: #fff; font-size: 1.1rem;
}
.check-item.ok { background: rgba(69, 201, 106, .95); color: #fff; }
.check-item.ok .mark { background: #fff; color: var(--pass); }

.check-progress { width: min(60vw, 520px); height: 16px; background: rgba(255,255,255,.7); border-radius: 999px; overflow: hidden; }
.check-progress .bar { height: 100%; width: 0; background: var(--pass); transition: width .1s linear; }

/* ─── HUD ในเกม ─── */
.hud {
  display: flex; align-items: center; gap: 32px; flex-wrap: wrap; justify-content: center;
  background: rgba(255, 255, 255, .88);
  border-radius: 999px;
  padding: 12px 32px;
  box-shadow: var(--shadow);
}
.stars { display: flex; gap: 6px; }
.star { font-size: 2.2rem; color: #DDD; transition: transform .3s, color .3s; }
.star.on { color: var(--sun); text-shadow: 0 3px 0 #D9A81E; transform: scale(1.15); }
.star.pop { animation: pop .5s ease; }
@keyframes pop { 40% { transform: scale(1.7) rotate(-12deg); } }

.stars-big .star { font-size: 3.4rem; }

.timer-wrap { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.timer-label { font-size: .9rem; opacity: .7; }
.timer-bar { width: min(46vw, 380px); height: 20px; background: #E7E7E7; border-radius: 999px; overflow: hidden; }
.timer-bar .fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--grass), var(--pass)); transition: width .12s linear; }
.timer-num { font-size: 1.05rem; font-weight: 700; }

/* ตัวนับเหรียญ (โชว์เฉพาะรอบโบนัส) */
.coin-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--sun);
  border-radius: 999px;
  padding: 6px 18px 6px 8px;
  font-size: 1.5rem; font-weight: 800;
  box-shadow: 0 4px 0 #D9A81E;
}
.coin-box[hidden] { display: none; }
.coin-box img { width: 34px; height: 34px; }
.coin-box.pop { animation: pop .35s ease; }

/* ─── เลย์เอาต์เกม ─── */
.game-layout { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; justify-content: center; }
.coach { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 260px; }
.mascot { width: 170px; height: 204px; }

/* การ์ดภาพท่าตัวอย่างที่เด็กต้องทำตาม */
.pose-card {
  background: var(--white);
  border-radius: 22px;
  padding: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.pose-card img {
  width: 100%;
  max-width: 220px;
  border-radius: 14px;
  background: #FFF9F0;
}
.pose-step {
  font-size: .95rem;
  font-weight: 800;
  color: var(--giraffe-dark);
  background: var(--sun);
  border-radius: 999px;
  padding: 2px 16px;
}
.pose-name { font-weight: 800; font-size: 1.1rem; text-align: center; }

/* ปุ่มข้ามท่า (สำหรับครู) — ทำให้เรียบไม่เด่น เด็กจะได้ไม่กดเล่น */
.btn-skip {
  font-size: .95rem;
  padding: 8px 20px;
  background: #ECECEC;
  box-shadow: 0 4px 0 #CFCFCF;
  opacity: .8;
}

/* ป้าย "เก่งมาก!" ตอนผ่านด่าน */
.stage-clear {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(69, 201, 106, .55);
  z-index: 5;
}
.stage-clear[hidden] { display: none; }
.stage-clear span {
  font-size: 3.2rem; font-weight: 800; color: #fff;
  text-shadow: 0 4px 14px rgba(0, 0, 0, .4);
  animation: pop .5s ease;
}
.coach-bubble {
  background: var(--white);
  border-radius: 22px;
  padding: 16px 20px;
  font-size: 1.2rem; font-weight: 700; text-align: center;
  box-shadow: var(--shadow);
  min-height: 84px;
  display: grid; place-items: center;
}
.coach-bubble.good { background: var(--pass); color: #fff; }

/* ─── วงแหวนนับเวลาค้างท่า ─── */
.hold-ring {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 180px; height: 180px;
  display: grid; place-items: center;
  pointer-events: none;
}
/* display ด้านบนกินความสำคัญเหนือ [hidden] ของเบราว์เซอร์ ต้องประกาศเองไม่งั้นซ่อนไม่ลง */
.hold-ring[hidden] { display: none; }
.hold-ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.hold-ring circle { fill: none; stroke-width: 8; stroke-linecap: round; }
.hold-ring .track { stroke: rgba(255, 255, 255, .35); }
.hold-ring .prog { stroke: var(--pass); stroke-dasharray: 276.5; stroke-dashoffset: 276.5; }
.hold-ring span {
  font-size: 1.3rem; font-weight: 800; color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}

/* ─── ข้อผิดพลาด ─── */
.error-box {
  position: fixed; inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  background: #fff; border: 6px solid var(--fail);
  border-radius: 24px; padding: 28px 32px;
  max-width: 520px; text-align: center; z-index: 99;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.error-box h3 { color: var(--fail); font-size: 1.5rem; margin-bottom: 10px; }
.error-box p { line-height: 1.6; font-family: 'Sarabun', sans-serif; }

/* ─── จอเล็ก / แท็บเล็ต ─── */
@media (max-width: 900px) {
  .stage, .stage-small { width: 92vw; }
  .coach { flex-direction: row; flex-wrap: wrap; width: 92vw; justify-content: center; align-items: center; }
  .mascot { width: 110px; height: 132px; }
  .pose-card { width: 200px; }
  .coach-bubble { flex: 1; min-width: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
