* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Prevent text selection */
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+/Edge */
}

body {
    background-color: #222;
    color: #fff;
    font-family: monospace;
    font-size: 16px;
    line-height: 1.5;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

#game-container {
    display: flex;
    flex-direction: column;
    width: 800px;
    height: 600px;
    border: 1px solid #444;
    background-color: #111;
    position: relative;
}

/* Mini-map for navigation */
#mini-map {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 150px;
    height: 150px;
    background-color: rgba(0, 0, 0, 0.7);
    border: 1px solid #666;
    z-index: 50;
    padding: 5px;
    display: flex;
    flex-direction: column;
    font-size: 8px;
}

#hover-tooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    border: 1px solid #666;
    max-width: 200px;
    white-space: nowrap;
}

.monster-tooltip {
    display: flex;
    flex-direction: column;
}

.monster-name {
    font-weight: bold;
    margin-bottom: 3px;
}

.monster-hp {
    display: flex;
    align-items: center;
    margin-top: 2px;
}

.hp-bar {
    height: 5px;
    width: 100%;
    background-color: #333;
    margin-top: 3px;
    border-radius: 2px;
    overflow: hidden;
}

.hp-fill {
    height: 100%;
    background-color: #f00;
}

#game-map {
    flex: 1;
    overflow: hidden;
    background-color: #000;
    padding: 5px;
    display: flex;
    flex-direction: column;
}

.map-row {
    display: flex;
    height: 20px;
}

.map-cell {
    width: 20px;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer; /* Show pointer cursor on map cells for better UX */
}

/* Path visualization */
.path-cell {
    position: relative;
}

.path-cell::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: rgba(100, 200, 255, 0.7);
    pointer-events: none;
}

#game-ui {
    height: 150px;
    background-color: #222;
    border-top: 1px solid #444;
    display: flex;
    flex-direction: column;
}

#stats-display {
    display: flex;
    justify-content: space-around;
    padding: 5px;
    background-color: #333;
    border-bottom: 1px solid #444;
}

#message-log {
    flex: 1;
    padding: 5px;
    overflow-y: auto;
    font-size: 14px;
}

.message {
    margin-bottom: 2px;
}

.message-info {
    color: #ccc;
}

.message-important {
    color: #ff6;
    font-weight: bold;
}

.message-danger {
    color: #f66;
    font-weight: bold;
}

.message-sign {
    color: #6cf;
    font-style: italic;
}

.message-item {
    color: #6f6;
}

.message-npc {
    color: #f9f;
}

/* Panels */
.panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #333;
    border: 2px solid #555;
    padding: 10px;
    z-index: 10;
    width: 400px;
    max-height: 500px;
    overflow-y: auto;
}

.panel h3 {
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
    margin-bottom: 10px;
}

.hidden {
    display: none !important;
}

/* Loading indicator */
.loading {
    color: #fff;
    font-size: 18px;
    text-align: center;
    padding: 20px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Inventory, Spellbook, and Dialogue UIs */
.inventory-ui,
.spellbook-ui,
.dialogue-ui {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    border-left: 2px solid #666;
    padding: 15px;
    width: 300px;
    z-index: 100;
    font-family: monospace;
    color: #fff;
    display: flex;
    flex-direction: column;
}

/* Dialogue UI specific styles */
.dialogue-ui {
    top: auto;
    right: auto;
    height: auto;
    width: auto;
    bottom: 150px;
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: 80%;
    background-color: rgba(0, 0, 0, 0.85);
    border: 2px solid #666;
    border-radius: 5px;
    z-index: 200;
}

.inventory-header,
.spellbook-header,
.dialogue-header {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    border-bottom: 1px solid #666;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.dialogue-content {
    padding: 15px;
    font-size: 16px;
    line-height: 1.5;
    min-height: 80px;
}

.dialogue-footer {
    text-align: center;
    font-size: 12px;
    color: #999;
    padding-top: 10px;
    border-top: 1px solid #666;
}

.inventory-items,
.spellbook-spells {
    margin: 10px 0;
    flex: 1;
    overflow-y: auto;
}

.inventory-item,
.spellbook-spell {
    display: flex;
    align-items: center;
    padding: 8px 5px;
    border-bottom: 1px solid #333;
    position: relative;
}

.inventory-item.selected,
.spellbook-spell.selected {
    background-color: #444;
    border: 1px solid #aaa;
    border-radius: 3px;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
}

.inventory-item.selected::before,
.spellbook-spell.selected::before {
    content: '➤';
    position: absolute;
    left: -5px;
    color: #ff0;
}

.spellbook-spell.disabled {
    opacity: 0.5;
    color: #888;
}

.spell-description {
    margin-top: 15px;
    padding: 10px;
    background-color: rgba(0, 0, 50, 0.3);
    border: 1px solid #446;
    border-radius: 3px;
    font-style: italic;
    color: #aaf;
}

.item-symbol,
.spell-element {
    width: 20px;
    height: 20px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    margin-right: 10px;
    font-weight: bold;
}

.item-name,
.spell-name {
    flex: 1;
}

/* Targeting Styles */
.targeting-highlight {
    animation: pulse 1.5s infinite alternate;
    box-shadow: 0 0 10px 2px rgba(255, 100, 0, 0.8);
    border: 2px solid #ff5500 !important;
    z-index: 10;
    position: relative;
}

@keyframes pulse {
    from {
        box-shadow: 0 0 5px 2px rgba(255, 100, 0, 0.7);
    }
    to {
        box-shadow: 0 0 10px 5px rgba(255, 200, 0, 0.9);
    }
}

@keyframes targetPulse {
    0% {
        box-shadow: 0 0 5px 2px rgba(255, 255, 255, 0.4);
    }
    50% {
        box-shadow: 0 0 12px 5px rgba(255, 255, 255, 0.7);
    }
    100% {
        box-shadow: 0 0 5px 2px rgba(255, 255, 255, 0.4);
    }
}

/* Enhanced targeting highlight styles */
.targeting-highlight {
    animation: pulse 1.5s infinite alternate;
    box-shadow: 0 0 10px 2px rgba(255, 100, 0, 0.8) !important;
    border: 2px solid #ff5500 !important;
    z-index: 10;
    position: relative;
}

/* New targeting system styles */
.targeting-cell {
    cursor: crosshair;
    z-index: 5;
    position: relative;
}

.targeting-cell.in-range {
    position: relative;
    z-index: 6;
}

.targeting-cell.out-of-range {
    opacity: 0.6;
}

.targeting-cell.has-target {
    z-index: 7;
}

.targeting-cell.current-target {
    z-index: 8;
}

#targeting-tooltip {
    border: 2px solid #ff5500;
    box-shadow: 0 0 10px rgba(255, 100, 0, 0.5);
    max-width: 350px;
}

.item-type,
.spell-info {
    color: #aaa;
    font-size: 0.9em;
    margin-left: auto;
}

/* Dialogue UI */
.dialogue-ui {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 600px;
    background-color: rgba(0, 0, 0, 0.8);
    border: 2px solid #666;
    color: #fff;
    padding: 10px;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: opacity 0.2s;
}

.dialogue-ui.hidden {
    display: none;
}

.dialogue-header {
    font-weight: bold;
    padding-bottom: 5px;
    border-bottom: 1px solid #666;
    margin-bottom: 10px;
}

.dialogue-content {
    margin-bottom: 10px;
    min-height: 60px;
}

.dialogue-footer {
    text-align: right;
    font-size: 0.8em;
    color: #999;
}

/* Shop UI */
.shop-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50%;
    max-width: 500px;
    background: #222;
    border: 2px solid #666;
    color: #fff;
    padding: 10px;
    display: flex;
    flex-direction: column;
    z-index: 100;
    font-family: monospace;
}

.shop-header {
    display: flex;
    justify-content: space-between;
    padding: 5px;
    background: #333;
    margin-bottom: 10px;
    font-weight: bold;
}

#player-gold {
    color: #ffd700;
}

.shop-mode-toggle {
    display: flex;
    margin-bottom: 10px;
}

.mode-option {
    flex: 1;
    text-align: center;
    padding: 5px;
    background: #333;
    cursor: pointer;
}

.mode-option.selected {
    background: #555;
    font-weight: bold;
}

.shop-items {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.shop-item {
    display: flex;
    justify-content: space-between;
    padding: 5px;
    border-bottom: 1px solid #444;
}

.shop-item.selected {
    background: #335;
}

.shop-empty {
    padding: 10px;
    text-align: center;
    color: #888;
    font-style: italic;
}

.shop-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    padding: 5px;
    background: #333;
    font-size: 0.8em;
}

.inventory-footer,
.spellbook-footer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #666;
    font-size: 12px;
    color: #aaa;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 10px;
}