:root {
    /* Colors */
    --bg-dark: #0f172a;
    --bg-glass: rgba(30, 41, 59, 0.7);
    --border-glass: rgba(255, 255, 255, 0.1);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --accent-blue: #38bdf8;
    --accent-blue-hover: #0ea5e9;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    
    /* Item Rarities */
    --rarity-common: #cbd5e1;
    --rarity-uncommon: #4ade80;
    --rarity-rare: #60a5fa;
    --rarity-epic: #c084fc;
    --rarity-legendary: #fbbf24;
    --rarity-mythical: #f43f5e;
    
    /* Layout */
    --radius: 8px;
    --font-main: 'Inter', sans-serif;
    --font-mono: 'Fira Code', monospace;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden; /* Desktop widget feel */
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    max-width: 1350px;
    height: 100%;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
}

/* Typography */
h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.5rem;
    color: var(--accent-blue);
}
h3 {
    font-size: 1rem;
    color: var(--text-main);
}
.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }

/* Components */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.hidden {
    display: none !important;
}

/* Header / Status Bar */
.status-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.level-up-flash {
    animation: levelUpGlow 3s ease-out;
}

@keyframes levelUpGlow {
    0% { box-shadow: 0 0 20px 5px var(--accent-green); background: rgba(34, 197, 94, 0.2); }
    100% { box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); background: var(--bg-glass); }
}

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

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.highlight { color: var(--accent-blue); }
.money-text { color: var(--accent-green); }

.xp-group {
    flex: 1;
    margin: 0 2rem;
}

.xp-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(0,0,0,0.4);
    border-radius: 4px;
    overflow: hidden;
    margin: 0.25rem 0;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    width: 0%;
    transition: width 0.3s ease-out;
}

@keyframes flashLevelUp {
    0% { filter: brightness(1); box-shadow: 0 0 0px rgba(56, 189, 248, 0); }
    50% { filter: brightness(1.5); box-shadow: 0 0 20px rgba(56, 189, 248, 1); }
    100% { filter: brightness(1); box-shadow: 0 0 0px rgba(56, 189, 248, 0); }
}
.flash { animation: flashLevelUp 0.8s ease-out; }

/* Main Layout */
.main-container {
    display: grid;
    grid-template-columns: 220px 220px 1fr 280px;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

/* Equipment */
.equipment-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.equip-slots {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.equip-slot {
    background: rgba(0,0,0,0.2);
    border: 1px dashed var(--border-glass);
    border-radius: var(--radius);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.2s;
}

.equip-slot:hover {
    border-color: var(--accent-blue);
}

.slot-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.slot-item {
    font-size: 0.9rem;
    font-weight: 500;
}
.slot-item.empty {
    color: var(--text-muted);
    font-style: italic;
}

/* Center Panel (Tabs & Views) */
.center-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    border-radius: 4px;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--accent-blue);
    color: #fff;
}

.view-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s ease-out;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    overflow-y: auto;
    padding-right: 0.5rem; /* For scrollbar */
}
.view.active {
    opacity: 1;
    transform: translateX(0);
    position: relative;
    pointer-events: auto;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-main);
    transition: transform 0.1s, filter 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { filter: brightness(1.1); }

.primary-btn {
    background: var(--accent-blue);
    color: #fff;
    width: 100%;
    font-size: 1.1rem;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.danger-btn { background: var(--accent-red); color: #fff; }
.buy-btn { background: var(--accent-green); color: #fff; }

.btn:disabled {
    background: #334155 !important;
    color: #64748b !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    opacity: 0.7;
    animation: none;
}

@keyframes pulseReady {
    0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

.btn-ready {
    animation: pulseReady 2s infinite;
}

/* Task Progress */
.task-progress-container {
    background: rgba(0,0,0,0.3);
    padding: 1rem;
    border-radius: var(--radius);
    margin-top: 1rem;
}

.task-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: rgba(0,0,0,0.5);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-green);
    width: 0%;
    transition: width 0.1s ease-out;
}

/* Task Queue */
.task-queue-container {
    padding: 1rem;
    height: auto;
    min-height: 250px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse; /* Newest at bottom visually, or we prepend. We will just use flex-end */
    justify-content: flex-end;
}

#task-queue {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.queued-task {
    background: rgba(0,0,0,0.4);
    padding: 0.75rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    border-left: 3px solid var(--accent-blue);
    animation: slideUp 0.3s ease-out;
}

.slide-in-right {
    animation: slideInRight 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Drops */
.drop-container {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    pointer-events: none; /* Let clicks pass through empty areas */
}

.drop-item {
    pointer-events: auto;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    cursor: pointer;
    animation: floatUp 0.3s ease-out;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}
.drop-item:hover { transform: scale(1.05); }

@keyframes floatUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Inventory */
.inventory-panel {
    display: flex;
    flex-direction: column;
}

.inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex: 1;
    align-content: start;
    overflow-y: auto;
}

.inv-slot {
    aspect-ratio: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-glass);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    position: relative;
}
.inv-slot:hover { background: rgba(255,255,255,0.05); }
.inv-slot.selected { border-color: #fff; box-shadow: 0 0 5px #fff; }

/* Item Context Panel */
.item-context {
    background: rgba(0,0,0,0.4);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: auto;
}

.ctx-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.action-btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.85rem;
    background: var(--bg-glass);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
}
.sell-btn { background: rgba(239, 68, 68, 0.2); }
.sell-btn:hover { background: rgba(239, 68, 68, 0.5); }

/* Skills */
.skills-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.skill-card {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-glass);
    padding: 1rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.skill-info h4 { color: var(--accent-blue); margin-bottom: 0.25rem; }
.skill-info p { font-size: 0.8rem; color: var(--text-muted); }

.skill-btn {
    background: var(--bg-glass);
    border: 1px solid var(--accent-blue);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}
.skill-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: var(--text-muted);
}
.skill-btn.purchased {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: #fff;
}

/* Rarity Colors */
.rarity-common { color: var(--rarity-common); border-color: var(--rarity-common) !important; }
.rarity-uncommon { color: var(--rarity-uncommon); border-color: var(--rarity-uncommon) !important; }
.rarity-rare { color: var(--rarity-rare); border-color: var(--rarity-rare) !important; }
.rarity-epic { color: var(--rarity-epic); border-color: var(--rarity-epic) !important; }
.rarity-legendary { color: var(--rarity-legendary); border-color: var(--rarity-legendary) !important; }
.rarity-mythical { color: var(--rarity-mythical); border-color: var(--rarity-mythical) !important; text-shadow: 0 0 5px var(--rarity-mythical); }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

/* Responsive / Scaling for small windows */
@media (max-width: 900px) {
    html { font-size: 14px; }
    .main-container {
        grid-template-columns: 1fr;
    }
    body {
        overflow-y: auto;
    }
    #app {
        height: auto;
        max-height: none;
    }
    .equipment-panel, .inventory-panel {
        min-height: 300px;
    }
}

@media (max-width: 500px) {
    html { font-size: 12px; }
    .status-bar {
        flex-direction: column;
        gap: 0.5rem;
    }
    .xp-group { margin: 0; width: 100%; }
}

/* Modals & Overlays */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); display: flex; justify-content: center; align-items: center; z-index: 1000; opacity: 1; transition: opacity 0.3s ease; }
.modal-overlay.hidden { opacity: 0; pointer-events: none; display: flex !important; }
.modal-box { background: #0f172a; border: 1px solid var(--border-glass); border-radius: var(--radius); padding: 1.5rem; width: 90%; max-width: 400px; box-shadow: 0 10px 30px rgba(0,0,0,0.8); text-align: center; transform: scale(1); transition: transform 0.3s ease; }
.modal-overlay.hidden .modal-box { transform: scale(0.9); }
.modal-actions { display: flex; gap: 1rem; margin-top: 1.5rem; justify-content: center; }
/* Roulette Spinner */
.roulette-window { width: 100%; height: 100px; background: rgba(0,0,0,0.5); border: 2px solid var(--border-glass); border-radius: var(--radius); margin-top: 1rem; position: relative; overflow: hidden; display: flex; align-items: center; }
.roulette-marker { position: absolute; left: 50%; top: 0; bottom: 0; width: 4px; background: #fff; z-index: 10; transform: translateX(-50%); box-shadow: 0 0 10px #fff; }
.roulette-strip { display: flex; gap: 0.5rem; height: 80px; align-items: center; position: absolute; left: 50%; transform: translateX(0); /* animated via JS */ }
.roulette-item { width: 80px; height: 80px; flex-shrink: 0; background: rgba(0,0,0,0.8); border: 2px solid var(--border-glass); border-radius: 4px; display: flex; flex-direction: column; justify-content: center; align-items: center; font-size: 1.5rem; font-weight: bold; }
.roulette-item-name { font-size: 0.6rem; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; padding: 0 2px; }


/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 34px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255,255,255,0.2); transition: .4s; border: 1px solid var(--border-glass); }
.slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 3px; bottom: 3px; background-color: var(--text-main); transition: .4s; }
input:checked + .slider { background-color: var(--accent-blue); }
input:checked + .slider:before { transform: translateX(14px); }
.slider.round { border-radius: 20px; }
.slider.round:before { border-radius: 50%; }


/* Uniform Market Buttons */
.shop-item button { width: 140px; flex: 0 0 140px; text-align: center; white-space: nowrap; }

/* Sell Drop Zone */
#sell-drop-zone { border: 2px dashed rgba(239, 68, 68, 0.5); padding: 1.5rem; text-align: center; border-radius: 8px; margin-top: 1rem; color: rgba(239, 68, 68, 0.8); transition: all 0.3s; }
#sell-drop-zone.drag-over { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 1); color: rgba(239, 68, 68, 1); }


/* Tooltip */
.item-tooltip { position: fixed; background: rgba(15, 23, 42, 0.95); border: 1px solid var(--border-glass); border-radius: 8px; padding: 1rem; pointer-events: none; z-index: 1000; box-shadow: 0 4px 12px rgba(0,0,0,0.5); backdrop-filter: blur(10px); color: var(--text-main); transform: translate(-50%, 10px); }
.item-tooltip.hidden { display: none; }

