*, *::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%); }

.hud-profile {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  min-width: 44px;
  min-height: 44px;
}

.hud-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform var(--dur-fast) var(--ease-spring);
}

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

.hud-level-badge {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gold);
  color: #1a1a1a;
  font-size: 9px;
  font-weight: 800;
  font-family: var(--font-lat);
  min-width: 16px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  border-radius: var(--r-full);
  padding: 0 3px;
}

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

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

.hud-stat .icon { display: flex; align-items: center; }
.hud-stat.hud-coins { color: var(--gold); }
.hud-stat.hud-gems { color: var(--purple); }

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

.hud-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform var(--dur-fast) var(--ease-spring);
}

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

.hud-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  background: var(--orange);
  color: white;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-lat);
  border-radius: var(--r-full);
  text-align: center;
  padding: 0 4px;
  display: none;
}

.hud-badge:not(:empty) { display: block; }

#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: 3px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--dur-fast), transform var(--dur-fast);
  min-width: 48px;
  min-height: 48px;
  justify-content: center;
}

.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); } }

/* Profile Avatar */
.profile-avatar-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  margin: 0 auto;
  cursor: pointer;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 3px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  overflow: hidden;
  transition: transform var(--dur-fast) var(--ease-spring);
}

.profile-avatar-wrap:active .profile-avatar { transform: scale(0.93); }

.profile-avatar-edit {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card);
}

/* 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); }


/* 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; }

/* Native App Mode */
.native-app .bottom-nav { display: none !important; }
.native-app .tab-bar { padding-bottom: calc(var(--safe-bottom) + 8px); }
