/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Courier New', monospace;
    background: #000;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.game-container {
    display: flex;
    height: 100vh;
    background: #000;
}

/* Left Panel Styles */
.left-panel {
    width: 300px;
    background: #1a1a2e;
    border-right: 4px solid #3d5a80;
    padding: 16px;
    overflow-y: auto;
    box-shadow: inset -4px 0 8px rgba(0,0,0,0.5);
}

/* Main Game Area */
.main-game {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #000;
}

.world-view {
    flex: 1;
    position: relative;
    background: #2d5016;
    overflow: hidden;
}

.world-grid {
    position: absolute;
    width: 1600px;
    height: 1184px;
    transition: transform 0.15s ease;
}

/* Tile System */
.tile {
    position: absolute;
    width: 32px;
    height: 32px;
    background-size: 32px 32px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Terrain Sprites */
.grass {
    background: 
        radial-gradient(circle at 8px 8px, #4a7c59 2px, transparent 2px),
        radial-gradient(circle at 24px 16px, #4a7c59 1px, transparent 1px),
        radial-gradient(circle at 16px 24px, #4a7c59 1px, transparent 1px),
        linear-gradient(45deg, #3d6b47 25%, transparent 25%),
        linear-gradient(-45deg, #3d6b47 25%, transparent 25%),
        #2d5016;
    background-size: 16px 16px, 16px 16px, 16px 16px, 8px 8px, 8px 8px, 32px 32px;
}

.water {
    background: 
        repeating-linear-gradient(
            0deg,
            #1e40af 0px,
            #1e40af 2px,
            #2563eb 2px,
            #2563eb 4px,
            #3b82f6 4px,
            #3b82f6 6px,
            #2563eb 6px,
            #2563eb 8px
        );
    animation: water-flow 2s linear infinite;
}

@keyframes water-flow {
    0% { background-position: 0 0; }
    100% { background-position: 0 -8px; }
}

.mountain {
    background: 
        conic-gradient(from 0deg at 50% 30%, #9ca3af 0deg, #6b7280 90deg, #4b5563 180deg, #374151 270deg),
        linear-gradient(to bottom, #9ca3af 0%, #6b7280 50%, #4b5563 100%);
    background-size: 32px 32px;
}

.forest {
    background: 
        radial-gradient(circle at 16px 8px, #166534 6px, transparent 6px),
        radial-gradient(circle at 8px 20px, #15803d 4px, transparent 4px),
        radial-gradient(circle at 24px 24px, #166534 5px, transparent 5px),
        #0f2a0a;
}

.road {
    background: 
        repeating-linear-gradient(
            90deg,
            #8b5a2b 0px,
            #8b5a2b 8px,
            #a16207 8px,
            #a16207 16px,
            #8b5a2b 16px,
            #8b5a2b 24px,
            #a16207 24px,
            #a16207 32px
        );
}

.sand {
    background: 
        radial-gradient(circle at 6px 6px, #f59e0b 1px, transparent 1px),
        radial-gradient(circle at 18px 14px, #f59e0b 1px, transparent 1px),
        radial-gradient(circle at 26px 26px, #f59e0b 1px, transparent 1px),
        radial-gradient(circle at 10px 22px, #f59e0b 1px, transparent 1px),
        #eab308;
    background-size: 16px 16px;
}

/* Building Sprites */
.building {
    width: 64px;
    height: 64px;
    position: absolute;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.building:hover {
    transform: scale(1.05);
}

.house {
    background: 
        linear-gradient(to bottom, #92400e 0px, #92400e 16px, #7c2d12 16px, #7c2d12 48px, #451a03 48px, #451a03 64px),
        linear-gradient(to right, transparent 16px, #451a03 16px, #451a03 48px, transparent 48px);
}

.house::before {
    content: '';
    position: absolute;
    top: 0px;
    left: 8px;
    right: 8px;
    height: 20px;
    background: 
        conic-gradient(from 0deg at 50% 100%, #dc2626 0deg, #b91c1c 60deg, #991b1b 120deg, #7f1d1d 180deg, #991b1b 240deg, #b91c1c 300deg);
}

.house::after {
    content: '';
    position: absolute;
    top: 32px;
    left: 24px;
    width: 16px;
    height: 20px;
    background: #451a03;
    border: 2px solid #1c0a00;
}

.shop {
    background: 
        linear-gradient(to bottom, #059669 0px, #059669 16px, #047857 16px, #047857 48px, #064e3b 48px, #064e3b 64px);
}

.shop::before {
    content: '';
    position: absolute;
    top: 0px;
    left: 4px;
    right: 4px;
    height: 20px;
    background: 
        repeating-linear-gradient(45deg, #dc2626 0px, #dc2626 4px, #fbbf24 4px, #fbbf24 8px);
}

.shop::after {
    content: '🏪';
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
}

.inn {
    background: 
        linear-gradient(to bottom, #7c3aed 0px, #7c3aed 16px, #6d28d9 16px, #6d28d9 48px, #4c1d95 48px, #4c1d95 64px);
}

.inn::before {
    content: '';
    position: absolute;
    top: 0px;
    left: 8px;
    right: 8px;
    height: 20px;
    background: 
        linear-gradient(to bottom, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
}

.inn::after {
    content: '🛏️';
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
}

.temple {
    background: 
        linear-gradient(to bottom, #fbbf24 0px, #fbbf24 16px, #f59e0b 16px, #f59e0b 48px, #d97706 48px, #d97706 64px);
}

.temple::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 16px solid transparent;
    border-right: 16px solid transparent;
    border-bottom: 24px solid #fbbf24;
}

.temple::after {
    content: '🙏';
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
    color: #fff;
}

.castle {
    width: 96px;
    height: 96px;
    background: 
        linear-gradient(to bottom, #6b7280 0px, #6b7280 24px, #4b5563 24px, #4b5563 72px, #374151 72px, #374151 96px);
}

.castle::before {
    content: '';
    position: absolute;
    top: -16px;
    left: 8px;
    right: 8px;
    height: 32px;
    background: 
        repeating-linear-gradient(0deg, #6b7280 0px, #6b7280 8px, #4b5563 8px, #4b5563 16px),
        linear-gradient(to bottom, #6b7280 0%, #4b5563 100%);
}

.castle::after {
    content: '👑';
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
}

/* Character Sprites */
.player-sprite {
    position: absolute;
    width: 32px;
    height: 32px;
    z-index: 100;
    transition: all 0.15s ease;
    background: 
        radial-gradient(circle at 16px 8px, #fbbf24 4px, transparent 4px),
        radial-gradient(circle at 12px 16px, #3b82f6 3px, transparent 3px),
        radial-gradient(circle at 20px 16px, #3b82f6 3px, transparent 3px),
        linear-gradient(to bottom, #fbbf24 0px, #fbbf24 12px, #3b82f6 12px, #3b82f6 20px, #8b5a2b 20px, #8b5a2b 28px, #451a03 28px, #451a03 32px);
    animation: player-idle-bob 0.8s ease-in-out infinite alternate;
}

@keyframes player-idle-bob {
    0% { transform: translateY(0px); }
    100% { transform: translateY(-2px); }
}

.player-sprite::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 14px;
    width: 4px;
    height: 4px;
    background: #000;
    border-radius: 50%;
    box-shadow: 4px 0 0 #000;
}

.player-sprite.walking {
    animation: player-walk 0.4s ease-in-out infinite alternate;
}

@keyframes player-walk {
    0% { transform: translateY(0px) scaleY(1); }
    100% { transform: translateY(-1px) scaleY(0.98); }
}

/* NPC Sprites */
.npc {
    position: absolute;
    width: 32px;
    height: 32px;
    z-index: 50;
    cursor: pointer;
    transition: transform 0.1s ease;
    animation: npc-idle 3s ease-in-out infinite;
}

.npc:hover {
    transform: scale(1.1);
}

@keyframes npc-idle {
    0%, 100% { transform: translateX(0px); }
    50% { transform: translateX(1px); }
}

.npc-villager {
    background: 
        radial-gradient(circle at 16px 8px, #8b5a2b 4px, transparent 4px),
        linear-gradient(to bottom, #8b5a2b 0px, #8b5a2b 12px, #059669 12px, #059669 20px, #451a03 20px, #451a03 28px, #1c0a00 28px, #1c0a00 32px);
}

.npc-merchant {
    background: 
        radial-gradient(circle at 16px 8px, #dc2626 4px, transparent 4px),
        linear-gradient(to bottom, #dc2626 0px, #dc2626 12px, #7c3aed 12px, #7c3aed 20px, #451a03 20px, #451a03 28px, #1c0a00 28px, #1c0a00 32px);
}

.npc-priest {
    background: 
        radial-gradient(circle at 16px 8px, #9ca3af 4px, transparent 4px),
        linear-gradient(to bottom, #9ca3af 0px, #9ca3af 12px, #fbbf24 12px, #fbbf24 20px, #8b5a2b 20px, #8b5a2b 28px, #451a03 28px, #451a03 32px);
}

.npc-elder {
    background: 
        radial-gradient(circle at 16px 8px, #e5e7eb 4px, transparent 4px),
        linear-gradient(to bottom, #e5e7eb 0px, #e5e7eb 12px, #6d28d9 12px, #6d28d9 20px, #451a03 20px, #451a03 28px, #1c0a00 28px, #1c0a00 32px);
}

/* Enemy Sprites */
.enemy-spawn {
    position: absolute;
    width: 32px;
    height: 32px;
    z-index: 30;
    cursor: pointer;
    animation: enemy-glow 2s ease-in-out infinite;
    transition: transform 0.1s ease;
}

.enemy-spawn:hover {
    transform: scale(1.1);
}

@keyframes enemy-glow {
    0%, 100% { 
        box-shadow: 0 0 8px #dc2626, inset 0 0 8px rgba(220, 38, 38, 0.3);
        filter: brightness(1);
    }
    50% { 
        box-shadow: 0 0 16px #dc2626, inset 0 0 16px rgba(220, 38, 38, 0.5);
        filter: brightness(1.2);
    }
}

.enemy-goblin {
    background: 
        radial-gradient(circle at 16px 8px, #16a34a 4px, transparent 4px),
        linear-gradient(to bottom, #16a34a 0px, #16a34a 12px, #7c2d12 12px, #7c2d12 20px, #166534 20px, #166534 28px, #064e3b 28px, #064e3b 32px);
}

.enemy-dragon {
    background: 
        radial-gradient(circle at 16px 6px, #dc2626 6px, transparent 6px),
        radial-gradient(circle at 8px 16px, #dc2626 4px, transparent 4px),
        radial-gradient(circle at 24px 16px, #dc2626 4px, transparent 4px),
        linear-gradient(to bottom, #dc2626 0px, #dc2626 12px, #991b1b 12px, #991b1b 24px, #7f1d1d 24px, #7f1d1d 32px);
}

.enemy-wolf {
    background: 
        radial-gradient(circle at 16px 8px, #4b5563 4px, transparent 4px),
        radial-gradient(circle at 12px 16px, #4b5563 3px, transparent 3px),
        radial-gradient(circle at 20px 16px, #4b5563 3px, transparent 3px),
        linear-gradient(to bottom, #4b5563 0px, #4b5563 12px, #374151 12px, #374151 24px, #1f2937 24px, #1f2937 32px);
}

/* Multiplayer Players */
.other-player {
    position: absolute;
    width: 32px;
    height: 32px;
    z-index: 99;
    cursor: pointer;
    background: linear-gradient(135deg, #10b981, #34d399);
    border: 2px solid #065f46;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    animation: player-pulse 2s ease-in-out infinite;
    transition: all 0.2s ease;
}

.other-player:hover {
    transform: scale(1.2);
}

@keyframes player-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 10px rgba(16, 185, 129, 0.5); }
    50% { transform: scale(1.1); box-shadow: 0 0 20px rgba(16, 185, 129, 0.8); }
}

/* UI Components */
.wallet-section, .character-info, .inventory, .multiplayer-section {
    background: linear-gradient(135deg, #0f3460 0%, #1e40af 25%, #0f3460 100%);
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 3px solid #3d5a80;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.wallet-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(0,0,0,0.3);
    border: 2px solid #3d5a80;
    border-radius: 6px;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    margin: 8px 0;
}

.wallet-input::placeholder {
    color: #9ca3af;
}

.wallet-input:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

.ui-panel {
    background: linear-gradient(to bottom, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border-top: 4px solid #3d5a80;
    padding: 16px;
    height: 140px;
    display: flex;
    gap: 20px;
    align-items: center;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.5);
}

.stat-block {
    background: linear-gradient(135deg, #0f3460 0%, #1e40af 50%, #0f3460 100%);
    padding: 12px;
    border-radius: 8px;
    border: 3px solid #3d5a80;
    min-width: 140px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.stat-bar {
    background: #000;
    height: 12px;
    border-radius: 6px;
    margin: 4px 0;
    overflow: hidden;
    border: 2px solid #3d5a80;
    position: relative;
}

.stat-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.stat-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        90deg,
        rgba(255,255,255,0.1) 0px,
        rgba(255,255,255,0.1) 2px,
        transparent 2px,
        transparent 4px
    );
}

.hp-fill { 
    background: linear-gradient(90deg, #dc2626 0%, #ef4444 50%, #f87171 100%);
}

.mp-fill { 
    background: linear-gradient(90deg, #1e40af 0%, #3b82f6 50%, #60a5fa 100%);
}

.xp-fill { 
    background: linear-gradient(90deg, #d97706 0%, #f59e0b 50%, #fbbf24 100%);
}

.controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-left: auto;
}

.control-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #1e40af 100%);
    border: 3px solid #3d5a80;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    transition: all 0.1s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.control-btn:hover {
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 50%, #3b82f6 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.control-btn:active {
    transform: translateY(0px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.control-btn.interact {
    background: linear-gradient(135deg, #059669 0%, #10b981 50%, #059669 100%);
}

.control-btn.interact:hover {
    background: linear-gradient(135deg, #10b981 0%, #34d399 50%, #10b981 100%);
}

.btn {
    padding: 10px 18px;
    border: 3px solid;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    font-size: 12px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    background: none;
    color: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #1e40af 100%);
    border-color: #3d5a80;
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 50%, #3b82f6 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.btn-success {
    background: linear-gradient(135deg, #059669 0%, #10b981 50%, #059669 100%);
    border-color: #065f46;
    color: white;
}

.btn-success:hover {
    background: linear-gradient(135deg, #10b981 0%, #34d399 50%, #10b981 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 50%, #dc2626 100%);
    border-color: #991b1b;
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #ef4444 0%, #f87171 50%, #ef4444 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #4b5563 0%, #6b7280 50%, #4b5563 100%);
    border-color: #374151;
    color: white;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #6b7280 0%, #9ca3af 50%, #6b7280 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border: 4px solid #3d5a80;
    border-radius: 16px;
    padding: 28px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 16px 32px rgba(0,0,0,0.8);
}

.battle-modal {
    background: linear-gradient(135deg, #1f2937 0%, #374151 50%, #1f2937 100%);
    display: none;
}

.battle-arena {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 24px 0;
    height: 220px;
    background: 
        radial-gradient(circle at center, rgba(220, 38, 38, 0.1) 0%, transparent 60%),
        linear-gradient(45deg, rgba(0,0,0,0.2) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0,0,0,0.2) 25%, transparent 25%);
    background-size: 200px 200px, 20px 20px, 20px 20px;
    border-radius: 12px;
    padding: 20px;
    border: 3px solid #4b5563;
}

.battle-character {
    width: 128px;
    height: 128px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 72px;
    border: 4px solid;
    animation: battle-ready 2s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}

.battle-character::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: repeating-conic-gradient(
        from 0deg,
        rgba(255,255,255,0.1) 0deg,
        rgba(255,255,255,0.1) 45deg,
        transparent 45deg,
        transparent 90deg
    );
    animation: battle-shimmer 3s linear infinite;
}

@keyframes battle-shimmer {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.battle-player {
    background: linear-gradient(135deg, #059669 0%, #10b981 50%, #34d399 100%);
    border-color: #065f46;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

.battle-enemy {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 50%, #f87171 100%);
    border-color: #991b1b;
    box-shadow: 0 0 20px rgba(220, 38, 38, 0.5);
}

@keyframes battle-ready {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.battle-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.battle-log {
    height: 120px;
    background: linear-gradient(135deg, #000 0%, #1f2937 50%, #000 100%);
    border: 3px solid #4b5563;
    border-radius: 8px;
    padding: 12px;
    overflow-y: auto;
    margin: 16px 0;
    font-size: 14px;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.5);
}

.log-entry {
    margin-bottom: 6px;
    padding: 4px 8px;
    border-radius: 4px;
    animation: log-slide-in 0.3s ease;
}

@keyframes log-slide-in {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.log-damage { 
    background: linear-gradient(90deg, rgba(220, 38, 38, 0.3), rgba(220, 38, 38, 0.1));
    border-left: 3px solid #dc2626;
}
.log-heal { 
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.3), rgba(16, 185, 129, 0.1));
    border-left: 3px solid #10b981;
}
.log-info { 
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.3), rgba(59, 130, 246, 0.1));
    border-left: 3px solid #3b82f6;
}

.connection-status {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: bold;
    z-index: 200;
    border: 2px solid;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.connected {
    background: linear-gradient(135deg, #059669, #10b981);
    border-color: #065f46;
    color: white;
}

.disconnected {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    border-color: #991b1b;
    color: white;
}

.location-info {
    position: absolute;
    top: 16px;
    left: 16px;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.95), rgba(22, 33, 62, 0.95));
    padding: 12px 18px;
    border-radius: 12px;
    border: 3px solid #3d5a80;
    z-index: 200;
    box-shadow: 0 8px 16px rgba(0,0,0,0.5);
}

/* CRITICAL FIX: Minimap styles */
.minimap {
    position: absolute;
    bottom: 160px;
    right: 16px;
    width: 220px;
    min-height: 150px;
    max-height: 400px;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.95), rgba(22, 33, 62, 0.95));
    border: 3px solid #3d5a80;
    border-radius: 12px;
    z-index: 200;
    overflow: hidden;
    box-shadow: 0 8px 16px rgba(0,0,0,0.5);
}

.minimap-content {
    position: relative;
    background: #2d5016;
    overflow: hidden;
    display: block; /* CRITICAL: Ensure display is block */
}

/* CRITICAL: Canvas inside minimap must be visible */
.minimap-content canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.floating-text {
    position: absolute;
    font-size: 16px;
    font-weight: bold;
    z-index: 1000;
    animation: float-up 2s ease-out forwards;
    pointer-events: none;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    font-family: 'Courier New', monospace;
}

@keyframes float-up {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    50% { opacity: 1; transform: translateY(-15px) scale(1.1); }
    100% { opacity: 0; transform: translateY(-40px) scale(0.8); }
}

.item-drop {
    position: absolute;
    width: 24px;
    height: 24px;
    background: 
        radial-gradient(circle at 50% 30%, #fbbf24 30%, #f59e0b 60%, #d97706 100%),
        linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
    border: 3px solid #92400e;
    border-radius: 50%;
    z-index: 80;
    cursor: pointer;
    animation: item-sparkle 2s ease-in-out infinite;
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
}

.item-drop::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 6px;
    width: 6px;
    height: 3px;
    background: #fff;
    border-radius: 50%;
    opacity: 0.8;
}

@keyframes item-sparkle {
    0%, 100% { 
        transform: scale(1) rotate(0deg);
        box-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
    }
    50% { 
        transform: scale(1.15) rotate(180deg);
        box-shadow: 0 0 20px rgba(251, 191, 36, 0.9);
    }
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fbbf24;
    border-radius: 50%;
    pointer-events: none;
    animation: particle-float 1.5s ease-out forwards;
    z-index: 999;
}

@keyframes particle-float {
    0% { 
        opacity: 1; 
        transform: scale(1) translateY(0);
    }
    100% { 
        opacity: 0; 
        transform: scale(0.5) translateY(-60px) translateX(calc(var(--random-x, 0) * 40px - 20px));
    }
}

.level-up-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
    padding: 24px 48px;
    border-radius: 20px;
    font-size: 28px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 16px 32px rgba(0,0,0,0.8), 0 0 40px rgba(251, 191, 36, 0.6);
    animation: level-up-pulse 3s ease-in-out;
    z-index: 1500;
    border: 4px solid #92400e;
}

@keyframes level-up-pulse {
    0%, 100% { 
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    10%, 90% { 
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    50% { 
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 1;
    }
}

.inventory-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 2px solid rgba(61, 90, 128, 0.3);
    font-size: 13px;
}

.inventory-item:last-child {
    border-bottom: none;
}

.inventory-item .item-icon {
    margin-right: 8px;
    font-size: 16px;
}

.stat-fill.damage {
    animation: damage-flash 0.3s ease;
}

.stat-fill.heal {
    animation: heal-glow 0.5s ease;
}

@keyframes damage-flash {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.5) saturate(1.5); }
}

@keyframes heal-glow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3) hue-rotate(90deg); }
}

.wallet-methods {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.wallet-method {
    flex: 1;
    padding: 8px;
    background: rgba(0,0,0,0.3);
    border: 2px solid #3d5a80;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    font-size: 11px;
}

.wallet-method:hover {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.wallet-method.active {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.2);
}

@keyframes battle-lightning {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

.online-players {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 10px;
    margin-top: 10px;
}

.player-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 5px;
    font-size: 0.9em;
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: #10b981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive Design */
@media (max-width: 1200px) {
    .left-panel {
        width: 260px;
    }
    
    .minimap {
        width: 180px;
        height: 135px;
    }
}

@media (max-width: 768px) {
    .left-panel {
        width: 220px;
    }
    
    .ui-panel {
        height: 100px;
        padding: 12px;
    }
    
    .control-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    /* Mobile-specific: Hide minimap for smaller screens */
    .minimap {
        display: none;
    }
    
    .location-info {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    /* Mobile-specific: Hide desktop direction handlers */
    .desktop-controls-hint {
        display: none;
    }

    .connection-status {
        font-size: 11px;
        padding: 6px 12px;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 600px) {
    .game-container {
        flex-direction: column;
    }
    
    .left-panel {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 4px solid #3d5a80;
    }
    
    .main-game {
        flex: 1;
    }
    
    .ui-panel {
        height: auto;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .stat-block {
        flex: 1 1 45%;
        min-width: auto;
    }
    
    .controls {
        gap: 4px;
    }
    
    .control-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    /* Show mobile D-pad on small screens */
    #mobile-controls {
        display: grid;
    }
}

/* Default state for mobile controls (hidden on desktop) */
#mobile-controls {
    display: none;
}

/* Make the game container full-screen mobile */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    touch-action: none;
}

/* Scale tiles down on small widths */
@media (max-width: 600px) {
    :root {
        --tile-size: 24px;
    }
}

/* D-pad container */
#mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 200px;
    grid-template-areas:
        ". up    ."
        "left .   right"
        ". down  .";
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px 60px 60px;
    gap: 10px;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    z-index: 1000;
}

/* Show on mobile devices and touch screens */
@media (max-width: 768px), (hover: none), (pointer: coarse) {
    #mobile-controls {
        display: grid !important;
    }
}

/* Individual D-pad buttons */
.ctl-btn {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.9) 100%);
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    border: 3px solid rgba(59, 130, 246, 0.6);
    border-radius: 15px;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 -2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease;
    position: relative;
    overflow: hidden;
}

/* Glow effect on buttons */
.ctl-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, rgba(59, 130, 246, 0.3) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.1s ease;
}

/* Button pressed state */
.ctl-btn:active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.9) 0%, rgba(37, 99, 235, 0.9) 100%);
    transform: scale(0.92);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.6),
        inset 0 2px 12px rgba(0, 0, 0, 0.5);
    border-color: rgba(96, 165, 250, 0.8);
}

.ctl-btn:active::before {
    opacity: 1;
}

.ctl-btn.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.9) 0%, rgba(37, 99, 235, 0.9) 100%);
    transform: scale(0.92);
}

/* Grid layout assignments */
.ctl-btn.up    { grid-area: up;    }
.ctl-btn.down  { grid-area: down;  }
.ctl-btn.left  { grid-area: left;  }
.ctl-btn.right { grid-area: right; }

/* Enhanced Avatar Styles */
.npc-avatar, .enemy-avatar, .other-player-avatar, .main-player-avatar {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.npc-avatar:hover, .enemy-avatar:hover, .other-player-avatar:hover {
    transform: scale(1.1);
    z-index: 20;
}

/* NPC Avatars */
.npc-avatar {
    background: linear-gradient(45deg, #3b82f6, #1d4ed8);
    border: 2px solid #e5e7eb;
}

.npc-avatar[data-npc-type="merchant"]::before { content: '🧑'; }
.npc-avatar[data-npc-type="merchant"] {
    background: linear-gradient(45deg, #f59e0b, #d97706);
}

.npc-avatar[data-npc-type="priest"]::before { content: '⛪'; }
.npc-avatar[data-npc-type="elder"]::before { content: '👴'; }
.npc-avatar[data-npc-type="villager"]::before { content: '🧑'; }

.npc-avatar[data-npc-type="priest"] {
    background: linear-gradient(45deg, #8b5cf6, #7c3aed);
}

.npc-avatar[data-npc-type="elder"] {
    background: linear-gradient(45deg, #6b7280, #4b5563);
}

/* Enemy Avatars */
.enemy-avatar {
    background: linear-gradient(45deg, #dc2626, #991b1b);
    border: 2px solid #fca5a5;
    animation: enemyPulse 1.5s ease-in-out infinite;
}

.enemy-avatar[data-enemy-type="goblin"]::before { content: '👹'; }
.enemy-avatar[data-enemy-type="dragon"]::before { content: '🐉'; }
.enemy-avatar[data-enemy-type="wolf"]::before { content: '🐺'; }
.enemy-avatar[data-enemy-type="monster"]::before { content: '👾'; }

.enemy-avatar[data-enemy-type="dragon"] {
    background: linear-gradient(45deg, #7c2d12, #dc2626);
    font-size: 20px;
}

@keyframes enemyPulse {
    0%, 100% { 
        box-shadow: 0 2px 6px rgba(0,0,0,0.3), 0 0 0 2px rgba(220, 38, 38, 0.3);
    }
    50% { 
        box-shadow: 0 2px 6px rgba(0,0,0,0.3), 0 0 0 4px rgba(220, 38, 38, 0.5);
    }
}

/* Player Avatars */
.other-player-avatar {
    background: linear-gradient(45deg, #34d399, #10b981);
    border: 2px solid #fff;
    animation: playerGlow 2s ease-in-out infinite;
}

.main-player-avatar {
    background: linear-gradient(45deg, #fbbf24, #f59e0b);
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 3px rgba(251, 191, 36, 0.4);
    animation: yourPlayerGlow 2s ease-in-out infinite;
    z-index: 20;
}

/* Player level tiers */
.other-player-avatar[data-player-level="novice"]::before,
.main-player-avatar[data-player-level="novice"]::before { content: '🧙‍♂️'; }

.other-player-avatar[data-player-level="veteran"]::before,
.main-player-avatar[data-player-level="veteran"]::before { content: '⚔️'; }

.other-player-avatar[data-player-level="expert"]::before,
.main-player-avatar[data-player-level="expert"]::before { content: '🛡️'; }

.other-player-avatar[data-player-level="master"]::before,
.main-player-avatar[data-player-level="master"]::before { content: '🏹'; }

.other-player-avatar[data-player-level="legendary"]::before,
.main-player-avatar[data-player-level="legendary"]::before { content: '👑'; }

/* High-level player styling */
.other-player-avatar[data-player-level="master"],
.main-player-avatar[data-player-level="master"] {
    background: linear-gradient(45deg, #8b5cf6, #7c3aed);
}

.other-player-avatar[data-player-level="legendary"],
.main-player-avatar[data-player-level="legendary"] {
    background: linear-gradient(45deg, #fbbf24, #f59e0b);
    border-color: #fbbf24;
    font-size: 20px;
}

@keyframes playerGlow {
    0%, 100% { 
        box-shadow: 0 2px 6px rgba(0,0,0,0.3), 0 0 0 2px rgba(52, 211, 153, 0.3);
    }
    50% { 
        box-shadow: 0 2px 6px rgba(0,0,0,0.3), 0 0 0 4px rgba(52, 211, 153, 0.5);
    }
}

@keyframes yourPlayerGlow {
    0%, 100% { 
        box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 3px rgba(251, 191, 36, 0.4);
    }
    50% { 
        box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 5px rgba(251, 191, 36, 0.6);
    }
}

/* Character name overlays */
.character-name-overlay {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: bold;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 25;
}

.npc-avatar:hover .character-name-overlay,
.other-player-avatar:hover .character-name-overlay {
    opacity: 1;
}

.your-name {
    background: rgba(251, 191, 36, 0.9);
    color: #000;
    opacity: 0.8;
}

.player-name {
    background: rgba(52, 211, 153, 0.9);
    color: #000;
}

/* Enemy health bars */
.enemy-health-bar {
    position: absolute;
    top: -8px;
    left: 2px;
    width: 28px;
    height: 4px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 2px;
    pointer-events: none;
}

.enemy-health-fill {
    height: 100%;
    background: linear-gradient(90deg, #dc2626, #ef4444);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Walking animation for main player */
.main-player-avatar.walking {
    animation: walk 0.3s ease-in-out;
}

@keyframes walk {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05) rotate(2deg); }
}

/* Special effects for interactions */
.character-interacting {
    animation: interact 0.5s ease-in-out;
}

@keyframes interact {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.door {
    background: 
        linear-gradient(to right, #451a03 0px, #451a03 12px, #92400e 12px, #92400e 20px, #451a03 20px, #451a03 32px),
        linear-gradient(to bottom, #92400e 0%, #7c2d12 50%, #451a03 100%);
    position: relative;
}

.door::before {
    content: '🚪';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
}

.door::after {
    content: '🔒';
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    font-size: 12px;
}

.boat-sprite {
    animation: boat-bob 2s ease-in-out infinite;
}

@keyframes boat-bob {
    0%, 100% { transform: translateY(0px) rotate(-2deg); }
    50% { transform: translateY(-3px) rotate(2deg); }
}

/* How to Play Button */
.help-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1e40af 100%);
    border: 3px solid #1e40af;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    z-index: 1900;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.help-button:hover {
    transform: translateY(-3px) scale(1.1);
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 50%, #2563eb 100%);
}

/* How to Play Modal */
.help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    overflow-y: auto;
}

.help-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border: 4px solid #3d5a80;
    border-radius: 16px;
    padding: 32px;
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 16px 32px rgba(0,0,0,0.8);
    color: white;
}

.help-section {
    margin-bottom: 24px;
}

.help-section h3 {
    color: #fbbf24;
    margin-bottom: 12px;
    font-size: 18px;
    border-bottom: 2px solid #3d5a80;
    padding-bottom: 8px;
}

.help-section ul {
    list-style: none;
    padding-left: 0;
}

.help-section li {
    margin-bottom: 8px;
    padding-left: 20px;
    position: relative;
}

.help-section li:before {
    content: "▶";
    position: absolute;
    left: 0;
    color: #10b981;
}

.help-key {
    display: inline-block;
    background: rgba(59, 130, 246, 0.2);
    border: 2px solid #3b82f6;
    border-radius: 4px;
    padding: 2px 8px;
    margin: 0 4px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.help-close {
    margin-top: 24px;
    width: 100%;
}

/* PvP Ready Button Active State */
.pvp-active {
    background: linear-gradient(135deg, #10b981 0%, #34d399 50%, #10b981 100%) !important;
    animation: pvp-pulse 2s ease-in-out infinite;
}

@keyframes pvp-pulse {
    0%, 100% { 
        box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 0 25px rgba(16, 185, 129, 0.8);
        transform: scale(1.02);
    }
}

/* PvP Broadcast Item */
.pvp-broadcast-item {
    transition: all 0.2s ease;
}

.pvp-broadcast-item:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* PvP Battle Modal Enhancements */
#pvpBattleModal .battle-arena {
    background: 
        radial-gradient(circle at center, rgba(251, 191, 36, 0.15) 0%, transparent 60%),
        linear-gradient(45deg, rgba(0,0,0,0.2) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0,0,0,0.2) 25%, transparent 25%);
}

/* Wager Display Shine Effect */
#pvpWagerDisplay {
    position: relative;
    overflow: hidden;
}

#pvpWagerDisplay::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: repeating-conic-gradient(
        from 0deg,
        rgba(255,255,255,0.05) 0deg,
        rgba(255,255,255,0.05) 45deg,
        transparent 45deg,
        transparent 90deg
    );
    animation: wager-shine 4s linear infinite;
}

@keyframes wager-shine {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Challenge Modal Pulse Animation */
@keyframes challenge-pulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 30px rgba(220, 38, 38, 0.5);
    }
    50% { 
        transform: scale(1.02);
        box-shadow: 0 0 40px rgba(220, 38, 38, 0.8);
    }
}

/* Challenge Icon Bounce */
@keyframes challenge-bounce {
    0%, 100% { 
        transform: translateY(0) scale(1);
    }
    50% { 
        transform: translateY(-10px) scale(1.1);
    }
}

/* Accept Button Pulse */
@keyframes accept-pulse {
    0%, 100% { 
        background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
        box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
    }
    50% { 
        background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        box-shadow: 0 6px 16px rgba(220, 38, 38, 0.6);
    }
}

/* Incoming Challenge Modal Specific Styles */
#incomingChallengeModal .modal-content {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.98) 0%, rgba(30, 41, 59, 0.98) 100%);
    border: 3px solid #dc2626;
    position: relative;
    overflow: hidden;
}

#incomingChallengeModal .modal-content::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(220, 38, 38, 0.05) 10px,
        rgba(220, 38, 38, 0.05) 20px
    );
    animation: challenge-stripe 20s linear infinite;
}

@keyframes challenge-stripe {
    0% { transform: translate(0, 0); }
    100% { transform: translate(50px, 50px); }
}

/* Ensure content is above the animated background */
#incomingChallengeModal .modal-content > * {
    position: relative;
    z-index: 1;
}

/* Entity Layer for Moving Entities */
.entity-layer {
    position: absolute;
    left: 0;
    top: 0;
    width: 1600px;
    height: 1184px;
    pointer-events: none;
}

.building { 
    z-index: 40; 
    pointer-events: auto;
}

.npc-avatar {
    z-index: 50;
    pointer-events: auto;
}

.enemy-avatar {
    z-index: 30;
    pointer-events: auto;
}

.item-drop {
    z-index: 35;
    pointer-events: auto;
}

.main-player-avatar,
.other-player-avatar {
    z-index: 100;
    pointer-events: none;
}
