* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: #000;
  color: #c8c8d8;
  font-family: "Press Start 2P", monospace;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
/* Pantalla casi completa, como un emulador (mGBA): solo el juego sobre negro */
#wrap {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0; gap: 0;
}
#screen { line-height: 0; }
#game {
  display: block;
  width: min(100vw, calc((100vh - 18px) * 1.5));
  aspect-ratio: 3 / 2;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}
#help {
  position: fixed; left: 0; right: 0; bottom: 0; height: 18px;
  font-size: 7px; line-height: 18px; text-align: center; margin: 0; opacity: .45;
  transition: opacity .3s;
}
#help:hover { opacity: .9; }
#help b { color: #f8d038; font-weight: normal; }
:fullscreen #game { width: min(100vw, calc(100vh * 1.5)); }
:fullscreen #help { display: none; }

/* ---------- controles táctiles (solo en móvil/tablet: clase .mobile) ---------- */
#touch { display: none; }
#touch button {
  font-family: inherit; color: #f0f0f8; border: 0; padding: 0;
  background: rgba(44, 44, 60, .62); box-shadow: 0 3px 0 rgba(0,0,0,.45);
  -webkit-tap-highlight-color: transparent; touch-action: none;
}
#touch button.on { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.45); background: rgba(90, 90, 120, .8); }
.dpad { display: grid; grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); touch-action: none; }
.dpad button { font-size: 16px; border-radius: 8px; }
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }
.mid { display: flex; gap: 8px; }
#touch .mid .small { font-size: 9px; padding: 11px 14px; border-radius: 14px; min-width: 44px; }
.ab { display: flex; gap: 16px; align-items: flex-end; }
.ab button { width: 64px; height: 64px; border-radius: 50%; font-size: 18px; background: rgba(176, 48, 72, .7); }
.ab .a { margin-bottom: 30px; }

html.mobile #help { display: none; }
html.mobile #wrap { height: 100vh; height: 100dvh; }
html.mobile #touch { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 5; }
html.mobile #touch .dpad, html.mobile #touch .ab, html.mobile #touch .mid { position: absolute; pointer-events: auto; }

/* Horizontal: el juego ocupa toda la altura y los botones van encima/a los lados */
@media (orientation: landscape) {
  html.mobile #game { width: min(100vw, calc(100vh * 1.5)); width: min(100vw, calc(100dvh * 1.5)); }
  html.mobile.wide #game { width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; }
  html.mobile.wide #touch button { background: rgba(30, 30, 44, .38); box-shadow: none; border: 2px solid rgba(255,255,255,.18); }
  html.mobile.wide #touch .ab button { background: rgba(176, 48, 72, .45); }
  html.mobile.wide #touch button.on { background: rgba(255, 255, 255, .35); }
  html.mobile #touch .dpad { left: max(12px, env(safe-area-inset-left)); bottom: 16px; }
  html.mobile #touch .ab { right: max(16px, env(safe-area-inset-right)); bottom: 20px; }
  html.mobile #touch .mid { top: 8px; right: max(12px, env(safe-area-inset-right)); flex-direction: column; }
}
/* Vertical: el juego arriba a todo lo ancho y los controles debajo */
@media (orientation: portrait) {
  html.mobile #wrap { justify-content: flex-start; padding-top: env(safe-area-inset-top); }
  html.mobile #game { width: 100vw; }
  html.mobile #touch .dpad { left: 18px; bottom: calc(40px + env(safe-area-inset-bottom)); }
  html.mobile #touch .ab { right: 22px; bottom: calc(46px + env(safe-area-inset-bottom)); }
  html.mobile #touch .mid { left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom)); }
  html.mobile #touch button { background: rgba(60, 60, 80, .9); }
  html.mobile #touch .ab button { background: #b03048; }
}

/* ---------- ventana del nombre ---------- */
#nameModal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
#nameModal[hidden] { display: none; }
#nameModal .panel {
  background: #f8f8f8; color: #404040; padding: 24px; border-radius: 10px;
  border: 4px solid #4c6880; text-align: center; width: min(90vw, 360px);
}
#nameModal p { margin: 0 0 16px; font-size: 12px; }
#nameModal input {
  font-family: inherit; font-size: 16px; width: 100%; padding: 10px; text-transform: uppercase;
  border: 3px solid #4c6880; border-radius: 6px; text-align: center; margin-bottom: 14px; outline: none;
}
#nameModal button {
  font-family: inherit; font-size: 12px; padding: 10px 26px; border: 0; border-radius: 6px;
  background: #d05838; color: #fff; cursor: pointer; box-shadow: 0 3px 0 #803020;
}

/* ---------- ventana de inicio de sesión ---------- */
#loginModal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 11;
}
#loginModal[hidden] { display: none; }
#loginModal .panel {
  background: #f8f8f8; color: #404040; padding: 20px 22px; border-radius: 10px;
  border: 4px solid #4c6880; text-align: center; width: min(92vw, 380px);
  max-height: 96vh; overflow: auto;
}
#loginModal .ttl { margin: 0 0 8px; font-size: 14px; color: #c04828; text-shadow: 2px 2px 0 #f8d038; }
#loginModal .sub { margin: 0 0 14px; font-size: 8px; line-height: 1.7; }
#loginModal input {
  font-family: inherit; font-size: 13px; width: 100%; padding: 10px; margin-bottom: 10px;
  border: 3px solid #4c6880; border-radius: 6px; text-align: center; outline: none;
}
#loginErr { min-height: 12px; margin: 0 0 10px; font-size: 8px; line-height: 1.6; color: #c03030; }
#loginModal .row { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
#loginModal button {
  font-family: inherit; font-size: 10px; padding: 10px 14px; border: 0; border-radius: 6px;
  background: #d05838; color: #fff; cursor: pointer; box-shadow: 0 3px 0 #803020;
}
#loginModal button.alt { background: #3870d8; box-shadow: 0 3px 0 #204890; }
#loginModal button.link { background: none; box-shadow: none; color: #606870; text-decoration: underline; font-size: 8px; }

/* ---------- aviso de iPhone (instalar como app) ---------- */
#iosTip { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 12; }
#iosTip[hidden] { display: none; }
#iosTip .panel { background: #f8f8f8; color: #404040; padding: 18px 20px; border-radius: 10px; border: 4px solid #4c6880; width: min(92vw, 420px); max-height: 94vh; overflow: auto; text-align: left; }
#iosTip .ttl { margin: 0 0 10px; font-size: 11px; color: #c04828; text-align: center; line-height: 1.5; }
#iosTip .sub { margin: 0 0 10px; font-size: 8px; line-height: 1.8; }
#iosTip ol { margin: 0 0 14px; padding-left: 20px; font-size: 8px; line-height: 2.2; }
#iosTip b { color: #2050a0; font-weight: normal; }
#iosTip svg { vertical-align: middle; }
#iosTip button { display: block; margin: 0 auto; font-family: inherit; font-size: 10px; padding: 10px 22px; border: 0; border-radius: 6px; background: #d05838; color: #fff; box-shadow: 0 3px 0 #803020; }
/* ya instalado como app: el botón de pantalla completa no hace falta */
html.standalone #touch .mid [data-act="full"] { display: none; }
html #touch .mid button.install, html.mobile #touch .mid button.install { background: rgba(56, 160, 72, .85); color: #fff; box-shadow: 0 3px 0 #286028; }
html.standalone #touch .mid .install, html:not(.mobile) #touch .mid .install { display: none; }
