:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-main: #333;
    --text-muted: #666;
    --color-blue: #4A90E2;
    --color-pink: #FF69B4;
    --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 15px 45px rgba(0, 0, 0, 0.2);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Montserrat', 'Segoe UI', Tahoma, sans-serif;
    background: var(--primary-gradient);
    min-height: 100vh;
    padding: 40px 20px;
    color: var(--text-main);
}

/* --- Botões de Ação --- */
.botoes-acao {
    display: flex;
    justify-content: center;
    margin-bottom: 40px;
}

.btn-acao {
    padding: 12px 30px;
    border: none;
    background: var(--card-bg);
    color: #667eea;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-acao:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    background: var(--text-main);
    color: var(--card-bg);
}

/* --- Layout Principal --- */
.main-container {
    display: flex;
    gap: 40px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    max-width: 1400px;
    margin: 0 auto;
}

.aluno-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    flex: 1;
    min-width: 350px; /* Garante que não fique muito espremido */
    max-width: 600px;
}

/* --- Wrapper dos Controles (Formulário + Sliders) --- */
.wrapper {
    display: flex;
    gap: 20px;
    width: 100%;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap; /* Permite que os sliders caiam pra baixo em telas menores */
}

/* Cards (Formulário e Controles) */
.container, .controles-foto {
    background: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s ease;
}

.container:hover, .controles-foto:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.container {
    flex: 2;
    min-width: 280px;
}

.controles-foto {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    border: 1px solid #eee;
}

/* --- Tipografia --- */
h1 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-main);
    text-align: center;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
}

h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-align: center;
}

/* --- Formulários --- */
.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.textbox, .file-input {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s;
    outline: none;
}

.textbox:focus {
    border-color: #667eea;
}

/* Estilo do Input File */
.file-input {
    padding: 5px;
    background: #f9f9f9;
}

.file-input::file-selector-button {
    padding: 8px 12px;
    border: none;
    background: var(--text-muted);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    margin-right: 10px;
    transition: background 0.3s;
}

.file-input::file-selector-button:hover {
    background: #667eea;
}

/* --- Toggles de Gênero (Input Radio Escondido + Label Estilizado) --- */
.nome-toggle-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.nome-toggle-wrapper > .form-group:first-child {
    flex: 1; /* O input de texto ocupa o espaço restante */
}

.toggle-wrapper {
    flex-shrink: 0; /* Impede que os botões sejam comprimidos */
    width: auto; /* Ocupa apenas o necessário */
    margin-bottom: 0; /* Remove margem inferior */
}

.toggle-group {
    display: flex;
    gap: 5px;
    padding-bottom: 0; /* Remove padding para alinhar com o input */
    height: 70px; /* Mesma altura do input (10px padding top + 10px padding bottom + linha) */
    align-items: center;
}

.toggle-label {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border-radius: 8px;
    cursor: pointer;
    color: #ccc;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1.2rem;
}

.toggle-label:hover {
    background: #e0e0e0;
}

/* Lógica de Cores com :has() */
/* Masculino Selecionado -> Azul */
.toggle-label:has(input[value="aluno"]:checked),
.toggle-label:has(input[value="masculino"]:checked) {
    background: var(--color-blue);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.4);
}

/* Feminino Selecionado -> Rosa */
.toggle-label:has(input[value="aluna"]:checked),
.toggle-label:has(input[value="feminino"]:checked) {
    background: var(--color-pink);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(255, 105, 180, 0.4);
}

/* --- Sliders --- */
.slider-item {
    margin-bottom: 5px;
}

.slider-control {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 5px;
    outline: none;
}

.slider-control::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* --- Canvas Preview --- */
.preview-container {
    width: 100%;
    display: flex;
    justify-content: center;
    position: relative;
}

canvas {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    background: white; /* Garante fundo branco se a imagem demorar */
}

/* --- Responsividade --- */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        align-items: center;
    }
    
    .aluno-section {
        width: 100%;
        border-bottom: 1px solid rgba(255,255,255,0.3);
        padding-bottom: 40px;
    }

    .wrapper {
        flex-direction: column;
    }
    
    .container, .controles-foto {
        width: 100%;
    }
}

/* --- Estilos de Impressão (CRUCIAL) --- */
@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }
    
    body {
        background: white;
        padding: 0;
        margin: 0;
    }

    /* Esconde apenas controles */
    .wrapper,
    .botoes-acao {
        display: none !important;
    }

    /* Mantém o container principal mas remove flex wrap */
    .main-container {
        display: block !important;
        max-width: none !important;
        margin: 0;
        padding: 0;
        gap: 0;
    }

    /* Cada aluno em uma página separada e centralizada */
    .aluno-section {
        display: flex !important;
        width: 100vw;
        height: 100vh;
        page-break-after: always;
        page-break-inside: avoid;
        align-items: center;
        justify-content: center;
        margin: 0;
        padding: 0;
        border: none;
        min-width: auto;
        max-width: none;
    }

    .aluno-section:last-child {
        page-break-after: auto;
    }

    .preview-container {
        display: flex !important;
        width: 90%;
        height: 90%;
        align-items: center;
        justify-content: center;
        box-shadow: none;
    }

    canvas {
        max-width: 100% !important;
        max-height: 100% !important;
        width: auto !important;
        height: auto !important;
        box-shadow: none !important;
        border-radius: 0;
        image-rendering: -webkit-optimize-contrast;
    }
}