:root {
  --neon-cyan: #00ffff;
  --neon-magenta: #ff00ff;
  --neon-green: #00ff00;
  --neon-red: #ff0000;
  --bg-color: #050505;
  --grid-color: rgba(0, 255, 255, 0.1);
  --grid-border: #00aaaa;
}

/* Kode Mono para dígitos, Orbitron para el resto */
@font-face {
  font-family: "Orbitron";
  font-weight: 400;
  src: url("https://fonts.gstatic.com/s/kodemono/v4/A2BYn5pb0QgtVEPFnlYOnYLw.woff2")
    format("woff2");
  unicode-range: U+0030-0039; /* dígitos 0–9 */
  size-adjust: 112%;
}
@font-face {
  font-family: "Orbitron";
  font-weight: 700;
  src: url("https://fonts.gstatic.com/s/kodemono/v4/A2BYn5pb0QgtVEPFnlYOnYLw.woff2")
    format("woff2");
  unicode-range: U+0030-0039; /* dígitos 0–9 */
  size-adjust: 112%;
}

body {
  font-family: "Orbitron", sans-serif;
  background-color: var(--bg-color);
  color: #fff;
  height: 100vh;
  margin: 0;
  overflow: hidden;
}

/* ── Game Background Canvas (Three.js tunnel) ────────────────────────────── */
#game-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen-card {
  background: linear-gradient(
    135deg,
    rgba(0, 20, 40, 0.9),
    rgba(0, 0, 0, 0.95)
  );
  padding: 40px;
  border-radius: 15px;
  text-align: center;
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 30px var(--neon-cyan);
  max-width: 480px;
  width: 90%;
}

.screen-card h2 {
  color: var(--neon-cyan);
  margin-top: 0;
  text-transform: uppercase;
}

#portada {
  background: transparent;
  overflow: hidden;
}
#juego {
  background: transparent;
  padding-bottom: 40px;
}
#juego h1 {
  margin-top: 0;
}
#game-over {
  background: transparent;
}
#ranking {
  background: transparent;
}

/* screen-card: margin:auto guarantees centering in the flex column */
.screen-card {
  margin: auto;
}


h1 {
  color: var(--neon-cyan);
  text-shadow:
    0 0 10px var(--neon-cyan),
    0 0 20px var(--neon-cyan);
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.score-board {
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: #fff;
  text-shadow: 0 0 5px var(--neon-magenta);
  border: 1px solid var(--neon-magenta);
  padding: 10px 20px;
  border-radius: 5px;
  background: rgba(30, 5, 30, 0.93);
  box-shadow: 0 0 10px rgba(255, 0, 255, 0.2);
  display: inline-block;
  min-width: 280px;
  text-align: center;
}

.score-board span {
  display: inline-block;
  min-width: 5.5ch;
  text-align: right;
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, 40px);
  grid-template-rows: repeat(10, 40px);
  gap: 2px;
  background-color: rgba(0, 0, 0, 0.8);
  border: 2px solid var(--neon-cyan);
  box-shadow:
    0 0 20px var(--neon-cyan),
    inset 0 0 20px var(--neon-cyan);
  margin: 0 auto;
  width: fit-content;
  padding: 5px;
  position: relative;
}

.grid::before {
  content: "";
  position: absolute;
  inset: -100px;
  background: radial-gradient(
    ellipse at center,
    rgba(5, 5, 5, 0.88) 30%,
    rgba(5, 5, 5, 0.5) 60%,
    transparent 100%
  );
  z-index: -1;
}

.cell {
  width: 40px;
  height: 40px;
  background-color: rgba(0, 255, 255, 0.05);
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(0, 255, 255, 0.1);
}

.player {
  background-color: transparent;
  color: transparent;
  /* Hide text */
  position: relative;
}

/* Sprites */
.player-sprite,
.enemy-sprite {
  position: absolute;
  width: 40px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  /* transition removed for instant movement */
  pointer-events: none;
  z-index: 5;
}

.player-sprite::after {
  content: "";
  width: 20px;
  height: 20px;
  background-color: var(--neon-green);
  border-radius: 50%;
  box-shadow:
    0 0 10px var(--neon-green),
    0 0 20px var(--neon-green);
  animation: pulse-player 1s infinite alternate;
}

.enemy-sprite::after {
  content: "";
  width: 24px;
  height: 24px;
  border: 2px solid var(--neon-magenta);
  background-color: rgba(255, 0, 255, 0.2);
  box-shadow:
    0 0 10px var(--neon-magenta),
    inset 0 0 10px var(--neon-magenta);
  transform: rotate(45deg);
  animation: spin-enemy 2s linear infinite;
}

/* Trail Particles */
.trail-particle {
  position: absolute;
  width: 40px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  z-index: 4;
  animation: fade-out 0.4s linear forwards;
}

.trail-particle.player-trail::after {
  content: "";
  width: 20px;
  height: 20px;
  background-color: var(--neon-green);
  border-radius: 50%;
  opacity: 0.5;
  box-shadow: 0 0 5px var(--neon-green);
}

.trail-particle.enemy-trail::after {
  content: "";
  width: 24px;
  height: 24px;
  border: 1px solid var(--neon-magenta);
  background-color: rgba(255, 0, 255, 0.4);
  /* Increased opacity */
  box-shadow: 0 0 5px var(--neon-magenta);
  /* Added glow */
  transform: rotate(45deg);
}

.trail-particle.blade-trail::after {
  content: "";
  width: 60px;
  height: 60px;
  flex-shrink: 0;   /* prevent flexbox from shrinking below disc size */
  background-color: var(--neon-red);
  border-radius: 50%;
  opacity: 0.28;
  box-shadow: 0 0 8px var(--neon-red), 0 0 18px var(--neon-red);
}

@keyframes fade-out {
  0% {
    opacity: 0.6;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.5);
  }
}

/* ── Game Over Background Canvas (Digital Corruption) ───────────────────── */
#game-over-bg {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#game-over-bg.active {
  display: block;
}

/* ── Game Over 3D Background Canvas ──────────────────────────────────────── */
#game-over-3d-bg {
  position: fixed;
  inset: 0;
  z-index: 40; /* Behind glitch effects but in front of game-bg if needed */
  display: none;
  width: 100%;
  height: 100%;
}
#game-over-3d-bg.active {
  display: block;
}

.hidden {
  display: none !important;
}

.final-score-hero {
  font-size: 2rem;
  color: #fff;
  text-shadow:
    0 0 20px rgba(255, 255, 255, 0.6),
    0 0 40px rgba(255, 255, 255, 0.3);
  letter-spacing: 4px;
  margin-bottom: 4px;
  line-height: 1;
}

.final-score-label {
  display: block;
  font-size: 0.7rem;
  color: #fff;
  text-shadow: none;
  letter-spacing: 3px;
  margin-bottom: 6px;
}

button {
  background-color: transparent;
  color: var(--neon-green);
  border: 2px solid var(--neon-green);
  padding: 15px 30px;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 5px;
  margin-top: 20px;
  font-family: "Orbitron", sans-serif;
  text-transform: uppercase;
  transition: all 0.3s ease;
  box-shadow: 0 0 10px rgba(0, 255, 0, 0.2);
}

button:hover,
button:focus-visible {
  background-color: var(--neon-green);
  color: #000;
  box-shadow: 0 0 20px var(--neon-green);
  outline: none;
}

.controls-hint {
  margin-top: 20px;
  color: #888;
  font-size: 0.9rem;
}

/* Shockwave Effect */
.shockwave {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--neon-magenta);
  background: transparent;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: shockwave-anim 0.8s ease-out forwards;
  z-index: 20;
}

@keyframes shockwave-anim {
  0% {
    width: 0;
    height: 0;
    opacity: 1;
    border-width: 5px;
  }

  100% {
    width: 500px;
    height: 500px;
    opacity: 0;
    border-width: 0;
  }
}

/* ── Score Ticker ─────────────────────────────────────────────────────────── */
.score-ticker-wrap {
  overflow: hidden;
  width: 100%;
}

.score-ticker {
  overflow: hidden;
  white-space: nowrap;
}

.score-ticker-inner {
  display: inline-block;
  animation: ticker-scroll 10s linear infinite;
}

.ticker-item {
  display: inline-block;
  margin: 0 14px;
  font-size: 0.75rem;
  color: rgba(0, 255, 255, 0.7);
  letter-spacing: 1px;
  transition:
    color 0.3s,
    text-shadow 0.3s;
}

.ticker-item.ticker-highlight {
  color: var(--neon-cyan);
  text-shadow:
    0 0 8px var(--neon-cyan),
    0 0 16px var(--neon-cyan);
  animation: ticker-pulse 3s ease-in-out;
}

@keyframes ticker-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

@keyframes ticker-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

/* ── Ranking Section ─────────────────────────────────────────────────────── */
.ranking-section {
  margin-top: 16px;
  text-align: left;
}

.ranking-status {
  font-size: 0.85rem;
  color: var(--neon-cyan);
  text-align: center;
  margin-top: 6px;
  margin-bottom: 16px;
  text-shadow: 0 0 6px var(--neon-cyan);
  min-height: 1.2em;
}

/* Initials form */
.initials-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.initials-form label {
  font-size: 0.75rem;
  color: #aaa;
  letter-spacing: 1px;
}

.initials-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

#initials-input {
  background: rgba(0, 255, 255, 0.05);
  border: 2px solid var(--neon-cyan);
  color: var(--neon-cyan);
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  text-align: center;
  letter-spacing: 6px;
  width: 90px;
  height: 3rem;
  padding: 0 4px;
  border-radius: 4px;
  outline: none;
  text-transform: uppercase;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.2);
  box-sizing: border-box;
}

#initials-input:focus {
  box-shadow: 0 0 14px var(--neon-cyan);
}

#save-score-btn {
  height: 3rem;
  padding: 0 20px;
  font-size: 1rem;
  margin-top: 0;
  box-sizing: border-box;
}

/* Continue button inside ranking section */
#continue-btn {
  display: block;
  margin: 20px auto 0;
  padding: 8px 24px;
  font-size: 0.85rem;
}

/* Reboot button inside ranking section */
#restart-btn {
  display: block;
  margin: 16px auto 0;
}

/* Ranking list */
.ranking-list-wrap {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid rgba(0, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  scrollbar-width: thin;
  scrollbar-color: var(--neon-cyan) transparent;
}

.ranking-list-wrap::-webkit-scrollbar {
  width: 4px;
}
.ranking-list-wrap::-webkit-scrollbar-track {
  background: transparent;
}
.ranking-list-wrap::-webkit-scrollbar-thumb {
  background: var(--neon-cyan);
  border-radius: 2px;
}

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ranking-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 12px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  gap: 8px;
}

.ranking-item:last-child {
  border-bottom: none;
}

.rank-pos {
  color: rgba(0, 255, 255, 0.5);
  min-width: 40px;
}

.rank-initials {
  flex: 1;
  letter-spacing: 2px;
}

.rank-score {
  color: var(--neon-green);
  text-shadow: 0 0 4px var(--neon-green);
  min-width: 50px;
  text-align: right;
}

/* Player's own row in the ranking */
.ranking-item.player-row {
  background: rgba(0, 255, 255, 0.1);
  border: 1px solid var(--neon-cyan);
  border-radius: 3px;
  color: #fff;
}

.ranking-item.player-row .rank-pos {
  color: var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
}

.ranking-item.player-row .rank-initials {
  color: var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
}

/* ── Start Screen Three.js Canvas ────────────────────────────────────────── */
#start-bg {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  z-index: 0;
}
#start-bg.active {
  display: block;
}

#version-tag {
  position: absolute;
  bottom: 10px;
  right: 15px;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 1px;
  z-index: 100;
  pointer-events: none;
}

/* ── Start Screen Floating Content ───────────────────────────────────────── */
.start-content {
  position: relative;
  z-index: 10;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 16rem;
  padding: 40px 50px;
  border-radius: 15px;
  border: 2px solid var(--neon-cyan);
  background: linear-gradient(
    135deg,
    rgba(0, 20, 40, 0.85),
    rgba(0, 0, 0, 0.92)
  );
  box-shadow:
    0 0 20px var(--neon-cyan),
    inset 0 0 20px rgba(0, 255, 255, 0.03);
}

.start-title {
  font-size: clamp(2.5rem, 5vw, 4rem);
  color: var(--neon-cyan);
  text-shadow:
    0 0 10px var(--neon-cyan),
    0 0 30px var(--neon-cyan),
    0 0 60px var(--neon-cyan);
  letter-spacing: 6px;
  margin: 0 0 1.5rem;
}

.start-copy {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.75);
  margin: 0.15rem 0;
  letter-spacing: 1px;
}

/* ── Start Screen Ticker (anchored bottom, faded edges) ──────────────────── */
#portada .score-ticker-wrap {
  position: absolute;
  bottom: 35%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  max-width: 90vw;
  padding: 5px 0;
  background: rgba(0, 0, 0, 0.78);
  border-top: 1px solid rgba(0, 255, 255, 0.45);
  border-bottom: 1px solid rgba(0, 255, 255, 0.45);
  mask-image: linear-gradient(
    to right,
    transparent 0%,
    black 12%,
    black 88%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0%,
    black 12%,
    black 88%,
    transparent 100%
  );
}

/* ── Pregame Countdown ───────────────────────────────────────────────────── */
#countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  z-index: 20;
}

#countdown-num {
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  font-size: 200px;
  line-height: 1;
  color: var(--neon-cyan);
  text-shadow:
    0 0 20px var(--neon-cyan),
    0 0 60px var(--neon-cyan),
    0 0 100px var(--neon-cyan);
  animation: countdown-pop 800ms ease-out forwards;
}

@keyframes countdown-pop {
  0%   { transform: scale(1);   opacity: 1; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* ── Power-ups ───────────────────────────────────────────────────────────── */
.powerup {
  position: absolute;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 0 6px var(--grid-border));
}

/* Frozen enemies — neon teal tint
   hue-rotate(240deg): magenta(300°) → cyan(180°)
   The box-shadow glow on ::after also shifts, giving a vivid neon look */
.frozen {
  filter: hue-rotate(240deg) brightness(1.3);
}

/* Frozen-warning enemies — same tint + rapid blink */
.frozen-warning {
  filter: hue-rotate(240deg) brightness(1.3);
  animation: freeze-blink 0.1s step-end infinite;
}

@keyframes freeze-blink {
  0%  { opacity: 1; }
  50% { opacity: 0.2; }
}

/* Collection wave — expanding ring from pickup point */
.powerup-wave {
  position: absolute;
  width: 0;
  height: 0;
  border-radius: 50%;
  border: 2px solid var(--grid-border);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: powerup-wave-expand 0.5s ease-out forwards;
}

@keyframes powerup-wave-expand {
  0%   { width: 0;    height: 0;    opacity: 0.8; }
  100% { width: 80px; height: 80px; opacity: 0;   }
}


/* Bomb / Laser / Blade power-ups — red neon glow */
.powerup-bomb,
.powerup-laser,
.powerup-blade {
  filter: drop-shadow(0 0 4px var(--neon-red)) drop-shadow(0 0 10px var(--neon-red));
}

/* Bomb explosion — expanding neon square (same pattern as .grid border, in red) */
.bomb-explosion {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 2px solid var(--neon-red);
  box-shadow:
    0 0 20px var(--neon-red),
    inset 0 0 20px var(--neon-red);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: bomb-expand 350ms linear forwards;
  z-index: 4;
}

.bomb-explosion-inner {
  position: absolute;
  inset: 0;
  animation: bomb-inner-fade 350ms linear forwards;
}

@keyframes bomb-expand {
  0%   { width: 40px;  height: 40px; }
  100% { width: 294px; height: 294px; } /* 2 × 3.5 gu × 42px = 294px */
}

@keyframes bomb-inner-fade {
  0%   { opacity: 1; }
  100% { opacity: 1; }
}

/* Enemy death diamond — neon red rotated square */
.enemy-death-diamond {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--neon-red);
  box-shadow: 0 0 6px var(--neon-red);
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(45deg);
  animation: death-diamond-fade 400ms ease-out forwards;
  z-index: 4;
}

@keyframes death-diamond-fade {
  0%   { opacity: 1;   transform: translate(-50%, -50%) rotate(45deg) scale(1);   }
  100% { opacity: 0;   transform: translate(-50%, -50%) rotate(45deg) scale(2.5); }
}

/* Laser beam — horizontal and vertical bars forming a cross.
   Animation duration must match POWERUP_REGISTRY laser.duration (in seconds). */
.laser-beam-h {
  position: absolute;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--neon-red);
  box-shadow: 0 0 8px var(--neon-red), 0 0 20px var(--neon-red);
  pointer-events: none;
  z-index: 4;
  animation: laser-fade 1000ms ease-out forwards;
}

.laser-beam-v {
  position: absolute;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--neon-red);
  box-shadow: 0 0 8px var(--neon-red), 0 0 20px var(--neon-red);
  pointer-events: none;
  z-index: 4;
  animation: laser-fade 1000ms ease-out forwards;
}

@keyframes laser-fade {
  0%, 80% { opacity: 1; }
  100%    { opacity: 0; }
}

/* ── Blade disc ─────────────────────────────────────────────────────────────── */
.blade-disc {
  position: absolute;
  width:  60px;
  height: 60px;
  pointer-events: none;
  z-index: 4;
  filter: drop-shadow(0 0 8px var(--neon-red)) drop-shadow(0 0 18px var(--neon-red));
  animation: blade-spin 0.8s linear infinite;
}

.blade-disc.blade-warning {
  animation: blade-spin 0.8s linear infinite, blade-blink 0.25s ease-in-out infinite;
}

@keyframes blade-spin {
  to { transform: rotate(-360deg); }
}

@keyframes blade-blink {
  0%, 100% { opacity: 1;   }
  50%       { opacity: 0.2; }
}

/* ── Enemy Spawn Portal ──────────────────────────────────────────────────── */
.spawn-portal {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--neon-magenta) 0%, rgba(255,0,255,0.4) 40%, transparent 70%);
  filter: blur(4px);
  pointer-events: none;
  z-index: 2;
  animation: portal-open 1s linear forwards;
}

.spawn-portal.frozen {
  animation-play-state: paused;
  filter: blur(4px) hue-rotate(240deg) brightness(1.3);
}

@keyframes portal-open {
  0%   { transform: scale(0);    opacity: 0;    }  /* apertura */
  20%  { transform: scale(0.8);  opacity: 0.75; }  /* abierto en 0.8 */
  36%  { transform: scale(1.25); opacity: 0.95; }  /* pulso 1 ↑ */
  52%  { transform: scale(0.8);  opacity: 0.75; }  /* pulso 2 ↓ */
  68%  { transform: scale(1.25); opacity: 0.95; }  /* pulso 3 ↑ */
  84%  { transform: scale(0.8);  opacity: 0.75; }  /* pulso 4 ↓ */
  100% { transform: scale(1.25); opacity: 0.95; }  /* pulso 5 ↑ — final */
}

/* Power-up expiry warning — rapid blink before disappearing */
.powerup-expiring {
  animation: powerup-blink 0.2s step-end infinite;
}

@keyframes powerup-blink {
  0%  { opacity: 1;   }
  50% { opacity: 0.1; }
}

/* ── Controls hint (portada) ─────────────────────────────────────────────── */
.hint-touch   { display: none; }
.hint-desktop { display: inline; }

@media (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch   { display: inline; }

  /* Portada: reduce margin and padding so the card fits portrait */
  .start-content {
    margin-bottom: 2rem;
    padding: 24px 28px;
  }

  /* Ticker: drop to bottom so it doesn't overlap the card on tablets */
  #portada .score-ticker-wrap {
    bottom: 4%;
  }

  /* Game over / ranking cards: cap to desktop width, leave margin on phones */
  .screen-card {
    padding: 24px 20px;
    box-sizing: border-box;
    max-width: min(480px, calc(100% - 24px));
  }

  /* Score board: single line, smaller font on narrow phones */
  .score-board {
    white-space: nowrap;
    font-size: 1rem;
    padding: 7px 14px;
  }
}

/* ── Grid wrapper (desktop: transparent pass-through) ────────────────────── */
#game-grid-wrapper {
  display: contents;
}

/* ── Touch D-pad ─────────────────────────────────────────────────────────── */
#touch-dpad {
  display: none;
  position: relative;
  z-index: 15; /* above player (5) and enemies (4) to prevent bleed-through */
  /* Phones: limited by viewport width. Tablets: bigger cap (340px) */
  width: min(55vw, 340px);
  aspect-ratio: 1;
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  border: 2px solid var(--grid-border);
  box-shadow: 0 0 16px var(--grid-border), inset 0 0 16px rgba(0, 170, 170, 0.08);
  background-color: rgba(5, 5, 5, 0.65);
  will-change: transform; /* forces own GPU compositing layer */
  /* X diagonal separator */
  background-image:
    linear-gradient(135deg,
      transparent calc(50% - 1px),
      rgba(0, 170, 170, 0.45) calc(50% - 1px),
      rgba(0, 170, 170, 0.45) calc(50% + 1px),
      transparent calc(50% + 1px)),
    linear-gradient(45deg,
      transparent calc(50% - 1px),
      rgba(0, 170, 170, 0.45) calc(50% - 1px),
      rgba(0, 170, 170, 0.45) calc(50% + 1px),
      transparent calc(50% + 1px));
}

.dpad-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 170, 170, 0.6);
  font-size: clamp(22px, 7vw, 40px);
  transition: background 0.06s, color 0.06s;
}

.dpad-zone[data-dir="up"]    { clip-path: polygon(0 0, 100% 0, 50% 50%); align-items: flex-start; padding-top: 8%; }
.dpad-zone[data-dir="down"]  { clip-path: polygon(0 100%, 100% 100%, 50% 50%); align-items: flex-end; padding-bottom: 8%; }
.dpad-zone[data-dir="left"]  { clip-path: polygon(0 0, 0 100%, 50% 50%); justify-content: flex-start; padding-left: 8%; }
.dpad-zone[data-dir="right"] { clip-path: polygon(100% 0, 100% 100%, 50% 50%); justify-content: flex-end; padding-right: 8%; }

.dpad-zone.active {
  background: rgba(0, 255, 255, 0.22);
  color: var(--neon-cyan);
  filter: drop-shadow(0 0 6px var(--neon-cyan));
}

/* ── Responsive portrait layout (touch devices) ──────────────────────────── */
@media (pointer: coarse) {
  #game-grid-wrapper {
    display: block;
    flex-shrink: 0;
    transform-origin: top center;
    isolation: isolate; /* grid compositing group: glows stay contained inside */
  }

  /* Hide the vignette that extends 100px around the grid — on touch it
     overlaps the score board and title when they are close to the grid */
  .grid::before {
    display: none;
  }

  #juego {
    /* space-between: score at top, grid centered, dpad at bottom */
    justify-content: space-between;
    padding: 10px 0 16px;
    overflow: hidden;
  }

  #juego h1 {
    display: none;
  }

  /* Score board: match grid width, keep margin on narrow screens */
  .score-board {
    min-width: unset;
    max-width: min(90vw, 432px);
    width: auto;
    flex-shrink: 0;
    margin-left: 12px;
    margin-right: 12px;
    box-sizing: border-box;
  }

  #touch-dpad {
    display: block;
  }
}

/* Grid scale by viewport width (grid natural size ≈ 432px) */
@media (pointer: coarse) and (max-width: 430px) {
  #game-grid-wrapper {
    transform: scale(0.97);
    margin-bottom: calc(-432px * 0.03);
  }
}
@media (pointer: coarse) and (max-width: 395px) {
  #game-grid-wrapper {
    transform: scale(0.88);
    margin-bottom: calc(-432px * 0.12);
  }
}
@media (pointer: coarse) and (max-width: 365px) {
  #game-grid-wrapper {
    transform: scale(0.82);
    margin-bottom: calc(-432px * 0.18);
  }
}
@media (pointer: coarse) and (max-width: 330px) {
  #game-grid-wrapper {
    transform: scale(0.74);
    margin-bottom: calc(-432px * 0.26);
  }
}

/* iPad-like layout: enough height to show title and use PC-style stacking */
@media (pointer: coarse) and (min-height: 850px) {
  #juego h1 {
    display: block;
    margin-top: auto; /* split free space: half above title, half above dpad */
  }
  #juego {
    justify-content: flex-start;
  }
  #touch-dpad {
    margin-top: auto; /* split free space: half above title, half above dpad */
  }
}

/* Grid scale by viewport HEIGHT: short phones need extra reduction */
/* Ensures dpad is always fully visible. Score(50) + gap(26) + dpad(min 160) = 236px */
@media (pointer: coarse) and (max-height: 760px) {
  #game-grid-wrapper {
    transform: scale(0.80);
    margin-bottom: calc(-432px * 0.20);
  }
}
@media (pointer: coarse) and (max-height: 680px) {
  #game-grid-wrapper {
    transform: scale(0.72);
    margin-bottom: calc(-432px * 0.28);
  }
}
