/**
 * Formula Display Fixes - Match Old Paper Styling
 * ===============================================
 *
 * This stylesheet updates the dynamic formula display to match the clean,
 * academic styling from principia-metaphysica-paper.html
 *
 * Key Changes:
 * - Remove heavy card backgrounds from equations
 * - Add equation numbers (right-aligned, in parentheses)
 * - Cleaner derivation box styling
 * - Better term/parameter display
 * - Consistent MathJax rendering
 *
 * Copyright (c) 2025-2026 Andrew Keith Watts. All rights reserved.
 */

/* ========================================================================
   FORMULA EQUATION DISPLAY - Match old paper
   ======================================================================== */

.formula-equation {
    /* Remove heavy styling - keep it clean like old paper */
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 1.5rem 0 !important;
    padding: 1rem 0 !important;
    overflow-x: auto;
    text-align: center;
    position: relative;
    clear: both;
}

/* Optional: Add subtle box for important equations */
.formula-equation.boxed {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
    border: 1px solid #dee2e6 !important;
    border-radius: 8px !important;
    padding: 1.5rem !important;
}

/* MathJax size consistency and wrapping */
.formula-equation .MathJax,
.formula-equation mjx-container,
.formula-equation .MathJax_Display,
.equation-content .MathJax,
.equation-content mjx-container,
.equation-wrapper .MathJax,
.equation-wrapper mjx-container {
    font-size: 1.2em !important;
    max-width: 100%;
    /* Allow natural wrapping instead of scroll boxes */
    overflow-x: visible;
    overflow-y: visible;
}

/* Force display style for all fractions in equations (prevents cramped fractions) */
.equation-content mjx-mfrac,
.equation-wrapper mjx-mfrac,
.formula-equation mjx-mfrac {
    /* MathJax 3 uses this for proper sizing */
    display: inline-block !important;
}

/* Ensure operators (=, +, etc.) stay aligned with fraction middle, not under divisor */
.equation-content mjx-mo,
.equation-wrapper mjx-mo {
    vertical-align: middle;
}

/* Long formulas: allow breaking at operators */
.equation-content mjx-mrow {
    flex-wrap: wrap;
}

/* Scale down very long formulas to fit */
.equation-wrapper.long-formula .MathJax,
.equation-wrapper.long-formula mjx-container {
    font-size: 0.95em !important;
}

/* Multi-line formulas (aligned environment) - allow natural wrapping */
.equation-wrapper {
    overflow-x: visible;
    overflow-y: visible;
    padding-bottom: 0.5rem;
    max-width: 100%;
}

/* For genuinely overflowing formulas, scale down instead of scroll */
.equation-content {
    max-width: 100%;
    overflow-x: visible;
}

/* MathJax aligned environment - proper stacking */
.equation-content mjx-mtable {
    display: block !important;
    max-width: 100% !important;
}

/* Hierarchy formulas get smaller font to fit */
.equation-wrapper mjx-container[display="true"] {
    max-width: 100%;
    overflow-x: visible;
}

/* Hide scrollbar - we prefer wrapping/scaling */
.equation-wrapper::-webkit-scrollbar {
    display: none;
}
.equation-wrapper {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Equation number - right-aligned in parentheses (like old paper) */
.equation-number {
    float: right;
    color: #666;
    font-size: 0.9rem;
    font-family: 'Crimson Text', Georgia, serif;
    margin-left: 1rem;
    line-height: 2;
}

/* Equation caption - italic, light, centered below equation */
.equation-caption {
    text-align: center;
    font-size: 0.9rem;
    font-style: italic;
    color: var(--text-muted, #888);
    margin-top: 0.5rem;
    padding: 0 1rem;
    opacity: 0.85;
}

/* ========================================================================
   DERIVATION BOXES - Dark theme with good contrast
   ======================================================================== */

.derivation-section,
.derivation-box {
    background: rgba(26, 31, 58, 0.8) !important;
    border: 1px solid rgba(139, 127, 255, 0.3) !important;
    border-radius: 8px !important;
    padding: 20px !important;
    margin: 1.5rem 0 !important;
}

.derivation-section h4,
.derivation-box h4 {
    font-size: 1rem;
    color: var(--accent-primary, #8b7fff);
    margin-bottom: 0.8rem;
    border-bottom: 1px solid rgba(139, 127, 255, 0.25);
    padding-bottom: 0.5rem;
}

.derivation-step {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: var(--text-secondary, #b0b0b0);
}

.derivation-step::before {
    content: counter(step);
    counter-increment: step;
    position: absolute;
    left: 0;
    color: var(--accent-primary, #8b7fff);
    font-weight: 600;
}

.derivation-steps {
    counter-reset: step;
    list-style: none;
    padding: 0;
}

.derivation-steps li {
    color: var(--text-secondary, #c0c0c0);
    line-height: 1.6;
}

.derivation-section p,
.derivation-box p {
    color: var(--text-secondary, #b0b0b0);
}

.derivation-section strong,
.derivation-box strong {
    color: var(--text-primary, #f0f0f0);
}

/* ========================================================================
   TERMS / PARAMETERS DISPLAY
   ======================================================================== */

.terms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.term-item {
    background: var(--bg-secondary, rgba(255, 255, 255, 0.05));
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    border-left: 3px solid var(--accent-primary, #8b7fff);
}

.term-symbol {
    font-weight: 700;
    color: var(--accent-primary, #8b7fff);
    margin-bottom: 0.25rem;
    font-family: 'Times New Roman', serif;
}

.term-description {
    color: var(--text-muted, #888);
    font-size: 0.85rem;
}

/* ========================================================================
   STATUS BADGES - Academic style
   ======================================================================== */

.status-badge {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.status-exact-match {
    background: rgba(80, 200, 120, 0.2);
    color: #50c878;
    border: 1px solid rgba(80, 200, 120, 0.4);
}

.status-validated {
    background: rgba(139, 127, 255, 0.2);
    color: #8b7fff;
    border: 1px solid rgba(139, 127, 255, 0.4);
}

.status-geometric {
    background: rgba(255, 193, 7, 0.2);
    color: #ffc107;
    border: 1px solid rgba(255, 193, 7, 0.4);
}

.status-prediction {
    background: rgba(255, 126, 182, 0.2);
    color: #ff7eb6;
    border: 1px solid rgba(255, 126, 182, 0.4);
}

/* ========================================================================
   FORMULA CARDS - Lighter styling
   ======================================================================== */

.formula-card {
    background: var(--bg-card, rgba(26, 31, 58, 0.6));
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border-primary, rgba(139, 127, 255, 0.2));
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.formula-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(139, 127, 255, 0.15);
}

/* ========================================================================
   INPUT/OUTPUT PARAMETERS
   ======================================================================== */

.formula-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.detail-item {
    background: var(--bg-secondary, rgba(255, 255, 255, 0.05));
    padding: 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--accent-primary, #8b7fff);
}

.detail-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #888);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.detail-value {
    color: var(--text-primary, #f8f9fa);
    font-size: 1rem;
    font-weight: 500;
}

.detail-value code {
    background: rgba(139, 127, 255, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Courier New', 'Fira Code', monospace;
    font-size: 0.9em;
}

/* ========================================================================
   MOBILE RESPONSIVE
   ======================================================================== */

@media screen and (max-width: 768px) {
    .formula-equation {
        padding: 0.5rem 0 !important;
        font-size: 0.9rem;
    }

    .formula-equation .MathJax,
    .formula-equation mjx-container,
    .formula-equation .MathJax_Display {
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 100%;
    }

    .equation-number {
        font-size: 0.8rem;
    }

    .derivation-section,
    .derivation-box {
        padding: 15px !important;
        margin: 1rem 0 !important;
    }

    .derivation-step {
        padding-left: 1.2rem;
        font-size: 0.9rem;
    }

    .formula-card {
        padding: 1.5rem;
    }

    .terms-grid {
        grid-template-columns: 1fr;
    }
}

@media screen and (max-width: 480px) {
    .formula-equation .MathJax,
    .formula-equation mjx-container {
        font-size: 1rem !important;
    }

    .derivation-section h4,
    .derivation-box h4 {
        font-size: 0.95rem;
    }

    .detail-label {
        font-size: 0.75rem;
    }

    .detail-value {
        font-size: 0.9rem;
    }
}

/* ========================================================================
   PRINT STYLES
   ======================================================================== */

@media print {
    .formula-equation {
        break-inside: avoid;
        overflow: visible !important;
    }

    .formula-card {
        border: 1px solid #000;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .derivation-section,
    .derivation-box {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .equation-number {
        color: #000;
    }

    /* Ensure formulas don't get scroll boxes in print */
    .equation-wrapper,
    .equation-content,
    .formula-block {
        overflow: visible !important;
        max-width: 100% !important;
    }

    /* Scale down large formulas for print */
    .equation-content mjx-container {
        max-width: 100% !important;
        transform-origin: left center;
    }

    /* Aligned environments should wrap naturally */
    mjx-mtable {
        max-width: 100% !important;
        display: block !important;
    }

    /* Remove interactive elements */
    .expand-toggle,
    .expand-icon {
        display: none;
    }

    .expand-content {
        max-height: none !important;
        overflow: visible !important;
    }
}
