:root {
    /* Color Palette - Dark Mode (Default) */
    --primary: #6366f1;
    /* Indigo 500 */
    --primary-hover: #4f46e5;
    /* Indigo 600 */
    --bg-body: #0f172a;
    /* Slate 900 */
    --bg-card: #1e293b;
    /* Slate 800 */
    --bg-input: #334155;
    /* Slate 700 */
    --text-main: #ffffff;
    --text-muted: #94a3b8;
    /* Slate 400 */
    --border-color: #334155;

    /* Geometry */
    --radius-btn: 12px;
    --radius-card: 20px;
    --radius-input: 12px;

    /* Animation */
    --transition: 0.3s ease;
}

[data-theme="light"] {
    /* Color Palette - Light Mode */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-body: #f1f5f9;
    /* Slate 100 */
    --bg-card: #ffffff;
    --bg-input: #e2e8f0;
    /* Slate 200 */
    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */
    --border-color: #cbd5e1;
}

/* Global Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: background-color var(--transition), color var(--transition);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

/* Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

.btn {
    padding: 12px 24px;
    border-radius: var(--radius-btn);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-icon {
    background: transparent;
    color: var(--text-main);
    padding: 8px;
    font-size: 1.2rem;
}

/* Header */
header {
    background-color: var(--bg-card);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Profile Dropdown */
.profile-container {
    position: relative;
}

.avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    border: 2px solid var(--bg-card);
}

.dropdown-menu {
    position: absolute;
    top: 120%;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    padding: 8px;
    min-width: 200px;
    display: none;
    /* Toggled via JS */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.1s ease;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: block;
    padding: 10px 16px;
    color: var(--text-main);
    border-radius: 8px;
    font-size: 0.95rem;
}

.dropdown-item:hover {
    background-color: var(--bg-input);
}

.danger {
    color: #ef4444;
}

/* Main Solution Engine */
.solver-section {
    padding: 40px 0;
    flex: 1;
}

.solver-card {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.tab-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-btn);
}

.tab-btn.active {
    background: var(--bg-input);
    color: var(--primary);
}

/* Inputs */
.input-area {
    min-height: 200px;
    display: none;
    /* Toggled via JS */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-input);
    background: var(--bg-input);
    margin-bottom: 20px;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.input-area.active {
    display: flex;
}

textarea.active {
    width: 100%;
    min-height: 150px;
    background: transparent;
    border: none;
    color: var(--text-main);
    outline: none;
    resize: vertical;
    font-size: 1rem;
}

/* Video & Canvas */
video#camera-feed {
    width: 100%;
    max-width: 500px;
    border-radius: 8px;
}

canvas#capture-canvas {
    display: none;
}

/* Solution Styles */
.final-answer-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    padding: 35px 25px 25px 25px;
    border-radius: var(--radius-card);
    margin-bottom: 24px;
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.25);
}

.final-answer-card h3 {
    margin-bottom: 12px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    opacity: 0.95;
    font-weight: 700;
}

.final-answer-card .answer-text {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.4;
}

.steps-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    overflow: hidden;
    transition: border-color 0.2s;
}

.step-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.step-number {
    font-weight: 800;
    color: var(--primary);
    background: var(--bg-input);
    width: 30px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.step-text-short {
    flex: 1;
    font-weight: 500;
}

.expand-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    /* Higher contrast */
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.expand-btn:hover {
    background: var(--bg-input);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.step-detail {
    display: none;
    padding: 0 16px 20px 62px;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
    border-top: 1px solid var(--border-color);
    margin-top: -10px;
    padding-top: 16px;
    animation: slideDown 0.3s ease;
}

.step-detail.visible {
    display: block;
}

.step-detail strong {
    color: var(--text-main);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Login Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal {
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius-card);
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {

    /* Chat UI Layout */
    body {
        height: 100dvh;
        overflow: hidden;
        /* Prevent body scroll, handle internally */
    }

    header {
        padding: 10px 0;
        flex-shrink: 0;
    }

    .header-content {
        flex-direction: row;
        padding: 0 15px;
    }

    .logo span {
        display: none;
        /* Icon only on mobile */
    }

    /* Main Content Area */
    .solver-section {
        padding: 0;
        display: flex;
        flex-direction: column;
        height: calc(100dvh - 60px);
        /* Adjust for header */
        position: relative;
    }

    /* 1. Results Area (Scrollable Conversation) */
    #solution-output {
        flex: 1;
        overflow-y: auto;
        padding: 20px 15px 100px 15px;
        /* Bottom padding for input */
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    /* 2. Input Area (Sticky Bottom) */
    .solver-card {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        border-radius: 20px 20px 0 0;
        padding: 15px;
        background: var(--bg-card);
        border-top: 1px solid var(--border-color);
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.2);
        z-index: 50;
    }

    /* Minimal Tabs */
    .tabs {
        justify-content: center;
        margin-bottom: 10px;
        gap: 5px;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    /* Text Input Styling for Mobile */
    .input-area {
        min-height: auto;
        padding: 10px;
        margin-bottom: 10px;
        background: var(--bg-input);
        border-radius: 24px;
        border: 1px solid var(--border-color);
    }

    textarea.active {
        min-height: 44px;
        /* Default single line height */
        max-height: 120px;
        height: 44px;
        padding: 10px;
        font-size: 1rem;
    }

    /* Hide large upload areas to save space, show compact if needed */
    #tab-upload,
    #tab-camera {
        min-height: 150px;
    }

    .btn-primary {
        width: 100%;
        border-radius: 24px;
        padding: 12px;
    }
}