:root {
    --primary-color: #ffd700; /* Gold */
    --secondary-color: #ff4500; /* OrangeRed */
    --accent-color: #00bfff; /* DeepSkyBlue */
    --bg-dark: #1a1a2e;
    --bg-panel: rgba(22, 33, 62, 0.95);
    --text-color: #eaeaea;
    --border-color: #0f3460;
    --success-color: #00ff7f;
    --danger-color: #ff0055;
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    color: var(--text-color);
    background-image: url("img/background.png");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

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

.screen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

/* --- Loader --- */
#loader {
    background-color: var(--bg-dark);
    z-index: 2000;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.1);
    border-top: 6px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Main Layout --- */
.main-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

.container {
    background-color: var(--bg-panel);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    padding: 20px;
    width: 90%;
    max-width: 450px;
    border: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    box-sizing: border-box;
}

/* --- Game Screen --- */
.header-stats {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.stat-box {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    text-align: center;
    min-width: 120px;
}

.stat-box .label {
    display: block;
    font-size: 0.9rem;
    color: #aaa;
    margin-bottom: 5px;
}

.stat-box .value {
    display: block;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.monster-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
    width: 100%;
}

.monster-area {
    position: relative;
    width: 250px;
    height: 250px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.monster {
    width: 180px;
    height: 180px;
    cursor: pointer;
    transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: drop-shadow(0 10px 10px rgba(0,0,0,0.5));
}

.monster:active {
    transform: scale(0.95);
}

.monster.hit {
    animation: shake 0.2s;
    filter: brightness(1.5) sepia(1) hue-rotate(-50deg) saturate(3);
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.hp-info {
    width: 100%;
    margin-top: 20px;
    text-align: center;
}

.hp-bar-bg {
    width: 100%;
    height: 24px;
    background: #333;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
    border: 1px solid #555;
}

.hp-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ff3333, #ff0055);
    transition: width 0.2s ease-out;
}

.hp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.85rem;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    color: white;
}

.stage-info {
    margin-top: 10px;
    font-size: 1.1rem;
    color: #aaa;
}

/* --- Floating Numbers --- */
.floating-number {
    position: absolute;
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
    font-weight: bold;
    font-size: 1.5rem;
    color: white;
    text-shadow: 2px 2px 0 #000;
    z-index: 10;
}

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

/* --- Controls Button --- */
.controls-container {
    display: flex;
    gap: 15px;
    width: 100%;
}

.nav-button {
    flex: 1;
    padding: 15px;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.shop-btn {
    background: linear-gradient(135deg, var(--primary-color), #daa520);
    color: #1a1a2e;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
}

.settings-btn {
    flex: 0 0 60px;
    background: #444;
    color: white;
}

.nav-button:hover {
    transform: translateY(-3px);
    filter: brightness(1.1);
}

.nav-button:active {
    transform: translateY(1px);
}

/* --- Shop Screen --- */
.shop-panel {
    max-height: 80vh;
}

.shop-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 15px;
}

.currency {
    font-size: 1.5rem;
    color: var(--primary-color);
    font-weight: bold;
}

.close-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: white;
}

.upgrades-list {
    width: 100%;
    overflow-y: auto;
    padding-right: 5px;
}

/* Custom Scrollbar for list */
.upgrades-list::-webkit-scrollbar {
    width: 8px;
}
.upgrades-list::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
}
.upgrades-list::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.upgrade-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
    transition: background 0.2s;
}

.upgrade-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.upgrade-info h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--accent-color);
}

.upgrade-info p {
    margin: 5px 0 0;
    font-size: 0.9rem;
    color: #aaa;
}

.upgrade-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.current-stat {
    font-size: 0.8rem;
    color: #888;
}

.upgrade-btn {
    background: #2a2a40;
    border: 1px solid var(--accent-color);
    color: white;
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 80px;
    font-weight: bold;
}

.upgrade-btn:hover:not(:disabled) {
    background: var(--accent-color);
    color: #1a1a2e;
}

.upgrade-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #555;
    background: #222;
}

/* --- Modal --- */
.modal {
    display: none; /* JS toggles 'flex' */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 3000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--bg-panel);
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    border: 2px solid var(--border-color);
    text-align: center;
    position: relative;
    box-shadow: 0 10px 40px black;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #aaa;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
}

.danger-btn {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.secondary-btn {
    background: #555;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
}

/* --- Monster Death Animation --- */
@keyframes monster-death {
    0% { transform: scale(1) rotate(0); opacity: 1; filter: grayscale(0); }
    50% { transform: scale(1.1) rotate(10deg); opacity: 0.7; filter: grayscale(1); }
    100% { transform: scale(0) rotate(-10deg); opacity: 0; filter: blur(10px); }
}

.monster-death {
    animation: monster-death 0.4s forwards ease-in;
}

/* --- Safe Area for mobile --- */
@media (max-width: 600px) {
    .container {
        width: 95%;
        padding: 15px;
    }
    
    .monster {
        width: 150px;
        height: 150px;
    }

    .stat-box .value {
        font-size: 1.5rem;
    }
}
