:root {
  --bg: #07070f;
  --panel: #11111e;
  --panel-2: #181828;
  --gold: #f5c542;
  --pink: #ff3d7f;
  --cyan: #2de2e6;
  --green: #2dff8a;
  --red: #ff4040;
  --text: #eaeaf2;
  --muted: #8a8aa3;
  --font-display: 'Orbitron', sans-serif;
  --font-body: 'Rajdhani', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#hud, #stage-bar, .game-card, #bigwin {
  -webkit-user-select: none;
  user-select: none;
}

#bg3d {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

#vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 61, 127, 0.08), transparent 55%),
    radial-gradient(ellipse at 50% 110%, rgba(45, 226, 230, 0.07), transparent 55%),
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) 14px calc(14px + env(safe-area-inset-left, 0px));
  background: linear-gradient(to bottom, rgba(7, 7, 15, 0.92), rgba(7, 7, 15, 0.55) 70%, transparent);
  pointer-events: none;
}
@media (min-width: 700px) {
  #hud { padding-left: 36px; padding-right: 36px; }
}
#hud > * { pointer-events: auto; }

#brand {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(18px, 3.4vw, 26px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 18px rgba(255, 61, 127, 0.55);
}
#brand span {
  color: var(--gold);
  text-shadow: 0 0 18px rgba(245, 197, 66, 0.8);
}

#bank { display: flex; align-items: center; gap: 10px; }

#bank-pill {
  display: flex;
  align-items: baseline;
  gap: 7px;
  background: var(--panel);
  border: 1px solid rgba(245, 197, 66, 0.45);
  border-radius: 999px;
  padding: 8px 18px;
  box-shadow: 0 0 22px rgba(245, 197, 66, 0.18), inset 0 0 14px rgba(245, 197, 66, 0.06);
  transition: transform 0.12s ease, box-shadow 0.25s ease;
}
#bank-pill.pulse {
  transform: scale(1.08);
  box-shadow: 0 0 38px rgba(245, 197, 66, 0.55), inset 0 0 18px rgba(245, 197, 66, 0.15);
}
#bank-pill.shake { animation: bank-shake 0.35s ease; border-color: var(--red); }
@keyframes bank-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

#balance {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(16px, 3vw, 22px);
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.chips-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
}

#refill {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #07070f;
  background: linear-gradient(135deg, var(--green), #1fd470);
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(45, 255, 138, 0.45);
  animation: refill-glow 1.4s ease-in-out infinite alternate;
}
@keyframes refill-glow {
  from { box-shadow: 0 0 12px rgba(45, 255, 138, 0.35); }
  to { box-shadow: 0 0 28px rgba(45, 255, 138, 0.7); }
}

/* ---------- Lobby ---------- */
#lobby {
  position: relative;
  z-index: 10;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(96px, 16vh, 150px) clamp(16px, 4vw, 40px) 48px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

#lobby-kicker {
  text-align: center;
  font-weight: 700;
  letter-spacing: 3px;
  font-size: clamp(10px, 2vw, 13px);
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(45, 226, 230, 0.6);
  margin-bottom: 10px;
}

#lobby-title {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(30px, 7vw, 58px);
  letter-spacing: 4px;
  background: linear-gradient(180deg, #fff 10%, var(--gold) 55%, #a87b1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(245, 197, 66, 0.35));
  margin-bottom: clamp(28px, 6vh, 54px);
}

#game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: clamp(14px, 2.5vw, 24px);
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 26px 22px 22px;
  background: linear-gradient(160deg, var(--panel-2), var(--panel) 70%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 12%, var(--accent, var(--gold)) 0%, transparent 45%);
  opacity: 0.12;
  transition: opacity 0.2s ease;
}
.game-card:hover, .game-card:focus-visible {
  transform: translateY(-5px) scale(1.015);
  border-color: var(--accent, var(--gold));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 28px color-mix(in srgb, var(--accent, var(--gold)) 35%, transparent);
}
.game-card:hover::before { opacity: 0.25; }
.game-card:active { transform: translateY(-2px) scale(0.99); }

.gc-icon { font-size: 38px; filter: drop-shadow(0 0 12px var(--accent, var(--gold))); }
.gc-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(15px, 2.4vw, 19px);
  letter-spacing: 1.5px;
}
.gc-tagline { color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: 0.5px; }
.gc-play {
  margin-top: 10px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent, var(--gold));
}

#lobby-footer {
  margin-top: auto;
  padding-top: 42px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
}

/* ---------- Stage ---------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: rgba(7, 7, 15, 0.97);
}
#stage[hidden] { display: none; }

#stage-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) clamp(12px, 3vw, 28px) 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(17, 17, 30, 0.85);
}
#stage-bar-spacer { width: 86px; }

#back {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--cyan);
  background: transparent;
  border: 1px solid rgba(45, 226, 230, 0.5);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
#back:hover { background: rgba(45, 226, 230, 0.12); box-shadow: 0 0 16px rgba(45, 226, 230, 0.35); }

#game-title {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(13px, 3vw, 18px);
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(245, 197, 66, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#game-root {
  position: relative;
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.loading, .game-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}
.game-error { color: var(--red); }
.game-error small { font-family: var(--font-body); letter-spacing: 0.5px; color: var(--muted); }

/* ---------- Big win overlay ---------- */
#bigwin {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 7, 15, 0.55);
  pointer-events: none;
}
#bigwin[hidden] { display: none; }

.bw-inner { text-align: center; animation: bw-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes bw-pop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.bw-text {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(44px, 11vw, 110px);
  letter-spacing: 6px;
  background: linear-gradient(180deg, #fff 5%, var(--gold) 50%, #b8860b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 35px rgba(245, 197, 66, 0.8));
  animation: bw-throb 0.6s ease-in-out infinite alternate;
}
@keyframes bw-throb {
  from { filter: drop-shadow(0 0 20px rgba(245, 197, 66, 0.6)); }
  to { filter: drop-shadow(0 0 50px rgba(245, 197, 66, 1)); }
}

.bw-amount {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(24px, 6vw, 52px);
  letter-spacing: 3px;
  color: var(--green);
  text-shadow: 0 0 24px rgba(45, 255, 138, 0.8);
  margin-top: 8px;
}

.bw-coin {
  position: fixed;
  top: -60px;
  font-size: 32px;
  z-index: 91;
  pointer-events: none;
  animation: coin-fall linear forwards;
}
@keyframes coin-fall {
  to { transform: translateY(115vh) rotate(720deg); }
}

@media (max-width: 560px) {
  #stage-bar-spacer { display: none; }
  .gc-icon { font-size: 32px; }
}
