/* ============================================================
   GameFight · estilos base y adaptación móvil
   ============================================================ */

:root {
  --bg-0: #020617;
  --bg-1: #0f172a;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --danger: #fb7185;
  --font-pixel: 'Press Start 2P', 'Segoe UI Symbol', 'Segoe UI', 'Courier New', monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-pixel);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 50% -10%, #1e293b 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 100%, #0c1a33 0%, transparent 55%),
    var(--bg-0);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

/* ============================================================
   Estructura
   ============================================================ */

.game-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.5vh, 16px);
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
}

.stage {
  position: relative;
  flex: 0 0 auto;
  width: min(100%, calc((100vh - 170px) * 16 / 9), 1000px);
  width: min(100%, calc((100dvh - 170px) * 16 / 9), 1000px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: clamp(4px, 0.8vw, 12px);
  background: #000;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.65),
    inset 0 0 0 1px rgba(56, 189, 248, 0.06);
  container-type: inline-size;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ============================================================
   HUD (vida y temporizador)
   ============================================================ */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: clamp(4px, 1cqw, 10px);
  padding: clamp(8px, 2cqw, 20px);
  padding-top: max(clamp(8px, 2cqw, 20px), env(safe-area-inset-top));
  padding-left: max(clamp(8px, 2cqw, 20px), env(safe-area-inset-left));
  padding-right: max(clamp(8px, 2cqw, 20px), env(safe-area-inset-right));
  pointer-events: none;
}

.health-wrap {
  flex: 1 1 0;
  min-width: 0;
}

.health-track {
  position: relative;
  height: clamp(10px, 3cqw, 30px);
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 8px, transparent 8px 16px),
    #3f0d12;
  border: clamp(2px, 0.4cqw, 4px) solid #f8fafc;
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
}

.health-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  transition: width 0.25s ease-out;
  will-change: width;
}

#playerHealth {
  left: 0;
  background: linear-gradient(180deg, #7dd3fc 0%, #38bdf8 45%, #2563eb 100%);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.65);
}

#enemyHealth {
  right: 0;
  background: linear-gradient(180deg, #fda4af 0%, #fb7185 45%, #e11d48 100%);
  box-shadow: 0 0 16px rgba(251, 113, 133, 0.65);
}

.timer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(46px, 9.5cqw, 96px);
  height: clamp(26px, 5cqw, 50px);
  font-size: clamp(10px, 2.2cqw, 22px);
  color: #fff;
  background: #020617;
  border: clamp(2px, 0.4cqw, 4px) solid #f8fafc;
  border-radius: 4px;
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.9);
  box-shadow:
    0 0 24px rgba(56, 189, 248, 0.25),
    inset 0 0 12px rgba(56, 189, 248, 0.15);
}

/* ============================================================
   Overlays (inicio y fin de partida)
   ============================================================ */

.message {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2.4cqw, 22px);
  padding: clamp(12px, 3cqw, 32px);
  padding-top: max(clamp(12px, 3cqw, 32px), env(safe-area-inset-top));
  padding-right: max(clamp(12px, 3cqw, 32px), env(safe-area-inset-right));
  padding-bottom: max(clamp(12px, 3cqw, 32px), env(safe-area-inset-bottom));
  padding-left: max(clamp(12px, 3cqw, 32px), env(safe-area-inset-left));
  text-align: center;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.message.visible {
  opacity: 1;
  visibility: visible;
}

.start-screen {
  background:
    radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.16) 0%, transparent 55%),
    rgba(2, 6, 23, 0.82);
}

.start-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.5cqw, 24px);
  max-width: 620px;
}

.logo {
  margin: 0;
  font-size: clamp(20px, 5.4cqw, 56px);
  line-height: 1.2;
  letter-spacing: clamp(1px, 0.4cqw, 5px);
  color: #f8fafc;
  text-shadow:
    0 0 18px rgba(56, 189, 248, 0.65),
    0 0 48px rgba(129, 140, 248, 0.35);
}

.logo span {
  color: var(--accent);
}

.tagline {
  margin: 0;
  font-size: clamp(8px, 1.4cqw, 13px);
  letter-spacing: 0.08em;
  color: var(--muted);
}

.result-text {
  font-size: clamp(16px, 4.5cqw, 46px);
  line-height: 1.5;
  text-shadow: 0 0 24px rgba(56, 189, 248, 0.8);
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.6cqw, 14px);
}

/* ============================================================
   Botones
   ============================================================ */

.btn {
  min-height: 44px;
  padding: clamp(10px, 1.8cqw, 15px) clamp(14px, 3cqw, 26px);
  font-family: var(--font-pixel);
  font-size: clamp(9px, 1.5cqw, 13px);
  line-height: 1;
  color: #f8fafc;
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 2px solid rgba(148, 163, 184, 0.35);
  border-radius: 8px;
  box-shadow: 0 6px 0 rgba(2, 6, 23, 0.8);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(2, 6, 23, 0.8);
}

.btn.primary {
  background: linear-gradient(180deg, #0ea5e9, #0369a1);
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow:
    0 6px 0 #082f49,
    0 0 24px rgba(56, 189, 248, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.btn.primary:active {
  box-shadow:
    0 3px 0 #082f49,
    0 0 18px rgba(56, 189, 248, 0.3);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.hints {
  margin: 0;
  font-size: clamp(7px, 1.2cqw, 11px);
  line-height: 1.9;
  color: var(--muted);
}

.hint-touch {
  display: none;
}

/* ============================================================
   Selección de personajes
   ============================================================ */

.select-screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  justify-content: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.18) 0%, transparent 60%),
    rgba(2, 6, 23, 0.94);
}

.select-panel {
  width: min(880px, 100%);
  max-width: 880px;
  margin: auto;
  gap: clamp(8px, 1.6vmin, 18px);
}

.select-panel .logo {
  font-size: clamp(18px, 4.2vmin, 38px);
}

.select-panel .tagline {
  font-size: clamp(7px, 1.15vmin, 11px);
}

.character-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 2vmin, 22px);
  width: 100%;
}

.select-column {
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 0.8vmin, 8px);
  min-width: 0;
}

.select-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  font-size: clamp(7px, 1.1vmin, 10px);
  letter-spacing: 0.06em;
  color: var(--muted);
}

.select-label span:first-child {
  color: var(--ink);
}

.select-label.p1 span:first-child {
  color: #7dd3fc;
}

.select-label.p2 span:first-child {
  color: #fda4af;
}

.select-keys {
  font-size: clamp(6px, 0.9vmin, 8px);
  color: rgba(148, 163, 184, 0.75);
  white-space: nowrap;
}

.select-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(6px, 1.2vmin, 12px);
}

.character-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(3px, 0.5vmin, 6px);
  min-width: 0;
  padding: clamp(6px, 1vmin, 10px) clamp(4px, 0.8vmin, 8px);
  font-family: inherit;
  color: var(--ink);
  background: rgba(15, 23, 42, 0.72);
  border: 2px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.1s ease,
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.character-option:hover,
.character-option:focus-visible {
  border-color: rgba(125, 211, 252, 0.6);
  background: rgba(30, 41, 59, 0.85);
  outline: none;
}

.character-option:active {
  transform: scale(0.97);
}

.character-portrait {
  width: clamp(44px, 8vmin, 82px);
  height: clamp(44px, 8vmin, 82px);
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.character-name {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(7px, 1.15vmin, 10px);
  line-height: 1.4;
}

.character-tag {
  font-size: clamp(6px, 0.95vmin, 8px);
  color: var(--muted);
}

.character-option.selected {
  border-color: var(--accent);
  background: rgba(14, 165, 233, 0.16);
  box-shadow:
    0 0 0 2px rgba(56, 189, 248, 0.22),
    0 0 24px rgba(56, 189, 248, 0.3);
}

.select-column:nth-child(2) .character-option.selected {
  border-color: var(--danger);
  background: rgba(244, 63, 94, 0.14);
  box-shadow:
    0 0 0 2px rgba(251, 113, 133, 0.2),
    0 0 24px rgba(251, 113, 133, 0.28);
}

.character-option.selected .character-name::after {
  content: ' ✓';
  color: #7dd3fc;
}

.select-column:nth-child(2) .character-option.selected .character-name::after {
  color: #fda4af;
}

.select-panel .start-actions {
  margin-top: clamp(2px, 0.6vmin, 6px);
}

@media (max-width: 520px) {
  .select-panel {
    width: 100%;
  }

  .character-select {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .select-keys {
    display: none;
  }

  .character-portrait {
    width: 52px;
    height: 52px;
  }
}

/* ============================================================
   Instrucciones de teclado (escritorio)
   ============================================================ */

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.5vw, 24px);
  width: min(100%, 1000px);
  padding: 12px 18px;
  font-size: clamp(8px, 1vw, 11px);
  line-height: 1.8;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 12px;
}

.legend-title {
  margin: 0;
  font-size: inherit;
  color: var(--ink);
}

.legend-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
}

.legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 3px 6px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: #e2e8f0;
  background: #1e293b;
  border: 1px solid #334155;
  border-bottom-width: 3px;
  border-radius: 4px;
}

/* ============================================================
   Controles táctiles
   ============================================================ */

.touch-controls {
  --btn: clamp(48px, 9vmin, 64px);

  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  padding:
    10px
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  pointer-events: none;
}

.cluster {
  display: grid;
  grid-template-columns: repeat(2, var(--btn));
  grid-template-rows: repeat(2, var(--btn));
  gap: 6px;
  pointer-events: auto;
}

.cluster-left .touch-btn[data-action='jump'] {
  grid-area: 1 / 1;
}

.cluster-left .touch-btn[data-action='attack'] {
  grid-area: 1 / 2;
}

.cluster-left .touch-btn[data-action='left'] {
  grid-area: 2 / 1;
}

.cluster-left .touch-btn[data-action='right'] {
  grid-area: 2 / 2;
}

.cluster-right .touch-btn[data-action='attack'] {
  grid-area: 1 / 1;
}

.cluster-right .touch-btn[data-action='jump'] {
  grid-area: 1 / 2;
}

.cluster-right .touch-btn[data-action='left'] {
  grid-area: 2 / 1;
}

.cluster-right .touch-btn[data-action='right'] {
  grid-area: 2 / 2;
}

.touch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--btn);
  height: var(--btn);
  padding: 0;
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.72);
  border: 2px solid rgba(148, 163, 184, 0.35);
  border-radius: 50%;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 12px rgba(0, 0, 0, 0.35);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.06s ease,
    background 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}

.touch-btn svg {
  width: 46%;
  height: 46%;
  pointer-events: none;
}

.touch-btn.jump {
  color: #bae6fd;
}

.touch-btn.attack {
  color: #fecdd3;
  border-color: rgba(251, 113, 133, 0.45);
}

.touch-btn.active {
  transform: scale(0.92);
  background: rgba(56, 189, 248, 0.35);
  border-color: rgba(125, 211, 252, 0.9);
  box-shadow:
    0 0 18px rgba(56, 189, 248, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.touch-btn.attack.active {
  background: rgba(244, 63, 94, 0.4);
  border-color: rgba(253, 164, 175, 0.95);
  box-shadow: 0 0 18px rgba(244, 63, 94, 0.6);
}

.touch-center {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding-bottom: 2px;
  pointer-events: auto;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 50%;
  font-family: system-ui, sans-serif;
  font-size: 18px;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.icon-btn:active {
  transform: scale(0.94);
  background: rgba(56, 189, 248, 0.3);
  border-color: rgba(125, 211, 252, 0.8);
}

.mobile-hint {
  display: none;
  margin: 0;
  font-size: 8px;
  line-height: 1.9;
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   Modo táctil
   ============================================================ */

.touch-mode .touch-controls {
  display: flex;
}

/* Los controles solo se muestran durante la partida para no tapar los overlays. */
.touch-mode:not(.is-playing) .touch-controls {
  visibility: hidden;
  pointer-events: none;
}

.touch-mode .legend,
.touch-mode .hint-desktop {
  display: none;
}

.touch-mode .hint-touch,
.touch-mode .mobile-hint {
  display: block;
}

.touch-mode .stage {
  width: min(100%, calc(100vh * 16 / 9));
  width: min(100%, calc(100dvh * 16 / 9));
  max-width: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (orientation: landscape) {
  .touch-mode .mobile-hint {
    display: none;
  }
}

@media (orientation: portrait) {
  .touch-mode .touch-controls {
    --btn: clamp(44px, 14vw, 60px);

    position: static;
    width: 100%;
    padding:
      12px
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .touch-mode .start-screen .tagline,
  .touch-mode .start-screen .hints {
    display: none;
  }
}

/* Móviles muy estrechos: mantiene todo dentro de la pantalla. */
@media (max-width: 360px) {
  .touch-center {
    gap: 4px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }
}

/* Pantalla completa: fondo sólido y sin bordes del navegador */
.game-shell:fullscreen {
  width: 100vw;
  height: 100dvh;
  background: var(--bg-0);
}

.game-shell:-webkit-full-screen {
  width: 100vw;
  height: 100dvh;
  background: var(--bg-0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
