* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  background: #000;
  color: #fff;
  font-family: "Courier New", Courier, monospace;
  font-weight: bold;
  text-transform: uppercase;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* iOS: sin menú de "mantener pulsado" */
}

/* iOS Safari: el documento entero queda fijo y sin gestos del navegador (scroll encadenado a la
   página de itch.io, rebote, zoom), así cualquier dedo dentro del juego llega al juego */
html {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

#screen,
#screen canvas {
  touch-action: none;
}

/* game.js fija el tamaño exacto según la pantalla y la orientación */
#screen {
  position: relative;
  box-shadow: 0 0 0 3px #fff;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

#hud {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: clamp(9px, 1.6vmax, 14px);
  letter-spacing: 1px;
  opacity: 0.7;
  pointer-events: none;
}

button {
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: clamp(12px, 2vmax, 18px);
  color: #fff;
  background: #000;
  border: 3px solid #fff;
  padding: 8px 16px;
  cursor: pointer;
  min-width: 150px;
  touch-action: manipulation;
}

button:hover,
button:focus-visible,
button.selected {
  background: #fff;
  color: #000;
  outline: none;
}

button.big {
  font-size: clamp(16px, 3vmax, 26px);
  padding: 10px 32px;
}

/* Pausa sobre la línea central, lejos de las paletas */
button.corner {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 16px;
  letter-spacing: 0;
  opacity: 0.8;
}

#screen.portrait button.corner {
  top: 50%;
  left: auto;
  right: 6px;
  transform: translateY(-50%);
}

/* En el RogueLike (horizontal) el centro lo ocupa el marcador y en KrostNoid los ladrillos: pausa arriba a la derecha */
#screen.knoid button.corner,
#screen.rogue:not(.portrait) button.corner {
  top: 6px;
  left: auto;
  right: 6px;
  transform: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2.2vmin, 18px);
  background: #000;
  text-align: center;
  padding: 16px;
  overflow: auto;
}

.overlay > * {
  max-width: 100%;
}

.overlay.translucent {
  background: rgba(0, 0, 0, 0.82);
}

/* Menú: deja ver la partida de demostración que se juega de fondo */
#menu {
  background: rgba(0, 0, 0, 0.6);
  text-shadow: 2px 2px 0 #000;
}

#menu button {
  text-shadow: none;
}

/* Menú en estilo moderno: colores, título con sombra pixelada y botones que brillan */
#screen.modern #menu {
  background: radial-gradient(ellipse at center, rgba(10, 40, 10, 0.35), rgba(5, 20, 5, 0.75));
}

#screen.modern #menu h1 {
  color: #ffd23f;
  text-shadow: 4px 4px 0 #ff5a4f, 8px 8px 0 #1d5fa8;
}

#screen.modern .overlay button {
  border-color: #7ee05a;
  background: rgba(10, 40, 10, 0.7);
  color: #e8ffe0;
}

#screen.modern .overlay button:hover,
#screen.modern .overlay button:focus-visible {
  background: #7ee05a;
  color: #0d2b0d;
}

#screen.modern #menu button.selected {
  background: #7ee05a;
  color: #0d2b0d;
  box-shadow: 0 0 10px #7ee05a, 0 0 22px rgba(126, 224, 90, 0.6);
}

#screen.modern #menu button[data-style="modern"].selected {
  background: #ffd23f;
  border-color: #fff3b0;
  animation: glow 1.4s ease-in-out infinite alternate;
}

@keyframes glow {
  from { box-shadow: 0 0 8px #ffd23f, 0 0 16px rgba(255, 210, 63, 0.5); }
  to { box-shadow: 0 0 16px #ffd23f, 0 0 36px rgba(255, 90, 79, 0.75); }
}

#screen.modern #menu .credit {
  color: #ffd23f;
}

@media (prefers-reduced-motion: reduce) {
  #screen.modern #menu button[data-style="modern"].selected { animation: none; }
}

h1 {
  font-size: clamp(44px, 11vmin, 120px);
  letter-spacing: 0.25em;
  margin-right: -0.25em;
  line-height: 1;
}

h2 {
  font-size: clamp(22px, 5vmin, 44px);
  letter-spacing: 4px;
}

#final {
  font-size: clamp(28px, 6vmin, 56px);
  letter-spacing: 8px;
}

.modes {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.help {
  font-size: clamp(9px, 1.5vmax, 14px);
  line-height: 1.7;
  opacity: 0.75;
}

.info {
  font-size: clamp(10px, 1.7vmax, 15px);
  letter-spacing: 1px;
  color: #ffd23f;
}

/* Resultados: récord y tabla de mejores puntuaciones */
#record-line {
  font-size: clamp(14px, 2.6vmax, 22px);
  letter-spacing: 3px;
  color: #ffd23f;
}

#record-line.new-record {
  font-size: clamp(18px, 3.6vmax, 30px);
  animation: record 0.6s ease-in-out infinite alternate;
}

@keyframes record {
  from { color: #ffd23f; text-shadow: 0 0 6px #ffd23f, 3px 3px 0 #ff5a4f; transform: scale(1); }
  to { color: #ffffff; text-shadow: 0 0 18px #ffd23f, 3px 3px 0 #3fa7ff; transform: scale(1.12); }
}

#board {
  list-style: none;
  font-size: clamp(10px, 1.6vmax, 14px);
  line-height: 1.6;
  letter-spacing: 1px;
  opacity: 0.9;
}

#board li.mine {
  color: #ffd23f;
}

@media (prefers-reduced-motion: reduce) {
  #record-line.new-record { animation: none; }
}

.credit {
  margin-top: clamp(4px, 2vmin, 16px);
  font-size: clamp(10px, 1.6vmax, 15px);
  letter-spacing: 3px;
}

#msg {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translate(-50%, -50%);
  background: #000;
  border: 3px solid #fff;
  padding: 6px 18px;
  font-size: clamp(16px, 3.5vmin, 30px);
  letter-spacing: 4px;
  pointer-events: none;
  white-space: nowrap;
}

/* Modo moderno: marco y mensajes a color; overlays más transparentes para ver el confeti */
#screen.modern {
  box-shadow: 0 0 0 3px #7ee05a;
}

#screen.modern .overlay.translucent {
  background: rgba(10, 30, 10, 0.55);
}

#screen.modern #msg {
  background: #1f4d1d;
  border-color: #ffd23f;
  color: #ffd23f;
}

/* --- RogueLike: HUD con insignias (piso, rival, monedas) --- */
#hud.rogue-hud {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  opacity: 1;
  max-width: calc(100% - 70px);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: clamp(9px, 1.5vmax, 13px);
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 1px 1px 0 #000;
}

.pill.floor.grass { border-color: #7ee05a; background: rgba(30, 80, 25, 0.8); }
.pill.floor.ice { border-color: #9fe6ff; background: rgba(30, 70, 100, 0.8); }
.pill.floor.lava { border-color: #ff7a1f; background: rgba(90, 30, 15, 0.85); }
.pill.enemy.boss { border-color: #ff5a4f; color: #ffb3ad; }
.pill.hearts { border-color: #ff4d5e; color: #ffb3bc; }
.pill.coins { border-color: #ffd23f; color: #ffd23f; }

/* Moneda pixelada: círculo dorado con borde oscuro y brillo */
i.coin {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3b0 0 18%, #ffd23f 20% 60%, #c99a12 62%);
  box-shadow: 0 0 0 1px #6b4e08;
}

.pill.coins.bump {
  animation: coin-bump 0.35s ease-out;
}

@keyframes coin-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); box-shadow: 0 0 10px #ffd23f; }
  100% { transform: scale(1); }
}

.pill .dots {
  display: inline-flex;
  gap: 3px;
}

.pill .dot {
  width: 6px;
  height: 6px;
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.pill .dot.done { background: #fff; }
.pill .dot.current { background: #ffd23f; border-color: #ffd23f; }
.pill .dot.boss { border-color: #ff5a4f; }

#rogue-sub {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- RogueLike: mapa, puertas y cartas --- */
.rogue-map {
  display: flex;
  gap: 8px;
  align-items: center;
}

.rogue-map .node {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.rogue-map .node.done {
  background: #7ee05a;
  border-color: #7ee05a;
  color: #0d2b0d;
}

.rogue-map .node.current {
  border-color: #ffd23f;
  box-shadow: 0 0 8px #ffd23f;
}

.rogue-map .node.boss {
  border-color: #ff5a4f;
  color: #ff5a4f;
}

.cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Cartas y puertas (doble id para ganar al estilo general de botones del modo moderno) */
#screen #rogue button.card,
#screen #rogue button.door {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: clamp(118px, 23vmax, 190px);
  min-width: 0;
  padding: 10px 8px;
  white-space: normal;
  letter-spacing: 1px;
  font-size: clamp(10px, 1.5vmax, 14px);
  color: #fff;
  background: rgba(8, 18, 28, 0.88);
  border: 3px solid #c8d0d8;
  transition: transform 0.1s;
}

#screen #rogue button.card:hover:not(:disabled),
#screen #rogue button.door:hover,
#screen #rogue button.card:focus-visible,
#screen #rogue button.door:focus-visible {
  transform: translateY(-3px);
  background: rgba(30, 50, 70, 0.95);
  color: #fff;
}

#screen #rogue button.card:disabled {
  opacity: 0.4;
  cursor: default;
}

#rogue .card .rarity,
#rogue .door .desc {
  font-size: 0.75em;
  opacity: 0.8;
}

#rogue .card .name,
#rogue .door .name {
  font-size: 1.15em;
}

#rogue .card .desc {
  font-size: 0.8em;
  line-height: 1.35;
  font-weight: normal;
  opacity: 0.9;
}

#rogue .card .price {
  color: #ffd23f;
}

#screen #rogue button.card.rare {
  border-color: #3fa7ff;
  box-shadow: 0 0 10px rgba(63, 167, 255, 0.5);
}

#screen #rogue button.card.legendary {
  border-color: #ffd23f;
  animation: legendary 1.2s ease-in-out infinite alternate;
}

@keyframes legendary {
  from { box-shadow: 0 0 6px rgba(255, 210, 63, 0.5); }
  to { box-shadow: 0 0 18px rgba(255, 210, 63, 0.9); }
}

#rogue .card.rare .rarity { color: #9fd4ff; }
#rogue .card.legendary .rarity { color: #ffd23f; }

#screen #rogue button.door.combat { border-color: #7ee05a; }
#screen #rogue button.door.elite { border-color: #b07cff; box-shadow: 0 0 10px rgba(176, 124, 255, 0.5); }
#screen #rogue button.door.shop { border-color: #ffd23f; }
#screen #rogue button.door.rest { border-color: #3fa7ff; }
#screen #rogue button.door.boss { border-color: #ff5a4f; box-shadow: 0 0 14px rgba(255, 90, 79, 0.7); }

#rogue-note {
  max-width: 90%;
}

@media (prefers-reduced-motion: reduce) {
  #screen #rogue button.card.legendary { animation: none; }
}

/* Pantallas bajas (móvil en horizontal): menú más compacto */
@media (max-height: 460px) {
  .overlay { gap: 5px; padding: 8px; }
  h1 { font-size: 36px; }
  button { padding: 4px 12px; }
  button.big { padding: 5px 24px; font-size: 18px; }
  .help { line-height: 1.35; font-size: 9px; }
  .credit { margin-top: 0; }
  #screen #rogue button.card,
  #screen #rogue button.door { padding: 6px; gap: 2px; }
}

/* Botón seleccionado con el mando o las flechas: mismo aspecto que al pasar el ratón, con contorno */
button.pad-focus,
#screen.modern .overlay button.pad-focus {
  background: #fff;
  color: #000;
  outline: 3px solid #ffd23f;
  outline-offset: 3px;
}

#screen #rogue button.card.pad-focus,
#screen #rogue button.door.pad-focus {
  transform: translateY(-3px);
  outline: 3px solid #ffd23f;
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}
