:root {
  --night: #140b2b;
  --deep: #22124a;
  --purple: #4b2a8c;
  --violet: #7b4fd6;
  --lilac: #c9b3ff;
  --orange: #ff8a1f;
  --orange-dark: #c25400;
  --yellow: #ffd24a;
  --blood: #e0263f;
  --cream: #fff6e5;
  --good: #3ad07a;
  --bad: #b06cff;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: "Kanit", system-ui, sans-serif;
  color: var(--cream);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
body {
  background:
    radial-gradient(circle at 78% 14%, rgba(255, 220, 140, .25), transparent 22%),
    radial-gradient(ellipse at 50% 120%, #5b2f91 0%, transparent 60%),
    linear-gradient(180deg, #0d0720 0%, #1c0f3d 55%, #2c1557 100%);
}
button { font-family: inherit; }
.hidden { display: none !important; }

/* Phone-shaped stage, centered on desktop */
#app {
  position: fixed; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; overflow: hidden; background: var(--night);
}
@media (min-width: 560px) {
  #app {
    top: 12px; bottom: 12px; border-radius: 28px;
    box-shadow: 0 0 0 2px rgba(201, 179, 255, .25), 0 30px 80px rgba(0, 0, 0, .6), 0 0 60px rgba(123, 79, 214, .35);
  }
}
#game { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 58px;
  display: flex; gap: 6px; align-items: stretch; pointer-events: none;
}
.hud-box, .hud-meter, .icon-btn {
  background: rgba(34, 18, 74, .82); border: 2.5px solid var(--orange); border-radius: 14px;
  box-shadow: 0 3px 0 var(--orange-dark), inset 0 0 12px rgba(123, 79, 214, .5);
}
.hud-box {
  padding: 2px 10px; min-width: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.label { font-size: 12px; color: var(--lilac); line-height: 1.2; }
.hud-box span:last-child { font-size: 26px; font-weight: 800; line-height: 1.05; color: var(--yellow); }
.hud-meter { flex: 1; padding: 4px 10px; display: flex; flex-direction: column; justify-content: center; }
.bar { position: relative; height: 18px; background: #160a30; border-radius: 9px; overflow: hidden; margin-top: 3px; }
#energyFill {
  position: absolute; inset: 0 auto 0 0; width: 0%;
  background: linear-gradient(90deg, #7a0f22, var(--blood) 60%, #ff5c7a);
  box-shadow: 0 0 10px rgba(255, 60, 90, .7);
  transition: width .2s ease;
}
#energyFill.full { background: linear-gradient(90deg, #ff8a1f, #ffd24a, #fff3a8); box-shadow: 0 0 14px rgba(255, 210, 74, .9); }
#energyText { position: relative; display: block; text-align: center; font-size: 12px; font-weight: 600; line-height: 18px; text-shadow: 0 1px 2px #000; }

.icon-btn {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 8px; z-index: 5;
  width: 44px; height: 44px; border-radius: 50%; font-size: 20px; cursor: pointer; color: #fff;
}

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(13, 6, 32, .55); backdrop-filter: blur(2px);
  overflow-y: auto; touch-action: pan-y;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; } }

.screen:not(.screen-start) { padding-top: max(62px, env(safe-area-inset-top)); }
.screen-start { background: linear-gradient(180deg, rgba(13, 6, 32, .35), rgba(13, 6, 32, .1) 40%, rgba(13, 6, 32, .55)); justify-content: space-between; gap: 6px; }

.demo-pill {
  font-size: 11px; color: var(--yellow); border: 1px dashed rgba(255, 210, 74, .6);
  border-radius: 999px; padding: 2px 10px; background: rgba(0, 0, 0, .3);
}

/* Title — sticker-style lettering */
.title { display: flex; flex-direction: column; align-items: center; font-family: "Mitr", "Kanit", sans-serif; line-height: 1; margin-top: 8px; transform: rotate(-3deg); }
/* the span itself is the white outline; ::after lays the gradient fill on top */
.title span {
  position: relative; display: block; font-weight: 700; color: #fff;
  -webkit-text-stroke: 12px #fff; paint-order: stroke fill;
  text-shadow: 0 6px 0 #3b1d78, 0 8px 18px rgba(0, 0, 0, .5);
}
.title span::after {
  content: attr(data-text); position: absolute; inset: 0;
  -webkit-text-stroke: 0; text-shadow: none; color: transparent;
  -webkit-background-clip: text; background-clip: text;
}
.title-top { font-size: clamp(46px, 14vw, 64px); }
.title-top::after { background-image: linear-gradient(180deg, #ffe066 0%, #ffb02e 50%, #ff7a1a 100%); }
.title-sub { margin-top: 6px; font-size: clamp(26px, 8vw, 36px); -webkit-text-stroke-width: 9px; transform: rotate(2deg); }
.title-sub::after { background-image: linear-gradient(180deg, #a77bff, #5b2fc0); }

.title-img { width: min(88%, 380px); height: auto; margin-top: 4px; filter: drop-shadow(0 8px 18px rgba(0, 0, 0, .5)); }
#hero { width: min(78vw, 300px); height: min(78vw, 300px); flex-shrink: 1; min-height: 160px; }

.btn-stack { display: grid; gap: 12px; width: 100%; max-width: 320px; }
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 24px; font-weight: 800; color: #fff; border: none; border-radius: 999px;
  padding: 12px 28px; cursor: pointer; width: 100%;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); }
.btn .arrow { font-size: .8em; }
.btn-orange {
  background: linear-gradient(180deg, #ffd24a 0%, #ff9a26 55%, #ff7a1a 100%);
  border: 3px solid #fff3c4; color: #5a1e00; text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
  box-shadow: 0 6px 0 var(--orange-dark), 0 10px 24px rgba(255, 138, 31, .45);
}
.btn-orange:active { box-shadow: 0 2px 0 var(--orange-dark); }
.btn-purple {
  font-size: 20px; background: linear-gradient(180deg, #a77bff, #6a3fd0);
  border: 3px solid #e2d4ff; box-shadow: 0 6px 0 #3b1d78, 0 10px 24px rgba(123, 79, 214, .45);
}
.btn-purple:active { box-shadow: 0 2px 0 #3b1d78; }
.btn-ghost { font-size: 18px; background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .35); }
.btn-sm { font-size: 18px; padding: 10px 18px; }
.link-btn { background: none; border: none; color: var(--lilac); font-size: 15px; margin-top: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.best { font-size: 13px; color: var(--lilac); }

/* Panel card */
.panel {
  width: 100%; max-width: 400px; margin: auto; text-align: center;
  background: linear-gradient(180deg, rgba(59, 29, 120, .96), rgba(30, 14, 66, .96));
  border: 3px solid var(--lilac); border-radius: 26px; padding: 20px 18px;
  box-shadow: 0 0 0 4px rgba(75, 42, 140, .8), 0 16px 40px rgba(0, 0, 0, .6), inset 0 0 30px rgba(167, 123, 255, .25);
}
.panel > .btn { margin-top: 10px; }
.panel-title { font-family: "Mitr", sans-serif; font-size: 28px; color: var(--yellow); text-shadow: 0 3px 0 #3b1d78; margin-bottom: 6px; }
.lead { font-size: 15px; margin-bottom: 10px; }
.hl { color: var(--yellow); }
.muted { color: var(--lilac); font-size: 14px; }

/* Rules */
.rule-head { font-size: 15px; text-align: left; margin: 10px 2px 6px; }
.rule-head.good { color: var(--good); }
.rule-head.bad { color: #ff7b9c; }
.rule-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rule-grid figure {
  background: rgba(0, 0, 0, .25); border: 2px solid rgba(201, 179, 255, .25); border-radius: 14px;
  padding: 6px 2px 4px; display: flex; flex-direction: column; align-items: center;
}
.rule-grid figure.rare { border-color: rgba(255, 210, 74, .7); box-shadow: inset 0 0 12px rgba(255, 210, 74, .25); }
.rule-grid canvas { width: 54px; height: 54px; }
.rule-grid figcaption { font-size: 12px; line-height: 1.25; display: flex; flex-direction: column; }
.pt { font-size: 15px; font-weight: 800; }
.pt.good { color: var(--good); } .pt.bad { color: #ff7b9c; } .pt.gold { color: var(--yellow); }
.steps { list-style: none; text-align: left; display: grid; gap: 6px; margin: 14px 0 6px; font-size: 14px; }
.steps li { display: flex; gap: 8px; align-items: flex-start; }
.steps span {
  flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--orange); color: #3a1300;
  font-weight: 800; font-size: 13px; display: grid; place-items: center; margin-top: 1px;
}

/* End */
.end-emoji { font-size: 56px; line-height: 1; margin-bottom: 4px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
#endMsg { font-size: 17px; margin: 4px 0 10px; }
.final { display: flex; flex-direction: column; align-items: center; margin-bottom: 4px; }
.final small { font-size: 14px; color: var(--lilac); }
#finalScore { font-size: 56px; font-weight: 800; color: var(--yellow); line-height: 1; text-shadow: 0 4px 0 #3b1d78; }
.panel-end .best { margin-bottom: 4px; }

/* ---------- Reward ---------- */
.screen-reward { background: radial-gradient(circle at 50% 38%, rgba(123, 79, 214, .55), rgba(13, 6, 32, .9) 70%); overflow: hidden; }
.reward-rays {
  position: absolute; left: 50%; top: 36%; width: 900px; height: 900px; margin: -450px 0 0 -450px; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255, 210, 74, .16) 0 10deg, transparent 10deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 0%, transparent 55%); mask: radial-gradient(circle, #000 0%, transparent 55%);
  animation: spin 24s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reward-phase { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; text-align: center; width: 100%; max-width: 400px; }

.mystery { width: 220px; height: 220px; animation: shake .6s ease-in-out infinite; filter: drop-shadow(0 0 24px rgba(167, 123, 255, .8)); }
@keyframes shake {
  0%, 100% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-6deg) scale(1.03); }
  40% { transform: rotate(5deg) scale(.98); }
  60% { transform: rotate(-4deg) scale(1.04); }
  80% { transform: rotate(3deg); }
}
.opening-text { font-size: 20px; font-weight: 600; margin-top: 8px; }
.dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.reward-badge {
  font-size: 16px; font-weight: 600; padding: 6px 18px; border-radius: 999px;
  background: rgba(0, 0, 0, .35); border: 2px solid var(--lilac);
  animation: popIn .5s .1s both cubic-bezier(.2, 1.6, .4, 1);
}
.reward-badge.grand { background: linear-gradient(90deg, #ff8a1f, #ffd24a); color: #4a1800; border-color: #fff3c4; box-shadow: 0 0 24px rgba(255, 210, 74, .7); }
.prize-stage {
  position: relative; width: min(72vw, 280px); aspect-ratio: 1; margin: 6px 0 2px;
  display: grid; place-items: center;
  background: radial-gradient(circle, rgba(255, 246, 229, .95) 0%, rgba(255, 210, 74, .55) 45%, transparent 70%);
  border-radius: 50%;
  animation: popIn .7s .35s both cubic-bezier(.2, 1.6, .4, 1);
}
.prize-stage img { width: 86%; height: 86%; object-fit: contain; filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .45)); animation: float 3s ease-in-out infinite; }
.prize-fallback { font-size: 140px; }
@keyframes float { 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes popIn { from { opacity: 0; transform: scale(.3); } }
.prize-name {
  font-family: "Mitr", sans-serif; font-size: clamp(28px, 8.5vw, 38px); line-height: 1.15; color: var(--yellow);
  text-shadow: 0 3px 0 #3b1d78, 0 0 20px rgba(255, 210, 74, .5);
  margin-top: 8px;
  animation: popIn .5s .15s both cubic-bezier(.2, 1.6, .4, 1);
}
.prize-desc { font-size: 16px; color: var(--cream); margin-top: 4px; min-height: 1em; animation: fadeIn .4s .6s both; }
.dup-note { font-size: 13px; color: var(--yellow); margin-top: 6px; }
.claim-hint { font-size: 13px; color: var(--lilac); margin: 14px 0 12px; line-height: 1.5; animation: fadeIn .4s .7s both; }
.claim-hint .ref { font-size: 11px; opacity: .75; letter-spacing: .5px; }
.reward-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; animation: fadeIn .4s .8s both; }

#confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* Prize catalogue */
.prize-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; }
.prize-card {
  position: relative; background: rgba(0, 0, 0, .28); border: 2px solid rgba(201, 179, 255, .3); border-radius: 16px;
  padding: 10px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.prize-card.grand { grid-column: span 2; border-color: var(--yellow); box-shadow: inset 0 0 20px rgba(255, 210, 74, .25); }
.prize-card img { width: 90px; height: 90px; object-fit: contain; }
.prize-card.grand img { width: 130px; height: 130px; }
.prize-card b { font-size: 15px; line-height: 1.2; }
.prize-card small { font-size: 12px; color: var(--lilac); }
.prize-card .tag { position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 600; background: var(--yellow); color: #4a1800; border-radius: 999px; padding: 1px 8px; }

@media (max-height: 640px) {
  #hero { height: 150px; }
  .title-top { font-size: 44px; }
  .title-sub { font-size: 26px; }
  .btn { font-size: 20px; padding: 9px 22px; }
}
@media (max-width: 380px) {
  .hud-box { min-width: 52px; padding: 2px 6px; }
  .hud-box span:last-child { font-size: 22px; }
  .rule-grid canvas { width: 46px; height: 46px; }
}
