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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-ar);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

#game {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

#scene-container {
  position: absolute;
  inset: 0;
  top: var(--hud-height);
  bottom: var(--tab-height);
}

#scene-container.game-mode {
  top: 0;
  bottom: 0;
}

#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--hud-height);
  padding-top: var(--safe-top);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: var(--s-4);
  background: var(--bg-base);
  border-bottom: 1px solid var(--border);
  transition: transform var(--dur-normal) var(--ease-out);
}

#hud.hidden { transform: translateY(-100%); }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#overlay.active { pointer-events: all; background: rgba(0,0,0,0.7); }

#toast-container {
  position: fixed;
  top: calc(var(--hud-height) + var(--s-2));
  left: 50%; transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hover);
  border-radius: var(--r-lg);
  padding: var(--s-3) var(--s-4);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: all;
}

.toast.out { animation: toastOut 0.2s ease-in forwards; }
.toast.reward { background: linear-gradient(135deg, #1a2440, #2a1a40); border-color: var(--gold); }
.toast.error { border-color: var(--error); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-30px) scale(0.8); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-15px) scale(0.9); } }

/* Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tab-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-base);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  transition: transform var(--dur-normal) var(--ease-out);
}

.tab-bar.hidden { transform: translateY(100%); }

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--dur-fast), transform var(--dur-fast);
}

.tab-item:active { transform: scale(0.9); }
.tab-item.active { color: var(--gold); }
.tab-item.active .tab-icon { filter: drop-shadow(0 0 6px var(--gold)); }

.tab-icon {
  width: 24px; height: 24px;
  fill: currentColor;
}

/* Scene transitions - game feel */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.scene-enter { animation: sceneIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.scene-exit { animation: sceneOut 0.15s ease-in forwards; }

@keyframes sceneIn { 0% { opacity: 0; transform: scale(0.88); } 60% { opacity: 1; transform: scale(1.02); } 100% { transform: scale(1); } }
@keyframes sceneOut { to { opacity: 0; transform: scale(1.05); } }

/* Cards */
.card {
  background: var(--bg-card);
  border: var(--card-border-width, 1px) solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-4);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-spring), box-shadow var(--dur-fast);
}

.card:active { transform: scale(0.96); box-shadow: var(--shadow-md); transition-duration: 80ms; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  border: none;
  border-radius: var(--r-full, 9999px);
  font-family: var(--font-ar);
  font-size: 15px;
  font-weight: var(--btn-weight, 700);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-spring), box-shadow var(--dur-fast);
  min-height: var(--btn-min-height, 44px);
}

.btn:active { transform: scale(var(--btn-press-scale, 0.92)); transition-duration: 50ms; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  color: #1a1a1a;
  box-shadow: var(--btn-shadow, 0 4px 16px rgba(228,172,56,0.3));
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: var(--card-border-width, 1px) solid var(--border-hover);
  border-radius: var(--r-btn-secondary, var(--r-full, 9999px));
}

.btn-game {
  background: linear-gradient(135deg, var(--game-primary, var(--blue)), var(--game-secondary, var(--cyan)));
  color: white;
  box-shadow: 0 4px 16px rgba(32,130,240,0.3);
  font-size: 18px;
  padding: var(--s-4) var(--s-8);
}

/* Inputs */
.input {
  width: 100%;
  padding: var(--s-3) var(--s-4);
  background: var(--bg-elevated);
  border: var(--card-border-width, 1px) solid var(--border);
  border-radius: var(--r-input, var(--r-md));
  color: var(--text-primary);
  font-family: var(--font-ar);
  font-size: 15px;
  outline: none;
  transition: border-color var(--dur-fast);
  min-height: var(--btn-min-height, 44px);
}

.input:focus { border-color: var(--gold); }
.input::placeholder { color: var(--text-muted); }

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.text-center { text-align: center; }
.text-gold { color: var(--gold); }
.text-secondary { color: var(--text-secondary); }
.w-full { width: 100%; }
.p-4 { padding: var(--s-4); }
.mt-4 { margin-top: var(--s-4); }

/* HUD elements */
.hud-brand {
  font-size: 20px;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: -0.5px;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-lat);
}

.hud-stat .icon { width: 16px; height: 16px; }
.hud-coins { color: var(--gold); }
.hud-gems { color: var(--purple); }
.hud-level { color: var(--cyan); }

.hud-actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.hud-btn {
  position: relative;
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-secondary);
  transition: transform var(--dur-fast);
}

.hud-btn:active { transform: scale(0.9); }

.hud-badge {
  position: absolute;
  top: -2px; right: -2px;
  width: 16px; height: 16px;
  background: var(--orange);
  border-radius: var(--r-full);
  font-size: 9px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud-badge:empty { display: none; }

/* Loading / Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-md);
}

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

/* ========= JUICE SYSTEM ========= */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 5px var(--gold); } 50% { box-shadow: 0 0 20px var(--gold); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-2px); } 80% { transform: translateX(2px); } }
@keyframes popIn { 0% { transform: scale(0); opacity: 0; } 60% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }
@keyframes slamIn { 0% { transform: scale(1.5); opacity: 0; } 60% { transform: scale(0.92); opacity: 1; } 80% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideUpBounce { 0% { transform: translateY(100%); } 70% { transform: translateY(-3%); } 100% { transform: translateY(0); } }
@keyframes bounceIn { 0% { transform: scale(0.3); opacity: 0; } 50% { transform: scale(1.08); } 70% { transform: scale(0.96); } 100% { transform: scale(1); opacity: 1; } }
@keyframes breatheGlow { 0%, 100% { box-shadow: 0 0 6px rgba(228,172,56,0.15); } 50% { box-shadow: 0 0 20px rgba(228,172,56,0.4); } }
@keyframes bgGradientMove { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@keyframes numberPop { 0% { transform: scale(1); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes ringExpand { 0% { transform: scale(0.5); opacity: 1; } 100% { transform: scale(2.5); opacity: 0; } }
@keyframes wobble { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
@keyframes shimmerBorder { 0% { border-color: rgba(228,172,56,0.1); } 50% { border-color: rgba(228,172,56,0.3); } 100% { border-color: rgba(228,172,56,0.1); } }

.pulse { animation: pulse 2s ease-in-out infinite; }
.float { animation: float 3s ease-in-out infinite; }
.shake { animation: shake 0.3s ease; }
.pop-in { animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.slam-in { animation: slamIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
.bounce-in { animation: bounceIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
.slide-up { animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.slide-up-bounce { animation: slideUpBounce 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.breathe-glow { animation: breatheGlow 2.5s ease-in-out infinite; }
.wobble { animation: wobble 0.5s ease; }
.number-pop { animation: numberPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* Ambient background — subtle alive gradient */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(228,172,56,0.03) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(32,130,240,0.02) 0%, transparent 50%);
  background-size: 200% 200%;
  animation: bgGradientMove 25s ease infinite;
  pointer-events: none;
  z-index: 0;
}

/* Primary buttons breathe when idle */
.btn-primary { animation: breatheGlow 2.5s ease-in-out infinite; }
.btn-primary:active { animation: none; }

/* Performance hints */
.btn, .card, .game-tile { will-change: transform; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 2px; }
