:root {
  --matcha: #5F913A;
  --matcha-dark: #3F6B2A;
  --matcha-soft: #E3EFD3;
  --hojicha: #8F5E38;
  --hojicha-soft: #EEDCC6;
  --cream: #F6EEDC;
  --cream-light: #FBF6EC;
  --ink: #3B2A1E;
  --ink-soft: rgba(59, 42, 30, 0.62);
  --danger: #D9534F;
  --radius: 18px;
  --font-en: 'Fredoka', 'Prompt', system-ui, sans-serif;
  --font-th: 'Prompt', 'Fredoka', system-ui, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ผนังห้องแล็บ: ตารางกระเบื้องจางๆ (ถ้ากราฟิกส่ง bg-game.png มา ภาพนั้นจะทับบน body แทน) */
html {
  background-color: var(--cream);
  background-image: linear-gradient(rgba(143, 94, 56, 0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(143, 94, 56, 0.07) 1px, transparent 1px);
  background-size: 26px 26px;
}

body {
  background: transparent center / cover no-repeat;
  color: var(--ink);
  font-family: var(--font-th);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: relative;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
}

button { font: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.screen.is-active { display: flex; }

.btn {
  display: block;
  width: 100%;
  border: 2px solid var(--hojicha);
  background: #fff;
  color: var(--hojicha);
  font-family: var(--font-en);
  font-weight: 600;
  font-size: 18px;
  padding: 13px 18px;
  border-radius: 999px;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--matcha); border-color: var(--matcha); color: #fff; box-shadow: 0 4px 0 var(--matcha-dark); }
.btn-ghost { background: transparent; }
.btn-text { border: none; background: none; font-size: 15px; padding: 8px; color: var(--ink-soft); }

.stack { display: grid; gap: 12px; width: 100%; }
.note { font-size: 12.5px; line-height: 1.6; color: var(--ink-soft); text-align: center; margin: 12px 0; }

/* ---------- Start ---------- */
.start-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  text-align: center;
  overflow-y: auto; /* จอเตี้ยหรือมีปุ่มรางวัลเพิ่ม: เลื่อนลงได้ */
  -webkit-overflow-scrolling: touch;
}
/* จัดกลางเมื่อพอดีจอ แต่ถ้ายาวเกินให้เริ่มจากบนสุด (justify-content: center จะตัดส่วนบนทิ้ง) */
.start-inner > :first-child { margin-top: auto; }
.start-inner > :last-child { margin-bottom: auto; }
.brand { font-family: var(--font-en); font-weight: 600; letter-spacing: 0.3em; font-size: 14px; color: var(--hojicha); }
.brand img { max-height: 44px; max-width: 200px; }
.title-wrap img { max-width: 100%; max-height: 140px; }
#title-text {
  margin: 0;
  font-family: var(--font-en);
  font-weight: 700;
  font-size: clamp(40px, 13vw, 56px);
  line-height: 0.95;
  color: var(--matcha);
}
#title-text span { display: block; font-size: 0.56em; color: var(--hojicha); letter-spacing: 0.04em; margin-top: 6px; }
.hero { position: relative; width: min(64vw, 240px); aspect-ratio: 1; }
.hero img { position: absolute; max-width: none; }
.hero img.full { inset: 0; width: 100%; height: 100%; object-fit: contain; }
.start-best { margin: 0; font-family: var(--font-en); font-weight: 600; color: var(--hojicha); }

/* ---------- Pages ---------- */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.page-title { font-family: var(--font-en); font-weight: 700; color: var(--matcha); font-size: 28px; margin: 4px 0; text-align: center; }

.howto { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.howto li {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--cream-light);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.howto .pic { flex: 0 0 64px; height: 64px; display: flex; align-items: center; justify-content: center; gap: 2px; }
.howto .pic img { width: 34px; height: 34px; }
.howto .pic .big { width: 52px; height: 52px; }
.howto .pic .arrow { font-family: var(--font-en); font-weight: 700; color: var(--hojicha); font-size: 16px; }
.howto h3 { margin: 0 0 2px; font-family: var(--font-en); font-size: 17px; color: var(--hojicha); }
.howto p { margin: 0; font-size: 14px; line-height: 1.5; }

.points-title { margin: 6px 0 0; font-family: var(--font-en); font-size: 20px; color: var(--matcha); text-align: center; }
.points-note { margin: 0; font-size: 13px; color: var(--ink-soft); text-align: center; }
.points { display: grid; gap: 4px; background: var(--cream-light); border-radius: var(--radius); padding: 8px 12px; }
.points-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.points-row + .points-row { border-top: 1px dashed rgba(143, 94, 56, 0.2); }
.points-row img { width: 34px; height: 34px; flex: none; }
.points-name { flex: 1; font-family: var(--font-en); font-weight: 600; font-size: 14px; line-height: 1.2; }
.points-name small { display: block; font-family: var(--font-th); font-weight: 400; font-size: 12px; color: var(--ink-soft); }
.points-row b { font-family: var(--font-en); font-size: 16px; color: var(--hojicha); }

/* ---------- Game ---------- */
#screen-game { padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom)); gap: 4px; } /* ขอบบางกว่าหน้าอื่น ให้ถาดได้พื้นที่มากที่สุด */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 50px;
}
.hud-left { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: none;
  background: var(--hojicha);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 20px; height: 20px; fill: #fff; }
.hud-best { display: flex; align-items: center; gap: 4px; font-family: var(--font-en); font-weight: 600; color: var(--hojicha); font-size: 16px; }
.hud-best svg { width: 18px; height: 18px; fill: #C9A14A; }
.hud-score {
  min-width: 112px;
  text-align: center;
  background: var(--hojicha);
  color: #fff;
  border-radius: 14px;
  padding: 3px 16px;
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 25px;
}
.hud-score.bump { animation: bump 0.25s ease; }
@keyframes bump { 50% { transform: scale(1.12); } }
.hud-next { justify-self: end; display: flex; flex-direction: column; align-items: center; font-family: var(--font-en); font-weight: 600; font-size: 12px; color: var(--hojicha); }
.hud-next img { width: 40px; height: 40px; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game-canvas { display: block; touch-action: none; }

.scoop-hint {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: #E8574B;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
}
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.helpers { display: flex; gap: 6px; justify-content: center; }
.helper {
  position: relative;
  display: flex; align-items: center; gap: 3px;
  padding: 2px 9px 2px 6px;
  border-radius: 999px;
  border: 2px solid var(--matcha);
  background: #fff;
  color: var(--matcha-dark);
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.helper svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* ประกายมุมขวาบน บอกว่าเป็นตัวช่วย */
.helper::after {
  content: '';
  position: absolute; top: -6px; right: -5px;
  width: 13px; height: 13px;
  background: #F2C94C;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
.helper:active:not(:disabled) { transform: scale(0.94); }
.helper:disabled { opacity: 0.4; cursor: default; }
.helper.is-on { background: #E8574B; border-color: #E8574B; color: #fff; }
.helper-cost { font-family: var(--font-en); font-weight: 700; font-size: 12px; color: var(--danger); }
.helper.is-on .helper-cost { color: #fff; }
.hud-score.minus { animation: minus 0.5s ease; }
@keyframes minus { 30% { transform: scale(0.9); background: var(--danger); } }

.evo {
  display: grid;
  gap: 4px;
  padding: 4px 10px 3px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  border: 2px solid rgba(143, 94, 56, 0.25);
}
.evo-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 1px; }
.evo-item { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.evo-item img { display: block; width: 100%; aspect-ratio: 1; }
.evo-item span { margin-top: 1px; font-family: var(--font-en); font-weight: 600; font-size: 10px; line-height: 1; color: var(--hojicha); white-space: nowrap; }

/* ---------- Modals ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(59, 42, 30, 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--cream-light);
  border-radius: 26px;
  padding: 22px 18px;
  display: grid;
  gap: 10px;
  text-align: center;
  animation: pop 0.22s ease;
}
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }
.sheet h2 { margin: 0 0 4px; font-family: var(--font-en); font-weight: 700; color: var(--matcha); font-size: 28px; }
.over-label { margin: 0; font-family: var(--font-en); color: var(--ink-soft); }
.over-score { margin: 0; font-family: var(--font-en); font-weight: 700; font-size: 56px; line-height: 1; color: var(--hojicha); }
.over-best { margin: 0 0 6px; font-family: var(--font-en); }
.new-best {
  margin: 0 auto;
  padding: 4px 14px;
  border-radius: 999px;
  background: #C9A14A;
  color: #fff;
  font-family: var(--font-en);
  font-weight: 600;
  animation: bump 0.6s ease 2;
}
.unlocked { background: var(--matcha-soft); border-radius: var(--radius); padding: 10px; }
.unlocked-title { margin: 0 0 8px; font-weight: 600; color: var(--matcha-dark); }
.unlocked-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.unlocked-list button {
  display: flex; flex-direction: column; align-items: center;
  width: 92px; border: none; background: #fff; border-radius: 14px; padding: 6px;
  font-family: var(--font-en); font-weight: 600; font-size: 12px; color: var(--ink);
}
.unlocked-list img { width: 64px; height: 64px; }

.sheet-card { max-width: 400px; padding: 14px; }
#card-img { width: 100%; border-radius: 14px; box-shadow: 0 6px 20px rgba(59, 42, 30, 0.18); -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; }
.hint { margin: 0; font-size: 13px; color: var(--ink-soft); }
.hint.strong { color: var(--matcha-dark); font-weight: 600; font-size: 14px; }
.row { display: flex; gap: 10px; }

/* ---------- Collection ---------- */
.collection-best { margin: 0; text-align: center; font-family: var(--font-en); color: var(--hojicha); }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card-tile {
  border: 2px solid transparent;
  background: var(--cream-light);
  border-radius: var(--radius);
  padding: 10px 8px 12px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.card-tile img { width: 100%; max-width: 120px; aspect-ratio: 1; }
.card-tile.is-locked img { filter: brightness(0) opacity(0.14); }
.card-tile.is-unlocked { border-color: var(--matcha); }
.card-tile .name { font-family: var(--font-en); font-weight: 600; font-size: 15px; }
.card-tile .status { font-size: 12px; color: var(--ink-soft); }
.card-tile.is-unlocked .status { color: var(--matcha-dark); font-weight: 600; }
.card-tile:last-child:nth-child(odd) { grid-column: span 2; }

/* ---------- Rotate ---------- */
#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--cream);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 18px;
  font-weight: 500;
  color: var(--hojicha);
}
/* เฉพาะมือถือ/แท็บเล็ตจอสัมผัส: หน้าต่างคอมที่เตี้ยไม่ต้องบอกให้หมุนจอ */
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  #rotate-overlay { display: flex; }
}

/* ---------- ตัวช่วย: จำนวนครั้งที่เหลือ ---------- */
.helper-left {
  position: absolute; bottom: -6px; right: -6px;
  min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 999px;
  background: var(--hojicha); color: #fff;
  font-family: var(--font-en); font-weight: 700; font-size: 10px; line-height: 16px; text-align: center;
}

/* ---------- รับสิทธิ์ ---------- */
.sheet-reward { text-align: center; gap: 8px; }
.sheet-reward h2 { margin: 0; }
.reward-live { margin: 0; display: inline-flex; align-items: center; gap: 6px; align-self: center; padding: 3px 10px; border-radius: 999px; background: #FDECE8; color: #B8392F; font-family: var(--font-en); font-weight: 700; font-size: 12px; letter-spacing: 1px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #E8574B; animation: live 1s ease-in-out infinite; }
@keyframes live { 50% { opacity: 0.2; transform: scale(0.6); } }
.reward-detail { margin: 0; font-size: 14px; color: var(--ink-soft); }
.reward-ticket {
  --ticket: #5F913A;
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 100%; padding: 16px 12px 14px;
  border: none; border-radius: 18px;
  background: var(--ticket); color: #fff;
  transition: background 0.25s ease;
}
/* แถบแสงวิ่งตลอดเวลา: ภาพแคปจะนิ่ง */
.reward-ticket::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.35) 50%, transparent 65%);
  transform: translateX(-100%);
  animation: shine 2.2s linear infinite;
  pointer-events: none;
}
@keyframes shine { to { transform: translateX(100%); } }
.reward-label { font-family: var(--font-en); font-weight: 600; font-size: 12px; letter-spacing: 2px; opacity: 0.85; }
.reward-clock { font-family: var(--font-en); font-weight: 600; font-size: 18px; font-variant-numeric: tabular-nums; }
.btn[hidden], .reward-buttons[hidden] { display: none; }
.reward-tier { font-size: 30px; font-weight: 600; line-height: 1.2; margin: 2px 0; }
.reward-desc { font-size: 13px; opacity: 0.9; }
.reward-clock-label { margin-top: 10px; font-size: 11px; opacity: 0.8; }
.reward-next { margin: 0; font-size: 14px; font-weight: 500; color: var(--matcha-dark); }
.reward-terms { margin: 0; font-size: 11px; color: var(--ink-soft); }
.reward-customer { margin: 0; font-size: 14px; font-weight: 500; color: var(--ink); }
.reward-buttons { display: grid; gap: 8px; }
.reward-conditions { margin: 0; padding: 10px 12px 10px 28px; text-align: left; font-size: 13px; line-height: 1.5; background: rgba(143, 94, 56, 0.07); border-radius: 12px; }
.reward-label b { font-weight: 700; }

/* ---------- ปุ่มสิทธิ์ (Reward Tile) ---------- */
.reward-tile {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 14px 10px 10px;
  border-radius: 18px; text-align: left;
  font: inherit;
  transition: transform 0.1s ease;
}
.rt-icon { flex: none; width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.rt-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.rt-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.rt-tier { font-family: var(--font-en); font-weight: 600; font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; opacity: 0.75; }
.rt-title { font-family: var(--font-en); font-weight: 700; font-size: 17px; letter-spacing: 0.5px; line-height: 1.15; }
.rt-sub { font-size: 12px; line-height: 1.3; }
.rt-bar { display: block; height: 6px; margin-top: 5px; border-radius: 99px; background: rgba(143, 94, 56, 0.15); overflow: hidden; }
.rt-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--matcha), #A9CF4C); }
.rt-end { flex: none; font-family: var(--font-en); font-weight: 700; font-size: 13px; }

/* ล็อก: การ์ดครีม ขอบประ ไอคอนกุญแจ + แถบความคืบหน้า */
.reward-tile.is-locked { background: #FFFDF7; border: 2px dashed rgba(143, 94, 56, 0.35); color: var(--ink); cursor: default; }
.reward-tile.is-locked .rt-icon { background: rgba(143, 94, 56, 0.1); color: var(--hojicha); }
.reward-tile.is-locked .rt-sub { color: var(--ink-soft); }
.reward-tile.is-locked .rt-end { color: var(--matcha-dark); }

/* ปลดล็อก: แดงไล่สี ขอบทอง แสงวิ่ง ไอคอนของขวัญเด้ง */
.reward-tile.is-open {
  border: 2px solid #F2C94C;
  background: linear-gradient(120deg, #E8574B, #F07A4F);
  color: #fff;
  box-shadow: 0 4px 0 #B8392F, 0 0 0 4px rgba(242, 201, 76, 0.25);
}
.reward-tile.is-open::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.4) 50%, transparent 65%);
  transform: translateX(-100%);
  animation: shine 2.6s ease-in-out infinite;
  pointer-events: none;
}
.reward-tile.is-open .rt-icon { background: #FFF6D6; color: #E8574B; animation: gift-bob 1.4s ease-in-out infinite; }
.reward-tile.is-open .rt-end { padding: 5px 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.22); }
.reward-tile.is-open:active { transform: translateY(2px); box-shadow: 0 2px 0 #B8392F; }
@keyframes gift-bob { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) translateY(-2px); } }

.over-cheer { margin: -2px 0 8px; font-size: 15px; font-weight: 500; line-height: 1.45; color: var(--matcha-dark); text-wrap: balance; }

.nobr { white-space: nowrap; }
.rt-title, .rt-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* ในกล่อง Game Over พื้นที่แคบกว่า: ย่อการ์ดลงนิด */
.sheet .reward-tile { gap: 10px; padding: 8px 10px 8px 8px; }
.sheet .rt-icon { width: 38px; height: 38px; border-radius: 12px; }
.sheet .rt-icon svg { width: 24px; height: 24px; }
.sheet .rt-title { font-size: 15px; }
.sheet .rt-sub { font-size: 11px; }
.sheet .rt-end { font-size: 12px; }

/* สิทธิ์ที่เก็บไว้: รหัสอ้างอิง + นับถอยหลัง */
.reward-claim { display: grid; gap: 2px; }
.reward-countdown { margin: 0; font-family: var(--font-th); font-weight: 600; font-size: 14px; color: #E8574B; }
.reward-countdown.is-expired { color: var(--ink-soft); }
.reward-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reward-dates p { margin: 0; display: grid; gap: 2px; padding: 8px 6px; border-radius: 14px; background: #F7F0E3; }
.reward-dates p:last-child { background: #FDECE8; }
.reward-dates span { font-size: 12px; color: var(--ink-soft); }
.reward-dates b { font-size: 17px; font-weight: 600; color: var(--ink); }
.reward-dates p:last-child b { color: #B8392F; }
.reward-claim { gap: 6px; }
.rt-sub b { font-weight: 600; }
.reward-tile.is-expired { background: #F1ECE2; border: 2px solid rgba(143, 94, 56, 0.2); color: var(--ink-soft); cursor: default; }
.reward-tile.is-expired .rt-icon { background: rgba(143, 94, 56, 0.08); color: rgba(143, 94, 56, 0.5); }

/* รางวัลปริศนา (ยังไม่ผ่านขั้นก่อนหน้า) */
.reward-tile.is-mystery {
  background: repeating-linear-gradient(135deg, #3B2A1E 0 14px, #4A3627 14px 28px);
  border: 2px solid #C9A14A; color: #F6EEDC; cursor: default;
}
.reward-tile.is-mystery .rt-icon { background: rgba(242, 201, 76, 0.18); color: #F2C94C; animation: mystery-wobble 2.4s ease-in-out infinite; }
.reward-tile.is-mystery .rt-title { letter-spacing: 1.5px; color: #F2C94C; }
.reward-tile.is-mystery .rt-sub { opacity: 0.8; }
.reward-tile.is-mystery .rt-end { font-size: 22px; color: #F2C94C; }
@keyframes mystery-wobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-10deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(0); } }

/* เพิ่งเปิดจากปริศนา: พลิกการ์ดเข้ามา + ป้าย NEW */
.reward-tile.is-reveal { animation: reveal-flip 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
@keyframes reveal-flip {
  0% { transform: perspective(600px) rotateX(90deg) scale(0.9); opacity: 0; }
  60% { transform: perspective(600px) rotateX(-12deg) scale(1.03); opacity: 1; }
  100% { transform: none; }
}
.rt-new {
  position: absolute; top: 6px; right: 10px; z-index: 1;
  padding: 2px 8px; border-radius: 99px;
  background: #F2C94C; color: #3B2A1E;
  font-family: var(--font-en); font-weight: 700; font-size: 11px; letter-spacing: 1px;
  animation: new-pulse 1s ease-in-out infinite;
}
@keyframes new-pulse { 50% { transform: scale(1.15); } }

/* =====================================================================
   COOKIE LAB theme (8 พ.ย. 2569) · LAB → OVEN → GIFT ตามบรีฟ Creative Direction
   ===================================================================== */

/* ---------- LAB: หน้าแรก ---------- */
.shelf { position: relative; display: flex; justify-content: center; align-items: flex-end; gap: clamp(14px, 7vw, 30px); width: 100%; padding-bottom: 9px; }
.shelf::after { content: ''; position: absolute; left: 2%; right: 2%; bottom: 0; height: 9px; border-radius: 5px; background: #B48A62; box-shadow: 0 4px 0 rgba(143, 94, 56, 0.25); }
.shelf:empty { display: none; }
.jar { display: flex; flex-direction: column; align-items: center; }
.jar-lid { display: block; width: 46px; height: 10px; border-radius: 4px; background: var(--hojicha); }
.jar-body { position: relative; width: 70px; height: 76px; box-sizing: border-box; border: 2px solid #CDBBA0; border-top: none; border-radius: 8px 8px 18px 18px; background: rgba(255, 255, 255, 0.5); display: flex; align-items: center; justify-content: center; }
.jar:nth-child(2) .jar-body { height: 86px; }
.jar-body img { width: 52px; height: 52px; }
.jar-body span { position: absolute; bottom: 5px; padding: 0 6px; border-radius: 5px; background: #FFFDF7; border: 1px solid #CDBBA0; font-family: var(--font-en); font-weight: 600; font-size: 9px; color: var(--hojicha); }
.tagline { margin: 8px 0 0; font-family: var(--font-en); font-weight: 500; font-size: 15px; color: #6E5440; }
.hero.is-lab { width: min(84vw, 300px); aspect-ratio: 3 / 2; }
.hero.is-lab::after { content: ''; position: absolute; left: -6%; right: -6%; bottom: 0; height: 10px; border-radius: 5px; background: #C9A27A; }
.hero.is-lab .flask { position: absolute; left: 50%; bottom: 8px; width: 34%; height: auto; transform: translateX(-50%); }
.hero.is-lab img { animation: lab-bob 3.2s ease-in-out infinite; }
.hero.is-lab img:nth-child(2) { animation-delay: -0.8s; }
.hero.is-lab img:nth-child(3) { animation-delay: -1.6s; }
.hero.is-lab img:nth-child(4) { animation-delay: -2.4s; }
@keyframes lab-bob { 50% { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .hero.is-lab img { animation: none; } }

/* ---------- OVEN: แผงควบคุมเตา (คะแนน · Best · Next · ตัวช่วย) ---------- */
.hud { background: var(--hojicha); border-radius: 20px; padding: 7px 10px 9px; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15); }
.icon-btn { background: var(--cream-light); }
.icon-btn svg { fill: var(--hojicha); }
.hud-best { color: var(--cream-light); }
.hud-best svg { fill: #F2C94C; }
.hud-score { background: #2B1D14; color: #FFC56B; border-radius: 10px; letter-spacing: 0.06em; box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6); }
.hud-score.minus { animation: minus-oven 0.5s ease; }
@keyframes minus-oven { 30% { transform: scale(0.9); color: #FF8A7A; } }
.helper { background: var(--cream-light); border-color: #A9CF4C; }
.helper-cost { color: #B03A2E; }
.helper-left { background: #3B2A1E; }
.hud-next { color: var(--cream-light); letter-spacing: 0.12em; text-transform: uppercase; font-size: 10px; gap: 2px; }
.hud-next img { box-sizing: border-box; width: 46px; height: 46px; padding: 3px; border-radius: 50%; background: var(--cream-light); border: 3px solid #C9A27A; }

/* ---------- OVEN: กระดาน RECIPE (ลำดับไอเทม) ---------- */
.evo { background: #34503A; border: 4px solid #B48A62; gap: 1px; }
.evo-title { font-family: var(--font-en); font-weight: 600; font-size: 9px; letter-spacing: 0.22em; color: #F1EAD8; line-height: 1; }
.evo-item span { color: #F1EAD8; }

/* ---------- GIFT: โบว์บนกล่องจบรอบ ---------- */
.sheet-bow { justify-self: center; width: 92px; height: 46px; margin: -6px 0 -6px; fill: none; stroke: #B7D1EA; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.sheet-bow circle { fill: #FFFFFF; stroke-width: 3; }

/* ---------- ธีมคริสต์มาส: หิมะจางๆ บนพื้นหลัง (ไฟประดับวาดบนเตาในเกม) ---------- */
#app { z-index: 1; }
body[data-theme="christmas"]::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.95) 2.5px, transparent 3px), radial-gradient(circle, rgba(255, 255, 255, 0.85) 2px, transparent 2.5px);
  background-size: 90px 110px, 130px 150px;
  background-position: 10px 20px, 60px 80px;
}

/* ---------- กล่องพนักงาน: กดใช้สิทธิ์หลังทำรายการใน Choco CRM ---------- */
.staff-box { display: grid; gap: 8px; padding: 12px; border-radius: 18px; background: #FFF8E6; border: 2px dashed #C9A14A; text-align: left; }
.staff-title { margin: 0; justify-self: center; padding: 4px 12px; border-radius: 999px; background: #3B2A1E; color: #FFF8E6; font-size: 13px; font-weight: 600; }
.staff-steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 13px; line-height: 1.45; color: var(--ink); }
.staff-steps[hidden], .staff-used[hidden] { display: none; }
.btn-staff { background: #3B2A1E; color: #FFF8E6; border-color: #3B2A1E; box-shadow: 0 4px 0 #1F150E; }
.staff-used { margin: 0; text-align: center; font-size: 14px; line-height: 1.5; color: #B8392F; }
.redeem-confirm[hidden] { display: none; }
.redeem-confirm { display: grid; gap: 6px; padding: 10px 12px; border-radius: 14px; background: #FDECE8; border: 2px solid #E8574B; text-align: center; }
.redeem-confirm p { margin: 0; font-size: 13px; line-height: 1.45; color: #8A2A22; }
.reward-stamp { display: none; }
.sheet-reward.is-used .reward-stamp {
  display: block; position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%) rotate(-14deg);
  padding: 4px 14px; border: 4px solid #fff; border-radius: 12px; background: rgba(184, 57, 47, 0.85);
  color: #fff; font-family: var(--font-th); font-weight: 600; font-size: 28px; white-space: nowrap; pointer-events: none;
}
.sheet-reward.is-used .reward-countdown { color: var(--matcha-dark); }
.reward-tile.is-used { background: #EEF3E4; border: 2px solid rgba(95, 145, 58, 0.35); color: var(--matcha-dark); }
.reward-tile.is-used .rt-icon { background: rgba(95, 145, 58, 0.14); color: var(--matcha-dark); }
.reward-tile.is-used .rt-end { color: var(--matcha-dark); }

/* ---------- ฉากเกมจากกราฟิก (13 พ.ย. 2569) ----------
   ภาพ scene-game.jpg (9:16) มีแผงคะแนนด้านบน + ถาดเงินด้านล่างวาดไว้แล้ว
   หน้าเล่นเกมจึงล็อกสัดส่วน 9:16 ชิดล่าง แล้ววาง HUD / เตา / Recipe ให้ตรงกับภาพ
   จอที่สูงหรือกว้างกว่า 9:16: ต่อผนังกระเบื้องเขียว + โต๊ะแดงรอบฉาก */
:root {
  --scene-w: min(100vw, 520px, calc(100vh * 9 / 16));
  --scene-wall: #6B7337;
  --scene-line: #979A63;
  --scene-table: #730506;
}
@supports (height: 100dvh) {
  :root { --scene-w: min(100vw, 520px, calc(100dvh * 9 / 16)); }
}
#screen-game {
  inset: auto 0 0 0;
  width: var(--scene-w);
  margin: 0 auto;
  aspect-ratio: 9 / 16;
  padding: 0;
  background: url(../assets/ui/scene-game.jpg) center / 100% 100% no-repeat;
}
#screen-game.is-active::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--scene-wall);
  background-image:
    linear-gradient(to bottom, transparent 70%, var(--scene-table) 70%),
    linear-gradient(var(--scene-line) 0 calc(var(--scene-w) * 0.0037), transparent 0),
    linear-gradient(90deg, var(--scene-line) 0 calc(var(--scene-w) * 0.0037), transparent 0);
  background-size: 100% 100%, calc(var(--scene-w) * 0.09) calc(var(--scene-w) * 0.09), calc(var(--scene-w) * 0.09) calc(var(--scene-w) * 0.09);
  background-position: 0 0, 0 0, calc(50% - var(--scene-w) / 2) 0;
  pointer-events: none;
}
#screen-game .hud {
  position: absolute;
  top: 2.2%; left: 5%; right: 5%;
  height: 11.6%;
  min-height: 0;
  padding: 0;
  background: none;
  box-shadow: none;
}
#screen-game .icon-btn { background: #C2547A; border-radius: 10px; }
#screen-game .icon-btn svg { fill: #FFFFFF; }
#screen-game .hud-score { background: #4A0A0A; color: #F6EEDC; }
#screen-game .helper { background: #F1E6C8; border-color: #F1E6C8; }
#screen-game .hud-next { color: #FFFFFF; font-style: italic; }
#screen-game .hud-next img { border-color: #E6D3A8; }
#screen-game .stage {
  position: absolute;
  top: 15.5%; bottom: 22.3%; left: 4%; right: 4%;
}
#screen-game .evo {
  position: absolute;
  top: 79.4%; left: 8%; right: 8%;
  height: 9.2%;
  padding: 0 2px;
  align-content: center;
  background: none;
  border: none;
}
#screen-game .evo-title { display: none; }
#screen-game .evo-item span { color: #3B2A1E; }

/* ---------- 13 พ.ย. 2569: ข้อความได้สิทธิ์แยกบรรทัด + กล่องพนักงาน ---------- */
.over-cheer .cheer-won, .over-cheer .cheer-rank, .over-cheer .cheer-gift, .over-cheer .cheer-hint { display: block; }
.over-cheer .cheer-rank { margin: 2px 0; font-size: 22px; font-weight: 600; color: #C2547A; line-height: 1.25; }
.over-cheer .cheer-rank small { display: block; font-family: var(--font-en); font-size: 13px; font-weight: 600; letter-spacing: 0.04em; color: var(--hojicha); }
.over-cheer .cheer-gift b { color: #4A0A0A; }
.over-cheer .cheer-hint { margin-top: 4px; font-size: 12.5px; opacity: 0.8; }
.staff-sub { margin: -2px 0 0; justify-self: center; text-align: center; font-size: 12px; opacity: 0.75; }
.sheet.is-used .staff-sub { display: none; }

/* ---------- ฉลองตอนได้ Gift Box / A Little Wish Box (เด้งกลางเตา ไม่บังการแตะ) ---------- */
.celebrate { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; overflow: hidden; text-align: center; }
.celebrate[hidden] { display: none; }
.celebrate::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 50% 45%, rgba(255, 196, 92, 0.75), rgba(255, 140, 60, 0.25) 45%, transparent 70%); opacity: 0; }
.celebrate-rays { position: absolute; left: 50%; top: 45%; width: 150%; aspect-ratio: 1; translate: -50% -50%; background: repeating-conic-gradient(rgba(255, 236, 170, 0.55) 0 10deg, transparent 10deg 24deg); -webkit-mask: radial-gradient(circle, #000 15%, transparent 60%); mask: radial-gradient(circle, #000 15%, transparent 60%); opacity: 0; }
.celebrate img { position: relative; width: 42%; max-width: 190px; filter: drop-shadow(0 8px 14px rgba(74, 10, 10, 0.35)); opacity: 0; }
.celebrate-kicker { position: relative; margin: 6px 0 0; padding: 3px 14px; border-radius: 999px; background: #4A0A0A; color: #F6EEDC; font-size: 14px; font-weight: 600; opacity: 0; }
.celebrate-title { position: relative; margin: 6px 12px 0; padding: 8px 18px; border-radius: 14px; background: #C2547A; color: #fff; font-size: 19px; font-weight: 600; line-height: 1.3; box-shadow: 0 4px 0 #8E3355, 0 10px 18px rgba(74, 10, 10, 0.3); opacity: 0; }
.confetti { position: absolute; left: 50%; top: 45%; width: 9px; height: 14px; border-radius: 2px; background: hsl(calc(var(--i) * 47deg) 75% 62%); opacity: 0; }

.celebrate.is-on::before { animation: cel-glow 2.2s ease-out forwards; }
.celebrate.is-on .celebrate-rays { animation: cel-rays 2.2s linear forwards; }
.celebrate.is-on img { animation: cel-pop 2.2s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.celebrate.is-on .celebrate-kicker { animation: cel-text 2.2s ease-out 0.15s forwards; }
.celebrate.is-on .celebrate-title { animation: cel-text 2.2s ease-out 0.3s forwards; }
.celebrate.is-on .confetti { animation: cel-confetti 1.6s ease-out 0.1s forwards; }

@keyframes cel-glow { 0% { opacity: 0; } 12% { opacity: 1; } 70% { opacity: 0.8; } 100% { opacity: 0; } }
@keyframes cel-rays { 0% { opacity: 0; rotate: 0deg; } 15% { opacity: 1; } 75% { opacity: 0.9; } 100% { opacity: 0; rotate: 60deg; } }
@keyframes cel-pop { 0% { opacity: 0; scale: 0.3; rotate: -12deg; } 20% { opacity: 1; scale: 1.1; rotate: 4deg; } 32% { scale: 1; rotate: 0deg; } 80% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: 0.85; translate: 0 -10px; } }
@keyframes cel-text { 0% { opacity: 0; translate: 0 14px; scale: 0.8; } 15% { opacity: 1; translate: 0 0; scale: 1.06; } 22% { scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; translate: 0 -8px; } }
@keyframes cel-confetti {
  0% { opacity: 1; translate: -50% -50%; rotate: 0deg; }
  100% { opacity: 0; translate: calc(-50% + cos(calc(var(--i) * 30deg)) * 160px) calc(-50% + sin(calc(var(--i) * 30deg)) * 160px + 60px); rotate: calc(var(--i) * 70deg + 200deg); }
}
@media (prefers-reduced-motion: reduce) {
  .celebrate.is-on .celebrate-rays, .celebrate.is-on .confetti { animation: none; }
}

/* ---------- หน้าแรกจากภาพกราฟิกจริง (18 พ.ย. 2569) ---------- */
.has-title-art .brand, .has-title-art .tagline { display: none; }
.has-title-art .title-wrap img { width: min(72vw, 270px, 30svh); max-height: none; }
.has-title-art .title-wrap { position: relative; z-index: 1; }
/* ภาพมีกรอบห้องแล็บว่างด้านบน: ดึงขึ้นไปอยู่ข้างโลโก้เหมือนภาพรวมของกราฟิก */
/* จอเตี้ย: ย่อภาพตามความสูงจอทั้งภาพ (ไม่ตัดล่าง) ปุ่มจะได้ไม่ทับ */
.hero.is-art { --hw: min(100%, 360px, calc(52svh * 1080 / 1352)); width: var(--hw); aspect-ratio: 1080 / 1352; margin-top: calc(var(--hw) * -0.32); flex-shrink: 0; }

/* ---------- หน้าจบเกมจากภาพกราฟิกจริง (18 พ.ย. 2569): ครัวสีเขียว + แผ่นครีม + กล่องของขวัญใส่การ์ดใหม่ ---------- */
#modal-over { background: #556030 url("../assets/ui/bg-over.png") center / cover no-repeat; -webkit-backdrop-filter: none; backdrop-filter: none; }
.sheet-over { background: #FAF6EB; border-radius: 30px; box-shadow: 0 10px 30px rgba(40, 20, 10, 0.25); }
.sheet-over .sheet-bow { display: none; }
.sheet-over h2 { font-style: italic; font-size: 32px; letter-spacing: 0.02em; text-transform: uppercase; color: #A33A63; }
.sheet-over .over-cheer, .sheet-over .over-cheer .cheer-hint { color: #C2547A; }
.sheet-over .over-label { font-style: italic; font-weight: 600; font-size: 17px; color: #1E1E1E; }
.sheet-over .over-score { color: #1E1E1E; font-size: 60px; }
.sheet-over .new-best { background: #C2547A; font-weight: 500; }
.sheet-over .over-best { color: var(--hojicha); }
/* การ์ดใหม่อยู่ในช่องกระจกของกล่องของขวัญ (ช่องว่างในภาพ: ซ้าย 23% กว้าง 55% · บน 25% สูง 55%) */
.sheet-over .unlocked { position: relative; margin: 0 -18px; padding: 0; border-radius: 0; background: url("../assets/ui/over-gift.png") center / 100% 100% no-repeat; aspect-ratio: 1000 / 811; }
.sheet-over .unlocked-title { position: absolute; left: 26%; right: 25%; top: 27%; margin: 0; padding: 2px 0; background: linear-gradient(90deg, transparent, #CBD38C 15%, #CBD38C 85%, transparent); font-family: var(--font-en); font-style: italic; font-size: 11px; letter-spacing: 0.06em; color: #fff; }
/* การ์ดเต็มช่องหน้าต่างกล่อง: ภาพยืดตามความสูงช่อง (ใบเดียวก็ใหญ่ หลายใบก็แบ่งกว้างกัน) */
.sheet-over .unlocked-list { position: absolute; left: 23%; right: 22%; top: 34%; bottom: 21%; flex-wrap: nowrap; align-items: stretch; gap: 5px; }
.sheet-over .unlocked-list button { flex: 0 1 120px; min-width: 0; height: 100%; justify-content: center; padding: 6px 3px 5px; background: #FFF8EC; box-shadow: 0 2px 6px rgba(59, 42, 30, 0.15); font-size: 11.5px; line-height: 1.15; }
.sheet-over .unlocked-list img { flex: 1 1 auto; min-height: 0; width: 100%; height: auto; object-fit: contain; margin-bottom: 3px; }
.sheet-over #over-rewards:not([hidden]) { padding: 10px; border: 2px dashed #C2547A; border-radius: 18px; background: #F8DDE6; }

/* ---------- หน้าแรกเคลื่อนไหว (18 พ.ย. 2569): ภาพนิ่ง มีแค่ของลอยออกจากขวด ---------- */
.hero.is-art { cursor: pointer; }
.hero-life { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.hero-life > * { position: absolute; }
.hero-rise { top: 46%; width: 13%; margin-left: -6.5%; opacity: 0; animation: hero-rise 6.4s ease-out infinite; }
@keyframes hero-rise {
  0% { opacity: 0; transform: translateY(0) scale(0.4) rotate(0); }
  12% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-150%) scale(0.95) rotate(25deg); }
}
.hero-bubble { top: 70%; width: 9px; height: 9px; margin-left: -4px; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, 0.95); background: rgba(255, 255, 255, 0.35); opacity: 0; animation: hero-bubble 6s ease-in infinite; }
@keyframes hero-bubble { 0% { opacity: 0; transform: translateY(0) scale(0.5); } 15% { opacity: 1; } 85% { opacity: 0.9; } 100% { opacity: 0; transform: translateY(-120px) scale(1.2); } }
.hero-pop { left: 50%; top: 44%; width: 12%; margin-left: -6%; animation: hero-pop 1s ease-out forwards; }
@keyframes hero-pop { 0% { transform: translate(0, 0) scale(0.3); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(200deg); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .hero-life { display: none; }
}

/* ---------- ภาพหน้าแรกแยกเลเยอร์ (18 พ.ย. 2569): ตัวละครสลับท่า คุกกี้หมุนผสม เส้นโรยลอย ---------- */
.hero-layers { position: absolute; inset: 0; overflow: hidden; visibility: hidden; } /* เลเยอร์สูงเท่าจอ ส่วนล่างว่าง ตัดทิ้งไม่ให้หน้าเลื่อน */
.hero.has-layers .hero-layers { visibility: visible; }
.hero.has-layers img.full { visibility: hidden; }
.hl-char { position: absolute; inset: 0; }
.hero .hl { position: absolute; left: 0; top: 0; width: 100%; height: auto; }
.hl-cookie { animation: hl-mix 4.4s linear infinite; }
@keyframes hl-mix {
  0% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(1.6%, -0.7%) rotate(8deg); }
  50% { transform: translate(0, -1.3%) rotate(0); }
  75% { transform: translate(-1.6%, -0.7%) rotate(-8deg); }
  100% { transform: translate(0, 0) rotate(0); }
}
.hl-sprinkles { animation: hl-drift 3.2s ease-in-out infinite; }
@keyframes hl-drift { 50% { transform: translateY(-0.5%); } }
/* สลับท่า 1 ↔ 2 แบบตัดภาพ (ไม่ขยับทั้งตัว) */
.hl-char .hl-b { opacity: 0; animation: hl-frame 1.4s steps(1) infinite; animation-delay: var(--d); }
.hl-char .hl-a { animation: hl-frame-a 1.4s steps(1) infinite; animation-delay: var(--d); }
@keyframes hl-frame { 0% { opacity: 0; } 50% { opacity: 1; } }
@keyframes hl-frame-a { 0% { opacity: 1; } 50% { opacity: 0; } }
/* ตัวละครเด้งเบาๆ ตามจังหวะสลับท่า (Yuki ไม่เด้ง เพราะบันไดอยู่ในภาพเดียวกัน) */
.hl-hop { animation: hl-hop 0.7s ease-in-out infinite; animation-delay: var(--d); }
@keyframes hl-hop { 50% { transform: translateY(-1.2%); } }
@media (prefers-reduced-motion: reduce) { .hl-cookie, .hl-sprinkles, .hl-hop, .hl-char .hl-a, .hl-char .hl-b { animation: none; } }

/* ---------- ไอคอนตัวช่วยจากกราฟิก (Pond ส่ง 19 พ.ย. 2569): ใช้แทน svg เดิม ---------- */
#btn-whisk svg, #btn-scoop svg { display: none; }
#btn-whisk::before, #btn-scoop::before { content: ''; width: 26px; height: 26px; background: center / contain no-repeat; }
#btn-whisk::before { background-image: url("../assets/ui/icon-whisk.png"); }
#btn-scoop::before { background-image: url("../assets/ui/icon-scoop.png"); }
#screen-game .helper.is-on { background: #E8574B; border-color: #E8574B; } /* กำลังเลือกชิ้นที่จะตัก: ปุ่มแดง ไอคอนขาว */
.helper.is-on::before { filter: brightness(0) invert(1); }
