:root {
    --bg-color: #0f172a;
    /* Fallback */
    --panel-bg: rgba(30, 41, 59, 0.85);
    --panel-border: rgba(255, 255, 255, 0.15);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;

    /* RPG Colors */
    --hp-color: #ef4444;
    --mp-color: #3b82f6;
    --exp-color: #10b981;
    --crit-color: #fbbf24;
    --dmg-color: #fca5a5;

    --font-pixel: 'Press Start 2P', cursive;
    --font-ui: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    /* Stop page scrolling */
}

/* Container locking aspect ratio or full screen */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

canvas {
    display: block;
    /* Maintain pixel art crispness */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Optional: scale up the canvas visually if needed, but we handle internal sizing */
}

/* UI Overlays */
.ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas by default */
    z-index: 10;
}

.ui-overlay.hidden {
    display: none;
}

/* Make specific UI elements clickable */
.glass-panel,
.btn,
.hotbar-slot,
.window-panel {
    pointer-events: auto;
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 2px solid var(--panel-border);
    border-radius: 4px;
    /* Pixely UI prefers less rounded corners */
    padding: 1rem;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
}

/* Text Utilities */
.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.text-dim {
    color: var(--text-secondary);
}

.pixel-title {
    font-family: var(--font-pixel);
    font-size: 2.5rem;
    color: #fff;
    text-shadow: 4px 4px 0 #3b82f6, -2px -2px 0 #8b5cf6;
    margin-bottom: 1rem;
}

.instructions {
    font-family: var(--font-pixel);
    font-size: 0.75rem;
    line-height: 2;
    color: var(--text-secondary);
}

/* Buttons */
.btn-pixel {
    font-family: var(--font-pixel);
    font-size: 1rem;
    background: #3b82f6;
    color: white;
    border: 4px solid #fff;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

.btn-pixel:hover {
    background: #60a5fa;
}

.btn-pixel:active {
    box-shadow: inset 4px 4px 0 rgba(0, 0, 0, 0.3);
    transform: translate(2px, 2px);
}

/* HUD System */
#player-hud {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 250px;
    padding: 10px;
}

.hud-top {
    font-family: var(--font-pixel);
    font-size: 0.7rem;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.bar-container {
    width: 100%;
    height: 18px;
    background: #000;
    border: 2px solid #333;
    position: relative;
}

.bar-fill {
    height: 100%;
    width: 100%;
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.hp-container .bar-fill {
    background: var(--hp-color);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3);
}

.exp-container .bar-fill {
    background: var(--exp-color);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3);
}

.bar-text {
    position: absolute;
    top: 50%;
    left: 5px;
    transform: translateY(-50%);
    font-family: var(--font-pixel);
    font-size: 0.5rem;
    color: white;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
}

/* Target HUD */
#target-hud {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    padding: 8px;
    text-align: center;
}

.target-name {
    font-family: var(--font-pixel);
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.target-hud .bar-container {
    height: 12px;
}

/* Hotbar */
.hotbar-container {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.5);
    padding: 6px;
    border: 2px solid #555;
    border-radius: 4px;
}

.hotbar-slot {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid #444;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: pointer;
}

.hotbar-slot.active {
    border-color: #fff;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
}

.slot-number {
    position: absolute;
    top: 2px;
    left: 4px;
    font-family: var(--font-pixel);
    font-size: 0.5rem;
    color: #aaa;
}

.slot-qty {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    text-shadow: 1px 1px 0 #000;
}

/* Draggable Windows */
.window-panel {
    position: absolute;
    top: 100px;
    left: 100px;
    width: 600px;
    min-height: 400px;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.window-header {
    background: #333;
    padding: 10px;
    font-family: var(--font-pixel);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    border-bottom: 2px solid var(--panel-border);
}

.close-btn {
    background: #ef4444;
    border: 2px solid #b91c1c;
    color: white;
    font-family: var(--font-pixel);
    padding: 4px;
    cursor: pointer;
}

.window-content.split-view {
    display: flex;
    flex-grow: 1;
    padding: 15px;
    gap: 20px;
}

.window-content h3 {
    font-family: var(--font-pixel);
    font-size: 0.9rem;
    margin-bottom: 15px;
    color: #fbbf24;
    border-bottom: 1px dashed #555;
    padding-bottom: 5px;
}

/* Stats Pane */
.stats-pane {
    flex: 1;
    border-right: 2px solid #444;
    padding-right: 15px;
    font-size: 0.9rem;
}

.stat-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

/* Inventory Pane */
.inventory-pane {
    flex: 1.5;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.inv-slot {
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #555;
    position: relative;
    cursor: pointer;
}

.inv-slot:hover {
    border-color: #888;
}

/* Menus & Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.hidden {
    display: none !important;
}

/* ==========================================================
 * NEW UI STYLES (Phase 4 Additions)
 * ========================================================== */

/* Bars */
.mp-container .bar-fill {
    background: var(--mp-color);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3);
}

.stamina-container .bar-fill {
    background: #84cc16;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3);
}

/* Menus */
.flex-col {
    display: flex;
    flex-direction: column;
}

.gap-4 {
    gap: 1rem;
}

.w-full {
    width: 100%;
}

.mb-4 {
    margin-bottom: 1rem;
}

.menu-panel {
    min-width: 300px;
    padding: 2rem;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    margin-top: 1rem;
}

.setting-row input[type=range] {
    width: 60%;
}

/* Upgrade Cards System */
.cards-container {
    max-width: 900px;
    width: 90%;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

.upgrade-card {
    background: rgba(30, 41, 59, 0.9);
    border: 2px solid var(--panel-border);
    border-radius: 12px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.34, 1.56, .64, 1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    min-height: 350px;
    position: relative;
    overflow: hidden;
}

.upgrade-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
}

.upgrade-card:hover {
    transform: translateY(-10px) scale(1.02);
    border-color: #fcd34d;
    box-shadow: 0 20px 25px -5px rgba(252, 211, 77, 0.3);
}

.card-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}

.card-title {
    font-family: var(--font-pixel);
    font-size: 1rem;
    color: #fbbf24;
    text-align: center;
    line-height: 1.4;
    margin-bottom: 1rem;
}

.card-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    flex-grow: 1;
    display: flex;
    align-items: center;
}