/* ============================================
   Melon Fruits By Sisda Games
   Custom Game Styles
   ============================================ */

/* ============================================
   KEYFRAME ANIMATIONS
   ============================================ */

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 5px rgba(34, 197, 94, 0.3); }
  50% { box-shadow: 0 0 20px rgba(34, 197, 94, 0.6); }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-80px) scale(0.5); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes melonSpawn {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  60% { transform: scale(1.1) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes melonHarvest {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); }
  100% { transform: scale(0) translateY(-50px); opacity: 0; }
}

@keyframes scoreFloat {
  0% { transform: translateY(0); opacity: 1; font-size: 1rem; }
  100% { transform: translateY(-60px); opacity: 0; font-size: 1.5rem; }
}

@keyframes eventSlide {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes progressBar {
  from { width: 100%; }
  to { width: 0%; }
}

@keyframes sparkle {
  0%, 100% { opacity: 0; transform: scale(0); }
  50% { opacity: 1; transform: scale(1); }
}

/* ============================================
   BASE & SCREEN TRANSITIONS
   ============================================ */

.screen {
  animation: fadeIn 0.3s ease-in;
}

.screen.hidden {
  display: none !important;
}

/* Login and results use flex centering, others use block */
#screen-login,
#screen-results {
  display: flex;
}

#screen-menu,
#screen-leaderboard,
#screen-market {
  display: block;
}

/* ============================================
   LOADING SCREEN
   ============================================ */

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ============================================
   GAME CARDS (Menu)
   ============================================ */

.game-card {
  position: relative;
  overflow: hidden;
}

.game-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
  z-index: 1;
}

.game-card:hover::before {
  left: 100%;
}

/* ============================================
   HARVEST GAME ELEMENTS
   ============================================ */

.melon-item {
  position: absolute;
  cursor: pointer;
  user-select: none;
  animation: melonSpawn 0.4s ease-out;
  transition: transform 0.1s ease;
  font-size: 3rem;
  filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.2));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.melon-item:hover {
  transform: scale(1.15);
  filter: drop-shadow(2px 4px 10px rgba(0,0,0,0.3));
}

.melon-item:active {
  transform: scale(0.9);
}

.melon-item.harvested {
  animation: melonHarvest 0.3s ease-out forwards;
  pointer-events: none;
}

.score-popup {
  position: absolute;
  font-weight: 700;
  color: #16a34a;
  pointer-events: none;
  animation: scoreFloat 0.8s ease-out forwards;
  z-index: 100;
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.score-popup.bonus {
  color: #f59e0b;
  font-size: 1.3rem;
}

/* Ground/Farm visual */
#harvest-field::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(to top, #4ade80, #86efac, transparent);
  border-radius: 0 0 1rem 1rem;
  pointer-events: none;
  z-index: 0;
}

/* Ensure harvest container fills space */
#harvest-melons-container {
  position: absolute !important;
  overflow: hidden;
  touch-action: none;
}

#game-harvest,
#game-truck,
#game-market {
  width: 100%;
}

#game-area {
  width: 100%;
  min-height: 0;
}

/* ============================================
   BRIX GAME ELEMENTS (removed - replaced by Truck)
   ============================================ */

/* ============================================
   TRUCK RUN GAME ELEMENTS
   ============================================ */

.truck-item {
  position: absolute;
  width: 55px;
  text-align: center;
  pointer-events: none;
  transition: top 0s linear;
  z-index: 5;
}

.truck-item-good {
  background: rgba(255,255,255,0.9);
  border-radius: 0.5rem;
  padding: 2px;
  border: 2px solid #22c55e;
}

.truck-item-bonus {
  background: rgba(255,255,200,0.95);
  border-radius: 0.5rem;
  padding: 2px;
  border: 2px solid #eab308;
  animation: pulseGlow 1s infinite;
}

.truck-item-obstacle {
  background: rgba(255,100,100,0.85);
  border-radius: 0.5rem;
  padding: 2px;
  border: 2px solid #dc2626;
}

.truck-item-collected {
  animation: melonHarvest 0.3s ease-out forwards;
}

.truck-shake {
  animation: shake 0.3s ease;
}

/* Road stripes animation */
.road-stripes {
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 40px,
    rgba(255, 255, 255, 0.15) 40px,
    rgba(255, 255, 255, 0.15) 80px
  );
  animation: roadScroll 0.8s linear infinite;
}

@keyframes roadScroll {
  0% { background-position-y: 0; }
  100% { background-position-y: 80px; }
}

/* ============================================
   MARKET GAME ELEMENTS
   ============================================ */

.market-event-toast {
  animation: eventSlide 0.5s ease-out;
  border-left: 4px solid #ef4444;
}

.market-event-toast.positive {
  border-left-color: #22c55e;
}

.trade-success {
  animation: pop 0.3s ease;
}

.price-up {
  color: #16a34a;
}

.price-up::before {
  content: '▲ ';
}

.price-down {
  color: #dc2626;
}

.price-down::before {
  content: '▼ ';
}

.price-stable {
  color: #6b7280;
}

/* ============================================
   LEADERBOARD STYLES
   ============================================ */

.lb-entry {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  transition: background-color 0.2s;
}

.lb-entry:hover {
  background-color: #f9fafb;
}

.lb-entry .rank {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.875rem;
}

.lb-entry .rank.gold {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: white;
}

.lb-entry .rank.silver {
  background: linear-gradient(135deg, #d1d5db, #9ca3af);
  color: white;
}

.lb-entry .rank.bronze {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: white;
}

.lb-entry .rank.normal {
  background-color: #f3f4f6;
  color: #6b7280;
}

.lb-tab.active {
  background: linear-gradient(135deg, #22c55e, #16a34a) !important;
  color: white !important;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast {
  animation: eventSlide 0.3s ease-out;
  padding: 1rem 1.5rem;
  border-radius: 1rem;
  background: white;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  border: 1px solid #e5e7eb;
  max-width: 360px;
  font-size: 0.875rem;
}

.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.warning { border-left: 4px solid #f59e0b; }
.toast.info { border-left: 4px solid #3b82f6; }

/* ============================================
   NAV BUTTONS ACTIVE STATE
   ============================================ */

.nav-btn.active {
  background-color: #dcfce7;
  color: #15803d;
  font-weight: 600;
}

/* ============================================
   SCROLLBAR CUSTOMIZATION
   ============================================ */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .melon-item {
    font-size: 2.5rem;
  }

  .game-card .h-40 {
    height: 8rem;
  }
}

@media (max-width: 480px) {
  .melon-item {
    font-size: 2rem;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.text-shadow {
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.glass {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================
   MOBILE / TOUCH OPTIMIZATIONS
   ============================================ */

/* Prevent pull-to-refresh and overscroll during gameplay */
#screen-game {
  touch-action: manipulation;
  overscroll-behavior: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: linear-gradient(to bottom right, #f0fdf4, #ecfdf5, #f7fee7);
  display: flex !important;
  flex-direction: column;
}

#screen-game.hidden {
  display: none !important;
}

#truck-road {
  touch-action: none;
}

#harvest-field {
  touch-action: manipulation;
}

/* Prevent text selection during game */
.game-instance {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Larger tap targets on mobile */
@media (max-width: 768px) {
  #screen-game .text-xl {
    font-size: 1rem;
  }

  /* Market game buttons bigger for touch */
  #game-market button {
    min-height: 48px;
    font-size: 1rem;
  }

  #game-market select,
  #game-market input {
    min-height: 44px;
    font-size: 1rem;
  }

  /* Truck mobile controls */
  .truck-mobile-btn {
    min-height: 56px;
  }
}

/* Prevent double-tap zoom on game elements */
#game-area {
  touch-action: manipulation;
}

/* Safe area for PWA standalone (notch phones) */
@supports (padding-top: env(safe-area-inset-top)) {
  header {
    padding-top: env(safe-area-inset-top);
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
