* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #2ed573;
    --error-color: #ff4757;
    --warning-color: #ffa502;
    --info-color: #3742fa;
    --text-color: #333;
    --bg-color: #ffffff;
    --card-bg: #ffffff;
    --border-color: #ddd;
    --shadow: 0 20px 40px rgba(0,0,0,0.1);
    --shadow-hover: 0 5px 15px rgba(0,0,0,0.2);
}

[data-theme="dark"] {
    --text-color: #e0e0e0;
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --border-color: #444;
    --shadow: 0 20px 40px rgba(0,0,0,0.3);
    --shadow-hover: 0 5px 15px rgba(0,0,0,0.4);
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    min-height: 100vh;
    color: var(--text-color);
    transition: all 0.3s ease;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

.main {
    flex: 1;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

/* Стили для секции API ключа */
.api-key-section {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    text-align: center;
}

.api-key-section h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.api-key-section p {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.api-key-section a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.api-key-section a:hover {
    text-decoration: underline;
}

.api-key-form {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.api-key-form input {
    flex: 1;
    min-width: 300px;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.api-key-form input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.api-key-form button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

#saveApiKeyBtn {
    background: linear-gradient(135deg, #2ed573 0%, #7bed9f 100%);
    color: white;
}

#saveApiKeyBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(46, 213, 115, 0.4);
}

.secondary-btn {
    background: #6c757d;
    color: white;
}

.secondary-btn:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

.api-key-status {
    font-size: 0.9rem;
    font-weight: 500;
    min-height: 20px;
}

.api-key-status.success {
    color: #2ed573;
}

.api-key-status.error {
    color: #ff4757;
}

.api-key-status.warning {
    color: #ffa502;
}

/* Скрытие секции API ключа когда ключ сохранен */
.api-key-section.hidden {
    display: none;
}

.upload-area {
    border: 3px dashed #ddd;
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: #fafafa;
}

.upload-area:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.upload-area.dragover {
    border-color: #667eea;
    background: #e8f2ff;
    transform: scale(1.02);
}

.upload-content h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: #333;
}

.upload-content p {
    color: #666;
    margin-bottom: 20px;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 20px;
}

.upload-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.preview-section {
    margin-top: 30px;
}

.image-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
}

.image-preview img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.remove-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.remove-btn:hover {
    background: #ff3742;
    transform: scale(1.1);
}

.solve-btn {
    background: linear-gradient(135deg, #2ed573 0%, #7bed9f 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 auto;
}

.solve-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(46, 213, 115, 0.4);
}

.solve-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #ffffff40;
    border-top: 2px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.result-section {
    margin-top: 30px;
    padding: 30px;
    background: #f8f9fa;
    border-radius: 15px;
    border-left: 4px solid #2ed573;
}

.result-section h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.result-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    line-height: 1.6;
    font-size: 1rem;
}

/* Стили для отформатированного текста решения */
.solution-text {
    margin: 0 0 15px 0;
    color: #333;
    line-height: 1.7;
}

.solution-header {
    color: #2ed573;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 20px 0 15px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #e8f5e8;
}

.numbered-step {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    padding: 15px 20px;
    margin: 10px 0;
    border-radius: 0 8px 8px 0;
    font-weight: 500;
    color: #333;
    line-height: 1.6;
}

.math-step {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    padding: 15px 20px;
    margin: 10px 0;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 1.05rem;
    color: #856404;
    line-height: 1.6;
}

/* Стили для математических выражений */
.math-step strong,
.solution-text strong {
    color: #2ed573;
    font-weight: 600;
}

/* Улучшенное отображение списков */
.result-content ul,
.result-content ol {
    margin: 15px 0;
    padding-left: 25px;
}

.result-content li {
    margin: 8px 0;
    line-height: 1.6;
}

/* Стили для заголовков в решении */
.result-content h1,
.result-content h2,
.result-content h3,
.result-content h4 {
    color: #2ed573;
    margin: 20px 0 15px 0;
    font-weight: 600;
}

.result-content h4 {
    font-size: 1.1rem;
    border-bottom: 1px solid #e8f5e8;
    padding-bottom: 5px;
}

/* Стили для элементов списка */
.list-item {
    background: #f8f9fa;
    border-left: 3px solid #2ed573;
    padding: 10px 15px;
    margin: 8px 0;
    border-radius: 0 5px 5px 0;
    color: #333;
    line-height: 1.5;
}

/* Улучшенное отображение для мобильных устройств */
@media (max-width: 768px) {
    .solution-text,
    .numbered-step,
    .math-step,
    .list-item {
        font-size: 0.95rem;
        padding: 12px 15px;
    }
    
    .solution-header {
        font-size: 1.1rem;
    }
}

.new-task-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.new-task-btn:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.error-section {
    margin-top: 30px;
    padding: 20px;
    background: #ffe6e6;
    border-radius: 15px;
    border-left: 4px solid #ff4757;
}

.error-message {
    color: #d63031;
    font-weight: 500;
    margin-bottom: 15px;
}

.retry-btn {
    background: #ff4757;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.retry-btn:hover {
    background: #ff3742;
    transform: translateY(-1px);
}

.footer {
    text-align: center;
    color: white;
    opacity: 0.8;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .main {
        padding: 20px;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .upload-area {
        padding: 40px 15px;
    }
}

.hidden {
    display: none !important;
}

/* Стили для заголовка с контролами */
.header-content {
    position: relative;
}

.header-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.theme-icon {
    font-size: 1.5rem;
    transition: transform 0.3s ease;
}

.theme-toggle:hover .theme-icon {
    transform: rotate(180deg);
}

.model-selector, .category-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.2);
    padding: 10px 15px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
}

.model-selector label, .category-selector label {
    color: white;
    font-weight: 500;
    font-size: 0.9rem;
}

.model-select, .category-select {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 15px;
    padding: 8px 12px;
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
}

.model-select:focus, .category-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

/* Стили для секции решения */
.solve-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.progress-container {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
    animation: progressPulse 2s ease-in-out infinite;
}

@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.progress-text {
    font-size: 0.9rem;
    color: var(--text-color);
    font-weight: 500;
}

/* Улучшенные стили для темной темы */
[data-theme="dark"] .upload-area {
    background: var(--card-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .upload-area:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: var(--primary-color);
}

[data-theme="dark"] .upload-content h3 {
    color: var(--text-color);
}

[data-theme="dark"] .upload-content p {
    color: var(--text-color);
    opacity: 0.8;
}

[data-theme="dark"] .result-content {
    background: var(--bg-color);
    color: var(--text-color);
}

[data-theme="dark"] .solution-text {
    color: var(--text-color);
}

[data-theme="dark"] .numbered-step {
    background: rgba(102, 126, 234, 0.1);
    border-left-color: var(--primary-color);
    color: var(--text-color);
}

[data-theme="dark"] .math-step {
    background: rgba(255, 165, 2, 0.1);
    border-color: var(--warning-color);
    color: var(--text-color);
}

[data-theme="dark"] .list-item {
    background: rgba(46, 213, 115, 0.1);
    border-left-color: var(--success-color);
    color: var(--text-color);
}

/* Анимации */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.6s ease-out;
}

/* Стили для результата с действиями */
.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.result-actions {
    display: flex;
    gap: 10px;
}

.export-btn, .save-btn {
    background: var(--info-color);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 15px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.export-btn:hover, .save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(55, 66, 250, 0.4);
}

.save-btn {
    background: var(--success-color);
}

.save-btn:hover {
    box-shadow: 0 5px 15px rgba(46, 213, 115, 0.4);
}

.result-footer {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

.history-section {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.history-btn {
    background: var(--warning-color);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-btn:hover {
    background: #ff9500;
    transform: translateY(-1px);
}

/* Стили для модального окна */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--card-bg);
    margin: 5% auto;
    padding: 0;
    border-radius: 20px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    background: var(--primary-color);
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.modal-body {
    padding: 20px 30px;
    max-height: 50vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    padding: 20px 30px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.02);
}

.clear-history-btn, .export-all-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 15px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-history-btn {
    background: var(--error-color);
    color: white;
}

.clear-history-btn:hover {
    background: #ff3742;
    transform: translateY(-1px);
}

.export-all-btn {
    background: var(--info-color);
    color: white;
}

.export-all-btn:hover {
    background: #2f3542;
    transform: translateY(-1px);
}

/* Стили для истории решений */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 20px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-color);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.history-item-title {
    font-weight: 600;
    color: var(--text-color);
    font-size: 1.1rem;
}

.history-item-date {
    color: var(--text-color);
    opacity: 0.7;
    font-size: 0.9rem;
}

.history-item-preview {
    color: var(--text-color);
    opacity: 0.8;
    line-height: 1.5;
    max-height: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
}

.history-item-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-item:hover .history-item-actions {
    opacity: 1;
}

.history-item-btn {
    padding: 5px 12px;
    border: none;
    border-radius: 10px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.view-btn {
    background: var(--primary-color);
    color: white;
}

.view-btn:hover {
    background: #5a6fd8;
}

.delete-btn {
    background: var(--error-color);
    color: white;
}

.delete-btn:hover {
    background: #ff3742;
}

.empty-history {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-color);
    opacity: 0.7;
}

.empty-history p {
    margin: 10px 0;
}

/* Улучшенная мобильная версия */
@media (max-width: 768px) {
    .header-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .model-selector {
        flex-direction: column;
        text-align: center;
        gap: 5px;
    }
    
    .theme-toggle {
        width: 45px;
        height: 45px;
    }
    
    .theme-icon {
        font-size: 1.3rem;
    }
    
    .result-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .result-actions {
        justify-content: center;
    }
    
    .result-footer {
        flex-direction: column;
        align-items: center;
    }
    
    .modal-content {
        margin: 10% auto;
        width: 95%;
    }
    
    .modal-header, .modal-body, .modal-footer {
        padding: 15px 20px;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .history-item-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .history-item-actions {
        opacity: 1;
        justify-content: center;
    }
}

/* SEO-оптимизированная секция */
.seo-description {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 10 !important;
    min-height: 200px !important;
    border: 3px solid #667eea !important;
    background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%) !important;
}

.description-content h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 20px;
    text-align: center;
}

.description-content p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 25px;
    text-align: center;
}

.advantages, .how-it-works, .examples {
    margin-bottom: 25px;
}

.advantages h3, .how-it-works h3, .examples h3 {
    color: var(--primary-color);
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 15px;
}

.advantages ul, .examples ul {
    list-style: none;
    padding-left: 0;
}

.advantages li, .examples li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
    line-height: 1.5;
}

.advantages li:before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--success-color);
    font-weight: bold;
    font-size: 1.2rem;
}

.examples li:before {
    content: "📝";
    position: absolute;
    left: 0;
    font-size: 1.1rem;
}

.how-it-works ol {
    padding-left: 20px;
}

.how-it-works li {
    padding: 8px 0;
    line-height: 1.5;
}

.cta-text {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    font-weight: 600;
    font-size: 1.1rem;
    margin-top: 25px;
}

/* Мобильная версия для SEO секции */
@media (max-width: 768px) {
    .seo-description {
        padding: 20px;
        margin-bottom: 20px;
    }
    
    .description-content h2 {
        font-size: 1.5rem;
    }
    
    .description-content p {
        font-size: 1rem;
    }
    
    .advantages h3, .how-it-works h3, .examples h3 {
        font-size: 1.2rem;
    }
    
    .cta-text {
        padding: 15px;
        font-size: 1rem;
    }
}
