@import url('https://fonts.googleapis.com/css2?family=Exo:ital,wght@0,100..900;1,100..900&display=swap');

html {
    -webkit-text-size-adjust: 100%; /* Impede o iOS de redimensionar o texto sozinho */
}

/* Garante que os textos da carta tenham altura de linha controlada */
.texto-codinome, .texto-nome, .texto-bonus, .texto-frase, 
.texto-hab-lider-titulo, .texto-hab-lider-desc, 
.texto-hab-descarte-titulo, .texto-hab-descarte-desc {
    line-height: 1 !important; /* Força o texto a ocupar apenas o seu tamanho real */
}

/* Variáveis de cor e layout */
:root {
    --bg-dark: #1e1e24;
    --bg-panel: #2b2b36;
    --text-light: #f0f0f0;
    --primary: #d9453a;
    --primary-hover: #b83a31;
    
    /* Novas variáveis para as cores da carta */
    --cor-carta-1: #802a32;
    --cor-carta-2: #922636;
    --cor-carta-3: #d9a05b;
}

@font-face {
    font-family: 'SF Proverbial Gothic';
    src: url('../assets/SF Proverbial Gothic Bold Oblique.ttf') format('truetype');
    font-weight: bold;
    font-style: italic; /* Oblique/Italic */
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: sans-serif;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100dvh;
}

/* Menu Lateral */
.sidebar {
    padding: 0; 
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-fixed-top {
    padding: 20px;
    background-color: var(--bg-panel);
    border-bottom: 2px solid #111;
    position: relative;
    z-index: 10;
}

.sidebar-fixed-top h2.title {
    font-family: 'SF Proverbial Gothic', sans-serif;
    font-size: 1.6em;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
    font-style: italic;
    color: var(--primary);
    margin-bottom: 5px;
}

.sidebar-scrollable-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.top-button-group {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.top-button-group button {
    flex: 1;
    padding: 8px 2px;
    font-size: 0.75em;
    white-space: nowrap;
}

/* Botão de Ajuda */
.btn-help {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    padding: 0;
    background: #555;
    font-size: 0.8em;
}

/* Créditos no rodapé */
.sidebar-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #444;
    font-size: 0.7em;
    color: #777;
    text-align: center;
    line-height: 1.4;
}

/* --- Modal --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: linear-gradient(145deg, #2b2b36, #1e1e24);
    margin: 10vh auto;
    padding: 30px;
    border: 1px solid rgba(217, 69, 58, 0.3);
    box-shadow: 0 0 30px rgba(0,0,0,0.5), inset 0 0 10px rgba(217, 69, 58, 0.1);
    width: 90%;
    max-width: 450px;
    border-radius: 16px;
    position: relative;
    color: #f0f0f0;
}

.modal-content h3 {
    font-family: 'SF Proverbial Gothic', sans-serif;
    color: var(--primary);
    font-size: 1.5em;
    margin-bottom: 20px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-content ul {
    list-style: none;
    padding: 0;
}

.modal-content li {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    line-height: 1.4;
    font-size: 0.95em;
}

.modal-content li::before {
    content: '▶';
    color: var(--primary);
    font-size: 0.7em;
    margin-top: 5px;
}

.modal-content strong {
    color: #fff;
    display: block;
    margin-bottom: 2px;
}

.close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 24px;
    color: #888;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover {
    color: var(--primary);
}

.btn-modal-close {
    background: var(--primary);
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: transform 0.2s, background 0.2s;
}

.btn-modal-close:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.title { margin-bottom: 10px; border-bottom: 2px solid var(--primary); padding-bottom: 5px; }

.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

.form-group label {
    font-family: 'Exo', sans-serif;
    font-size: 0.9em;
    font-weight: 700;
    color: #9898b3;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.form-group input, .form-group select {
    padding: 8px; border-radius: 4px; border: 1px solid #444; background: #1e1e24; color: #fff;
}

.form-group textarea {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #444;
    background: #1e1e24;
    color: #fff;
    font-family: 'Exo', sans-serif;
    resize: vertical; 
    min-height: 60px;
    max-height: 300px;
}

.color-group { 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
}
.color-group .form-group { flex: 1; }

/* --- ESTILIZAÇÃO DA BARRA DE SCROLL --- */
.sidebar-scrollable-content::-webkit-scrollbar { width: 8px; }
.sidebar-scrollable-content::-webkit-scrollbar-track { background: var(--bg-dark); border-radius: 10px; }
.sidebar-scrollable-content::-webkit-scrollbar-thumb { background: #444; border-radius: 10px; border: 2px solid var(--bg-dark); }
.sidebar-scrollable-content::-webkit-scrollbar-thumb:hover { background: var(--primary); }
.sidebar-scrollable-content { scrollbar-width: thin; scrollbar-color: #444 var(--bg-dark); }

/* Botões */
.button-group {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px;
    padding-top: 15px; border-top: 1px solid #444;
}
button { padding: 10px; cursor: pointer; border: none; border-radius: 4px; font-weight: bold; background: #444; color: #fff; }
.btn-primary { background: var(--primary); grid-column: span 2; }
.btn-primary:hover { background: var(--primary-hover); }

/* Área da Carta */
.preview-area {
    flex: 1; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle, #333, #111);
}

.card-preview {
    width: 700px; 
    aspect-ratio: 63 / 88; 
    background-color: #000;
    border-radius: 24px; 
    position: relative;
    overflow: hidden; 
    box-shadow: 0 20px 60px rgba(0,0,0,0.8); 
    transform: scale(0.6);
    transform-origin: center center;
    margin: -35% 0; 
}

/* Camadas da Carta */
.card-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
}

#camada-arte {
    z-index: 1;
    position: absolute;
    top: 50%;
    left: 50%;
    background-size: cover;
    background-position: center; 
    background-repeat: no-repeat;
    transform-origin: center center;
}

#camada-fundo-preto {
    z-index: 2;
    background-image: url('../assets/fundo_preto.svg');
    background-size: 100% 100%;
    pointer-events: none; 
}

#camada-moldura-principal {
    z-index: 3; 
    pointer-events: none;
}
#camada-moldura-principal svg { width: 100%; height: 100%; display: block; }

#camada-habilidade {
    z-index: 4; 
    pointer-events: none;
}
#camada-habilidade svg { width: 100%; height: 100%; display: block; }

#camada-sombra {
    z-index: 5; 
    background-image: url('../assets/moldura.png');
    background-size: 100% 100%;
    pointer-events: none;
}

/* Controles de Imagem */
.image-controls {
    display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
    background: #222; padding: 10px; border-radius: 6px; border: 1px solid #444;
}
.control-row { display: flex; align-items: center; gap: 5px; }
.control-row span { font-size: 0.8em; color: #bbb; width: 45px; }
.control-row button { flex: 1; padding: 6px; font-size: 0.9em; background: #333; }
.control-row button:hover { background: #555; }

/* Controles de Cor */
.color-group input[type="color"] {
    width: 100%; height: 42px; padding: 0; background: none; border: none; cursor: pointer;
}
.color-input-wrapper { display: flex; align-items: center; gap: 8px; }
.color-input-wrapper input[type="text"] {
    flex-grow: 1; width: 100%; min-width: 0; padding: 8px 4px;
    text-transform: uppercase; font-family: monospace; font-size: 0.9em; text-align: center; 
}
.color-input-wrapper input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input-wrapper input[type="color"]::-webkit-color-swatch { border: 1px solid #444; border-radius: 4px; }
.color-input-wrapper input[type="color"]::-moz-color-swatch { border: 1px solid #444; border-radius: 4px; }

/* Textos da Carta */
#camada-textos { z-index: 7; pointer-events: none; }

.texto-codinome {
    position: absolute; top: 43px; right: 50px; text-align: right;
    color: #ffffff; font-size: 56px; font-family: 'SF Proverbial Gothic', sans-serif;
    text-transform: uppercase; white-space: pre-wrap;
    text-shadow: -4px -4px 1px #000, 0px -4px 1px #000, 8px -4px 1px #000,
                 -4px  0px 1px #000, 8px  0px 1px #000, -4px  8px 1px #000,
                  0px  8px 1px #000, 8px  8px 1px #000;
}

.texto-nome {
    position: absolute; top: 94px; right: 50px; text-align: right;
    color: #ffffff; font-size: 26px; font-family: 'SF Proverbial Gothic', sans-serif;
    white-space: pre-wrap;
    text-shadow: -2px -2px 1px #000, 0px -2px 1px #000, 4px -2px 1px #000,
                 -2px  0px 1px #000, 4px  0px 1px #000, -2px  4px 1px #000,
                  0px  4px 1px #000, 4px  4px 1px #000;
}

.texto-bonus {
    position: absolute; top: 50px; left: 38px; width: 120px; text-align: center;
    color: #ffffff; font-size: 116px; font-family: 'SF Proverbial Gothic', sans-serif;
    text-shadow: 10px 0px 0 var(--cor-carta-1);  
    letter-spacing: -1px;
}

.texto-frase {
    position: absolute; top: 504px; text-align: center; width: 100%;
    color: #ffffff; font-size: 24px; font-family: 'SF Proverbial Gothic', sans-serif;
    padding: 0 40px; line-height: 24px; white-space: pre-wrap;
    text-shadow: -2px -2px 1px #000, 0px -2px 1px #000, 4px -2px 1px #000,
                 -2px  0px 1px #000, 4px  0px 1px #000, -2px  4px 1px #000,
                  0px  4px 1px #000, 4px  4px 1px #000;
}

/* Brasões Equipes */
#camada-equipe { z-index: 6; pointer-events: none; }
#display-equipe1 { position: absolute; top: 180px; left: 50px; width: 120px; height: 120px; object-fit: contain; }
#display-equipe2 { position: absolute; top: 290px; left: 50px; width: 120px; height: 120px; object-fit: contain; }

/* Textos Habilidades */
.texto-hab-lider-titulo, .texto-hab-descarte-titulo {
    position: absolute; left: 120px; width: 340px; text-align: left;
    color: #fff; font-size: 30px; font-family: 'SF Proverbial Gothic', sans-serif;
    text-shadow: -2px -2px 1px #000, 0px -2px 1px #000, 4px -2px 1px #000,
                 -2px  0px 1px #000, 4px  0px 1px #000, -2px  4px 1px #000,
                  0px  4px 1px #000, 4px  4px 1px #000;
}
.texto-hab-lider-desc, .texto-hab-descarte-desc {
    position: absolute; width: 80%; left: 70px; text-align: center;
    color: #ffffff; font-size: 24px; font-family: 'Exo', sans-serif;
    white-space: pre-wrap; line-height: 26px;
    text-shadow: -2px -2px 1px #000, 0px -2px 1px #000, 4px -2px 1px #000,
                 -2px  0px 1px #000, 4px  0px 1px #000, -2px  4px 1px #000,
                  0px  4px 1px #000, 4px  4px 1px #000;
}

.texto-hab-lider-titulo { top: 566px; }
.texto-hab-lider-desc { top: 624px; }
.texto-hab-descarte-titulo { top: 742px; }
.texto-hab-descarte-desc { top: 800px; }

/* Ícones Habilidades */
#camada-tipos-hab { z-index: 6; pointer-events: none; }
#display-tipoHabLider { position: absolute; top: 524px; right: 40px; width: 106px; height: 106px; object-fit: contain; }
#display-tipoHabDescarte { position: absolute; top: 700px; right: 40px; width: 106px; height: 106px; object-fit: contain; }

/* Container de Navegação */
.nav-builders { margin-top: 20px; padding-top: 15px; border-top: 2px solid #111; }
.nav-title {
    font-family: 'Exo', sans-serif; font-size: 0.8em; color: #9898b3;
    text-transform: uppercase; margin-bottom: 10px; text-align: center;
}
.nav-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.btn-nav {
    display: flex; align-items: center; justify-content: center; background: #333; color: #fff;
    text-decoration: none; font-size: 0.7em; font-weight: bold; padding: 8px 2px;
    border-radius: 4px; text-align: center; transition: background 0.2s;
}
.btn-nav:hover { background: var(--primary); }
.btn-full { grid-column: span 4; margin-top: 2px; }

/* ========================================================= */
/* ESTILOS ESPECÍFICOS DO AGREGADOR DE IMPRESSÃO             */
/* ========================================================= */

/* A Folha A4 na tela (Substitui a carta única do builder) */
.folha-a4 {
    width: 210mm;
    height: 297mm; /* Agora tem altura fixa para garantir a proporção */
    background: #ffffff;
    padding: 11mm 8.5mm; /* Margens perfeitas para centralizar 3 cartas de 63mm */
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: grid;
    grid-template-columns: repeat(3, 63mm);
    grid-template-rows: repeat(3, 88mm);
    gap: 2mm;
    margin: 0 auto;
}

/* Espaço da carta (Estático agora) */
.carta-slot {
    width: 63mm;
    height: 88mm;
    border: 1px dashed rgba(0,0,0,0.3);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Fundamental para o giro não quebrar o layout */
    box-sizing: border-box;
}

.carta-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

/* Classes das 4 posições de rotação */
.carta-slot img.rot-0 {
    transform: rotate(0deg);
}

.carta-slot img.rot-90 {
    width: 88mm;
    height: 63mm;
    transform: rotate(90deg);
}

.carta-slot img.rot-180 {
    transform: rotate(180deg);
}

.carta-slot img.rot-270 {
    width: 88mm;
    height: 63mm;
    transform: rotate(270deg);
}

/* ===================================== */
/* ESTILOS DOS BOTÕES INDIVIDUAIS (1 a 9)*/
/* ===================================== */
.controle-carta {
    background: #222;
    border: 1px solid #444;
    padding: 10px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.controle-topo {
    display: flex;
    justify-content: space-between;
    font-family: 'Exo', sans-serif;
    font-size: 0.9em;
    font-weight: bold;
    color: var(--primary);
}
.controle-botoes {
    display: flex;
    gap: 5px;
}
.controle-botoes button, .controle-botoes label {
    flex: 1; padding: 6px 0; font-size: 0.7em; cursor: pointer; text-align: center;
}
.btn-adicionar { background: #444; color: #fff; border-radius: 4px; font-weight: bold; }
.btn-adicionar:hover { background: #555; }

/* Bloqueia o zoom nativo da tela toda e permite arrastar a folha */
.preview-area {
    touch-action: pan-x pan-y;
}

/* O zoom da folha vai ancorar no topo esquerdo para não sumir da tela */
.folha-a4 {
    transform-origin: top left !important;
}

/* --- REGRAS DE IMPRESSÃO (O que acontece ao clicar no botão Imprimir) --- */
@media print {
    /* Força a impressora a entender que o papel é A4 e tira margem do navegador */
    @page {
        size: A4 portrait; 
        margin: 0; 
    }

    /* Remove as cores escuras de fundo */
    body, html {
        background: white !important;
        margin: 0;
        padding: 0;
        height: auto !important; 
        overflow: visible !important;
    }

    .app-container {
        display: block !important; 
        height: auto !important; 
    }

    /* Esconde o menu lateral, botões de ajuda e qualquer modal */
    .sidebar, .btn-help, #modalAjuda {
        display: none !important;
    }

    /* Remove gradientes e rolagem da área da folha, deixando ela plana */
    .preview-area, #area-impressao {
        background: none !important; 
        padding: 0 !important;
        display: block !important;
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
    }

    /* Formata a folha A4 exatamente pro papel */
    .folha-a4 {
        box-shadow: none !important;
        margin: 0 !important;
        width: 210mm !important;
        height: 297mm !important; 
        
        /* Remove o "always" que gerava a página em branco */
        page-break-after: auto !important; 
    }
	
	#controles-zoom-mobile { 
        display: none !important; 
    }
    
    /* Na hora de imprimir, a linha pontilhada fica mais fina e cinza claro */
    .carta-slot {
        page-break-inside: avoid;
        border: 0.5px dotted #ccc; 
    }
}

/* --- VERSÃO MOBILE: CARTA NAVEGÁVEL (PAN) E MENU DE 30% --- */
@media (max-width: 768px) {
    body { overflow: hidden; }
    .app-container { flex-direction: column; height: 100dvh; }

    /* 1. Área de Preview: Ocupa 70% da tela e permite deslizar com o dedo (Pan) */
    .preview-area {
        position: relative; 
        z-index: 100; 
        flex: 0 0 60vh; /* Exatos 70% da altura da tela */
        width: 100%;
        background: radial-gradient(circle, #222, #525271);
        
        /* O segredo para navegar com os dedos: */
        display: block !important; /* Importante para não travar o scroll */
        overflow: auto !important; /* Libera rolagem em X e Y */
        -webkit-overflow-scrolling: touch; /* Deslize suave no iOS */
        padding: 20px !important;
        order: 1;
    }

    /* Garante que a folha A4 mantenha seu tamanho e não sofra scale bizarro no mobile */
    .folha-a4 {
        margin: 0; /* Tira o margin: 0 auto para permitir scroll desde o canto esquerdo */
    }

    /* 2. Menu Lateral: Ocupa 30% da tela travado na base */
    .sidebar { 
        flex: 0 0 40vh; /* Exatos 30% da altura da tela */
        width: 100%; 
        min-width: 100%; 
        order: 2; 
        border-right: none;
        border-top: 3px solid var(--primary); 
        display: flex; 
        flex-direction: column;
        overflow: hidden; 
        background-color: var(--bg-panel);
    }

    /* O conteúdo de dentro do menu continua rolando normalmente */
    .sidebar-scrollable-content {
        flex: 1; 
        overflow-y: auto !important; 
        padding: 10px 15px;
        -webkit-overflow-scrolling: touch;
    }

    /* Ajustes dos botões do topo do menu para caberem bem */
    .sidebar-fixed-top { padding: 10px 15px; flex-shrink: 0; position: relative; }
    .sidebar-fixed-top h2.title { font-size: 1.1em; margin-bottom: 8px; }
    .btn-help { top: 10px; right: 15px; }

    .top-button-group { display: flex; flex-wrap: nowrap; gap: 5px; }
    .top-button-group button { flex: 1; padding: 10px 2px; font-size: 0.65em; white-space: nowrap; }
}