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

html, body {
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: #080808;
  color: #f5f5f0;
  overflow: hidden;
  font-family: "Courier New", monospace;
}

#wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#screen {
  display: block;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 0 4px #141414, 0 0 0 6px #7f3fc7, 0 0 40px rgba(157, 220, 58, 0.15);
  cursor: pointer;
  touch-action: none;
}

#bar {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  letter-spacing: 1px;
  color: #8c8c86;
  padding: 0 16px;
  flex-wrap: wrap;
  justify-content: center;
}

#soundBtn, #crtBtn {
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  background: #080808;
  color: #9ddc3a;
  border: 2px solid #9ddc3a;
  padding: 4px 10px;
  cursor: pointer;
}
#soundBtn.off, #crtBtn.off { color: #8c8c86; border-color: #8c8c86; }
#soundBtn:hover, #crtBtn:hover { background: #9ddc3a; color: #080808; }

/* ---------------- controles táctiles ---------------- */
#touch { display: none; }
body.touch #touch {
  display: flex;
  width: 100%;
  max-width: 560px;
  padding: 4px 14px 10px;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  touch-action: none;
}
body.touch .keys, body.touch #crtBtn { display: none; }
body.touch #wrap { gap: 12px; padding-bottom: env(safe-area-inset-bottom); }
.pad { display: flex; gap: 10px; align-items: center; }
.mid { display: flex; flex-direction: column; gap: 10px; }
.tb {
  font-family: inherit;
  font-weight: bold;
  letter-spacing: 1px;
  color: #9ddc3a;
  background: #0d0b12;
  border: 3px solid #7f3fc7;
  border-radius: 14px;
  box-shadow: 0 4px 0 #2e1150;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tb.on { background: #7f3fc7; color: #f5f5f0; border-color: #c084fc; transform: translateY(3px); box-shadow: 0 1px 0 #2e1150; }
.dir { width: 74px; height: 74px; }
.fire {
  width: 96px; height: 96px; border-radius: 50%;
  background: #f4ca3f; color: #080808; border-color: #c9971c; box-shadow: 0 5px 0 #8a5a00;
  font-size: 12px;
}
.fire.on { background: #fff1a8; color: #080808; border-color: #f4ca3f; box-shadow: 0 2px 0 #8a5a00; }
.small { font-size: 11px; padding: 9px 12px; border-radius: 8px; color: #f5f5f0; }
.tri { display: block; width: 0; height: 0; margin: auto; border-top: 15px solid transparent; border-bottom: 15px solid transparent; }
.tri.l { border-right: 22px solid currentColor; }
.tri.r { border-left: 22px solid currentColor; }

/* Celular horizontal: el juego ocupa el alto y los controles flotan a los lados */
@media (orientation: landscape) {
  body.touch #touch {
    position: fixed; left: 0; right: 0; bottom: 0; max-width: none;
    padding: 0 max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
    pointer-events: none; align-items: flex-end;
  }
  body.touch #touch .tb { pointer-events: auto; opacity: 0.9; }
  body.touch .mid { position: fixed; top: 8px; right: max(8px, env(safe-area-inset-right)); flex-direction: row; }
  body.touch .dir { width: 66px; height: 66px; }
  body.touch .fire { width: 84px; height: 84px; }
  body.touch #bar { position: fixed; top: 8px; left: 8px; padding: 0; }
  body.touch #wrap { gap: 0; }
}

/* Enlace de vuelta al sitio: solo cuando el juego se abre fuera de la página */
#backLink {
  font-family: inherit; font-size: 11px; font-weight: bold; letter-spacing: 1px;
  color: #080808; background: #b6ff4b; border: 2px solid #b6ff4b; padding: 4px 10px; text-decoration: none;
}
body.embedded #backLink { display: none; }

/* Pantallas angostas (o el juego dentro de la página en un celular): botones un poco más chicos */
@media (max-width: 400px) and (orientation: portrait) {
  body.touch #touch { padding: 2px 8px 8px; gap: 6px; }
  body.touch .pad { gap: 7px; }
  body.touch .dir { width: 60px; height: 60px; }
  body.touch .fire { width: 80px; height: 80px; font-size: 11px; }
  body.touch .small { padding: 8px 9px; font-size: 10px; }
}
