/* ===== CSS RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --background: #0f172a;
    --surface: #1e293b;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --success-color: #10b981;
    --error-color: #ef4444;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
    overflow-x: hidden;
}

/* ===== CONTAINER & LAYOUT ===== */
.container {
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== HEADER ===== */
header {
    text-align: center;
    margin-bottom: 40px;
    animation: slideDown 0.8s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: 500px;
    margin: 0 auto;
}

/* ===== CALCULATOR CARD ===== */
.calculator-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.calculator-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

/* ===== FORM STYLES ===== */
.form-group {
    margin-bottom: 25px;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    cursor: pointer;
}

.help-text {
    display: block;
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== MATHLIVE STYLING ===== */
math-field.math-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1.2rem;
    transition: all 0.3s ease;
    outline: none;
    min-height: 50px;
    display: flex;
    align-items: center;
}

math-field.math-input:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* MathLive dark theme customization */
math-field.math-input::part(content) {
    color: var(--text-primary);
    background: transparent;
}

math-field.math-input::part(virtual-keyboard-toggle) {
    color: var(--primary-color);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 4px 8px;
    transition: all 0.3s ease;
}

math-field.math-input::part(virtual-keyboard-toggle):hover {
    background: var(--primary-color);
    color: white;
}

/* Override MathLive's default colors for dark theme */
math-field.math-input {
    --caret-color: var(--primary-color);
    --selection-background-color: rgba(99, 102, 241, 0.3);
    --contains-highlight-background-color: rgba(99, 102, 241, 0.2);
}

/* ===== FUNCTION PREVIEW ===== */
.function-preview {
    margin-top: 12px;
    padding: 15px;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    animation: fadeIn 0.3s ease-out;
}

.function-preview .preview-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.function-preview .preview-content {
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.function-preview .preview-content .katex {
    color: var(--text-primary);
    font-size: 1.2em;
}

.function-preview .preview-content .katex .mord,
.function-preview .preview-content .katex .mbin,
.function-preview .preview-content .katex .mrel,
.function-preview .preview-content .katex .mopen,
.function-preview .preview-content .katex .mclose,
.function-preview .preview-content .katex .mpunct {
    color: var(--text-primary);
}

.preview-error {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
}

/* ===== 3D GRAPH SECTION ===== */
.graph-section {
    margin-top: 20px;
    animation: fadeIn 0.3s ease-out;
}

.graph-container {
    padding: 20px;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    animation: fadeIn 0.3s ease-out;
}

.graph-container .graph-label {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 12px;
    font-weight: 600;
}

.graph-3d {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    background: var(--surface);
}

/* ===== COORDINATES GRID ===== */
.coordinates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.coordinates-grid .form-control {
    margin: 0;
}

/* ===== BUTTON STYLES ===== */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.btn-primary:disabled:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.btn-primary .icon {
    transition: transform 0.3s ease;
}

.btn-primary:hover .icon {
    transform: translateX(5px);
}

.btn-secondary {
    width: 100%;
    padding: 12px 20px;
    background: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    margin-bottom: 15px;
}

.btn-secondary:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-secondary:active {
    transform: translateY(0);
}

.btn-secondary .icon {
    transition: transform 0.3s ease;
}

.btn-secondary:hover .icon {
    transform: rotate(180deg);
}

/* ===== RESULTS SECTION ===== */
.results-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid var(--border-color);
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-section h2 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.result-card:hover {
    border-color: var(--primary-color);
    transform: translateX(5px);
}

.result-card h3 {
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-bottom: 12px;
    font-weight: 600;
}

.result-content {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.8;
    background: var(--background);
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
}

.result-content p {
    margin-bottom: 8px;
}

.result-content strong {
    color: var(--text-primary);
}

/* KaTeX styling overrides for better dark theme integration */
.result-content .katex {
    color: var(--text-primary);
    font-size: 1.1em;
}

.result-content .katex-display {
    margin: 1em 0;
}

.result-content .katex .mord,
.result-content .katex .mbin,
.result-content .katex .mrel,
.result-content .katex .mopen,
.result-content .katex .mclose,
.result-content .katex .mpunct {
    color: var(--text-primary);
}

/* ===== ERROR MESSAGE ===== */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid var(--error-color);
    color: var(--error-color);
    padding: 16px;
    border-radius: 10px;
    margin-top: 20px;
    font-weight: 500;
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* ===== HIDDEN CLASS ===== */
.hidden {
    display: none !important;
}

/* ===== FOOTER ===== */
footer {
    text-align: center;
    margin-top: 40px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .calculator-card {
        padding: 25px;
    }

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

    .result-content {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .calculator-card {
        padding: 20px;
    }
}

/* ===== CUSTOM SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}
