/* Base Reset & Variables */
:root {
    --gold: #DDB771;
    --epic-purple: #9b59b6;
    --bg-dark: #0f1115;
    --text-light: #f5f6fa;
    --accent-blue: #00d2d3;
    --danger-red: #ff4757;
    --orange-glow: #ff9f43;
    --font-main: 'Inter', 'Segoe UI', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
    user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 450px;
    /* Mobile vertical constrained */
    height: 100vh;
    max-height: 900px;
    background: #111;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

/* Backgrounds */
#background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('https://lh3.googleusercontent.com/aida-public/AB6AXuDmAvZIPN0X9zc1SWmg9wnmc3s2rn4FwaBpLVVB55wcM6i00vZ18VKgkp0jabZQJp16WNsx8QvWDKrnrnQrCAcYviAKfYihAEQtVVnd2GzsLvD7s_JcckQLua-y69Wt5M8IuKEmQnEZ3ZtXWTHPFw2byJE98jid4doV6TaYlF62ddvKjaPW_wnNZV99OskWqy8-Ifxo7eT_h6AaOimyxH5uEHcJrs9Q-iqVXcSy7xepMRnN77sqAtp7iWz6WpiY2BOd_FHTD4rNRQ') no-repeat center center;
    background-size: cover;
    filter: blur(8px) brightness(0.3);
    z-index: 1;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
}

/* --- Main Menu --- */
#main-menu {
    justify-content: space-between;
    padding: 40px 20px;
    align-items: center;
}

.logo-container {
    margin-top: 15vh;
}

.logo-text {
    font-size: 3.2rem;
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #fff;
    text-shadow: 0 0 10px rgba(221, 183, 113, 0.8), 0 0 20px rgba(221, 183, 113, 1), 0 0 40px rgba(221, 183, 113, 0.6);
    animation: float 3s ease-in-out infinite;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    margin-bottom: 5vh;
}

.primary-btn {
    width: 100%;
    padding: 20px;
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    border: none;
    border-radius: 12px;
    background: linear-gradient(45deg, var(--gold), #fbc531);
    color: #111;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(221, 183, 113, 0.5);
    transition: transform 0.2s, box-shadow 0.2s;
}

.glow-pulse {
    animation: pulseGlow 2s infinite;
}

.primary-btn:active {
    transform: scale(0.95);
}

.secondary-buttons {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.secondary-btn {
    flex: 1;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--gold);
    box-shadow: 0 0 5px rgba(221, 183, 113, 0.3);
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
    backdrop-filter: blur(5px);
    cursor: pointer;
    transition: background 0.2s;
}

.secondary-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

/* --- Battle Screen --- */
.battle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
    z-index: 20;
}

.player-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid var(--gold);
    background-color: #333;
    background-size: cover;
    background-position: center;
}

.p1-avatar {
    background-image: url('https://lh3.googleusercontent.com/aida-public/AB6AXuBlFF8q3t6j5A4blovGeKzVI4lO4Abo_sIJDC8iI3Kxo9u_rBI57NieZJBfytxXZR22XbozDll9O7DLqDmtW9OhhAorLRMXPfg_e0d3BrQ8P5YqJcjn4tC8a3Q-IFG3allpgpQ5tmwsgADmY_t6Jg51HlXRRa7WB8Xn08hTLt6ZSOnJHbxC7jEWH7-oa7U_x-ht_e4PZ-BAzP1NYkfUC1RLI1hz-uLD76eNBwtf6sTrG80gxFjbMlGrynTwA5F_z6CId9b4yIGMJg');
}

.p2-avatar {
    background-image: url('https://lh3.googleusercontent.com/aida-public/AB6AXuBy_aqUKHnBV65_OY77qaspaWbI0uOIZ6wDDInGXcWHQBtLb13YtBKCPqPjavyN0ueoZJfWlUtxtVYG8ruDJNejxIp_G5hBuD2d5YjLo468Te280jrfGa_JgFb6kqTkfhpXzJJCGW6BWetBqVk52RdJqh6RzB2ONCti_e4Ln6Y9b0AyMyxcpVAYc_183R-p9jf18l2u9A-K7grZagdoxrX0NQiVjhnQ1ZOLHCU9LBoBNoAjUi_aSgjZTnMVMcZPr0zko1vQ5uFaGw');
}

.hp-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 15px;
}

#timer {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 5px;
    text-shadow: 0 0 5px #fff;
}

.hp-bar {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    margin: 2px 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.hp-fill {
    height: 100%;
    background: linear-gradient(to right, #ff4757, #ff9f43);
    width: 100%;
    transition: width 0.3s ease-out;
}

.pause-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

.arena {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 15px;
    perspective: 1000px;
    z-index: 15;
}

.card-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    height: 35%;
    /* roughly 1/3 of arena */
}

/* Combat Zone */
.combat-zone {
    height: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.slash-effect,
.blast-effect {
    position: absolute;
    width: 150px;
    height: 150px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    pointer-events: none;
}

/* --- Cards --- */
.card {
    width: 28%;
    /* 3 cards fit nicely */
    aspect-ratio: 4 / 5;
    background-color: #222;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.9), 0 5px 15px rgba(0, 0, 0, 0.7);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    background-size: cover;
    background-position: center;
}

.card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 -40px 30px -10px rgba(0, 0, 0, 0.9);
    pointer-events: none;
}

.card.gold-rarity {
    border: 2px solid var(--gold);
    box-shadow: 0 0 15px rgba(221, 183, 113, 0.4), 0 10px 20px rgba(0, 0, 0, 0.8);
}

.card.epic-rarity {
    border: 2px solid var(--epic-purple);
    box-shadow: 0 0 15px rgba(155, 89, 182, 0.4), 0 10px 20px rgba(0, 0, 0, 0.8);
}

.card:hover,
.card.selected {
    transform: scale(1.05) translateY(-5px);
    z-index: 20;
}

.card.gold-rarity:hover {
    box-shadow: 0 0 25px var(--gold);
}

.card.epic-rarity:hover {
    box-shadow: 0 0 25px var(--epic-purple);
}

.card-name {
    position: absolute;
    bottom: 25px;
    left: 5px;
    right: 5px;
    font-size: 0.75rem;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 2;
}

.card-stats {
    position: absolute;
    bottom: 5px;
    left: 5px;
    right: 5px;
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 900;
    z-index: 2;
}

.stat-atk {
    color: #ff6b81;
    text-shadow: 1px 1px 2px #000;
}

.stat-hp {
    color: #2ed573;
    text-shadow: 1px 1px 2px #000;
}

.card.dead {
    filter: grayscale(100%) brightness(0.4);
    opacity: 0.5;
    pointer-events: none;
}

/* Animations */
.anim-attack-up {
    animation: attackUp 0.3s ease-in-out alternate 2;
}

.anim-attack-down {
    animation: attackDown 0.3s ease-in-out alternate 2;
}

.anim-shake {
    animation: shake 0.3s cubic-bezier(.36, .07, .19, .97) both;
}

/* Bottom Panel */
.bottom-panel {
    background: rgba(15, 17, 21, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 15px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls {
    display: flex;
    justify-content: space-between;
}

.control-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.border-glow {
    border-color: var(--accent-blue);
    box-shadow: 0 0 8px rgba(0, 210, 211, 0.3);
}

.battle-log {
    height: 40px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 0.75rem;
    color: #aaa;
    overflow-y: hidden;
    display: flex;
    align-items: center;
    position: relative;
}

.battle-log::after {
    content: "▼";
    position: absolute;
    right: 10px;
    opacity: 0.5;
    font-size: 0.6rem;
}

/* Overlays & Alerts */
#turn-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.8), 0 0 10px var(--gold);
    z-index: 50;
    pointer-events: none;
    animation: zoomFade 1.5s forwards;
}

.hidden {
    display: none !important;
}

/* Damage Numbers */
.dmg-number {
    position: absolute;
    color: #ff4757;
    font-size: 1.5rem;
    font-weight: 900;
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
    z-index: 30;
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
}

.heal-number {
    color: #2ed573;
}

/* Miss Text */
.dmg-number.miss-text {
    color: #a4b0be;
    font-size: 1.2rem;
    text-shadow: 1px 1px 0 #000;
}

/* Crit Text */
.dmg-number.crit-text {
    color: #ffa502;
    font-size: 2rem;
    font-weight: 900;
    text-shadow: 2px 2px 0 #ff4757, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
    animation: floatUpCrit 1s ease-out forwards;
}

/* VFX */
.vfx-hit {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.8) 0%, rgba(255, 71, 87, 0) 70%);
    pointer-events: none;
    z-index: 25;
    animation: vfxFlash 0.3s ease-out forwards;
}

.vfx-crit {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(255, 165, 2, 1) 0%, rgba(255, 71, 87, 1) 50%, rgba(0, 0, 0, 0) 80%);
    pointer-events: none;
    z-index: 25;
    animation: vfxFlashCrit 0.4s ease-out forwards;
    mix-blend-mode: screen;
}

.anim-evade {
    animation: evadeSide 0.3s ease-in-out;
}

/* Keyframes */
@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 10px rgba(221, 183, 113, 0.4);
    }

    50% {
        box-shadow: 0 0 30px rgba(221, 183, 113, 0.8);
    }

    100% {
        box-shadow: 0 0 10px rgba(221, 183, 113, 0.4);
    }
}

@keyframes attackUp {
    100% {
        transform: translateY(-30px) scale(1.1);
        z-index: 30;
    }
}

@keyframes attackDown {
    100% {
        transform: translateY(30px) scale(1.1);
        z-index: 30;
    }
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-2px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(4px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-8px, 0, 0);
        filter: brightness(2) drop-shadow(0 0 10px red);
    }

    40%,
    60% {
        transform: translate3d(8px, 0, 0);
    }
}

@keyframes zoomFade {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

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

    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(0.5);
        opacity: 1;
    }

    50% {
        transform: translateY(-30px) scale(1.5);
    }

    100% {
        transform: translateY(-50px) scale(1);
        opacity: 0;
    }
}

#result-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.9);
}

#result-title {
    font-size: 3rem;
    color: var(--gold);
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(221, 183, 113, 0.6);
}