:root {
    --bg-color: #0d0d0d;
    --text-color: #f0e6d2;
    --gold: #d4af37;
    --gold-dim: #8b7322;
    --panel-bg: rgba(10, 10, 10, 0.9);
    --font-ui: "Cinzel", "Times New Roman", serif;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-ui);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* 3D Canvas Layer */
#game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Lowest layer */
}

canvas {
    display: block;
    /* Remove inline canvas gap */
}

/* Center Crosshair */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.5);
    font-size: 24px;
    z-index: 5;
    pointer-events: none;
}

/* UI Overlay Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to 3D canvas unless stopped */
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    background: var(--panel-bg);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    /* Catch clicks for the menus */
}

.screen.hidden {
    display: none !important;
}

/* Specific purely HUD adjustments */
#screen-hud {
    background: transparent;
    justify-content: flex-start;
}

#screen-hud.active {
    pointer-events: none;
    /* Crucial: HUD should not block clicks to the 3D scene */
}

/* Menu Components */
h1.title {
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 0 0 10px var(--gold-dim);
    margin-bottom: 0.5rem;
    text-align: center;
}

h2.subtitle {
    font-size: 1.5rem;
    color: #ccc;
    margin-bottom: 3rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 250px;
}

.btn {
    background: linear-gradient(to bottom, #4a3e14, #2a230b);
    border: 1px solid var(--gold);
    color: var(--text-color);
    padding: 12px 20px;
    font-size: 1.2rem;
    font-family: inherit;
    cursor: pointer;
    border-radius: 5px;
    text-shadow: 1px 1px 2px black;
    transition: all 0.2s;
    outline: none;
}

.btn:hover {
    background: linear-gradient(to bottom, #605118, #3a3010);
}

.btn:active {
    transform: scale(0.95);
}

.btn.small {
    padding: 5px 10px;
    font-size: 1rem;
}

/* HUD Top Bar */
.hud-top {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    /* Allow passthrough mostly */
}

/* Minimap */
.minimap-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 2px solid var(--gold);
    overflow: hidden;
    pointer-events: auto;
    /* Catch click */
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
    background: #111;
    z-index: 50;
    /* Above action buttons */
}

/* Stats */
.hud-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Move to left side next to menu button */
    pointer-events: none;
    text-shadow: 1px 1px 2px black;
    font-size: 1.2rem;
    margin-left: 20px;
}

.inventory-counts {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

/* Bottom Inventory */
.hud-inventory {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--gold-dim);
    pointer-events: none;
}

.inv-slot {
    width: 40px;
    height: 40px;
    border: 1px solid #555;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    border-radius: 5px;
}

/* Message Overlay (Center screen text popup) */
.msg-overlay {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    color: var(--gold);
    text-shadow: 0 0 5px black, 0 0 10px black;
    text-align: center;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 5px;
    opacity: 1;
    transition: opacity 0.5s;
    pointer-events: none;
}

.msg-overlay.hidden {
    opacity: 0;
}

/* Modals */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    pointer-events: auto;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal-box {
    background: var(--panel-bg);
    border: 2px solid var(--gold-dim);
    border-radius: 10px;
    padding: 20px;
    width: 80%;
    max-width: 400px;
    text-align: center;
}

/* Utilities */
.text-danger {
    color: #e74c3c;
    text-shadow: 0 0 10px #e74c3c;
}

.text-success {
    color: #2ecc71;
    text-shadow: 0 0 10px #2ecc71;
}

.mt-4 {
    margin-top: 20px;
}

/* Ad Placeholder */
.ad-banner {
    margin-top: 40px;
    width: 320px;
    height: 50px;
    background: #222;
    border: 1px dashed #555;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #666;
    font-size: 0.8rem;
}

/* ========= MOBILE/TOUCH CONTROLS ========= */
.virtual-joystick {
    position: absolute;
    bottom: 30px;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: none;
    /* Hidden on desktop */
}

.virtual-joystick.left {
    left: 20px;
}

.virtual-joystick.right {
    right: 20px;
}

/* Optional if we just use screen drag for looking */
.virtual-joystick .knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(212, 175, 55, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.mobile-action-buttons {
    position: absolute;
    bottom: 30px;
    right: 20px;
    display: none;
    /* Hidden on desktop */
    flex-direction: row;
    gap: 15px;
}

.action-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid var(--gold-dim);
    color: white;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.action-btn:active {
    background: rgba(212, 175, 55, 0.5);
}

/* Show touch controls on coarse pointer */
@media (pointer: coarse) {
    .virtual-joystick.left {
        display: block;
    }

    .mobile-action-buttons {
        display: flex;
        bottom: 200px;
    }

    /* Bump above minimap */
    .hud-inventory {
        bottom: 100px;
    }

    /* Bump inventory up */
}

/* Settings */
.settings-panel {
    background: rgba(0, 0, 0, 0.5);
    padding: 20px;
    margin: 20px 0;
    border-radius: 10px;
    border: 1px solid var(--gold-dim);
    width: 300px;
}

.setting-row {
    margin-bottom: 20px;
}

.setting-row label {
    display: block;
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.setting-row input[type=range] {
    width: 100%;
    cursor: pointer;
}