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

html, body {
  width: 100%;
  height: 100%;
  background: #0a0a0f;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

/* ===== MENÚ ===== */
#menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* flex-start (no center): si el contenido no cabe en ventanas bajas
     (ej. la vista mini de Discord Activities), "center" lo empuja fuera
     del scroll alcanzable. .menu-inner se encarga de centrar SOLO
     cuando sobra espacio, con margin:auto. */
  justify-content: flex-start;
  background: linear-gradient(160deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
  z-index: 30;
  padding: 24px 16px;
  overflow-y: auto;
}

.menu-inner {
  margin: auto 0; /* centra verticalmente cuando hay espacio de sobra */
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.music-credit {
  color: #7dd3fc;
  font-size: 0.8rem;
  margin-bottom: 20px;
  text-align: center;
}

/* Ventanas muy bajas (ej. vista mini/flotante de Discord Activities):
   todo más compacto para que quepa sin cortar nada. */
@media (max-height: 480px) {
  #menu { padding: 12px 16px; }
  #menu h1 { font-size: 1.3rem; margin-bottom: 2px; }
  #menu .subtitle { font-size: 0.8rem; margin-bottom: 6px; }
  .music-credit { font-size: 0.72rem; margin-bottom: 10px; }
  .games-grid { gap: 8px; }
  .game-card { padding: 6px; }
  .game-card .name { font-size: 0.75rem; }
  .game-card .meta { font-size: 0.6rem; margin-top: 2px; }
}

#menu h1 {
  font-size: 1.9rem;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(90deg, #57f287, #5865f2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#menu .subtitle {
  color: #94a3b8;
  font-size: 0.95rem;
  margin-bottom: 28px;
  text-align: center;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  max-width: 680px;
  width: 100%;
}

.game-card {
  background: rgba(30, 30, 50, 0.9);
  border: 2px solid #2a2a45;
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  user-select: none;
}

.game-card:hover {
  border-color: #5865f2;
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(88, 101, 242, 0.25);
}

.game-card .cover {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  background: #111;
  overflow: hidden;
  margin-bottom: 8px;
}

.game-card .cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.game-card .name {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
}

.game-card .meta {
  font-size: 0.68rem;
  color: #64748b;
  margin-top: 4px;
  display: flex;
  justify-content: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ===== LOADING ===== */
#loading {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 40;
  gap: 14px;
  padding: 20px;
}

#loading .spinner {
  width: 42px;
  height: 42px;
  border: 3px solid #222;
  border-top-color: #5865f2;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading-text {
  color: #e2e8f0;
  font-size: 1rem;
  text-align: center;
}

.progress-wrap {
  width: min(320px, 80vw);
  height: 10px;
  background: #1e1e2e;
  border-radius: 999px;
  overflow: hidden;
  display: none;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5865f2, #57f287);
  border-radius: 999px;
  transition: width 0.15s ease;
}

.progress-label {
  color: #94a3b8;
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* ===== EMULADOR ===== */
#game-container {
  position: absolute;
  inset: 0;
  display: none;
  background: #000;
}

#game { width: 100%; height: 100%; }

#btn-back {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 9999 !important;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  display: none;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Controles móviles base */
.ejs_virtualGamepad_open {
  top: auto !important;
  bottom: 230px !important;
  right: 88px !important;
  left: auto !important;
  z-index: 100 !important;
}

.ejs_virtualGamepad_right {
  bottom: 12px !important;
  right: 88px !important;
}

.ejs_virtualGamepad_left {
  bottom: 12px !important;
  left: 12px !important;
}

.ejs_virtualGamepad_bottom {
  bottom: 10px !important;
}


/* Palanca virtual (nipplejs): visible y neutra. nipplejs aplica opacidad
   .5 al contenedor Y a cada pieza, así que se fuerza a 1 y el color se
   controla solo con el rgba. */
.ejs_virtualGamepad_parent .nipple {
  opacity: 1 !important;
}
.ejs_virtualGamepad_parent .nipple .back {
  background: rgba(255, 255, 255, 0.22) !important;
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-sizing: border-box;
  opacity: 1 !important;
}
.ejs_virtualGamepad_parent .nipple .front {
  background: rgba(255, 255, 255, 0.75) !important;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-sizing: border-box;
  opacity: 1 !important;
}

/* Enlace al repositorio (solo en la web; en Discord se oculta) */
.gh-link {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.08);
  opacity: 0.75;
  transition: opacity 0.2s, background 0.2s;
}
.gh-link:hover { opacity: 1; background: rgba(255, 255, 255, 0.18); }
.in-discord .gh-link { display: none; }
