:root {
  --bg: #120d1c;
  --panel: #1d1530;
  --panel-2: #271d40;
  --line: #3a2c5c;
  --text: #f4eefc;
  --muted: #b3a6cc;
  --red: #e6282f;
  --red-dark: #a8161c;
  --gold: #ffc828;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  /* fondo rojo con textura de pixeles (assets/bg_page.png, 64x64 mostrado a 4x sin suavizar) */
  background: #b2121a url(/assets/bg_page.png) repeat;
  background-size: 256px 256px;
  image-rendering: pixelated;
  color: var(--text);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
}

#app {
  image-rendering: auto;           /* el pixelado es solo para el fondo de la pagina */
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}
.topbar .icon-btn { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }

.logo {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(18px, 4vw, 28px);
  letter-spacing: 1px;
}
.logo { color: #fff; text-shadow: 3px 3px 0 rgba(40, 0, 4, 0.55); }
.logo-cap { color: inherit; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
.icon-btn[aria-pressed="true"] { color: var(--muted); text-decoration: line-through; }

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* Botones tactiles: solo en pantallas tactiles mientras se juega */
#touch {
  display: none;
  gap: 12px;
}
.touch-btn {
  flex: 1;
  min-height: 120px;
  border-radius: 14px;
  border: 3px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--pixel);
  font-size: 14px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.touch-btn.is-down { background: var(--line); transform: translateY(2px); }
.touch-jump { background: var(--red-dark); border-color: var(--red); }
.touch-jump.is-down { background: var(--red); }

.is-touch #app[data-state="playing"] #touch {
  display: flex;
  position: relative;
}
.is-touch .keys-hint { display: none; }

/* Celular acostado: el juego ocupa la pantalla y los botones van encima */
@media (orientation: landscape) and (max-height: 520px) {
  .is-touch #app[data-state="playing"] {
    padding: 0;
    max-width: none;
  }
  .is-touch #app[data-state="playing"] .topbar { display: none; }
  .is-touch #app[data-state="playing"] #stage {
    height: 100dvh;
    width: auto;
    margin: 0 auto;
    border: 0;
    border-radius: 0;
  }
  .is-touch #app[data-state="playing"] #touch {
    position: fixed;
    inset: auto 16px 16px 16px;
    justify-content: space-between;
  }
  .is-touch #app[data-state="playing"] .touch-btn {
    flex: 0 0 140px;
    min-height: 120px;
    opacity: 0.75;
  }
}

/* En vertical los botones van debajo del juego y todo queda centrado en la pantalla */
.is-touch #app[data-state="playing"],
.is-touch #app[data-state="countdown"] {
  min-height: 100dvh;
  justify-content: center;
}
.is-touch #app[data-state="countdown"] #touch { display: flex; }
.is-touch #app[data-state="countdown"] .touch-btn { opacity: 0.5; }

.keys-hint {
  margin: 0;
  text-align: center;
  color: #ffe9ea;
  font-size: 14px;
}
kbd {
  font-family: var(--pixel);
  font-size: 10px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel[hidden] { display: none; }
.panel h2 {
  margin: 0;
  font-family: var(--pixel);
  font-size: 16px;
  line-height: 1.5;
}

.muted { color: var(--muted); margin: 0; }
.small { font-size: 14px; }
.center { text-align: center; }

form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 15px; font-weight: 600; }
input[type="email"], input[type="text"], select {
  font: inherit;
  font-weight: 400;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--red); }
.check a { color: var(--gold); }
.form-error { margin: 0; color: #ff8a8f; font-weight: 600; }

.btn-primary {
  font-family: var(--pixel);
  font-size: 14px;
  padding: 16px;
  border-radius: 12px;
  border: 0;
  background: var(--red);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--red-dark);
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--red-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-play { font-size: 18px; padding: 20px; }

.link {
  font: inherit;
  color: var(--gold);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.hello p { margin: 0 0 4px; font-size: 18px; }

.result { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.result-label { margin: 0; font-family: var(--pixel); font-size: 12px; color: var(--muted); }
.result-score { margin: 0; font-family: var(--pixel); font-size: clamp(32px, 9vw, 52px); color: var(--gold); }
.ranks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.ranks div { background: var(--panel-2); border-radius: 10px; padding: 10px 6px; display: flex; flex-direction: column; gap: 6px; }
.ranks strong { font-family: var(--pixel); font-size: 14px; }

.board { display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 6px; }
.tabs button {
  flex: 1;
  font-family: var(--pixel);
  font-size: 11px;
  padding: 12px 8px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--text); border-color: var(--gold); }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rows li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 15px;
}
.rows li.me { outline: 2px solid var(--gold); }
.rows .pos { font-family: var(--pixel); font-size: 11px; color: var(--muted); }
.rows li:nth-child(1) .pos { color: var(--gold); }
.rows .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .pts { font-family: var(--pixel); font-size: 12px; }
.rows .empty { display: block; text-align: center; color: var(--muted); background: none; }

@media (max-width: 480px) {
  #app { padding: 10px 12px 24px; }
  .panel { padding: 16px; }
  .ranks strong { font-size: 12px; }
}

/* modo de registro: solo se muestran los campos del modo actual */
#app[data-mode="test"] [data-mode="live"],
#app[data-mode="test"] .js-live-info,
#app[data-mode="live"] [data-mode="test"],
#app[data-mode="live"] .js-test-info { display: none; }
#app[data-mode="test"] .ranks { grid-template-columns: repeat(2, 1fr); }

.lives {
  margin: 0;
  text-align: center;
  font-family: var(--pixel);
  font-size: 12px;
  line-height: 1.6;
  color: var(--gold);
}
.lives.is-empty { color: #ff8a8f; }

/* selector de personaje */
.picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 12px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--pixel);
  font-size: 13px;
}
.pick[aria-checked="true"] { border-color: var(--gold); background: var(--panel-2); color: var(--text); }
.pick-sprite {
  width: min(128px, 100%);
  margin: -12px 0 -4px;            /* el personaje ocupa el centro del cuadro de 64x64 */
  aspect-ratio: 1;
  background-repeat: no-repeat;
  background-size: 2100% 100%;     /* 21 cuadros en la hoja */
  background-position: 0 0;
}
.pick[aria-checked="true"] .pick-sprite { animation: pick-run 0.6s steps(9) infinite; }
@keyframes pick-run { from { background-position-x: 0%; } to { background-position-x: 45%; } }
/* el perro corre con 7 cuadros */
.pick[aria-checked="true"] .pick-sprite[data-run="7"] { animation: pick-run-7 0.5s steps(7) infinite; }
@keyframes pick-run-7 { from { background-position-x: 0%; } to { background-position-x: 35%; } }
@media (prefers-reduced-motion: reduce) { .pick[aria-checked="true"] .pick-sprite { animation: none; } }

/* aviso al desbloquear el personaje secreto */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 14px 18px;
  border-radius: 12px;
  background: var(--gold);
  color: #1a1206;
  font-family: var(--pixel);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 6px 0 #a87a00;
  z-index: 10;
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in { from { transform: translate(-50%, 20px); opacity: 0; } }
.logo { cursor: default; user-select: none; -webkit-user-select: none; }

/* ------------------------------------------------------------------ textos legales */

.field-hint { font-size: 13px; font-weight: 400; line-height: 1.45; color: var(--muted); }
.field-hint strong { color: var(--text); }
.result-note { margin: 4px 0 0; font-size: 14px; line-height: 1.5; color: var(--muted); }
.result-note strong { color: var(--text); }
.result-note a, .site-legal a { color: var(--gold); }

.site-legal { text-align: center; font-size: 13px; color: #ffe9ea; }
.site-legal a { color: #fff; }
/* mientras se juega no estorba (y no cuenta en el alto del lienzo vertical) */
#app[data-state="countdown"] .site-legal,
#app[data-state="playing"] .site-legal { display: none; }

.legal {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.legal-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.legal-top .logo { font-size: clamp(14px, 3.5vw, 20px); }
.legal-back { color: #fff; font-weight: 600; text-decoration: none; padding: 10px 0; }
.legal-back:hover { text-decoration: underline; }

.legal-doc {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: clamp(18px, 4vw, 32px);
  font-size: 16px;
  line-height: 1.65;
}
.legal-doc h1 { margin: 0; font-family: var(--pixel); font-size: clamp(16px, 4vw, 22px); line-height: 1.5; }
.legal-doc h2 { margin: 0 0 8px; font-size: 18px; line-height: 1.35; }
.legal-doc h3 { margin: 16px 0 6px; font-size: 16px; line-height: 1.4; color: var(--gold); }
.legal-doc section { margin-top: 28px; scroll-margin-top: 16px; }
.legal-doc p { margin: 0 0 10px; }
.legal-doc ul, .legal-doc ol { margin: 0 0 10px; padding-left: 22px; }
.legal-doc li { margin-bottom: 6px; }
.legal-doc li > ul { margin-top: 6px; }
.legal-doc a { color: var(--gold); }
.legal-date { color: var(--muted); font-size: 14px; margin-top: 6px !important; }

.legal-key {
  margin: 20px 0 0;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 2px solid var(--gold);
}
.legal-key h2 { font-family: var(--pixel); font-size: 12px; color: var(--gold); margin-bottom: 10px; }
.legal-key ul { margin: 0; }

.legal-toc { margin-top: 20px; font-size: 15px; }
.legal-toc ol { columns: 2 220px; column-gap: 24px; margin: 0; }
.legal-toc li { break-inside: avoid; margin-bottom: 4px; }

.legal-callout {
  padding: 12px 14px;
  border-left: 4px solid var(--red);
  background: rgba(230, 40, 47, 0.12);
  border-radius: 0 8px 8px 0;
}

.legal-links { text-align: center; font-size: 14px; color: #ffe9ea; }
.legal-links a { color: #fff; }
