/* Desmos-Style Visual Math Editor Styles */

.math-editor {
    min-height: 2.5rem;
    padding: 0.75rem;
    border: 2px solid #475569; /* slate-600 */
    border-radius: 0.5rem;
    background-color: #0f172a; /* slate-900 */
    color: #f1f5f9; /* gray-100 */
    font-family: 'Times New Roman', serif;
    font-size: 1.125rem; /* 18px */
    line-height: 1.5;
    outline: none;
    transition: all 0.2s ease-in-out;
    cursor: text;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.math-editor:focus,
.math-editor.math-editor-focused {
    border-color: #3b82f6; /* blue-500 */
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.math-editor:hover {
    border-color: #64748b; /* slate-500 */
}

/* Placeholder styling */
.math-placeholder {
    color: #64748b; /* slate-500 */
    font-style: italic;
    pointer-events: none;
    user-select: none;
}

/* Math element highlighting */
.math-input-highlight {
    background-color: rgba(59, 130, 246, 0.2) !important; /* blue with opacity */
    border: 1px dashed #3b82f6;
    border-radius: 0.25rem;
    padding: 0.125rem 0.25rem;
    min-width: 1rem;
    min-height: 1.25rem;
    display: inline-block;
    outline: none;
}

.math-input-active {
    background-color: rgba(59, 130, 246, 0.3) !important;
    border-color: #1d4ed8; /* blue-700 */
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}

/* Fraction styling */
.math-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 0.25rem;
    position: relative;
}

.math-numerator {
    display: block;
    text-align: center;
    padding: 0.125rem 0.25rem;
    min-width: 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    margin-bottom: 0.125rem;
}

.math-denominator {
    display: block;
    text-align: center;
    padding: 0.125rem 0.25rem;
    min-width: 1.5rem;
    margin-top: 0.125rem;
}

.math-fraction-bar {
    width: 100%;
    height: 1px;
    background-color: #f1f5f9;
    margin: 0.125rem 0;
    min-width: 2rem;
}

/* Square root styling */
.math-sqrt {
    display: inline-flex;
    align-items: center;
    position: relative;
    margin: 0 0.125rem;
    font-size: 1.25em;
}

.math-sqrt::before {
    content: '';
    position: absolute;
    top: 0;
    left: 1.2em;
    right: 0;
    height: 1px;
    background-color: #f1f5f9;
    z-index: 1;
}

.math-radicand {
    padding: 0.125rem 0.25rem;
    margin-left: 0.25rem;
    min-width: 1.5rem;
    border-top: 1px solid #f1f5f9;
    position: relative;
}

.math-root-index {
    font-size: 0.75em;
    position: relative;
    top: -0.5em;
    left: -0.25em;
    margin-right: -0.25em;
}

/* Superscript and subscript styling */
sup.math-exponent,
sub.math-subscript {
    font-size: 0.8em;
    padding: 0.125rem 0.25rem;
    min-width: 1rem;
    position: relative;
}

sup.math-exponent {
    top: -0.5em;
}

sub.math-subscript {
    bottom: -0.25em;
}

/* Function styling */
.math-function {
    font-style: normal;
    font-weight: 500;
    color: #3b82f6; /* blue-500 */
    margin-right: 0.125rem;
}

.math-function-arg {
    padding: 0.125rem 0.25rem;
    min-width: 1.5rem;
}

/* Absolute value styling */
.math-abs {
    display: inline-flex;
    align-items: center;
    font-size: 1.25em;
    margin: 0 0.125rem;
}

.math-abs-content {
    padding: 0.125rem 0.25rem;
    min-width: 1.5rem;
    margin: 0 0.125rem;
}

/* Parentheses and brackets */
.math-paren,
.math-bracket {
    font-size: 1.25em;
    font-weight: 500;
    margin: 0 0.125rem;
}

/* Mathematical symbols */
.math-symbol {
    font-weight: 500;
    margin: 0 0.125rem;
}

/* Greek letters */
.math-greek {
    font-style: italic;
    font-weight: 500;
    color: #8b5cf6; /* violet-500 */
}

/* Operators */
.math-operator {
    margin: 0 0.25rem;
    font-weight: 500;
}

/* Complex expressions */
.math-expression {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.125rem;
}

/* Hover effects for interactive elements */
.math-input-highlight:hover {
    background-color: rgba(59, 130, 246, 0.25) !important;
}

.math-input-highlight:focus {
    background-color: rgba(59, 130, 246, 0.3) !important;
    border-color: #1d4ed8;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}

/* Animation for transformations */
.math-transform-enter {
    animation: mathTransformIn 0.2s ease-out;
}

@keyframes mathTransformIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .math-editor {
        font-size: 1rem;
        padding: 0.5rem;
    }
    
    .math-fraction {
        margin: 0 0.125rem;
    }
    
    .math-numerator,
    .math-denominator {
        min-width: 1rem;
        padding: 0.0625rem 0.125rem;
    }
    
    .math-radicand,
    .math-function-arg,
    .math-abs-content {
        min-width: 1rem;
        padding: 0.0625rem 0.125rem;
    }
}

/* Dark theme specific adjustments */
.dark .math-editor {
    background-color: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

.dark .math-editor:focus,
.dark .math-editor.math-editor-focused {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.dark .math-placeholder {
    color: #64748b;
}

.dark .math-input-highlight {
    background-color: rgba(59, 130, 246, 0.15) !important;
    border-color: #3b82f6;
}

.dark .math-input-active {
    background-color: rgba(59, 130, 246, 0.25) !important;
    border-color: #1d4ed8;
}

.dark .math-numerator,
.dark .math-fraction-bar,
.dark .math-radicand {
    border-color: #f1f5f9;
}

.dark .math-sqrt::before {
    background-color: #f1f5f9;
}

.dark .math-function {
    color: #60a5fa; /* blue-400 for better contrast in dark mode */
}

.dark .math-greek {
    color: #a78bfa; /* violet-400 for better contrast in dark mode */
}

/* Print styles */
@media print {
    .math-editor {
        border: 1px solid #000;
        background-color: #fff;
        color: #000;
    }
    
    .math-input-highlight {
        background-color: transparent !important;
        border: none !important;
    }
    
    .math-placeholder {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .math-editor {
        border-width: 3px;
    }
    
    .math-input-highlight {
        border-width: 2px;
    }
    
    .math-function {
        font-weight: 700;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .math-editor,
    .math-input-highlight,
    .math-transform-enter {
        transition: none;
        animation: none;
    }
}

/* Focus visible for keyboard navigation */
.math-editor:focus-visible,
.math-input-highlight:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Selection styling */
.math-editor ::selection {
    background-color: rgba(59, 130, 246, 0.3);
    color: inherit;
}

.math-editor ::-moz-selection {
    background-color: rgba(59, 130, 246, 0.3);
    color: inherit;
}
