:root {
  --bg: #0d0620;
  --stage-a: #3b0f7a;
  --stage-b: #1a0b3d;
  --gold: #f9c74f;
  --gold-dark: #c98a12;
  --red: #e0262f;
  --ink: #ffffff;
  --ink-2: #d9ccff;
  --bad: #ff8a8a;
  --good: #7dffb0;
  --font: Kanit, "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg) radial-gradient(circle at 50% 40%, #2a1052, var(--bg) 70%);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

html.kiosk,
html.kiosk body {
  user-select: none;
  -webkit-user-select: none;
  cursor: none;
}
html.kiosk .modal input {
  user-select: text;
  -webkit-user-select: text;
}

/* ---------- 9:16 stage: exact on a 1080x1920 kiosk, letterboxed on wide screens,
   and allowed to grow taller (up to 9:19.5) so modern phones are filled edge to edge ---------- */
.stage {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100vw, 100dvh * 9 / 16);
  height: min(100dvh, 100vw * 19.5 / 9);
  container-type: size;
  overflow: hidden;
  overflow: clip; /* unlike hidden, cannot be scrolled by focus()/scrollIntoView */
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  justify-items: center;
  padding: max(env(safe-area-inset-top), 3cqh) 4cqw max(env(safe-area-inset-bottom), 2cqh);
  background: radial-gradient(circle at 50% 42%, var(--stage-a), var(--stage-b) 75%);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
}

.rays {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.rays::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 46%;
  width: 180cqh;
  height: 180cqh;
  translate: -50% -50%;
  background: repeating-conic-gradient(rgba(255, 255, 255, 0.05) 0 10deg, transparent 10deg 20deg);
  mask: radial-gradient(circle, #000 15%, transparent 55%);
  animation: rays 60s linear infinite;
}
@keyframes rays {
  to {
    rotate: 360deg;
  }
}

.hotspot {
  position: absolute;
  left: 0;
  top: 0;
  width: 14cqw;
  height: 14cqw;
  z-index: 5;
}

.banner {
  position: absolute;
  inset: 0 0 auto;
  z-index: 6;
  padding: 1.2cqh 4cqw;
  background: #b5121b;
  font-size: 2cqh;
  text-align: center;
}

/* ---------- header ---------- */
.head {
  position: relative;
  text-align: center;
  z-index: 1;
}
.head h1 {
  margin: 0;
  font-size: 5.2cqh;
  font-weight: 800;
  line-height: 1.1;
  background: linear-gradient(180deg, #fff6c9, var(--gold) 55%, var(--gold-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0.4cqh 0 rgba(0, 0, 0, 0.35));
  text-wrap: balance;
}
.subtitle {
  margin: 1cqh 0 0;
  font-size: 2.4cqh;
  color: var(--ink-2);
}
.stage[data-state="ready"] .subtitle {
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.55;
    transform: scale(0.97);
  }
}

/* ---------- wheel ---------- */
.wheel-wrap {
  position: relative;
  align-self: center;
  width: min(96cqw, 58cqh);
  aspect-ratio: 1;
  z-index: 1;
  container-type: inline-size;
}
/* label over the canvas hub (hub radius = 0.2 * R, R = 41.5% of the wheel) */
.wheel-hub {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font: 800 4.15cqw/1 var(--font);
  color: #fff;
  white-space: nowrap;
}
#wheel {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* ---------- controls ---------- */
.panel {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 1.4cqh;
  width: 100%;
  min-height: 16cqh;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 1.6cqh 6cqw;
  font: 800 2.6cqh/1 var(--font);
  color: #3a1d00;
  background: linear-gradient(180deg, #fff1a8, var(--gold) 50%, var(--gold-dark));
  box-shadow: 0 0.6cqh 0 #8a5a00, 0 1cqh 2cqh rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s;
}
.btn:active:not(:disabled) {
  transform: translateY(0.5cqh);
  box-shadow: 0 0.1cqh 0 #8a5a00, 0 0.5cqh 1cqh rgba(0, 0, 0, 0.4);
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  box-shadow: inset 0 0 0 0.25cqh rgba(255, 255, 255, 0.35);
}

.spin-btn {
  font-size: 3.6cqh;
  padding: 2cqh 14cqw;
  background: linear-gradient(180deg, #ff7a7f, var(--red) 55%, #9b0f17);
  color: #fff;
  box-shadow: 0 0.7cqh 0 #6d0a10, 0 1.2cqh 2.5cqh rgba(0, 0, 0, 0.45);
  text-shadow: 0 0.3cqh 0 rgba(0, 0, 0, 0.25);
}
.stage[data-state="ready"] .spin-btn {
  animation: bob 1.4s ease-in-out infinite;
}
@keyframes bob {
  50% {
    transform: scale(1.05);
  }
}
.spin-btn:active:not(:disabled) {
  box-shadow: 0 0.1cqh 0 #6d0a10, 0 0.5cqh 1cqh rgba(0, 0, 0, 0.4);
}

.code-form {
  display: flex;
  gap: 2cqw;
  width: 100%;
  justify-content: center;
}
.code-form[hidden] {
  display: none;
}
.code-form input {
  width: 52cqw;
  min-width: 0;
  border: 0.3cqh solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  padding: 1.4cqh 4cqw;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font: 600 2.8cqh/1 ui-monospace, "Cascadia Mono", Menlo, monospace;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
  outline: none;
}
.code-form input:focus {
  border-color: var(--gold);
}
.code-form .btn {
  font-size: 2.2cqh;
  padding: 1.4cqh 4cqw;
}

.status {
  margin: 0;
  min-height: 2.6cqh;
  font-size: 2.1cqh;
  text-align: center;
  color: var(--ink-2);
  text-wrap: balance;
}
.status.error {
  color: var(--bad);
}

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--gold);
  font: 600 2cqh var(--font);
  text-decoration: underline;
  text-underline-offset: 0.4cqh;
  cursor: pointer;
  padding: 0.5cqh 2cqw;
}

.foot {
  font-size: 1.5cqh;
  color: rgba(255, 255, 255, 0.4);
  min-height: 1.5cqh;
  z-index: 1;
}

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* ---------- modals ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 5cqw;
  background: rgba(8, 2, 20, 0.72);
  backdrop-filter: blur(3px);
  animation: fade 0.25s ease-out;
}
.modal[hidden] {
  display: none;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}

.card {
  position: relative;
  width: 100%;
  border-radius: 3cqh;
  background: linear-gradient(180deg, #4a1896, #23094d);
  box-shadow: inset 0 0 0 0.4cqh rgba(255, 255, 255, 0.15), 0 2cqh 5cqh rgba(0, 0, 0, 0.5);
  padding: 4cqh 6cqw;
  text-align: center;
}

.result-card {
  overflow: hidden;
  animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}
.result-card .glow {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 160%;
  aspect-ratio: 1;
  translate: -50% -50%;
  background: repeating-conic-gradient(rgba(255, 230, 140, 0.18) 0 12deg, transparent 12deg 24deg);
  mask: radial-gradient(circle, #000 10%, transparent 60%);
  animation: rays 12s linear infinite;
  pointer-events: none;
}
.kicker {
  position: relative;
  margin: 0;
  font-size: 3.4cqh;
  font-weight: 800;
  color: var(--gold);
}
.prize-pic {
  position: relative;
  width: 30cqh;
  max-width: 70cqw;
  aspect-ratio: 1;
  margin: 2cqh auto;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0.8cqh var(--gold), 0 0 5cqh rgba(249, 199, 79, 0.6);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.prize-pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.prize-pic span {
  font-size: 15cqh;
}
.result-card h2 {
  position: relative;
  margin: 0;
  font-size: 4cqh;
  line-height: 1.2;
  text-wrap: balance;
}
.result-card .note {
  position: relative;
  margin: 1.5cqh 0 2.5cqh;
  font-size: 1.9cqh;
  color: var(--ink-2);
  text-wrap: balance;
}
.result-card .note:empty {
  margin: 1.5cqh 0;
}

#result.grand .result-card {
  background: linear-gradient(180deg, #7a4d00, #2b1600);
  box-shadow: inset 0 0 0 0.5cqh var(--gold), 0 0 8cqh rgba(249, 199, 79, 0.55);
}
#result.grand .kicker {
  font-size: 4cqh;
  animation: pulse 0.9s ease-in-out infinite;
}

/* ---------- setup ---------- */
.setup-card {
  text-align: left;
  display: grid;
  gap: 1.4cqh;
}
.setup-card h2 {
  margin: 0;
  font-size: 3cqh;
}
.setup-card .hint {
  margin: 0;
  font-size: 1.6cqh;
  color: var(--ink-2);
}
.setup-card label {
  display: grid;
  gap: 0.6cqh;
  font-size: 1.8cqh;
  color: var(--ink-2);
}
.setup-card label[hidden] {
  display: none;
}
.setup-card input {
  border: 0.2cqh solid rgba(255, 255, 255, 0.3);
  border-radius: 1.2cqh;
  padding: 1.2cqh 3cqw;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font: 400 2cqh var(--font);
  outline: none;
}
.setup-card input:focus {
  border-color: var(--gold);
}
.setup-card .row {
  display: flex;
  justify-content: space-between;
  gap: 3cqw;
}
.setup-card .row .btn {
  flex: 1;
  font-size: 2.2cqh;
  padding: 1.4cqh 2cqw;
}
.msg {
  margin: 0;
  min-height: 2cqh;
  font-size: 1.8cqh;
}
.msg.error {
  color: var(--bad);
}
.msg.ok {
  color: var(--good);
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .rays::before,
  .result-card .glow,
  .stage[data-state="ready"] .subtitle,
  .stage[data-state="ready"] .spin-btn {
    animation: none;
  }
}
