:root {
  --bg-color: #fff8ec;
  --text-main: #333;
  --text-sub: #666;
  --card-bg: #ffffff;
}

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

body {
  font-family: "Mali", "Noto Sans Thai", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-shrink: 0;
}

h1 {
  font-size: 24px;
  font-weight: 600;
}

/* Grid for Home and Category Explore */
.grid-container {
  display: grid;
  gap: 20px;
  flex: 1;
  align-content: start;
}

#home-categories {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.explore-grid {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  height: 100%;
}

@media (max-aspect-ratio: 1/1) {
  .explore-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
  }
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: 28px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: transform 0.2s ease;
  min-height: 150px;
  border: 4px solid transparent;
}

.card:active {
  transform: scale(0.95);
}

.card img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  margin-bottom: 10px;
}

.card .title-th {
  font-size: 24px;
  font-weight: 600;
}

.card .title-en {
  font-size: 16px;
  color: var(--text-sub);
}

.fallback-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
  font-weight: bold;
  margin-bottom: 10px;
}

/* Buttons */
button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
}

#settings-btn {
  font-size: 32px;
  padding: 10px;
  min-width: 64px;
  min-height: 64px;
}

.nav-btn {
  font-size: 40px;
  width: 64px;
  height: 64px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-switch {
  display: flex;
  background: white;
  border-radius: 30px;
  padding: 5px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.mode-btn {
  padding: 10px 20px;
  font-size: 20px;
  border-radius: 25px;
  color: var(--text-sub);
}

.mode-btn.active {
  background: #ffe082;
  color: #333;
  font-weight: bold;
}

.action-btn {
  background: #4caf50;
  color: white;
  font-size: 24px;
  padding: 15px 30px;
  border-radius: 30px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  min-height: 64px;
}

/* Modals */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 248, 236, 0.95);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal.active {
  display: flex;
}

#close-modal-btn {
  position: absolute;
  top: 20px;
  left: 20px;
}

.modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  justify-content: center;
}

.expanded-card {
  background: white;
  border-radius: 40px;
  padding: 40px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
  max-width: 90%;
  max-height: 70%;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.expanded-card.bounce {
  animation: bounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.expanded-card img {
  width: 250px;
  height: 250px;
  object-fit: contain;
  margin-bottom: 20px;
}

.expanded-card .fallback-circle {
  width: 250px;
  height: 250px;
  font-size: 48px;
}

.expanded-card h2 {
  font-size: 64px;
  margin-bottom: 10px;
}

.expanded-card h3 {
  font-size: 32px;
  color: var(--text-sub);
}

.jiggle {
  animation: jiggle 0.5s ease-in-out infinite alternate;
}

/* Quiz Mode */
.quiz-controls {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.quiz-container {
  display: flex;
  gap: 30px;
  justify-content: center;
  align-items: center;
  flex: 1;
}

.quiz-card {
  width: 40%;
  max-width: 300px;
  aspect-ratio: 1;
  background: white;
  border-radius: 40px;
  padding: 20px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 8px solid transparent;
}

.quiz-card img {
  width: 80%;
  height: 80%;
  object-fit: contain;
}

.quiz-card .fallback-circle {
  width: 80%;
  height: 80%;
  font-size: 40px;
}

.glow {
  box-shadow: 0 0 30px #ffd54f;
  border-color: #ffd54f;
}

.shake {
  animation: shake 0.4s ease-in-out;
}

/* End Screen */
.end-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
}

.end-stars {
  font-size: 64px;
  margin-bottom: 20px;
}

.end-content h2 {
  font-size: 40px;
  color: #ff9800;
}

.end-content p {
  font-size: 24px;
  margin-bottom: 30px;
}

.recent-container {
  display: flex;
  gap: 15px;
  margin-bottom: 40px;
}

.recent-card {
  background: white;
  border-radius: 20px;
  padding: 10px;
  width: 120px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.recent-card img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}

.recent-card .fallback-circle {
  width: 60px;
  height: 60px;
  font-size: 20px;
}

.recent-card span {
  font-size: 16px;
  font-weight: 600;
  margin-top: 5px;
}

/* Hold Button */
.hold-btn {
  position: relative;
  background: #e0e0e0;
  border-radius: 40px;
  padding: 20px 40px;
  overflow: hidden;
  color: var(--text-sub);
  font-size: 18px;
}

.progress-ring {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: #4caf50;
  opacity: 0.3;
  transition: width 0.1s linear;
}

.btn-text {
  position: relative;
  z-index: 1;
}

/* Settings */
.settings-content {
  background: white;
  padding: 40px;
  border-radius: 30px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.settings-content h2 {
  margin-bottom: 20px;
  font-size: 32px;
}

.settings-group {
  margin-bottom: 20px;
}

.settings-group label {
  font-size: 20px;
  display: block;
  margin-bottom: 10px;
}

.time-options {
  display: flex;
  gap: 10px;
}

.time-btn {
  flex: 1;
  padding: 15px;
  font-size: 20px;
  border-radius: 15px;
  background: #f5f5f5;
}

.time-btn.active {
  background: #2196f3;
  color: white;
}

.print-link {
  display: block;
  text-align: center;
  background: #9c27b0;
  color: white;
  padding: 15px;
  border-radius: 15px;
  text-decoration: none;
  font-size: 20px;
}

.advice {
  background: #fff8e1;
  padding: 15px;
  border-radius: 15px;
  margin-bottom: 20px;
  font-size: 16px;
  line-height: 1.5;
}

/* Effects */
#effects-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

.particle {
  position: absolute;
  font-size: 40px;
  animation: floatUp 1.5s ease-out forwards;
}

/* Animations */
@keyframes bounce {
  0% {
    transform: scale(0.5);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes jiggle {
  from {
    transform: rotate(-3deg);
  }
  to {
    transform: rotate(3deg);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-10px) rotate(-5deg);
  }
  75% {
    transform: translateX(10px) rotate(5deg);
  }
}

@keyframes floatUp {
  0% {
    transform: translateY(0) scale(0.5);
    opacity: 1;
  }
  100% {
    transform: translateY(-100px) scale(1.5);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
  .card:active {
    transform: none;
  }
  .expanded-card {
    transition: none;
  }
  .expanded-card.bounce {
    animation: none;
    transform: scale(1);
  }
  .jiggle {
    animation: none;
  }
  .shake {
    animation: none;
  }
  .particle {
    animation-duration: 0s;
    opacity: 0;
  }
}

/* ===== Claude pass · ขยายรูปให้เต็มการ์ด (เด็กต้องเห็นรูปก่อนตัวหนังสือ) ===== */
img {
  mix-blend-mode: multiply;
} /* กลืนพื้นขาวของภาพเข้ากับการ์ด ไม่เห็นกรอบเทา */

.screen {
  padding: 16px 20px;
}
.view.active {
  min-height: 0;
}

#home-categories {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: stretch;
  gap: 20px;
  min-height: 0;
}
#home-categories .card {
  flex: 0 0 calc((100% - 40px) / 3);
  height: calc((100% - 20px) / 2);
}
.card {
  min-height: 0;
  overflow: hidden;
}
.card img {
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  margin-bottom: 6px;
}
.card .title-th {
  font-size: clamp(22px, 3.2vw, 34px);
  line-height: 1.3;
}
.card .title-en {
  font-size: clamp(14px, 1.8vw, 20px);
}
.explore-grid {
  min-height: 0;
  grid-auto-rows: 1fr;
}

.quiz-card {
  width: 42%;
  max-width: 400px;
}
.quiz-card img {
  width: 90%;
  height: 90%;
}
.expanded-card img {
  width: min(300px, 40vh);
  height: min(300px, 40vh);
}
.recent-card {
  width: 140px;
}
.recent-card img {
  width: 96px;
  height: 96px;
}

@media (max-aspect-ratio: 1/1) {
  #home-categories .card {
    flex-basis: calc((100% - 20px) / 2);
    height: calc((100% - 40px) / 3);
  }
  .quiz-container {
    flex-direction: column;
  }
  .quiz-card {
    width: 70%;
    max-width: 340px;
  }
}

/* ===== ซับ + ปุ่มเลื่อนภาพ ===== */
#caption {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 900px);
  padding: 12px 28px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  font-size: clamp(22px, 3.2vw, 34px);
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: #3a3a3a;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  z-index: 150;
}
#caption.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#card-modal {
  touch-action: none;
} /* ให้ปัดซ้ายขวาได้ ไม่โดนเบราว์เซอร์แย่ง */
#close-modal-btn {
  width: 80px;
  height: 80px;
  font-size: 44px;
  z-index: 2;
}
.modal-content {
  padding-bottom: 90px;
} /* เว้นที่ให้ซับ */
.side-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  font-size: 40px;
  color: #ff9800;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.side-btn.prev {
  left: 24px;
}
.side-btn.next {
  right: 24px;
}
.side-btn:active,
#hunt-btn:active {
  transform: translateY(-50%) scale(0.92);
}
#hunt-btn:active {
  transform: scale(0.94);
}
#hunt-btn.speaking {
  animation: pulse 0.9s ease-in-out infinite alternate;
}
@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.06);
  }
}

@media (max-aspect-ratio: 1/1) {
  .side-btn {
    top: auto;
    bottom: 110px;
    transform: none;
    width: 80px;
    height: 80px;
  }
  .side-btn:active {
    transform: scale(0.92);
  }
}
@media (prefers-reduced-motion: reduce) {
  #hunt-btn.speaking {
    animation: none;
  }
  #caption {
    transition: none;
  }
}
/* fix: fixed+left:50% ทำให้กล่องกว้างได้แค่ครึ่งจอ → ตัดบรรทัดเร็ว */
#caption {
  width: max-content;
}
#quiz-view,
#explore-view {
  padding-bottom: 84px;
} /* เว้นที่ให้ซับ ไม่ทับการ์ด */
.expanded-card {
  max-height: none;
  padding: 28px 40px;
}
.expanded-card img {
  width: min(300px, 34vh);
  height: min(300px, 34vh);
  margin-bottom: 8px;
}
.expanded-card h2 {
  font-size: clamp(44px, 7vh, 64px);
  margin-bottom: 0;
  line-height: 1.3;
}
.expanded-card h3 {
  font-size: clamp(22px, 3.6vh, 32px);
}

/* Level Badges */
.card-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  background: white;
  border-radius: 20px;
  padding: 4px 8px;
  font-size: 14px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  z-index: 2;
  border: 2px solid #eee;
}
.level-badge {
  background: #fff;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 20px;
  font-weight: 600;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
  border: 3px solid #eee;
  color: #333;
}

/* Home Card layout changes */
#home-categories .card {
  position: relative;
  overflow: visible;
}

/* Sticker Dots in Home Card */
.sticker-dots {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  justify-content: center;
  width: 100%;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e0e0e0;
}
.dot.active {
  background: var(--cat-color);
}

/* Header actions */
.header-actions {
  display: flex;
  gap: 10px;
}
#sticker-btn {
  font-size: 32px;
  padding: 10px;
  min-width: 64px;
  min-height: 64px;
}

/* Quiz Header & Progress */
.quiz-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.progress-dots {
  display: flex;
  gap: 8px;
}
.quiz-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e0e0e0;
}
.quiz-dot.active {
  background: var(--cat-color);
}
.quiz-dot.current {
  animation: pulse-dot 1s infinite alternate;
  background: var(--cat-color);
  opacity: 0.5;
}
@keyframes pulse-dot {
  from {
    transform: scale(1);
    opacity: 0.5;
  }
  to {
    transform: scale(1.3);
    opacity: 1;
  }
}

/* Level Up Overlay */
.levelup-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: white;
  padding: 40px;
  border-radius: 40px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
  text-align: center;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#levelup-badge {
  margin-bottom: 20px;
}
@keyframes popIn {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.sticker-circle {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: white;
  border: 8px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}
.sticker-circle img {
  width: 100px;
  height: 100px;
  object-fit: contain;
}
.next-cat-btn {
  margin-top: 20px;
  font-size: 28px;
  padding: 20px 40px;
  border-radius: 40px;
  background: #2196f3;
  animation: pulse 1s infinite alternate;
}

/* Sticker Book */
.sticker-book {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}
.sticker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  padding: 10px 20px;
  border-radius: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}
.sticker-cat-name {
  width: 100px;
  font-size: 18px;
  font-weight: bold;
  color: var(--text-sub);
}
.sticker-slots {
  display: flex;
  gap: 15px;
  flex: 1;
  justify-content: space-around;
}
.sticker-slot {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 4px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
  transition: transform 0.2s ease;
}
.sticker-slot.unlocked {
  border-color: var(--cat-color);
  background: white;
  cursor: pointer;
}
.sticker-slot.unlocked:active {
  transform: scale(0.9);
}
.sticker-slot img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}
.sticker-slot.locked img {
  filter: brightness(0) opacity(0.12);
}

.reset-btn {
  background: #ff5252;
  color: white;
  width: 100%;
  margin-top: 10px;
}
.reset-btn .progress-ring {
  background: #b71c1c;
}

.quiz-card.wrong {
  opacity: 0.35;
  pointer-events: none;
}

/* =====================================================================
   RESPONSIVE LAYER (Claude) · ทุกขนาดอิงจอจริง (vmin/dvh/container)
   เป้า: iPad แนวนอน/ตั้ง, iPad Pro, มือถือแนวตั้ง/นอน, มือถือเล็ก · ไม่ล้น ไม่ต้องเลื่อน
   ===================================================================== */
:root {
  --gap: clamp(8px, 2vmin, 22px);
  --tap: clamp(48px, 8.5vmin, 80px);
  --btn-font: clamp(15px, 2.7vmin, 26px);
  --cap-space: clamp(50px, 9vmin, 88px);
}
html,
body {
  height: 100%;
}
body {
  height: 100vh;
  height: 100dvh;
}
.screen {
  padding: max(10px, 1.8vmin) max(12px, 2.4vmin);
  padding-bottom: calc(max(10px, 1.8vmin) + env(safe-area-inset-bottom));
}
header {
  margin-bottom: var(--gap);
  gap: var(--gap);
}
h1 {
  font-size: clamp(18px, 3.4vmin, 32px);
}
.nav-btn,
#settings-btn,
#sticker-btn {
  width: var(--tap);
  height: var(--tap);
  min-width: 0;
  min-height: 0;
  padding: 0;
  font-size: calc(var(--tap) * 0.52);
}
.header-actions {
  gap: var(--gap);
}
.mode-btn {
  font-size: var(--btn-font);
  padding: 1vmin 2.2vmin;
}
.action-btn {
  font-size: var(--btn-font);
  padding: 1vmin 3.2vmin;
  min-height: clamp(44px, 7.5vmin, 66px);
  border-radius: 999px;
}

/* ---------- การ์ด (หน้าแรก + แตะดู) ---------- */
#home-categories,
.explore-grid {
  display: grid !important;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  gap: var(--gap);
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  align-content: stretch;
}
#explore-view.active {
  padding-bottom: var(--cap-space);
  min-height: 0;
}
@media (orientation: portrait) {
  #home-categories,
  .explore-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
  }
}
#home-categories .card,
.explore-grid .card {
  flex: none;
  height: auto;
  min-height: 0;
  padding: clamp(6px, 1.4vmin, 16px);
  border-radius: clamp(16px, 3vmin, 30px);
  border-width: clamp(3px, 0.5vmin, 5px);
}
.card img {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  height: auto;
  margin-bottom: 0.6vmin;
}
.card .title-th {
  font-size: clamp(15px, 3.1vmin, 32px);
  line-height: 1.25;
  white-space: nowrap;
}
.card .title-en {
  font-size: clamp(11px, 1.8vmin, 19px);
  line-height: 1.2;
}
.card-badge {
  top: -0.8vmin;
  right: -0.8vmin;
  font-size: clamp(11px, 2vmin, 20px);
  padding: 0.3vmin 1vmin;
}
.sticker-dots {
  margin-top: 0.6vmin;
  gap: 0.6vmin;
}
.dot {
  width: clamp(6px, 1.3vmin, 13px);
  height: clamp(6px, 1.3vmin, 13px);
}
@media (max-height: 520px) {
  .card .title-en {
    display: none;
  }
}

/* ---------- โหมดไหนนะ? ---------- */
#quiz-view.active {
  min-height: 0;
  padding-bottom: var(--cap-space);
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 1.2vmin;
}
.quiz-header {
  margin: 0;
  gap: 0.8vmin;
}
.quiz-controls {
  margin: 0;
}
.level-badge {
  font-size: clamp(14px, 2.5vmin, 24px);
  padding: 0.6vmin 2vmin;
  border-width: 2px;
}
.progress-dots {
  gap: clamp(5px, 1vmin, 10px);
}
.quiz-dot {
  width: clamp(8px, 1.6vmin, 16px);
  height: clamp(8px, 1.6vmin, 16px);
}
@media (orientation: landscape) {
  /* แนวนอน: ป้ายเลเวล+จุด กับปุ่มฟังอีกครั้ง อยู่แถวเดียวกัน การ์ดได้ความสูงเพิ่ม */
  #quiz-view.active {
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .quiz-header {
    grid-column: 2;
    grid-row: 1;
    flex-direction: row;
  }
  .quiz-controls {
    grid-column: 3;
    grid-row: 1;
    justify-content: flex-end;
  }
  .quiz-container {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}
.quiz-container {
  --n: 2;
  container-type: size;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 4vmin;
}
.quiz-container[data-n="3"] {
  --n: 3;
}
.quiz-container .quiz-card {
  flex: none;
  max-width: none;
  padding: 2.5vmin;
  aspect-ratio: 1;
  height: auto;
  width: 38vmin;
  width: min(94cqh, calc((100cqw - (var(--n) - 1) * 4vmin) / var(--n)));
  border-radius: clamp(18px, 4vmin, 40px);
  border-width: clamp(4px, 0.8vmin, 8px);
}
.quiz-container .quiz-card img {
  width: 92%;
  height: 92%;
}
@media (orientation: portrait) {
  .quiz-container {
    flex-direction: column;
  }
  .quiz-container .quiz-card {
    width: min(88cqw, calc((100cqh - (var(--n) - 1) * 4vmin) / var(--n)));
  }
}

/* ---------- การ์ดขยาย ---------- */
.modal-content {
  box-sizing: border-box;
  padding: 2vmin calc(var(--tap) * 1.4) var(--cap-space);
  gap: 1.6vmin;
}
.expanded-card {
  padding: 2.2vmin 4vmin;
  margin-bottom: 0;
  border-radius: 4vmin;
  max-width: 100%;
}
.expanded-card img,
.expanded-card .fallback-circle {
  width: min(40dvh, 58vw, 340px);
  height: min(40dvh, 58vw, 340px);
  margin-bottom: 0.5vmin;
}
.expanded-card h2 {
  font-size: clamp(26px, 7vmin, 66px);
}
.expanded-card h3 {
  font-size: clamp(15px, 3.3vmin, 32px);
}
#close-modal-btn {
  width: var(--tap);
  height: var(--tap);
  font-size: calc(var(--tap) * 0.5);
  top: 2vmin;
  left: 2vmin;
}
.side-btn {
  width: calc(var(--tap) * 1.15);
  height: calc(var(--tap) * 1.15);
  font-size: calc(var(--tap) * 0.5);
}
.side-btn.prev {
  left: 2vmin;
}
.side-btn.next {
  right: 2vmin;
}
@media (orientation: portrait) {
  .modal-content {
    padding-left: 4vw;
    padding-right: 4vw;
    padding-bottom: calc(var(--cap-space) + var(--tap) * 1.3);
  }
  .side-btn {
    top: auto;
    bottom: calc(var(--cap-space) + 1vmin);
    transform: none;
  }
}

/* ---------- ฉลองสติกเกอร์ ---------- */
.levelup-content {
  padding: 3vmin 5vmin;
  border-radius: 5vmin;
  max-width: 92vw;
  max-height: 94dvh;
  gap: 1.2vmin;
}
.sticker-circle {
  width: clamp(110px, 36vmin, 330px);
  height: clamp(110px, 36vmin, 330px);
  border-width: clamp(5px, 1vmin, 10px);
  margin-bottom: 1vmin;
}
.sticker-circle img {
  width: 84%;
  height: 84%;
}
#levelup-badge {
  margin-bottom: 0.5vmin;
}
#levelup-title {
  font-size: clamp(18px, 4.2vmin, 38px);
}
.next-cat-btn {
  margin-top: 1vmin;
  font-size: clamp(18px, 3.4vmin, 30px);
  padding: 1.4vmin 4vmin;
}

/* ---------- สมุดสติกเกอร์ (เลื่อนแนวตั้งได้ ห้ามล้นข้าง) ---------- */
#sticker-screen header h1 {
  flex: 1;
  text-align: center;
}
#sticker-screen header > div:last-child {
  width: var(--tap) !important;
}
.sticker-book {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  max-width: 900px;
  width: 100%;
  padding-bottom: var(--cap-space);
  align-content: start;
}
@media (orientation: landscape) {
  .sticker-book {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: none;
  }
}
.sticker-row {
  gap: 1.5vmin;
  padding: 1vmin 2vmin;
  border-radius: 2.5vmin;
  min-width: 0;
}
.sticker-cat-name {
  flex: 0 0 auto;
  width: clamp(62px, 13vmin, 130px);
  font-size: clamp(13px, 2.3vmin, 22px);
}
.sticker-slots {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.2vmin;
}
.sticker-slot {
  width: 100%;
  max-width: clamp(56px, 14vmin, 120px);
  height: auto;
  aspect-ratio: 1;
  justify-self: center;
  border-width: clamp(2px, 0.5vmin, 4px);
}
.sticker-slot img {
  width: 86%;
  height: 86%;
}
/* เงาจางของรูปจริง · brightness(0) เดิมทำพื้นขาวของรูปกลายเป็นกล่องทึบ */
.sticker-slot.locked img {
  filter: grayscale(1) opacity(0.18);
}

/* ---------- หน้าจบ + ตั้งค่า ---------- */
.end-content {
  gap: 1.6vmin;
}
.end-stars {
  font-size: clamp(30px, 8vmin, 64px);
  margin: 0;
}
.end-content h2 {
  font-size: clamp(24px, 5.5vmin, 44px);
}
.end-content p {
  font-size: clamp(15px, 3vmin, 24px);
  margin: 0;
}
.recent-container {
  margin: 0;
  gap: 1.6vmin;
}
.recent-card {
  width: clamp(84px, 17vmin, 150px);
}
.recent-card img {
  width: clamp(52px, 12vmin, 104px);
  height: clamp(52px, 12vmin, 104px);
}
.hold-btn {
  font-size: clamp(13px, 2.2vmin, 18px);
  padding: 1.4vmin 4vmin;
}
.settings-content {
  max-height: 92dvh;
  overflow-y: auto;
  padding: 3vmin 4vmin;
}

/* ---------- ซับ ---------- */
#caption {
  font-size: clamp(16px, 3.1vmin, 34px);
  padding: 1vmin 3vmin;
}

/* ---------- มุมผู้ปกครอง: บททดสอบรายหมวด ---------- */
.settings-content {
  max-width: min(620px, 94vw);
}
.settings-hint {
  font-size: clamp(12px, 1.9vmin, 15px);
  color: var(--text-sub);
  margin: -4px 0 8px;
}
.cat-reset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cat-reset-row {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  border-radius: 14px;
  background: #fafafa;
  border-left: 6px solid var(--cat-color);
  transition: background 0.3s;
}
.cat-reset-row.flash {
  background: #e8f5e9;
}
.cat-reset-name {
  font-size: clamp(14px, 2.2vmin, 18px);
  font-weight: 600;
  line-height: 1.2;
}
.cat-reset-name small {
  display: block;
  font-size: 0.72em;
  font-weight: 400;
  color: var(--text-sub);
}
.cat-level-pick {
  display: flex;
  gap: 4px;
}
.lv-btn {
  min-width: 44px;
  height: 44px;
  padding: 0 6px;
  border-radius: 12px;
  background: white;
  border: 2px solid #e0e0e0;
  font-size: clamp(12px, 1.8vmin, 15px);
  white-space: nowrap;
}
.lv-btn.active {
  border-color: var(--cat-color);
  background: color-mix(in srgb, var(--cat-color) 22%, white);
}
.cat-reset-btn {
  width: 48px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  font-size: 22px;
  background: #ffebee;
  color: #c62828;
}
.cat-reset-btn .progress-ring {
  background: #ef9a9a;
  opacity: 0.6;
}
@media (max-width: 480px) {
  .cat-reset-row {
    grid-template-columns: 1fr auto;
  }
  .cat-level-pick {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: space-between;
  }
  .cat-level-pick .lv-btn {
    flex: 1;
  }
  .cat-reset-btn {
    grid-column: 2;
    grid-row: 1;
  }
}

/* ---------- English เล่นอิสระ ---------- */
.english-btn {
  height: var(--tap);
  padding: 0 clamp(12px, 2.4vmin, 24px);
  border-radius: 999px;
  background: #e3f2fd;
  color: #1565c0;
  font-weight: 700;
  font-size: var(--btn-font);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
}
.english-btn:active {
  transform: scale(0.95);
}
.header-spacer {
  width: var(--tap);
  flex: none;
}
#english-screen header h1 {
  flex: 1;
  text-align: center;
}
.english-grid {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  gap: var(--gap);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}
.english-grid .card {
  height: auto;
  min-height: 0;
  padding: clamp(6px, 1.4vmin, 16px);
  border-radius: clamp(16px, 3vmin, 30px);
  border-width: clamp(3px, 0.5vmin, 5px);
}
.english-grid .card:first-child {
  background: linear-gradient(135deg, #e3f2fd, #fff8e1);
}
.free-en-title {
  display: none;
  font-size: clamp(16px, 3vmin, 28px);
  font-weight: 700;
  color: #1565c0;
  flex: 1;
  text-align: center;
}
#category-screen.free-en .free-en-title {
  display: block;
}
#category-screen.free-en .mode-switch {
  display: none;
}
#category-screen.free-en header::after {
  content: "";
  width: var(--tap);
  flex: none;
}
@media (max-width: 480px) {
  .english-btn {
    padding: 0 10px;
    font-size: 14px;
  }
  #home-screen h1 {
    font-size: 16px;
  }
}

/* ---------- วิธีเล่น (พ่อแม่) ---------- */
#help-btn {
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  font-size: calc(var(--tap) * 0.5);
  background: none;
  border: none;
}
#help-modal {
  z-index: 120;
  padding: max(10px, 2vmin);
  box-sizing: border-box;
}
.help-content {
  background: white;
  width: min(760px, 100%);
  max-height: 100%;
  border-radius: clamp(18px, 3vmin, 30px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(10px, 2vmin, 18px) clamp(14px, 3vmin, 28px);
  background: #fff3d6;
  flex: none;
}
.help-head h2 {
  font-size: clamp(18px, 3.2vmin, 28px);
  margin: 0;
}
#close-help-btn {
  flex: none;
}
.help-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: clamp(10px, 2vmin, 20px) clamp(14px, 3vmin, 28px)
    clamp(18px, 3vmin, 30px);
  font-size: clamp(14px, 2.1vmin, 18px);
  line-height: 1.6;
  color: #3a3a3a;
}
.help-body section {
  padding: 10px 0;
  border-bottom: 1px dashed #eee;
}
.help-body section:last-child {
  border-bottom: none;
}
.help-body h3 {
  font-size: 1.12em;
  margin: 0 0 4px;
  color: #e65100;
}
.help-body p {
  margin: 4px 0;
}
.help-body ul,
.help-body ol {
  margin: 4px 0;
  padding-left: 1.4em;
}
.help-body li {
  margin: 3px 0;
}
.help-lead p {
  background: #e8f5e9;
  border-radius: 14px;
  padding: 10px 14px;
  margin: 0;
}
.help-tips {
  background: #fff8e1;
  border-radius: 16px;
  padding: 10px 14px !important;
  margin-top: 8px;
}
.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 0.95em;
}
.help-table th,
.help-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
}
.help-table th {
  background: #fafafa;
  font-weight: 600;
}
.help-table td:first-child,
.help-table th:first-child {
  white-space: nowrap;
}
.help-table td:last-child,
.help-table th:last-child {
  text-align: center;
}
.help-link {
  width: 100%;
  padding: 14px;
  border-radius: 15px;
  font-size: 18px;
  background: #fff3d6;
  color: #8d5a00;
  font-weight: 600;
}

/* ===== NEW REWARDS ====== */
.progress-stars-container {
  display: flex;
  gap: 4px;
  align-items: center;
}
.star-slot {
  width: clamp(16px, 3.4vmin, 30px);
  height: clamp(16px, 3.4vmin, 30px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.star-slot svg {
  width: 100%;
  height: 100%;
  fill: transparent;
  stroke: #e3dccb;
  stroke-width: 2;
  stroke-linejoin: round;
  transition: all 0.3s ease;
}
.star-slot.filled svg {
  fill: #f2c94c;
  stroke: #e0a800;
  animation: star-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.star-slot.current svg {
  animation: star-pulse 1.5s infinite alternate;
}
@keyframes star-pop {
  0% {
    transform: scale(0.5);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes star-pulse {
  from {
    stroke: var(--cat-color);
    transform: scale(1);
    opacity: 0.5;
  }
  to {
    stroke: var(--cat-color);
    transform: scale(1.15);
    opacity: 1;
  }
}
.end-sticker-container {
  width: clamp(24px, 5vmin, 40px);
  height: clamp(24px, 5vmin, 40px);
  margin-left: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.end-sticker-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: grayscale(1) opacity(0.35);
  transition:
    opacity 0.3s ease,
    filter 0.3s ease;
}
.end-sticker-container.celebrate img {
  animation: sticker-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  opacity: 1 !important;
  filter: none !important;
}
@keyframes sticker-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.4);
  }
  100% {
    transform: scale(1.2);
  }
}
.quiz-card.correct {
  background-color: #fff6da !important;
  border-color: #f2c94c !important;
  animation: correctPop 0.45s ease-out;
}
@keyframes correctPop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}
.flying-star-wrap {
  position: fixed;
  z-index: 300;
  pointer-events: none;
}
.flying-star {
  width: clamp(28px, 6vmin, 56px);
  height: clamp(28px, 6vmin, 56px);
}
.flying-star svg {
  width: 100%;
  height: 100%;
}
.falling-star {
  position: absolute;
  width: clamp(12px, 3vmin, 24px);
  height: clamp(12px, 3vmin, 24px);
  opacity: 0;
  pointer-events: none;
  animation: fallDown linear forwards;
  z-index: 5;
}
@keyframes fallDown {
  0% {
    transform: translateY(-50px) rotate(0deg);
    opacity: 0;
  }
  20% {
    opacity: 0.7;
  }
  80% {
    opacity: 0.7;
  }
  100% {
    transform: translateY(150px) rotate(180deg);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .star-slot.filled svg,
  .star-slot.current svg,
  .end-sticker-container.celebrate img,
  .quiz-card.correct {
    animation: none;
  }
}

.quiz-card {
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease;
}

/* Claude · ดาวให้ใหญ่พอสำหรับเด็ก 2 ขวบ (เดิม ~16-22px เล็กไป) */
.star-slot {
  width: clamp(20px, 4.6vmin, 42px);
  height: clamp(20px, 4.6vmin, 42px);
}
.end-sticker-container {
  width: clamp(30px, 6.5vmin, 58px);
  height: clamp(30px, 6.5vmin, 58px);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  padding: 3px;
}
.flying-star {
  width: clamp(38px, 8.5vmin, 76px);
  height: clamp(38px, 8.5vmin, 76px);
  pointer-events: none;
}
.flying-star svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 10px rgba(224, 168, 0, 0.35));
}
.progress-dots {
  gap: clamp(4px, 0.9vmin, 10px);
  align-items: center;
}

/* ย้ายจาก inline style (CSP) */
#next-category-btn {
  display: none;
}
.header-spacer {
  width: 64px;
  flex: none;
}
.locked-category { font: inherit; color: inherit; cursor: pointer; }
.locked-category img { filter: grayscale(1); opacity: .45; }
.locked-category .title-th, .locked-category .title-en { opacity: .6; }
#locked-pack-dialog { max-width: min(90vw, 480px); border: 0; border-radius: 24px; padding: 24px; text-align: center; color: #493a30; }
#locked-pack-dialog::backdrop { background: #0008; }
#locked-pack-dialog .hold-btn { width: 100%; margin-block: 20px; }
