:root {
    --primary: #cd5c2c;
    /* Rust Orange */
    --primary-light: #ff763b;
    --health: linear-gradient(90deg, #c0392b, #e74c3c);
    --hunger: linear-gradient(90deg, #f39c12, #f1c40f);
    --thirst: linear-gradient(90deg, #2980b9, #3498db);
    --radiation: linear-gradient(90deg, #27ae60, #2ecc71);
    --bg-dark: rgba(10, 10, 10, 0.98);
    --border: rgba(255, 255, 255, 0.08);
    --slot-bg: rgba(255, 255, 255, 0.02);

    /* Rarity Colors */
    --rarity-common: #607d8b;
    --rarity-rare: #1e88e5;
    --rarity-elite: #43a047;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background-color: #000;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a0a;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    color: white;
}

.loader {
    width: 60px;
    height: 60px;
    border: 4px solid #1a1a1a;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

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

/* HUD */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.top-left {
    position: absolute;
    top: 30px;
    left: 30px;
}

.stat-bar {
    width: 250px;
    height: 12px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    margin-bottom: 8px;
    position: relative;
}

.bar-fill {
    height: 100%;
    transition: width 0.3s;
}

.health .bar-fill {
    background: var(--health);
}

.hunger .bar-fill {
    background: var(--hunger);
}

.thirst .bar-fill {
    background: var(--thirst);
}

.radiation .bar-fill {
    background: var(--radiation);
}

.stats {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    gap: 20px;
    color: white;
    font-weight: bold;
}

#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.rarity-common {
    border-color: var(--rarity-common) !important;
    color: var(--rarity-common);
}

.rarity-rare {
    border-color: var(--rarity-rare) !important;
    color: var(--rarity-rare);
}

.rarity-elite {
    border-color: var(--rarity-elite) !important;
    color: var(--rarity-elite);
}

.rarity-elite i {
    text-shadow: 0 0 10px var(--rarity-elite);
}

/* New Rust-Style Inventory Overlay */
#inventory {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 15, 0.9);
    display: none;
    z-index: 1100;
    color: #e0e0e0;
    backdrop-filter: blur(15px);
    padding: 40px;
    box-sizing: border-box;
    flex-direction: column;
}


.inventory-tabs {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 10px;
}

.tab-item {
    font-size: 0.9rem;
    font-weight: 800;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 15px;
    transition: 0.2s;
}

.tab-item.active {
    color: #fff;
    border-bottom: 2px solid var(--primary);
}

.inventory-wrapper {
    display: none;
    grid-template-columns: 240px 1fr 400px;
    gap: 20px;
    flex: 1;
    overflow: hidden;
}

.inventory-wrapper.active {
    display: grid;
}

.inventory-main-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding: 10px;
}

.inv-grid-slot {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.player-stats-preview {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#player-3d-preview {
    flex: 1;
    width: 100%;
}

.clothing-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 20px;
}

.clothing-slot {
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #444;
}


/* Sidebar */
.inventory-sidebar {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
}

.category-item {
    padding: 12px 15px;
    font-size: 0.75rem;
    font-weight: 800;
    color: #888;
    cursor: pointer;
    transition: 0.2s;
    letter-spacing: 1px;
}

.category-item:hover,
.category-item.active {
    background: var(--primary);
    color: white;
}

/* Center Grid */
.inventory-center {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.search-container {
    position: relative;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 10px;
}

.search-container input {
    background: none;
    border: none;
    color: white;
    width: 100%;
    outline: none;
    padding-left: 30px;
}

.search-container i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
}

.crafting-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    gap: 4px;
    overflow-y: auto;
    flex: 1;
}

.craft-slot {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: 0.1s;
    padding: 5px;
    text-align: center;
}

.craft-slot:hover {
    background: rgba(255, 255, 255, 0.08);
}

.craft-slot.active {
    border: 2px solid var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

.craft-slot i {
    font-size: 1.8rem;
    color: #ccc;
    margin-bottom: 5px;
}

.item-name-label {
    font-size: 0.55rem;
    font-weight: 800;
    color: #888;
    text-transform: uppercase;
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* Detail Panel */
.inventory-right {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.detail-empty {
    margin: auto;
    text-align: center;
    color: #444;
}

.detail-empty i {
    font-size: 3rem;
    margin-bottom: 10px;
}

.detail-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
}

.detail-title {
    font-size: 1.4rem;
    font-weight: 900;
    text-transform: uppercase;
}

.detail-subtitle {
    font-size: 0.7rem;
    color: #2ecc71;
    font-weight: 800;
    margin-top: 5px;
}

.detail-desc {
    font-size: 0.85rem;
    color: #888;
    line-height: 1.4;
}

.cost-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cost-header {
    display: grid;
    grid-template-columns: 80px 1fr 60px 60px;
    font-size: 0.6rem;
    color: #555;
    padding: 5px;
    font-weight: 800;
}

.cost-item {
    display: grid;
    grid-template-columns: 80px 1fr 60px 60px;
    background: rgba(255, 255, 255, 0.02);
    padding: 10px 5px;
    font-size: 0.8rem;
    align-items: center;
}

.cost-item.missing {
    color: #e74c3c;
}

.action-row {
    margin-top: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.qty-control {
    display: flex;
    background: #1a1a1a;
    border: 1px solid #333;
}

.qty-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
}

.qty-val {
    width: 60px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid #333;
    border-right: 1px solid #333;
    font-size: 0.9rem;
}

.craft-btn {
    flex: 1;
    background: #2ecc71;
    color: white;
    font-weight: 900;
    height: 40px;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
}

.craft-btn:disabled {
    background: #2c3e50;
    color: #5d6d7e;
    cursor: not-allowed;
}

.inventory-bottom-bar {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}


/* Instructions */
#instructions {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

#start-button {
    padding: 15px 40px;
    background: var(--primary);
    border: none;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    cursor: pointer;
    margin-top: 20px;
}

/* Mobile Controls Styling */
#mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2000;
}

#joystick-zone {
    position: absolute;
    bottom: 50px;
    left: 50px;
    width: 150px;
    height: 150px;
    pointer-events: all;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

#joystick-base {
    position: relative;
    width: 100%;
    height: 100%;
}

#joystick-stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    background: var(--primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 20px rgba(205, 92, 44, 0.5);
}

#action-buttons {
    position: absolute;
    bottom: 50px;
    right: 50px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    pointer-events: all;
}

.mobile-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mobile-btn:active {
    background: var(--primary);
    transform: scale(0.9);
}

@media (max-width: 768px) {
    #mobile-controls {
        display: block !important;
    }

    #hud .top-left {
        top: 10px;
        left: 10px;
        transform: scale(0.8);
        transform-origin: top left;
    }

    #hud .hotbar {
        bottom: 10px;
        transform: scale(0.8);
    }
}