* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050816;
  font-family: Arial, sans-serif;
  color: #ffffff;
  position: fixed;
}

body {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#gameShell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050816;
}

canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
}

/* MENU E FINESTRA */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 20, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden {
  display: none !important;
}

.panel {
  width: min(92vw, 650px);
  padding: 42px 35px;
  text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(14, 24, 55, 0.94), rgba(5, 10, 27, 0.96));
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.5);
  max-height: 90vh;
  overflow-y: auto;
}

.panel.small {
  width: min(90vw, 430px);
  padding: 30px 25px;
}

/* TITOLO */
.badge {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 999px;
  background: #17264c;
  color: #75e8ff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
}

h1 {
  margin: 22px 0 18px;
  font-size: clamp(36px, 8vw, 88px);
  line-height: 0.85;
  letter-spacing: 3px;
  text-shadow: 5px 5px #101a3b;
}

h1 span {
  color: #75e8ff;
}

h2 {
  margin: 0 0 25px;
  font-size: clamp(32px, 6vw, 44px);
}

p {
  font-size: clamp(14px, 2.5vw, 17px);
  line-height: 1.5;
  color: #c7d1ed;
}

/* PULSANTI MENU */
button {
  margin: 7px;
  padding: 15px 32px;
  border: 0;
  border-radius: 14px;
  background: #75e8ff;
  color: #071126;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 0 #287d98;
  transition: 0.08s;
}

button:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #287d98;
}

.secondary {
  background: #263456;
  color: #ffffff;
  box-shadow: 0 8px 0 #141d35;
}

.sound {
  display: block;
  margin: 18px auto 0;
  padding: 11px 20px;
  background: #263456;
  color: #ffffff;
  font-size: 14px;
  box-shadow: 0 6px 0 #141d35;
}

.hint {
  margin-top: 20px;
  color: #8f9aba;
  font-size: 13px;
}

/* =========================================
   CONTROLLI TOUCH - RESPONSIVE
   Ottimizzati per iPhone, iPad, Android
========================================= */
#touchControls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex !important;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(20px, env(safe-area-inset-left)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-right));
  pointer-events: none;
  z-index: 9999;
  width: 100%;
}

/* Gruppo pulsanti movimento (sinistra) */
#touchControls > div {
  display: flex;
  gap: clamp(12px, 3vw, 22px);
  pointer-events: auto;
  align-items: flex-end;
}

/* Pulsante salto (destra) */
#touchControls > button[data-key="jump"] {
  pointer-events: auto;
}

/* Stile base per tutti i pulsanti touch */
#touchControls button {
  width: clamp(65px, 14vw, 90px);
  height: clamp(65px, 14vw, 90px);
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.45);
  background: rgba(15, 29, 63, 0.9);
  color: #ffffff;
  font-size: clamp(26px, 6vw, 38px);
  font-weight: bold;
  box-shadow: 
    0 6px 0 rgba(0, 0, 0, 0.6),
    0 0 20px rgba(0, 0, 0, 0.4),
    inset 0 -4px 8px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.05s, background 0.1s;
}

#touchControls button:active {
  background: rgba(117, 232, 255, 0.7);
  transform: translateY(4px);
  box-shadow: 
    0 2px 0 rgba(0, 0, 0, 0.6),
    0 0 15px rgba(117, 232, 255, 0.5);
}

/* Pulsante salto più grande e colorato */
#touchControls > button[data-key="jump"] {
  width: clamp(80px, 18vw, 110px);
  height: clamp(80px, 18vw, 110px);
  font-size: clamp(32px, 7vw, 44px);
  background: rgba(117, 232, 255, 0.25);
  border-color: rgba(117, 232, 255, 0.7);
  box-shadow: 
    0 6px 0 rgba(0, 0, 0, 0.6),
    0 0 25px rgba(117, 232, 255, 0.4),
    inset 0 -4px 8px rgba(0, 0, 0, 0.3);
}

#touchControls > button[data-key="jump"]:active {
  background: rgba(117, 232, 255, 0.8);
}

/* =========================================
   OTTIMIZZAZIONI PER DISPOSITIVO
========================================= */

/* iPhone portrait (schermi piccoli) */
@media (max-width: 430px) and (orientation: portrait) {
  #touchControls {
    padding: 0 15px calc(15px + env(safe-area-inset-bottom)) 15px;
  }
  
  #touchControls button {
    width: 70px;
    height: 70px;
    font-size: 28px;
  }
  
  #touchControls > button[data-key="jump"] {
    width: 85px;
    height: 85px;
    font-size: 34px;
  }
  
  #touchControls > div {
    gap: 12px;
  }
}

/* iPhone landscape */
@media (max-height: 430px) and (orientation: landscape) {
  #touchControls {
    padding: 0 25px calc(10px + env(safe-area-inset-bottom)) 25px;
  }
  
  #touchControls button {
    width: 65px;
    height: 65px;
    font-size: 26px;
  }
  
  #touchControls > button[data-key="jump"] {
    width: 80px;
    height: 80px;
    font-size: 32px;
  }
}

/* iPad portrait */
@media (min-width: 700px) and (max-width: 900px) and (orientation: portrait) {
  #touchControls {
    padding: 0 40px calc(30px + env(safe-area-inset-bottom)) 40px;
  }
  
  #touchControls button {
    width: 85px;
    height: 85px;
    font-size: 34px;
  }
  
  #touchControls > button[data-key="jump"] {
    width: 105px;
    height: 105px;
    font-size: 42px;
  }
}

/* iPad landscape */
@media (min-width: 900px) and (orientation: landscape) {
  #touchControls {
    padding: 0 50px calc(35px + env(safe-area-inset-bottom)) 50px;
  }
  
  #touchControls button {
    width: 90px;
    height: 90px;
    font-size: 36px;
  }
  
  #touchControls > button[data-key="jump"] {
    width: 110px;
    height: 110px;
    font-size: 44px;
  }
}

/* Android tablet grande */
@media (min-width: 1000px) {
  #touchControls {
    padding: 0 60px calc(40px + env(safe-area-inset-bottom)) 60px;
  }
  
  #touchControls button {
    width: 95px;
    height: 95px;
    font-size: 38px;
  }
  
  #touchControls > button[data-key="jump"] {
    width: 115px;
    height: 115px;
    font-size: 46px;
  }
}

/* Desktop con mouse - nasconde i controlli */
@media (hover: hover) and (pointer: fine) and (min-width: 1024px) {
  #touchControls {
    display: none !important;
  }
}