/* Clenchito's Adventure 5 — página contenedora. El juego vive en el canvas #screen. */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #2a1450 0%, #120a24 60%, #07040f 100%);
  background-color: #120a24;
  color: #e8e0ff;
  font-family: 'Press Start 2P', ui-monospace, Menlo, Consolas, monospace;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.game-header {
  text-align: center;
  padding: 14px 16px 8px;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(18px, 4vw, 30px);
  color: #ffd700;
  text-shadow: 3px 3px 0 #ff3d6e, 6px 6px 0 #3a1a6e;
  letter-spacing: 1px;
}

.subtitle {
  margin: 4px 0 8px;
  color: #7df9ff;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 3px;
}

.back-button {
  color: #87ceeb;
  text-decoration: none;
  font-size: 14px;
}

.back-button:hover { color: #ffd700; }

#stage-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 16px;
}

#screen {
  display: block;
  width: 384px;
  height: 224px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border: 4px solid #ffd700;
  border-radius: 6px;
  box-shadow: 0 0 0 4px #3a1a6e, 0 0 32px rgba(255, 61, 110, 0.45);
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.loading {
  position: absolute;
  margin: 0;
  color: #ffd700;
  font-size: 12px;
  pointer-events: none;
}

.game-info {
  max-width: 920px;
  margin: 18px auto 0;
  padding: 0 16px 28px;
  text-align: center;
}

.game-info h2 {
  color: #ffd700;
  font-size: 16px;
  margin: 8px 0 12px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  text-align: left;
}

.control-card {
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 215, 0, 0.35);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.7;
}

.control-card h3 {
  margin: 0 0 6px;
  color: #7df9ff;
  font-size: 13px;
}

.control-card p { margin: 2px 0; }

kbd {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  background: #ffd700;
  color: #1a1a2e;
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 3px;
  font-weight: bold;
  font-family: inherit;
  box-shadow: 0 2px 0 #b8860b;
}

.credits {
  margin-top: 18px;
  color: #bbb;
  font-size: 12px;
}

/* ------------------------------------------------------------------------- */
/* Controles táctiles                                                         */
/* ------------------------------------------------------------------------- */
#touch-controls {
  display: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

@media (pointer: coarse), (hover: none) {
  #touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    max-width: 920px;
    margin: 8px auto 0;
  }
  .game-info { display: none; }
  body.touch-landscape .game-header { display: none; }
}

.dpad {
  position: relative;
  width: 132px;
  height: 132px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12) 0%, rgba(0, 0, 0, 0.55) 70%);
  border: 3px solid #ffd700;
  touch-action: none;
}

.dpad-arrow {
  position: absolute;
  color: #ffd700;
  font-size: 18px;
  pointer-events: none;
}
.dpad-arrow.up { top: 6px; left: 50%; transform: translateX(-50%); }
.dpad-arrow.down { bottom: 6px; left: 50%; transform: translateX(-50%); }
.dpad-arrow.left { left: 8px; top: 50%; transform: translateY(-50%); }
.dpad-arrow.right { right: 8px; top: 50%; transform: translateY(-50%); }

.dpad-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 215, 0, 0.55);
  border: 2px solid #fff3a0;
  pointer-events: none;
  transition: transform 40ms linear;
}

.touch-mid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.touch-small {
  width: 48px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid #7df9ff;
  background: rgba(0, 0, 0, 0.7);
  color: #7df9ff;
  font-size: 14px;
  touch-action: none;
}

.touch-buttons {
  display: grid;
  grid-template-columns: 64px 64px 64px;
  grid-template-rows: 64px 64px;
  gap: 8px;
  flex: 0 0 auto;
}

.touch-btn {
  border-radius: 50%;
  border: 3px solid #ffd700;
  background: rgba(0, 0, 0, 0.8);
  color: #ffd700;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn b { font-size: 18px; }
.touch-btn small { font-size: 9px; margin-top: 2px; }
.touch-btn.punch { border-color: #ff6b6b; color: #ffb3b3; }
.touch-btn.kick { border-color: #4fc3f7; color: #b3e5fc; }
.touch-btn.strong { background: rgba(60, 10, 30, 0.85); }
.touch-btn.kick.strong { background: rgba(10, 30, 60, 0.85); }
.touch-btn.super {
  grid-column: 3;
  grid-row: 1 / span 2;
  border-radius: 18px;
  border-color: #ffd700;
  background: linear-gradient(180deg, rgba(255, 215, 0, 0.35), rgba(255, 61, 110, 0.35));
}
.touch-btn.super b { font-size: 11px; }
.touch-btn.punch { grid-row: 1; }
.touch-btn.kick { grid-row: 2; }
.touch-btn.pressed, .touch-small.pressed {
  transform: scale(0.92);
  background: rgba(255, 215, 0, 0.45);
}

@media (max-width: 420px) {
  .dpad { width: 116px; height: 116px; }
  .touch-buttons { grid-template-columns: 56px 56px 56px; grid-template-rows: 56px 56px; gap: 6px; }
}

/* Teléfono vertical estrecho: aprovechar el ancho */
@media (max-width: 480px) {
  #stage-wrap { padding: 0 4px; }
}

/* Teléfono en horizontal: el canvas queda al centro y los controles en columnas
   laterales. main.js descuenta el padding de #stage-wrap al escalar, así que las
   columnas nunca tapan el HUD. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  .game-header { display: none; }
  #stage-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0 calc(150px + env(safe-area-inset-right, 0px)) 0 calc(150px + env(safe-area-inset-left, 0px));
  }
  #touch-controls {
    display: block;
    position: fixed;
    inset: 0;
    margin: 0;
    padding: 0;
    max-width: none;
    pointer-events: none;
    z-index: 50;
  }
  .dpad {
    position: absolute;
    left: calc(12px + env(safe-area-inset-left, 0px));
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 126px;
    height: 126px;
    pointer-events: auto;
  }
  .touch-mid {
    position: absolute;
    left: calc(22px + env(safe-area-inset-left, 0px));
    top: 14px;
    flex-direction: row;
    pointer-events: auto;
  }
  .touch-buttons {
    position: absolute;
    right: calc(10px + env(safe-area-inset-right, 0px));
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: 62px 62px;
    grid-template-rows: 46px 62px 62px;
    gap: 6px;
    pointer-events: auto;
  }
  .touch-btn.super { grid-column: 1 / span 2; grid-row: 1; border-radius: 14px; }
  .touch-btn.punch { grid-row: 2; }
  .touch-btn.kick { grid-row: 3; }
}

/* ------------------------------------------------------------------------- */
/* Pantalla completa y aviso de girar                                         */
/* ------------------------------------------------------------------------- */
.fullscreen-btn {
  display: block;
  margin: 10px auto 0;
  padding: 6px 12px;
  border-radius: 6px;
  border: 2px solid #7df9ff;
  background: rgba(0, 0, 0, 0.6);
  color: #7df9ff;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.fullscreen-btn:hover { color: #ffd700; border-color: #ffd700; }

@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  .fullscreen-btn {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    margin: 0;
    z-index: 60;
    font-size: 10px;
    padding: 6px 8px;
  }
}

#rotate-hint { display: none; }

@media (pointer: coarse) and (orientation: portrait) {
  body:not(.rotate-dismissed) #rotate-hint {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
    background: rgba(7, 4, 15, 0.9);
  }
}

.rotate-card {
  max-width: 320px;
  text-align: center;
  background: #1e1038;
  border: 3px solid #ffd700;
  border-radius: 10px;
  padding: 18px 16px;
  font-size: 13px;
  line-height: 1.6;
}
.rotate-icon {
  font-size: 40px;
  animation: rotate-wiggle 1.6s ease-in-out infinite;
}
.rotate-ios { color: #7df9ff; font-size: 12px; }
#rotate-ok {
  margin-top: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 2px solid #ffd700;
  background: #ffd700;
  color: #1a1a2e;
  font-family: inherit;
  font-weight: bold;
  font-size: 13px;
}
@keyframes rotate-wiggle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
@media (prefers-reduced-motion: reduce) {
  .rotate-icon { animation: none; }
}

/* ------------------------------------------------------------------------- */
/* v5.4 — Modo encuentro (?encuentro=1): la v6 abre la v5 en un iframe a      */
/* pantalla completa. main.js pone body.encuentro solo si los parámetros son  */
/* válidos; sin esa clase nada de esto aplica. Sin cabecera, sin información, */
/* sin botón de pantalla completa ni aviso de girar: el lienzo usa el iframe. */
/* ------------------------------------------------------------------------- */
body.encuentro {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
body.encuentro .game-header,
body.encuentro .game-info,
body.encuentro #btn-fullscreen,
body.encuentro #rotate-hint { display: none !important; }
body.encuentro #stage-wrap { flex: 0 0 auto; padding: 0; }

@media (pointer: coarse), (hover: none) {
  body.encuentro #touch-controls {
    flex: 0 0 auto;
    width: 100%;
    margin: 6px auto 0;
  }
}

/* Táctil en horizontal: mismas columnas laterales que la v5 normal. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  body.encuentro #stage-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0 calc(150px + env(safe-area-inset-right, 0px)) 0 calc(150px + env(safe-area-inset-left, 0px));
  }
  body.encuentro #touch-controls { margin: 0; }
}
