/* Math Solver - Standalone Styles
   Extracted from AI Tutor
   ============================================================ */

/* ============================================================
   Variables
   ============================================================ */
:root {
    --primary: #8B5CF6;
    --primary-hover: #7C3AED;
    --primary-dark: #6D28D9;
    --primary-light: rgba(139, 92, 246, 0.08);

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --success: #10b981;
    --danger: #ef4444;

    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ============================================================
   Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-800);
    background-color: #f5f3ff;
    background-image:
        linear-gradient(rgba(139, 92, 246, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(139, 92, 246, 0.05) 1px, transparent 1px);
    background-size: 16px 16px;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; }
p { margin: 0 0 1rem 0; }

.text-muted { color: var(--gray-500); }

/* ============================================================
   Header
   ============================================================ */
.app-header {
    background: linear-gradient(135deg, #8B5CF6, #7C3AED);
    color: white;
    padding: 24px 20px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 4px;
}

.header-brand h1 {
    font-size: 24px;
    font-weight: 700;
}

.header-subtitle {
    margin: 0;
    font-size: 14px;
    opacity: 0.85;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: linear-gradient(135deg, #8B5CF6, #7C3AED);
    color: white;
    padding: 10px 20px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #7C3AED, #6D28D9);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

/* ============================================================
   Main Layout
   ============================================================ */
.solver-container {
    max-width: 800px;
    margin: 32px auto;
    padding: 0 20px;
}

.solver-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ============================================================
   Math Solver Input Section
   ============================================================ */
.math-solver-input-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.math-solver-input-section label {
    font-weight: 600;
    color: var(--gray-700);
}

/* MathLive Input Container */
.math-input-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#mathFieldInput {
    font-size: 22px;
    padding: 16px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    background: white;
    min-height: 60px;
}

#mathFieldInput:focus-within {
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.math-input-help {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--gray-500);
}

.math-input-help .help-tip {
    cursor: help;
    padding: 2px 6px;
    background: var(--gray-100);
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
}

.math-input-help .help-tip:hover {
    background: var(--gray-200);
}

/* Text input as alternative */
.math-text-input {
    padding: 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: 'Consolas', 'Monaco', monospace;
    resize: vertical;
    min-height: 100px;
}

.math-text-input:focus {
    outline: none;
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.math-text-input::placeholder {
    color: var(--gray-400);
    font-family: var(--font);
}

/* ============================================================
   Mode Toggle
   ============================================================ */
.math-solver-mode-toggle {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.math-solver-mode-toggle .mode-option {
    flex: 1;
    cursor: pointer;
}

.math-solver-mode-toggle .mode-option input {
    display: none;
}

.math-solver-mode-toggle .mode-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.math-solver-mode-toggle .mode-option input:checked + .mode-label {
    border-color: #8B5CF6;
    background: rgba(139, 92, 246, 0.08);
    color: #7C3AED;
}

.math-solver-mode-toggle .mode-label:hover {
    border-color: #8B5CF6;
}

.math-solver-mode-toggle .mode-label svg {
    flex-shrink: 0;
}

/* ============================================================
   Knowledge Level Selector
   ============================================================ */
.knowledge-level-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.knowledge-level-section label {
    font-weight: 600;
    color: var(--gray-700);
    font-size: 14px;
}

.knowledge-level-select {
    padding: 10px 14px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: var(--font);
    color: var(--gray-700);
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.knowledge-level-select:focus {
    outline: none;
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

/* ============================================================
   Action Buttons
   ============================================================ */
.math-solver-actions {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

/* ============================================================
   Output Section
   ============================================================ */
.math-solver-output-section {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 20px;
    min-height: 300px;
    overflow-y: auto;
}

.math-solver-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    text-align: center;
    color: var(--gray-500);
}

.math-solver-placeholder p {
    margin: 0;
}

/* Loading State */
.math-solver-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px;
}

.math-solver-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: #8B5CF6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Solution Display
   ============================================================ */
.math-solver-solution {
    line-height: 1.7;
}

.math-solver-solution h4 {
    margin: 0 0 16px 0;
    color: #7C3AED;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-solver-solution .step {
    margin-bottom: 16px;
    padding: 12px 16px;
    background: white;
    border-radius: var(--radius);
    border-left: 3px solid #8B5CF6;
}

.math-solver-solution .step-number {
    font-weight: 600;
    color: #7C3AED;
    margin-bottom: 4px;
}

.math-solver-solution .step-content {
    color: var(--gray-700);
}

.math-solver-solution .final-answer {
    margin-top: 20px;
    padding: 16px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(124, 58, 237, 0.1));
    border-radius: var(--radius);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.math-solver-solution .final-answer h5 {
    margin: 0 0 8px 0;
    color: #7C3AED;
    font-size: 14px;
}

.math-solver-solution .final-answer p {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-800);
    font-family: 'Consolas', 'Monaco', monospace;
}

/* ============================================================
   Test Mode Styles
   ============================================================ */
.math-test-container {
    padding: 8px;
}

.math-test-problem-banner {
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(124, 58, 237, 0.1));
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 15px;
    color: var(--gray-800);
    font-family: 'Consolas', 'Monaco', monospace;
    line-height: 1.6;
}

.math-test-problem-banner strong {
    color: #7C3AED;
    font-family: var(--font);
}

.math-test-progress {
    margin-bottom: 20px;
}

.math-test-progress .progress-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.math-test-progress .progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #8B5CF6, #7C3AED);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.math-test-progress .progress-text {
    font-size: 13px;
    color: var(--gray-500);
    font-weight: 500;
}

.math-test-question {
    margin-bottom: 20px;
}

.math-test-question h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: var(--gray-800);
    line-height: 1.5;
}

.math-test-question .test-context {
    margin: 0;
    padding: 10px 14px;
    background: var(--gray-100);
    border-radius: var(--radius);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px;
    color: var(--gray-700);
}

.math-test-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.math-test-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 14px;
    font-family: var(--font);
}

.math-test-option:hover:not(:disabled) {
    border-color: #8B5CF6;
    background: rgba(139, 92, 246, 0.05);
}

.math-test-option:disabled {
    cursor: default;
}

.math-test-option .option-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gray-100);
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-600);
    flex-shrink: 0;
}

.math-test-option .option-text {
    font-size: 14px;
    color: var(--gray-700);
    font-family: 'Consolas', 'Monaco', monospace;
}

.math-test-option.correct {
    border-color: #10B981;
    background: rgba(16, 185, 129, 0.08);
}

.math-test-option.correct .option-letter {
    background: #10B981;
    color: white;
}

.math-test-option.selected-correct {
    border-color: #10B981;
    background: rgba(16, 185, 129, 0.15);
}

.math-test-option.selected-wrong {
    border-color: #EF4444;
    background: rgba(239, 68, 68, 0.08);
}

.math-test-option.selected-wrong .option-letter {
    background: #EF4444;
    color: white;
}

/* Test Feedback */
.math-test-feedback {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: var(--radius);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.math-test-feedback.correct {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #059669;
    align-items: center;
}

.math-test-feedback.correct svg {
    color: #10B981;
}

.math-test-feedback.correct span {
    font-weight: 600;
    font-size: 15px;
}

.math-test-feedback.wrong {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    flex-direction: column;
    gap: 8px;
}

.math-test-feedback.wrong .feedback-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #DC2626;
    font-weight: 600;
}

.math-test-feedback.wrong .feedback-header svg {
    color: #EF4444;
}

.math-test-feedback.wrong .feedback-explanation {
    color: var(--gray-700);
    font-size: 14px;
    line-height: 1.6;
}

.math-test-feedback.wrong .feedback-explanation strong {
    color: #059669;
    font-family: 'Consolas', 'Monaco', monospace;
}

.math-test-feedback.wrong .feedback-explanation p {
    margin: 8px 0 0 0;
}

/* Continue Button */
.math-test-continue {
    margin-top: 20px;
    width: 100%;
    justify-content: center;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Test Complete Screen */
.math-test-complete {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.math-test-complete svg {
    color: #10B981;
    margin-bottom: 16px;
}

.math-test-complete h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    color: var(--gray-800);
}

.math-test-complete p {
    margin: 0 0 24px 0;
    color: var(--gray-600);
}

.test-complete-actions {
    display: flex;
    gap: 12px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
    .solver-container {
        margin: 16px auto;
        padding: 0 12px;
    }

    .solver-card {
        padding: 16px;
    }

    .math-solver-mode-toggle {
        flex-direction: column;
    }

    .math-solver-actions {
        flex-direction: column;
    }

    .math-solver-actions .btn {
        width: 100%;
    }

    .test-complete-actions {
        flex-direction: column;
        width: 100%;
    }

    .test-complete-actions .btn {
        width: 100%;
    }

    #mathFieldInput {
        font-size: 18px;
        padding: 12px;
    }

    .header-brand h1 {
        font-size: 20px;
    }
}
