@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Roboto:wght@700&display=swap');

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #c2a36b;
    /* Color arena / terracota base */
    font-family: 'Fredoka One', cursive, sans-serif;
    user-select: none;
}

/* El Canvas toma toda la pantalla por debajo de la interfaz */
#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    /* Nivel base */
    background: radial-gradient(circle at center, #e3c990 0%, #a88540 100%);
}

#top-hud {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    /* Que los clicks pasen al canvas si fuera necesario */
}

.gold-box,
.waves-box {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 25px;
    border-radius: 20px;
    border: 3px solid #ffcc00;
    font-size: 24px;
    text-shadow: 2px 2px 0px #000;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.waves-box {
    border-color: #aa00ff;
    color: #e5b3ff;
}

.gold-box span {
    color: #ffde59;
}

.nav-secret {
    pointer-events: auto;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 10px;
}

.nav-secret a {
    color: white;
    text-decoration: none;
}

/* UPGRADES (Inspirado en Mage Tower) */
#upgrades-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    gap: 15px;
}

.upg-btn {
    background: linear-gradient(180deg, #9b59b6 0%, #8e44ad 100%);
    border: 4px solid #fff;
    border-radius: 15px;
    color: white;
    padding: 10px 20px;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0px 5px 0px #5e3370, 0 10px 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s;
    width: 140px;
    text-align: center;
}

.upg-btn:active {
    transform: translateY(5px);
    box-shadow: 0px 0px 0px #5e3370, 0 5px 10px rgba(0, 0, 0, 0.5);
}

.upg-title {
    font-size: 18px;
    text-transform: uppercase;
    margin-bottom: 5px;
    text-shadow: 1px 1px 0px #000;
}

.upg-cost {
    font-size: 14px;
    color: #ffde59;
}

.upg-level {
    font-size: 12px;
    color: #ccc;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    display: inline-block;
    padding: 2px 6px;
    margin-top: 5px;
}

/* Reutilizando Leaderboard de otros juegos */
#leaderboard-container {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 250px;
    background: rgba(0, 0, 0, 0.85);
    border: 3px solid #ffcc00;
    border-radius: 10px;
    padding: 10px;
    color: white;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
}

#leaderboard-container h3 {
    text-align: center;
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #ffcc00;
    text-transform: uppercase;
}

.leader-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 5px;
    padding: 5px;
    border-radius: 5px;
}

.leader-item img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    margin-right: 10px;
}

.leader-item span {
    flex-grow: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leader-item strong {
    color: #ffde59;
    font-size: 14px;
}

/* SCREEN SHAKE PARA REGALOS CAROS */
@keyframes nuke-shake {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    10% {
        transform: translate(-30px, 30px) rotate(-2deg) scale(1.05);
    }

    20% {
        transform: translate(30px, -30px) rotate(2deg) scale(0.95);
    }

    30% {
        transform: translate(-30px, -30px) rotate(0deg) scale(1.08);
    }

    40% {
        transform: translate(30px, 30px) rotate(1deg) scale(1.02);
    }

    50% {
        transform: translate(-20px, 20px) rotate(-1deg) scale(1.05);
        filter: contrast(200%) brightness(150%) hue-rotate(90deg);
    }

    60% {
        transform: translate(20px, -20px) rotate(2deg);
        filter: contrast(150%) brightness(100%);
    }

    70% {
        transform: translate(-10px, 10px) rotate(-1deg);
        filter: contrast(100%);
    }

    80% {
        transform: translate(10px, -10px) rotate(1deg);
    }

    90% {
        transform: translate(-5px, 5px) rotate(0deg);
    }

    100% {
        transform: translate(0, 0) rotate(0deg);
    }
}

.screen-shake-anim {
    animation: nuke-shake 1.5s cubic-bezier(.36, .07, .19, .97) both;
}

/* =========================================
   ELEMENTOS DEL JUEGO (DOM MIGRADOS)
========================================= */

/* Torre y Rango */
.attack-range-circle {
    position: absolute;
    border: 2px dashed rgba(255, 255, 255, 0.4);
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    /* El script pondrá left y top en pixeles */
    z-index: 10;
}

.tower-container {
    position: absolute;
    transform: translate(-50%, -100%);
    /* Anclado a su base (piso) */
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tower-img {
    height: 150px;
    /* Tamaño por defecto escalable */
    object-fit: contain;
    filter: drop-shadow(0 15px 15px rgba(0, 0, 0, 0.5));
}

/* Enemigos (Monstruos animables) */
.enemy-container {
    position: absolute;
    transform: translate(-50%, -100%);
    z-index: 30;
    /* Encima de la torre en perspectiva (El JS ordenará Z-index luego si se desea) */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.enemy-nameplate {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 5px;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.enemy-nameplate img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ffcc00;
}

.enemy-img {
    height: 90px;
    object-fit: contain;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.4));
    transition: transform 0.1s;
}

/* Barras de Vida (Estilo MOBA) */
.health-bar-bg {
    width: 50px;
    height: 6px;
    background: #000;
    border: 1px solid #333;
    border-radius: 3px;
    margin-top: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.health-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #c0392b, #e74c3c);
    border-radius: 2px;
    transition: width 0.1s linear;
}

#tower-hp-bar {
    width: 100px;
    height: 10px;
    margin-top: 10px;
}

#tower-hp-fill {
    background: linear-gradient(90deg, #27ae60, #2ecc71);
}

/* Proyectiles y Partículas */
.projectile {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 25;
    width: 40px;
    height: 40px;
}

.projectile img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 10px #f1c40f);
}

.floating-text {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 26px;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 0px #000, -1px -1px 0px #000;
    z-index: 50;
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
}

@keyframes floatUp {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }

    20% {
        transform: translate(-50%, -80%) scale(1.2);
    }

    100% {
        transform: translate(-50%, -150%) scale(1);
        opacity: 0;
    }
}