/* === General Body & Font Reset === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Quicksand', sans-serif;
    font-weight: 400; 
    background-color: #222629; 
    color: #E0E0E0; 
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: 20px;
}

/* === General Footer Styling === */
footer {
    text-align: center;
    padding: 20px;
    background-color: #1A1D1F; 
    color: #6B6E70; 
    font-size: 0.9em;
    margin-top: auto; 
    font-weight: 400;
}

/* === Index Page (index.html) Specific Header Styling === */
header { 
    text-align: center;
    padding: 30px 20px;
    margin-bottom: 30px;
}

header h1 {
    font-weight: 700; 
    font-size: 2.8em;
    color: #86C232; 
    margin-bottom: 10px;
}

header p {
    font-weight: 400; 
    font-size: 1.2em;
    color: #6B6E70; 
}

/* === Index Page (index.html) Main Content Grid === */
main { 
    flex-grow: 1;
    width: 90%;
    max-width: 1200px;
    margin: 0 auto; 
    padding-bottom: 40px;
}

.topics-grid { 
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px; 
}

/* Index Page (index.html) Topic Card Styling */
.topic-card { 
    background-color: #474B4F; 
    border-radius: 8px;
    text-decoration: none;
    color: #E0E0E0;
    padding: 25px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border-left: 5px solid transparent;
    min-height: 180px;
}

.topic-card:hover,
.topic-card:focus {
    transform: translateY(-8px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
    border-left-color: #86C232;
}

.topic-card h2 {
    font-weight: 700; 
    font-size: 1.6em;
    margin-bottom: 8px;
    color: #FFFFFF;
}

.topic-card .topic-detail-note { 
    font-size: 0.8em;
    color: #6B6E70;
    font-style: italic;
    margin-top: 5px;
    font-weight: 400;
}

/* === Styles for Topic Pages (e.g., algebra.html, funkcijas.html) === */
.page-header { 
    text-align: center;
    padding: 20px; 
    margin-bottom: 20px;
}

.page-header h1 { 
    font-weight: 700;
    font-size: 2.4em;
    color: #86C232;
    margin-top: 0;
}

.back-to-home {
    display: inline-block;
    text-decoration: none;
    color: #86C232;
    font-weight: 500;
    padding: 8px 15px;
    border: 1px solid #86C232;
    border-radius: 5px;
    transition: background-color 0.3s ease, color 0.3s ease;
    margin-bottom: 20px; 
}

.back-to-home:hover {
    background-color: #86C232;
    color: #222629;
}

.topic-content { 
    width: 90%;
    max-width: 900px; 
    margin: 0 auto 40px auto;
}

.topic-intro {
    font-size: 1.1em;
    color: #B0B0B0;
    margin-bottom: 30px;
    text-align: center;
    font-weight: 300;
}

/* Subtopic Cards Grid on Topic Pages (Using Flexbox for better symmetry) */
.subtopics-grid {
    display: flex;        
    flex-wrap: wrap;      
    justify-content: center; 
    gap: 25px; 
    margin-top: 30px;
}

.subtopic-card { 
    background-color: #474B4F;
    color: #E0E0E0;
    padding: 20px 25px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 140px;
    flex-basis: calc(50% - 12.5px); 
    max-width: 320px; 
    box-sizing: border-box; 
}

.subtopic-card h2 { 
    font-weight: 500;
    font-size: 1.3em;
    color: #FFFFFF;
    margin-bottom: 0; 
}

.subtopic-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
    border-color: #86C232;
}

/* === Modal Styles === */
.overlay {
    position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.7);z-index: 999;opacity: 0;visibility: hidden;transition: opacity 0.3s ease, visibility 0s 0.3s linear;
}
.overlay.active {opacity: 1;visibility: visible;transition: opacity 0.3s ease;}
.modal {position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%) scale(0.9);width: 80%;max-width: 800px;max-height: 85vh;background-color: #3a3f42;border-radius: 10px;box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);z-index: 1000;opacity: 0;visibility: hidden;transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s linear;display: flex;flex-direction: column;}
.modal.active {opacity: 1;visibility: visible;transform: translate(-50%, -50%) scale(1);transition: opacity 0.3s ease, transform 0.3s ease;}
.modal-content-wrapper {display: flex;flex-direction: column;height: 100%;overflow: hidden;}
.modal-header {display: flex;justify-content: space-between;align-items: center;padding: 15px 25px;background-color: #474B4F;color: #E0E0E0;border-top-left-radius: 10px;border-top-right-radius: 10px;flex-shrink: 0;}
.modal-header h3 {font-size: 1.4em;font-weight: 700;color: #FFFFFF;}
.modal-close-btn {background: none;border: none;color: #E0E0E0;font-size: 2em;line-height: 1;cursor: pointer;padding: 0 5px;transition: color 0.2s ease;}
.modal-close-btn:hover {color: #86C232;}
.modal-body-content {padding: 20px 25px;overflow-y: auto;flex-grow: 1;color: #D0D0D0;min-height: 0;}
.modal-body-content::-webkit-scrollbar {width: 10px;}
.modal-body-content::-webkit-scrollbar-track {background: #222629;border-radius: 5px;}
.modal-body-content::-webkit-scrollbar-thumb {background-color: #61892F;border-radius: 5px;border: 2px solid #222629;}
.modal-body-content::-webkit-scrollbar-thumb:hover {background-color: #86C232;}
.modal-body-content {scrollbar-width: thin;scrollbar-color: #61892F #222629;}
.modal-body-content .sub-section {margin-bottom: 25px;padding-bottom: 15px;border-bottom: 1px solid #474B4F;}
.modal-body-content .sub-section:last-child {border-bottom: none;margin-bottom: 0;}
.modal-body-content .sub-section h5 {font-size: 1.2em;color: #86C232;margin-bottom: 15px;font-weight: 700;border-left: 3px solid #61892F;padding-left: 10px;}
.modal-body-content .formula-example-block {background-color: #2E353B;border: 1px solid #4A535C;padding: 15px;margin: 20px 0;border-radius: 6px;box-shadow: 0 2px 5px rgba(0,0,0,0.3);}
.modal-body-content .example-block-title {font-weight: 500;color: #E0E0E0;margin-bottom: 10px;font-size: 1.05em;display: block;}
.modal-body-content .example-block-description {font-weight: 400;color: #B0BCC0;margin-bottom: 15px;font-size: 0.95em;}
.modal-body-content .example-block-source {font-size: 0.85em;color: #7B8892;font-style: italic;text-align: right;margin-top: 10px;}
.modal-body-content .formula-example-block p {margin-bottom: 8px;line-height: 1.7;color: #C8C8C8;word-break: break-word;}
.modal-body-content .formula-example-block p:last-child {margin-bottom: 0;}

/* Ensuring MathJax rendered formulas are light-colored and flow correctly */
.modal-body-content mjx-container { 
    color: #E0E0E0 !important; 
    line-height: normal !important; 
    text-align: left; 
}
.modal-body-content mjx-container[display="true"] {
    display: block !important;
    margin: 0.8em auto !important; 
}
/* REFINED: For inline math ($ ... $), help it flow better with text */
.modal-body-content p mjx-container:not([display="true"]), 
.modal-body-content li mjx-container:not([display="true"]) { 
    display: inline !important;      /* Force inline behavior */
    white-space: normal;             /* Allow browser/MathJax to wrap if needed */
    vertical-align: -0.2ex;         /* Adjust for better baseline alignment with Quicksand */
    margin: 0 0.1em !important;      
    padding: 0 !important;
    line-height: inherit !important; 
    max-width: 100%; /* Ensure it doesn't overflow its parent paragraph/li */
}
.modal-body-content mjx-container mjx-math,
.modal-body-content mjx-container mjx-mrow {
    display: inline !important; /* Attempt to keep internal MathJax elements inline */
}
.modal-body-content mjx-assistive-mml { 
    display: none !important;
}

.modal-body-content ul {list-style-position: inside;padding-left: 5px;margin: 10px 0;}
.modal-body-content li {margin-bottom: 8px;line-height: 1.6;}
.modal-body-content p {margin-bottom: 15px;line-height: 1.7;}


/* === Responsive Adjustments (Consolidated) === */
@media (max-width: 768px) { 
    header h1 { font-size: 2.2em; }
    .topics-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
    .topic-card h2 { font-size: 1.4em; }

    .page-header h1 { font-size: 2em; }
    .subtopics-grid { /* Flexbox will handle wrapping */ }
    .subtopic-card {
        flex-basis: calc(50% - 12.5px); 
        min-width: 250px; 
        max-width: 300px; 
    }
    
    .modal { width: 90%; }
    .modal-header h3 { font-size: 1.2em; }
}

@media (max-width: 600px) { 
    .subtopic-card {
        flex-basis: 100%; 
        max-width: 400px; 
    }
}

@media (max-width: 480px) { 
    body { padding-top: 10px; }
    header { padding: 20px 15px; margin-bottom: 20px; }
    header h1 { font-size: 1.8em; }
    header p { font-size: 1em; }
    
    .topics-grid { grid-template-columns: 1fr; gap: 20px; }
    .topic-card { min-height: 150px; padding: 20px; }
    .topic-card h2 { font-size: 1.3em; }

    .page-header { padding: 15px; margin-bottom: 15px; }
    .page-header h1 { font-size: 1.7em; }
    .back-to-home { padding: 6px 10px; font-size: 0.9em; margin-bottom: 15px; }
    
    .subtopics-grid { padding: 0; }
    .subtopic-card {
        flex-basis: 100%; 
        max-width: none; 
    }

    .modal { width: 95%; max-height: 90vh; }
    .modal-header { padding: 10px 15px; }
    .modal-header h3 { font-size: 1.1em; }
    .modal-body-content { padding: 15px 20px; }
    .modal-close-btn { font-size: 1.8em; }
}

.header-top-nav {
    display: flex;
    justify-content: space-between; /* Pushes "Back" to left, "Logout" to right */
    align-items: center;
    margin-bottom: 10px; /* Space before the main H1 */
    width: 100%; /* Ensure it takes available width if inside a centered container */
    max-width: 900px; /* Align with .topic-content max-width */
    margin-left: auto;
    margin-right: auto;
    padding: 0 10px; /* Some padding so it doesn't touch edges */
}

.page-header .header-top-nav { /* Specific to topic pages */
    /* max-width already set by .topic-content which .page-header is usually within or aligned with */
}

.main-page-header-nav { /* Specific to main_content.php header */
    max-width: 1200px; /* Align with its main content width */
    padding-top: 10px; /* Some spacing at the top */
}
.main-page-header-nav span { /* If you keep the placeholder span */
    flex-grow: 1; /* Takes up space if only logout is present */
}


.logout-button {
    display: inline-block;
    text-decoration: none;
    color: #E0E0E0; /* Light gray, less prominent than green */
    font-weight: 500;
    padding: 6px 12px;
    border: 1px solid #6B6E70; /* Light gray border */
    border-radius: 5px;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.logout-button:hover {
    background-color: #86C232; /* Green accent on hover */
    color: #222629; /* Dark text on hover */
    border-color: #86C232;
}