/* =========================================================
   AquaRescate · estilos
   ========================================================= */

/* Esconde cualquier pantalla. El JavaScript pone o quita esta clase. */
.oculto {
    display: none !important;
}

/* ---------- Colores y medidas ---------- */
:root {
    --azul-cielo: #38bdf8;
    --azul: #0369a1;
    --azul-profundo: #062a5a;
    --turquesa: #22d3ee;
    --turquesa-claro: #a5f3fc;
    --verde: #22c55e;
    --verde-claro: #86efac;
    --amarillo: #facc15;
    --naranja: #fb923c;
    --rojo: #ef4444;
    --blanco: #ffffff;

    --vidrio-fondo: linear-gradient(135deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.07));
    --vidrio-borde: rgba(255, 255, 255, 0.38);
    --sombra-grande: 0 24px 60px rgba(0, 18, 50, 0.45);

    /* Ancho del juego: lo más grande posible sin pasar de 800px,
       sin salirse de la pantalla a lo ancho, y dejando espacio arriba para el marcador. */
    --ancho-juego: min(800px, calc(100vw - 32px), calc((100vh - 150px) * 4 / 3));
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    min-height: 100%;
}

body {
    font-family: "Fredoka", "Segoe UI Rounded", "Segoe UI", system-ui, sans-serif;
    color: var(--blanco);
    background: linear-gradient(180deg, var(--azul-cielo) 0%, #0284c7 30%, var(--azul) 60%, var(--azul-profundo) 100%);
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* =========================================================
   FONDO DECORATIVO: rayos de luz, burbujas y olas
   ========================================================= */
.oceano {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

/* Rayos de sol que entran al agua */
.rayos {
    position: absolute;
    top: -20%;
    left: -10%;
    width: 120%;
    height: 90%;
    background:
        repeating-linear-gradient(100deg,
            rgba(255, 255, 255, 0) 0px,
            rgba(255, 255, 255, 0.10) 40px,
            rgba(255, 255, 255, 0) 90px,
            rgba(255, 255, 255, 0) 160px);
    mask-image: linear-gradient(180deg, #000 0%, transparent 85%);
    -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 85%);
    animation: rayos 9s ease-in-out infinite alternate;
}

@keyframes rayos {
    from { transform: translateX(-3%) skewX(-4deg); opacity: 0.55; }
    to   { transform: translateX(3%) skewX(4deg);   opacity: 1; }
}

/* Burbujas que suben */
.burbuja {
    position: absolute;
    bottom: -60px;
    left: var(--x);
    width: var(--s);
    height: var(--s);
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.95) 0 12%, rgba(255, 255, 255, 0.25) 13% 45%, rgba(255, 255, 255, 0.05) 70%);
    border: 1px solid rgba(255, 255, 255, 0.55);
    box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.4);
    animation: subir var(--t) linear var(--d) infinite;
    opacity: 0;
}

@keyframes subir {
    0%   { transform: translate(0, 0) scale(0.6);          opacity: 0; }
    10%  { opacity: 0.9; }
    25%  { transform: translate(14px, -25vh) scale(0.8); }
    50%  { transform: translate(-12px, -55vh) scale(1); }
    75%  { transform: translate(10px, -85vh) scale(1.1); }
    90%  { opacity: 0.8; }
    100% { transform: translate(-6px, -115vh) scale(1.2);  opacity: 0; }
}

/* Olas en la parte de abajo */
.ola {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 200%;
    height: 130px;
    background-repeat: repeat-x;
    background-size: 50% 100%;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 120' preserveAspectRatio='none'><path d='M0,60 C150,110 350,10 600,60 C850,110 1050,10 1200,60 L1200,120 L0,120 Z' fill='white'/></svg>");
    animation: olas linear infinite;
}

.ola1 { opacity: 0.10; animation-duration: 18s; height: 150px; }
.ola2 { opacity: 0.14; animation-duration: 12s; animation-direction: reverse; height: 110px; bottom: -10px; }
.ola3 { opacity: 0.20; animation-duration: 8s;  height: 80px;  bottom: -20px; }

@keyframes olas {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

/* =========================================================
   PANTALLAS
   ========================================================= */
.pantalla {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* Efecto de vidrio (se usa en el menú y en el marcador) */
.vidrio {
    background: var(--vidrio-fondo);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border: 1px solid var(--vidrio-borde);
    box-shadow: var(--sombra-grande), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* =========================================================
   MENÚ
   ========================================================= */
.tarjeta {
    position: relative;
    width: 100%;
    max-width: 540px;
    padding: 36px 40px 40px;
    border-radius: 32px;
    text-align: center;
    overflow: hidden;
    animation: aparecer 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

/* Brillo que cruza la tarjeta */
.tarjeta::before {
    content: "";
    position: absolute;
    top: 0;
    left: -60%;
    width: 40%;
    height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.22), transparent);
    transform: skewX(-20deg);
    animation: brilloTarjeta 6s ease-in-out 1s infinite;
    pointer-events: none;
}

@keyframes brilloTarjeta {
    0%, 60% { left: -60%; }
    100%    { left: 130%; }
}

@keyframes aparecer {
    from { opacity: 0; transform: translateY(40px) scale(0.92); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.logo {
    width: 110px;
    height: 110px;
    object-fit: contain;
    filter: drop-shadow(0 10px 18px rgba(0, 40, 90, 0.45));
    animation: flotar 3.2s ease-in-out infinite;
}

@keyframes flotar {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    50%      { transform: translateY(-12px) rotate(4deg); }
}

h1 {
    margin-top: 6px;
    font-size: clamp(2.6rem, 8vw, 4.2rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.5px;
    background: linear-gradient(180deg, var(--blanco) 35%, var(--turquesa-claro) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 4px 0 rgba(3, 60, 120, 0.55)) drop-shadow(0 10px 18px rgba(0, 30, 70, 0.4));
}

.subtitulo {
    margin: 14px auto 22px;
    max-width: 380px;
    font-size: 1.1rem;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.92);
}

.controles {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
    text-align: left;
}

.control {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 1rem;
}

.control img,
.control .icono {
    width: 32px;
    height: 32px;
    object-fit: contain;
    font-size: 24px;
    line-height: 32px;
    text-align: center;
    flex-shrink: 0;
}

.control b {
    color: var(--amarillo);
    font-weight: 600;
}

.teclas {
    display: inline-flex;
    gap: 4px;
}

.o {
    opacity: 0.8;
}

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--azul-profundo);
    background: linear-gradient(180deg, #ffffff, #d6f4ff);
    box-shadow: 0 3px 0 #7fb8d6, 0 4px 8px rgba(0, 0, 0, 0.25);
}

/* Botón grande con brillo */
.boton {
    position: relative;
    overflow: hidden;
    padding: 16px 64px;
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--blanco);
    cursor: pointer;
    background: linear-gradient(180deg, #5eead4 0%, var(--turquesa) 40%, #0891b2 100%);
    box-shadow:
        0 6px 0 #0e7490,
        0 12px 28px rgba(8, 145, 178, 0.6),
        inset 0 2px 0 rgba(255, 255, 255, 0.6);
    text-shadow: 0 2px 0 rgba(14, 116, 144, 0.7);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    animation: latido 2.2s ease-in-out infinite;
}

.boton::before {
    content: "";
    position: absolute;
    top: 0;
    left: -75%;
    width: 50%;
    height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.7), transparent);
    transform: skewX(-25deg);
    animation: brilloBoton 2.8s ease-in-out infinite;
}

.boton:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow:
        0 9px 0 #0e7490,
        0 18px 36px rgba(8, 145, 178, 0.75),
        inset 0 2px 0 rgba(255, 255, 255, 0.6);
}

.boton:active {
    transform: translateY(4px) scale(0.98);
    box-shadow:
        0 2px 0 #0e7490,
        0 6px 14px rgba(8, 145, 178, 0.5),
        inset 0 2px 0 rgba(255, 255, 255, 0.6);
}

.boton:focus-visible {
    outline: 3px solid var(--amarillo);
    outline-offset: 4px;
}

@keyframes brilloBoton {
    0%, 50% { left: -75%; }
    100%    { left: 130%; }
}

@keyframes latido {
    0%, 100% { filter: brightness(1); }
    50%      { filter: brightness(1.12); }
}

/* =========================================================
   PANTALLA DE JUEGO
   ========================================================= */
#pantallaJuego {
    gap: 12px;
    animation: aparecer 0.6s ease-out both;
}

/* ---------- Marcador ---------- */
#marcador {
    width: var(--ancho-juego);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 14px;
    padding: 10px 16px;
    border-radius: 20px;
}

.dato {
    display: flex;
    align-items: center;
    gap: 10px;
}

.etiqueta {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.85;
}

.valor {
    min-width: 2.5ch;
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--amarillo);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.valor.chico {
    font-size: 1.1rem;
    color: var(--blanco);
    min-width: 3.5ch;
}

/* Corazones */
.vidas {
    gap: 6px;
}

.corazon {
    width: 34px;
    height: 34px;
    object-fit: contain;
    filter: drop-shadow(0 3px 4px rgba(120, 0, 0, 0.45));
    animation: latidoCorazon 1.4s ease-in-out infinite;
    transition: filter 0.4s, opacity 0.4s, transform 0.4s;
}

.corazon:nth-child(2) { animation-delay: 0.15s; }
.corazon:nth-child(3) { animation-delay: 0.3s; }
.corazon:nth-child(4) { animation-delay: 0.45s; }
.corazon:nth-child(5) { animation-delay: 0.6s; }

.corazon.perdido {
    filter: grayscale(1) brightness(0.7);
    opacity: 0.35;
    transform: scale(0.8);
    animation: none;
}

@keyframes latidoCorazon {
    0%, 100% { transform: scale(1); }
    15%      { transform: scale(1.15); }
    30%      { transform: scale(1); }
    45%      { transform: scale(1.1); }
}

/* Barra de contaminación con efecto de líquido */
.barra {
    position: relative;
    width: clamp(90px, 16vw, 150px);
    height: 24px;
    border-radius: 999px;
    background: rgba(0, 30, 60, 0.35);
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.liquido {
    position: relative;
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--verde-claro) 0%, var(--verde) 60%, #15803d 100%);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.7);
    transition: width 0.6s cubic-bezier(0.3, 1.4, 0.5, 1), background 0.5s, box-shadow 0.5s;
    overflow: hidden;
}

/* Rayitas que "fluyen" dentro del líquido */
.liquido::before {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(-45deg,
            rgba(255, 255, 255, 0.22) 0 8px,
            rgba(255, 255, 255, 0) 8px 16px);
    background-size: 22.63px 22.63px;
    animation: fluir 0.9s linear infinite;
}

/* Reflejo de luz arriba del líquido */
.liquido::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 6px;
    right: 6px;
    height: 35%;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0));
}

@keyframes fluir {
    from { background-position: 0 0; }
    to   { background-position: 22.63px 0; }
}

.liquido.media {
    background: linear-gradient(180deg, #fde68a 0%, var(--amarillo) 55%, #ca8a04 100%);
    box-shadow: 0 0 12px rgba(250, 204, 21, 0.75);
}

.liquido.alta {
    background: linear-gradient(180deg, #fca5a5 0%, var(--rojo) 55%, #b91c1c 100%);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.9);
    animation: alerta 0.8s ease-in-out infinite;
}

@keyframes alerta {
    0%, 100% { filter: brightness(1); }
    50%      { filter: brightness(1.35); }
}

/* ---------- Marco del canvas ---------- */
.marco {
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    line-height: 0;
    border: 3px solid rgba(255, 255, 255, 0.7);
    box-shadow:
        0 0 0 6px rgba(255, 255, 255, 0.12),
        var(--sombra-grande);
}

/* El canvas sigue midiendo 800x600 por dentro (en el HTML);
   aquí solo cambiamos el tamaño con el que SE VE, sin deformarlo. */
#juego {
    display: block;
    width: var(--ancho-juego);
    height: auto;
    aspect-ratio: 4 / 3;
}

/* ---------- Insignia del nivel (en el marcador) ---------- */
.insignia-nivel {
    padding: 4px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--azul-profundo);
    background: linear-gradient(180deg, var(--turquesa-claro), var(--turquesa));
    box-shadow: 0 3px 0 rgba(0, 40, 80, 0.35), 0 0 14px rgba(34, 211, 238, 0.6);
}

/* En el marcador las etiquetas van un poco más juntas para que todo quepa en un renglón */
#marcador .etiqueta {
    letter-spacing: 0.5px;
}

.nivel .valor.chico {
    white-space: nowrap;
    min-width: 5ch;
}

/* ---------- Aviso de nivel (encima del río) ---------- */
.aviso-nivel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    line-height: 1.3;          /* .marco tiene line-height: 0 por el canvas */
    background: radial-gradient(circle at 50% 45%, rgba(3, 105, 161, 0.55), rgba(6, 42, 90, 0.85));
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: avisoEntrar 0.45s ease-out both;
    /* Si no cabe todo (ventana bajita), se puede deslizar y el botón nunca queda cortado */
    overflow-y: auto;
    justify-content: safe center;
}

.aviso-superado {
    font-size: clamp(1rem, 2.4vw, 1.35rem);
    font-weight: 700;
    color: var(--verde-claro);
    text-shadow: 0 0 12px rgba(34, 197, 94, 0.8);
    animation: avisoSaltar 0.6s 0.1s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

/* Si no superaste un nivel (al empezar o reintentar), esa línea no ocupa espacio */
.aviso-superado:empty {
    display: none;
}

.aviso-numero {
    padding: 5px 16px;
    border-radius: 999px;
    font-size: clamp(0.85rem, 1.8vw, 1.05rem);
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.45);
}

.aviso-nivel h2 {
    font-size: clamp(2rem, 6vw, 3.6rem);
    line-height: 1.1;
    background: linear-gradient(180deg, #ffffff 20%, var(--turquesa-claro) 60%, var(--turquesa) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 4px 0 rgba(0, 30, 70, 0.55));
    animation: avisoSaltar 0.6s 0.2s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.aviso-nivel p {
    max-width: 44ch;
    font-size: clamp(1rem, 2.3vw, 1.3rem);
    opacity: 0.95;
    animation: aparecer 0.5s 0.35s ease-out both;
}

/* Resumen de cómo vas (puntos, vidas, contaminación) */
.aviso-resumen {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 10px;
    animation: aparecer 0.5s 0.25s ease-out both;
}

.aviso-resumen span {
    padding: 6px 14px;
    border-radius: 14px;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.aviso-resumen b {
    color: var(--amarillo);
}

.aviso-resumen.oculto {
    display: none;
}

/* Botón para empezar el nivel: entra rebotando y "respira" para llamar la atención */
.aviso-nivel .boton {
    margin-top: 6px;
    padding: clamp(8px, 1.8vw, 14px) clamp(24px, 6vw, 52px);
    font-size: clamp(1rem, 2.6vw, 1.45rem);
    animation: avisoSaltar 0.6s 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both,
               respirarBoton 1.6s 1.1s ease-in-out infinite;
}

.aviso-nivel.jefe .boton {
    background: linear-gradient(180deg, #fb923c, var(--rojo));
    box-shadow: 0 8px 0 #7f1d1d, 0 0 28px rgba(239, 68, 68, 0.7);
}

@keyframes respirarBoton {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}

/* Temblor del río cuando explota Basurón (la clase la pone jefe.js) */
.marco.temblor {
    animation: temblorExplosion 0.6s ease-out;
}

@keyframes temblorExplosion {
    0%, 100% { transform: translate(0, 0); }
    15%      { transform: translate(-10px, 6px); }
    30%      { transform: translate(9px, -7px); }
    45%      { transform: translate(-7px, -4px); }
    60%      { transform: translate(6px, 5px); }
    80%      { transform: translate(-3px, 2px); }
}

/* Aviso del jefe final: rojo, oscuro y temblando */
.aviso-nivel.jefe {
    background: radial-gradient(circle at 50% 45%, rgba(120, 53, 15, 0.6), rgba(40, 8, 0, 0.9));
}

.aviso-nivel.jefe .aviso-numero {
    background: var(--rojo);
    border-color: #fecaca;
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.8);
    animation: alerta 0.8s ease-in-out infinite;
}

.aviso-nivel.jefe h2 {
    background: linear-gradient(180deg, #fde68a 10%, var(--naranja) 55%, var(--rojo) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    animation: avisoSaltar 0.6s 0.2s cubic-bezier(0.3, 1.6, 0.5, 1) both,
               temblarJefe 0.35s 0.9s ease-in-out 4;
}

@keyframes avisoEntrar {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes avisoSaltar {
    from { opacity: 0; transform: scale(0.4); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes temblarJefe {
    0%, 100% { transform: translateX(0) rotate(0); }
    25%      { transform: translateX(-6px) rotate(-2deg); }
    75%      { transform: translateX(6px) rotate(2deg); }
}

/* =========================================================
   PANTALLA FINAL (ventana de vidrio encima del juego)
   ========================================================= */
#pantallaFinal {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
    background: radial-gradient(circle at 50% 40%, rgba(6, 42, 90, 0.35), rgba(2, 16, 40, 0.75));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: oscurecer 0.4s ease-out both;
}

@keyframes oscurecer {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#tarjetaFinal {
    max-width: 500px;
    margin: auto;
    animation: aparecerFinal 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

@keyframes aparecerFinal {
    from { opacity: 0; transform: translateY(60px) scale(0.85); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.icono-final {
    font-size: 76px;
    line-height: 1;
    filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.35));
    animation: flotar 3s ease-in-out infinite;
}

#tituloFinal {
    margin-top: 8px;
    font-size: clamp(2.2rem, 7vw, 3.4rem);
    font-weight: 700;
    line-height: 1.05;
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    background-image: linear-gradient(180deg, var(--blanco) 30%, var(--turquesa-claro));
    filter: drop-shadow(0 4px 0 rgba(3, 60, 120, 0.55));
}

/* Colores cuando gana: dorado y verde */
#tarjetaFinal.gano {
    border-color: rgba(250, 204, 21, 0.75);
    box-shadow:
        var(--sombra-grande),
        0 0 60px rgba(250, 204, 21, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#tarjetaFinal.gano #tituloFinal {
    background-image: linear-gradient(180deg, #fff7c2 20%, var(--amarillo) 70%, #f59e0b);
    filter: drop-shadow(0 4px 0 rgba(146, 64, 14, 0.55));
}

#tarjetaFinal.gano .icono-final {
    animation: celebrar 1.2s ease-in-out infinite;
}

@keyframes celebrar {
    0%, 100% { transform: translateY(0) rotate(0) scale(1); }
    25%      { transform: translateY(-14px) rotate(-10deg) scale(1.1); }
    50%      { transform: translateY(0) rotate(0) scale(1); }
    75%      { transform: translateY(-14px) rotate(10deg) scale(1.1); }
}

/* Colores cuando pierde: rojo y café */
#tarjetaFinal.perdio {
    border-color: rgba(252, 165, 165, 0.6);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05)),
        linear-gradient(180deg, rgba(120, 53, 15, 0.25), rgba(127, 29, 29, 0.25));
    box-shadow:
        var(--sombra-grande),
        0 0 50px rgba(239, 68, 68, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#tarjetaFinal.perdio #tituloFinal {
    background-image: linear-gradient(180deg, #ffffff 20%, #fecaca 70%, #fca5a5);
    filter: drop-shadow(0 4px 0 rgba(127, 29, 29, 0.6));
}

#tarjetaFinal.perdio .icono-final {
    animation: temblar 2.4s ease-in-out infinite;
}

@keyframes temblar {
    0%, 70%, 100% { transform: rotate(0); }
    75%           { transform: rotate(-8deg); }
    80%           { transform: rotate(8deg); }
    85%           { transform: rotate(-6deg); }
    90%           { transform: rotate(6deg); }
}

.resultados {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 18px;
}

.resultado {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 12px 10px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.13);
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.resultado .valor {
    font-size: 2.1rem;
}

.dato-agua {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 26px;
    padding: 14px 16px;
    border-radius: 18px;
    text-align: left;
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.28), rgba(14, 116, 144, 0.22));
    border: 1px solid rgba(165, 243, 252, 0.5);
}

.dato-agua .etiqueta {
    display: block;
    margin-bottom: 4px;
    color: var(--turquesa-claro);
}

.dato-agua p {
    font-size: 1rem;
    line-height: 1.4;
}

.icono-dato {
    font-size: 34px;
    line-height: 1;
    flex-shrink: 0;
}

#btnReiniciar {
    padding: 14px 44px;
    font-size: 1.4rem;
}

/* =========================================================
   PANTALLAS CHICAS
   ========================================================= */
/* En pantallas chicas el río se ve pequeño: apretamos la pantalla del nivel para que quepa */
@media (max-width: 600px) {
    .aviso-nivel {
        gap: 5px;
        padding: 8px;
        overflow-y: auto;
        justify-content: safe center;
    }

    .aviso-nivel p {
        font-size: 0.8rem;
    }

    .aviso-resumen span {
        padding: 3px 8px;
        font-size: 0.75rem;
    }
}

@media (max-width: 600px) {
    .tarjeta {
        padding: 28px 20px 30px;
        border-radius: 24px;
    }

    .boton {
        padding: 14px 48px;
        font-size: 1.4rem;
    }

    #marcador {
        justify-content: center;
        padding: 8px 12px;
    }

    .valor {
        font-size: 1.4rem;
    }

    .corazon {
        width: 28px;
        height: 28px;
    }
}

/* Si la persona prefiere menos movimiento, apagamos las animaciones decorativas */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* =========================================================
   CONTROLES PARA CELULAR (joystick en la pantalla)
   Solo se ven en pantallas táctiles (pointer: coarse = se usa con el dedo).
   ========================================================= */
.controles-tactiles {
    display: none;
}

.solo-tactil {
    display: none !important;
}

@media (pointer: coarse) {
    /* En el menú: mostrar la instrucción de celular y esconder la del teclado */
    .solo-tactil {
        display: flex !important;
    }

    .solo-teclado {
        display: none !important;
    }

    /* Dejamos espacio abajo para el joystick, y el río se hace un poco más chico si hace falta */
    :root {
        --ancho-juego: min(800px, calc(100vw - 32px), calc((100vh - 340px) * 4 / 3));
    }

    #pantallaJuego {
        padding-bottom: 190px;
    }

    /* El joystick va fijo abajo, al centro */
    .controles-tactiles {
        position: fixed;
        z-index: 5;                 /* debajo de la pantalla final (z-index 10) */
        left: 50%;
        bottom: max(18px, env(safe-area-inset-bottom));
        transform: translateX(-50%);
        display: block;
        /* Que el dedo no haga zoom, ni scroll, ni seleccione texto */
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Base: un círculo de vidrio con un anillo de agua alrededor */
    .joystick {
        position: relative;
        width: 150px;
        height: 150px;
        border-radius: 50%;
        touch-action: none;
        background:
            radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.06) 0 38%, transparent 39%),
            radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.28), rgba(14, 116, 144, 0.35) 70%);
        border: 2px solid rgba(255, 255, 255, 0.55);
        box-shadow:
            inset 0 0 0 10px rgba(255, 255, 255, 0.08),
            inset 0 6px 18px rgba(0, 40, 80, 0.35),
            0 10px 26px rgba(0, 30, 70, 0.35),
            0 0 22px rgba(94, 234, 212, 0.35);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    /* Anillo interior punteado: marca hasta dónde llega la palanca */
    .joystick::before {
        content: "";
        position: absolute;
        inset: 16px;
        border-radius: 50%;
        border: 2px dashed rgba(255, 255, 255, 0.35);
        pointer-events: none;
    }

    /* Palanca: la bolita que se arrastra (el JS la mueve con transform) */
    .palanca {
        position: absolute;
        left: calc(50% - 32px);
        top: calc(50% - 32px);
        width: 64px;
        height: 64px;
        border-radius: 50%;
        pointer-events: none;
        background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, #5eead4 30%, var(--turquesa) 60%, #0e7490 100%);
        border: 2px solid rgba(255, 255, 255, 0.85);
        box-shadow:
            0 6px 0 rgba(14, 116, 144, 0.9),
            0 10px 18px rgba(0, 40, 80, 0.45),
            inset 0 -4px 8px rgba(0, 60, 90, 0.35);
        transition: transform 0.12s ease-out; /* al soltarla regresa suave al centro */
    }

    /* Mientras se arrastra, la palanca sigue al dedo sin retraso y brilla */
    .joystick.activo .palanca {
        transition: none;
        box-shadow:
            0 6px 0 rgba(14, 116, 144, 0.9),
            0 10px 18px rgba(0, 40, 80, 0.45),
            0 0 22px rgba(250, 204, 21, 0.75),
            inset 0 -4px 8px rgba(0, 60, 90, 0.35);
    }
}

/* Celular acostado: el río se ve con la altura normal y el joystick se va a la esquina izquierda */
@media (pointer: coarse) and (orientation: landscape) {
    :root {
        --ancho-juego: min(800px, calc(100vw - 32px), calc((100vh - 150px) * 4 / 3));
    }

    #pantallaJuego {
        padding-bottom: 16px;
    }

    .controles-tactiles {
        left: max(18px, env(safe-area-inset-left));
        transform: none;
    }
}
