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

html, body {
  margin: 0; padding: 0;
  background: #f5f7fa; color: #2d3748;
  font-family: "Prompt", "Sarabun", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  height: 100vh; display: flex; flex-direction: column; align-items: center;
  user-select: none;
  overflow-x: hidden;
}

/* พื้นหลังสดใสไล่สี */
body::before {
  content: "";
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 45%, #a1c4fd 100%);
  background-size: 200% 200%;
  animation: bgMove 10s ease infinite;
  z-index: -1;
}
@keyframes bgMove {
  0% { background-position: 0% 0%; }
  50% { background-position: 100% 100%; }
  100% { background-position: 0% 0%; }
}

.container { width: 100%; max-width: 520px; padding: 12px; display: flex; flex-direction: column; gap: 12px; height: 100%; }

header {
  background: rgba(255,255,255,0.9); color: #2d3748; border-radius: 16px;
  padding: 16px 14px; text-align: center; box-shadow: 0 8px 24px rgba(45,55,72,0.12);
  backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,0.6);
}
.header-wrap { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
header h1 { margin: 0 0 6px; font-size: 24px; font-weight: 900; letter-spacing: 0.4px; color: #2d3748; }
header p { margin: 0; font-size: 13.5px; color: #4a5568; }
.btn-sound {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid #cbd5e0;
  background: #fff; font-size: 20px; cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.btn-sound:active { transform: scale(0.92); }

.card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 18px;
  padding: 20px 16px; box-shadow: 0 10px 25px rgba(45,55,72,0.10); flex: 1;
  display: flex; flex-direction: column; gap: 12px; position: relative; overflow: hidden;
}
.card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 15px; color: #4a5568; font-weight: 800; }
.form-group input, .form-group select {
  font-size: 16px; padding: 10px 12px; border: 1px solid #cbd5e0; border-radius: 12px;
  background: #fff; color: #2d3748;
}
.form-group input:focus, .form-group select:focus { outline: 2px solid #48dbfb; border-color: transparent; }

.btn {
  width: 100%; background: linear-gradient(135deg, #48dbfb 0%, #09f7d0 100%);
  color: #fff; border: 0; border-radius: 14px; padding: 14px 0; font-size: 18px; font-weight: 900;
  cursor: pointer; box-shadow: 0 4px 0 #06b6d4;
}
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn-ghost { background: #fff; color: #2d3748; border: 1px solid #e2e8f0; box-shadow: none; }
.btn-ghost:active { background: #f1f5f9; }
.btn-start { font-size: 21px; padding: 18px 0; background: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%); box-shadow: 0 4px 0 #e0564d; }
.btn-small { width: auto; padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }

/* ---------- เกม ---------- */
.game { gap: 10px; }
.top-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 900; color: #2d3748;
}
#timer { font-size: 28px; color: #09f7d0; margin-left: 6px; }

.progress-wrap { margin: 4px 0 2px; }
.progress-bar {
  height: 10px; background: #e2e8f0; border-radius: 6px; overflow: hidden;
  border: 1px solid #cbd5e0;
}
.progress-fill {
  height: 100%; width: 0%; background: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb);
  border-radius: 6px; transition: width 0.35s ease;
}

.q-card {
  background: #fff; border: 2px solid #e2e8f0; border-radius: 18px;
  padding: 22px 14px; text-align: center; flex: 1;
  display: flex; flex-direction: column; gap: 10px; position: relative;
}
.question { font-size: 64px; font-weight: 900; color: #2d3748; margin: 0; line-height: 1; }
.typed {
  font-size: 36px; letter-spacing: 14px; color: #09f7d0; min-height: 46px;
  background: #f0fff4; border: 2px dashed #48dbfb; border-radius: 12px;
  padding: 8px 0;
}
#feedback { font-size: 17px; font-weight: 900; min-height: 24px; text-align: center; height: 24px; }
#feedback.ok { color: #2ecc71; }
#feedback.no { color: #e74c3c; }


.keypad {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: auto;
}
.key {
  border: 1px solid #cbd5e0; background: #fff; border-radius: 14px;
  font-size: 26px; font-weight: 900; padding: 20px 4; color: #2d3748;
  cursor: pointer; touch-action: manipulation; box-shadow: 0 3px 0 #a0aec0;
}
.key:active { transform: translateY(2px); box-shadow: none; background: #edf2f7; }
.key-del { background: #fff5f5; border-color: #fc8181; color: #e53e3e; }
.key-clr { background: #fffaf0; border-color: #f6e05e; color: #d69e2e; }
.key-enter {
  grid-column: span 2; background: linear-gradient(135deg, #48dbfb 0%, #09f7d0 100%);
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 0 #06b6d4;
}
.key-enter:active { transform: translateY(3px); box-shadow: none; }

/* ---------- ผลลัพธ์ ---------- */
.result { gap: 14px; text-align: center; }
.result h2 { margin: 0; font-size: 26px; color: #2d3748; }
.big-score { font-size: 56px; font-weight: 900; color: #09f7d0; margin: 4px 0 2px; text-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.sum-row { display: flex; justify-content: center; gap: 16px; font-size: 16px; color: #4a5568; margin: 4px 0 14px; flex-wrap: wrap; }
.sum-row b { color: #2d3748; }

.review-wrap { width: 100%; display: flex; justify-content: center; gap: 8px; margin-top: 2px; }
.review-list {
  max-height: 220px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 8px; background: #fff; margin-top: 8px;
}
.review-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 6px; border-bottom: 1px solid #f1f5f9; border-radius: 8px; margin: 2px 0;
  font-size: 15px; font-weight: 700; color: #2d3748;
}
.review-item:last-child { border-bottom: none; }
.review-item .wrong { color: #e53e3e; }
.review-item .right { color: #2ecc71; }

/* ---------- ตารางคะแนน ---------- */
/* ---------- TOP 10 กระดานคะแนน ---------- */
.lb-board { display: flex; flex-direction: column; gap: 6px; }
.lb-entry {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 10px 12px; border-radius: 12px;
  background: #f7fafc; border: 1px solid #e2e8f0;
  font-size: 15px; font-weight: 800; color: #2d3748;
  animation: lbPop 0.4s cubic-bezier(.175,.885,.32,1.275) both;
}
.lb-entry:nth-child(1) { animation-delay: 0.05s; }
.lb-entry:nth-child(2) { animation-delay: 0.1s; }
.lb-entry:nth-child(3) { animation-delay: 0.15s; }
.lb-entry:nth-child(4) { animation-delay: 0.2s; }
.lb-entry:nth-child(5) { animation-delay: 0.25s; }
.lb-top { background: linear-gradient(135deg, #fff7e6, #ffeaa7); border-color: #f6e05e; }
.lb-badge { font-size: 20px; min-width: 32px; text-align: center; }
.lb-rank {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: #cbd5e0; color: #fff; font-size: 13px;
}
.lb-name { flex: 1; text-align: left; color: #1a202c; }
.lb-score { color: #09f7d0; min-width: 55px; text-align: right; }
.lb-time { color: #718096; font-size: 13px; font-weight: 600; min-width: 55px; text-align: right; }

/* ---------- TOP 10 บนหน้าแรก (กระชับ) ---------- */
.home-lb-wrap { margin-top: 12px; padding-top: 10px; border-top: 1px solid #f1f5f9; }
.home-lb-title { font-size: 16px; font-weight: 900; color: #4a5568; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
#homeLbList { display: flex; flex-direction: column; gap: 4px; }
.home-lb-entry {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 6px 10px; border-radius: 10px;
  background: #f7fafc; border: 1px solid #e2e8f0;
  font-size: 13px; font-weight: 800; color: #2d3748;
}
.home-lb-entry:nth-child(-n+3) { background: linear-gradient(135deg, #fff7e6, #ffeaa7); border-color: #f6e05e; }
.home-lb-badge { font-size: 16px; min-width: 24px; text-align: center; }
.home-lb-rank { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: #cbd5e0; color: #fff; font-size: 11px; }
.home-lb-name { flex: 1; color: #1a202c; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-lb-score { color: #09f7d0; min-width: 45px; text-align: right; }
.home-lb-time { color: #718096; font-size: 11px; font-weight: 600; min-width: 40px; text-align: right; }

@keyframes lbPop {
  0% { transform: translateY(12px) scale(0.92); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}


/* ---------- แอนิเมชัน ---------- */
@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  80% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1;
}
.result.pop-in { animation: popIn 0.45s cubic-bezier(.175,.885,.32,1.275) both; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-6px); }
  40%,80% { transform: translateX(6px); }
}
.wrong-shake { animation: shake 0.5s ease both; }

@keyframes bounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.feedback-bounce { animation: bounce 0.45s ease both; }

/* ---------- Confetti canvas ---------- */
.confetti {
  position: fixed; inset: 0; width: 100vw; height: 100vh;
  pointer-events: none; z-index: 9999; display: block;
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .question { font-size: 48px; }
  .key { padding: 16px 4; font-size: 22px; }
  .big-score { font-size: 44px; }
  .container { padding: 8px; }
}
