* {
    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, .tooltip, #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;
}

/* Path highlighting styles */
.path-highlight {
    position: relative;
    box-shadow: inset 0 0 10px rgba(0, 255, 255, 0.5);
    z-index: 1;
}

.path-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #00ffff;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 1px 1px 1px #000;
    pointer-events: none;
    z-index: 2;
}

/* Spell effects styles */
.spell-effect {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
}

/* Bolt spell effects */
.spell-effect.bolt {
    height: 8px;
    border-radius: 2px;
    transform-origin: left center;
    animation: bolt-animation 0.5s forwards;
}

.spell-effect.bolt.fire {
    background: linear-gradient(to right, #F60, #F90);
    box-shadow: 0 0 10px #F60;
}

.spell-effect.bolt.ice {
    background: linear-gradient(to right, #08F, #0CF);
    box-shadow: 0 0 10px #0CF;
}

.spell-effect.bolt.lightning {
    background: linear-gradient(to right, #FF0, #FF8);
    box-shadow: 0 0 10px #FF8;
}

/* Impact spell effects */
.spell-effect.impact {
    border-radius: 50%;
    animation: impact-animation 0.6s forwards;
}

.spell-effect.impact.fire {
    background-color: rgba(255, 102, 0, 0.7);
    box-shadow: 0 0 15px #F60;
}

.spell-effect.impact.ice {
    background-color: rgba(0, 191, 255, 0.7);
    box-shadow: 0 0 15px #0CF;
}

.spell-effect.impact.lightning {
    background-color: rgba(255, 255, 0, 0.7);
    box-shadow: 0 0 15px #FF0;
}

/* Aura spell effects */
.spell-effect.aura {
    border-radius: 50%;
    animation: aura-animation 0.8s forwards;
}

.spell-effect.aura.fire {
    background-color: rgba(255, 102, 0, 0.3);
    box-shadow: inset 0 0 30px #F60, 0 0 20px #F60;
}

.spell-effect.aura.ice {
    background-color: rgba(0, 191, 255, 0.3);
    box-shadow: inset 0 0 30px #0CF, 0 0 20px #0CF;
}

.spell-effect.aura.lightning {
    background-color: rgba(255, 255, 0, 0.3);
    box-shadow: inset 0 0 30px #FF0, 0 0 20px #FF0;
}

/* Spell effect animations */
@keyframes bolt-animation {
    0% {
        opacity: 0.9;
        width: 0;
    }
    70% {
        opacity: 1;
        width: 100%;
    }
    100% {
        opacity: 0;
        width: 100%;
    }
}

@keyframes impact-animation {
    0% {
        transform: scale(0.2);
        opacity: 0.9;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

@keyframes aura-animation {
    0% {
        transform: scale(0.2);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.0);
        opacity: 0.9;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Targeting mode styles */
.targeting-current {
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    z-index: 5;
}

.targeting-valid {
    position: relative;
}

.targeting-valid::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 255, 0, 0.2);
    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: 350px; /* Increased default width */
    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;
}

/* New container for spell list to enable scrolling */
.spellbook-list-container {
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 10px;
    padding-right: 5px;
}

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

.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;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 5px;
}

/* 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;
}

/* Special tiles highlighting */
.stairs-down, .stairs-up, .area-exit, .dungeon-entrance {
    animation: stairsPulse 3s infinite alternate;
    box-shadow: 0 0 8px 2px rgba(100, 255, 255, 0.5);
    border: 1px solid #00ffff;
    z-index: 5;
    position: relative;
    cursor: pointer;
}

@keyframes stairsPulse {
    from {
        box-shadow: 0 0 5px 1px rgba(100, 255, 255, 0.4);
    }
    to {
        box-shadow: 0 0 8px 3px rgba(100, 255, 255, 0.7);
    }
}

@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);
    }
}

/* Spell visual effects */
.spell-effect {
    position: absolute;
    pointer-events: none;
    z-index: 1000 !important; /* Force high z-index */
    opacity: 0.9;
    animation: spellFade 1.2s forwards;
}

.spell-effect.fire {
    background-color: rgba(255, 50, 0, 0.8);
    box-shadow: 0 0 15px 5px rgba(255, 70, 20, 0.9);
    border: 2px solid rgba(255, 200, 0, 0.9);
}

.spell-effect.ice {
    background-color: rgba(100, 200, 255, 0.8);
    box-shadow: 0 0 15px 5px rgba(120, 210, 255, 0.9);
    border: 2px solid rgba(200, 255, 255, 0.9);
}

.spell-effect.lightning {
    background-color: rgba(200, 200, 50, 0.8);
    box-shadow: 0 0 15px 5px rgba(220, 220, 70, 0.9);
    border: 2px solid rgba(255, 255, 150, 0.9);
}

.spell-effect.nature {
    background-color: rgba(50, 200, 50, 0.8);
    box-shadow: 0 0 15px 5px rgba(70, 220, 70, 0.9);
    border: 2px solid rgba(150, 255, 150, 0.9);
}

.spell-effect.arcane {
    background-color: rgba(200, 50, 200, 0.8);
    box-shadow: 0 0 15px 5px rgba(220, 70, 220, 0.9);
    border: 2px solid rgba(255, 150, 255, 0.9);
}

.spell-effect.aura {
    border-radius: 50%;
    animation: auraExpand 1.5s forwards;
}

.spell-effect.bolt {
    /* Let's implement a very different approach for bolts */
    height: 10px; /* Slightly thicker to be visible */
    transform-origin: left center !important;
    /* Only animate opacity, not transform */
    animation: boltFade 0.8s forwards;
    z-index: 1000 !important;
    /* Make bolts very visible */
    box-shadow: 0 0 10px 3px currentColor, 0 0 5px 2px white !important;
    border-radius: 4px;
    /* Force transform to override any parent effects */
    display: block !important;
    will-change: transform, opacity;
}

/* Fire bolt specific styling to make it obvious */
.spell-effect.fire.bolt {
    border: 2px solid #FF0 !important;
    background: linear-gradient(to right, #F00, #F80) !important;
}

/* Ice bolt specific styling */
.spell-effect.ice.bolt {
    border: 2px solid #8FF !important;
    background: linear-gradient(to right, #08F, #0CF) !important;
}

.spell-effect.wave {
    border-radius: 50%;
    animation: waveExpand 1.5s forwards;
}

.spell-effect.impact {
    border-radius: 50%;
    animation: impactPulse 0.6s forwards;
}

.spell-effect.persistent-aura {
    border-radius: 50%;
    animation: auraPersist 3s infinite;
    opacity: 0.7;
}

@keyframes spellFade {
    0% { opacity: 0.8; }
    100% { opacity: 0; }
}

@keyframes auraExpand {
    0% { 
        transform: scale(0.1);
        opacity: 0.9;
    }
    100% { 
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes waveExpand {
    0% { 
        transform: scale(0.1);
        opacity: 0.9;
    }
    50% {
        opacity: 0.7;
    }
    100% { 
        transform: scale(1.2);
        opacity: 0;
    }
}

@keyframes impactPulse {
    0% { 
        transform: scale(0.1);
        opacity: 0.95;
    }
    50% {
        transform: scale(1.3);
        opacity: 0.8;
    }
    100% { 
        transform: scale(0.8);
        opacity: 0;
    }
}

@keyframes auraPersist {
    0% { 
        transform: scale(0.9);
        opacity: 0.4;
    }
    50% {
        transform: scale(1);
        opacity: 0.7;
    }
    100% { 
        transform: scale(0.9);
        opacity: 0.4;
    }
}

@keyframes boltFade {
    0% { 
        opacity: 0.4;
    }
    20% {
        opacity: 1.0;
    }
    80% { 
        opacity: 0.9;
    }
    100% { 
        opacity: 0;
    }
}

/* 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;
}

/* Arena UI */
.arena-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    max-width: 600px;
    background: #222;
    border: 2px solid #8b0000;
    color: #fff;
    padding: 15px;
    display: flex;
    flex-direction: column;
    z-index: 100;
    font-family: monospace;
}

.arena-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #331111;
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 18px;
    color: #cd853f;
}

.arena-monster-select, 
.arena-selected-monsters {
    margin-bottom: 15px;
    padding: 10px;
    background: #333;
    border: 1px solid #555;
}

.monster-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.monster-list li {
    padding: 8px;
    margin-bottom: 5px;
    background: #444;
    cursor: pointer;
    border-radius: 3px;
}

.monster-list li:hover {
    background: #555;
}

.arena-selected-monsters ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.arena-selected-monsters li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin-bottom: 5px;
    background: #445;
    border-radius: 3px;
}

.arena-selected-monsters button {
    background: #a33;
    border: none;
    color: white;
    padding: 3px 8px;
    cursor: pointer;
    border-radius: 3px;
}

.arena-buttons {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.arena-buttons button {
    flex: 1;
    padding: 8px;
    background: #444;
    border: 1px solid #666;
    color: white;
    cursor: pointer;
    border-radius: 3px;
}

.arena-buttons button:hover {
    background: #555;
}

.arena-buttons button:disabled {
    background: #333;
    color: #777;
    cursor: not-allowed;
}

.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;
}