html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  
  /* OPZIONE 1: Colore solido */
  background: #A743FA;
  
  /* OPZIONE 2: Gradiente */
  /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
  
  /* OPZIONE 4: Pattern ripetuto */
  /* background: url('Assets/pattern.png');
  background-repeat: repeat;
  background-size: 100px 100px; */
}

/* body {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 1280px;
  height: 1024px;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  background: #111;
  background-image: url('Assets/grass_tile.png');
  background-repeat: repeat;
  background-size: 64px 64px;
  color: white;
  font-family: 'Fredoka', sans-serif;
} */
 body {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 1280px;
  height: 832px;  /* CAMBIATO: 13 celle * 64px = 832px */
  transform: translate(-50%, -50%);
  transform-origin: center center;
  background: #111;
  background-image: url('Assets/grass_tile.png');
  background-repeat: repeat;
  background-size: 64px 64px;
  overflow: hidden;
  color: white;
  font-family: 'Fredoka', sans-serif;
}

/* Contatore vite */
#lives-counter {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 28px;
  font-weight: 600;
  color: #d32f2f;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
  animation: bounce-in 0.5s ease-out;
}

.skull-icon {
  font-size: 32px;
  animation: wiggle 2s ease-in-out infinite;
}

/* Contatore mele */
#counter {
  position: fixed;
  top: 20px;
  left: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 28px;
  font-weight: 600;
  color: #e91e63;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
  animation: bounce-in 0.5s ease-out;
}

.apple-icon {
  font-size: 32px;
  animation: wiggle 2s ease-in-out infinite;
}

@keyframes bounce-in {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes wiggle {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-5deg);
  }
  75% {
    transform: rotate(5deg);
  }
}

/* Player */
#player {
  width: 80px;
  height: 80px;
  background: url('Assets/kuromi.png') no-repeat center center;
  background-size: contain;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  image-rendering: pixelated; /* Per Firefox e Chrome moderni */
  image-rendering: -moz-crisp-edges; /* Firefox vecchi */
  image-rendering: crisp-edges; /* Standard */
  -ms-interpolation-mode: nearest-neighbor; /* IE */
}

#mymelody {
  width: 80px;
  height: 80px;
  background: url('Assets/mymelody.png') no-repeat center center;
  background-size: contain;
  position: absolute;
  z-index: 10;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  image-rendering: pixelated; /* Per Firefox e Chrome moderni */
  image-rendering: -moz-crisp-edges; /* Firefox vecchi */
  image-rendering: crisp-edges; /* Standard */
  -ms-interpolation-mode: nearest-neighbor; /* IE */
}

/* Fantasmi aggiuntivi */
#mymelody-cyan,
#mymelody-green,
#mymelody-yellow {
  width: 80px;
  height: 80px;
  background-size: contain;
  position: absolute;
  z-index: 10;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
}

#mymelody-cyan {
  background: url('Assets/mymelody_cyan.png') no-repeat center center;
  background-size: contain;
}

#mymelody-green {
  background: url('Assets/mymelody_green.png') no-repeat center center;
  background-size: contain;
}

#mymelody-yellow {
  background: url('Assets/mymelody_yellow.png') no-repeat center center;
  background-size: contain;
}


/* Mele */
.apple {
  width: 30px;
  height: 30px;
  position: absolute;
  font-size: 30px;
  cursor: pointer;
  animation: apple-appear 0.5s ease-out, apple-float 3s ease-in-out infinite;
  z-index: 5;
  filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
  /*non deve essere cliccabile*/
  pointer-events: none;
}

/*Tree*/
/* .tree {
  position: absolute;
  width: 64px;
  height: 64px;
  background-image: url('Assets/tree.png');
  background-size: contain;
  pointer-events: none;
  z-index: 5;
} */
 /*Tree*/
.tree {
  position: absolute;
  width: 64px;
  height: 64px;
  background-image: url('Assets/tree.png');
  background-size: cover;  /* CAMBIATO: da "contain" a "cover" */
  background-position: center;
  pointer-events: none;
  z-index: 5;
  image-rendering: pixelated;  /* NUOVO: mantiene pixel art nitida */
  image-rendering: crisp-edges;
}

@keyframes apple-appear {
  0% {
    transform: scale(0) rotate(0deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
    opacity: 1;
  }
}

@keyframes apple-float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Animazione quando raccogli la mela */
@keyframes apple-collect {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.5) rotate(360deg);
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

.apple.collecting {
  animation: apple-collect 0.4s ease-out forwards;
}

/* Animazione contatore quando raccogli */
@keyframes counter-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

#counter.pop {
  animation: counter-pop 0.3s ease-out;
}

/* Messaggio motivazionale */
#motivational-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 20px 35px;
  border-radius: 20px;
  font-size: 24px;
  font-weight: 600;
  color: #9c27b0;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  text-align: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  max-width: 80%;
  line-height: 1.4;
}

#motivational-message.show {
  animation: message-appear 0.5s ease-out forwards, message-disappear 0.5s ease-out 4.5s forwards;
}

/* Pausa - rimane visualizzata senza scomparire */
#motivational-message.paused {
  animation: message-appear 0.5s ease-out forwards;
  font-size: 48px;
  padding: 30px 50px;
}

@keyframes message-appear {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes message-disappear {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
}

#countdown {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 120px;
  font-weight: 700;
  color: white;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 
               0 0 40px rgba(147, 51, 234, 0.6);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
}

#countdown.show {
  animation: countdown-pulse 1s ease-in-out;
}

@keyframes countdown-pulse {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* HUD Controlli — nascosto su desktop, visibile solo mobile */
#controls-hud {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 15px 25px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: none; /* Nascosto di default (desktop) */
  align-items: center;
  gap: 15px;
  z-index: 100;
  animation: bounce-in 0.5s ease-out 0.3s backwards;
}

.control-group {
  display: flex;
  gap: 8px;
}

.key {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  width: 35px;
  height: 35px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.control-divider {
  color: #999;
  font-size: 18px;
  font-weight: 500;
}


#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  /* Oppure usa un pattern o colore solido */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease-out;
}

#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.logo {
  max-width: 300px;
  animation: logo-pulse 2s ease-in-out infinite;
  filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.3));
}

@keyframes logo-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.progress-bar-container {
  width: 400px;
  height: 20px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50px;
  margin-top: 40px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #fff 0%, #f0f0f0 100%);
  border-radius: 50px;
  transition: width 0.3s ease-out;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

/* Waypoint visuali (per debug) */
.waypoint {
  position: absolute;
  width: 20px;
  height: 20px;
  background: rgba(255, 215, 0, 0.8);
  border: 3px solid #ff6b00;
  border-radius: 50%;
  z-index: 15;
  transform: translate(-50%, -50%);
  animation: waypoint-pulse 1.5s ease-in-out infinite;
  pointer-events: none;
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

.waypoint.active {
  background: rgba(255, 0, 0, 0.9);
  border-color: #ff0000;
  box-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
  width: 26px;
  height: 26px;
}

@keyframes waypoint-pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.8;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }
}

/* Controlli touch mobile */
/* Contenitore sinistro: SU / GIÙ */
#touch-controls-left {
  position: fixed;
  bottom: 40px;
  left: 20px;
  width: 100px;
  height: 200px;
  z-index: 9999;
  pointer-events: none;
  display: none;
}

/* Contenitore destro: SINISTRA / DESTRA */
#touch-controls-right {
  position: fixed;
  bottom: 40px;
  right: 20px;
  width: 200px;
  height: 100px;
  z-index: 9999;
  pointer-events: none;
  display: none;
}

.touch-btn {
  position: absolute;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 100%;
  font-size: 64px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  user-select: none;
  pointer-events: auto;
}

/* LATO SINISTRO */
#btn-up {
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
}

#btn-down {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

/* LATO DESTRO */
#btn-left {
  top: 50%;
  left: -50%;
  transform: translateY(-50%);
}

#btn-right {
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}

.touch-btn:active {
  background: rgba(200, 200, 255, 0.9);
  transform: scale(0.95);
  opacity: 1 !important;
}

/* Mostra controlli solo su mobile */
@media (max-width: 768px), (pointer: coarse) {
  #touch-controls-left,
  #touch-controls-right {
    display: block !important;
  }
  #controls-hud {
    display: none !important;
  }
  /* Trasparenti di default, si illuminano solo quando premuti */
  .touch-btn {
    opacity: 0.15;
    transition: opacity 0.15s ease;
  }
  .touch-btn:active {
    opacity: 1;
  }
}

#level-indicator {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 32px;
  border-radius: 50px;
  font-size: 24px;
  font-weight: 700;
  color: #FF6B00;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
  animation: bounce-in 0.5s ease-out;
}

.level-label {
  font-size: 18px;
  font-weight: 500;
  color: #666;
}

/* Fantasma spaventato (quando mangi power pellet) */
#mymelody.scared,
#mymelody-cyan.scared,
#mymelody-green.scared,
#mymelody-yellow.scared {
  filter: brightness(0.5) contrast(1.5);
  animation: scared-blink 0.3s ease-in-out infinite;
}

@keyframes scared-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Fantasma morto */
#mymelody.dead,
#mymelody-cyan.dead,
#mymelody-green.dead,
#mymelody-yellow.dead {
  opacity: 0.3 !important;
}