/* Стили для Markdown контента */
.markdown-content h1, 
.markdown-content h2, 
.markdown-content h3, 
.markdown-content h4, 
.markdown-content h5, 
.markdown-content h6,
.preview-container .markdown-content h1, 
.preview-container .markdown-content h2, 
.preview-container .markdown-content h3, 
.preview-container .markdown-content h4, 
.preview-container .markdown-content h5, 
.preview-container .markdown-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    color: #333;
}

/* Основной контейнер контента - обеспечивает контекст для обтекания */
.markdown-content,
.preview-container .markdown-content {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;/* Современный стек шрифтов */
    font-size: 1.1rem;          /* Базовый размер шрифта */
    line-height: 1.6;         /* Улучшенная читаемость */
    color: #0a0909;              /* Цвет текста */
    text-align: justify; /* Выравнивание по ширине */
    line-height: 2; 
    /* Обеспечиваем очистку float элементов */
    display: flow-root;
}

/* Стили для обычных параграфов */
.markdown-content p,
.preview-container .markdown-content p {
    margin-bottom: 1.2rem;
    font-size: 1rem;
    line-height: 1.6;
}

/* Улучшенные стили для заголовков */
.markdown-content h1,
.preview-container .markdown-content h1 { 
    font-size: 2rem; 
    font-weight: 700;
    color: #2c3e50;
}
.markdown-content h2,
.preview-container .markdown-content h2 { 
    font-size: 1.75rem; 
    font-weight: 600;
    color: #34495e;
}
.markdown-content h3,
.preview-container .markdown-content h3 { 
    font-size: 1.5rem; 
    font-weight: 600;
    color: #34495e;
}
.markdown-content h4,
.preview-container .markdown-content h4 { 
    font-size: 1.25rem; 
    font-weight: 600;
}
.markdown-content h5,
.preview-container .markdown-content h5 { 
    font-size: 1.1rem; 
    font-weight: 600;
}
.markdown-content h6,
.preview-container .markdown-content h6 { 
    font-size: 1rem; 
    font-weight: 600;
}

/* Списки */
.markdown-content ul, 
.markdown-content ol,
.preview-container .markdown-content ul, 
.preview-container .markdown-content ol {
    margin-bottom: 1em;
    padding-left: 1em;
}

.markdown-content li,
.preview-container .markdown-content li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.markdown-content::after,
.preview-container .markdown-content::after {
    content: "";
    display: table;
    clear: both;
}

.markdown-content blockquote,
.preview-container .markdown-content blockquote {
    border-left: 4px solid #a081ff;
    padding-left: 1em;
    margin-left: 0;
    color: #2c2a2a;
    background: #e2f0ff6b;
    padding: 1rem;
    border-radius: 0 5px 8px 8;
}

.markdown-content code,
.preview-container .markdown-content code {
    background-color: #f5f5f5;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.markdown-content pre,
.preview-container .markdown-content pre {
    background-color: #f8f9fa;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    border-left: 4px solid #007bff;
}

.markdown-content pre code,
.preview-container .markdown-content pre code {
    background: none;
    padding: 0;
}

/* Улучшенные таблицы */
.markdown-content table,
.preview-container .markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.markdown-content th,
.preview-container .markdown-content th {
    background: #a081ff;
    color: white;
    font-weight: 600;
    padding: 12px 15px;
    text-align: left;
}

.markdown-content td,
.preview-container .markdown-content td {
    padding: 10px 15px;
    border-bottom: 1px solid #e9ecef;
}

.markdown-content tr:nth-child(even),
.preview-container .markdown-content tr:nth-child(even) {
    background: #f8f9fa;
}

.markdown-content tr:hover,
.preview-container .markdown-content tr:hover {
    background: #e3f2fd;
}

/* Стили для интерактивных букв в теориях */
.markdown-content .interactive-letter,
.preview-container .markdown-content .interactive-letter {
    display: inline-block;
    transition: all 0.1s ease;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 20px;
    margin: 0 1px;
}

.markdown-content .interactive-letter:hover,
.preview-container .markdown-content .interactive-letter:hover {
    transform: translateY(-3px) scale(1.1);
    background-color: #e3f2fd;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.683);
    color: #1976d2;
}

.markdown-content .interactive-letter.underline,
.preview-container .markdown-content .interactive-letter.underline {
    border-bottom: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.markdown-content .interactive-letter.underline:hover,
.preview-container .markdown-content .interactive-letter.underline:hover {
    border-bottom-color: #1976d2;
    transform: none;
}

.markdown-content .interactive-letter.pop-out,
.preview-container .markdown-content .interactive-letter.pop-out {
    position: relative;
    z-index: 1;
}

.markdown-content .interactive-letter.pop-out:hover,
.preview-container .markdown-content .interactive-letter.pop-out:hover {
    transform: scale(1.2);
    z-index: 10;
    background: linear-gradient(145deg, #ffffff, #e6e6e6);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}


/* ===== СТИЛИ ДЛЯ ПРЕДСКАЗУЕМОГО ОБТЕКАНИЯ ИЗОБРАЖЕНИЙ ===== */

/* Контейнер теории */
.theory-content-wrapper,
.preview-container .theory-content-wrapper {
    background: rgb(255, 255, 255);
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 2rem;
    margin-bottom: 2rem;
    z-index: 100;
}


/* БАЗОВЫЕ СТИЛИ ДЛЯ КОНТЕЙНЕРОВ ИЗОБРАЖЕНИЙ С ОБТЕКАНИЕМ */
.markdown-image-left,
.markdown-image-right,
.preview-container .markdown-image-left,
.preview-container .markdown-image-right {
    margin: 0.5rem 0 1rem 0;
    overflow: hidden;
}

/* ОБТЕКАНИЕ СЛЕВА: картинка слева, текст справа */
.markdown-image-left,
.preview-container .markdown-image-left {
    float: left;                    /* Основное свойство обтекания */
    margin-right: .5rem;          /* Отступ между картинкой и текстом */
    border-radius: 8px;
}

/* ОБТЕКАНИЕ СПРАВА: картинка справа, текст слева */
.markdown-image-right,
.preview-container .markdown-image-right {
    float: right;                   /* Основное свойство обтекания */
    margin-left: 0.5rem;           /* Отступ между картинкой и текстом */
    border-radius: 8px;
}

/* Стили для самих изображений внутри контейнеров */
.markdown-image-left img,
.markdown-image-right img,
.preview-container .markdown-image-left img,
.preview-container .markdown-image-right img {
    width: 100%;                   /* Растягиваем изображение на всю ширину контейнера */
    height: auto;                  /* Сохраняем пропорции */
    border-radius: 25px;
    /* box-shadow: 0 0px 12px rgba(0,0,0,0.15); */
    padding: 10px;
    border: 10px solid #ffffff00;
    box-sizing: border-box;
}

/* Подписи к изображениям */
.markdown-image-left .image-caption,
.markdown-image-right .image-caption,
.preview-container .markdown-image-left .image-caption,
.preview-container .markdown-image-right .image-caption {
    text-align: center;            /* Центрируем подпись */
    font-style: italic;
    color: #666;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    display: block;                /* Подпись на отдельной строке */
    width: 100%;                   /* Растягиваем на всю ширину контейнера */
}

/* ЦЕНТРИРОВАННЫЕ ИЗОБРАЖЕНИЯ (без обтекания) */
.markdown-image-center,
.preview-container .markdown-image-center {
    display: block;                /* Блочный элемент */
    margin: 1.5rem auto;          /* Центрируем по горизонтали */
    text-align: center;            /* Центрируем содержимое */
    max-width: 40%;               /* Ограничиваем максимальную ширину */
    border-radius: 8px;
}

.markdown-image-center img,
.preview-container .markdown-image-center img {
    margin: 0 auto;               /* Центрируем изображение */
    padding: 8px;
    border: 8px solid #ffffff00;
    box-sizing: border-box;
}

/* ОЧИСТКА ОБТЕКАНИЯ - важные стили для управления потоком */

/* Способ 1: Использование псевдоэлемента для очистки float */
.markdown-content::after,
.preview-container .markdown-content::after {
    content: "";
    display: table;
    clear: both;
}

/* ВЕРТИКАЛЬНОЕ ВЫРАВНИВАНИЕ КАРТИНОК ОТНОСИТЕЛЬНО ТЕКСТА */

/* Выравнивание по верху (по умолчанию для float) */
.markdown-image-left.align-top,
.markdown-image-right.align-top,
.preview-container .markdown-image-left.align-top,
.preview-container .markdown-image-right.align-top {
    vertical-align: top;
    margin-top: 5;          /* Можно настроить отступ сверху */
    margin-left: 0;
}

/* Выравнивание по середине */
.markdown-image-left.align-middle,
.markdown-image-right.align-middle,
.preview-container .markdown-image-left.align-middle,
.preview-container .markdown-image-right.align-middle {
    vertical-align: middle;
}

/* Выравнивание по низу */
.markdown-image-left.align-bottom,
.markdown-image-right.align-bottom,
.preview-container .markdown-image-left.align-bottom,
.preview-container .markdown-image-right.align-bottom {
    vertical-align: bottom;
    margin-bottom: 0;       /* Можно настроить отступ снизу */
}

/* ДОПОЛНИТЕЛЬНЫЕ НАСТРОЙКИ ДЛЯ КОНТРОЛЯ ОБТЕКАНИЯ */

/* Минимальная высота для контейнеров с обтеканием */
.markdown-image-left,
.markdown-image-right,
.preview-container .markdown-image-left,
.preview-container .markdown-image-right {
    min-height: 80px;            /* Минимальная высота блока */
    /* Альтернатива: */
    /* min-height: auto;       Автоматическая высота */
}

/* АДАПТИВНОСТЬ ДЛЯ МОБИЛЬНЫХ УСТРОЙСТВ */

@media (max-width: 768px) {
    /* На мобильных убираем обтекание - картинки и текст идут вертикально */
    .markdown-image-left,
    .markdown-image-right,
    .preview-container .markdown-image-left,
    .preview-container .markdown-image-right {
        float: none;               /* Убираем обтекание */
        display: block;            /* Блочное отображение */
        margin: 1rem auto;         /* Центрируем и добавляем отступы */
        max-width: 100%;           /* На всю ширину экрана */
    }
    
    /* Убираем боковые отступы на мобильных */
    .markdown-image-left,
    .preview-container .markdown-image-left {
        margin-right: 0;
    }
    
    /* Центрируем подписи на мобильных */
    .markdown-image-left .image-caption,
    .markdown-image-right .image-caption,
    .preview-container .markdown-image-left .image-caption,
    .preview-container .markdown-image-right .image-caption {
        text-align: center;
    }
}

/* СТИЛИ ДЛЯ ГАЛЕРЕЙ И ЦЕНТРИРОВАННЫХ ИЗОБРАЖЕНИЙ (оставляем как есть) */
.markdown-image,
.preview-container .markdown-image {
    margin: 1.5em 0;
    text-align: center;
}

.markdown-gallery,
.preview-container .markdown-gallery {
    margin: 2em 0;
}

.gallery-grid,
.preview-container .gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1em 0;
}

.gallery-item,
.preview-container .gallery-item {
    text-align: center;
}

.gallery-item img,
.preview-container .gallery-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.gallery-item img:hover,
.preview-container .gallery-item img:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

/* Стили для переключаемых слов в теориях */
.word-switcher,
.preview-container .word-switcher {
    cursor: pointer;
    padding: 1px 6px;
    border-radius: 3px;
    transition: all 0.2s ease;
    display: inline-block;
    margin: 0 1px;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
    font-size: 0.95em;
    vertical-align: baseline;
    position: relative;
    /* Убираем фиксированную минимальную ширину */
    min-width: auto;
}

/* Стили для переключаемых слов в теориях */
.word-switcher,
.preview-container .word-switcher {
    cursor: pointer;
    padding: 1px 6px;
    border-radius: 3px;
    transition: all 0.2s ease;
    display: inline-block;
    margin: 0 1px;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
    font-size: 0.95em;
    vertical-align: baseline;
    position: relative;
    /* Убираем фиксированную минимальную ширину */
    min-width: auto;
}

/* Первое слово - светло-фиолетовый фон */
.word-switcher[data-current="word1"],
.preview-container .word-switcher[data-current="word1"] {
    background-color: #e2c7fd !important;
    color: #333;
    border: 1px solid #d8b1ff;
}

/* Второе слово - светло-голубой фон */
.word-switcher[data-current="word2"],
.preview-container .word-switcher[data-current="word2"] {
    background-color: #f5ff82 !important;
    color: #333;
    border: 1px solid #375561;
}

/* Для пустых слов - показываем второе слово полупрозрачным */
.word-switcher[data-current="word1"]:empty::before,
.preview-container .word-switcher[data-current="word1"]:empty::before {
    content: attr(data-word2);
    opacity: 0.01;
    display: inline-block;
}

/* Эффект при наведении */
.word-switcher:hover,
.preview-container .word-switcher:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    .word-switcher,
    .preview-container .word-switcher {
        padding: 1px 4px;
        margin: 0 1px;
        font-size: 0.9em;
    }
}