body {
    margin: 0;
    overflow: hidden;
    background-color: #000;
    font-family: 'Courier New', Courier, monospace;
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    padding: 20px;
    box-sizing: border-box;
}

#player-stats-hud {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#player-health-bar, #player-exp-bar {
    width: 300px;
    height: 20px;
    background-color: #333;
    border: 2px solid #fff;
}

#player-health {
    width: 100%;
    height: 100%;
    background-color: #0f0;
    transition: width 0.2s;
}

#player-exp {
    width: 0%;
    height: 100%;
    background-color: #00f;
    transition: width 0.2s;
}

#player-level-display {
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
}

#zone-display {
    position: absolute;
    bottom: 20px;
    right: 20px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 4px black;
}

#online-counter {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #00ffcc;
    font-size: 20px;
    font-weight: bold;
    text-shadow: 2px 2px 4px black;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 15px;
    border-radius: 5px;
    border: 1px solid #00ffcc;
}

#sound-toggle {
    position: absolute;
    top: 62px;
    right: 20px;
    color: #00ffcc;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 12px;
    border-radius: 5px;
    border: 1px solid #00ffcc;
    cursor: pointer;
}
#sound-toggle:hover { background: rgba(0, 255, 204, 0.2); }
#sound-toggle.muted { color: #888; border-color: #888; }

#instructions {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    color: white;
    font-size: 18px;
    text-shadow: 1px 1px 2px black;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: right;
    pointer-events: none;
}

#dialogue-box {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    background: rgba(0, 0, 50, 0.8);
    border: 2px solid #fff;
    border-radius: 10px;
    padding: 20px;
    color: white;
    font-size: 20px;
    z-index: 20;
}

#dialogue-box .hint {
    font-size: 14px;
    color: #aaa;
    text-align: right;
    margin-top: 10px;
    margin-bottom: 0;
}

#game-over {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(100, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    pointer-events: auto;
    z-index: 30;
}

#game-over h1 {
    font-size: 64px;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px black;
}

#restart-btn {
    padding: 10px 20px;
    font-size: 24px;
    cursor: pointer;
    background: white;
    border: none;
    border-radius: 5px;
}

#restart-btn:hover {
    background: #ddd;
}

#enemy-health-container {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 5;
}

.enemy-health-bar {
    position: absolute;
    width: 50px;
    height: 6px;
    background-color: #333;
    border: 1px solid #fff;
    transform: translate(-50%, -50%);
    display: none;
}

.enemy-health-fill {
    width: 100%;
    height: 100%;
    background-color: #f00;
    transition: width 0.2s;
}

/* Boss floating health bar (wider + gold styling) */
.boss-health-bar {
    width: 90px;
    height: 9px;
    border: 2px solid #ffaa00;
    box-shadow: 0 0 8px #ffaa00;
}

/* Enemy name tags (float above health bar) */
.enemy-name-tag {
    color: #ff6666;
    font-size: 12px;
    transform: translate(-50%, -100%);
}

.boss-name-tag {
    color: #ffaa00;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Player Name Tags */
.player-name-tag {
    position: absolute;
    color: white;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 1px 1px 2px black, -1px -1px 2px black, 1px -1px 2px black, -1px 1px 2px black;
    transform: translate(-50%, -100%);
    pointer-events: none;
    z-index: 5;
}

/* Chat UI */
#chat-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 350px;
    z-index: 10;
    pointer-events: auto;
}

#chat-tabs {
    display: flex;
    gap: 2px;
}
.chat-tab {
    flex: 1;
    padding: 5px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 5px 5px 0 0;
    color: #aaa;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}
.chat-tab.active {
    background: rgba(0, 0, 0, 0.75);
    color: #ffaa00;
    font-weight: bold;
}

.chat-pane {
    height: 150px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    color: white;
    font-size: 14px;
    text-shadow: 1px 1px 1px black;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.chat-msg {
    word-wrap: break-word;
}

.chat-msg .sender {
    font-weight: bold;
    color: #ffaa00;
}

.system-msg {
    word-wrap: break-word;
    color: #8fd18f;
}
.system-msg .sys-time {
    color: #888;
    margin-right: 6px;
    font-size: 12px;
}

#chat-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid #555;
    border-radius: 0 0 5px 5px;
    color: white;
    font-size: 14px;
    outline: none;
}

#chat-input:focus {
    border-color: #ffaa00;
}

/* --- New UI Panels --- */
.panel {
    position: absolute;
    background: rgba(20, 20, 40, 0.9);
    border: 2px solid #aaa;
    border-radius: 8px;
    padding: 20px;
    color: white;
    pointer-events: auto;
    z-index: 15;
}

.panel h2 {
    margin-top: 0;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
}

/* Inventory */
#inventory-panel {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
}

#inventory-gold, #shop-gold {
    color: #ffd24a;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 15px;
}
#inventory-gold .coin, #shop-gold .coin {
    color: #ffcc33;
    text-shadow: 0 0 4px #aa7700;
}

/* Merchant shop */
#shop-menu {
    min-width: 280px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#blacksmith-menu {
    min-width: 320px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Draggable panel header affordance */
.panel h2 { cursor: move; user-select: none; }

/* Equipment slots */
#equipment-slots {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    justify-content: center;
}
.equip-slot {
    width: 70px;
    height: 70px;
    border: 1px solid #555;
    border-radius: 6px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.3);
}
.equip-slot .equip-label { opacity: 0.4; }
.equip-slot .item {
    position: absolute;
    inset: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}
.shop-section { margin-bottom: 12px; }
.shop-section h3 {
    margin: 6px 0 4px;
    font-size: 14px;
    color: #ccc;
    border-bottom: 1px solid #555;
    padding-bottom: 3px;
}
.shop-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 0;
}
.shop-row .price { color: #ffd24a; font-size: 13px; }
.shop-row button {
    padding: 3px 12px;
    font-size: 13px;
    cursor: pointer;
}
.shop-row button:disabled { opacity: 0.4; cursor: not-allowed; }
.shop-empty { color: #888; font-size: 13px; font-style: italic; }

#inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}

.inv-slot {
    width: 60px;
    height: 60px;
    background: #333;
    border: 1px solid #666;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.inv-slot:hover {
    border-color: #fff;
}

.item {
    width: 50px;
    height: 50px;
    background: #888;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    text-align: center;
    user-select: none;
    position: relative;
}

.item.potion { background: #f55; }
.item.loot { background: #aa5; }

.item-qty {
    position: absolute;
    right: 2px;
    bottom: 1px;
    font-size: 11px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 3px #000, 0 0 3px #000;
    pointer-events: none;
}

/* Stats */
#stats-panel {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
}

.stat-upgrade {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.up-btn {
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 3px;
    width: 25px;
    height: 25px;
    cursor: pointer;
}

.up-btn:disabled {
    background: #555;
    cursor: not-allowed;
}

/* Hotbar */
#hotbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    pointer-events: auto;
    z-index: 15;
}

.hotbar-slot {
    width: 60px;
    height: 60px;
    background: rgba(50, 50, 50, 0.8);
    border: 2px solid #888;
    border-radius: 5px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.key-hint {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 12px;
    color: #ccc;
}

/* Portal Menu */
#portal-menu {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    text-align: center;
}

.dungeon-btn, #close-portal-btn {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    background: #444;
    color: white;
    border: 1px solid #888;
    cursor: pointer;
}

.dungeon-btn:hover, #close-portal-btn:hover {
    background: #666;
}

/* Initial Loading Screen */
#initial-loading-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #111;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 100;
    transition: opacity 1s ease-out; /* Add fade out transition */
}

.loader-content {
    text-align: center;
    width: 400px;
}

.loader-content h1 {
    margin-bottom: 20px;
    color: #ffaa00;
    text-shadow: 2px 2px 4px black;
}

.progress-bar-container {
    width: 100%;
    height: 20px;
    background: #333;
    border: 2px solid #fff;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

#initial-progress-bar {
    width: 0%;
    height: 100%;
    background: #4CAF50;
    transition: width 0.2s;
}

#initial-loading-text {
    font-size: 16px;
    color: #aaa;
}

/* Loading & Splash Screens */
#loading-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 50;
}

#loading-screen h1 {
    font-size: 48px;
    animation: pulse 1.5s infinite;
}

#splash-screen {
    position: absolute;
    top: 30%; left: 50%;
    transform: translate(-50%, -50%);
    color: #ffaa00;
    text-shadow: 2px 2px 10px black;
    z-index: 40;
    pointer-events: none;
}

#splash-screen h1 {
    font-size: 72px;
    margin: 0;
}

#countdown-timer {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border: 2px solid #fff;
    border-radius: 5px;
    font-size: 24px;
    font-weight: bold;
    z-index: 20;
}

#interact-prompt {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: #ffaa00;
    padding: 5px 10px;
    border: 1px solid #ffaa00;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 25;
    white-space: nowrap;
}

@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}