/* =========================================================
   REVIRA COFRADE - STYLE
   Responsive mejorado para movil.
   ========================================================= */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  background: #070912;
  font-family: 'Courier New', monospace;
  color: #f4efe3;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game-wrapper {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, rgba(255, 240, 187, 0.35) 0%, rgba(240, 223, 190, 0.95) 42%, #8b2f2a 120%);
}

#phaser-game {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

canvas {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
  display: block;
  box-shadow: 0 0 40px rgba(214, 168, 79, 0.15);
  border: 6px solid #fff0bb;
}

/* En movil quitamos el marco para aprovechar todo el espacio */
@media (pointer: coarse), (max-width: 900px) {
  canvas {
    border: none;
    box-shadow: none;
  }
  #game-wrapper {
    background: #070912;
  }
}

/* =========================================================
   CONTROLES MOVILES
   ========================================================= */
#mobile-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

#mobile-controls.hidden {
  display: none !important;
}

/* D-PAD: izquierda abajo */
.dpad {
  position: absolute;
  bottom: 18px;
  left: 14px;
  width: 195px;
  height: 195px;
  pointer-events: auto;
}

.dpad-btn {
  position: absolute;
  width: 65px;
  height: 65px;
  background: rgba(60, 40, 92, 0.78);
  color: #ffd36b;
  border: 2px solid #d6a84f;
  border-radius: 12px;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45), inset 0 0 8px rgba(214, 168, 79, 0.18);
  transition: background 0.05s, transform 0.05s;
  letter-spacing: 0.5px;
}

.dpad-btn:active,
.dpad-btn.active {
  background: rgba(214, 168, 79, 0.85);
  color: #070912;
  transform: scale(0.94);
}

.dpad-btn.up    { top: 0;    left: 65px; }
.dpad-btn.left  { top: 65px; left: 0;    }
.dpad-btn.right { top: 65px; left: 130px;}
.dpad-btn.down  { top: 130px;left: 65px; }

/* ACTION BUTTONS: derecha abajo */
.action-buttons {
  position: absolute;
  bottom: 24px;
  right: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  gap: 10px;
  pointer-events: auto;
}

.action-btn {
  min-width: 105px;
  padding: 16px 16px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 13px;
  letter-spacing: 1px;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  transition: transform 0.05s, background 0.05s, filter 0.05s;
}

.action-btn.cielo {
  background: rgba(122, 31, 43, 0.92);
  color: #ffd36b;
  border-color: #ffd36b;
}

.action-btn.stop {
  background: rgba(60, 40, 92, 0.92);
  color: #f4efe3;
  border-color: #f4efe3;
}

.action-btn.bailar {
  grid-column: span 2;
  background: rgba(214, 168, 79, 0.95);
  color: #2a1004;
  border-color: #fff0bb;
}

.action-btn.turn {
  background: rgba(49, 95, 135, 0.92);
  color: #fff0bb;
  border-color: #fff0bb;
}

.action-btn:active,
.action-btn.active {
  transform: scale(0.92);
  filter: brightness(1.4);
}

/* ----- Pantallas anchas (tablet landscape) ----- */
@media (min-width: 900px) and (pointer: coarse) {
  .dpad { bottom: 30px; left: 30px; width: 210px; height: 210px; }
  .dpad-btn { width: 70px; height: 70px; font-size: 12px; }
  .dpad-btn.up    { top: 0;    left: 70px; }
  .dpad-btn.left  { top: 70px; left: 0;    }
  .dpad-btn.right { top: 70px; left: 140px;}
  .dpad-btn.down  { top: 140px;left: 70px; }
  .action-buttons { bottom: 36px; right: 30px; gap: 12px; }
  .action-btn { min-width: 120px; padding: 18px 20px; font-size: 14px; }
}

/* ----- Móvil en vertical (como La Iguala): controles abajo, compactos ----- */
body.vertical .dpad { width: 156px; height: 156px; bottom: 10px; left: 8px; }
body.vertical .dpad-btn { width: 52px; height: 52px; font-size: 10px; letter-spacing: 0;
  background: rgba(40, 26, 14, 0.62); }
body.vertical .dpad-btn.up    { top: 0;     left: 52px; }
body.vertical .dpad-btn.left  { top: 52px;  left: 0;    }
body.vertical .dpad-btn.right { top: 52px;  left: 104px;}
body.vertical .dpad-btn.down  { top: 104px; left: 52px; }
body.vertical .action-buttons { bottom: 10px; right: 6px; gap: 5px;
  width: calc(100vw - 178px); max-width: 240px;
  grid-template-columns: repeat(3, 1fr); }
body.vertical .action-btn { min-width: 0; padding: 8px 2px; font-size: 9px; line-height: 1.15;
  white-space: normal; letter-spacing: 0; border-radius: 10px; opacity: 0.9;
  font-family: Verdana, sans-serif; min-height: 44px; }
body.vertical .dpad-btn { font-family: Verdana, sans-serif; }
body.vertical .action-btn.bailar { grid-column: auto; }

/* ----- Landscape muy bajo (telefono apaisado) ----- */
@media (max-height: 460px) and (orientation: landscape) {
  .dpad { width: 155px; height: 155px; bottom: 8px; left: 8px; }
  .dpad-btn { width: 51px; height: 51px; font-size: 10px; }
  .dpad-btn.up    { top: 0;    left: 51px; }
  .dpad-btn.left  { top: 51px; left: 0;    }
  .dpad-btn.right { top: 51px; left: 102px;}
  .dpad-btn.down  { top: 102px;left: 51px; }
  .action-buttons { bottom: 10px; right: 8px; gap: 6px; }
  .action-btn { min-width: 80px; padding: 10px 10px; font-size: 10px; }
}

/* === Musica del usuario === */
#music-actions,
#music-indicator,
#drop-overlay {
  display: none !important;
}

#music-actions {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

#music-pick-btn,
#music-folder-btn {
  background: rgba(20, 14, 8, 0.85);
  color: #d6a84f;
  border: 2px solid #d6a84f;
  padding: 8px 14px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
#music-pick-btn:hover,
#music-folder-btn:hover {
  background: rgba(214, 168, 79, 0.2);
  color: #ffd36b;
  border-color: #ffd36b;
}
#music-pick-btn.has-music,
#music-folder-btn.has-music {
  border-color: #5fff8a;
  color: #5fff8a;
}

#music-indicator {
  position: fixed;
  top: 86px;
  right: 12px;
  z-index: 50;
  background: rgba(20, 14, 8, 0.85);
  color: #fff0bb;
  padding: 6px 10px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #4a3a1a;
}
#music-indicator.hidden { display: none; }
#music-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#music-toggle {
  background: none;
  border: none;
  color: #d6a84f;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}

#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border: 6px dashed #d6a84f;
}
body.dropping #drop-overlay { display: flex; }
.drop-text {
  font-family: 'Courier New', monospace;
  font-size: 22px;
  color: #ffd36b;
  text-align: center;
  text-shadow: 0 2px 6px #000;
}
.drop-text small {
  font-size: 13px;
  color: #d6a84f;
}

/* Aviso de rotar a landscape en moviles muy estrechos en portrait */
#rotate-hint {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(7, 9, 18, 0.95);
  z-index: 200;
  text-align: center;
  font-family: 'Courier New', monospace;
  color: #ffd36b;
  padding: 30px;
  font-size: 18px;
  line-height: 1.6;
}
#rotate-hint.show { display: flex; }
#rotate-hint .icon { font-size: 50px; margin-bottom: 14px; display: block; }
