:root {
    /* Color Palette */
    --bg-main: #1a1a2e;
    --bg-sidebar: rgba(10, 10, 25, 0.85);
    --bg-sidebar-mobile: rgba(10, 10, 25, 0.95);
    
    /* Base Accent: #e0a35c */
    --accent-rgb: 224, 163, 92;
    --color-accent: rgb(var(--accent-rgb));
    --color-accent-hover: rgba(var(--accent-rgb), 0.15);
    --color-accent-active: rgba(var(--accent-rgb), 0.3);
    --color-text-muted: rgba(var(--accent-rgb), 0.6);
    --color-text-semi: rgba(var(--accent-rgb), 0.7);
    
    --color-error: #e05555;
    --color-error-shadow: rgba(224, 85, 85, 0.5);

    /* Typography */
    --font-sm: 12px;
    --font-base: 14px;
    --font-md: 16px;
    --font-lg: 24px;
    --font-xl: 28px;
    --font-xxl: 42px;

    /* Spacing & Sizing */
    --space-xs: 4px;
    --space-sm: 12px;
    --space-md: 20px;
    --space-lg: 30px;
    
    --radius-md: 10px;
    --radius-lg: 12px;
    
    --border-md: 3px;
    --border-lg: 4px;

    /* Z-Index Layers */
    --z-background: 0;
    --z-element-low: 1;
    --z-element-high: 2;
    --z-ui-base: 10;
    --z-ui-overlay: 15;
    --z-mobile-nav: 20;
    --z-mobile-top: 30;

    /* Animations & Transitions */
    --timing-fast: 0.15s;
    --timing-med: 0.3s;
    --timing-slow: 0.4s;
    --ease-bounce: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-main);
    overflow: hidden;
    font-family: Arial, sans-serif;
}

#playArea {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: var(--z-background);
}

#gameCanvas {
    display: block;
}

/* --- Sidebar --- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 200px;
    height: 100vh;
    background-color: var(--bg-sidebar);
    border-right: 2px solid var(--color-accent-active);
    z-index: var(--z-ui-overlay);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-lg) 15px;
}

#massDisplay {
    color: var(--color-accent);
    font-size: var(--font-xxl);
    font-weight: bold;
    margin: 0;
}

#massLabel {
    color: var(--color-text-muted);
    font-size: var(--font-base);
    letter-spacing: 3px;
    margin-top: 2px;
    margin-bottom: var(--space-lg);
}

#statsList {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.statRow {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.statLabel {
    color: var(--color-text-muted);
    font-size: var(--font-md);
}

.statValue {
    color: var(--color-accent);
    font-weight: bold;
    font-size: var(--font-md);
}

/* --- Upgrades --- */
#upgradeBar {
    position: fixed;
    top: var(--space-md);
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    opacity: 0;
    pointer-events: none;
    display: flex;
    gap: var(--space-md);
    z-index: var(--z-ui-base);
    transition: transform var(--timing-slow) var(--ease-bounce), 
                opacity var(--timing-med) var(--ease-bounce);
}

#upgradeBar.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.upgradeBlock {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.upgradeButton {
    width: 5rem;
    min-width: 10vw;
    height: 50px;
    font-size: var(--font-lg);
    background: none;
    border: var(--border-md) solid var(--color-accent);
    border-radius: var(--radius-md);
    color: var(--color-accent);
    font-weight: bold;
    cursor: pointer;
    transition: background-color var(--timing-fast), 
                color var(--timing-fast), 
                transform var(--timing-fast);
}

.upgradeButton:hover {
    background-color: var(--color-accent-hover);
    transform: scale(1.1);
    z-index: var(--z-element-high);
}

.upgradeButton:active {
    background-color: var(--color-accent);
    color: var(--bg-main);
}

.upgradeButton.maxed {
    opacity: 0.35;
    cursor: not-allowed;
}

.upgradeBlock > p {
    color: var(--color-text-semi);
    font-weight: bold;
    font-size: var(--font-md);
    margin-top: var(--space-xs);
}

.upgradeBlock > p::before {
    content: "Cost: ";
}

/* --- Interaction Elements --- */
#shop {
    color: var(--color-accent);
    font-size: var(--font-lg);
    font-weight: bold;
    margin-top: 2rem;
    align-items: center;
    background: none;
    cursor: pointer;
    border: none;
}

#shop:hover {
    transform: scale(1.1);
}

#bottomBar {
    position: fixed;
    bottom: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-ui-base);
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
}

#bottomBarInteractive {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#createDust {
    position: relative;
    width: 500px;
    height: 60px;
    font-size: var(--font-xl);
    font-weight: bold;
    background: none;
    border: var(--border-lg) solid var(--color-accent);
    border-radius: var(--radius-lg);
    color: var(--color-accent);
    cursor: pointer;
    transition: background-color var(--timing-fast), color var(--timing-fast);
    letter-spacing: 2px;
    overflow: hidden;
}

#createDustText {
    position: relative;
    z-index: var(--z-element-high);
    pointer-events: none;
}

#cooldownBar {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 0%;
    background-color: rgba(var(--accent-rgb), 0.25);
    z-index: var(--z-element-low);
    transition: none;
}

#createDust.on-cooldown {
    cursor: not-allowed;
    opacity: 0.6;
}

#createDust:hover {
    background-color: var(--color-accent-hover);
}

#createDust:active {
    background-color: var(--color-accent);
    color: var(--bg-main);
}

#autoPlayBtn {
    width: 60px;
    height: 60px;
    background: none;
    border: var(--border-lg) solid var(--color-accent);
    border-radius: var(--radius-lg);
    color: var(--color-accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--timing-fast), color var(--timing-fast);
}

#autoPlayBtn:hover {
    background-color: var(--color-accent-hover);
}

#autoPlayBtn.active {
    background-color: var(--color-accent-active);
    border-color: var(--color-accent);
}

#homeButton {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: auto;
    padding: var(--space-sm) 0;
    background: none;
    border: none;
    cursor: pointer;
}

#homeButton img {
    height: 80px;
    width: auto;
}

#meteorInventoryDisplay {
    color: var(--color-accent);
    font-weight: bold;
    font-size: var(--font-md);
}

/* Animations */
@keyframes flashRed {
    0%   { border-color: var(--color-error); box-shadow: 0 0 12px var(--color-error-shadow); }
    100% { border-color: var(--color-accent); box-shadow: none; }
}

.upgradeButton.flash-red {
    animation: flashRed var(--timing-slow) ease-out;
}

/* --- Media Queries --- */
@media (max-width: 1050px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        min-width: 100vw;
        max-width: 100vw;
        height: 70px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        padding: 0 6px;
        border-right: none;
        border-bottom: 2px solid var(--color-accent-active);
        z-index: var(--z-mobile-nav);
        background-color: var(--bg-sidebar-mobile);
        overflow-x: auto;
        overflow-y: hidden;
    }

    #homeButton {
        position: absolute;
        right: var(--space-sm);
        top: 50%;
        transform: translateY(-50%);
        margin-top: 0;
        width: auto;
        padding: 0;
        z-index: var(--z-mobile-top);
    }
    
    #homeButton img {
        height: 60px;
    }

    #massDisplay {
        font-size: var(--font-lg);
        margin: 0 10px 0 0;
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #massLabel {
        font-size: 20px;
        margin: 0 10px 0 0;
        letter-spacing: 1px;
        padding-right: 0.5rem;
        max-width: 120px;
        overflow: hidden;
        white-space: nowrap;
    }

    #statsList {
        flex-direction: row;
        gap: 1rem;
        width: auto;
        margin-left: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 70vw;
        scrollbar-width: none; 
        -ms-overflow-style: none;
    }

    #statsList::-webkit-scrollbar {
        display: none; 
    }

    .statRow {
        flex-direction: column;
        align-items: flex-start;
        width: auto;
        min-width: 1rem;
        max-width: 5rem;
    }

    .statLabel, .statValue {
        font-size: var(--font-md);
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #upgradeBar {
        top: 90px;
        width: 100vw;
        justify-content: center;
        flex-direction: row;
        gap: 16px;
        z-index: var(--z-ui-overlay);
        background: none;
    }

    .upgradeButton {
        width: 4rem;
        min-width: 80px;
        font-size: 1rem;
    }

    #createDust {
        max-width: 500px;
        width: 60vw;
    }

    #shop {
        margin-top: 0;
        font-size: var(--font-md);
        margin-left: 1rem;
    }
}

@media (max-width: 500px) {
    #sidebar {
        height: 50px;
    }

    #massDisplay {
        font-size: var(--font-md);
        max-width: 60px;
    }

    #massLabel {
        font-size: var(--font-base);
        max-width: 100px;
    }

    .statLabel, .statValue {
        font-size: var(--font-sm);
        max-width: 60px;
    }

    .upgradeButton {
        width: 3rem;
    }

    #upgradeBar {
        flex-wrap: wrap;
        width: 90vw;
        row-gap: var(--space-xs);
        right: unset;
    }

    #shop {
        font-size: var(--font-base);
    }

    #homeButton {
        right: 0;
    }

    #homeButton img {
        height: 40px;
    }
}
