/* Mobile : commandes tactiles et adaptation aux petits écrans */

html,
body {
  touch-action: none; /* pas de zoom ni de défilement pendant le jeu */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
input {
  user-select: text;
  touch-action: manipulation;
}

/* --- Commandes tactiles --- */
#touchControls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
#joystickZone {
  position: absolute;
  left: 0;
  top: 0;
  width: 55%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}
#joystickBase {
  display: none;
  position: absolute;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid rgba(0, 255, 255, 0.4);
  background: rgba(0, 255, 255, 0.08);
  pointer-events: none;
}
#joystickBase.active {
  display: block;
}
#joystickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(0, 255, 255, 0.5);
  box-shadow: 0 0 15px #00ffff;
}

.touch-btn {
  width: 72px;
  height: 72px;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
  pointer-events: auto;
  touch-action: none;
  opacity: 0.85;
  border: 2px solid rgba(255, 255, 255, 0.3);
}
.touch-btn:active {
  transform: scale(0.92);
  filter: brightness(1.3);
}
.touch-actions {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 84px 84px;
  justify-items: center;
  align-items: center;
  grid-template-areas:
    "box ult"
    ". dash";
  gap: 14px;
}
.touch-dash {
  grid-area: dash;
  width: 84px;
  height: 84px;
  background: radial-gradient(circle, #00ffff, #006688);
}
.touch-dash.cooldown {
  opacity: 0.35;
}
.touch-ult {
  grid-area: ult;
  background: radial-gradient(circle, #553300, #221100);
  color: #ffaa00;
  border-color: #ff6600;
}
.touch-ult.ready {
  background: radial-gradient(circle, #ffaa00, #ff6600);
  color: #000;
  animation: pulseGold 1s infinite;
}
.touch-box {
  grid-area: box;
  display: none;
  font-size: 26px;
  background: radial-gradient(circle, #0088cc, #003355);
}
.touch-pause {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  font-size: 14px;
  background: rgba(30, 30, 40, 0.8);
  color: #fff;
}

/* Sur tactile : pas d'aide clavier, HUD compact */
body.touch #controls {
  display: none;
}
body.touch #levelIndicator {
  font-size: 18px;
  bottom: 18px;
}

/* --- Petits écrans (téléphones) --- */
@media (max-width: 760px), (max-height: 560px) {
  #ui {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    min-width: 0;
    width: 200px;
    padding: 8px 10px;
    font-size: 12px;
  }
  .ui-header {
    margin-bottom: 4px;
  }
  .stat-grid,
  .ui-divider,
  .skill-box {
    display: none;
  }
  .health-bar {
    height: 16px;
  }
  #runGoldContainer {
    margin-top: 6px;
    font-size: 14px;
  }
  #boxIndicator {
    top: calc(110px + env(safe-area-inset-top));
    font-size: 11px;
  }
  #bossWarning {
    font-size: 20px;
  }
  /* En haut : le bas de l'écran appartient au joystick et aux boutons */
  .tutorial-bubble {
    top: calc(140px + env(safe-area-inset-top));
    bottom: auto;
    width: min(420px, calc(100vw - 24px));
    padding: 8px 12px;
    font-size: 12px;
  }
  .tutorial-bubble button {
    margin-top: 6px;
    padding: 5px 12px;
    font-size: 10px;
  }

  .menu-overlay {
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: 500px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 20px 16px;
    border-radius: 14px;
  }
  .menu-overlay h1 {
    font-size: 22px;
    margin-bottom: 15px;
  }
  .menu-overlay#gameOver h1 {
    font-size: 26px;
  }
  .menu-overlay h2 {
    font-size: 18px;
    margin-bottom: 12px;
  }
  button {
    padding: 12px;
    font-size: 14px;
  }
  .btn-grid {
    gap: 10px;
    margin-top: 15px;
  }
  .pseudo-input {
    padding: 10px;
    font-size: 16px; /* 16px minimum : évite le zoom auto d'iOS */
    margin: 5px 0 10px;
  }
  .upgrade-option {
    padding: 10px;
    margin: 8px 0;
  }
  .upgrade-option:hover {
    transform: none;
  }
  .icon {
    width: 38px;
    height: 38px;
    font-size: 20px;
    margin-right: 10px;
  }
  .upg-info h4 {
    font-size: 14px;
  }
  .shop-item {
    flex-direction: column;
    align-items: stretch;
  }
  .shop-item-info {
    width: 100%;
  }
  .lb-table {
    font-size: 12px;
  }
  .lb-table th,
  .lb-table td {
    padding: 6px;
  }
}

/* Les menus restent défilables au doigt */
.menu-overlay,
.inv-list,
.lb-scroll {
  touch-action: pan-y;
}

/* Paysage sur téléphone : la bulle descend entre le joystick et les boutons */
@media (max-height: 560px) {
  .tutorial-bubble {
    top: auto;
    bottom: calc(60px + env(safe-area-inset-bottom));
    width: min(500px, 60vw);
    padding: 6px 10px;
  }
}
