/* =========================================
   TOWER DEFENSE
   GUARDIANES DEL REINO
========================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #080b16;
    --panel: #111827;
    --panel-light: #1e293b;
    --primary: #7c3aed;
    --primary-light: #a78bfa;
    --gold: #fbbf24;
    --danger: #ef4444;
    --success: #22c55e;
    --cyan: #22d3ee;
    --ice: #67e8f9;
    --text: #f8fafc;
    --muted: #94a3b8;
}

body {
    font-family:
        "Segoe UI",
        Arial,
        sans-serif;

    background:
        radial-gradient(
            circle at top,
            #1e1b4b,
            #080b16 60%
        );

    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
}


/* =========================================
   PANTALLAS
========================================= */

.screen {
    position: fixed;
    inset: 0;

    display: none;

    justify-content: center;
    align-items: center;

    background:
        radial-gradient(
            circle at center,
            rgba(124, 58, 237, 0.18),
            transparent 45%
        ),
        #080b16;

    z-index: 1000;
}

.screen.active {
    display: flex;
}


/* =========================================
   MENU
========================================= */

.menu-card {
    width: min(520px, 92vw);

    padding: 45px 40px;

    text-align: center;

    background:
        linear-gradient(
            145deg,
            rgba(30, 41, 59, 0.96),
            rgba(15, 23, 42, 0.98)
        );

    border:
        1px solid rgba(167, 139, 250, 0.25);

    border-radius: 28px;

    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.6),
        0 0 60px rgba(124, 58, 237, 0.12);
}

.crown {
    font-size: 60px;
    color: var(--gold);

    text-shadow:
        0 0 20px rgba(251, 191, 36, 0.5);
}

.menu-card h1 {
    margin-top: 5px;

    font-size: clamp(38px, 7vw, 65px);

    letter-spacing: 5px;

    background:
        linear-gradient(
            90deg,
            #fbbf24,
            #a78bfa,
            #22d3ee
        );

    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.menu-card h2 {
    font-size: 17px;
    letter-spacing: 4px;
    color: var(--muted);
    margin-bottom: 20px;
}

.menu-description {
    color: #cbd5e1;
    line-height: 1.6;
    margin: 20px auto 30px;
    max-width: 420px;
}

.menu-button {
    display: block;

    width: 100%;

    margin: 12px 0;

    padding: 15px 20px;

    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 13px;

    background:
        linear-gradient(
            135deg,
            #1e293b,
            #111827
        );

    color: white;

    font-size: 16px;
    font-weight: 800;

    letter-spacing: 1px;

    cursor: pointer;

    transition:
        transform 0.2s,
        box-shadow 0.2s,
        border-color 0.2s;
}

.menu-button:hover {
    transform: translateY(-2px);

    border-color: var(--primary-light);

    box-shadow:
        0 10px 25px rgba(0, 0, 0, 0.3);
}

.menu-button.primary {
    background:
        linear-gradient(
            135deg,
            #7c3aed,
            #4f46e5
        );

    border-color: transparent;
}

.menu-record {
    margin-top: 30px;

    font-size: 13px;

    color: var(--muted);
}

.menu-record span {
    color: var(--gold);
    font-weight: 900;
}


/* =========================================
   MODALES
========================================= */

.modal-card {
    position: relative;

    width: min(700px, 92vw);
    max-height: 90vh;

    overflow-y: auto;

    padding: 40px;

    background:
        linear-gradient(
            145deg,
            #1e293b,
            #0f172a
        );

    border-radius: 25px;

    border: 1px solid rgba(167, 139, 250, 0.25);

    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.7);
}

.modal-card h2 {
    text-align: center;

    font-size: 32px;

    margin-bottom: 25px;
}

.close-button {
    position: absolute;

    right: 18px;
    top: 15px;

    width: 40px;
    height: 40px;

    border: none;
    border-radius: 50%;

    background: #334155;

    color: white;

    font-size: 25px;

    cursor: pointer;
}

.instructions-grid {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 15px;
}

.instructions-grid > div {
    padding: 20px;

    border-radius: 15px;

    background:
        rgba(15, 23, 42, 0.8);

    border:
        1px solid rgba(148, 163, 184, 0.12);
}

.instructions-grid h3 {
    color: var(--primary-light);

    margin-bottom: 8px;
}

.instructions-grid p {
    color: #cbd5e1;

    line-height: 1.5;

    font-size: 14px;
}

.credits-text {
    text-align: center;

    line-height: 1.8;

    font-size: 20px;
}

.tech-list {
    display: flex;

    flex-wrap: wrap;

    justify-content: center;

    gap: 10px;

    margin: 25px 0;
}

.tech-list span {
    padding: 8px 13px;

    border-radius: 20px;

    background: #312e81;

    color: #ddd6fe;
}

.small-text {
    color: var(--muted);
    text-align: center;
}


/* =========================================
   GAME
========================================= */

#gameScreen {
    display: none;

    position: fixed;

    inset: 0;
}

#gameScreen.active {
    display: flex;

    flex-direction: column;
}


/* =========================================
   HUD
========================================= */

#hud {
    height: 72px;

    flex-shrink: 0;

    display: flex;

    align-items: center;

    gap: 10px;

    padding: 8px 12px;

    background:
        linear-gradient(
            180deg,
            rgba(15, 23, 42, 0.98),
            rgba(15, 23, 42, 0.92)
        );

    border-bottom:
        1px solid rgba(148, 163, 184, 0.15);

    z-index: 10;
}

.hud-item {
    min-width: 105px;

    display: flex;

    align-items: center;

    gap: 8px;

    padding: 8px 13px;

    border-radius: 12px;

    background:
        rgba(30, 41, 59, 0.8);

    border:
        1px solid rgba(148, 163, 184, 0.1);
}

.hud-item > span {
    font-size: 22px;
}

.hud-item div {
    display: flex;
    flex-direction: column;
}

.hud-item small {
    color: var(--muted);

    font-size: 9px;

    letter-spacing: 1px;
}

.hud-item strong {
    font-size: 17px;
}

.hud-item.gold strong {
    color: var(--gold);
}

.hud-item.lives strong {
    color: #fb7185;
}

.hud-item.wave strong {
    color: var(--cyan);
}

.hud-item.score strong {
    color: #c4b5fd;
}

.hud-item.highscore strong {
    color: var(--gold);
}

.hud-button {
    margin-left: auto;

    padding: 12px 18px;

    border: 1px solid #475569;

    border-radius: 10px;

    background: #1e293b;

    color: white;

    font-weight: 800;

    cursor: pointer;
}


/* =========================================
   GAME AREA
========================================= */

#gameArea {
    position: relative;

    flex: 1;

    min-height: 0;

    background: #142019;
}

#gameCanvas {
    position: absolute;

    inset: 0;

    width: 100%;
    height: 100%;

    display: block;

    touch-action: none;
}


/* =========================================
   SHOP
========================================= */

#towerShop {
    position: absolute;

    left: 12px;
    bottom: 12px;

    display: flex;

    align-items: center;

    gap: 7px;

    padding: 9px;

    border-radius: 16px;

    background:
        rgba(15, 23, 42, 0.94);

    border:
        1px solid rgba(148, 163, 184, 0.15);

    backdrop-filter: blur(10px);

    z-index: 5;
}

.shop-tower {
    width: 75px;

    min-height: 76px;

    display: flex;

    flex-direction: column;

    justify-content: center;

    align-items: center;

    gap: 3px;

    padding: 5px;

    border-radius: 11px;

    background:
        linear-gradient(
            145deg,
            #334155,
            #1e293b
        );

    border: 1px solid transparent;

    cursor: pointer;

    transition:
        transform 0.15s,
        border-color 0.15s;
}

.shop-tower:hover {
    transform: translateY(-4px);

    border-color: var(--primary-light);
}

.shop-tower.selected {
    border-color: var(--gold);

    box-shadow:
        0 0 15px rgba(251, 191, 36, 0.3);
}

.tower-icon {
    font-size: 27px;
}

.shop-tower strong {
    font-size: 10px;
}

.shop-tower span {
    color: var(--gold);

    font-size: 10px;
    font-weight: 800;
}

.wave-button {
    min-width: 150px;

    height: 64px;

    border: none;

    border-radius: 12px;

    background:
        linear-gradient(
            135deg,
            #16a34a,
            #15803d
        );

    color: white;

    font-size: 12px;

    font-weight: 900;

    cursor: pointer;

    box-shadow:
        0 7px 20px rgba(22, 163, 74, 0.25);

    transition: 0.2s;
}

.wave-button:hover {
    transform: translateY(-2px);
}

.wave-button:disabled {
    opacity: 0.5;

    cursor: not-allowed;

    transform: none;
}


/* =========================================
   TOWER PANEL
========================================= */

.side-panel {
    position: absolute;

    right: 15px;
    top: 15px;

    width: 245px;

    padding: 20px;

    border-radius: 18px;

    background:
        rgba(15, 23, 42, 0.96);

    border:
        1px solid rgba(167, 139, 250, 0.25);

    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.4);

    z-index: 8;
}

.hidden {
    display: none !important;
}

.panel-close {
    position: absolute;

    right: 10px;
    top: 10px;

    border: none;

    background: transparent;

    color: white;

    font-size: 23px;

    cursor: pointer;
}

.side-panel h3 {
    color: var(--primary-light);

    font-size: 20px;

    margin-bottom: 5px;
}

.tower-level {
    color: var(--gold);

    font-weight: 800;

    font-size: 12px;

    margin-bottom: 15px;
}

.tower-stats {
    display: grid;

    gap: 7px;

    margin-bottom: 15px;
}

.tower-stats div {
    display: flex;

    justify-content: space-between;

    padding: 8px;

    background: #1e293b;

    border-radius: 8px;
}

.tower-stats span {
    color: var(--muted);

    font-size: 12px;
}

.tower-stats strong {
    font-size: 12px;
}

.panel-button {
    width: 100%;

    padding: 12px;

    border: none;

    border-radius: 9px;

    color: white;

    font-weight: 800;

    cursor: pointer;

    margin-top: 7px;
}

.panel-button.upgrade {
    background:
        linear-gradient(
            135deg,
            #7c3aed,
            #4f46e5
        );
}

.panel-button.sell {
    background:
        linear-gradient(
            135deg,
            #b91c1c,
            #7f1d1d
        );
}


/* =========================================
   ABILITIES
========================================= */

#abilities {
    position: absolute;

    right: 15px;
    bottom: 15px;

    display: flex;

    gap: 7px;

    z-index: 6;
}

.ability {
    width: 92px;

    height: 75px;

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    border: 1px solid rgba(148, 163, 184, 0.2);

    border-radius: 12px;

    background: rgba(15, 23, 42, 0.94);

    color: white;

    cursor: pointer;

    transition: 0.2s;
}

.ability:hover {
    transform: translateY(-3px);
}

.ability > span {
    font-size: 25px;
}

.ability small {
    font-size: 8px;

    font-weight: 800;

    color: #cbd5e1;
}

.ability b {
    color: var(--success);

    font-size: 8px;

    margin-top: 2px;
}

.ability.cooldown {
    opacity: 0.45;

    cursor: not-allowed;
}


/* =========================================
   NOTIFICACIONES
========================================= */

#notification {
    position: absolute;

    left: 50%;
    top: 20px;

    transform:
        translateX(-50%)
        translateY(-20px);

    padding: 11px 20px;

    border-radius: 30px;

    background:
        rgba(15, 23, 42, 0.95);

    color: white;

    font-weight: 800;

    opacity: 0;

    pointer-events: none;

    transition: 0.25s;

    z-index: 20;
}

#notification.show {
    opacity: 1;

    transform:
        translateX(-50%)
        translateY(0);
}

#notification.warning {
    border: 1px solid var(--danger);

    color: #fecaca;
}

#notification.success {
    border: 1px solid var(--success);

    color: #bbf7d0;
}


/* =========================================
   WAVE MESSAGE
========================================= */

#waveMessage {
    position: absolute;

    left: 50%;
    top: 30%;

    transform:
        translate(-50%, -50%)
        scale(0.8);

    opacity: 0;

    pointer-events: none;

    text-align: center;

    z-index: 4;

    transition:
        opacity 0.4s,
        transform 0.4s;
}

#waveMessage.show {
    opacity: 1;

    transform:
        translate(-50%, -50%)
        scale(1);
}

#waveMessageTitle {
    display: block;

    font-size: clamp(35px, 7vw, 70px);

    font-weight: 1000;

    letter-spacing: 5px;

    text-shadow:
        0 4px 20px #000;
}

#waveMessageText {
    display: block;

    color: #cbd5e1;

    font-size: 15px;

    margin-top: 5px;
}


/* =========================================
   OVERLAYS
========================================= */

.overlay {
    position: fixed;

    inset: 0;

    display: none;

    justify-content: center;
    align-items: center;

    background:
        rgba(2, 6, 23, 0.8);

    backdrop-filter: blur(7px);

    z-index: 100;
}

.overlay.active {
    display: flex;
}

.pause-card {
    width: min(420px, 90vw);

    text-align: center;
}

.gameover-card {
    width: min(500px, 92vw);

    text-align: center;
}

.gameover-icon {
    font-size: 65px;

    color: var(--danger);

    text-shadow:
        0 0 30px rgba(239, 68, 68, 0.5);
}

.gameover-card h2 {
    color: #f87171;

    font-size: 48px;

    margin: 0;
}

.gameover-card p {
    color: var(--muted);

    margin-bottom: 25px;
}

.gameover-stats {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 10px;

    margin-bottom: 20px;
}

.gameover-stats div {
    padding: 15px;

    border-radius: 12px;

    background: #1e293b;
}

.gameover-stats span {
    display: block;

    color: var(--muted);

    font-size: 10px;

    letter-spacing: 1px;
}

.gameover-stats strong {
    display: block;

    margin-top: 5px;

    color: white;

    font-size: 22px;
}

.new-record {
    display: none;

    color: var(--gold);

    font-size: 18px;

    font-weight: 900;

    margin-bottom: 15px;

    animation: pulse 1s infinite;
}

.new-record.show {
    display: block;
}


/* =========================================
   ANIMACIONES
========================================= */

@keyframes pulse {
    50% {
        transform: scale(1.08);
    }
}


/* =========================================
   RESPONSIVE
========================================= */

@media (max-width: 1000px) {

    .hud-item {
        min-width: 80px;
    }

    .hud-item > span {
        font-size: 17px;
    }

    .hud-item strong {
        font-size: 14px;
    }

    .shop-tower {
        width: 62px;
    }

    .wave-button {
        min-width: 125px;
    }

    .ability {
        width: 75px;
    }
}


@media (max-width: 700px) {

    #hud {
        height: 58px;

        gap: 4px;

        padding: 5px;
    }

    .hud-item {
        min-width: 0;

        flex: 1;

        padding: 5px;

        justify-content: center;
    }

    .hud-item > span {
        display: none;
    }

    .hud-item small {
        font-size: 7px;
    }

    .hud-item strong {
        font-size: 12px;
    }

    .hud-button {
        padding: 8px;

        font-size: 10px;
    }

    #towerShop {
        left: 5px;
        right: 5px;
        bottom: 5px;

        overflow-x: auto;

        justify-content: flex-start;
    }

    .shop-tower {
        min-width: 62px;
    }

    .wave-button {
        min-width: 115px;
    }

    #abilities {
        right: 5px;
        bottom: 95px;
    }

    .ability {
        width: 65px;
        height: 58px;
    }

    .ability > span {
        font-size: 19px;
    }

    .ability small {
        font-size: 6px;
    }

    .instructions-grid {
        grid-template-columns: 1fr;
    }

    .modal-card {
        padding: 25px;
    }
}


@media (max-width: 450px) {

    .shop-tower {
        min-width: 55px;
    }

    .tower-icon {
        font-size: 21px;
    }

    .shop-tower strong,
    .shop-tower span {
        font-size: 8px;
    }

    .wave-button {
        min-width: 100px;

        font-size: 9px;
    }

    #abilities {
        gap: 3px;
    }

    .ability {
        width: 57px;
    }

    .ability small {
        display: none;
    }

    .side-panel {
        left: 10px;
        right: 10px;
        width: auto;
    }
}