/* เกมมหาผัน — โทนพาสเทล น่ารัก */
/* ฟอนต์เก็บในเว็บเอง (assets/fonts, สัญญาอนุญาต OFL) — เฉพาะชุดอักษรไทยและละติน */
/* Mitr 400 thai */
@font-face {
  font-family: 'Mitr';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/mitr-400-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
/* Mitr 400 latin */
@font-face {
  font-family: 'Mitr';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/mitr-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Mitr 500 thai */
@font-face {
  font-family: 'Mitr';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(../assets/fonts/mitr-500-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
/* Mitr 500 latin */
@font-face {
  font-family: 'Mitr';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(../assets/fonts/mitr-500-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Mitr 600 thai */
@font-face {
  font-family: 'Mitr';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(../assets/fonts/mitr-600-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
/* Mitr 600 latin */
@font-face {
  font-family: 'Mitr';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(../assets/fonts/mitr-600-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Sarabun 400 thai */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/sarabun-400-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}

/* Sarabun 400 latin */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/sarabun-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Sarabun 600 thai */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(../assets/fonts/sarabun-600-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}

/* Sarabun 600 latin */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(../assets/fonts/sarabun-600-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Sarabun 700 thai */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../assets/fonts/sarabun-700-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}

/* Sarabun 700 latin */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../assets/fonts/sarabun-700-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #4a2c3b;
  --ink-soft: #7a5867;
  --pink: #ff7aa2;
  --pink-deep: #e0567f;
  --pink-soft: #ffd3e0;
  --cream: #fffaf2;
  --mint: #bfeadb;
  --gold: #f2c14e;
  --gold-deep: #c98f12;
  --font-fun: "Mitr", "Leelawadee UI", "Thonburi", sans-serif;
  --font-body: "Sarabun", "Leelawadee UI", "Thonburi", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(circle at 20% 10%, #ffe3ec, transparent 50%),
              radial-gradient(circle at 80% 90%, #d9f3e8, transparent 50%),
              #fff4ea;
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.stage {
  position: relative;
  width: 100%; max-width: 480px;
  height: 100vh; height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
@media (min-width: 560px) and (min-height: 700px) {
  .stage { height: min(100dvh - 32px, 880px); margin-top: 16px; border-radius: 32px; box-shadow: 0 30px 80px rgba(160, 80, 110, 0.25); }
}
canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
}
.hud[hidden] { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px; padding: 4px 12px;
  font-family: var(--font-fun); font-size: 1.15rem; color: var(--ink);
  box-shadow: 0 3px 0 rgba(224, 86, 127, 0.18), 0 6px 14px rgba(160, 80, 110, 0.12);
  min-width: 64px; justify-content: center;
}
.pill small { font-size: 0.75rem; color: var(--ink-soft); }
.pill-icon { width: 22px; height: 22px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.timebar {
  flex: 1; height: 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 2px 4px rgba(160, 80, 110, 0.15);
  overflow: hidden;
}
.timebar i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #8fdcb8, #ffd36b 60%, #ff8fb1);
  border-radius: 999px; transform-origin: left center;
}
.timebar.hurry i { animation: hurry 0.5s ease-in-out infinite alternate; }
@keyframes hurry { to { filter: brightness(1.2) saturate(1.3); } }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, 0.88); color: var(--pink-deep);
  box-shadow: 0 3px 0 rgba(224, 86, 127, 0.25), 0 6px 14px rgba(160, 80, 110, 0.12);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(224, 86, 127, 0.25); }

.combo {
  position: absolute; left: 50%; top: calc(64px + env(safe-area-inset-top)); z-index: 5;
  transform: translateX(-50%);
  font-family: var(--font-fun); font-size: 1.1rem; color: #fff;
  background: linear-gradient(135deg, #ffb347, #ff7aa2);
  padding: 2px 14px; border-radius: 999px;
  box-shadow: 0 4px 12px rgba(255, 122, 162, 0.4);
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; white-space: nowrap;
}
.combo.show { opacity: 1; animation: pop 0.3s ease; }

.countdown {
  position: absolute; inset: 0; z-index: 6;
  display: grid; place-items: center; pointer-events: none;
  font-family: var(--font-fun); font-size: 7rem; color: #fff;
  text-shadow: 0 6px 0 var(--pink-deep), 0 14px 30px rgba(224, 86, 127, 0.45);
}
.countdown[hidden] { display: none; }
.countdown span { animation: pop 0.6s ease both; }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(255, 244, 248, 0.35);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  overflow-y: auto; touch-action: pan-y;
}
.overlay[hidden] { display: none; }
.top-row { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: center; }
.back-link { color: var(--ink); font-size: 0.92rem; text-decoration: none; background: rgba(255, 255, 255, 0.8); padding: 6px 12px; border-radius: 999px; }

.panel {
  width: 100%; max-width: 380px; text-align: center;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 30px; padding: 22px 20px 18px;
  box-shadow: 0 6px 0 rgba(255, 170, 196, 0.55), 0 20px 50px rgba(160, 80, 110, 0.2);
  animation: rise 0.35s ease both;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.start-panel, .end-panel { margin-top: 64px; padding-top: 0; }
.hero-mascot { width: 118px; height: auto; margin: -62px auto 0; filter: drop-shadow(0 10px 12px rgba(224, 86, 127, 0.25)); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.kicker { margin: 4px 0 0; font-size: 0.9rem; color: var(--pink-deep); font-weight: 700; }
.title { font-family: var(--font-fun); font-weight: 600; font-size: 2rem; line-height: 1.3; margin: 2px 0 6px; color: var(--ink); }
.title.small { font-size: 1.5rem; }
.lead { margin: 0 0 12px; color: var(--ink-soft); line-height: 1.6; }

.legend { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.legend li {
  display: flex; align-items: center; gap: 6px;
  background: #fff6f9; border-radius: 16px; padding: 6px 8px; font-size: 0.92rem; color: var(--ink-soft);
}
.legend li.bad { background: #f1effa; }
.legend b { font-family: var(--font-fun); color: var(--ink); font-weight: 500; }
.legend span { width: 36px; height: 36px; flex: none; display: block; }
.legend canvas { display: block; }
.goal { margin: 0 0 14px; font-size: 0.95rem; color: var(--ink); background: linear-gradient(90deg, #fff1c9, #ffe0ea); border-radius: 14px; padding: 8px 10px; }
.goal:empty { display: none; }

.gbtn {
  display: block; width: 100%; min-height: 56px; border: 0; cursor: pointer;
  border-radius: 999px; padding: 10px 20px;
  font-family: var(--font-fun); font-size: 1.3rem; color: #fff; letter-spacing: 0.02em;
  background: linear-gradient(180deg, #ff9fbd, #ff6f9a);
  box-shadow: 0 6px 0 var(--pink-deep), 0 12px 24px rgba(255, 111, 154, 0.35);
  transition: transform 0.08s, box-shadow 0.08s;
}
.gbtn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--pink-deep), 0 4px 10px rgba(255, 111, 154, 0.3); }
.gbtn:focus-visible, .link-btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid #7cc9a6; outline-offset: 3px; }
.link-btn {
  display: block; width: 100%; margin-top: 10px; padding: 10px;
  background: none; border: 0; cursor: pointer; text-decoration: none; text-align: center;
  font-family: var(--font-body); font-size: 1rem; font-weight: 600; color: var(--pink-deep);
}
.link-btn[hidden] { display: none; }
.tiny { font-size: 0.78rem; color: var(--ink-soft); margin: 10px 0 0; line-height: 1.5; }

.end-panel .title { font-size: 2.2rem; }
.end-panel #end-score { color: var(--pink-deep); }
.best { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }
.reward-msg { margin: 10px 0 16px; padding: 10px 12px; border-radius: 16px; background: #fff6d9; font-size: 1rem; line-height: 1.55; }

/* ---------- Coupon ---------- */
.coupon-screen { justify-content: flex-start; background: rgba(255, 240, 246, 0.82); }
.coupon {
  position: relative; width: 100%; max-width: 360px; margin-top: 12px; flex: none;
  background: linear-gradient(160deg, #fffdf7 0%, #fff4e6 55%, #ffeef3 100%);
  border-radius: 24px;
  padding: 16px 18px 12px;
  box-shadow: 0 0 0 2px #f5d58a, 0 0 0 6px #fff, 0 0 0 8px #ffc2d4, 0 18px 40px rgba(160, 80, 110, 0.25);
  text-align: center; overflow: hidden;
  animation: rise 0.4s ease both;
}
.coupon::before, .coupon::after {
  content: ""; position: absolute; top: 57%; width: 22px; height: 22px; border-radius: 50%;
  background: #ffeef4; box-shadow: inset 0 0 0 2px #f5d58a;
}
.coupon::before { left: -11px; }
.coupon::after { right: -11px; }
.coupon-head { display: flex; align-items: center; justify-content: center; gap: 8px; }
.coupon-head img { width: 34px; height: 34px; background: #1a130a; border-radius: 10px; padding: 3px; }
.coupon-head div { text-align: left; line-height: 1.15; }
.coupon-head b { font-family: var(--font-fun); font-size: 1.15rem; display: block; }
.coupon-head small { font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-deep); }
.c-label { margin: 10px 0 0; font-size: 0.9rem; font-weight: 700; color: var(--pink-deep); letter-spacing: 0.08em; }
.c-discount {
  margin: 0; font-family: var(--font-fun); font-weight: 600; font-size: 2.7rem; line-height: 1.25;
  background: linear-gradient(135deg, #ff6f9a, #e3a31f); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.c-detail { margin: 0 0 8px; font-size: 0.95rem; color: var(--ink-soft); }
.c-code {
  margin: 0 auto 10px; padding: 8px 10px; max-width: 280px;
  border: 2px dashed #f0a9c0; border-radius: 14px; background: #fff;
}
.c-code small { display: block; font-size: 0.75rem; color: var(--ink-soft); }
.c-code b { font-family: ui-monospace, "Consolas", "Menlo", monospace; font-size: 1.45rem; letter-spacing: 0.08em; color: var(--ink); }
.c-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; border-top: 1.5px dashed #f2cfa0; padding-top: 10px; }
.c-meta small { display: block; font-size: 0.75rem; color: var(--ink-soft); }
.c-meta b { font-family: var(--font-fun); font-weight: 500; font-size: 1.05rem; }
.c-terms { list-style: none; margin: 0 0 6px; padding: 0; text-align: left; font-size: 0.78rem; line-height: 1.45; color: var(--ink-soft); }
.c-terms li { position: relative; padding-left: 14px; }
.c-terms li::before { content: "•"; position: absolute; left: 3px; color: var(--pink); }
.c-shop { margin: 6px 0 0; font-size: 0.8rem; font-weight: 600; color: var(--ink); }
.c-shop span { white-space: nowrap; }
.c-foot { margin: 2px 0 0; font-size: 0.72rem; color: var(--ink-soft); }
.stamp {
  position: absolute; top: 12px; right: -34px; transform: rotate(28deg);
  background: #ff5b5b; color: #fff; font-family: var(--font-fun); font-size: 0.85rem; line-height: 1.15;
  padding: 4px 40px; text-align: center; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.stamp small { font-size: 0.65rem; }
.stamp[hidden] { display: none; }
.snap-hint { margin: 14px 0 6px; font-weight: 700; color: var(--ink); font-size: 1rem; }
.coupon-actions { width: 100%; max-width: 360px; }
.toast { min-height: 1.4em; margin: 6px 0 0; font-size: 0.9rem; color: var(--pink-deep); text-align: center; }

/* ---------- Staff ---------- */
.staff-form { display: grid; gap: 10px; margin: 6px 0 10px; }
.staff-form input {
  min-height: 52px; border-radius: 16px; border: 2px solid #ffc2d4; padding: 8px 14px;
  font-family: ui-monospace, "Consolas", monospace; font-size: 1.3rem; text-align: center; text-transform: uppercase; color: var(--ink);
}
.staff-result { font-size: 1rem; line-height: 1.6; min-height: 1.6em; margin: 0; }
.staff-result.ok { color: #1f7a4f; }
.staff-result.bad { color: #c0392b; }

@media (prefers-reduced-motion: reduce) {
  .hero-mascot, .panel, .coupon, .countdown span, .combo.show { animation: none; }
}
@media (max-height: 640px) {
  .start-panel { margin-top: 48px; }
  .hero-mascot { width: 92px; margin-top: -48px; }
  .title { font-size: 1.7rem; }
  .legend li { padding: 4px 6px; }
}

/* ---------- ปุ่มเลือกภาษา + สถิติพนักงาน ---------- */
.lang-pills { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.85); border-radius: 999px; padding: 3px; }
.lang-pills button {
  border: 0; background: none; cursor: pointer; min-height: 32px; padding: 2px 9px; border-radius: 999px;
  font-family: var(--font-body); font-size: 0.85rem; font-weight: 600; color: var(--ink-soft);
}
.lang-pills button[aria-pressed="true"] { background: var(--pink-soft); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--pink); }
.staff-stats { margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: #fff6f9; text-align: left; font-size: 0.9rem; line-height: 1.6; }
.staff-stats:empty { display: none; }
