* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #1d1f24;
  font-family: ui-monospace, "Courier New", monospace;
  color: #e8eaed;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  background: linear-gradient(#10141c, #1b2029 60%, #262c38);
}

/* FIX canvas: contenedor exclusivo del canvas de Phaser */
#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#game-canvas canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ---------- Pantallas ---------- */
#start-screen,
#game-over-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(10, 10, 20, 0.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#start-screen {
  background: rgba(10, 13, 20, 0.94);
  backdrop-filter: blur(4px);
}

#start-screen h1 {
  font-size: clamp(1.8rem, 7vw, 3rem);
  margin: 0;
  letter-spacing: 1px;
}

#start-screen p {
  margin: 0;
  color: #9aa4b2;
  font-size: clamp(0.8rem, 3.2vw, 1rem);
  max-width: 420px;
}

#alias-input {
  font: inherit;
  font-size: clamp(1rem, 4vw, 1.4rem);
  padding: 12px 16px;
  width: min(360px, 80vw);
  text-align: center;
  border-radius: 10px;
  border: 2px solid #3a4454;
  background: #131822;
  color: #e8eaed;
  outline: none;
}

#alias-input:focus { border-color: #4cc2ff; }

/* ---------- Botones ---------- */
.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  font: inherit;
  font-size: clamp(0.9rem, 3.6vw, 1.1rem);
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  background: #4cc2ff;
  color: #06121b;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
  touch-action: manipulation;
}

button:active { transform: scale(0.96); }
button:disabled { filter: grayscale(0.6) brightness(0.7); cursor: progress; }

button.ghost {
  background: transparent;
  color: #9aa4b2;
  border: 2px solid #3a4454;
}

.error {
  color: #ff6b6b;
  font-size: clamp(0.75rem, 3vw, 0.9rem);
  min-height: 1.2em;
  margin: 0;
}

/* ---------- HUD ---------- */
#ui {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 18px;
  pointer-events: none;
}

#hud-left { display: flex; flex-direction: column; gap: 2px; text-align: left; }
#hud-alias { font-size: clamp(0.7rem, 2.8vw, 0.9rem); color: #9aa4b2; letter-spacing: 1px; }
#hud-score { font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 700; color: #4cc2ff; font-variant-numeric: tabular-nums; }
#hud-speed { font-size: clamp(0.75rem, 3vw, 0.95rem); color: #9aa4b2; font-variant-numeric: tabular-nums; }

/* ---------- Game over ---------- */
#game-over-screen h2 {
  margin: 0;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  color: #ff6b6b;
  letter-spacing: 2px;
}

.final {
  margin: 0;
  font-size: clamp(0.95rem, 4vw, 1.2rem);
  color: #c7cdd6;
}

#final-score-text { color: #4cc2ff; font-weight: 700; font-size: 1.3em; }

#position-line {
  font-size: clamp(0.8rem, 3.4vw, 1rem);
  color: #9aa4b2;
}

#position-line strong { color: #ffd166; font-size: 1.2em; }

#game-over-screen h3 {
  margin: 6px 0 0;
  font-size: clamp(0.8rem, 3.4vw, 1rem);
  letter-spacing: 3px;
  color: #9aa4b2;
}

#top3-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(400px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #161b24;
  border: 1px solid #2a3342;
  font-size: clamp(0.85rem, 3.6vw, 1rem);
}

.rank-item.first {
  background: linear-gradient(90deg, #3a2f10, #1c1f26);
  border-color: #ffd166;
}

.rank-item.me {
  border-color: #4cc2ff;
  box-shadow: 0 0 0 1px #4cc2ff inset;
}

.rank-alias { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { color: #4cc2ff; font-weight: 700; font-variant-numeric: tabular-nums; }

.rank-item.me .rank-alias { color: #4cc2ff; font-weight: 700; }

@media (max-height: 520px) {
  #game-over-screen { gap: 8px; padding: 10px; }
  #game-over-screen h2 { font-size: 1.4rem; }
  .rank-item { padding: 6px 10px; }
}
/* Mobile: evita gestos táctiles no deseados */
body, #game-container, canvas {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}


/* === HUD v7: bottom center + barras verticales === */
#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 0;
  z-index: 15;
  display: block !important;
}

#hud-left {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  padding: 6px 18px;
  border-radius: 14px;
  font-family: monospace;
  min-width: 170px;
  line-height: 1.25;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#hud-alias {
  font-size: 10px;
  opacity: 0.65;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}

#hud-score {
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
}

#hud-next-life {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 3px;
  color: #ffdd00;
}

#hud-lives {
  font-size: 11px;
  margin-top: 2px;
  color: #aaa;
}

#hud-speed {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  padding: 4px 10px;
  border-radius: 10px;
  font-family: monospace;
  font-size: 12px;
  line-height: 1;
}

/* === Artículos (guías) === */
.site-header { padding: 1rem 1.2rem; background: #111; border-bottom: 1px solid #333; }
.site-nav { display: flex; gap: 1rem; align-items: center; max-width: 780px; margin: 0 auto; }
.site-nav a { color: #ffd700; text-decoration: none; font-weight: bold; font-size: 0.95rem; }
.site-nav .nav-brand { font-size: 1.1rem; margin-right: auto; }

.article {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
  line-height: 1.7;
  font-size: 1.05rem;
  color: #e8e8e8;
  background: #1a1a1a;
}
.article h1 { font-size: 2rem; margin: 0 0 0.5rem; line-height: 1.25; color: #fff; }
.article h2 { font-size: 1.4rem; margin: 2rem 0 0.8rem; color: #ffd700; }
.article h3 { font-size: 1.15rem; margin: 1.5rem 0 0.6rem; color: #ffd700; }
.article p { margin: 1rem 0; }
.article code {
  background: #2a2a2a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #ffd700;
}
.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}
.article th, .article td {
  padding: 0.5rem;
  border: 1px solid #333;
  text-align: left;
}
.article th { background: #2a2a2a; font-weight: bold; color: #ffd700; }
.article a { color: #4ea8ff; text-decoration: underline; }
.article a:hover { color: #6fc0ff; }
.article ul, .article ol { margin: 1rem 0; padding-left: 1.5rem; }
.article li { margin: 0.4rem 0; }
.article img { max-width: 100%; height: auto; border-radius: 8px; margin: 1rem 0; }
.article-meta { color: #888; font-size: 0.9rem; margin-bottom: 1.5rem; }
.article-caption { color: #999; font-size: 0.9rem; font-style: italic; margin: 1rem 0; }

.cta {
  margin: 2rem 0;
  padding: 1.2rem;
  background: #2a2a2a;
  border-radius: 8px;
  text-align: center;
  border: 1px solid #444;
}
.cta a { font-size: 1.15rem; font-weight: bold; color: #ffd700; text-decoration: none; }
.cta a:hover { text-decoration: underline; }

.related {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #333;
}
.related h3 { color: #ffd700; font-size: 1.15rem; margin-bottom: 0.8rem; }
.related ul { list-style: none; padding: 0; }
.related li { margin: 0.5rem 0; }
.related a { color: #4ea8ff; }

.site-footer {
  padding: 1.5rem 1.2rem;
  text-align: center;
  background: #111;
  border-top: 1px solid #333;
  font-size: 0.9rem;
  color: #888;
}
.site-footer a { color: #4ea8ff; text-decoration: none; }

@media (max-width: 600px) {
  .article { padding: 1.5rem 1rem 3rem; font-size: 1rem; }
  .article h1 { font-size: 1.6rem; }
  .article h2 { font-size: 1.2rem; }
  .article table { font-size: 0.85rem; }
  .article th, .article td { padding: 0.4rem; }
  .site-nav { font-size: 0.9rem; }
}

/* === Tablas Markdown en artículos === */
.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.95em;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.md-table thead {
  background: #2c3e50;
  color: #fff;
}
.md-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #1a252f;
}
.md-table td {
  padding: 10px 16px;
  border-bottom: 1px solid #eee;
}
.md-table tbody tr:nth-child(even) {
  background: #f8f9fa;
}
.md-table tbody tr:hover {
  background: #eef2f7;
}

/* === Sección de artículos en home === */
.site-articles {
  max-width: 900px;
  margin: 3em auto;
  padding: 2em;
  background: #f8f9fa;
  border-radius: 12px;
}
.site-articles h2 {
  font-size: 1.8em;
  margin-bottom: 1em;
  color: #2c3e50;
  text-align: center;
}
.articles-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.8em;
}
.articles-list li {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.articles-list li:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.articles-list a {
  display: block;
  padding: 14px 18px;
  color: #2c3e50;
  text-decoration: none;
  font-weight: 500;
}
.articles-list a:hover {
  color: #e74c3c;
}



.site-articles h2 {
  font-size: 1.6em;
  margin-bottom: 1em;
  color: #2c3e50;
  text-align: center;
}
.articles-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.8em;
}
.articles-list li {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.articles-list li:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.articles-list a {
  display: block;
  padding: 14px 18px;
  color: #2c3e50;
  text-decoration: none;
  font-weight: 500;
}
.articles-list a:hover {
  color: #e74c3c;
}


.site-articles h2 {
  font-size: 1.6em;
  margin-bottom: 1em;
  color: #2c3e50;
  text-align: center;
}
.articles-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.8em;
}
.articles-list li {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.articles-list li:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.articles-list a {
  display: block;
  padding: 14px 18px;
  color: #2c3e50;
  text-decoration: none;
  font-weight: 500;
}
.articles-list a:hover {
  color: #e74c3c;
}

/* === FIX MÓVIL: permitir scroll para ver los artículos === */
@media (max-width: 768px) {
  /* Permitir scroll en html y body */
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100vh !important;
  }
  /* El body ya no centra todo: los hijos se apilan */
  body {
    display: block !important;
  }
  /* El juego ocupa exactamente una pantalla */
  #game-container {
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    position: relative !important;
    width: 100vw !important;
  }
  #game-canvas {
    position: absolute !important;
    inset: 0 !important;
  }
  /* Los artículos debajo, con scroll natural */
  .site-articles {
    margin: 1em auto !important;
    padding: 1em !important;
    border-radius: 8px;
    width: 95% !important;
  }
  .site-articles h2 {
    font-size: 1.3em;
  }
  .articles-list {
    grid-template-columns: 1fr !important;
    gap: 0.5em !important;
  }
  .articles-list a {
    padding: 10px 14px !important;
    font-size: 0.95em;
  }
}


.site-articles h2 {
  font-size: 1.6em;
  margin-bottom: 1em;
  color: #2c3e50;
  text-align: center;
}
.articles-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.8em;
}
.articles-list li {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.articles-list li:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.articles-list a {
  display: block;
  padding: 14px 18px;
  color: #2c3e50;
  text-decoration: none;
  font-weight: 500;
}
.articles-list a:hover {
  color: #e74c3c;
}

/* === FIX MÓVIL: permitir scroll para ver los artículos === */
@media (max-width: 768px) {
  html, body {
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 100vh;
  }
  body {
    display: block;
  }
  #game-container {
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    position: relative;
    width: 100vw;
  }
  #game-canvas {
    position: absolute;
    inset: 0;
  }
  .site-articles {
    margin: 1em auto;
    padding: 1em;
    border-radius: 8px;
    width: 95%;
  }
  .site-articles h2 {
    font-size: 1.3em;
  }
  .articles-list {
    grid-template-columns: 1fr;
    gap: 0.5em;
  }
  .articles-list a {
    padding: 10px 14px;
    font-size: 0.95em;
  }
}

/* === Página de guías === */
.guias-page {
  background: #1a1a1a;
  color: #e8e8e8;
  min-height: 100vh;
  overflow-y: auto;
  display: block;
}
.guias-page .article {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
  line-height: 1.7;
  font-size: 1.05rem;
  color: #e8e8e8;
  background: #1a1a1a;
}
.guias-page .article h1 { color: #fff; }
.guias-page .article h2 { color: #ffd700; margin-top: 2rem; }
.guias-page .article a { color: #4ea8ff; text-decoration: underline; }
.guias-page .article a:hover { color: #6fc0ff; }
.guias-page .article ul { margin: 1rem 0; padding-left: 1.5rem; }
.guias-page .article li { margin: 0.4rem 0; }
.guias-page .site-header { background: #111; border-bottom: 1px solid #333; padding: 1rem 1.2rem; }
.guias-page .site-nav { display: flex; gap: 1rem; align-items: center; max-width: 780px; margin: 0 auto; }
.guias-page .site-nav a { color: #ffd700; text-decoration: none; font-weight: bold; font-size: 0.95rem; }
.guias-page .site-nav .nav-brand { font-size: 1.1rem; margin-right: auto; }
.guias-page .cta { margin: 2rem 0; padding: 1.2rem; background: #2a2a2a; border-radius: 8px; text-align: center; border: 1px solid #444; }
.guias-page .cta a { font-size: 1.15rem; font-weight: bold; color: #ffd700; text-decoration: none; }
.guias-page .site-footer { padding: 1.5rem 1.2rem; text-align: center; background: #111; border-top: 1px solid #333; font-size: 0.9rem; color: #888; }
.guias-page .site-footer a { color: #4ea8ff; text-decoration: none; }


/* === FIX: permitir scroll en la página /guias === */
body.guias-page {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: auto !important;
  min-height: 100vh !important;
  display: block !important;
  touch-action: pan-y !important;
}
html:has(.guias-page) {
  overflow-y: auto !important;
  height: auto !important;
}


/* === FIX: permitir scroll en articulos individuales === */
body.article-page {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: auto !important;
  min-height: 100vh !important;
  display: block !important;
  touch-action: pan-y !important;
  background: #1a1a1a;
  color: #e8e8e8;
}
html:has(.article-page) {
  overflow-y: auto !important;
  height: auto !important;
}
/* Estilos de articulo para body.article-page */
body.article-page .article-content {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
  line-height: 1.7;
  font-size: 1.05rem;
  color: #e8e8e8;
}
body.article-page .article-content h1 {
  font-size: 2rem;
  margin: 0 0 0.5rem;
  line-height: 1.25;
  color: #fff;
}
body.article-page .article-content h2 {
  font-size: 1.4rem;
  margin: 2rem 0 0.8rem;
  color: #ffd700;
}
body.article-page .article-content h3 {
  font-size: 1.15rem;
  margin: 1.5rem 0 0.6rem;
  color: #ffd700;
}
body.article-page .article-content p { margin: 1rem 0; }
body.article-page .article-content a { color: #4ea8ff; text-decoration: underline; }
body.article-page .article-content a:hover { color: #6fc0ff; }
body.article-page .article-content ul,
body.article-page .article-content ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}
body.article-page .article-content li { margin: 0.4rem 0; }
body.article-page .site-header {
  padding: 1rem 1.2rem;
  background: #111;
  border-bottom: 1px solid #333;
}
body.article-page .site-nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  max-width: 780px;
  margin: 0 auto;
}
body.article-page .site-nav a {
  color: #ffd700;
  text-decoration: none;
  font-weight: bold;
  font-size: 0.95rem;
}
body.article-page .site-nav .nav-brand {
  font-size: 1.1rem;
  margin-right: auto;
}
body.article-page .site-footer {
  padding: 1.5rem 1.2rem;
  text-align: center;
  background: #111;
  border-top: 1px solid #333;
  font-size: 0.9rem;
  color: #888;
}
body.article-page .site-footer a { color: #4ea8ff; text-decoration: none; }

/* === Enlaces en el start-screen (sin romper el layout) === */
.start-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 6px 0 10px;
  font-size: 0.8rem;
  max-width: 90vw;
}
.start-links a {
  color: #4cc2ff;
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s ease;
}
.start-links a:hover {
  background: rgba(76, 194, 255, 0.12);
  text-decoration: underline;
}

/* En pantallas pequeñas, reducir aún más */
@media (max-height: 600px) {
  .start-links {
    font-size: 0.72rem;
    gap: 4px 10px;
    margin: 4px 0 8px;
  }
}
