/* Базовые стили и CSS переменные для тем */
:root {
    /* Цветовая палитра */
    --primary-color: #4361ee;
    --primary-light: #4895ef;
    --primary-dark: #3a56d4;
    --secondary-color: #7209b7;
    --secondary-light: #b5179e;
    --success-color: #4cc9f0;
    --success-dark: #3aabd0;
    --warning-color: #f72585;
    --warning-dark: #d91a6e;
    --danger-color: #e63946;
    --info-color: #4361ee;
    
    /* Системные цвета */
    --text-color: #2b2d42;
    --text-light: #6c757d;
    --text-muted: #8d99ae;
    --bg-color: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --border-color: #dee2e6;
    --border-light: #f1f3f4;
    
    /* Тени */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Радиусы */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* Анимации */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
    
    /* Typography */
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --font-size-4xl: 2.5rem;
    
    /* Layout */
    --container-max-width: 1200px;
    --header-height: 70px;
}

/* Темная тема */
[data-theme="dark"] {
    --text-color: #e9ecef;
    --text-light: #adb5bd;
    --text-muted: #6c757d;
    --bg-color: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --border-color: #404040;
    --border-light: #333333;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* Сброс стилей и базовые настройки */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-color) 100%);
    color: var(--text-color);
    line-height: 1.6;
    transition: all var(--transition-normal);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Контейнер */
.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* Шапка */
.header {
    background: var(--bg-color);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid var(--border-light);
    height: var(--header-height);
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 20px;
}

.logo {
    font-size: var(--font-size-2xl);
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo::before {
    content: '📚';
    font-size: var(--font-size-xl);
}

.theme-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    border: 1px solid var(--border-color);
}

.theme-btn {
    background: none;
    border: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-base);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-btn:hover {
    background: var(--bg-tertiary);
}

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

/* Основной контент */
.main {
    min-height: calc(100vh - var(--header-height));
    padding: 2rem 0;
}

/* Экраны */
.screen {
    display: none;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

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

/* Карточка приветствия */
.welcome-card {
    background: var(--bg-color);
    border-radius: var(--radius-xl);
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    max-width: 800px;
    margin: 0 auto;
}

.welcome-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
}

.welcome-header {
    margin-bottom: 2rem;
}

.welcome-header h2 {
    font-size: var(--font-size-4xl);
    margin-bottom: 1rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.welcome-header p {
    font-size: var(--font-size-lg);
    color: var(--text-light);
    line-height: 1.6;
}

/* Информация о тесте */
.test-info {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    border-left: 4px solid var(--primary-color);
    text-align: left;
}

.test-info h3 {
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-size: var(--font-size-xl);
    font-weight: 700;
}

.test-info p {
    color: var(--text-light);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.test-meta {
    display: flex;
    gap: 1rem;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.test-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Формы */
.start-form {
    max-width: 480px;
    margin: 0 auto 3rem;
}

.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
    font-size: var(--font-size-base);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    transition: all var(--transition-fast);
    background: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
    transform: translateY(-1px);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

.form-hint {
    font-size: var(--font-size-sm);
    color: var(--text-light);
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.form-hint span {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Кнопки */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left var(--transition-slow);
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
    border-color: var(--primary-color);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-color), var(--success-dark));
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color), #c53030);
    color: white;
}

.btn-large {
    padding: 16px 32px;
    font-size: var(--font-size-lg);
    border-radius: var(--radius-xl);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn:disabled::before {
    display: none;
}

/* Фичи приветствия */
.welcome-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 3rem;
}

.feature {
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    text-align: center;
    transition: all var(--transition-normal);
    border: 1px solid transparent;
}

.feature:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.feature span {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.feature p {
    font-weight: 600;
    color: var(--text-color);
    font-size: var(--font-size-base);
    margin-bottom: 0.5rem;
}

.feature small {
    color: var(--text-light);
    font-size: var(--font-size-sm);
    line-height: 1.4;
}

/* Контейнер тестирования */
.test-container {
    background: var(--bg-color);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    max-width: 800px;
    margin: 0 auto;
}

/* Прогресс-бар */
.progress-section {
    margin-bottom: 2rem;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

#progress-text {
    font-weight: 700;
    color: var(--text-color);
    font-size: var(--font-size-base);
}

#timer {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-weight: 700;
    color: var(--primary-color);
    font-size: var(--font-size-base);
    background: var(--bg-secondary);
    padding: 6px 10px;
    border-radius: var(--radius-md);
}

.progress-bar {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 4px;
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 0%;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Вопросы */
.question-container {
    margin-bottom: 2rem;
    min-height: 200px;
}

.question-card {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--primary-color);
    animation: slideInUp 0.4s ease;
}

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

.question-text {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    line-height: 1.5;
}

.required-badge {
    background: linear-gradient(135deg, var(--warning-color), var(--warning-dark));
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    margin-left: 8px;
    vertical-align: middle;
}

/* Варианты ответов */
.answers-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.answer-option {
    padding: 16px 20px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    background: var(--bg-color);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.answer-option:hover {
    border-color: var(--primary-color);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.answer-option.selected {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, rgba(67, 97, 238, 0.1), rgba(114, 9, 183, 0.05));
    transform: translateX(4px);
}

.answer-option::before {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    margin-top: 2px;
}

.answer-option.selected::before {
    border-color: var(--primary-color);
    background: var(--primary-color);
    box-shadow: inset 0 0 0 3px var(--bg-color);
}

.answer-text {
    font-weight: 500;
    font-size: var(--font-size-base);
    color: var(--text-color);
    line-height: 1.4;
    flex: 1;
}

/* Текстовый ввод */
.text-answer {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    resize: vertical;
    min-height: 120px;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
    transition: all var(--transition-normal);
    line-height: 1.6;
}

.text-answer:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
    transform: translateY(-1px);
}

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

/* Навигация */
.navigation-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Экран завершения */
.completion-card {
    text-align: center;
    background: var(--bg-color);
    border-radius: var(--radius-xl);
    padding: 3rem 2rem;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    max-width: 600px;
    margin: 0 auto;
}

.completion-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
}

.completion-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    animation: bounce 1s ease infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0px); }
    to { transform: translateY(-10px); }
}

.completion-card h2 {
    margin-bottom: 1rem;
    color: var(--text-color);
    font-size: var(--font-size-3xl);
    font-weight: 800;
}

.completion-card p {
    font-size: var(--font-size-lg);
    color: var(--text-light);
    margin-bottom: 2rem;
    line-height: 1.6;
}

.completion-stats {
    max-width: 400px;
    margin: 2rem auto;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
}

.stat-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.stat-value {
    font-weight: 700;
    font-size: var(--font-size-base);
}

.completion-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin: 2rem 0;
}

.completion-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.completion-footer p {
    color: var(--text-light);
    font-size: var(--font-size-sm);
}

.completion-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.completion-footer a:hover {
    text-decoration: underline;
}

/* Уведомления */
.toast-container {
    position: fixed;
    top: 90px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    color: white;
    font-weight: 600;
    box-shadow: var(--shadow-xl);
    animation: toastSlideIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
}

.toast::before {
    font-size: var(--font-size-lg);
}

.toast.success {
    background: linear-gradient(135deg, var(--success-color), var(--success-dark));
}

.toast.success::before {
    content: '✅';
}

.toast.error {
    background: linear-gradient(135deg, var(--warning-color), var(--warning-dark));
}

.toast.error::before {
    content: '❌';
}

.toast.info {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
}

.toast.info::before {
    content: 'ℹ️';
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Адаптивность */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    .header .container {
        padding: 0 15px;
    }
    
    .logo {
        font-size: var(--font-size-xl);
    }
    
    .welcome-card {
        padding: 2rem 1rem;
        margin: 1rem 0;
        border-radius: var(--radius-lg);
    }
    
    .welcome-header h2 {
        font-size: var(--font-size-3xl);
    }
    
    .test-container {
        padding: 1.5rem;
        margin: 1rem 0;
        border-radius: var(--radius-lg);
    }
    
    .question-card {
        padding: 1.5rem;
        margin: 1rem 0;
    }
    
    .navigation-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .welcome-features {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .completion-card {
        padding: 2rem 1.5rem;
        margin: 1rem 0;
        border-radius: var(--radius-lg);
    }
    
    .completion-icon {
        font-size: 3rem;
    }
    
    .completion-actions {
        flex-direction: column;
    }
    
    .toast-container {
        left: 15px;
        right: 15px;
        max-width: none;
        top: 80px;
    }
    
    .progress-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
    
    .test-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .welcome-card {
        padding: 1.5rem 1rem;
    }
    
    .test-container {
        padding: 1rem;
    }
    
    .question-card {
        padding: 1rem;
    }
    
    .answer-option {
        padding: 12px 16px;
    }
    
    .completion-card {
        padding: 1.5rem 1rem;
    }
}

/* Улучшенный скроллбар */
::-webkit-scrollbar {
    width: 8px;
}

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

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

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

/* Утилитарные классы */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

/* Анимация тряски для ошибок */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

/* Состояния загрузки */
.loading {
    opacity: 0.7;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Print styles */
@media print {
    .header,
    .theme-toggle,
    .navigation-buttons,
    .completion-actions {
        display: none !important;
    }
    
    .test-container,
    .completion-card {
        box-shadow: none;
        border: 1px solid #000;
    }
}