/* ===== ส่วนที่มีเฉพาะตอนเป็นแอปติดตั้งได้ =====
   ไฟล์นี้เขียนเอง ไม่ได้ถูกสร้างจาก build.js */

/* เผื่อขอบจอโค้งและแถบล่างของ iPhone ตอนเปิดแบบเต็มจอ */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ===== ตัวละคร 3D ประจำพยัญชนะ ===== */
.char3d {
  width: 100%;
  height: 220px;
  margin-bottom: 10px;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 62%,
    rgba(56, 189, 248, .16), rgba(139, 92, 246, .07) 55%, transparent 72%);
  animation: charIn .45s cubic-bezier(.2, .9, .3, 1.2);
}
.char3d model-viewer {
  width: 100%;
  height: 100%;
  --poster-color: transparent;
  --progress-bar-color: var(--sky, #38bdf8);
  background: transparent;
}

@keyframes charIn {
  from { opacity: 0; transform: scale(.82) translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* เด็กบางคนไวต่อการเคลื่อนไหว และบางเครื่องแบตน้อย */
@media (prefers-reduced-motion: reduce) {
  .char3d { animation: none; }
}

/* ===== รางวัลและเอฟเฟกต์ =====
   ทุกอย่างใช้ transform กับ opacity เท่านั้น เพราะสองตัวนี้เบราว์เซอร์
   ส่งให้การ์ดจอทำ ไม่ต้องคำนวณผังหน้าใหม่ จึงลื่นแม้บนมือถือราคาถูก */

/* ตอบถูก — เด้งสั้น ๆ 0.45 วินาที ไม่ขัดจังหวะการอ่าน */
.fx-pop { animation: fxPop .45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes fxPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* ตอบผิด — ส่ายเบา ๆ พอให้รู้ว่ายังไม่ใช่ ไม่ใช่การดุ */
.fx-nudge { animation: fxNudge .4s ease-in-out; }
@keyframes fxNudge {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-5px); }
  75%      { transform: translateX(5px); }
}

/* โปรยกระดาษ — เฉพาะตอนจบบท ไม่ใช่ทุกข้อ */
.fx-confetti {
  position: absolute; inset: 0;
  overflow: hidden; pointer-events: none;
  border-radius: inherit;
}
.fx-confetti i {
  position: absolute; top: -14px;
  width: 8px; height: 12px; border-radius: 2px;
  animation: fxFall 2.2s cubic-bezier(.25, .6, .4, 1) forwards;
}
@keyframes fxFall {
  0%   { opacity: 0; transform: translateY(0) rotate(0); }
  12%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(320px) rotate(540deg); }
}

/* ตราทักษะ — ได้เมื่อผ่านบท ไม่ใช่ทุกครั้งที่ตอบถูก */
.fx-badge {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 14px; padding: 9px 16px 9px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(251, 191, 36, .18), rgba(251, 113, 133, .14));
  border: 1px solid rgba(251, 191, 36, .45);
  font-weight: 800; font-size: .95rem;
}
.fx-badge-in { animation: fxBadge .6s cubic-bezier(.2, .9, .3, 1.35); }
@keyframes fxBadge {
  0%   { opacity: 0; transform: scale(.5) translateY(10px); }
  100% { opacity: 1; transform: none; }
}

/* หน้าสรุปผลต้องเป็นจุดอ้างอิงให้กระดาษโปรยอยู่ในกรอบการ์ด */
#vResult .card { position: relative; overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .fx-pop, .fx-nudge, .fx-badge-in { animation: none; }
  .fx-confetti { display: none; }
}

/* ===== แถบบอกว่าเน็ตหลุด ===== */
.netbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 900;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: #f59e0b;
  color: #422006;
  font-size: .9rem;
  font-weight: 700;
  text-align: center;
  transform: translateY(110%);
  transition: transform .25s ease;
}
.netbar.on { transform: translateY(0); }

/* ===== ปุ่มติดตั้งลงหน้าจอโฮม ===== */
.install {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 880;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--sky, #38bdf8), var(--grape, #8b5cf6));
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: .95rem;
  box-shadow: 0 8px 22px rgba(56, 189, 248, .42);
  cursor: pointer;
}
.install.on { display: inline-flex; }
.install:active { transform: translateY(1px); }

/* ===== หน้าบอกว่ายังไม่ได้ตั้งค่า =====
   ขึ้นทับทุกอย่าง เพราะถ้าไม่ตั้งค่า แอปทำอะไรไม่ได้เลย
   ยอมให้เห็นชัดตั้งแต่แรก ดีกว่าปล่อยให้กดแล้วเงียบ */
.setup {
  position: fixed;
  inset: 0;
  z-index: 999;
  overflow: auto;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
  background: #0f172a;
  color: #e2e8f0;
  font-size: .95rem;
  line-height: 1.65;
}
.setup .box {
  max-width: 560px;
  margin: 0 auto;
}
.setup h1 { font-size: 1.3rem; margin: 0 0 6px; color: #fff; }
.setup .lead { color: #94a3b8; margin-bottom: 20px; }
.setup ol { padding-left: 20px; margin: 0 0 18px; }
.setup li { margin-bottom: 10px; }
.setup code {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  background: #1e293b;
  color: #7dd3fc;
  font-size: .88em;
  word-break: break-all;
}
.setup pre {
  margin: 8px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #1e293b;
  color: #7dd3fc;
  font-size: .85rem;
  overflow-x: auto;
}
.setup .warn {
  margin-top: 18px;
  padding: 12px 14px;
  border-left: 4px solid #f59e0b;
  border-radius: 0 10px 10px 0;
  background: rgba(245, 158, 11, .12);
  color: #fcd34d;
}
