/* ========================================
   EQUATION OVERLAY
   Display mathematical equations over the canvas
   ======================================== */

#equation-overlay {
    position: fixed;
    top: calc(32px + 25px); /* Align with display-options panel */
    left: 280px; /* 20px (display-options left) + 240px (width) + 20px (gap) */
    /* Stop before zoom-pan-controls (rightmost panel):
       From right edge: 380px (zoom-pan position) + 130px (zoom-pan width) + 20px (gap) = 530px
       Available width: 100vw - 280px (left) - 530px (right) = 100vw - 810px */
    max-width: calc(100vw - 810px); /* Don't exceed available space */
    max-height: calc(100vh - 100px);
    overflow: visible; /* Don't clip, let scaling handle overflow */
    padding: 16px 20px;
    /* Width will be set dynamically by JavaScript to fit scaled content */
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid rgba(76, 175, 80, 0.3);
    border-radius: 8px;
    backdrop-filter: blur(8px);
    pointer-events: none; /* Allow clicks to pass through */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #e0e0e0;
    z-index: var(--z-equation-overlay, 50);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#equation-overlay.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Content wrapper for equations (keeps button separate) */
.equation-content {
    width: 100%;
    height: 100%;
}

/* Light theme styling */
body.light-theme #equation-overlay {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(76, 175, 80, 0.4);
    color: #1a1a1a;
}

/* MathJax content styling */
#equation-overlay .MathJax {
    color: inherit !important;
}

/* Ensure equations render nicely */
#equation-overlay mjx-container {
    margin: 4px 0;
    color: #e0e0e0 !important;
}

/* Force color on all MathJax elements - use very specific selectors */
#equation-overlay mjx-container,
#equation-overlay mjx-container *,
#equation-overlay mjx-math,
#equation-overlay mjx-math *,
#equation-overlay mjx-c,
#equation-overlay [class^="mjx-"] {
    color: #e0e0e0 !important;
    fill: #e0e0e0 !important;
}

/* FIX: MathJax glyphs have width: 0 - force them to auto */
#equation-overlay mjx-c::before {
    width: auto !important;
    display: inline !important;
}

/* Light theme */
body.light-theme #equation-overlay mjx-container,
body.light-theme #equation-overlay mjx-container *,
body.light-theme #equation-overlay mjx-math,
body.light-theme #equation-overlay mjx-math *,
body.light-theme #equation-overlay mjx-c,
body.light-theme #equation-overlay [class^="mjx-"] {
    color: #1a1a1a !important;
    fill: #1a1a1a !important;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    #equation-overlay {
        top: 60px; /* Account for mobile menu bar */
        left: 10px;
        right: 10px;
        max-width: calc(100vw - 20px);
        padding: 12px 16px;
        font-size: 14px;
    }
}
