/* Math-specific CSS for LaTeX rendering and mathematical content */

/* MathJax container styling */
.MathJax {
    font-size: 18pt !important;
    max-width: 100% !important;

}

.MathJax_Display {
    margin: 0.25rem 0 !important;
    padding: 0 !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
}

/* Ensure MathJax SVG elements wrap properly */
mjx-container {
    max-width: 100% !important;
    padding: 0.5rem 0 !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
}

mjx-container[display="true"] {
    display: block !important;
    padding: 0.75rem 0 !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
}

/* Handle text within MathJax */
mjx-mtext {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
}

/* Math expression containers */
.exercise-math {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 6px;
    border-left: 4px solid #3498db;
    margin: 1rem 0;
    font-size: 1.1rem;
}

.solution-math {
    background-color: #e8f5e8;
    padding: 1rem;
    border-radius: 6px;
    border-left: 4px solid #27ae60;
    margin: 1rem 0;
    font-size: 1.1rem;
}

/* Boxed elements styling */
.boxed-element {
    display: inline-block;
    min-width: 2rem;
    min-height: 1.5rem;
    border: 2px solid #3498db;
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    margin: 0 0.2rem;
    background-color: white;
    vertical-align: baseline;
}

.boxed-element.empty {
    background-color: #f8f9fa;
    border-style: dashed;
}

.boxed-element.filled {
    background-color: #e8f5e8;
    border-color: #27ae60;
}

/* Mathematical notation enhancements */
.fraction {
    display: inline-block;
    vertical-align: middle;
    text-align: center;
}

.fraction .numerator {
    display: block;
    border-bottom: 1px solid #333;
    padding-bottom: 0.1rem;
}

.fraction .denominator {
    display: block;
    padding-top: 0.1rem;
}

/* Special math symbols and operators */
.math-operator {
    font-weight: bold;
    margin: 0 0.3rem;
}

.math-equals {
    margin: 0 0.5rem;
    font-weight: bold;
}

.math-variable {
    font-style: italic;
    color: #2c3e50;
}

.math-constant {
    font-weight: bold;
    color: #8e44ad;
}

/* Exercise-specific math styling */
.exercise .boxed-element {
    background-color: white;
    border-color: #3498db;
    border-style: solid;
}

.exercise .boxed-element.empty {
    background-color: #f8f9fa;
    border-style: dashed;
    min-width: 3rem;
}

/* Solution-specific math styling */
.solution .boxed-element {
    background-color: #e8f5e8;
    border-color: #27ae60;
    border-style: solid;
}

.solution .boxed-element.filled {
    font-weight: 500;
}

/* Mathematical diagrams and figures */
.math-figure {
    text-align: center;
    margin: 2rem 0;
    padding: 1rem;
    background-color: white;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.math-figure img {
    max-width: 100%;
    height: auto;
}

.math-figure .caption {
    margin-top: 1rem;
    font-style: italic;
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* Step-by-step solutions */
.solution-steps {
    margin: 1rem 0;
}

.solution-step {
    margin: 1rem 0;
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #3498db;
}

.solution-step .step-number {
    font-weight: bold;
    color: #3498db;
    margin-bottom: 0.5rem;
}

.solution-step .step-explanation {
    margin-bottom: 0.5rem;
    color: #555;
}

.solution-step .step-math {
    font-family: 'Times New Roman', serif;
    font-size: 1.1rem;
}

/* Mathematical tables */
.math-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background-color: white;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.math-table th,
.math-table td {
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid #ecf0f1;
}

.math-table th {
    background-color: #3498db;
    color: white;
    font-weight: 600;
}

.math-table tr:hover {
    background-color: #f8f9fa;
}

/* Prevent scrollbars in math content */
.solution-math,
.solution-math *,
.solution-content .MathJax,
.solution-content mjx-container {
    overflow: visible !important;
    max-height: none !important;
}

/* Responsive math content */
@media (max-width: 768px) {
    .exercise-math,
    .solution-math {
        padding: 0.75rem;
        font-size: 1rem;
    }
    
    .MathJax {
        font-size: 1rem !important;
    }
    
    .boxed-element {
        min-width: 1.5rem;
        min-height: 1.2rem;
        padding: 0.1rem 0.3rem;
    }
    
    .math-figure {
        padding: 0.75rem;
        margin: 1rem 0;
    }
    
    .solution-step {
        padding: 0.75rem;
    }
    
    .math-table th,
    .math-table td {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .exercise-math,
    .solution-math {
        padding: 0.5rem;
        font-size: 0.95rem;
    }
    
    .MathJax {
        font-size: 0.9rem !important;
    }
    
    .boxed-element {
        min-width: 1.2rem;
        min-height: 1rem;
        padding: 0.1rem 0.2rem;
        margin: 0 0.1rem;
    }
    
    .math-table {
        font-size: 0.8rem;
    }
    
    .math-table th,
    .math-table td {
        padding: 0.4rem;
    }
}

/* Print styles for math content */
@media print {
    .exercise-math,
    .solution-math {
        background-color: transparent !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 0.5rem 0 !important;
        page-break-inside: avoid;
    }

    .boxed-element {
        border-color: #333 !important;
    }

    .math-figure {
        page-break-inside: avoid;
    }

    .solution-step {
        page-break-inside: avoid;
    }

    /* Align MathJax display math to the left */
    .MathJax_Display {
        text-align: left !important;
        margin-left: 0 !important;
    }

    mjx-container[display="true"] {
        text-align: left !important;
        margin-left: 0 !important;
    }
}