:root {
  --bg-deep: #02030a;
  --bg-mid: #060814;
  --bg-edge: #0a0c1c;
  --gold-light: #fff2c2;
  --gold: #ffcc44;
  --gold-deep: #b8862a;
  --gold-shadow: #5a4012;
  --text: #d8d4e0;
  --muted: #6a6878;
  --card-bg: rgba(10, 12, 22, 0.9);
  --border: rgba(255, 204, 68, 0.15);
  /* Rarity colors */
  --r-common:    #a0a0b0;
  --r-uncommon:  #5aa0ff;
  --r-rare:      #b06aff;
  --r-epic:      #ff6abc;
  --r-legendary: #ffcc44;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at center, var(--bg-edge) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#app { position: relative; width: 100vw; height: 100vh; }
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 24px 16px;
  overflow-y: auto;
}
.screen.visible { display: flex; }
.title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 50%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 8px rgba(255, 204, 68, 0.25));
  text-align: center;
}
.title::after {
  content: '';
  display: block;
  width: 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 6px auto 0;
}
h2 {
  font-size: 24px;
  color: var(--gold);
  margin-top: 20px;
}
.hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
  min-height: 16px;
}
.stats-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 380px;
}
.stat-pill {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
}
.stat-label {
  display: block;
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: var(--gold);
  margin-top: 2px;
}
/* Box stage */
.box-stage {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto 0;     /* auto vertical margin fills empty space above and below */
}
.box-glow {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 204, 68, 0.4) 0%, rgba(176, 106, 255, 0.2) 40%, transparent 70%);
  filter: blur(20px);
  animation: pulse 2.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.9); opacity: 0.7; }
  50%      { transform: scale(1.1); opacity: 1; }
}

/* Box container — falls in on load, then floats gently */
.box-container {
  position: relative;
  width: 85%;
  height: 85%;
  cursor: pointer;
  z-index: 2;
  transform-origin: center bottom;
  animation: fallIn 1s cubic-bezier(0.34, 1.56, 0.64, 1), floatBox 3s ease-in-out 1s infinite;
}
.box-container.shaking { animation: shake 0.15s ease-in-out 6; }
.box-container.opening { animation: openBox 0.6s forwards; }
.box-container.hidden { display: none; }

/* Both PNG images stack in the same spot */
.box-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(255, 204, 68, 0.4))
          drop-shadow(0 4px 12px rgba(0, 0, 0, 0.7));
  transition: transform 0.2s ease, opacity 0.2s ease;
  pointer-events: none;
}

/* Closed version is visible by default */
.box-img-closed { opacity: 1; }

/* Open version hidden by default */
.box-img-open   { opacity: 0; }

/* When the container has class "opened", swap which image shows */
.box-container.opened .box-img-closed { opacity: 0; }
.box-container.opened .box-img-open   { opacity: 1; animation: openPop 0.5s ease-out; }

@keyframes openPop {
  0%   { transform: scale(0.5) rotate(-10deg); }
  60%  { transform: scale(1.15) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

.box-container:hover .box-img { transform: scale(1.04) rotate(-2deg); }
.box-container:active .box-img { transform: scale(0.97); }

/* Light burst from inside the box when opening */
.box-burst {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 232, 160, 1) 0%, rgba(255, 204, 68, 0.8) 30%, rgba(255, 204, 68, 0) 70%);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
}
.box-container.opened .box-burst {
  animation: burst 0.8s ease-out;
}
@keyframes burst {
  0%   { width: 0; height: 0; opacity: 1; }
  100% { width: 400px; height: 400px; opacity: 0; }
}

/* Falls from above with a slight bounce */
@keyframes fallIn {
  0%   { transform: translateY(-300px) rotate(-20deg); opacity: 0; }
  60%  { transform: translateY(20px) rotate(8deg); opacity: 1; }
  80%  { transform: translateY(-10px) rotate(-4deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* Constant gentle floating idle motion */
@keyframes floatBox {
  0%, 100% { transform: translateY(0) rotate(0); }
  25%      { transform: translateY(-8px) rotate(-1.5deg); }
  50%      { transform: translateY(0) rotate(0); }
  75%      { transform: translateY(-4px) rotate(1.5deg); }
}

/* Quick sharp shake when clicked */
@keyframes shake {
  0%, 100% { transform: rotate(0) scale(1); }
  25%      { transform: rotate(-5deg) scale(1.02); }
  75%      { transform: rotate(5deg) scale(1.02); }
}

/* After opening, fade the open box away before showing reel */
@keyframes openBox {
  0%   { transform: scale(1) rotate(0); opacity: 1; }
  100% { transform: scale(1.5) rotate(0); opacity: 0; }
}

.box-sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.spark {
  position: absolute;
  font-size: 18px;
  opacity: 0;
  animation: sparkle 3s ease-in-out infinite;
  filter: drop-shadow(0 0 6px rgba(255, 232, 160, 0.8));
}
.spark.sp1 { top: 5%;   left: 10%; animation-delay: 0s; }
.spark.sp2 { top: 15%;  right: 8%; animation-delay: 0.6s; }
.spark.sp3 { bottom: 20%; left: 12%; animation-delay: 1.2s; }
.spark.sp4 { bottom: 8%; right: 14%; animation-delay: 1.8s; }
.spark.sp5 { top: 50%;  right: 20%; animation-delay: 2.4s; font-size: 14px; }
@keyframes sparkle {
  0%, 100% { opacity: 0; transform: scale(0.5); }
  50%      { opacity: 1; transform: scale(1.2); }
}
.tap-hint {
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 3px;
  animation: glow 1.5s ease-in-out infinite;
  white-space: nowrap;
}
@keyframes glow {
  0%, 100% { text-shadow: 0 0 8px rgba(255, 204, 68, 0.4); opacity: 0.7; }
  50%      { text-shadow: 0 0 16px rgba(255, 204, 68, 0.9); opacity: 1; }
}
/* Reel — case opening style */
.reel-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 180px;
  margin: auto 0;     /* same: center in remaining space */
}
.reel-pointer {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 22px solid var(--gold);
  filter: drop-shadow(0 0 12px rgba(255, 204, 68, 0.9));
  z-index: 3;
}
.reel-pointer::after {
  content: '';
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  height: 180px;
  background: linear-gradient(180deg, rgba(255, 204, 68, 0.9), transparent);
}
.reel-mask {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: var(--card-bg);
  border: 2px solid var(--gold);
  border-radius: 14px;
  box-shadow:
    0 0 50px rgba(255, 204, 68, 0.4),
    0 0 100px rgba(255, 204, 68, 0.15),
    inset 0 0 30px rgba(0, 0, 0, 0.7);
  -webkit-mask-image: linear-gradient(90deg, transparent, black 12%, black 88%, transparent);
          mask-image: linear-gradient(90deg, transparent, black 12%, black 88%, transparent);
}
.reel {
  display: flex;
  height: 100%;
  will-change: transform;
}
.reel-item {
  flex: 0 0 140px;
  width: 140px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
}
.reel-item::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent);
  z-index: 0;
}
.reel-item .icon {
  font-size: 48px;
  z-index: 1;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.7));
}
.reel-item .label {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.5px;
  z-index: 1;
  text-align: center;
}

.reel-item.common    .label { color: var(--r-common); }
.reel-item.uncommon  .label { color: var(--r-uncommon); }
.reel-item.rare      .label { color: var(--r-rare); }
.reel-item.epic      .label { color: var(--r-epic); }
.reel-item.legendary .label { color: var(--r-legendary); }
.reel-item.common::before    { background: linear-gradient(180deg, rgba(160, 160, 176, 0.15), transparent); }
.reel-item.uncommon::before  { background: linear-gradient(180deg, rgba(90, 160, 255, 0.18), transparent); }
.reel-item.rare::before      { background: linear-gradient(180deg, rgba(176, 106, 255, 0.22), transparent); }
.reel-item.epic::before      { background: linear-gradient(180deg, rgba(255, 106, 188, 0.25), transparent); }
.reel-item.legendary::before { background: linear-gradient(180deg, rgba(255, 204, 68, 0.3), transparent); }
/* Buttons */
.btn {
  width: 100%;
  max-width: 340px;
  padding: 14px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { border-color: rgba(255, 204, 68, 0.3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 40%, var(--gold-deep) 80%, var(--gold-shadow) 100%);
  border: 1px solid var(--gold);
  color: #1a0c00;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  box-shadow:
    0 4px 20px rgba(255, 204, 68, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
/* Result overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  backdrop-filter: blur(6px);
}
.overlay.visible { display: flex; }
.result-card {
  background: var(--card-bg);
  border: 2px solid var(--gold);
  border-radius: 18px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 50px rgba(255, 204, 68, 0.4), 0 20px 60px rgba(0, 0, 0, 0.9);
}
.result-card.legendary { border-color: var(--r-legendary); box-shadow: 0 0 80px rgba(255, 204, 68, 0.7); }
.result-card.epic      { border-color: var(--r-epic);      box-shadow: 0 0 60px rgba(255, 106, 188, 0.6); }
.result-card.rare      { border-color: var(--r-rare);      box-shadow: 0 0 50px rgba(176, 106, 255, 0.5); }
.result-card.uncommon  { border-color: var(--r-uncommon);  box-shadow: 0 0 40px rgba(90, 160, 255, 0.5); }
@keyframes popIn {
  0%   { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}
.prize-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}
.trophy {
  font-size: 64px;
  filter: drop-shadow(0 4px 14px rgba(255, 204, 68, 0.5));
}
.amount {
  font-size: 38px;
  font-weight: 900;
  background: linear-gradient(180deg, var(--gold-light), var(--gold), var(--gold-deep));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 204, 68, 0.4));
}
.promo-box {
  background: rgba(0, 0, 0, 0.5);
  border: 1px dashed var(--gold);
  border-radius: 10px;
  padding: 14px;
  margin: 8px 0;
}
.promo-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.promo-code {
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
}
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}
#codes-list {
  list-style: none;
  width: 100%;
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
}
#codes-list li {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
#codes-list li .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
#codes-list li .code {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  margin-top: 4px;
}
.toast {
  position: fixed;
  bottom: 30px; left: 50%;
  transform: translateX(-50%);
  background: rgba(5, 5, 12, 0.98);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  border: 1px solid var(--border);
  z-index: 2000;
}
.toast.show { opacity: 1; }

/* Reel pulses with subtle glow when spinning */
.reel-wrap.spinning .reel-mask {
  animation: reelPulse 0.5s ease-in-out infinite alternate;
}
@keyframes reelPulse {
  from { box-shadow: 0 0 50px rgba(255, 204, 68, 0.4), 0 0 100px rgba(255, 204, 68, 0.15), inset 0 0 30px rgba(0, 0, 0, 0.7); }
  to   { box-shadow: 0 0 70px rgba(255, 204, 68, 0.7), 0 0 140px rgba(255, 204, 68, 0.3), inset 0 0 30px rgba(0, 0, 0, 0.7); }
}