/* ==========================================================================
   VARIÁVEIS GLOBAIS E RESET DE PÁGINA
   ========================================================================== */
:root { 
    --accent: #00ffcc; /* Cor de destaque principal (Verde Água) */
    --bg: #0f172a;     /* Cor de fundo padrão */
    --panel: rgba(30, 41, 59, 0.95); /* Cor das caixas de menu */
}

body { 
    margin: 0; 
    overflow: hidden; /* Esconde as barras de rolagem nativas */
    background: var(--bg); 
    font-family: 'Segoe UI', sans-serif; 
    color: white; 
}

/* ==========================================================================
   CENÁRIO PRINCIPAL E CÂMERA (FÍSICA DO MAPA)
   ========================================================================== */
#viewport { 
    width: 100vw; 
    height: 100vh; 
    overflow: hidden; 
    position: relative; 
    cursor: grab; 
}

#canvas-area { 
    width: 5000px; /* Tamanho do mundo virtual */
    height: 5000px; 
    position: absolute; 
    transform-origin: 0 0; 
}

canvas { 
    position: absolute; 
    top: 0; left: 0; 
    z-index: 1; /* Fica atrás das bolhas */
    pointer-events: none; /* Deixa o mouse "atravessar" a linha para clicar no fundo */
}

/* ==========================================================================
   INTERFACE E MENUS
   ========================================================================== */
/* Botões do Topo */
#ui-top { position: fixed; top: 20px; left: 20px; z-index: 2000; display: flex; gap: 10px; }
.main-btn { padding: 10px 20px; background: var(--accent); color: #0f172a; border: none; border-radius: 25px; cursor: pointer; font-weight: bold; box-shadow: 0 4px 10px rgba(0,255,204,0.3); transition: transform 0.2s; }
.main-btn:hover { transform: scale(1.05); }

/* Menu Lateral (Sidebar de Projetos) */
#sidebar { position: fixed; top: 80px; left: 20px; z-index: 2000; background: var(--panel); padding: 15px; border-radius: 15px; border: 1px solid rgba(255,255,255,0.1); width: 200px; max-height: 70vh; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.proj-item { padding: 10px; margin-bottom: 5px; background: rgba(255,255,255,0.05); border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-size: 13px; transition: background 0.2s; }
.proj-item:hover { background: rgba(255,255,255,0.1); }
.proj-item.active { border: 1px solid var(--accent); background: rgba(0,255,204,0.15); color: var(--accent); font-weight: bold; }
.btn-del-proj { color: #ff5e57; font-weight: bold; padding: 2px 6px; border-radius: 4px; cursor: pointer; }
.btn-del-proj:hover { background: rgba(255, 94, 87, 0.2); }

/* Menu de Fundo (Canto Direito) */
#menu-right { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,0.7); padding: 8px 15px; border-radius: 25px; border: 1px solid rgba(255,255,255,0.1); }

/* Rodapé */
#footer-auteria { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); font-size: 12px; color: rgba(255,255,255,0.3); z-index: 2000; pointer-events: none; letter-spacing: 1px; }

/* ==========================================================================
   ANIMAÇÃO DE BRILHO DO BOTÃO DE VERSÃO
   ========================================================================== */
@keyframes pulsar-borda {
    0% { border-color: rgba(0, 255, 204, 0.2); box-shadow: 0 0 0 rgba(0, 255, 204, 0); }
    50% { border-color: rgba(0, 255, 204, 1); box-shadow: 0 0 12px rgba(0, 255, 204, 0.6); color: #00ffcc; }
    100% { border-color: rgba(0, 255, 204, 0.2); box-shadow: 0 0 0 rgba(0, 255, 204, 0); }
}

#version-btn { 
    position: fixed; bottom: 10px; left: 20px; z-index: 2000; 
    background: rgba(255, 255, 255, 0.05); padding: 5px 10px; border-radius: 8px; 
    font-size: 11px; color: #94a3b8; cursor: pointer; transition: background 0.2s; 
    border: 1px solid rgba(0, 255, 204, 0.3); 
    animation: pulsar-borda 2.5s infinite ease-in-out;
}

#version-btn:hover { 
    background: rgba(0, 255, 204, 0.1); color: var(--accent); border-color: var(--accent); 
    animation: none; box-shadow: 0 0 15px rgba(0, 255, 204, 0.8);
}

/* Modais */
.modal-box { position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); background:#1e293b; padding:25px; border-radius:15px; border:1px solid var(--accent); z-index:3000; box-shadow:0 10px 40px rgba(0,0,0,0.8); width: 350px; max-width: 90vw; }
.modal-box h3 { color: var(--accent); margin-top: 0; text-align: center; }
.tutorial-content p, .patch-content p, .patch-content li { font-size: 13px; color: #e2e8f0; margin-bottom: 10px; line-height: 1.5; }
.patch-content h4 { color: #a29bfe; margin-bottom: 5px; margin-top: 0; }
.patch-content ul { padding-left: 20px; margin-top: 0; }
.tutorial-content strong { color: #feca57; }

/* ==========================================================================
   ENTIDADES (BOLHAS DE IDEIA E IMAGENS)
   ========================================================================== */
.entity { 
    position: absolute; 
    z-index: 100; 
    cursor: grab; 
    background: #1e293b; 
    border: 2px solid rgba(255,255,255,0.1); 
    transition: box-shadow 0.3s, background 0.3s; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    user-select: none; 
    -webkit-user-select: none; 
}

/* Bolha Inteligente (Tamanho Base Fixo) */
.bubble { 
    width: 120px;  
    height: 120px; 
    border-radius: 50%; 
    align-items: center; 
    justify-content: center; 
    padding: 15px; 
    box-sizing: border-box;
}

/* Imagem */
.image-card { width: 250px; height: 200px; border-radius: 15px; resize: both; }

/* Título Curto da Bolha Fechada */
.label { 
    font-weight: bold; 
    text-align: center; 
    color: var(--accent); 
    padding: 5px; 
    pointer-events: none; 
    word-wrap: break-word; 
    font-size: 14px;
    line-height: 1.2;
}

/* ==========================================================================
   ESTADO EXPANDIDO (ESTILO POST-IT QUADRADINHO / VIDRO JATEADO)
   ========================================================================== */
.expanded { 
    width: 400px !important; 
    height: auto !important; 
    min-height: 200px !important;
    max-height: 80vh !important; 
    max-width: none !important; 
    aspect-ratio: unset !important; 
    border-radius: 15px !important; 
    z-index: 9000 !important; 
    cursor: default !important; 
    background: rgba(15, 23, 42, 0.85); 
    border: 2px solid rgba(0, 255, 204, 0.4); 
    backdrop-filter: blur(12px) !important; 
    -webkit-backdrop-filter: blur(12px) !important; 
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8) !important; 
    display: flex !important; 
    flex-direction: column !important;
}

.expanded .label { display: none; }

/* Área onde o usuário escreve (A mola que empurra o menu) */
.content-area { 
    flex: 1; 
    width: 100%; 
    height: 100%; 
    outline: none; 
    display: none; 
    overflow-y: auto; 
    padding: 20px; 
    color: #e2e8f0; 
    cursor: text; 
    box-sizing: border-box; 
    user-select: text; 
    -webkit-user-select: text; 
}
.expanded .content-area { 
    display: block; 
    flex: 1; 
    overflow-y: auto; 
    padding-right: 5px; 
}

/* Menu de Ferramentas (Preso na Base) */
.tools { 
    margin-top: auto; 
    display: none; 
    width: 100%; 
    background: rgba(0,0,0,0.8); 
    padding: 8px; 
    justify-content: space-around; 
    border-top: 1px solid rgba(255,255,255,0.1); 
    box-sizing: border-box; 
}
.expanded .tools, .image-card:hover .tools { display: flex; }
.tool-btn { background: none; border: none; color: white; cursor: pointer; font-size: 16px; opacity: 0.8; }
.tool-btn:hover { opacity: 1; transform: scale(1.1); }

/* ==========================================================================
   OTIMIZAÇÃO DEFINITIVA PARA CELULAR E TABLETS
   ========================================================================== */
@media (max-width: 1024px), (max-height: 500px) {
  
    #ui-top { 
        flex-wrap: nowrap;
        justify-content: flex-start; 
        overflow-x: auto; 
        padding: 12px; 
        gap: 12px; 
        width: 100vw; 
        box-sizing: border-box; 
        border-radius: 0 0 15px 15px;
        background: rgba(0, 0, 0, 0.25);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px); 
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        -webkit-overflow-scrolling: touch; 
    }
    
    #ui-top::-webkit-scrollbar { display: none; }

    #ui-top button, #box-escala { 
        flex: 0 0 auto !important; 
        margin: 0 !important; 
        font-size: 12px !important; 
        padding: 8px 16px !important; 
    }

    #menu-right {
        top: auto;
        bottom: 20px;
        right: 20px;
        background: rgba(0,0,0,0.85);
    }

    #version-btn {
        bottom: 20px;
        left: 20px;
        background: rgba(0,0,0,0.85);
    }

    #sidebar { 
        position: fixed; 
        top: 50%; 
        left: 50%; 
        transform: translate(-50%, -50%); 
        width: 85%; 
        max-width: 320px; 
        bottom: auto;
        padding: 20px; 
        z-index: 2500; 
        box-shadow: 0 10px 50px rgba(0,0,0,0.9); 
    }

    #footer-auteria { display: none; }
    .entity { transform: scale(0.85); } 
}

/* ==========================================================================
   INDICADOR DE SELEÇÃO ATIVA E CAIXA DE SELEÇÃO MÚLTIPLA
   ========================================================================== */
.entity.selecionada-ativa { z-index: 150 !important; }

#caixa-selecao {
    position: fixed; border: 1px dashed #00ffcc; background: rgba(0, 255, 204, 0.1);
    z-index: 9999; pointer-events: none; display: none; 
}

/* ==========================================================================
   SIDEBAR DE MANUAL E ATUALIZAÇÕES (PATCH NOTES)
   ========================================================================== */
#modal-patch {
    position: fixed; top: 70px; right: 0; width: 320px; height: calc(100vh - 90px);
    background: var(--panel); border: 1px solid var(--accent); border-right: none;
    border-radius: 15px 0 0 15px; padding: 20px; box-sizing: border-box; z-index: 2000;
    color: white; box-shadow: -5px 0 25px rgba(0,0,0,0.5);
    transform: translateX(110%); transition: transform 0.3s ease-in-out;
    display: flex; flex-direction: column;
}

#modal-patch.aberto { transform: translateX(0); }
.patch-content { flex-grow: 1; overflow-y: auto; padding-right: 8px; }
.patch-content::-webkit-scrollbar { width: 6px; }
.patch-content::-webkit-scrollbar-thumb { background: #00ffcc; border-radius: 10px; }

/* ==========================================================================
   CONTRASTE AUTOMÁTICO PARA FUNDOS CLAROS
   ========================================================================== */
@media (max-width: 1024px), (max-height: 500px) {
    .tema-claro #ui-top { background: rgba(255, 255, 255, 0.4) !important; border-bottom: 1px solid rgba(0, 0, 0, 0.1); }
}

.tema-claro .label { color: #0f172a !important; font-weight: 900; }
.tema-claro .content-area { color: #1e293b !important; font-weight: 500; }
.tema-claro .tool-btn { color: #0f172a !important; }
.tema-claro #menu-right span, .tema-claro #box-escala span { color: #0f172a !important; }

.tema-claro .expanded {
    background: rgba(255, 255, 255, 0.85); border: 2px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15) !important;
}

/* ==========================================================================
   LEGENDA DAS IMAGENS
   ========================================================================== */
.legenda-area {
    text-align: center; outline: none; font-size: 13px; margin-top: 5px; color: #e2e8f0;
    user-select: text; -webkit-user-select: text; cursor: text; min-height: 18px; word-wrap: break-word;
}

.legenda-area:empty::before { content: "Adicionar legenda..."; color: rgba(255,255,255,0.3); pointer-events: none; }
.entity:not(.expanded) .legenda-area:empty { display: none; }
.tema-claro .legenda-area { color: #1e293b !important; }

/* ==========================================================================
   PALETA DE CORES DO FUNDO
   ========================================================================== */
#menu-right { cursor: pointer; } 

#paleta-fundo {
    position: absolute; top: 130%; right: 0; background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 12px;
    border-radius: 12px; border: 1px solid rgba(0, 255, 204, 0.3); display: none; 
    gap: 10px; flex-wrap: wrap; width: 145px; box-shadow: 0 10px 30px rgba(0,0,0,0.8); cursor: default;
}

#paleta-fundo.mostrar { display: flex; }
.swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid rgba(255,255,255,0.1); transition: transform 0.2s, border-color 0.2s; box-sizing: border-box; }
.swatch:hover { transform: scale(1.15); border-color: #00ffcc; }
.custom-color-btn { display: flex; align-items: center; justify-content: center; background: #334155; font-size: 14px; border: 1px dashed rgba(255,255,255,0.4); }

@media (max-width: 1024px), (max-height: 500px) {
    #paleta-fundo { top: auto; bottom: 130%; }
    #menu-right { bottom: 30px; } 
}

/* ==========================================================================
   ANIMAÇÃO: RESPIRAÇÃO DA BOLHA SELECIONADA
   ========================================================================== */
@keyframes flutuar { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }
.selecionada-ativa { animation: flutuar 3s ease-in-out infinite; }

/* ==========================================================================
   MODO APRESENTAÇÃO (CSS)
   ========================================================================== */
body.modo-apresentacao #ui-top, body.modo-apresentacao #sidebar,
body.modo-apresentacao #menu-right, body.modo-apresentacao #version-btn,
body.modo-apresentacao .tools { display: none !important; }

body.modo-apresentacao .content-area, body.modo-apresentacao .legenda-area {
    pointer-events: none !important; user-select: none;
}

#btn-sair-apresentacao {
    display: none; position: fixed; top: 20px; right: 20px; z-index: 9999;
    background: rgba(255, 118, 117, 0.9); color: white; border: none; padding: 10px 20px;
    border-radius: 8px; font-weight: bold; cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.5); backdrop-filter: blur(5px);
}

body.modo-apresentacao #btn-sair-apresentacao { display: block; }