/* ═══════════════════════════════════════════════════
   MoneySpread – Design System & Layout
   ═══════════════════════════════════════════════════ */

/* ── Tokens ── */
:root {
  /* Color Palette */
  --color-bg-base: #080710;
  --color-bg-hud: rgba(6, 9, 20, 0.85);
  --color-bg-stage-top: #0a1129;
  --color-bg-stage-mid: #050613;
  --color-bg-stage-bot: #02020a;
  --color-bg-stake: rgba(9, 10, 24, 0.95);
  --color-surface: rgba(255, 255, 255, 0.04);
  --color-surface-hover: rgba(255, 255, 255, 0.08);
  --color-glass: rgba(255, 255, 255, 0.06);
  --color-glass-border: rgba(166, 186, 237, 0.2);

  /* Accents – Gold Palette */
  --color-primary: #e8b94e;
  --color-primary-dim: rgba(232, 185, 78, 0.2);
  --color-primary-glow: rgba(232, 185, 78, 0.4);
  --color-secondary: #ffa4d6;
  --color-accent: #d93cff;
  --color-success: #39ff14;
  --color-success-dim: rgba(57, 255, 20, 0.2);

  /* Typography */
  --color-text: #f8f9ff;
  --color-text-dim: #9aa0b8;
  --font-main: 'Outfit', system-ui, sans-serif;

  /* Sizing Constraints */
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 2px;
  --radius-pill: 9999px;

  /* Card Metrics */
  --card-w: min(22vw, 90px);
  --card-h: calc(var(--card-w) * (1024 / 493));
  /* Currency note exact aspect ratio based on 1024x493 */

  /* Misc */
  --btn-spread-size: clamp(110px, 20vw, 140px);
  --transition-fast: 0.15s ease-out;
  --transition-base: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg-base);
  color: var(--color-text);
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ═══════════ LOADING SCREEN ═══════════ */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-base);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}

#loader-logo {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 40px;
  position: relative;
  z-index: 2;
}

.logo-money {
  color: var(--color-text);
}

.logo-spread {
  color: var(--color-primary);
}

#loader-ring {
  position: relative;
  width: 260px;
  height: 260px;
}

#loader-tagline {
  margin-top: 36px;
  font-size: 0.95rem;
  color: var(--color-text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: fadeInUp 0.6s ease both 0.3s;
}

/* loader cards */
.loader-card {
  position: absolute;
  width: 45px;
  height: calc(45px * (1024 / 493));
  border-radius: 0;
  background: linear-gradient(135deg, #130f24 0%, #1b1633 100%);
  border: 0px solid var(--color-primary);
  box-shadow: 0 0 0px var(--color-primary-dim);
  left: 50%;
  top: 50%;
  transform-origin: center center;
  overflow: hidden;
}

/* ═══════════ GAME SCREEN ═══════════ */
#game-screen {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  position: relative;
}

/* ── UNIFIED HEADER (Shared with Lobby) ── */
#lobby-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 5vw;
  background: var(--color-bg-hud);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-glass-border);
  z-index: 100;
}

#lobby-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

#btn-back-lobby {
  background: var(--color-glass);
  border: 1px solid var(--color-glass-border);
  color: var(--color-text-dim);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all var(--transition-fast);
}

#btn-back-lobby:hover {
  background: var(--color-primary-dim);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.profile-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-glass);
  border: 1px solid var(--color-glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-dim);
}

.profile-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  display: none;
}

@media (min-width: 768px) {
  .profile-name { display: block; }
}

#lobby-logo {
  font-size: clamp(1.1rem, 3.8vw, 1.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

#lobby-balance-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

#lobby-balance-box {
  background: rgba(232, 185, 78, 0.05);
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-md);
  padding: 2px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.balance-label {
  font-size: 0.5rem;
  letter-spacing: 0.12em;
  color: var(--color-text-dim);
}

#lobby-balance-value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--color-primary);
}

#lobby-deposit-btn {
  background: var(--color-primary);
  color: #000;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── UNIFIED GAME AREA ── */
#game-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 4vh 3vw;
  background: linear-gradient(155deg, var(--color-bg-stage-top), var(--color-bg-stage-mid), var(--color-bg-stage-bot));
  z-index: 91;
  perspective: 1000px;
}

#game-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(232, 185, 78, 0.05), transparent 60%);
  pointer-events: none;
}

/* 1. Deck Container */
#deck-container {
  position: relative;
  z-index: 2;
  width: min(80vw, 380px);
  aspect-ratio: 1.1;
  /* slightly wider space for the deck */
  max-height: 48vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Game Cards */
.game-card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  cursor: default;
  pointer-events: none;
  transition: transform var(--transition-base), opacity var(--transition-base);
}

.game-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--transition-bounce);
}

.game-card.flipped .game-card-inner {
  transform: rotateY(180deg);
}

.game-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Card Back */
.card-back {
  background: linear-gradient(145deg, #1b1429, #0a0714);
  border: 1px solid #00d9ff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.card-back::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 4px;
  border: 1px solid rgba(0, 217, 255, 0.2);
  background: repeating-linear-gradient(45deg,
      transparent, transparent 4px,
      rgba(0, 217, 255, 0.05) 4px,
      rgba(0, 217, 255, 0.05) 8px);
}

/* Card Front */
.card-front {
  transform: rotateY(180deg);
  font-weight: 700;
}

.card-front.currency {
  background: linear-gradient(135deg, #071f10, #020a05);
  border: 1px solid var(--color-success);
  box-shadow: 0 0 20px var(--color-success-dim);
}

.card-front.currency .card-value {
  font-size: min(1.8rem, 6vw);
  color: var(--color-success);
  line-height: 1;
}

.card-front.currency .card-label {
  font-size: 0.5rem;
  color: var(--color-success);
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
}

.card-front.currency .card-icon {
  font-size: min(2rem, 8vw);
  margin-bottom: 2px;
}

.card-front.joker {
  background: linear-gradient(135deg, #1d0729, #0a0210);
  border: 1px solid var(--color-secondary);
  box-shadow: 0 0 15px rgba(255, 164, 214, 0.15);
}

.card-front.joker .card-icon {
  font-size: min(2.5rem, 9vw);
}

.card-front.joker .card-label {
  font-size: 0.6rem;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 4px;
}

/* Shimmer Overlays */
.card-front.currency::before,
.card-front.joker::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.card-front.currency::before {
  background: linear-gradient(120deg, transparent 30%, rgba(57, 255, 20, 0.15) 50%, transparent 70%);
  animation: shimmerReveal 2.5s ease infinite;
}

.card-front.joker::before {
  background: linear-gradient(120deg, transparent 30%, rgba(255, 0, 127, 0.1) 50%, transparent 70%);
  animation: shimmerReveal 3s steps(6) infinite reverse;
}

/* Dynamic Fan Reveal Classes */
.dynamic-fan-card {
  --fan-delay: 0s;
  animation: cardFlyIn 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) var(--fan-delay) backwards;
  top: calc(50% - (var(--card-h) / 2));
  left: calc(50% - (var(--card-w) / 2));
  transform-origin: 50% 250%;
  transition: transform 0.25s var(--transition-bounce), filter 0.2s;
}



#spread-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* 2. Spread Button (Modern & Cool with Indicator) */
#spread-btn {
  position: relative;
  width: var(--btn-spread-size);
  height: var(--btn-spread-size);
  border-radius: var(--radius-pill);
  border: none;
  background: radial-gradient(circle at 50% 30%, #151b2e 0%, #02020a 100%);
  color: var(--color-primary);
  cursor: pointer;
  z-index: 1002;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.6),
    inset 0 0 20px rgba(232, 185, 78, 0.05);
  transition: transform var(--transition-bounce), box-shadow var(--transition-fast), filter 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  overflow: visible;
  /* Let the indicator shine */
}

/* Dynamic Split-Oval Choice UI */
#choice-ui {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: auto;
  height: auto;
  pointer-events: none;
  z-index: 10000; /* Extremely high */
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

#choice-ui:not(.hidden) {
  pointer-events: auto;
}

#choice-ui.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.8);
  pointer-events: none;
}

#choice-oval {
  display: flex !important;
  align-items: stretch !important;
  background: #111 !important; /* solid for debug */
  border: 2px solid #e8b94e !important;
  border-radius: 50px;
  width: 320px !important; 
  height: 90px !important; /* fixed for debug */
  overflow: visible !important; /* disable clipping */
  box-shadow: 0 0 30px rgba(232, 185, 78, 0.4);
}

.oval-half {
  position: relative;
  flex: 1;
  background: transparent !important;
  border: none;
  color: #fff !important;
  cursor: pointer;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 10px;
  min-width: 140px;
  z-index: 10001;
}

.oval-half:hover {
  background: rgba(255, 255, 255, 0.06);
}

.oval-half.left:hover {
  background: rgba(0, 255, 204, 0.05);
}

.oval-half.right:hover {
  background: rgba(232, 185, 78, 0.05);
}

.oval-half:active {
  transform: scale(0.96);
}

.oval-divider {
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(232, 185, 78, 0.5), transparent);
  margin: 12px 0;
}

.bubble-label {
  display: block !important;
  font-size: 0.7rem !important;
  font-weight: 800 !important;
  letter-spacing: 0.15em !important;
  color: #ffffff !important;
  text-transform: uppercase !important;
  margin-bottom: 4px !important;
  line-height: 1 !important;
}

#current-win-amount {
  display: block !important;
  font-size: 1.2rem !important;
  font-weight: 900 !important;
  color: #e8b94e !important;
  text-shadow: 0 0 10px rgba(232, 185, 78, 0.6) !important;
}

.bubble-sub {
  display: block !important;
  font-size: 0.8rem !important;
  font-weight: 800 !important;
  color: #e8b94e !important;
  text-shadow: 0 0 8px rgba(232, 185, 78, 0.5) !important;
}

.spread-indicator {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  pointer-events: none;
  transform: rotate(-90deg);
  /* Start from top */
  z-index: -1;
  filter: drop-shadow(0 0 8px var(--color-primary-dim));
}

#spread-btn .btn-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
}

#spread-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8), 0 0 15px var(--color-primary-dim);
  filter: brightness(1.1);
}

#spread-btn:not(:disabled) {
  animation: none;
  /* remove old pulse */
}

#spread-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.8);
  background: #0d1017;
  color: var(--color-text-dim);
}

#spread-btn-label {
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  font-weight: 800;
  letter-spacing: 0.15em;
  text-shadow: 0 0 10px rgba(232, 185, 78, 0.4);
}

#spread-btn-count {
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.7;
  margin-top: 4px;
  letter-spacing: 0.05em;
}

/* 3. Stake Container (Hidden in auto-start mode) */
#stake-container.auto-hide,
#spread-btn.auto-hide {
  display: none !important;
}

#stake-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  z-index: 90;
  margin-top: 45px;
  /* Added healthy margin */
}

/* Input Row */
#stake-input-row {
  display: flex;
  align-items: center;
  width: min(100%, 300px);
  background: var(--color-surface);
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-pill);
  padding: 10px 20px;
  margin-bottom: 16px;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

#stake-input-row:focus-within {
  border-color: var(--color-primary);
  background: var(--color-surface-hover);
  box-shadow: 0 0 12px var(--color-primary-dim);
}

.currency-prefix {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-primary);
  user-select: none;
  margin-right: 8px;
}

#stake-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 1.1rem;
  font-weight: 600;
  width: 100%;
}

#stake-input::placeholder {
  color: var(--color-text-dim);
  font-weight: 400;
}

/* Betting Chips */
#stake-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 400px;
}

.chip {
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-glass-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip:hover {
  background: var(--color-primary-dim);
  border-color: var(--color-primary);
  transform: translateY(-2px);
}

.chip.active {
  background: var(--color-primary-glow);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 0 15px var(--color-primary-dim);
}

/* ── NON-BLOCKING RESULT TOAST ── */
#spread-result-toast {
  position: absolute;
  right: -120%;
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-glass-border);
  border-left: 4px solid var(--color-primary);
  padding: 16px 24px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  box-shadow: -5px 10px 30px rgba(0, 0, 0, 0.4);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  transition: right var(--transition-bounce);
  z-index: 2000;
}

#spread-result-toast.show {
  right: 0;
}

#spread-result-toast.win {
  border-left-color: var(--color-success);
  color: var(--color-success);
}

#spread-result-toast.lose {
  border-left-color: var(--color-text-dim);
  color: var(--color-text-dim);
}

/* ═══════════ GLOBALLY USED KEYFRAMES ═══════════ */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardFlyIn {
  0% {
    opacity: 0;
    rotate: 45deg;
    transform: translateX(50vw) translateY(-50vh) rotate(5deg);
  }

  40% {
    opacity: 1;
  }

  75%,
  100% {
    transform: translateX(0) translateY(0) rotate(0);
  }
}

@keyframes balancePulse {
  0% {
    transform: scale(1);
    color: var(--color-success);
  }

  50% {
    transform: scale(1.1);
    color: var(--color-success);
  }

  100% {
    transform: scale(1);
    color: var(--color-primary);
  }
}

@keyframes glowPulse {
  0% {
    box-shadow: 0 0 20px var(--color-primary-dim);
  }

  50% {
    box-shadow: 0 0 35px var(--color-primary-glow);
  }

  100% {
    box-shadow: 0 0 20px var(--color-primary-dim);
  }
}

@keyframes shimmerReveal {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

/* For confetti elements generated in JS */
.confetti {
  position: fixed;
  top: -10px;
  z-index: 2000;
  transform-origin: center center;
  animation: confettiFall var(--fall-dur) linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

/* ═══════════ RESPONSIVE REFINEMENTS ═══════════ */
@media (max-width: 768px) {
  :root {
    --card-w: min(18vw, 85px);
    --btn-spread-size: clamp(115px, 22vw, 140px);
  }

  .dynamic-fan-card {
    transform-origin: 50% 160%;
  }

  #deck-container {
    width: 95vw;
  }
}

@media (max-width: 480px) {
  :root {
    --card-w: min(16vw, 75px);
    --btn-spread-size: clamp(105px, 20vw, 125px);
  }

  .dynamic-fan-card {
    transform-origin: 50% 125%;
  }

  #deck-container {
    width: 100vw;
  }
}