/* Variáveis de Cores e Estilo */
:root {
    --bg-dark: #0a0512;
    --bg-card: rgba(20, 10, 35, 0.75);
    --blood-red: #9e0c1b;
    --blood-red-glow: rgba(158, 12, 27, 0.6);
    --purple-neon: #a855f7;
    --purple-glow: rgba(168, 85, 247, 0.4);
    --xp-blue: #06b6d4;
    --xp-glow: rgba(6, 182, 212, 0.4);
    --text-primary: #f3f4f6;
    --text-muted: #9ca3af;
    --gold: #eab308;
    --border-color: rgba(168, 85, 247, 0.2);
    --border-red: rgba(158, 12, 27, 0.4);
}

/* Reset Geral e Fontes */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    touch-action: manipulation;
}

/* Container de Jogo e Canvas */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    display: block;
    background-color: #0d0914;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.9);
}

/* Utilidades */
.hidden {
    display: none !important;
}

/* HUD (Interface sobreposta no Canvas) */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Deixa cliques passarem para o Canvas */
    z-index: 10;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#hud * {
    pointer-events: auto; /* Reativa cliques nos botões/itens do HUD */
}

/* Barra de XP no Topo */
#xp-bar-container {
    width: 100%;
    height: 20px;
    background: rgba(15, 10, 25, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

#xp-bar-fill {
    height: 100%;
    width: 0%; /* Alterado via JS */
    background: linear-gradient(90deg, #6366f1, #06b6d4);
    box-shadow: 0 0 10px var(--xp-glow);
    transition: width 0.2s ease-out;
}

#xp-text {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: #ffffff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

/* Status no Topo */
.hud-top-stats {
    position: absolute;
    top: 55px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
}

.stat-box {
    background: rgba(20, 12, 35, 0.8);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 8px;
    padding: 6px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 90px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    font-family: monospace;
}

/* Barra de Vida (Canto Inferior Esquerdo) */
#health-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 250px;
    background: rgba(15, 5, 5, 0.85);
    border: 1px solid var(--border-red);
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}

.health-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #fca5a5;
    margin-bottom: 4px;
}

#health-bar-bg {
    width: 100%;
    height: 12px;
    background: rgba(50, 10, 10, 0.6);
    border-radius: 3px;
    overflow: hidden;
}

#health-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #7f1d1d, #ef4444);
    box-shadow: 0 0 8px var(--blood-red-glow);
    transition: width 0.1s ease-out;
}

/* Inventário (Canto Inferior Direito) */
#inventory-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(20, 10, 35, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    min-width: 180px;
}

.inventory-title {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: var(--purple-neon);
    text-align: center;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(168, 85, 247, 0.2);
    padding-bottom: 4px;
}

#inventory-slots {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.inventory-slot {
    width: 36px;
    height: 36px;
    background: rgba(10, 5, 20, 0.7);
    border: 1px solid rgba(168, 85, 247, 0.4);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    position: relative;
}

.inventory-level {
    position: absolute;
    bottom: 1px;
    right: 3px;
    font-size: 0.55rem;
    font-weight: 800;
    color: var(--gold);
}

/* Botão de Pause */
#btn-pause-toggle {
    position: absolute;
    top: 55px;
    right: 20px;
    width: 36px;
    height: 36px;
    background: rgba(20, 12, 35, 0.8);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

#btn-pause-toggle:hover {
    background: var(--purple-neon);
    border-color: #ffffff;
    box-shadow: 0 0 10px var(--purple-glow);
    transform: scale(1.05);
}

/* Telas de Menu Overlays */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(4, 2, 8, 0.85);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

/* Glassmorphism Card Style */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--border-color);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8),
                0 0 30px rgba(168, 85, 247, 0.1);
    border-radius: 16px;
}

.menu-content {
    width: 90%;
    max-width: 520px;
    padding: 40px;
    text-align: center;
    animation: scaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Título Gótico */
.game-title {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: 4px;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
    margin-bottom: 15px;
}

.game-title .highlight {
    color: var(--blood-red);
    text-shadow: 0 0 15px var(--blood-red-glow), 0 0 30px #ef4444;
}

.game-subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 30px;
    line-height: 1.6;
}

/* Instruções */
.instructions {
    text-align: left;
    background: rgba(10, 5, 20, 0.6);
    border: 1px solid rgba(168, 85, 247, 0.15);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 35px;
}

.instructions h3 {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    letter-spacing: 2px;
    color: var(--purple-neon);
    margin-bottom: 12px;
    text-align: center;
    border-bottom: 1px solid rgba(168, 85, 247, 0.1);
    padding-bottom: 6px;
}

.instructions ul {
    list-style-type: none;
}

.instructions li {
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

.instructions li:last-child {
    margin-bottom: 0;
}

.key {
    background: #2a1f40;
    border: 1px solid #583d8c;
    border-bottom: 3px solid #1a0f2e;
    border-radius: 4px;
    padding: 2px 8px;
    font-family: monospace;
    font-size: 0.8rem;
    font-weight: bold;
    color: #e9d5ff;
}

.gem-highlight {
    color: #c084fc;
    font-weight: 800;
    text-shadow: 0 0 5px var(--purple-glow);
}

/* Botões com Brilho Glow */
.glow-button {
    width: 100%;
    padding: 16px 30px;
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 2px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--blood-red), #5c050f);
    border: 1px solid #ef4444;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
    transition: all 0.25s ease;
    outline: none;
}

.glow-button:hover {
    background: linear-gradient(135deg, #b91c1c, #7f1d1d);
    box-shadow: 0 0 25px var(--blood-red-glow), 0 0 5px rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
}

.glow-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

/* Estilo do Menu de Upgrade */
#menu-upgrade {
    background: rgba(3, 1, 6, 0.9);
}

#menu-upgrade .menu-content {
    max-width: 780px;
    width: 95%;
}

.section-title {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    letter-spacing: 3px;
    color: #ffffff;
    text-shadow: 0 0 15px var(--purple-glow);
    margin-bottom: 8px;
}

.section-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 35px;
}

#upgrade-cards-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* Upgrade Card */
.upgrade-card {
    background: linear-gradient(180deg, rgba(25, 12, 45, 0.9), rgba(13, 6, 25, 0.95));
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 12px;
    width: 220px;
    padding: 25px 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}

.upgrade-card:hover {
    border-color: var(--purple-neon);
    transform: translateY(-8px);
    box-shadow: 0 12px 30px rgba(168, 85, 247, 0.25),
                0 0 15px rgba(168, 85, 247, 0.15);
}

.upgrade-icon {
    font-size: 2.2rem;
    margin-bottom: 16px;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.2));
}

.upgrade-name {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: #ffffff;
    margin-bottom: 4px;
}

.upgrade-level {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    background: rgba(234, 179, 8, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

.upgrade-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Fim de Jogo */
#menu-game-over {
    background: rgba(8, 2, 2, 0.92);
}

.game-over-title {
    font-family: 'Cinzel', serif;
    font-size: 2.5rem;
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: 3px;
    color: #ffffff;
    margin-bottom: 10px;
}

.game-over-title .red-highlight {
    color: var(--blood-red);
    text-shadow: 0 0 15px rgba(158, 12, 27, 0.8), 0 0 35px #ef4444;
}

.game-over-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 30px;
}

.stats-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(20, 5, 5, 0.6);
    border: 1px solid var(--border-red);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 35px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed rgba(158, 12, 27, 0.2);
    padding-bottom: 8px;
}

.summary-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.summary-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.summary-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
}

.restart-button {
    background: linear-gradient(135deg, var(--blood-red), #5c050f);
}

/* Pause Menu content */
#menu-pause .menu-content {
    max-width: 320px;
}

/* Animações CSS */
@keyframes scaleUp {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsividade de Tela Pequena */
@media (max-width: 600px) {
    .game-title {
        font-size: 2.2rem;
    }
    .menu-content {
        padding: 25px 15px;
    }
    #upgrade-cards-container {
        gap: 10px;
    }
    .upgrade-card {
        width: 100%;
        max-width: 320px;
        flex-direction: row;
        align-items: center;
        text-align: left;
        padding: 15px;
        gap: 15px;
    }
    .upgrade-icon {
        margin-bottom: 0;
        font-size: 1.8rem;
    }
    .upgrade-desc {
        text-align: left;
    }
    #health-container {
        width: 180px;
    }
    #inventory-container {
        min-width: 140px;
    }
}

/* Estilos para o Ataque Especial */
#special-row {
    margin-top: 10px;
    border-top: 1px dashed rgba(168, 85, 247, 0.2);
    padding-top: 8px;
}

.special-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--purple-neon);
    margin-bottom: 4px;
    transition: all 0.2s ease;
}

#special-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(30, 10, 45, 0.6);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

#special-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #c084fc, var(--purple-neon));
    box-shadow: 0 0 6px rgba(168, 85, 247, 0.6);
    transition: width 0.1s linear;
}

/* Quando especial está carregado e pronto */
#special-row.ready .special-label-row {
    color: #ef4444;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.8);
    animation: pulseText 1.2s infinite alternate;
}

#special-row.ready #special-bar-fill {
    background: linear-gradient(90deg, #f43f5e, #ef4444);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.9);
}

@keyframes pulseText {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
    }
}

/* --- CONTROLES DE TOQUE (CELULAR) --- */
#joystick-container {
    display: none;
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 120px;
    height: 120px;
    z-index: 20;
    justify-content: center;
    align-items: center;
    touch-action: none;
}

#joystick-base {
    width: 100px;
    height: 100px;
    background: rgba(20, 10, 35, 0.5);
    border: 2px solid rgba(168, 85, 247, 0.4);
    border-radius: 50%;
    position: relative;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(168, 85, 247, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
}

#joystick-knob {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--purple-neon), #6d28d9);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    position: absolute;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), 0 0 8px var(--purple-glow);
    touch-action: none;
}

#btn-special-touch {
    display: none;
    position: absolute;
    bottom: 40px;
    right: 40px;
    width: 70px;
    height: 70px;
    background: rgba(20, 10, 35, 0.65);
    border: 2px solid rgba(168, 85, 247, 0.4);
    border-radius: 50%;
    color: #ffffff;
    font-size: 1.8rem;
    z-index: 20;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    touch-action: none;
    transition: transform 0.1s ease, border-color 0.2s ease, background-color 0.2s ease;
}

#btn-special-touch:active {
    transform: scale(0.92);
}

/* Quando especial está pronto, o botão brilha vermelho */
#btn-special-touch.ready {
    border-color: #ef4444;
    background: rgba(158, 12, 27, 0.4);
    box-shadow: 0 0 15px var(--blood-red-glow), 0 0 5px rgba(255, 255, 255, 0.4);
    animation: touchPulse 1.5s infinite alternate ease-in-out;
}

@keyframes touchPulse {
    from {
        transform: scale(1);
        box-shadow: 0 0 10px var(--blood-red-glow);
    }
    to {
        transform: scale(1.06);
        box-shadow: 0 0 20px #ef4444;
    }
}

#btn-special-touch.cooldown {
    opacity: 0.4;
    background: rgba(10, 5, 20, 0.8);
    border-color: rgba(120, 120, 120, 0.3);
    color: var(--text-muted);
}

/* Se for um dispositivo de toque (mobile) */
@media (pointer: coarse) and (max-width: 1024px) {
    body.touch-device #joystick-container {
        display: flex;
    }

    body.touch-device #btn-special-touch {
        display: flex;
    }

    /* Ajuste no botão de pause no celular para ser mais fácil de tocar */
    body.touch-device #btn-pause-toggle {
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
        top: 50px;
        right: 20px;
    }
}
