/* ============================================================
   ÉRASE YO — Estilos Mobile-First
   Fuente: Nunito | Diseñado para 390px primero
   ============================================================ */

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

html { font-size: 16px; }

body {
    font-family: 'Nunito', sans-serif;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }

/* ============================================================
   VARIABLES DE COLOR
   ============================================================ */
:root {
    --purple-start: #6C63FF;
    --purple-end:   #A855F7;
    --orange-start: #FF6B6B;
    --orange-end:   #FF8E53;
    --teal-start:   #00C9A7;
    --teal-end:     #00B4D8;
    --dark-bg:      #1a1a2e;
    --dark-card:    #16213e;
    --dark-accent:  #A855F7;
    --text-dark:    #1a1a2e;
    --text-muted:   #6b7280;
    --white:        #ffffff;
    --radius:       16px;
    --shadow:       0 4px 20px rgba(0,0,0,0.12);
}

/* ============================================================
   UTILIDADES
   ============================================================ */
.alerta {
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 20px;
    line-height: 1.4;
}
.alerta-error { background: #fee2e2; color: #b91c1c; }
.alerta-info  { background: #ede9fe; color: #5b21b6; }

/* ============================================================
   PÁGINA: BIENVENIDA (index.php)
   ============================================================ */
.page-bienvenida {
    background: linear-gradient(160deg, #5B54E8 0%, #8B3CF7 60%, #A855F7 100%);
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 40px 24px;
    position: relative; overflow: hidden;
}
.page-bienvenida::before {
    content: '';
    position: absolute; top: -80px; right: -80px;
    width: 300px; height: 300px;
    background: rgba(255,255,255,0.06);
    border-radius: 50%;
}
.page-bienvenida::after {
    content: '';
    position: absolute; bottom: -60px; left: -60px;
    width: 220px; height: 220px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
}

.bienvenida-container {
    width: 100%; max-width: 420px;
    position: relative; z-index: 1;
}

/* Hero */
.bienvenida-hero { display: flex; flex-direction: column; gap: 28px; }

.hero-logo {
    display: flex; align-items: center; gap: 14px;
}
.hero-libro { font-size: 3rem; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2)); }
.logo-titulo { font-size: 2.4rem; font-weight: 900; color: var(--white); line-height: 1; }
.logo-tagline { font-size: 1rem; color: rgba(255,255,255,0.8); font-weight: 600; margin-top: 3px; }

/* Preview card */
.hero-preview { position: relative; }
.preview-card {
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 20px;
    padding: 20px;
}
.preview-pagina {
    display: flex; gap: 14px; align-items: flex-start;
}
.preview-img {
    font-size: 3.5rem;
    background: rgba(255,255,255,0.15);
    border-radius: 14px;
    width: 80px; height: 80px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.preview-texto {
    font-size: 0.95rem; font-weight: 600;
    color: var(--white); line-height: 1.5;
    padding-top: 8px;
}
.preview-texto strong { font-weight: 900; }
.preview-dots {
    display: flex; gap: 6px; justify-content: center; margin-top: 14px;
}
.dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: rgba(255,255,255,0.3);
}
.dot.activo { background: var(--white); width: 20px; border-radius: 4px; }

.preview-badge {
    position: absolute; top: -10px; right: 16px;
    background: #FFD700;
    color: #1a1a2e; font-size: 0.78rem; font-weight: 800;
    padding: 5px 12px; border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Features */
.hero-features {
    display: flex; gap: 8px;
}
.feature {
    flex: 1;
    background: rgba(255,255,255,0.12);
    border-radius: 14px; padding: 12px 8px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.15);
}
.feature span { font-size: 1.4rem; display: block; margin-bottom: 5px; }
.feature p { font-size: 0.75rem; font-weight: 700; color: rgba(255,255,255,0.9); line-height: 1.3; }

/* Acciones */
.hero-acciones { display: flex; flex-direction: column; gap: 14px; }

/* Login en index */
.login-wrap { display: flex; flex-direction: column; gap: 24px; }
.login-header {
    display: flex; align-items: center; gap: 16px;
}
.btn-volver-blanco {
    background: rgba(255,255,255,0.2);
    color: var(--white); font-size: 1.3rem; font-weight: 700;
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.login-logo { font-size: 1.1rem; font-weight: 900; color: var(--white); }

.bienvenida-acciones {
    display: flex; flex-direction: column; gap: 16px; align-items: center;
}

/* ============================================================
   BOTONES GLOBALES
   ============================================================ */
.btn-principal {
    display: block; width: 100%;
    background: var(--white);
    color: var(--purple-start);
    font-family: 'Nunito', sans-serif;
    font-size: 1.1rem; font-weight: 800;
    padding: 16px 24px;
    border-radius: 14px;
    border: none; cursor: pointer;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-principal:active { transform: scale(0.97); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }

.page-registro .btn-principal,
.page-perfil .btn-principal {
    background: linear-gradient(135deg, var(--orange-start), var(--orange-end));
    color: var(--white);
}
.page-home .btn-principal,
.page-visor .btn-principal {
    background: linear-gradient(135deg, var(--purple-start), var(--purple-end));
    color: var(--white);
}

.link-secundario {
    color: rgba(255,255,255,0.9);
    font-size: 0.95rem; font-weight: 600;
    text-align: center; display: block;
}
.link-secundario:hover { color: var(--white); }

/* ============================================================
   FORMULARIOS (registro, perfil, login)
   ============================================================ */
.page-registro {
    background: linear-gradient(145deg, var(--orange-start), var(--orange-end));
    min-height: 100vh; padding: 24px 20px;
}
.page-perfil {
    background: linear-gradient(145deg, var(--orange-start), var(--orange-end));
    min-height: 100vh; padding: 24px 20px;
}

.form-container { max-width: 420px; margin: 0 auto; }

.form-header {
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 28px; position: relative;
}

.btn-volver {
    position: absolute; left: 0;
    background: rgba(255,255,255,0.3);
    color: var(--white);
    font-size: 1.4rem; font-weight: 700;
    width: 44px; height: 44px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
}

.pasos-indicator {
    display: flex; align-items: center; gap: 8px;
}
.paso {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,0.3);
    color: var(--white); font-weight: 800; font-size: 0.9rem;
    display: flex; align-items: center; justify-content: center;
}
.paso.activo { background: var(--white); color: var(--orange-start); }
.paso.completado { background: rgba(255,255,255,0.9); color: var(--orange-start); }
.paso-linea {
    width: 40px; height: 3px;
    background: rgba(255,255,255,0.3); border-radius: 2px;
}
.paso-linea.activa { background: var(--white); }

.form-titulo-wrap { margin-bottom: 24px; }
.form-titulo { font-size: 1.8rem; font-weight: 900; color: var(--white); }
.form-subtitulo { font-size: 0.95rem; color: rgba(255,255,255,0.8); font-weight: 600; margin-top: 4px; }

.form-card {
    background: var(--white);
    border-radius: 20px;
    padding: 24px 20px;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 18px;
}

.campo-grupo { display: flex; flex-direction: column; gap: 6px; }
.campo-grupo label {
    font-size: 0.9rem; font-weight: 700;
    color: var(--text-dark);
}
.campo-grupo input,
.campo-grupo select {
    width: 100%; padding: 14px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 1rem; font-weight: 600;
    color: var(--text-dark);
    background: #f9fafb;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}
.campo-grupo input:focus,
.campo-grupo select:focus {
    outline: none; border-color: var(--orange-start);
    background: var(--white);
}
.select-edad {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 44px;
    cursor: pointer;
}
.campo-ayuda { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; }

.form-footer-link {
    text-align: center; margin-top: 20px;
    font-size: 0.9rem; font-weight: 600;
    color: rgba(255,255,255,0.85);
}
.form-footer-link a { color: var(--white); font-weight: 800; }

/* Login embebido en index */
.login-form-wrap {
    background: var(--white);
    border-radius: 20px;
    padding: 24px 20px;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 18px;
}
.login-form-wrap .form-titulo {
    font-size: 1.5rem; font-weight: 900;
    color: var(--text-dark);
}
.login-form-wrap form { display: flex; flex-direction: column; gap: 16px; }
.login-form-wrap .btn-principal {
    background: linear-gradient(135deg, var(--purple-start), var(--purple-end));
    color: var(--white);
}
.login-form-wrap .campo-grupo label { color: var(--text-dark); }

/* ============================================================
   PÁGINA: HOME
   ============================================================ */
.page-home {
    background: #f0fdfa;
    min-height: 100vh;
}

.home-header {
    background: linear-gradient(135deg, var(--teal-start), var(--teal-end));
    padding: 16px 20px;
    display: flex; align-items: center; justify-content: space-between;
}
.header-logo { font-size: 1.2rem; font-weight: 900; color: var(--white); }
.btn-logout {
    background: rgba(255,255,255,0.2);
    color: var(--white); font-size: 0.85rem; font-weight: 700;
    padding: 8px 16px; border-radius: 10px;
}

.home-main { padding: 24px 20px; max-width: 600px; margin: 0 auto; }

.saludo-wrap { margin-bottom: 24px; }
.saludo { font-size: 1.6rem; font-weight: 900; color: var(--text-dark); }
.saludo-sub { font-size: 1.1rem; color: var(--text-muted); font-weight: 600; margin-top: 4px; }

.crear-form { display: flex; flex-direction: column; gap: 24px; }

.seccion-selector { display: flex; flex-direction: column; gap: 12px; }
.selector-titulo {
    font-size: 1.1rem; font-weight: 800; color: var(--text-dark);
}
.leccion-categoria {
    font-size: 0.85rem; font-weight: 700; color: var(--text-muted);
    margin-top: 8px; margin-bottom: 4px;
}

.chips-grid {
    display: flex; flex-wrap: wrap; gap: 8px;
}
.chip { cursor: pointer; }
.chip input[type="radio"] { display: none; }
.chip span {
    display: inline-block;
    padding: 10px 16px;
    border-radius: 50px;
    background: var(--white);
    border: 2px solid #e5e7eb;
    font-size: 0.9rem; font-weight: 700;
    color: var(--text-dark);
    transition: all 0.15s;
    white-space: nowrap;
}
.chip input:checked + span {
    background: linear-gradient(135deg, var(--teal-start), var(--teal-end));
    border-color: transparent;
    color: var(--white);
    transform: scale(1.03);
}

.crear-btn-wrap { padding: 8px 0 16px; }
.btn-crear {
    display: block; width: 100%;
    background: linear-gradient(135deg, var(--teal-start), var(--teal-end));
    color: var(--white);
    font-family: 'Nunito', sans-serif;
    font-size: 1.15rem; font-weight: 900;
    padding: 18px 24px;
    border-radius: 16px; border: none; cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,201,167,0.4);
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-crear:active { transform: scale(0.97); }
.btn-crear:disabled { opacity: 0.6; cursor: wait; }

.limite-card {
    background: var(--white);
    border-radius: 20px; padding: 32px 24px;
    text-align: center; box-shadow: var(--shadow);
    margin-bottom: 24px;
}
.limite-emoji { font-size: 3rem; display: block; margin-bottom: 12px; }
.limite-card p { font-size: 1.05rem; font-weight: 700; color: var(--text-dark); }
.limite-sub { color: var(--text-muted) !important; font-size: 0.9rem !important; margin-top: 6px; }

/* Biblioteca */
.biblioteca { margin-top: 32px; }
.biblioteca-titulo {
    font-size: 1.2rem; font-weight: 800; color: var(--text-dark);
    margin-bottom: 16px;
}
.cuentos-grid { display: flex; flex-direction: column; gap: 14px; }
.cuento-card {
    background: var(--white);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    transition: transform 0.15s;
}
.cuento-card:active { transform: scale(0.98); }
.cuento-portada { width: 90px; flex-shrink: 0; }
.cuento-portada img { width: 90px; height: 90px; object-fit: cover; }
.cuento-info {
    padding: 12px 14px;
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
}
.cuento-info h3 { font-size: 0.95rem; font-weight: 800; color: var(--text-dark); line-height: 1.3; }
.cuento-info p { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.cuento-fecha { font-size: 0.78rem; color: #9ca3af; font-weight: 600; }

/* ============================================================
   PÁGINA: LOADER
   ============================================================ */
.page-loader {
    background: linear-gradient(145deg, var(--dark-bg), #0f3460);
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
}

.loader-container {
    text-align: center; padding: 32px 24px;
    max-width: 380px; width: 100%;
}

.loader-animacion {
    position: relative; height: 120px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 32px;
}
.libro-animado {
    font-size: 5rem;
    animation: pulso 1.5s ease-in-out infinite;
}
.estrellitas {
    position: absolute; top: 0; right: 60px;
    font-size: 1.5rem;
    animation: orbita 2s linear infinite;
}

@keyframes pulso {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes orbita {
    0%   { transform: rotate(0deg) translateX(30px) rotate(0deg); opacity: 1; }
    50%  { opacity: 0.4; }
    100% { transform: rotate(360deg) translateX(30px) rotate(-360deg); opacity: 1; }
}

.loader-frases { min-height: 60px; margin-bottom: 32px; }
.frase {
    font-size: 1.15rem; font-weight: 700; color: var(--white);
    opacity: 0; transition: opacity 0.5s;
    position: absolute; width: 100%; left: 0;
}
.frase.activa { opacity: 1; position: relative; }
.loader-frases { position: relative; }

.loader-barra {
    background: rgba(255,255,255,0.15);
    border-radius: 10px; height: 6px; overflow: hidden;
}
.loader-progreso {
    height: 100%;
    background: linear-gradient(90deg, var(--teal-start), var(--purple-end));
    border-radius: 10px;
    animation: carga 30s linear forwards;
}
@keyframes carga {
    0%   { width: 0%; }
    80%  { width: 85%; }
    100% { width: 95%; }
}

/* ============================================================
   PÁGINA: VISOR DE CUENTO
   ============================================================ */
.page-visor {
    background: var(--dark-bg);
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
}

.visor-container {
    position: relative;
    width: 100%; max-width: 500px;
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
}

.visor-progreso {
    position: fixed; top: 0; left: 50%; transform: translateX(-50%);
    display: flex; gap: 8px;
    padding: 16px 20px;
    z-index: 10;
    width: 100%; max-width: 500px;
    justify-content: center;
}
.progreso-punto {
    flex: 1; max-width: 50px; height: 4px;
    background: rgba(255,255,255,0.25); border-radius: 2px;
    transition: background 0.3s;
}
.progreso-punto.activo { background: var(--white); }

.pagina {
    display: none; flex-direction: column;
    width: 100%; min-height: 100vh;
    padding-top: 52px;
}
.pagina.activa { display: flex; }

.pagina-imagen {
    flex: 0 0 60vh;
    overflow: hidden;
}
.pagina-imagen img {
    width: 100%; height: 60vh;
    object-fit: cover;
}

.pagina-texto {
    flex: 1;
    background: var(--dark-card);
    padding: 24px 20px;
    display: flex; align-items: center;
}
.pagina-texto p {
    font-size: 1.15rem; font-weight: 700; line-height: 1.6;
    color: var(--white);
}

.pagina-numero {
    position: absolute; bottom: 80px; right: 20px;
    font-size: 0.8rem; color: rgba(255,255,255,0.4); font-weight: 700;
}

.visor-nav {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 500px;
    display: flex; justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(transparent, var(--dark-bg));
}
.nav-btn {
    background: rgba(255,255,255,0.1);
    border: none; cursor: pointer;
    color: var(--white); font-size: 2rem;
    width: 54px; height: 54px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, opacity 0.15s;
}
.nav-btn:active { background: rgba(255,255,255,0.25); }

/* Pantalla fin */
.pagina-fin .fin-contenido {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 100vh; padding: 32px 24px;
    text-align: center; gap: 16px;
}
.fin-emoji { font-size: 4rem; }
.pagina-fin h2 {
    font-size: 1.6rem; font-weight: 900; color: var(--white); line-height: 1.3;
}
.fin-sub { font-size: 1rem; color: rgba(255,255,255,0.7); font-weight: 600; }
.pagina-fin .btn-principal {
    margin-top: 8px;
    background: linear-gradient(135deg, var(--teal-start), var(--purple-end));
    color: var(--white); max-width: 300px;
}

/* ============================================================
   DESKTOP (min 640px)
   ============================================================ */
@media (min-width: 640px) {
    .form-card { padding: 32px 28px; }
    .home-main { padding: 32px 24px; }
    .saludo { font-size: 2rem; }
    .chips-grid { gap: 10px; }
    .chip span { padding: 12px 20px; font-size: 0.95rem; }
    .btn-crear { font-size: 1.2rem; }
    .cuentos-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    .cuento-portada { width: 120px; }
    .cuento-portada img { width: 120px; height: 120px; }
}
