/* Level themes animate through these registered colors. */
@property --c1 { syntax: '<color>'; inherits: true; initial-value: #14072e; }
@property --c2 { syntax: '<color>'; inherits: true; initial-value: #5b21b6; }
@property --accent { syntax: '<color>'; inherits: true; initial-value: #c4a1ff; }

:root {
  --c1: #14072e;
  --c2: #5b21b6;
  --accent: #c4a1ff;
  --gold: #ffd24a;
  --ink: #fff;
  --soft: rgba(255, 255, 255, 0.62);
  --glass: rgba(255, 255, 255, 0.09);
  --glass-edge: rgba(255, 255, 255, 0.16);
  --font: "SF Pro Rounded", ui-rounded, "Nunito", "Varela Round", system-ui, -apple-system, sans-serif;
  transition: --c1 0.9s ease, --c2 0.9s ease, --accent 0.9s ease;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--c1);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---- Backdrop: theme gradient, slow sunburst, vignette ------------------ */
#bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(110% 75% at 50% 42%, var(--c2) 0%, var(--c1) 72%);
}
#bg::before {
  content: "";
  position: absolute;
  left: 50%; top: 42%;
  width: 220vmax; height: 220vmax;
  translate: -50% -50%;
  background: repeating-conic-gradient(rgba(255, 255, 255, 0.055) 0deg 9deg, transparent 9deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 42%);
  mask-image: radial-gradient(circle, #000 0%, transparent 42%);
  animation: spin 90s linear infinite;
}
#bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 90% at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
}
@keyframes spin { to { rotate: 360deg; } }

/* ---- Layout -------------------------------------------------------------- */
#app {
  position: relative;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  gap: 10px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 19px;
  letter-spacing: 0.06em;
}
.brand svg { width: 22px; height: 22px; color: var(--gold); filter: drop-shadow(0 0 8px rgba(255, 210, 74, 0.5)); }
.brand b { color: var(--accent); margin-left: 3px; }

.top-right { display: flex; align-items: center; gap: 8px; }
.tickets {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.tickets svg { width: 22px; height: 22px; color: var(--gold); }
.tickets b { font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; min-width: 1.4em; }
.tickets.bump { animation: bump 0.45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 40% { transform: scale(1.18); } }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .mute { display: none; }
.icon-btn.off .mute { display: inline; }
.icon-btn.off .wave { display: none; }
.icon-btn.off { color: var(--soft); }

/* ---- Progress pips ------------------------------------------------------- */
.progress { padding: 4px 2px 0; }
.meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 900;
  letter-spacing: 0.1em;
  font-size: 13px;
  margin-bottom: 8px;
}
#lvlName { color: var(--ink); }
#prize { color: var(--gold); }
#pips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(9, 1fr) 1.6fr;
  gap: 5px;
}
#pips li {
  height: 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: background 0.35s, box-shadow 0.35s;
}
#pips li.done { background: var(--accent); box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent); }
#pips li.current { background: #fff; animation: blinkpip 0.9s ease-in-out infinite alternate; }
#pips li.jackpot { background: linear-gradient(90deg, #b8860b, var(--gold)); opacity: 0.45; }
#pips li.jackpot.current, #pips li.jackpot.done { opacity: 1; box-shadow: 0 0 14px rgba(255, 210, 74, 0.8); animation: none; }
@keyframes blinkpip { from { opacity: 0.45; } to { opacity: 1; } }

/* ---- Stage --------------------------------------------------------------- */
#stage { flex: 1; min-height: 0; position: relative; }
#ring { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#banner {
  text-align: center;
  font-weight: 900;
  font-size: clamp(18px, 5.2vw, 24px);
  letter-spacing: 0.12em;
  min-height: 1.3em;
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
#banner.pop { animation: pop 0.5s cubic-bezier(.3, 1.6, .5, 1); }
#banner.win { color: var(--gold); }
#banner.lose { color: #ff6b81; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

/* ---- Big button ---------------------------------------------------------- */
.controls { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#hit {
  width: min(78vw, 340px);
  height: clamp(72px, 11dvh, 92px);
  border: 0;
  border-radius: 999px;
  font-size: clamp(26px, 7vw, 32px);
  font-weight: 900;
  letter-spacing: 0.2em;
  padding-left: 0.2em;
  color: color-mix(in srgb, var(--accent) 22%, #120020);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 52%),
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 75%, #fff), var(--accent));
  box-shadow:
    0 9px 0 color-mix(in srgb, var(--accent) 48%, #000),
    0 20px 34px rgba(0, 0, 0, 0.38),
    inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.06s, box-shadow 0.06s;
}
#hit:active, #hit.pressed {
  transform: translateY(7px);
  box-shadow:
    0 2px 0 color-mix(in srgb, var(--accent) 48%, #000),
    0 8px 18px rgba(0, 0, 0, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
#hit:focus-visible { outline: 3px solid #fff; outline-offset: 6px; }
.hint { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--soft); }

/* ---- Overlay card -------------------------------------------------------- */
#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 20px;
  background: rgba(8, 2, 20, 0.45);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0s 0.3s;
}
#overlay.show { opacity: 1; visibility: visible; transition: opacity 0.3s; }
.card {
  width: min(100%, 360px);
  text-align: center;
  padding: 30px 24px 24px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transform: translateY(16px) scale(0.96);
  transition: transform 0.4s cubic-bezier(.3, 1.4, .5, 1);
}
#overlay.show .card { transform: none; }
.card-lock { width: 88px; height: 88px; margin: -4px auto 10px; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.4)); }
.card-lock svg { width: 100%; height: 100%; overflow: visible; }
#cardShackle { transition: transform 0.5s cubic-bezier(.3, 1.6, .5, 1); }
#overlay.open #cardShackle { transform: translateY(-9px); }
#overlay.show .card-lock { animation: wobble 2.4s ease-in-out 0.5s infinite; }
@keyframes wobble { 0%, 80%, 100% { rotate: 0deg; } 85% { rotate: -8deg; } 90% { rotate: 7deg; } 95% { rotate: -4deg; } }

.kicker { font-size: 12px; font-weight: 900; letter-spacing: 0.24em; color: var(--accent); }
#ovTitle {
  margin: 6px 0 8px;
  font-size: clamp(36px, 11vw, 46px);
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}
#overlay.jackpot #ovTitle {
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 210, 74, 0.6), 0 4px 0 #a8650a;
}
#ovBody { margin: 0 0 18px; color: var(--soft); font-weight: 600; font-size: 15px; line-height: 1.45; }
.ov-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.ov-stats div { padding: 10px 6px; border-radius: 16px; background: rgba(0, 0, 0, 0.22); }
.ov-stats small { display: block; font-size: 11px; font-weight: 900; letter-spacing: 0.18em; color: var(--soft); }
.ov-stats b { font-size: 26px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
#ovPlay {
  width: 100%;
  height: 62px;
  border: 0;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.18em;
  color: #2a1600;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 55%), linear-gradient(180deg, #ffe27a, #f2a91a);
  box-shadow: 0 7px 0 #a8650a, 0 16px 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.06s, box-shadow 0.06s;
}
#ovPlay:active { transform: translateY(6px); box-shadow: 0 1px 0 #a8650a, 0 8px 16px rgba(0, 0, 0, 0.3); }

@media (max-height: 680px) {
  .hint { display: none; }
  .card-lock { width: 64px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  #bg::before, #overlay.show .card-lock, #pips li.current { animation: none; }
}
