:root {
    --orange: #FF6B00; /* Naranja Explosivo */
    --blue: #2ECC71; /* Verde Radiactivo */
    --white: #FDFBF7; /* Blanco Crema */
    --gold: #E9B824; /* Dorado Pop */
    --green: #2ECC71;
    --ink: #000000; /* Negro Puro */
    --comic-yellow: #FDFBF7; /* Blanco Crema para áreas de lectura */
    
    --primary: var(--gold);
    --secondary: var(--blue);
    --surface: #0C0E0C; /* Negro Obsidiana (Fondo App) */
    --surface-container: #FDFBF7; /* Blanco Crema (Tarjetas) */
    --text: var(--ink);
    --text-dim: #333; /* Darkened per user request */
}

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

body {
    font-family: 'Poppins', sans-serif; /* Poppins para lectura, Luckiest Guy para títulos */
    background-color: var(--surface);
    /* Halftone pattern (oscurecido para fondo negro obsidiana) */
    background-image: radial-gradient(#111 15%, transparent 16%),
                      radial-gradient(#111 15%, transparent 16%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    color: var(--text);
    line-height: 1.6;
    overflow: hidden;
    font-size: 1.1rem;
}

/* Add a semi-transparent overlay to make text readable over the halftone */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(255, 248, 214, 0.95); /* comic-yellow with 95% opacity */
    z-index: -1;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Luckiest Guy', cursive;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
    color: var(--ink);
}

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

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--surface-container);
    border-right: 4px solid var(--ink);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: relative;
    z-index: 10;
    box-shadow: 6px 0 0 rgba(17, 17, 17, 0.1);
}

.sidebar-header {
    margin-bottom: 2rem;
    text-align: center;
}

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

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

.chapter-nav {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
}

.nav-label {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.2rem;
    letter-spacing: 2px;
    color: var(--ink);
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    border-bottom: 3px solid var(--ink);
    padding-bottom: 5px;
}

#chapter-list {
    list-style: none;
}

.chapter-item {
    padding: 1rem;
    background: var(--white);
    border: 2px solid var(--ink);
    border-radius: 0;
    margin-bottom: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 3px 3px 0 var(--ink);
    position: relative;
}

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

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

.chapter-item .chapter-prefix {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.1rem;
    display: block;
    color: var(--blue);
    margin-bottom: 4px;
    letter-spacing: 1px;
}

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

.chapter-item .chapter-title {
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Poppins', sans-serif;
}

/* Chapter Completed Style */
.chapter-item.completed {
    background: #EAFaf1;
    border-color: var(--blue); /* Now green */
}
.chapter-item.completed .chapter-prefix {
    color: var(--blue);
}

.btn-nav {
    width: 100%;
    padding: 1rem;
    border: 3px solid var(--ink);
    background: var(--white);
    color: var(--ink);
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.2rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 4px 4px 0 var(--ink);
    text-transform: uppercase;
}

.btn-nav.primary {
    background: var(--orange);
    color: var(--white);
    text-shadow: 2px 2px 0 var(--ink);
}

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

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

/* Main Content */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent;
    position: relative;
}

/* Progress Bar */
.progress-bar-container {
    height: 8px;
    background: var(--surface-container);
    border-bottom: 2px solid var(--ink);
    width: 100%;
    z-index: 4;
}

.progress-bar-fill {
    height: 100%;
    background: var(--blue); /* The new green */
    width: 0%;
    transition: width 0.4s ease-out;
}

.content-header {
    height: 80px;
    padding: 0 3rem;
    border-bottom: 4px solid var(--ink);
    background: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    z-index: 5;
}

.btn-menu {
    display: none; /* hidden on desktop */
    background: var(--white);
    border: 3px solid var(--ink);
    color: var(--ink);
    cursor: pointer;
    padding: 0.5rem;
    box-shadow: 3px 3px 0 var(--ink);
}

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

.chapter-title-display {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.4rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink);
}

.btn-action-icon {
    background: var(--white);
    color: var(--ink);
    border: 3px solid var(--ink);
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 3px 3px 0 var(--ink);
}

.btn-action-icon:hover {
    background: var(--gold);
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 var(--ink);
}

.btn-action-icon:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--ink);
}

.btn-action-icon.saving {
    animation: pulseComic 1s infinite;
    background: var(--green);
    color: var(--white);
}

@keyframes pulseComic {
    0% { transform: scale(1); }
    50% { transform: scale(1.1) rotate(5deg); }
    100% { transform: scale(1); }
}

.workbook-viewer {
    flex: 1;
    overflow-y: auto;
    padding: 4rem 15%;
}

.workbook-content {
    max-width: 800px;
    margin: 0 auto;
    background: var(--white);
    border: 4px solid var(--ink);
    box-shadow: 10px 10px 0 var(--ink);
    padding: 3rem;
    position: relative;
}

/* Add a comic folded corner effect */
.workbook-content::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    border-width: 0 40px 40px 0;
    border-style: solid;
    border-color: transparent var(--surface) transparent transparent;
}
.workbook-content::before {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    border-width: 0 40px 40px 0;
    border-style: solid;
    border-color: transparent var(--ink) transparent transparent;
    z-index: 1;
    transform: translate(-2px, 2px);
}


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

.welcome-screen h1 {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    color: var(--orange);
    text-shadow: 3px 3px 0 var(--ink);
    transform: rotate(-2deg);
}

.welcome-screen p {
    font-size: 1.2rem;
    font-weight: 700;
}

.info-card {
    background: var(--white);
    padding: 2rem;
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    margin-top: 3rem;
    position: relative;
}

.info-card h3 {
    color: var(--blue);
    font-size: 1.8rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 1px 1px 0 var(--ink);
}

/* Typography Overrides for generated content */
.workbook-content h1 {
    font-size: 2.5rem;
    color: var(--orange);
    text-shadow: 2px 2px 0 var(--ink);
    margin-bottom: 1.5rem;
    line-height: 1.1;
    font-family: 'Bangers', cursive;
    letter-spacing: 2px;
}

.workbook-content h2 {
    font-size: 1.8rem;
    color: var(--gold);
    text-shadow: 1px 1px 0 var(--ink);
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-family: 'Bangers', cursive;
    letter-spacing: 1px;
}

.workbook-content h3 {
    font-size: 1.5rem;
    color: var(--ink);
    font-family: 'Bangers', cursive;
}

.workbook-content p {
    font-size: 1.15rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
}

.workbook-content blockquote {
    font-family: 'Kalam', cursive;
    font-size: 1.5rem;
    background: var(--gold);
    padding: 1.5rem;
    border: 3px solid var(--ink);
    box-shadow: 5px 5px 0 var(--ink);
    margin: 2rem 0;
    transform: rotate(1deg);
}

.workbook-content .highlight {
    background: var(--white) !important;
    border: 3px solid var(--ink) !important;
    box-shadow: 5px 5px 0 var(--ink) !important;
    padding: 2.5rem 1.5rem 1.5rem 1.5rem !important; /* increased top padding to clear the flag */
    margin: 2.5rem 0 2rem 0 !important; /* added top margin to prevent flag hitting previous text */
    position: relative;
}
.workbook-content .highlight::before {
    content: '¡OJO!';
    position: absolute;
    top: -25px;
    left: -15px;
    background: var(--orange);
    color: var(--white);
    font-family: 'Bangers', cursive;
    padding: 5px 15px;
    border: 3px solid var(--ink);
    transform: rotate(-8deg);
    font-size: 1.5rem;
    text-shadow: 2px 2px 0 var(--ink);
    z-index: 5;
}

.workbook-content .warning-box {
    background: var(--comic-yellow) !important;
    border: 3px solid var(--ink) !important;
    box-shadow: 5px 5px 0 var(--ink) !important;
    padding: 1.5rem !important;
    margin: 2rem 0 !important;
}

/* Exercise Styling (Comic version) */
.exercise-box {
    background: var(--white);
    border: 4px solid var(--ink);
    box-shadow: 8px 8px 0 var(--ink);
    padding: 2rem;
    margin: 3rem 0;
    position: relative;
    display: none !important;
    gap: 1.5rem;
}

.exercise-box::before {
    content: '¡ACCIÓN!';
    position: absolute;
    top: -20px;
    right: -20px;
    background: var(--gold);
    color: var(--ink);
    font-family: 'Bangers', cursive;
    padding: 5px 20px;
    border: 3px solid var(--ink);
    transform: rotate(5deg);
    font-size: 1.8rem;
    box-shadow: 3px 3px 0 var(--ink);
}

.exercise-icon-container {
    width: 60px;
    height: 60px;
    background: var(--blue);
    border: 3px solid var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--white);
    flex-shrink: 0;
    box-shadow: 3px 3px 0 var(--ink);
}

.exercise-icon-container svg {
    stroke: var(--white);
    stroke-width: 2.5;
}

.exercise-tag {
    font-family: 'Bangers', cursive;
    font-size: 1.5rem;
    color: var(--orange);
    text-shadow: 1px 1px 0 var(--ink);
    display: block;
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}

.exercise-text {
    font-size: 1.1rem;
    font-weight: 700;
}

.workbook-trigger {
    color: var(--blue) !important;
    background: var(--gold);
    padding: 2px 8px;
    border: 2px solid var(--ink);
    border-radius: 4px;
    display: inline-block;
    transition: all 0.2s;
    text-decoration: none !important;
}

.workbook-trigger:hover {
    transform: scale(1.05) rotate(-2deg);
    box-shadow: 2px 2px 0 var(--ink);
}

/* Navigation Controls (Next / Prev) */
.nav-controls {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    gap: 1rem;
}

.btn-nav-comic {
    padding: 0.8rem 1.5rem;
    border: 3px solid var(--ink);
    background: var(--surface-container);
    color: var(--ink);
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.2rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 4px 4px 0 var(--ink);
    text-transform: uppercase;
    flex: 1;
    max-width: 250px;
}

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

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

.btn-nav-comic.primary {
    background: var(--orange);
    color: var(--white);
    text-shadow: 1px 1px 0 var(--ink);
}
.btn-nav-comic.primary:hover {
    background: #ff8533;
}

/* Formulas and Inputs */
.exercise-item {
    margin-bottom: 5rem;
    background: var(--white);
    border: 3px solid var(--ink);
    padding: 2rem;
    box-shadow: 6px 6px 0 var(--ink);
}

.exercise-main-label {
    display: block;
    color: var(--orange);
    font-family: 'Bangers', cursive;
    font-size: 2rem;
    text-shadow: 2px 2px 0 var(--ink);
    margin-bottom: 1.5rem;
    letter-spacing: 1px;
}

.calculation-table {
    background: var(--white);
    border: 3px solid var(--ink);
    border-radius: 0;
    overflow: hidden;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--surface-container);
    border-bottom: 3px solid var(--ink);
    z-index: 10;
}

.calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 2rem;
    border-bottom: 3px solid var(--ink);
}

.calc-row:last-child {
    border-bottom: none;
    background: var(--gold); 
}

.calc-row:last-child .field-label {
    color: var(--ink);
    font-weight: 700;
    font-size: 1.3rem;
    font-family: 'Bangers', cursive;
    letter-spacing: 1px;
}

.field-label {
    font-size: 1.1rem;
    color: var(--ink);
    font-weight: 700;
    flex: 1;
}

.input-wrapper {
    width: 200px;
}

.input-wrapper input {
    width: 100%;
    background: var(--white);
    border: 3px solid var(--ink);
    border-radius: 0;
    padding: 0.8rem;
    color: var(--blue);
    text-align: right;
    font-family: 'Kalam', cursive; 
    font-size: 1.5rem;
    font-weight: 700;
    outline: none;
    box-shadow: inset 2px 2px 0 rgba(0,0,0,0.1);
}

.input-wrapper input:focus {
    border-color: var(--orange);
    background: var(--comic-yellow);
}

.input-wrapper input[readonly] {
    background: transparent;
    border: none;
    color: var(--ink);
    box-shadow: none;
    font-size: 1.8rem;
}

.exercise-input {
    width: 100%;
    min-height: 120px;
    background: var(--white);
    border: 3px solid var(--ink);
    border-radius: 0;
    padding: 1rem;
    color: var(--blue);
    font-family: 'Kalam', cursive;
    font-size: 1.3rem;
    font-weight: 700;
    outline: none;
    resize: vertical;
    transition: all 0.2s;
    box-shadow: inset 3px 3px 0 rgba(0,0,0,0.05);
}

.exercise-input:focus {
    border-color: var(--orange);
    background: var(--comic-yellow);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 12px;
}
::-webkit-scrollbar-track {
    background: var(--white);
    border-left: 3px solid var(--ink);
}
::-webkit-scrollbar-thumb {
    background: var(--blue);
    border: 3px solid var(--ink);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--orange);
}

/* Index Cards */
.index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.index-card {
    background: var(--white);
    border: 3px solid var(--ink);
    padding: 1.5rem;
    cursor: pointer;
    box-shadow: 4px 4px 0 var(--ink);
    transition: all 0.2s;
}

.index-card:hover {
    transform: translate(-3px, -3px) rotate(-1deg);
    box-shadow: 7px 7px 0 var(--ink);
    background: var(--comic-yellow);
}

.index-card-title {
    display: flex;
    flex-direction: column;
}

.index-card .chapter-prefix {
    font-family: 'Bangers', cursive;
    font-size: 1.3rem;
    color: var(--orange);
    text-shadow: 1px 1px 0 var(--ink);
}

.index-card .chapter-desc {
    font-weight: 700;
    font-size: 1.1rem;
}

/* Mobile Responsive */
@media (max-width: 900px) {
    body {
        overflow: auto;
    }
    .app-container {
        flex-direction: column;
        height: auto;
    }
    .content-header {
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--surface-container);
        border-bottom: 3px solid var(--ink);
        height: auto;
        min-height: 60px;
        padding: 0.5rem 1rem;
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 10px;
    }
    .btn-menu {
        display: block;
        padding: 0;
    }
    .chapter-title-display {
        flex: 1;
        font-size: 1rem;
        line-height: 1.2;
    }
    .btn-action-icon {
        width: 38px;
        height: 38px;
    }
    .btn-action-icon svg {
        width: 18px;
        height: 18px;
    }
    
    /* Off-canvas sidebar */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 280px;
        height: 100vh;
        max-height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        padding: 2rem 1.5rem;
    }
    .sidebar.open {
        left: 0;
    }
    .sidebar-overlay.active {
        display: block;
    }
    
    .chapter-nav {
        max-height: none;
    }
    .content-area {
        min-height: 100vh;
    }
    .workbook-viewer {
        padding: 2rem 1rem;
        overflow-y: visible;
    }
    .workbook-content {
        padding: 1.5rem;
        border-width: 3px;
        box-shadow: 5px 5px 0 var(--ink);
    }
    .calc-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 1rem;
    }
    .input-wrapper, .calc-row input {
        width: 100% !important;
    }
    .exercise-box {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 1.5rem;
    }
    .exercise-box::before {
        font-size: 1.2rem;
        top: -15px;
        right: -10px;
    }
}

/* DESKTOP SIDEBAR TOGGLE OVERRIDES */
@media (min-width: 1200px) {
    .menu-toggle-btn {
        display: flex !important;
        background: transparent !important;
        border: none !important;
        color: var(--pure-black) !important;
        padding: 0 1rem 0 0 !important;
        font-size: 2rem !important;
    }
    
    .sidebar {
        transition: margin-left 0.3s ease, transform 0.3s ease !important;
    }
    
    .sidebar.collapsed {
        margin-left: -320px;
        transform: translateX(-100%);
    }
}
