/* ==========================================================================
   IMPORTS & CONFIGURAÇÕES GLOBAIS
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=MedievalSharp&display=swap');

/* Paleta de Cores de Phaos:
   Preto Profundo: #0a0a0a
   Cinza Ferro:    #2c2c2c
   Ouro Medieval:  #c5a059
   Sangue:         #8b0000
   Pergaminho:     #d2b48c
*/

body {
    margin: 0;
    padding: 0;
    background-color: #050505;
    color: #c5a059;
    font-family: 'MedievalSharp', cursive, serif;
    image-rendering: pixelated; /* Mantém o aspecto retro/pixel art sem borrões */
    overflow: hidden;
    user-select: none;          /* Impede o jogador de selecionar textos sem querer */
}

/* ==========================================================================
   VIEWPORT E CAMADAS (MAPA E CÂMERA)
   ========================================================================== */
#game-viewport {
    width: 100vw;
    height: 100vh;
    position: relative;
    background: radial-gradient(circle, #1a1a1a 0%, #000 100%);
    border: 8px solid #2c2c2c;
    box-sizing: border-box;
    overflow: hidden;
}

/* Camada do Mapa (Simulação de Tiles por Grid) */
#map-layer {
    width: 2000px; /* Tamanho total do cenário */
    height: 2000px;
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 32px 32px; /* Força o Grid visual de 32px */
    position: absolute;
    top: 0;
    left: 0;
}

/* Camadas de Elementos Dinâmicos */
#players-layer, #monster-layer, #entities-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ==========================================================================
   ENTIDADES (PLAYERS E MONSTROS)
   ========================================================================== */
.player, .monster {
    width: 32px;
    height: 32px;
    position: absolute;
    transition: left 0.12s ease-out, top 0.12s ease-out; /* Suaviza o movimento vindo do AJAX */
    box-sizing: border-box;
}

#my-player {
    background: #c5a059; /* Ouro */
    box-shadow: 0 0 15px rgba(197, 160, 89, 0.6);
    border-radius: 4px;
    border: 2px solid #fff;
    z-index: 50; /* Garante que você fica por cima de outros players */
}

.other-player {
    background: #4a90e2; /* Azul */
    border: 2px solid #2171cc;
    border-radius: 4px;
    z-index: 40;
}

.monster {
    background: #8b0000; /* Vermelho Escuro */
    border: 1px solid #ff0000;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
    z-index: 30;
    cursor: crosshair;
    pointer-events: auto;
    transition: all 0.3s ease;
}

.monster:hover {
    filter: brightness(1.5);
    border: 1px solid #fff;
}

/* Barra de Vida sobre o Monstro */
.monster .hp-bar-container {
    position: absolute;
    top: -10px;
    left: 0;
    width: 32px;
    height: 4px;
    background: #333;
    border: 1px solid #000;
}

.monster .hp-bar-fill {
    height: 100%;
    background: #ff0000;
}

/* Nome acima das Entidades */
.p-name {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    white-space: nowrap;
    background: rgba(10, 10, 10, 0.85);
    color: #fff;
    padding: 2px 6px;
    border: 1px solid #c5a059;
    border-radius: 3px;
    text-shadow: 1px 1px #000;
}

/* ==========================================================================
   INTERFACES DE USUÁRIO (UI OVERLAYS FIXOS)
   ========================================================================== */
#ui-overlay {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
    min-width: 220px;
    box-sizing: border-box;
}

.ui-box {
    background: rgba(10, 10, 10, 0.9);
    padding: 15px;
    border: 2px solid #c5a059;
    box-shadow: 5px 5px 0px #000;
    color: #fff;
}

#ui-overlay b {
    color: #fff;
    text-shadow: 1px 1px #000;
}

/* Barra de Vida Retrô da UI */
.hp-bar-container {
    width: 100%;
    height: 10px;
    background: #1a1a1a;
    margin-top: 8px;
    border: 1px solid #c5a059;
    box-sizing: border-box;
    overflow: hidden;
}

.hp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #8b0000 0%, #ff0000 100%);
    width: 100%; 
    transition: width 0.2s ease-in-out;
}

/* ==========================================================================
   SISTEMA DE CHAT MURAL
   ========================================================================== */
#chat-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 380px;
    background: rgba(10, 10, 10, 0.85);
    border: 2px solid #c5a059;
    z-index: 100;
    box-shadow: 4px 4px 0px #000;
}

.chat-tabs {
    display: flex;
    background: #000;
    border-bottom: 1px solid #c5a059;
}

.chat-tabs button {
    flex: 1;
    background: none;
    border: none;
    color: #555;
    padding: 6px;
    cursor: pointer;
    font-weight: bold;
    font-family: 'MedievalSharp', cursive;
    font-size: 12px;
}

.chat-tabs button.active {
    color: #c5a059;
    background: #1a1a1a;
}

#chat-messages {
    height: 140px;
    overflow-y: auto;
    padding: 8px;
    font-size: 13px;
    color: #fff;
    display: flex;
    flex-direction: column;
}

.chat-msg { margin-bottom: 4px; }
.chat-user { color: #c5a059; font-weight: bold; margin-right: 5px; }
.chat-time { color: #777; font-size: 10px; margin-right: 5px; }

/* Cor diferenciada para mensagens de guilda */
.msg-guild {
    color: #00ff00; /* Verde esmeralda para aliados */
    border-left: 2px solid #00ff00;
    padding-left: 5px;
}

#chat-input {
    width: 100%;
    background: #111;
    border: none;
    border-top: 1px solid #c5a059;
    color: #fff;
    padding: 8px;
    box-sizing: border-box;
    font-family: 'MedievalSharp', cursive;
}

/* ==========================================================================
   MINIMAPA (Painel Superior Direito)
   ========================================================================== */
#minimap-container {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 160px;
    background: rgba(10, 10, 10, 0.9);
    border: 2px solid #c5a059;
    text-align: center;
    color: #fff;
    z-index: 100;
    box-shadow: -4px 4px 0px #000;
}

#minimap-label { 
    background: #c5a059; 
    color: #000; 
    font-weight: bold; 
    padding: 4px; 
    font-size: 12px; 
}

#minimap-viewport { 
    width: 130px; 
    height: 130px; 
    background: #111; 
    margin: 10px auto; 
    border: 1px solid #222; 
    position: relative;
}

#minimap-player {
    width: 6px;
    height: 6px;
    background: #00ff00;
    position: absolute;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#minimap-coords {
    font-size: 11px;
    padding-bottom: 6px;
    color: #aaa;
}

/* ==========================================================================
   MENU LATERAL DO HERÓI (Alinhado abaixo do Minimapa)
   ========================================================================== */
#side-menu {
    position: fixed;
    top: 220px; /* Encaixa logo abaixo do container do minimapa */
    right: 20px;
    width: 250px;
    height: calc(100vh - 260px); /* Se adapta dinamicamente à altura da tela */
    min-height: 350px;
    background: #141414;
    border: 2px solid #c5a059;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: -5px 5px 15px rgba(0, 0, 0, 0.7);
}

.menu-header {
    background: #8b4513;
    color: #ffd700;
    text-align: center;
    padding: 10px;
    font-weight: bold;
    text-transform: uppercase;
    border-bottom: 1px solid #c5a059;
    font-size: 14px;
    letter-spacing: 1px;
}

.menu-nav-btns { 
    display: flex; 
    background: #222; 
    border-bottom: 1px solid #333;
}

.menu-btn {
    flex: 1; 
    padding: 10px 0; 
    background: none; 
    border: none;
    color: #c5a059; 
    cursor: pointer; 
    font-weight: bold; 
    font-size: 12px;
    font-family: 'MedievalSharp', cursive;
    transition: background 0.2s;
}

.menu-btn:hover, .menu-btn.active { 
    background: #c5a059; 
    color: #000; 
}

#menu-content { 
    flex: 1; 
    padding: 15px; 
    color: #fff; 
    overflow-y: auto; 
}

.tab-content { 
    font-size: 14px; 
}

.btn-exit-sidebar {
    background: #8b0000;
    color: #fff;
    text-align: center;
    padding: 12px;
    text-decoration: none;
    font-weight: bold;
    font-size: 13px;
    border-top: 1px solid #c5a059;
    transition: background 0.2s;
}

.btn-exit-sidebar:hover { 
    background: #ff0000; 
}

/* ==========================================================================
   JANELA DE INVENTÁRIO ANTIGA (MANTIDA EM FALLBACK SE NECESSÁRIO)
   ========================================================================== */
#inventory-window {
    position: fixed;
    right: 290px;
    top: 220px;
    width: 260px;
    background: #d2b48c;
    border: 4px ridge #8b4513;
    padding: 12px;
    color: #3e2723;
    display: none;
    z-index: 101;
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);
    box-sizing: border-box;
}

.slots-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px;
}

.item-slot {
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.08);
    border: 2px inset #8b4513;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
}

/* ==========================================================================
   MECÂNICAS VISUAIS DE EVENTOS E MAPAS
   ========================================================================== */
.portal {
    width: 64px;
    height: 64px;
    position: absolute;
    background: radial-gradient(circle, rgba(197, 160, 89, 0.8) 0%, transparent 70%);
    border-radius: 50%;
    animation: portalPulse 2s infinite ease-in-out;
    z-index: 5;
}

@keyframes portalPulse {
    0% { transform: scale(0.8); opacity: 0.5; box-shadow: 0 0 10px #c5a059; }
    50% { transform: scale(1.1); opacity: 0.9; box-shadow: 0 0 30px #c5a059; }
    100% { transform: scale(0.8); opacity: 0.5; box-shadow: 0 0 10px #c5a059; }
}

#pvp-alert {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    color: #f00;
    font-weight: bold;
    text-shadow: 2px 2px #000;
    font-size: 24px;
    z-index: 110;
    display: none;
}

#castle-banner {
    position: fixed;
    top: 0;
    width: 100%;
    text-align: center;
    background: linear-gradient(to bottom, #8b0000, transparent);
    color: #ffd700;
    padding: 10px;
    font-size: 18px;
    text-shadow: 2px 2px #000;
    z-index: 90;
    display: none;
}

/* Filtros de Ambiente */
.map-style-1 {
    filter: sepia(0.2) hue-rotate(-10deg);
}
.map-style-2 {
    filter: grayscale(0.5) contrast(1.2) brightness(0.8);
}

#inventory-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 5px;
}

.item-card {
    background: #111;
    border: 1px solid #3a2f1d;
    padding: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.item-card.equipped {
    border-color: #ffd700;
    background: linear-gradient(to right, #1a1508, #111);
}

.item-info strong {
    display: block;
    font-size: 13px;
    color: #c5a059;
}

.item-info small {
    font-size: 10px;
    color: #888;
}

.item-actions button {
    background: #222;
    border: 1px solid #c5a059;
    color: #fff;
    padding: 3px 6px;
    font-size: 11px;
    cursor: pointer;
    font-family: monospace;
}

.item-actions button:hover {
    background: #c5a059;
    color: #000;
}

/* Container da Grade da Mochila */
#inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 slots por linha */
    gap: 8px;
    padding: 5px;
    background: #0f0b08;
    border: 2px solid #3a2f1d;
    border-radius: 4px;
}

/* Slot de Item Estilo Medieval */
.item-slot {
    aspect-ratio: 1; /* Mantém o slot perfeitamente quadrado */
    background: radial-gradient(circle, #2a2015 0%, #15100a 100%);
    border: 2px solid #5a4530;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.8);
    position: relative;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-slot:hover {
    border-color: #c5a059;
    transform: scale(1.03);
}

.item-slot.equipped {
    border-color: #2ecc71;
    box-shadow: inset 0 0 10px rgba(46, 204, 113, 0.4), 0 0 5px rgba(46, 204, 113, 0.5);
}

/* Ícones de texto ou emoji simulando os itens */
.item-icon {
    font-size: 24px;
    filter: drop-shadow(0px 2px 3px rgba(0,0,0,0.8));
}

/* Mini tag para mostrar se está equipado */
.equipped-tag {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #2ecc71;
    color: #000;
    font-size: 8px;
    font-weight: bold;
    padding: 1px 3px;
    border-radius: 2px;
    text-transform: uppercase;
}

/* Menu de contexto rápido ao clicar no item */
.item-tooltip {
    display: none;
    position: absolute;
    bottom: 105%;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1510;
    border: 1px solid #c5a059;
    color: #e0d0b0;
    padding: 6px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    text-align: center;
}

.item-slot:hover .item-tooltip {
    display: block;
}

.item-tooltip button {
    background: #3a2f1d;
    color: #ffd700;
    border: 1px solid #c5a059;
    cursor: pointer;
    font-size: 10px;
    margin-top: 4px;
    padding: 2px 4px;
    width: 100%;
}
.item-tooltip button:hover { background: #ffd700; color: #000; }

/* Visual da Loja */
.shop-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.3);
    border: 1px solid #3a2f1d;
    margin-bottom: 6px;
    padding: 6px;
}
.btn-buy {
    background: #006400;
    color: #fff;
    border: 1px solid #000;
    padding: 4px 8px;
    cursor: pointer;
    font-weight: bold;
}
.btn-buy:hover { background: #008000; }


/* Estilos para o Mapa Dinâmico */
#map-layer {
    position: relative;
    width: 640px;  /* 20 colunas x 32px */
    height: 512px; /* 16 linhas x 32px */
    background: #111;
    overflow: hidden;
}

.tile {
    box-sizing: border-box;
}

/* Cores medievais retro para testes (podes trocar por imagens/sprites depois) */
.piso-grama {
    background: #1b3d1b; /* Verde Escuro */
    border: 1px solid #142e14;
}

.piso-parede {
    background: #2c251e; /* Castanho/Rocha */
    border: 1px solid #1a1511;
}

.piso-banco {
    background: #a67c1e; /* Dourado/🏛️ */
    border: 2px dashed #ffd700;
}

.piso-loja {
    background: #a63a1e; /* Vermelho/🏪 */
    border: 2px dashed #ff5533;
}