/* ==========================================================================
   Club Penguin Wonder - Mobile On-Screen Game Controls (v3.3)
   Controles táctiles automáticos integrados estrictamente dentro de la pantalla de juego
   Optimizado con botones amplios y cómodos para celulares móviles (iPhone / Android)
   ========================================================================== */

#cp-mobile-controls-wrapper {
  display: none !important; /* Estrictamente oculto por defecto en salas normales */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2500;
  font-family: 'Burbank Small', 'Comic Sans MS', 'Arial Rounded MT Bold', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overflow: hidden; /* Garantiza que los controles nunca sobresalgan del marco del juego */
}

/* Solo se vuelve visible cuando un minijuego objetivo está activo */
#cp-mobile-controls-wrapper.cp-active {
  display: block !important;
}

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

/* Cruceta direccional (D-Pad) dentro de la esquina inferior izquierda */
.cp-dpad-box {
  position: absolute;
  bottom: 18px;
  left: 20px;
  width: 165px;
  height: 165px;
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 5px;
  justify-content: center;
  align-content: center;
  pointer-events: none;
  opacity: 0.94;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Botón individual del D-Pad */
.cp-touch-btn {
  pointer-events: auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #38bdf8 0%, #0090d4 50%, #005f9e 100%);
  border: 3.5px solid #002b54;
  box-shadow: 0 5px 12px rgba(0, 25, 55, 0.65), 
              inset 0 2px 4px rgba(255, 255, 255, 0.7), 
              inset 0 -3px 6px rgba(0, 30, 70, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  position: relative;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, filter 0.08s ease, background 0.08s ease;
}

.cp-touch-btn:active,
.cp-touch-btn.active {
  transform: translateY(2px) scale(0.92);
  background: radial-gradient(circle at 35% 30%, #0284c7 0%, #026aa2 60%, #014574 100%);
  border-color: #001a35;
  box-shadow: 0 2px 6px rgba(0, 20, 45, 0.75), 
              inset 0 1px 3px rgba(255, 255, 255, 0.3), 
              inset 0 -2px 4px rgba(0, 20, 50, 0.85);
}

/* Zona táctil ampliada para máxima comodidad de toque con los pulgares */
.cp-touch-btn::after {
  content: '';
  position: absolute;
  top: -7px;
  left: -7px;
  right: -7px;
  bottom: -7px;
  border-radius: 50%;
}

.cp-btn-up { grid-column: 2; grid-row: 1; }
.cp-btn-left { grid-column: 1; grid-row: 2; }
.cp-btn-down { grid-column: 2; grid-row: 2; }
.cp-btn-right { grid-column: 3; grid-row: 2; }

.cp-touch-btn svg {
  width: 62%;
  height: 62%;
  filter: drop-shadow(0 2px 3px rgba(0, 30, 65, 0.6));
  pointer-events: none;
}

/* Botón de Acción 'A' dentro de la esquina inferior derecha */
.cp-action-box {
  position: absolute;
  bottom: 20px;
  right: 22px;
  pointer-events: none;
  opacity: 0.94;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.cp-btn-action {
  width: 68px;
  height: 68px;
  border-width: 4px;
  background: radial-gradient(circle at 35% 30%, #38bdf8 0%, #009be6 50%, #0068b0 100%);
}

.cp-btn-action svg {
  width: 70%;
  height: 70%;
}

/* Botón central en el medio de la pantalla del juego (ocultar / aparecer controles) */
.cp-toggle-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  z-index: 2600;
}

.cp-btn-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(0, 40, 80, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid #38bdf8;
  border-radius: 9999px;
  padding: 6px 16px;
  color: #ffffff;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.4px;
  text-shadow: 1px 1px 2px rgba(0, 20, 50, 0.8);
  box-shadow: 0 4px 12px rgba(0, 20, 45, 0.45);
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cp-btn-toggle:active {
  transform: scale(0.95);
  background: rgba(0, 30, 65, 0.95);
}

.cp-toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  transition: background-color 0.2s, box-shadow 0.2s;
}

.cp-btn-toggle.minimized .cp-toggle-dot {
  background-color: #94a3b8;
  box-shadow: none;
}

/* Estado minimizado (D-Pad y Botón A ocultos) */
.cp-minimized .cp-dpad-box,
.cp-minimized .cp-action-box {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(12px) scale(0.92);
}

/* Notificación flotante de juego detectado */
.cp-game-toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 45, 85, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid #38bdf8;
  border-radius: 20px;
  padding: 6px 18px;
  color: #ffffff;
  font-size: 13px;
  font-weight: bold;
  pointer-events: none;
  z-index: 2700;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.45);
}

.cp-game-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

/* ==========================================================================
   OPTIMIZACIÓN TÁCTIL PARA CELULARES EN HORIZONTAL / APAISADO (iPhone / Android)
   Botones amplios, fáciles de pulsar con pulgares y cómodos para jugar
   ========================================================================== */
@media (max-height: 600px) {
  .cp-dpad-box {
    bottom: 10px;
    left: 12px;
    width: 168px;
    height: 168px;
    grid-template-columns: 54px 54px 54px;
    grid-template-rows: 54px 54px 54px;
    gap: 4px;
  }
  .cp-touch-btn {
    border-width: 3.5px;
  }
  .cp-touch-btn svg {
    width: 64%;
    height: 64%;
  }
  .cp-btn-action {
    width: 70px;
    height: 70px;
    bottom: 12px;
    right: 14px;
    border-width: 4px;
  }
  .cp-btn-action svg {
    width: 72%;
    height: 72%;
  }
  .cp-toggle-bar {
    bottom: 8px;
  }
  .cp-btn-toggle {
    font-size: 11px;
    padding: 3px 12px;
    gap: 5px;
  }
  .cp-toggle-dot {
    width: 6.5px;
    height: 6.5px;
  }
  .cp-game-toast {
    top: 10px;
    padding: 4px 14px;
    font-size: 11.5px;
  }
}

/* Responsive para pantallas verticales de celular (portrait) */
@media (max-width: 600px) and (min-height: 601px) {
  .cp-dpad-box {
    bottom: 10px;
    left: 8px;
    width: 140px;
    height: 140px;
    grid-template-columns: 44px 44px 44px;
    grid-template-rows: 44px 44px 44px;
    gap: 3px;
  }
  .cp-btn-action {
    width: 58px;
    height: 58px;
    bottom: 10px;
    right: 10px;
  }
  .cp-toggle-bar {
    bottom: 8px;
  }
  .cp-btn-toggle {
    font-size: 11px;
    padding: 3px 10px;
  }
}
