/* Generador Herramientas Inicial - Estilos */
:root {
    --primary: #059669;
    --primary-dark: #047857;
    --bg: #f0fdf4;
    --card: #fff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #d1d5db;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 16px;
    opacity: 0;
    animation: generadorFadeIn 0.35s ease forwards;
}
@keyframes generadorFadeIn {
    to { opacity: 1; }
}
.app { max-width: 900px; margin: 0 auto; }

.header {
    text-align: center;
    margin-bottom: 28px;
}
.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin: 0 0 8px 0;
}
.subtitle { color: var(--text-muted); font-size: 0.95rem; margin: 0; }

.steps-wrapper { position: relative; min-height: 280px; }
.step {
    transition: opacity 0.35s ease;
}
.step.step-visible {
    opacity: 1;
    visibility: visible;
    position: relative;
}
.step.step-hidden {
    opacity: 0;
    visibility: hidden;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    pointer-events: none;
}
.step h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--text);
}

/* Tarjetas de herramienta */
.tool-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.tool-card {
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
/* Oculto mientras IA imágenes/historietas esté desactivada en script.js */
.tool-card.tool-card--ia-pausada {
    display: none !important;
}

.tool-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 20px rgba(5, 150, 105, 0.15);
    transform: translateY(-2px);
}
.tool-emoji { font-size: 2.5rem; }
.tool-name { font-weight: 600; font-size: 1rem; }
.tool-desc { font-size: 0.8rem; color: var(--text-muted); }

/* Aviso en desarrollo */
.dev-notice {
    margin: 24px 0 0;
    padding: 12px 16px;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
}

/* Opciones */
.options-step .opciones-panel {
    background: var(--card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.options-step label {
    display: block;
    font-weight: 500;
    margin: 12px 0 6px 0;
    font-size: 0.9rem;
}
.options-step select,
.options-step textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
}
.options-step textarea { resize: vertical; min-height: 80px; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
    font-weight: normal;
    cursor: pointer;
}
.hint { font-size: 0.85rem; color: var(--text-muted); margin: 8px 0 0 0; }

.btn-back {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 16px;
    padding: 0;
}
.btn-back:hover { text-decoration: underline; }

.btn-generate,
.btn-download {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 12px;
    transition: background 0.2s;
}
.btn-generate:hover,
.btn-download:hover { background: var(--primary-dark); }
.btn-download { background: #2563eb; margin-left: 0; }
.btn-download:hover { background: #1d4ed8; }

.preview-actions {
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.preview-area {
    background: #ffffff !important;
    border-radius: 12px;
    padding: 24px;
    min-height: 300px;
    border: 1px solid var(--border);
    animation: fadeIn 0.25s ease;
}
/* Contenedor imagen colorear: fondo blanco puro para vista y PDF */
.preview-area .colorear-container.colorear-ia-result {
    background: #ffffff !important;
}

/* Sopa de letras - cuadrícula */
.sopa-container { text-align: center; }
.sopa-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.sopa-grid {
    display: inline-grid;
    gap: 0;
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin: 16px 0;
}
.sopa-cell {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e5e7eb;
    text-transform: uppercase;
}
.sopa-palabras {
    margin-top: 20px;
    text-align: left;
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    justify-content: center;
}
.sopa-palabra-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
}

/* Relacionar */
.relacionar-container { padding: 12px 0; page-break-inside: avoid; }
.relacionar-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 12px; text-align: center; }
.relacionar-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 6px 16px;
    align-items: center;
    max-width: 380px;
    margin: 0 auto;
}
.relacionar-emoji { font-size: 1.75rem; text-align: center; }
.relacionar-linea { width: 36px; height: 2px; background: #ccc; }
.relacionar-palabra { font-size: 0.95rem; text-align: left; }

/* Colorear */
.colorear-container { padding: 16px 0; }
.colorear-title { font-size: 1rem; font-weight: 700; margin-bottom: 16px; text-align: center; }
.colorear-grid {
    display: grid;
    gap: 20px;
    justify-content: center;
    margin: 0 auto;
}
.colorear-item {
    text-align: center;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: 12px;
}
.colorear-emoji { font-size: 4rem; display: block; margin-bottom: 8px; }

/* Generar con IA (pago por consumo) */
.colorear-ia-block {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.colorear-ia-block hr { border: none; margin: 0; }
.colorear-ia-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0 0 6px 0;
    color: var(--text);
}
.colorear-ia-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 10px 0;
}
.colorear-ia-block input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    margin-bottom: 10px;
}
.btn-ia-generate {
    background: #7c3aed;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-ia-generate:hover { background: #6d28d9; }
.btn-ia-generate:disabled { opacity: 0.7; cursor: not-allowed; }
.colorear-ia-status {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 8px 0 0 0;
    min-height: 1.2em;
}
.colorear-ia-image-wrap {
    text-align: center;
    margin-top: 12px;
}
.colorear-ia-img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
/* Imagen IA: cabe en 1 hoja A4, blanco y negro, fondo blanco */
.colorear-ia-a4-wrap {
    width: 165mm;
    max-width: 100%;
    margin: 0 auto;
    text-align: center;
    padding: 4px 0;
    page-break-inside: avoid;
    background: #ffffff !important;
}
.colorear-ia-result {
    max-height: 270mm;
    overflow: hidden;
    background: #ffffff !important;
}
.colorear-ia-img-a4 {
    width: 100%;
    max-width: 165mm;
    height: auto;
    display: block;
    margin: 0 auto;
    background: #ffffff !important;
    /* La imagen ya viene procesada con líneas negras desde JS */
    image-rendering: crisp-edges;
}

/* Barra de progreso historietas */
.historietas-progress {
    margin: 16px 0;
    padding: 16px;
    background: #f0fdf4;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.historietas-progress-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
    position: relative;
}
.historietas-progress-fill {
    position: absolute;
    left: 0;
    height: 100%;
    width: 35%;
    background: linear-gradient(90deg, var(--primary), #34d399);
    border-radius: 4px;
    animation: historietas-progress-move 1.5s ease-in-out infinite;
}
@keyframes historietas-progress-move {
    0% { left: 0; }
    50% { left: 65%; }
    100% { left: 0; }
}
.historietas-progress-text {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    text-align: center;
}

/* Historietas */
.historietas-container { padding: 16px 0; }
.historietas-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; text-align: center; }
.historietas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    max-width: 900px;
    margin: 0 auto;
}
.historieta-panel {
    border: 2px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}
.historieta-img-wrap { padding: 8px; background: #f9fafb; }
.historieta-img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}
.historieta-dialogo {
    padding: 10px 12px;
    font-size: 0.9rem;
    text-align: center;
    background: #fffbeb;
    border-top: 1px solid var(--border);
    font-style: italic;
}

/* Impresión */
@media print {
    body { background: white; padding: 0; }
    .header, .btn-back, .preview-actions, .step:not(.preview-step) { display: none !important; }
    .preview-step { display: block !important; }
    .preview-area { border: none; box-shadow: none; padding: 16px; }
    .sopa-cell { width: 24px; height: 24px; font-size: 0.9rem; }
    .historietas-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
    .historieta-panel { break-inside: avoid; }
}

@media (max-width: 600px) {
    .tool-cards { grid-template-columns: 1fr; }
    .preview-actions { flex-direction: column; }
}
