/* --- 1. Top-Tier Variables & Reset --- */
:root {
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0, 0, 0, 0.05);
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.07);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.1);
    --anim-speed: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body {
    background: var(--bg-body);
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
    transition: all var(--anim-speed);
}

ul {
    list-style: none;
}

/* --- 2. Polished Header --- */
#header-container {
    min-height: 70px; /* Reserve space to prevent layout shift (CLS) */
    display: block;
}

/* Skeleton Loading State */
#header-container:empty {
    background-color: var(--glass-bg);
    background-image: 
        linear-gradient(rgba(0,0,0,0.05) 100%, transparent 0), /* Logo Placeholder */
        linear-gradient(rgba(0,0,0,0.05) 100%, transparent 0), /* Nav Placeholder */
        linear-gradient(90deg, transparent 0, rgba(255,255,255,0.8) 50%, transparent 100%); /* Shimmer */
    
    background-size: 
        120px 32px,
        200px 16px,
        200px 100%;
    
    background-position: 
        2rem center,
        calc(100% - 2rem) center,
        -200px 0;
    
    background-repeat: no-repeat;
    animation: header-skeleton 1.5s infinite linear;
    border-bottom: 1px solid var(--glass-border);
}

@keyframes header-skeleton {
    to {
        background-position: 
            2rem center,
            calc(100% - 2rem) center,
            calc(100% + 300px) 0;
    }
}

@media (max-width: 768px) {
    #header-container:empty {
        background-position: 
            1rem center,
            calc(100% - 1rem) center,
            -200px 0;
        animation-name: header-skeleton-mobile;
    }
    @keyframes header-skeleton-mobile {
        to {
            background-position: 1rem center, calc(100% - 1rem) center, calc(100% + 300px) 0;
        }
    }
}

header {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 0 1rem;
    height: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.03);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo .logo-symbol {
    font-size: 2rem;
    font-weight: 400;
}

.mobile-toggle {
    display: block;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-dark);
}

nav {
    display: none;
    position: absolute;
    top: 70px;
    left: 0;
    width: 100%;
    background: white;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

nav.active {
    display: block;
}

nav ul {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

nav a {
    font-weight: 500;
    font-size: 1rem;
    color: var(--text-light);
}

nav a:hover, nav a.active {
    color: var(--primary);
}


/* --- 3. Polished Hero Section --- */
.page-hero {
    text-align: center;
    padding: 1.5rem 5% 1rem;
    background: radial-gradient(circle at 50% 50%, rgba(142, 68, 173, 0.08), transparent 70%);
}

.breadcrumbs {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.breadcrumbs a:hover {
    color: var(--primary);
}

.breadcrumbs span {
    color: var(--accent);
    font-weight: 600;
    background: #fff8e1;
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid #ffe082;
}

.page-hero h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.25rem;
}

.page-hero p {
    font-size: 1rem;
    color: var(--text-light);
    max-width: 90%;
    margin: 0 auto;
}

/* --- 4. Polished Worksheet View --- */
.worksheet-view {
    max-width: 1000px;
    margin: 0 auto 4rem;
    padding: 2rem 5%;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
    text-align: center;
}

.worksheet-content {
    text-align: left;
    margin-bottom: 2rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.question-list {
    padding-left: 1.5rem;
    list-style-position: outside;
}

.question-list li {
    margin-bottom: 1.5rem;
    font-size: 1rem;
    color: var(--text-dark);
    word-wrap: break-word; /* Redundant due to parent, but for safety */
    overflow-wrap: break-word;
}

.question-list li::marker {
    font-weight: 600;
    color: var(--primary);
}


.question-list li strong {
    color: var(--primary);
    font-weight: 600;
    display: block;
    margin-bottom: 0.5rem;
}

.answer-box {
    margin-top: 0.75rem;
    padding: 1rem;
    background: var(--accent-purple-light);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text-dark);
    display: none;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow-x: auto;
}

.mcq-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 10px 0;
}

.mcq-options > div {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
}
.mcq-options > div:hover {
    background-color: var(--soft1, #f3e5f5);
    color: var(--primary);
    border-color: var(--primary);
}

@media (max-width: 500px) {
    .mcq-options {
        grid-template-columns: 1fr;
    }
}

.solution-toggle-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 6px 16px;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.solution-toggle-btn:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.answer-box strong {
    font-weight: 600;
    color: var(--primary);
}


/* --- 5. Polished Buttons --- */

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.nav-btn-back {
    display: inline-flex; align-items: center; gap: 10px; padding: 10px 24px;
    border-radius: 50px; font-weight: 600; font-size: 0.9rem;
    background: var(--bg-card, #ffffff) !important; color: var(--primary) !important; border: 1px solid var(--primary);
    box-shadow: var(--shadow-soft); transition: all 0.3s ease;
    -webkit-text-fill-color: var(--primary) !important;
}
.nav-btn-back:hover { background: var(--primary) !important; color: #ffffff !important; -webkit-text-fill-color: #ffffff !important; transform: translateX(-5px); box-shadow: var(--shadow-hover); }

.btn-download, .btn-share, .btn-toggle-answers, .ws-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    text-align: center;
    padding: 14px 20px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.btn-download {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(142, 68, 173, 0.2);
    /* Overrides for visibility */
    background: var(--bg-card, #ffffff) !important; border: 1px solid var(--primary); color: var(--primary) !important;
    -webkit-text-fill-color: var(--primary) !important;
    display: inline-flex;
    width: auto;
    margin-right: 10px; margin-bottom: 10px;
}

.btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(142, 68, 173, 0.3);
    background: var(--primary) !important; color: #ffffff !important; -webkit-text-fill-color: #ffffff !important;
}

.btn-share {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.2);
    /* Overrides */
    background: var(--bg-card, #ffffff) !important; border: 1px solid var(--primary); color: var(--primary) !important;
    -webkit-text-fill-color: var(--primary) !important;
    display: inline-flex;
    width: auto;
    margin-right: 10px; margin-bottom: 10px;
}

.btn-share:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(243, 156, 18, 0.3);
    background: var(--primary) !important; color: #ffffff !important; -webkit-text-fill-color: #ffffff !important;
}

.floating-actions {
    position: fixed; bottom: 30px; right: 30px; z-index: 100;
    display: flex; gap: 12px; align-items: center;
}

.btn-toggle-answers {
    position: static;
    width: auto;
    margin: 0;
    padding: 12px 24px; border-radius: 50px; font-weight: 600;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15); border: none;
    background: var(--primary); color: white; cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-toggle-answers:hover {
    background: var(--primary-dark); transform: scale(1.05);
}

.floating-dark-btn {
    width: 50px; height: 50px; border-radius: 50%; border: none;
    background: var(--text-dark); color: var(--bg-body);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15); cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
    transition: all 0.3s ease;
}
.floating-dark-btn:hover { transform: scale(1.1); }

.worksheet-nav-buttons {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    margin-top: 2rem;
}

.ws-nav-btn {
    font-size: 0.95rem;
    text-decoration: none; padding: 10px 24px; border-radius: 50px; font-weight: 600;
    background: var(--soft1); color: var(--primary); transition: all 0.3s;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    width: auto;
    flex: 1;
}

.prev-btn {
    /* Handled by ws-nav-btn */
}
.prev-btn:hover {
    background: var(--primary); color: white; transform: translateY(-2px); box-shadow: var(--shadow-soft);
}

.next-btn {
    /* Handled by ws-nav-btn */
}
.next-btn:hover {
    background: var(--primary); color: white; transform: translateY(-2px); box-shadow: var(--shadow-soft);
}

/* --- 6. Chapter List / Accordion Styles --- */
.nav-buttons-container {
    max-width: 900px;
    margin: 0 auto 1.5rem;
    padding: 0 1.5rem;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text-light);
    transition: color 0.2s;
}

.nav-btn:hover {
    color: var(--primary);
}

.chapter-container {
    max-width: 800px;
    margin: 0 auto 4rem;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chapter-item {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--glass-border);
    overflow: hidden;
    transition: all 0.3s ease;
}

.chapter-item:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.chapter-header {
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: white;
    transition: background 0.2s;
}

.chapter-header:hover {
    background: #f8f9fa;
}

.chap-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.chap-badge {
    background: var(--primary-light);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.chap-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-dark);
    margin-bottom: 0.2rem;
}

.chap-meta {
    font-size: 0.85rem;
    color: var(--text-light);
}

.toggle-icon {
    color: var(--text-light);
    transition: transform 0.3s ease;
}

.chapter-item.active .toggle-icon {
    transform: rotate(180deg);
    color: var(--primary);
}

.exercise-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: #f8f9fa;
    border-top: 1px solid var(--glass-border);
}

.exercise-grid {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.ex-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1rem;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    color: var(--text-dark);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.ex-btn i {
    color: var(--secondary);
}

.ex-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    transform: translateY(-2px);
}

/* --- 7. Tablet and Desktop Styles --- */
@media (min-width: 768px) {
    header {
        padding: 0 2rem;
    }

    .mobile-toggle {
        display: none;
    }

    nav {
        display: flex;
        position: static;
        width: auto;
        background: none;
        padding: 0;
        box-shadow: none;
    }

    nav ul {
        flex-direction: row;
        gap: 2.5rem;
    }

    .page-hero {
        padding: 2rem 2rem 1.5rem;
    }

    .page-hero h1 {
        font-size: 2.8rem;
    }

    .page-hero p {
        font-size: 1.1rem;
        max-width: 600px;
    }

    .worksheet-view {
        max-width: 800px;
        margin: 0 auto 5rem;
        padding: 3rem;
    }

    .btn-group {
        flex-direction: row;
        justify-content: center;
    }

    .btn-download, .btn-share {
        width: auto;
    }

    .btn-toggle-answers {
        bottom: 30px;
        left: 30px;
        right: auto;
        width: auto;
    }

    .worksheet-nav-buttons {
        flex-direction: row;
        justify-content: space-between;
    }

    .ws-nav-btn {
        flex: 0 0 auto;
    }
}
@media print {
    header, .page-hero, .nav-buttons-container, footer, .btn-toggle-answers, .btn-download, .btn-share, .worksheet-nav-buttons {
        display: none !important;
    }
    body {
        background: white;
        color: black;
    }
    .worksheet-view {
        box-shadow: none;
        border: none;
        margin: 0;
        padding: 0;
    }
    .worksheet-content {
        background: none;
        border: none;
        padding: 0;
    }
}

/* MathJax Responsive Fix */
mjx-container {
    max-width: 100%;
    overflow-x: auto;
}