:root {
  --noche: #1b2440;
  --noche-2: #26345c;
  --crema: #f8f0d8;
  --tinta: #283028;
  --rojo: #e05048;
  --rojo-osc: #a83030;
  --azul: #4878c8;
  --verde: #70c058;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --texto: 'Nunito', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse at top, var(--noche-2), var(--noche) 70%);
  color: var(--crema);
  font-family: var(--texto);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid #f8d048; outline-offset: 2px; }

/* ---------- Pantalla de entrada ---------- */
#pantalla-entrada {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: calc(24px + env(safe-area-inset-top)) 16px 32px;
}
.logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 8px; }
.logo-poke {
  font-family: var(--pixel); font-size: clamp(26px, 7vw, 44px); color: #f8d048;
  text-shadow: 3px 3px 0 #3060a8, 6px 6px 0 #182850; letter-spacing: 2px;
}
.logo-valles {
  font-family: var(--pixel); font-size: clamp(16px, 4vw, 24px); color: var(--crema);
  text-shadow: 2px 2px 0 var(--rojo-osc); letter-spacing: 6px;
}
.logo-sub { font-size: 14px; opacity: .75; text-align: center; }

.pestanas { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pestana, .idioma {
  font-family: var(--pixel); font-size: 10px; padding: 10px 12px;
  background: transparent; color: var(--crema); border: 2px solid #5870a8; border-radius: 4px;
}
.pestana.activa { background: var(--crema); color: var(--noche); border-color: var(--crema); }

.tarjeta {
  width: min(460px, 100%);
  background: var(--crema); color: var(--tinta);
  border: 4px solid var(--tinta); border-radius: 6px;
  box-shadow: 0 0 0 4px #b8a888 inset, 6px 6px 0 rgba(0,0,0,.35);
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.tarjeta label { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: 14px; }
.tarjeta input {
  font: inherit; font-weight: 600; padding: 10px 12px; border: 2px solid var(--tinta); border-radius: 4px;
  background: #fffaf0; color: var(--tinta);
}
.etiqueta { margin: 4px 0 0; font-weight: 800; font-size: 14px; }
.boton {
  font-family: var(--pixel); font-size: 12px; padding: 14px; margin-top: 4px;
  background: var(--rojo); color: #fff; border: 3px solid var(--tinta); border-radius: 4px;
  box-shadow: 0 4px 0 var(--rojo-osc);
}
.boton:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--rojo-osc); }
.error { color: var(--rojo-osc); font-weight: 800; margin: 0; min-height: 1.2em; font-size: 14px; }

.personajes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.personaje {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #fffaf0; border: 2px solid #c8b898; border-radius: 6px; padding: 8px 4px 6px;
  color: var(--tinta); font-weight: 800; font-size: 13px;
}
.personaje img { height: 96px; width: auto; image-rendering: pixelated; }
.personaje[aria-pressed="true"] { border-color: var(--rojo); background: #ffe8d8; box-shadow: 0 0 0 2px var(--rojo); }

/* ---------- Juego ---------- */
#pantalla-juego { height: 100%; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; overflow: hidden; background: #000; }
#marco { position: relative; flex: 1 1 auto; overflow: hidden; display: flex; align-items: flex-start; justify-content: center; }
#lienzo { display: block; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }

#dialogo {
  position: absolute; left: max(3%, calc(50% - 460px)); right: max(3%, calc(50% - 460px)); bottom: 3%;
  background: #f8f8f8; color: #303030; border: 4px solid #506878; border-radius: 6px;
  box-shadow: 0 0 0 3px #f8f8f8, 0 0 0 5px #303030;
  padding: 12px 16px 14px; font-family: var(--pixel); font-size: clamp(9px, 1.6vw, 14px); line-height: 1.8;
}
#dialogo p { margin: 0; white-space: pre-line; }
#dialogo-nombre { color: #3060b0; margin-bottom: 4px !important; }
#dialogo .flecha { position: absolute; right: 12px; bottom: 6px; color: var(--rojo); animation: bote .7s infinite; font-size: 10px; }
@keyframes bote { 50% { transform: translateY(3px); } }

#chat { position: absolute; left: 8px; bottom: 8px; width: min(62%, 420px); pointer-events: none; display: flex; flex-direction: column; justify-content: flex-end; z-index: 6; }
#chat-lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
#chat-lista li {
  background: rgba(16, 24, 40, .72); color: #fff; padding: 3px 8px; border-radius: 3px;
  font-size: 13px; font-weight: 600; width: fit-content; max-width: 100%; overflow-wrap: anywhere;
  transition: opacity 1s;
}
#chat-lista li.aviso { color: #f8d048; font-style: italic; }
#chat-lista li b { color: #88c8ff; }
#chat-lista li.viejo { opacity: 0; }
#chat-form { pointer-events: auto; margin-top: 6px; }
#chat-input { width: 100%; font: inherit; font-weight: 600; padding: 8px 10px; border-radius: 4px; border: 2px solid #88c8ff; background: rgba(16,24,40,.9); color: #fff; }

#barra { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; }
.mini {
  font-family: var(--pixel); font-size: 8px; padding: 7px 8px; border-radius: 4px;
  background: rgba(16, 24, 40, .75); color: var(--crema); border: 2px solid rgba(248,240,216,.4);
}
#estado {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8,12,24,.7);
  font-family: var(--pixel); font-size: 12px; text-align: center; padding: 16px; line-height: 2;
}

/* Controles táctiles */
#controles {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px calc(16px + env(safe-area-inset-bottom)); user-select: none; -webkit-user-select: none;
}
.cruceta { position: relative; width: 150px; height: 150px; }
.cruceta button {
  position: absolute; width: 50px; height: 50px; background: #303848; border: 3px solid #181c28; border-radius: 6px;
  touch-action: none;
}
.cruceta button.pulsado, .ab.pulsado { filter: brightness(1.5); }
.c-arriba { left: 50px; top: 0; } .c-abajo { left: 50px; bottom: 0; }
.c-izq { left: 0; top: 50px; } .c-der { right: 0; top: 50px; }
.cruceta::after { content: ''; position: absolute; left: 50px; top: 50px; width: 50px; height: 50px; background: #303848; }
.botones-ab { display: flex; gap: 14px; align-items: flex-end; }
.ab {
  width: 64px; height: 64px; border-radius: 50%; border: 3px solid #181c28; touch-action: none;
  font-family: var(--pixel); font-size: 14px; color: #fff;
}
.ab.a { background: var(--rojo); margin-bottom: 24px; }
.ab.b { background: #8858a8; }

@media (prefers-reduced-motion: reduce) { #dialogo .flecha { animation: none; } }

/* ======================= Combate (estilo GBA) ======================= */
.combate { position: absolute; left: calc(50% - var(--bw, 100%) / 2); top: calc(50% - var(--bh, 100%) / 2); width: var(--bw, 100%); height: var(--bh, 100%); display: flex; flex-direction: column; background: #f8f8f0; border-radius: 4px; overflow: hidden; z-index: 20; font-family: var(--pixel); }
.combate.abriendo { animation: abrir-combate .5s steps(6); }
.combate.cerrando { animation: abrir-combate .4s steps(5) reverse; }
@keyframes abrir-combate { from { clip-path: inset(50% 0 50% 0); } to { clip-path: inset(0 0 0 0); } }
.escena {
  position: relative; flex: 1 1 auto; min-height: 0;
  background: linear-gradient(#b8e0f8 0%, #d8f0f8 38%, #a8d890 38.1%, #88c870 100%);
  --destello: #fff;
}
.escena.destello::after { content: ''; position: absolute; inset: 0; background: var(--destello); opacity: 0; animation: destello .35s; pointer-events: none; }
@keyframes destello { 30% { opacity: .45; } }
.plataforma { position: absolute; border-radius: 50%; background: radial-gradient(#b8d888, #88b060 70%); box-shadow: inset 0 -3px 0 #709850; }
.plataforma.rival { right: 7%; top: 34%; width: 36%; height: 13%; }
.plataforma.propia { left: 2%; bottom: 3%; width: 44%; height: 15%; }
.sprite { position: absolute; image-rendering: pixelated; }
.sprite.rival { right: 9%; top: -2%; width: 34%; max-width: 260px; }
.sprite.propio { left: 4%; bottom: -2%; width: 42%; max-width: 320px; }
.sprite.entra { animation: aparecer .35s steps(4); }
@keyframes aparecer { from { transform: scale(.2); opacity: 0; filter: brightness(3); } }
.sprite.debilitado { animation: caer .5s forwards; }
@keyframes caer { to { transform: translateY(60%); opacity: 0; clip-path: inset(0 0 60% 0); } }
.sprite.embiste { animation: embiste .3s; } .sprite.embiste-rival { animation: embiste-rival .3s; }
@keyframes embiste { 50% { transform: translate(12%, -8%); } }
@keyframes embiste-rival { 50% { transform: translate(-12%, 8%); } }
.sprite.golpeado { animation: golpe .45s steps(2) 1; }
@keyframes golpe { 0%, 50% { opacity: .15; } 25%, 75%, 100% { opacity: 1; } }
.sprite.sube { animation: sube .4s; } .sprite.baja { animation: baja .4s; }
@keyframes sube { 50% { filter: brightness(1.6) hue-rotate(-20deg); transform: translateY(-4%); } }
@keyframes baja { 50% { filter: brightness(.6) hue-rotate(180deg); transform: translateY(4%); } }
.sprite.absorbido { animation: absorber .4s forwards; }
@keyframes absorber { to { transform: scale(0); filter: brightness(4) sepia(1) hue-rotate(-40deg); opacity: 0; } }
.entrenador-rival { position: absolute; right: 12%; top: 1%; height: 62%; image-rendering: pixelated; animation: entrar-ent .4s; }
.entrenador-rival.sale { animation: salir-ent .4s forwards; }
@keyframes entrar-ent { from { transform: translateX(120%); } }
@keyframes salir-ent { to { transform: translateX(140%); } }
.ball-anim { position: absolute; width: 5%; aspect-ratio: 1; border-radius: 50%; background: linear-gradient(#e83838 0 46%, #202020 46% 54%, #f8f8f8 54%); border: 2px solid #202020; }
.ball-anim.lanzar { animation: lanzar .6s cubic-bezier(.3,.6,.6,1) forwards; }
@keyframes lanzar { from { left: 12%; top: 70%; } 50% { top: 5%; } to { left: 72%; top: 30%; } }
.ball-anim.en-suelo { left: 72%; top: 30%; }
.ball-anim.sacude { animation: sacude .6s; }
@keyframes sacude { 25% { transform: rotate(-25deg); } 75% { transform: rotate(25deg); } }
.ball-anim.capturado { filter: brightness(.7); }

.caja-ps {
  position: absolute; background: #f8f8e0; border: 3px solid #384838; border-radius: 6px 6px 10px 6px;
  padding: 5px 9px 6px; box-shadow: 3px 3px 0 rgba(0,0,0,.25); font-size: clamp(8px, 1.5vw, 12px); color: #303030; min-width: 42%;
}
.caja-ps.rival { left: 4%; top: 6%; }
.caja-ps.propia { right: 3%; bottom: 8%; }
.caja-ps .fila { display: flex; align-items: center; gap: 6px; justify-content: space-between; margin: 2px 0; }
.caja-ps .etq { color: #f0a000; font-size: .8em; }
.caja-ps .barra, .tarjeta-pk .barra { flex: 1; height: 7px; background: #506058; border: 2px solid #384838; border-radius: 3px; overflow: hidden; }
.caja-ps .relleno, .tarjeta-pk .relleno { height: 100%; background: #58d080; }
.caja-ps .numeros { justify-content: flex-end; }
.barra-exp { height: 4px; background: #506058; margin-top: 3px; } .relleno-exp { height: 100%; background: #48a8f8; width: 0; transition: width .8s; }
.estado-badge { font-size: .75em; color: #fff; padding: 1px 4px; border-radius: 3px; }

.panel-inferior { position: relative; flex: 0 0 30%; background: #284060; border-top: 4px solid #c8a848; display: flex; align-items: stretch; }
.texto-combate {
  flex: 1; margin: 8px; padding: 10px 14px; background: #f8f8f8; color: #303030; border: 4px solid #6878a0; border-radius: 6px;
  font-size: clamp(9px, 1.7vw, 14px); line-height: 1.8; overflow: hidden; cursor: pointer;
}
.acciones { position: absolute; right: 8px; top: 8px; bottom: 8px; width: 46%; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: #f8f8f8; border: 4px solid #6878a0; border-radius: 6px; padding: 6px; }
.acciones button, .movimientos button, .panel-aprender button { font-family: var(--pixel); font-size: clamp(8px, 1.5vw, 12px); border: 0; border-radius: 4px; background: transparent; color: #303030; text-align: left; padding: 4px 8px; }
.acciones button:focus-visible, .acciones button:hover { background: #f8e0a0; outline: none; }
.acciones button:disabled { color: #a0a0a0; }
.movimientos, .panel-aprender { position: absolute; inset: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #f8f8f8; border: 4px solid #6878a0; border-radius: 6px; padding: 6px; z-index: 2; }
.mov { display: flex; flex-direction: column; justify-content: center; gap: 2px; border-left: 8px solid var(--tipo) !important; background: #f0f0e8 !important; }
.mov:focus-visible, .mov:hover { background: #f8e0a0 !important; outline: none; }
.mov:disabled { opacity: .45; }
.mov-nombre { font-size: 1em; } .mov-info { font-family: var(--texto); font-weight: 800; font-size: clamp(9px, 1.4vw, 12px); color: #585858; }
.mov.estatico { padding: 6px 10px; border-radius: 4px; color: #303030; font-family: var(--pixel); font-size: 11px; }
.no-aprender { grid-column: span 2; border-left-color: #888 !important; }

/* ======================= Paneles (menú, equipo, mochila, tienda) ======================= */
.panel-juego {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(94%, 560px); max-height: 94%;
  display: flex; flex-direction: column; background: #f8f8f0; color: #303030; border: 4px solid #384868; border-radius: 8px;
  box-shadow: 0 0 0 3px #f8f8f0, 0 0 0 6px #384868, 0 12px 30px rgba(0,0,0,.5); z-index: 30;
}
.panel-cab { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: #4868a8; color: #fff; }
.panel-cab h2 { margin: 0; font-family: var(--pixel); font-size: clamp(10px, 1.8vw, 14px); }
.panel-cerrar { background: transparent; border: 0; color: #fff; font-size: 18px; }
.panel-cuerpo { padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.boton-panel, .fila-objeto, .tarjeta-pk, .opcion {
  font-family: var(--texto); font-weight: 800; font-size: 15px; text-align: left; padding: 10px 14px;
  background: #fff; color: #303030; border: 2px solid #c8c8d8; border-radius: 6px;
}
.boton-panel:focus-visible, .fila-objeto:focus-visible, .tarjeta-pk:focus-visible, .opcion:focus-visible,
.boton-panel:hover, .fila-objeto:hover, .tarjeta-pk:hover, .opcion:hover { border-color: #e05048; background: #fff4e8; outline: none; }
.boton-panel:disabled { color: #606060; background: #f0f0f0; }
.fila-objeto { display: flex; justify-content: space-between; }
.cantidad { color: #4868a8; }
.vacio, .nota { font-weight: 700; color: #606060; margin: 4px 0; }
.tarjeta-pk { display: flex; align-items: center; gap: 10px; }
.tarjeta-pk.activo { border-color: #4868a8; }
.tarjeta-pk.kao { background: #f8e0e0; }
.tarjeta-pk.moviendo { border-color: #f0a000; border-style: dashed; }
.tarjeta-pk .mini { width: 56px; height: 56px; image-rendering: pixelated; object-fit: contain; }
.tarjeta-pk .info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.tarjeta-pk .fila { display: flex; align-items: center; gap: 8px; }
.tarjeta-pk .nombre { flex: 1; } .tarjeta-pk .ps { font-size: 13px; color: #606060; min-width: 64px; text-align: right; }
.ficha-cab { display: flex; gap: 12px; align-items: center; }
.ficha-cab .grande { width: 120px; height: 120px; image-rendering: pixelated; object-fit: contain; background: #e8f0e0; border-radius: 8px; }
.ficha-datos p { margin: 2px 0; font-weight: 700; font-size: 14px; }
.ficha-movs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.dinero { font-family: var(--pixel); font-size: 11px; margin: 0 0 4px; }
.fila-tienda { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.fila-tienda span:first-child { flex: 1; } .precio { color: #4868a8; min-width: 70px; text-align: right; }
.mini-boton { font-family: var(--pixel); font-size: 9px; padding: 7px 8px; border: 2px solid #c8c8d8; background: #fff; border-radius: 4px; color: #303030; }
.mini-boton:focus-visible, .mini-boton:hover { border-color: #e05048; outline: none; }

.opciones-dialogo {
  position: absolute; right: 3%; bottom: 30%; display: flex; flex-direction: column; gap: 4px; background: #f8f8f8;
  border: 4px solid #506878; border-radius: 6px; padding: 8px; z-index: 25; min-width: 40%;
}
.opcion { font-size: 14px; padding: 8px 12px; }
.iniciales { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.inicial { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; background: #fff; border: 3px solid var(--tipo); border-radius: 10px; font-family: var(--texto); font-weight: 800; color: #303030; }
.inicial img { width: 96px; height: 96px; image-rendering: pixelated; object-fit: contain; }
.inicial .tipo { font-size: 12px; color: #606060; }
.inicial:focus-visible, .inicial:hover { background: #fff4e8; outline: none; transform: translateY(-2px); }
#dialogo { z-index: 24; cursor: pointer; }
@media (prefers-reduced-motion: reduce) {
  .combate.abriendo, .combate.cerrando, .sprite.entra, .sprite.embiste, .sprite.embiste-rival, .sprite.golpeado, .escena.destello::after { animation: none; }
}
.subtitulo { font-family: var(--pixel); font-size: 11px; margin: 8px 0 0; color: #4868a8; }
.tabla-scroll { overflow-x: auto; }
.tabla-clasif { width: 100%; border-collapse: collapse; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.tabla-clasif th { text-align: left; font-family: var(--pixel); font-size: 9px; color: #4868a8; padding: 6px; border-bottom: 2px solid #c8c8d8; }
.tabla-clasif td { padding: 6px; border-bottom: 1px solid #e0e0e8; white-space: nowrap; }
.tabla-clasif tr:first-child td { color: #c08000; }
.filtros-dex { display: flex; gap: 6px; }
.lista-dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.entrada-dex { display: flex; align-items: center; gap: 6px; background: #fff; border: 2px solid #d8d8e0; border-radius: 6px; padding: 4px 6px; font-weight: 800; font-size: 13px; min-height: 44px; }
.entrada-dex img { width: 40px; height: 40px; image-rendering: pixelated; object-fit: contain; }
.entrada-dex .num { font-family: var(--pixel); font-size: 8px; color: #8888a0; }
.entrada-dex.desconocido { color: #a0a0b0; background: #f0f0f4; }

/* La gràfica d'en Llopis falla también en combate */
.combate.glitch { animation: glitch-gpu 4.3s steps(1) infinite; }
.combate.glitch::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 20; opacity: 0;
  background: repeating-linear-gradient(0deg, rgba(255,0,90,0.25) 0 2px, transparent 2px 9px, rgba(0,255,210,0.2) 9px 10px, transparent 10px 23px);
  animation: glitch-franjas 4.3s steps(1) infinite;
}
@keyframes glitch-gpu {
  0%, 100% { transform: none; filter: none; }
  61% { transform: translateX(-4px) skewX(3deg); filter: hue-rotate(90deg) saturate(3); }
  63% { transform: translateX(5px); filter: invert(1); }
  65% { transform: none; filter: none; }
  88% { transform: translateY(3px); filter: hue-rotate(-120deg) contrast(2); }
  89% { transform: none; filter: none; }
}
@keyframes glitch-franjas { 0%, 100% { opacity: 0; } 61% { opacity: 1; } 65% { opacity: 0; } 88% { opacity: 1; } 90% { opacity: 0; } }

/* Evolución */
.evolucion { position: absolute; inset: 0 0 30% 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle, #6c88c8 0%, #34488a 45%, #141c40 100%); z-index: 30; }
.evo-sprite { width: 96px; height: 96px; image-rendering: pixelated; transform: scale(1.4); }
.evo-sprite.brillo { filter: brightness(0) invert(1) drop-shadow(0 0 6px #fff); }
.evolucion.destello { animation: evo-destello .6s ease-out; }
@keyframes evo-destello { from { box-shadow: inset 0 0 0 999px #fff; } to { box-shadow: inset 0 0 0 999px transparent; } }

/* Salón de la Fama */
.salon-fama { position: absolute; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(circle at 50% 40%, #3a2a70 0%, #150c30 70%); color: #ffe890; font-family: var(--pixel); text-align: center; padding: 12px; }
.sf-titulo { font-size: 20px; letter-spacing: 3px; text-shadow: 2px 2px 0 #a04000; animation: sf-brillo 2s infinite alternate; }
.sf-nombre { font-size: 16px; color: #fff; }
.sf-equipo { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 100%; }
.sf-poke { display: flex; flex-direction: column; align-items: center; color: #fff; font-size: 10px; opacity: 0; animation: sf-entra .5s forwards; }
.sf-poke img { width: 88px; height: 88px; image-rendering: pixelated; }
.sf-texto { font-size: 13px; color: #fff; }
.sf-boton { font-family: var(--pixel); padding: 6px 16px; }
@keyframes sf-entra { from { opacity: 0; transform: translateY(12px) scale(.6); } to { opacity: 1; transform: none; } }
@keyframes sf-brillo { from { color: #ffe890; } to { color: #fff8d0; } }

#btn-musica.apagado { opacity: .55; }

.subtitulo-tienda { margin: 8px 0 2px; font-weight: bold; border-top: 1px solid rgba(0,0,0,.2); padding-top: 6px; }
.texto-aprender { min-height: 3em; }

/* Móvil: chat a todo el ancho y HUD compacto */
@media (max-width: 560px) {
  #chat { width: calc(100% - 16px); }
  #chat-lista li { font-size: 12px; }
}

/* ===================== Carrusel de personajes ===================== */
.carrusel { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(ellipse at 50% 45%, #3b4f8a 0%, #1b2440 55%, #0e1428 100%); color: #fff; font-family: var(--pixel);
  opacity: 0; transition: opacity .5s; overflow: hidden; padding: 16px; user-select: none; }
.carrusel.visible { opacity: 1; }
.carrusel.saliendo { opacity: 0; transform: scale(1.05); transition: opacity .6s, transform .6s; }
.car-titulo { font-size: clamp(14px, 3.4vw, 26px); letter-spacing: 2px; margin: 0; color: #ffd84a; text-shadow: 3px 3px 0 #b03a2e; text-align: center; }
.car-escenario { position: relative; width: min(100%, 900px); height: min(52vh, 460px); touch-action: pan-y; }
.car-foco { position: absolute; left: 50%; bottom: 4%; width: min(46vw, 320px); height: 18%; transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(255,240,170,.55) 0%, rgba(255,240,170,0) 70%); }
.car-item { position: absolute; left: 50%; bottom: 8%; height: 86%; display: flex; align-items: flex-end; justify-content: center; cursor: pointer;
  transition: transform .5s cubic-bezier(.2,.9,.25,1.15), opacity .5s, filter .5s; transform-origin: 50% 100%; }
.car-item img { height: 100%; width: auto; image-rendering: pixelated; pointer-events: none; }
.car-item[data-pos="0"] { transform: translateX(-50%) scale(1); opacity: 1; z-index: 5; }
.car-item.activo img { animation: car-respira 1.6s ease-in-out infinite; }
.car-item[data-pos="1"] { transform: translateX(calc(-50% + min(30vw, 270px))) scale(.55); opacity: .7; filter: brightness(.55); z-index: 4; }
.car-item[data-pos="-1"] { transform: translateX(calc(-50% - min(30vw, 270px))) scale(.55); opacity: .7; filter: brightness(.55); z-index: 4; }
.car-item[data-pos="2"] { transform: translateX(calc(-50% + min(46vw, 410px))) scale(.36); opacity: .35; filter: brightness(.4); z-index: 3; }
.car-item[data-pos="-2"] { transform: translateX(calc(-50% - min(46vw, 410px))) scale(.36); opacity: .35; filter: brightness(.4); z-index: 3; }
.car-item[data-pos="3"], .car-item[data-pos="-3"] { transform: translateX(-50%) scale(.2); opacity: 0; z-index: 1; pointer-events: none; }
@keyframes car-respira { 0%, 100% { transform: translateY(0) scaleY(1); } 50% { transform: translateY(-4px) scaleY(1.015); } }
.car-flecha { position: absolute; top: 45%; z-index: 6; font-size: 26px; width: 48px; height: 48px; border-radius: 50%; border: 3px solid #fff;
  background: rgba(16,24,48,.7); color: #fff; cursor: pointer; font-family: var(--pixel); }
.car-flecha.izq { left: 4px; } .car-flecha.der { right: 4px; }
.car-flecha:active { transform: scale(.92); }
.car-nombre { font-size: clamp(20px, 4.5vw, 36px); color: #fff; text-shadow: 3px 3px 0 #000; }
.car-nombre.entra { animation: car-nombre .35s ease-out; }
@keyframes car-nombre { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.car-bocadillo { position: relative; width: min(92vw, 620px); min-height: 3.4em; background: #f8f8f0; color: #202020; border: 4px solid #303848;
  border-radius: 10px; padding: 12px 16px; font-family: var(--texto, 'Nunito', sans-serif); font-weight: 800; font-size: clamp(14px, 2.6vw, 18px); line-height: 1.35; }
.car-bocadillo::before { content: ''; position: absolute; top: -14px; left: 50%; transform: translateX(-50%); border: 10px solid transparent; border-bottom-color: #303848; border-top: 0; }
.car-bocadillo.pop { animation: car-pop .3s ease-out; }
@keyframes car-pop { from { transform: scale(.9); opacity: .4; } to { transform: none; opacity: 1; } }
.car-puntos { display: flex; gap: 8px; }
.car-puntos span { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.3); transition: background .3s, transform .3s; }
.car-puntos span.on { background: #ffd84a; transform: scale(1.3); }
.car-elegir { font-family: var(--pixel); font-size: clamp(12px, 2.6vw, 16px); padding: 14px 26px; border-radius: 8px; border: 3px solid #fff;
  background: #e04838; color: #fff; cursor: pointer; box-shadow: 0 4px 0 #8a2018; }
.car-elegir:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a2018; }
.car-modal { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); }
.car-modal-caja { background: #f8f8f0; color: #202020; border: 4px solid #303848; border-radius: 10px; padding: 18px 22px; text-align: center;
  font-family: var(--texto, 'Nunito', sans-serif); font-weight: 800; font-size: 18px; max-width: 90vw; }
.car-modal-nota { font-size: 13px; opacity: .7; margin-top: -4px; }
.car-modal-caja button { font-family: var(--pixel); font-size: 13px; margin: 6px; padding: 10px 18px; border-radius: 6px; border: 3px solid #303848; cursor: pointer; }
.car-si { background: #48b048; color: #fff; } .car-no { background: #ddd; }
.car-modal-caja button:focus { outline: 3px solid #ffd84a; outline-offset: 2px; }

/* ===================== Intro de la historia ===================== */
.intro { position: fixed; inset: 0; z-index: 100; background: #000; opacity: 0; transition: opacity .8s; overflow: hidden; cursor: pointer; user-select: none; }
.intro.visible { opacity: 1; }
.intro.saliendo { opacity: 0; transition: opacity .9s; }
.intro-fondo { position: absolute; inset: 0; background-repeat: no-repeat; background-size: auto 170%; image-rendering: pixelated;
  opacity: 0; transition: opacity 1s; filter: saturate(1.05); }
.intro-fondo::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 40%, rgba(0,0,0,0) 30%, rgba(0,0,0,.65) 100%); }
.intro-fondo.visible { opacity: 1; }
.intro-fondo.oscuro { filter: brightness(.55) saturate(1.3) hue-rotate(-10deg); }
.intro-fondo.pan { animation: intro-pan 14s linear forwards; }
@keyframes intro-pan { from { background-position: 10% 25%; } to { background-position: 80% 65%; } }
.intro-sprite { position: absolute; left: 50%; bottom: 26%; height: 46vh; transform: translateX(-50%) translateY(20px); image-rendering: pixelated;
  opacity: 0; transition: opacity .8s, transform .8s; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
.intro-sprite.visible { opacity: 1; transform: translateX(-50%); }
.intro-sprite.silueta { filter: brightness(0) drop-shadow(0 0 12px rgba(255,80,40,.8)); }
.intro-caja { position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%); width: min(94vw, 760px); min-height: 5.2em;
  background: #f8f8f0; border: 4px solid #303848; border-radius: 10px; box-shadow: 0 0 0 4px #f8f8f0, 0 8px 24px rgba(0,0,0,.6); padding: 14px 18px; }
.intro-texto { margin: 0; color: #202020; font-family: var(--texto, 'Nunito', sans-serif); font-weight: 800; font-size: clamp(15px, 2.6vw, 20px); line-height: 1.4; }
.intro-flecha { position: absolute; right: 14px; bottom: 8px; color: #e04838; animation: intro-flecha .7s steps(2) infinite; }
@keyframes intro-flecha { 50% { transform: translateY(3px); } }
.intro-saltar { position: absolute; top: 12px; right: 12px; font-family: var(--pixel); font-size: 11px; padding: 8px 12px; border-radius: 6px;
  border: 2px solid #fff; background: rgba(0,0,0,.5); color: #fff; cursor: pointer; z-index: 2; }

/* ===================== HUD: lugar y equipo ===================== */
#hud { position: absolute; left: 8px; top: 8px; z-index: 5; pointer-events: none; display: flex; flex-direction: column; gap: 6px; max-width: 46%; }
#hud-lugar { align-self: flex-start; font-family: var(--pixel); font-size: clamp(9px, 1.3vw, 13px); color: #303030; background: #f8f8f0;
  border: 3px solid #506878; border-radius: 6px; box-shadow: 0 0 0 2px #f8f8f0, 0 0 0 4px #303030; padding: 7px 10px; white-space: nowrap; }
#hud-lugar:empty { display: none; }
#hud-lugar.entra { animation: hud-lugar .6s cubic-bezier(.2,.9,.3,1.2); }
@keyframes hud-lugar { from { transform: translateY(-140%); } to { transform: none; } }
#hud-equipo { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
#hud-equipo li { display: flex; align-items: center; gap: 6px; background: rgba(16,24,40,.78); border: 2px solid rgba(248,240,216,.35); border-radius: 6px;
  padding: 2px 8px 2px 2px; width: 190px; }
#hud-equipo li.debil { filter: grayscale(1); opacity: .7; }
.hud-icono { width: 32px; height: 32px; flex: none; background-size: 200%; background-position: 50% 62%; background-repeat: no-repeat; image-rendering: pixelated; }
.hud-info { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.hud-linea { display: flex; justify-content: space-between; gap: 6px; font-weight: 800; font-size: 12px; color: #fff; }
.hud-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-nivel { color: #ffd84a; flex: none; }
.hud-barra { height: 5px; background: #404850; border-radius: 3px; overflow: hidden; }
.hud-barra span { display: block; height: 100%; transition: width .4s; }
.hud-barra .alta { background: #58d068; } .hud-barra .media { background: #f8c030; } .hud-barra .baja { background: #f05838; }
@media (max-width: 560px) {
  #hud { max-width: 60%; top: 44px; }
  #hud-equipo li { width: 130px; padding-right: 6px; }
  .hud-icono { width: 24px; height: 24px; }
  .hud-linea { font-size: 10px; }
}

/* ===================== Ranking de jugadores ===================== */
.panel-ranking { width: min(94vw, 640px) !important; max-height: 90% !important; }
.rk-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.rk-tab { font-family: var(--pixel); font-size: 9px; padding: 7px 9px; border-radius: 5px; border: 2px solid #506878; background: #e8ecf0; color: #303030; cursor: pointer; }
.rk-tab.activa { background: #3060b0; color: #fff; border-color: #203f78; }
.rk-lista { display: flex; flex-direction: column; gap: 6px; }
.rk-card { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 6px 10px; border-radius: 8px; border: 2px solid #c8d0d8;
  background: #fff; cursor: pointer; font: inherit; color: #202020; }
.rk-card:focus, .rk-card:hover { border-color: #3060b0; }
.rk-card.yo { background: #fff6d8; border-color: #e0b030; }
.rk-card.top1 { box-shadow: inset 4px 0 0 #f0c020; } .rk-card.top2 { box-shadow: inset 4px 0 0 #b8c0c8; } .rk-card.top3 { box-shadow: inset 4px 0 0 #c88040; }
.rk-pos { font-family: var(--pixel); font-size: 13px; width: 34px; text-align: center; flex: none; }
.rk-avatar { height: 52px; width: 40px; object-fit: contain; object-position: bottom; image-rendering: pixelated; flex: none; }
.rk-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rk-nombre { font-weight: 800; font-size: 15px; }
.rk-etapa { font-size: 12px; color: #506070; font-weight: 700; }
.rk-estado { font-size: 11px; color: #8890a0; font-weight: 700; }
.rk-estado.online { color: #2f9a48; }
.rk-medallas { display: flex; gap: 2px; }
.rk-medalla { font-size: 13px; filter: grayscale(1); opacity: .25; }
.rk-medalla.tiene { filter: none; opacity: 1; }
.rk-valor { font-family: var(--pixel); font-size: 11px; color: #3060b0; flex: none; text-align: right; max-width: 34%; }
.rk-perfil-cab { display: flex; gap: 14px; align-items: flex-end; margin-bottom: 4px; }
.rk-perfil-avatar { height: 110px; image-rendering: pixelated; }
.rk-perfil-datos { display: flex; flex-direction: column; gap: 4px; padding-bottom: 6px; }
.rk-perfil-nombre { font-family: var(--pixel); font-size: 16px; }
.rk-sub { font-family: var(--pixel); font-size: 10px; margin: 12px 0 6px; color: #3060b0; }
.rk-medallas-grandes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rk-medalla-g { display: flex; flex-direction: column; align-items: center; padding: 6px 2px; border-radius: 8px; background: #eef1f4; filter: grayscale(1); opacity: .45; text-align: center; }
.rk-medalla-g.tiene { filter: none; opacity: 1; background: #fff3c8; box-shadow: inset 0 0 0 2px #e0b030; }
.rk-medalla-icono { font-size: 22px; }
.rk-medalla-nombre { font-size: 11px; font-weight: 800; }
.rk-medalla-lider { font-size: 10px; color: #607080; }
.rk-equipo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rk-poke { display: flex; flex-direction: column; align-items: center; background: #eef1f4; border-radius: 8px; padding: 4px 6px 6px; gap: 2px; }
.rk-poke img { width: 72px; height: 72px; image-rendering: pixelated; margin: -10px 0 -8px; }
.rk-poke-nombre { font-size: 12px; font-weight: 800; }
.rk-poke-nivel { font-size: 11px; color: #3060b0; font-weight: 800; }
.rk-poke .hud-barra { width: 100%; }
.rk-legendarios { display: flex; flex-wrap: wrap; gap: 2px; }
.rk-legendarios img { width: 64px; height: 64px; image-rendering: pixelated; }
.rk-stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin-bottom: 8px; }
.rk-stat-k { color: #607080; font-weight: 700; } .rk-stat-v { font-weight: 800; }
@media (max-width: 560px) {
  .rk-valor { display: none; }
  .rk-medallas-grandes { grid-template-columns: repeat(2, 1fr); }
  .rk-equipo { grid-template-columns: repeat(2, 1fr); }
}

/* ===================== Combate: capa de animaciones, botones con color ===================== */
.anim-capa { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }
.escena.temblor { animation: temblor .5s steps(8); }
@keyframes temblor { 0%, 100% { transform: none; } 20% { transform: translate(-6px, 2px); } 40% { transform: translate(5px, -2px); } 60% { transform: translate(-4px, 1px); } 80% { transform: translate(3px, -1px); } }
.sprite.shiny { filter: drop-shadow(0 0 3px rgba(255,248,180,.8)); }

.panel-inferior { background: linear-gradient(#2c4870, #1c3050) !important; }
.acciones { background: transparent !important; border: 0 !important; gap: 6px !important; padding: 0 !important; }
.acciones button { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center !important;
  color: #fff !important; text-shadow: 2px 2px 0 rgba(0,0,0,.45); border-radius: 10px !important; border: 3px solid rgba(255,255,255,.85) !important;
  box-shadow: 0 4px 0 rgba(0,0,0,.35), inset 0 -6px 0 rgba(0,0,0,.18), inset 0 6px 0 rgba(255,255,255,.18);
  transition: transform .1s, filter .1s; font-size: clamp(9px, 1.6vw, 13px) !important; overflow: hidden; }
.acciones button::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, rgba(255,255,255,.08) 0 6px, transparent 6px 12px); pointer-events: none; }
.acciones button .ico { font-size: 1.5em; text-shadow: none; filter: drop-shadow(1px 1px 0 rgba(0,0,0,.4)); }
.acciones button[data-a="luchar"] { background: linear-gradient(#f05a48, #c02818) !important; }
.acciones button[data-a="mochila"] { background: linear-gradient(#f8b840, #d88010) !important; }
.acciones button[data-a="pokemon"] { background: linear-gradient(#58c858, #2c8c34) !important; }
.acciones button[data-a="huir"] { background: linear-gradient(#5890f0, #2858b8) !important; }
.acciones button:hover, .acciones button:focus-visible { transform: translateY(-2px) scale(1.03); filter: brightness(1.12); outline: none !important; }
.acciones button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.acciones button:disabled { filter: grayscale(1) brightness(.8); }

.movimientos { background: #e8eef8 !important; }
.movimientos .mov { position: relative; border: 3px solid rgba(255,255,255,.9) !important; border-left: 3px solid rgba(255,255,255,.9) !important; border-radius: 10px !important;
  background: linear-gradient(color-mix(in srgb, var(--tipo) 75%, #fff), var(--tipo)) !important; color: #fff !important; text-shadow: 1px 1px 0 rgba(0,0,0,.5);
  box-shadow: 0 3px 0 rgba(0,0,0,.3); transition: transform .1s, filter .1s; }
.movimientos .mov:hover, .movimientos .mov:focus-visible { transform: translateY(-2px); filter: brightness(1.1); outline: none !important; }
.movimientos .mov .mov-info { color: rgba(255,255,255,.92) !important; }
.movimientos .mov:disabled { filter: grayscale(.8) brightness(.8); }

/* Fondo del combate según el sitio y la hora */
.escena.noche { background: linear-gradient(#18204a 0%, #2c3870 38%, #3c6040 38.1%, #2c4a30 100%) !important; }
.escena.interior { background: linear-gradient(#d8d0c0 0%, #e8e0d0 38%, #b8a888 38.1%, #a09070 100%) !important; }
.escena.frio { background: linear-gradient(#c0d8f0 0%, #e8f0f8 38%, #e8f0f8 38.1%, #c8d8e8 100%) !important; }
.escena.volcan { background: linear-gradient(#401818 0%, #803020 38%, #604030 38.1%, #402820 100%) !important; }
.escena.agua { background: linear-gradient(#b8e0f8 0%, #d8f0f8 38%, #58a0e0 38.1%, #3878c0 100%) !important; }

/* ===================== Tutorial de controles ===================== */
.tuto { position: absolute; left: 50%; top: 16%; transform: translate(-50%, -10px); z-index: 60; display: flex; align-items: center; gap: 14px;
  background: rgba(16, 24, 48, .92); color: #fff; border: 3px solid #ffd84a; border-radius: 12px; padding: 12px 18px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  opacity: 0; transition: opacity .4s, transform .4s; pointer-events: none; max-width: min(92vw, 640px); }
.intro .tuto { position: fixed; top: auto; bottom: calc(4% + 7.5em); }
.tuto.visible { opacity: 1; transform: translate(-50%, 0); animation: tuto-flota 2s ease-in-out infinite; }
@keyframes tuto-flota { 50% { transform: translate(-50%, -5px); } }
.tuto-texto { font-weight: 800; font-size: clamp(13px, 2.2vw, 17px); line-height: 1.3; }
.tuto-anim { display: flex; align-items: center; gap: 6px; flex: none; }
.tuto-tecla { display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 6px; border-radius: 6px; font-family: var(--pixel); font-size: 12px;
  color: #303030; background: linear-gradient(#ffffff, #d8dce4); border: 2px solid #9098a8; box-shadow: 0 4px 0 #6a7282; }
.tuto-tecla.pulsa { animation: tuto-pulsa 1s ease-in-out infinite; }
@keyframes tuto-pulsa { 0%, 55%, 100% { transform: none; box-shadow: 0 4px 0 #6a7282; } 65%, 80% { transform: translateY(4px); box-shadow: 0 0 0 #6a7282; background: #ffe680; } }
.tuto-cruz { display: grid; grid-template-columns: repeat(3, 36px); grid-template-rows: repeat(2, 36px); gap: 3px; }
.tuto-cruz .f-arriba { grid-column: 2; grid-row: 1; } .tuto-cruz .f-izquierda { grid-column: 1; grid-row: 2; }
.tuto-cruz .f-abajo { grid-column: 2; grid-row: 2; } .tuto-cruz .f-derecha { grid-column: 3; grid-row: 2; }
.tuto-cruz .tuto-tecla, .tuto-flecha { animation: tuto-pulsa 2s ease-in-out infinite; }
.tuto-cruz .f-arriba { animation-delay: 0s; } .tuto-cruz .f-derecha { animation-delay: .5s; } .tuto-cruz .f-abajo { animation-delay: 1s; } .tuto-cruz .f-izquierda { animation-delay: 1.5s; }
.tuto-flecha { display: grid; place-items: center; background: #303848; color: #fff; border-radius: 6px; border: 2px solid #181c28; }
.tuto-o { font-weight: 800; margin: 0 2px; }
.tuto-boton-a { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--rojo, #e04838); color: #fff;
  font-family: var(--pixel); border: 3px solid #181c28; animation: tuto-pulsa 1s ease-in-out infinite; }
.tuto-pulso { animation: tuto-anillo 1.1s ease-out infinite; }
@keyframes tuto-anillo { 0% { box-shadow: 0 0 0 0 rgba(255,216,74,.9); } 100% { box-shadow: 0 0 0 16px rgba(255,216,74,0); } }
@media (max-width: 560px) { .tuto { top: 22%; padding: 10px 12px; gap: 10px; } }
