/* --- Basic Reset & Smooth Scroll --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    /* Adjust scroll padding based on whether header is fixed or static */
    /* Default for fixed header */
     scroll-padding-top: 20px;
}

body {
    font-family: 'Lato', sans-serif;
    line-height: 1.7;
    background-color: #f8f9fa;
    color: #495057;
    /* Add padding-left ONLY for larger screens where sidebar is fixed */
    padding-left: 270px; /* Sidebar width + gap */
    position: relative; /* Needed for potential positioning contexts */
    min-height: 100vh; /* Ensure body takes full viewport height */
    display: flex; /* Use flexbox for layout */
    flex-direction: row; /* Default direction: sidebar left, content right */
}

/* --- Fixed Sidebar Menu --- */
.sidebar-menu {
    position: fixed; /* Stick to the viewport on larger screens */
    left: 0;
    top: 0;
    width: 250px; /* Width of the sidebar */
    height: 100vh; /* Full viewport height */
    background-color: #f1f3f5;
    border-right: 1px solid #dee2e6;
    padding: 25px 15px; /* Adjusted padding */
    overflow-y: auto; /* Allow sidebar to scroll if content is tall */
    z-index: 100; /* Keep it on top */
    flex-shrink: 0; /* Prevent sidebar from shrinking */
}

.sidebar-menu h3 {
    color: #343a40;
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.3em;
    border-bottom: 1px solid #ced4da;
    padding-bottom: 10px;
    font-weight: 700;
}

.sidebar-menu ul {
    list-style: none;
    padding-left: 0;
}

.sidebar-menu ul ul {
    padding-left: 15px; /* Indent sub-items */
    margin-top: 5px;
    margin-bottom: 5px;
}

.sidebar-menu li {
    margin-bottom: 8px;
}

.sidebar-menu a {
    text-decoration: none;
    color: #005ea2;
    display: block; /* Make the whole area clickable */
    padding: 4px 8px; /* Add some padding for easier clicking */
    border-radius: 4px;
    transition: color 0.2s ease, background-color 0.2s ease;
    font-size: 0.95em;
}

.sidebar-menu a:hover,
.sidebar-menu a:focus {
    color: #003c6b;
    background-color: #e9ecef; /* Highlight on hover/focus */
    text-decoration: none; /* Remove underline */
}

 /* --- Main Content Area --- */
.content-area {
    /* This element now handles the main flow */
    flex-grow: 1; /* Allow content area to take remaining space */
    /* Padding added inside the container */
     width: 100%; /* Needed for some flex contexts */
}

.container {
    /* Max-width applies within the content-area */
    max-width: 950px;
    margin: 0 auto; /* Center container within content-area */
    padding: 30px 25px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    min-height: 100%; /* Try to fill height */
}

/* --- Standard Content Styling (Mostly Unchanged) --- */
h1 {
    text-align: center;
    color: #2c3e50;
    border-bottom: 3px solid #e9ecef;
    padding-bottom: 15px;
    margin-bottom: 35px; /* Added margin */
    font-weight: 700;
    font-size: 2.2em;
}

h2 {
    color: #005ea2;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 8px;
    margin-top: 45px;
    margin-bottom: 25px;
    font-size: 1.8em;
    font-weight: 700;
}

h3 { /* Styles for h3 *inside* the content */
    color: #1a73e8;
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 1.4em;
    font-weight: 700;
}

h4 {
    color: #e13030f0;
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.15em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

p, div:not(.formula-block):not(.container):not(.content-area):not(.sidebar-menu) {
    margin-bottom: 15px;
    color: #343a40;
}

strong {
   font-weight: 700;
   color: #212529;
}

.formula-block {
    background-color: #eef2f7;
    border: 1px solid #d1d9e6;
    padding: 20px 25px;
    margin: 20px 0 25px 0;
    overflow-x: auto;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.3s ease-in-out;
}
.formula-block:hover { box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08); }
.formula-block p { margin-bottom: 10px; color: #3a3f44; }
.formula-block p:last-child { margin-bottom: 0; }
.formula-block em { color: #6c757d; font-size: 0.9em; display: block; margin-top: 10px; }

.MJX-SVG { display: block; margin: 15px 0; }
mjx-container[jax="SVG"] { text-align: left !important; overflow-x: auto; overflow-y: hidden; padding: 5px 0; }

/* --- Scroll-to-Top Button --- */
#scrollToTopBtn {
    display: none;
    opacity: 0;
    position: fixed;
    bottom: 25px;
    right: 30px;
    z-index: 999; /* Above sidebar (even when static) */
    border: none;
    outline: none;
    background-color: #0056b3;
    color: white;
    cursor: pointer;
    padding: 10px 15px;
    border-radius: 50%;
    font-size: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: opacity 0.3s ease-in-out, background-color 0.3s ease-in-out;
}
#scrollToTopBtn:hover { background-color: #003d82; }
#scrollToTopBtn.show { display: block; opacity: 1; }

/* --- Responsive Adjustments --- */
/* Breakpoint for tablets and larger phones where fixed sidebar becomes problematic */
@media (max-width: 992px) {
    html {
        /* Adjust scroll padding if menu becomes static */
        scroll-padding-top: 10px; /* Example, adjust as needed */
    }
    body {
        padding-left: 0; /* Remove body padding for fixed sidebar */
        flex-direction: column; /* Stack elements vertically */
    }

    .sidebar-menu {
        position: static; /* Change from fixed */
        width: 100%; /* Full width */
        height: auto; /* Natural height */
        border-right: none;
        border-bottom: 1px solid #dee2e6; /* Add border below */
        margin-bottom: 25px; /* Space below menu */
        z-index: auto; /* Reset z-index */
        overflow-y: visible; /* No separate scroll needed */
        /* Optional: Limit height and make scrollable if menu gets very long */
        /* max-height: 50vh; */
        /* overflow-y: auto; */
    }

    .content-area {
        /* No changes needed here usually, it will flow below */
        width: 100%; /* Ensure it takes full width */
    }

    .container {
         /* Adjust padding/margins if needed */
         padding: 20px 15px;
         margin: 0 auto; /* Keep centered horizontally */
         max-width: 100%; /* Allow container to use full width */
         border-radius: 0; /* Optional: remove radius on small screens */
         box-shadow: none; /* Optional: remove shadow on small screens */
         /* Ensure container starts below the menu */
    }

    /* Adjust heading margins for stacked layout */
    h1 { margin-bottom: 25px; font-size: 2em; }
    h2 { margin-top: 35px; font-size: 1.7em; }
    h3 { font-size: 1.35em; }
}

/* Breakpoint for smaller phones */
@media (max-width: 768px) {
    .container {
        padding: 15px 10px;
    }
     h1 { font-size: 1.8em; }
     h2 { font-size: 1.6em; margin-top: 30px; margin-bottom: 20px; }
     h3 { font-size: 1.3em; margin-top: 25px; margin-bottom: 12px; }
     h4 { font-size: 1.1em; margin-top: 18px; margin-bottom: 8px; }

    .formula-block { padding: 15px 18px; }

     /* Ensure MathJax formulas are scrollable if too wide */
     mjx-container[jax="SVG"] {
         max-width: 100%;
     }
}

 /* Very small screens */
 @media (max-width: 480px) {
     body { line-height: 1.6; }
     .sidebar-menu { padding: 15px 10px; margin-bottom: 20px; }
     .sidebar-menu h3 { font-size: 1.2em; margin-bottom: 15px; }
     .sidebar-menu a { font-size: 0.9em; padding: 3px 6px;}

     .container { padding: 15px 8px; }
     h1 { font-size: 1.6em; margin-bottom: 20px; padding-bottom: 10px; }
     h2 { font-size: 1.4em; }
     h3 { font-size: 1.2em; }
     h4 { font-size: 1.05em; }

     .formula-block { padding: 12px 15px; margin: 15px 0 20px 0; }
     #scrollToTopBtn { bottom: 15px; right: 15px; padding: 8px 12px; font-size: 18px; }
 }