:root {
    /* Variables CSS unificadas */
    --primary: #FF6B00;
    --primary-container: #FF6B00;
    --secondary: #151a20;
    
    --surface: #ffffff;
    --surface-container: #fdfdfd;
    --surface-container-high: #f0f0f0;
    --background: #faf8eb;
    
    --on-surface: #000000;
    --on-surface-variant: #333333;
    
    --pure-black: #000000;
    --pearl: #fbf9ec;
    
    /* Colores comic/neubrutalism */
    --ink: #000000;
    --gold: #E9B824;
    --green: #2ECC71;
    --orange: #FF6B00;
    --cream: #fbf9ec;
    
    /* Neubrutalism estilos */
    --radius-sm: 4px;
    --radius-md: 8px;
    --comic-border: 2px solid var(--pure-black);
    --comic-shadow: 4px 4px 0px var(--pure-black);
    --comic-shadow-hover: 2px 2px 0px var(--pure-black);
}

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

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--surface);
    color: var(--on-surface);
    line-height: 1.6;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 320px;
    background-color: var(--surface);
    border-right: 4px solid var(--ink);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: margin-left 0.3s ease, transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    background-color: var(--surface);
    display: flex;
    flex-direction: column;
    text-align: center;
}

.logo-text {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.8rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--orange);
    text-shadow: 2px 2px 0 var(--ink);
    margin-bottom: 0.5rem;
    transform: rotate(-3deg);
    line-height: 1;
}

.status-badge {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.1rem;
    letter-spacing: 2px;
    background: var(--gold);
    color: var(--ink);
    padding: 6px 12px;
    border: 2px solid var(--ink);
    box-shadow: 3px 3px 0 var(--ink);
    display: inline-block;
    transform: rotate(2deg);
    border-radius: 0;
}

.control-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: center;
    align-items: center;
}

.control-btn {
    background: #fff !important;
    color: var(--ink) !important;
    border: 2px solid var(--ink) !important;
    box-shadow: 2px 2px 0 var(--ink) !important;
    padding: 5px 10px !important;
    border-radius: 4px !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}

.control-btn:active {
    transform: scale(0.95);
}

.chapter-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0;
    background-color: transparent;
}

.chapter-nav ul {
    list-style: none;
    padding: 0 1.5rem;
}

.chapter-item {
    margin-bottom: 15px;
    padding: 1.25rem;
    cursor: pointer;
    background: #fff;
    border: 3px solid var(--ink);
    color: var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    border-radius: 0;
    transition: transform 0.1s, box-shadow 0.1s;
    font-size: 1rem;
    letter-spacing: 1px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
}

.chapter-item:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--ink);
}

.chapter-item.active {
    background: var(--gold);
    color: var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    transform: translate(-2px, -2px);
}

.chapter-title {
    font-size: 1rem;
    font-weight: 700;
    color: inherit;
    line-height: 1.4;
}

.chapter-prefix {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.2rem;
    letter-spacing: 1px;
    color: var(--orange);
    text-transform: uppercase;
    display: block;
    margin-bottom: 5px;
    font-weight: 900;
}

.chapter-item.active .chapter-prefix {
    color: var(--ink);
}

.chapter-desc {
    color: inherit;
    font-weight: 800;
    font-family: 'Montserrat', sans-serif;
}

.chapter-item.active .chapter-desc {
    color: var(--surface);
}

.chapter-item.bloque-header {
    background: var(--cream);
    border: 3px solid var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    color: var(--ink);
    text-transform: uppercase;
    font-weight: 800;
    border-radius: 4px;
}

/* BLOQUES no clickeables */
.chapter-item.no-clickeable {
    cursor: default !important;
    pointer-events: none !important;
    opacity: 0.8;
    background: var(--cream);
    color: #999;
}

.chapter-item.no-clickeable:hover {
    transform: none !important;
    box-shadow: 4px 4px 0 var(--ink) !important;
}

.chapter-item.no-clickeable .chapter-prefix {
    color: #999;
}

.sidebar-footer {
    padding: 1.5rem;
    background-color: transparent;
    border-top: 2px solid var(--ink);
}

.progress-label {
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
    color: var(--orange);
}

.progress-bar-bg {
    height: 12px;
    background-color: var(--surface);
    border: 2px solid var(--ink);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--ink);
    border-right: 2px solid var(--ink);
    transition: width 0.5s ease;
}

/* ===== CONTENT AREA ===== */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--surface);
    /* IMPORTANTE: padding-bottom para los botones fijos */
    padding-bottom: 80px;
}

.content-header {
    min-height: 80px;
    padding: 0 3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--surface-container);
    border-bottom: 2px solid var(--ink);
    position: sticky;
    top: 0;
    z-index: 100;
}

.menu-toggle-btn {
    display: none;
    background: var(--orange);
    border: 2px solid var(--ink);
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0px var(--ink);
    transition: transform 0.1s ease;
    font-size: 1.8rem;
    width: auto;
    height: auto;
    min-width: 44px;
    min-height: 44px;
}

.menu-toggle-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.chapter-title-display {
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
    font-size: 1.5rem;
    color: var(--orange);
    flex: 1;
    padding-right: 2rem;
}

/* ===== SPLIT LAYOUT ===== */
.split-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    gap: 0;
}

.image-viewer-container {
    flex: 0 0 50%;
    background-color: var(--surface);
    border-right: 2px solid var(--ink);
    overflow-y: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* IMPORTANTE: Ocultar el panel de imágenes en comic-mode */
.split-layout.comic-mode .image-viewer-container {
    display: none !important;
}

.text-panel {
    flex: 1;
    background-color: var(--surface);
    overflow-y: auto;
    padding: 2rem;
}

.content-body {
    max-width: 800px;
    margin: 0 auto;
}

/* ===== BOTONES NAVIGATION (CORREGIDO) ===== */
.header-actions {
    position: fixed;
    bottom: 15px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 3px solid var(--ink);
    padding: 15px;
    display: flex;
    justify-content: center;
    gap: 15px;
    z-index: 9999;
    box-sizing: border-box;
    /* IMPORTANTE: respeta safe areas en dispositivos con notch */
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    /* IMPORTANTE: No ocupa el sidebar - max-width y margin auto */
    max-width: calc(100% - 320px);
    margin-left: 320px;
}

.btn-nav {
    flex: 1;
    background: #fff;
    color: var(--ink);
    border: 3px solid var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    padding: 0.8rem 1rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    border-radius: 4px;
}

.btn-nav:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--ink);
}

.btn-nav:active {
    transform: scale(0.95);
}

.btn-nav.primary {
    background: var(--ink);
    color: #fff;
}

/* ===== WELCOME SCREEN ===== */
.welcome-article {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    padding: 2rem 0;
}

.welcome-content {
    text-align: center;
}

/* ===== WORKBOOK ===== */
.workbook-section {
    padding: 2rem;
}

.workbook-section.hidden {
    display: none;
}

.workbook-card {
    background: var(--surface);
    border: 3px solid var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    padding: 2rem;
    border-radius: 4px;
}

.workbook-content {
    min-height: 300px;
}

.workbook-footer {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--ink);
    text-align: center;
}

.btn-workbook {
    background: var(--green);
    color: var(--ink);
    border: 2px solid var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    padding: 1rem 2rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 4px;
    transition: transform 0.1s;
}

.btn-workbook:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--ink);
}

.save-note {
    font-size: 0.85rem;
    color: var(--on-surface-variant);
    margin-top: 1rem;
}

/* ===== FORMULAS ===== */
.formulas {
    font-size: 0.85rem;
    color: var(--on-surface-variant);
    background: var(--surface-container);
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    border: 1px solid #ddd;
}

/* ===== MODAL ALERTA ===== */
#comic-alert-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(12, 14, 12, 0.85);
    z-index: 10000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Poppins', sans-serif;
}

#comic-alert-modal[style*="display: flex"] {
    display: flex !important;
}

/* ===== RESPONSIVE ===== */

/* Tablets y dispositivos pequeños (900px - 1199px) */
@media (max-width: 1199px) {
    .content-area {
        padding-bottom: 80px;
    }
    
    .header-actions {
        max-width: calc(100% - 320px);
        margin-left: 320px;
    }
}

/* Tablets pequeños y móviles (hasta 900px) */
@media (max-width: 900px) {
    .app-container {
        display: flex;
        flex-direction: column;
        height: 100vh;
    }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        width: 280px;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .menu-toggle-btn {
        display: flex !important;
    }
    
    .content-area {
        flex: 1;
        padding-bottom: 100px;
        width: 100%;
        margin-left: 0 !important;
    }
    
    .split-layout {
        flex-direction: column;
    }
    
    .image-viewer-container {
        display: none !important;
    }
    
    .text-panel {
        width: 100%;
        padding: 1.5rem;
        padding-bottom: 4rem;
    }
    
    .content-header {
        padding: 0 1rem;
        min-height: 60px;
    }
    
    .chapter-title-display {
        font-size: 1.2rem;
        padding-right: 1rem;
    }
    
    /* Botones en móvil: ocupan TODO el ancho */
    .header-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100% !important;
        margin-left: 0 !important;
        padding: 12px;
        gap: 12px;
        flex-wrap: wrap;
        justify-content: center;
        background: var(--surface);
        border-top: 3px solid var(--ink);
        box-sizing: border-box;
    }
    
    .btn-nav {
        flex: 1;
        font-size: 0.9rem;
        padding: 1rem 0.8rem;
        min-width: 120px;
    }
    
    /* Welcome screen mobile */
    .welcome-article {
        min-height: auto;
        padding: 1rem;
    }
    
    .welcome-content {
        width: 100%;
    }
    
    /* Comic mode - full width */
    .split-layout.comic-mode .text-panel {
        width: 100%;
        padding: 1.5rem;
        padding-bottom: 4rem;
    }
}

/* Móviles muy pequeños (hasta 480px) */
@media (max-width: 480px) {
    .app-container {
        height: 100vh;
        width: 100vw;
    }
    
    .logo-text {
        font-size: 1.5rem;
    }
    
    .status-badge {
        font-size: 0.9rem;
        padding: 4px 8px;
    }
    
    .content-header {
        padding: 0 0.5rem;
        min-height: 50px;
    }
    
    .menu-toggle-btn {
        font-size: 1.4rem;
    }
    
    .chapter-title-display {
        font-size: 1rem;
        max-height: 60px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    
    .header-actions {
        padding: 10px;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        gap: 10px;
        justify-content: center;
    }
    
    .btn-nav {
        font-size: 0.85rem;
        padding: 0.9rem 0.6rem;
        min-width: 100px;
    }
    
    .text-panel {
        padding: 1rem;
        padding-bottom: 4rem;
    }
    
    .content-area {
        padding-bottom: 100px;
    }
}

/* ===== PRINT ===== */
@media print {
    .header-actions,
    .content-header,
    .sidebar,
    .sidebar-overlay {
        display: none !important;
    }
    
    .content-area {
        padding-bottom: 0;
        height: auto;
    }
    
    .split-layout {
        flex-direction: column;
    }
    
    h1, h2, h3, h4 {
        page-break-after: avoid;
        break-after: avoid;
    }
    
    .print-comic-chapter {
        page-break-inside: avoid;
        break-inside: avoid;
        margin-bottom: 2rem;
    }
}

/* ===== UTILIDADES ===== */
.hidden {
    display: none !important;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}
