:root {
    /* НОВАЯ ЦВЕТОВАЯ ГАММА ИЗ ЧАТА */
    --primary: #D63384;
    --primary-dark: #B52A6F;
    --primary-light: #F8BBD9;
    --primary-lighter: #FDF8F8;
    --primary-gradient: linear-gradient(135deg, #D63384 0%, #E91E63 50%, #9C27B0 100%);
    --secondary: #5A5A5A;
    --accent: #9C27B0;
    --success: #48BB78;
    --warning: #f59e0b;

    /* Светлая тема (по умолчанию) */
    --page-bg: #ffffff;
    --page-text: #2D3748;
    --page-border: #e2e8f0;

    --white: #ffffff;
    --light-bg: #FDF8F8;
    --card-bg: #ffffff;
    --card-hover: #f1f5f9;
    --border-light: #e2e8f0;
    --border: #cbd5e1;
    --text-primary: #2D3748;
    --text-secondary: #5A5A5A;
    --text-tertiary: #718096;

    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    --sidebar-text: #2D3748;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 999px;

    --transition-fast: all 0.15s ease;
    --transition: all 0.25s ease;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(214, 51, 132, 0.15);
    --shadow-lg: 0 8px 30px rgba(214, 51, 132, 0.15);

    /* Размеры шрифта */
    --font-size-small: 16px;
    --font-size-normal: 18px;
    --font-size-large: 20px;
    --font-size-xlarge: 22px;
    --current-font-size: var(--font-size-normal);

    /* Размеры страницы А4 */
    --a4-width: 210mm;
    --a4-height: 297mm;
    --a4-padding: 30mm;
}

/* Тёмная тема */
body.dark-theme {
    --primary: #D63384;
    --primary-dark: #B52A6F;
    --primary-light: #F8BBD9;
    --primary-lighter: #1a0f1a;
    --primary-gradient: linear-gradient(135deg, #D63384 0%, #E91E63 50%, #9C27B0 100%);
    --secondary: #8b5cf6;
    --accent: #f472b6;
    --success: #10b981;

    --page-bg: #1a0f1a;
    --page-text: #cbd5e1;
    --page-border: #4a374a;

    --white: #1a0f1a;
    --light-bg: #2d1f2d;
    --card-bg: #2d1f2d;
    --card-hover: #4a374a;
    --border-light: #4a374a;
    --border: #5A5A5A;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #64748b;

    --sidebar-bg: #2d1f2d;
    --sidebar-border: #4a374a;
    --sidebar-text: #f1f5f9;
}

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

body {
    background: var(--light-bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========== МОБИЛЬНАЯ ШАПКА ========== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    z-index: 1000;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
}

.mobile-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-header-center {
    font-size: 18px;
    font-weight: 700;
    color: var(--sidebar-text);
    font-family: 'Inter', sans-serif;
}

.mobile-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-toggle,
.mobile-new-story {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--light-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.mobile-menu-toggle:hover,
.mobile-new-story:hover {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

/* Основной контент */
.main-content {
    flex: 1;
    margin-left: 260px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.3s ease, opacity 0.5s ease, transform 0.5s ease;
}

.main-content.sidebar-collapsed {
    margin-left: 70px;
}

/* ========== МОБИЛЬНОЕ ПОЛЕ ВВОДА С ПЕРВОЙ БУКВОЙ ========== */
.mobile-input-panel {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--page-bg);
    border-top: 1px solid var(--page-border);
    padding: 12px 16px;
    z-index: 1000;
    /* Фиксируем панель внизу */
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

.mobile-input-container {
    position: relative;
    width: 100%;
    display: flex;
    align-items: flex-end; /* Выравниваем по нижнему краю */
    gap: 12px;
}

/* Контейнер для поля ввода в мобильной версии */
.mobile-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    min-width: 0; /* Важно для правильной работы flexbox */
}

/* Поле ввода для мобильных с возможностью первой буквы */
.mobile-ai-input-editable {
    width: 100%;
    min-height: 44px;
    max-height: 120px; /* Максимальная высота с прокруткой */
    padding: 12px 45px 12px 40px;
    border: none;
    background: var(--light-bg);
    font-family: 'Cormorant Garamond', 'Literata', serif;
    font-size: 17px; /* Увеличенный шрифт для мобильных */
    line-height: 1.4;
    color: var(--page-text);
    outline: none;
    overflow-y: auto; /* Включаем прокрутку при необходимости */
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    white-space: pre-wrap; /* Очень важно - перенос по словам */
    word-wrap: break-word; /* Перенос длинных слов */
    word-break: break-word; /* Лучший перенос слов */
    overflow-wrap: break-word; /* Современный вариант */
    cursor: text;
    resize: none;
    flex: 1;
    min-width: 0; /* Важно для правильного растяжения */
}

.mobile-ai-input-editable:focus {
    background: var(--card-bg);
    min-height: 60px;
    max-height: 160px;
}

.mobile-ai-input-editable::first-letter {
    font-size: 24px; /* Увеличенная первая буква */
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Playfair Display', serif;
    text-transform: uppercase;
    line-height: 0.9;
}

.mobile-ai-input-editable:empty::before {
    content: attr(placeholder);
    color: var(--text-tertiary);
    font-style: italic;
    font-size: 15px; /* Увеличенный шрифт плейсхолдера */
    font-weight: 400;
    position: absolute;
    left: 40px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

/* Оригинальное текстовое поле скрываем */
.mobile-ai-input {
    display: none;
}

.mobile-settings-toggle,
.mobile-send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--light-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    align-self: flex-end; /* Фиксируем кнопки внизу контейнера */
    margin-bottom: 0; /* Убираем отступ снизу */
}

.mobile-send-btn {
    background: var(--primary);
    color: var(--white);
    border: none;
}

.mobile-settings-toggle:hover {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.mobile-send-btn:hover {
    background: var(--primary-dark);
}

/* ========== КОНТЕЙНЕР ДЛЯ ГАЛОЧКИ "ПРОДОЛЖАЕМ РАССКАЗ" ========== */
.continue-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    width: 100%;
    justify-content: center;
    margin-top: 8px;
    /* Фиксируем галочку внизу панели */
    position: relative;
    z-index: 2;
}

.continue-checkbox-container {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.continue-checkbox {
    width: 16px;
    height: 16px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.continue-checkbox.checked {
    background: var(--primary);
    border-color: var(--primary);
}

.continue-checkbox.checked::after {
    content: '✓';
    color: var(--white);
    font-size: 10px;
    font-weight: bold;
}

.continue-label {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
}

.continue-help {
    color: var(--text-tertiary);
    cursor: help;
    position: relative;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

/* Подсказка при наведении на знак вопроса */
.continue-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-size: 11px;
    color: var(--text-primary);
    width: 200px;
    text-align: center;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.continue-help:hover .continue-tooltip {
    opacity: 1;
    visibility: visible;
}

.continue-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--border-light);
}

/* ========== РЕДАКТОР В СТИЛЕ А4 ========== */
.content-area {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 0;
    overflow: hidden;
    padding: 20px;
    background: var(--light-bg);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

/* Редактор - чистый лист А4 */
.editor-container {
    background: var(--page-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--page-border);
    position: relative;
    transition: var(--transition);
}

/* Панель навигации по страницам */
.page-navigation {
    padding: 12px 24px;
    border-bottom: 1px solid var(--page-border);
    background: var(--page-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-secondary);
    transition: var(--transition);
}

.page-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-controls {
    display: flex;
    align-items: center;
    gap: 12px; /* Увеличили отступ для новой кнопки */
}

/* Кнопка "Читать рассказ" в панели навигации */
.page-read-btn {
    padding: 6px 12px;
    border-radius: var(--radius-md);
    background: var(--primary);
    border: none;
    color: var(--white);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-read-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(214, 51, 132, 0.25);
}

.page-read-btn i {
    font-size: 12px;
}

.page-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--light-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.page-btn:hover:not(:disabled) {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Область текста с несколькими страницами */
.editor-content {
    flex: 1;
    overflow-y: auto;
    background: var(--light-bg);
    padding: 20px;
    position: relative;
    transition: var(--transition);
}

.editor-content::-webkit-scrollbar {
    width: 8px;
}

.editor-content::-webkit-scrollbar-track {
    background: var(--light-bg);
    border-radius: var(--radius-full);
}

.editor-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

/* Контейнер для страниц */
.pages-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
    padding: 20px 0;
}

/* Страница в стиле А4 */
.story-page {
    width: var(--a4-width);
    min-height: var(--a4-height);
    background: var(--page-bg);
    padding: var(--a4-padding);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border-radius: 2px;
    position: relative;
    page-break-after: always;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Номер страницы */
.page-number {
    position: absolute;
    bottom: 20px;
    right: 30mm;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
}

/* Текст рассказа с улучшенной типографикой */
.story-content {
    font-family: 'Literata', 'Source Serif Pro', serif;
    font-size: var(--current-font-size);
    line-height: 1.8;
    color: var(--page-text);
    text-align: justify;
    font-weight: 400;
    letter-spacing: 0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    flex: 1;
}

/* Заголовок главы */
.chapter-title {
    font-size: calc(var(--current-font-size) * 1.4);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 1.5em;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
    font-family: 'Playfair Display', serif;
    text-align: center;
    letter-spacing: -0.02em;
    page-break-after: avoid;
}

/* Параграфы с большой первой буквой - ИСПРАВЛЕН ЦВЕТ */
.story-paragraph {
    margin-bottom: 1.6em;
    position: relative;
    text-align: justify;
    transition: var(--transition);
    text-indent: 1.5em;
    page-break-inside: avoid;
    orphans: 3;
    widows: 3;
}

.story-paragraph:first-of-type {
    text-indent: 0;
}

.story-paragraph:first-of-type::first-letter {
    font-size: 4.2em;
    font-weight: 700;
    color: var(--text-primary);
    float: left;
    line-height: 0.8;
    margin: 0.12em 0.15em 0.05em 0;
    padding: 0.05em;
    font-family: 'Playfair Display', serif;
}

/* Иллюстрация к рассказу */
.story-illustration {
    margin: 2em auto;
    width: 80%;
    max-width: 400px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    page-break-inside: avoid;
    position: relative;
    background: var(--light-bg);
    border: 1px solid var(--border-light);
}

/* ОБНОВЛЁННЫЙ СТИЛЬ ИЛЛЮСТРАЦИИ БЕЗ ПОДПИСИ, С КНОПКОЙ РЕГЕНЕРАЦИИ */
.illustration-img {
    width: 100%;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--light-bg);
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-style: italic;
    overflow: hidden;
    position: relative;
}

.illustration-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Кнопка регенерации изображения */
.illustration-regenerate-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: var(--white);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    z-index: 10;
    opacity: 0;
    transform: translateY(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.story-illustration:hover .illustration-regenerate-btn {
    opacity: 1;
    transform: translateY(0);
}

.illustration-regenerate-btn:hover {
    background: var(--primary);
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 4px 12px rgba(214, 51, 132, 0.4);
}

.illustration-regenerate-btn:active {
    transform: translateY(0) scale(0.95);
}

/* Подпись убрана */

/* Блок пользователя - исправлен цвет текста для темной темы */
.user-block {
    margin: 1.8em 0;
    padding: 22px;
    background: var(--primary-light);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary);
    position: relative;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    page-break-inside: avoid;
}

.user-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.user-avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 13px;
    font-weight: 600;
}

.user-info-sm {
    flex: 1;
}

.user-name-sm {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
}

.user-time {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
}

.user-content {
    font-style: italic;
    color: var(--text-primary); /* Исправлено: был var(--page-text), теперь var(--text-primary) */
    line-height: 1.7;
    font-size: calc(var(--current-font-size) * 0.95);
    font-family: 'Literata', 'Source Serif Pro', serif;
}

/* Для темной темы специальные стили для блока пользователя */
body.dark-theme .user-block {
    background: rgba(214, 51, 132, 0.15); /* Более темный фон для темной темы */
    border-left-color: var(--accent);
}

body.dark-theme .user-content {
    color: #f1f5f9; /* Яркий белый для темной темы */
}

/* Для темной темы стили кнопки регенерации */
body.dark-theme .illustration-regenerate-btn {
    background: rgba(45, 31, 45, 0.8);
    border: 1px solid var(--border-light);
}

body.dark-theme .illustration-regenerate-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* ========== УЛУЧШЕННАЯ ПАНЕЛЬ ВВОДА (ДЛЯ ДЕСКТОПА) ========== */
.desktop-input-panel {
    padding: 16px 24px;
    border-top: 1px solid var(--page-border);
    background: var(--page-bg);
    position: relative;
    transition: var(--transition);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.input-container {
    position: relative;
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

/* Contenteditable div для десктопного ввода */
.ai-input-editable {
    width: 100%;
    min-height: 60px;
    max-height: 160px;
    padding: 18px 100px 18px 50px;
    border: none;
    background: var(--light-bg);
    font-family: 'Cormorant Garamond', 'Literata', serif;
    font-size: 20px;
    line-height: 1.5;
    color: var(--page-text);
    outline: none;
    overflow-y: auto;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    white-space: pre-wrap; /* Перенос по словам */
    word-wrap: break-word; /* Перенос длинных слов */
    word-break: break-word; /* Лучший перенос слов */
    overflow-wrap: break-word; /* Современный вариант */
    cursor: text;
    resize: none;
}

.ai-input-editable:focus {
    background: var(--card-bg);
    min-height: 80px;
    max-height: 200px;
}

.ai-input-editable::first-letter {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Playfair Display', serif;
    text-transform: uppercase;
    line-height: 0.9;
}

.ai-input-editable:empty::before {
    content: attr(placeholder);
    color: var(--text-tertiary);
    font-style: italic;
    font-size: 18px;
    font-weight: 400;
    position: absolute;
    left: 60px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

/* Кнопка открытия правой панели в десктопной версии */
.desktop-input-panel .mobile-settings-toggle {
    display: none;
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
}

.input-actions {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--primary);
    border: none;
    color: var(--white);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.input-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(214, 51, 132, 0.25);
}

.input-btn:active {
    transform: translateY(0) scale(0.98);
}

.char-count {
    position: absolute;
    bottom: 8px;
    right: 68px;
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
    background: var(--page-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    transition: var(--transition-fast);
    opacity: 0.8;
}

/* ИНДИКАТОР НАБОРА ТЕКСТА УБРАН */

/* ========== НОВЫЙ РЕЖИМ ЧТЕНИЯ ========== */
.reading-mode {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: none;
    flex-direction: column;
    background: var(--page-bg);
    animation: slideIn 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow: hidden;
}

.reading-mode.active {
    display: flex;
}

.reading-mode.hiding {
    animation: slideOut 0.6s cubic-bezier(0.55, 0.085, 0.68, 0.53) forwards;
}

.reading-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--page-border);
    background: var(--page-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.reading-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Playfair Display', serif;
}

.reading-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reading-control-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--light-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.reading-control-btn:hover {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.reading-control-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.speed-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-right: 10px;
}

.speed-btn {
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--light-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: 13px;
    font-weight: 500;
}

.speed-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}

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

.reading-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.reading-content-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    background: var(--light-bg);
}

.reading-content {
    max-width: var(--a4-width);
    margin: 0 auto;
    background: var(--page-bg);
    padding: var(--a4-padding);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border-radius: 2px;
    min-height: var(--a4-height);
    position: relative;
    page-break-after: always;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.reading-story-content {
    font-family: 'Literata', 'Source Serif Pro', serif;
    font-size: var(--current-font-size);
    line-height: 1.8;
    color: var(--page-text);
    text-align: justify;
    font-weight: 400;
    letter-spacing: 0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    flex: 1;
}

.highlighted-word {
    background: rgba(214, 51, 132, 0.15);
    border-radius: 3px;
    padding: 0 2px;
    transition: background 0.2s ease;
    animation: textHighlight 1s ease;
}

.reading-progress {
    height: 4px;
    background: var(--border-light);
    position: relative;
    overflow: hidden;
}

.reading-progress-bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

.reading-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--page-border);
    background: var(--page-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.reading-action-btn {
    padding: 10px 24px;
    border-radius: var(--radius-md);
    background: var(--primary);
    border: none;
    color: var(--white);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 8px;
}

.reading-action-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.reading-action-btn.secondary {
    background: var(--light-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.reading-action-btn.secondary:hover {
    background: var(--card-hover);
    border-color: var(--primary);
    color: var(--primary);
}

/* Анимации */
@keyframes slideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

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

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

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

@keyframes textHighlight {
    0% { background: transparent; }
    50% { background: rgba(214, 51, 132, 0.25); }
    100% { background: rgba(214, 51, 132, 0.15); }
}

.story-paragraph {
    animation: fadeIn 0.3s ease-out;
}

.user-block {
    animation: fadeIn 0.3s ease-out;
}

.story-illustration {
    animation: fadeIn 0.5s ease-out;
}

/* Адаптивность */
@media (max-width: 1200px) {
    .content-area {
        grid-template-columns: 1fr 380px;
        padding: 16px;
    }

    .story-page {
        width: 100%;
        min-height: auto;
        padding: 20px;
    }

    .ai-input-editable {
        font-size: 18px;
        min-height: 55px;
        max-height: 140px;
        padding: 18px 90px 18px 45px;
    }

    .ai-input-editable:focus {
        min-height: 70px;
        max-height: 180px;
    }

    .mobile-ai-input-editable {
        font-size: 16px;
        padding: 12px 45px 12px 40px;
        min-height: 44px;
        max-height: 100px;
    }

    .mobile-ai-input-editable:focus {
        min-height: 60px;
        max-height: 140px;
    }

    .reading-content {
        width: 100%;
        min-height: auto;
        padding: 20px;
    }
}

/* ИЗМЕНЕНИЕ: Обновляем breakpoint с 1024px на 1190px для правой панели */
@media (max-width: 1190px) {
    .content-area {
        grid-template-columns: 1fr;
        padding: 16px;
        position: relative;
    }

    /* Скрываем правую панель */
    .settings-panel {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        width: 100%;
        max-width: 420px;
        height: 100vh;
        z-index: 1000;
        border-radius: 0;
        box-shadow: var(--shadow-lg);
    }

    .settings-panel.active {
        display: flex;
    }

    /* Растягиваем редактор на всю ширину */
    .editor-container {
        width: 100%;
        height: 100%;
        border-radius: var(--radius-lg);
    }

    /* Убираем пустое пространство справа */
    .content-area:not(.settings-open) .editor-container {
        margin-right: 0;
        grid-column: 1 / -1;
    }

    /* ПОКАЗЫВАЕМ КНОПКУ В ДЕСКТОПНОЙ ПАНЕЛИ */
    .desktop-input-panel .mobile-settings-toggle {
        display: flex !important;
    }

    /* СДВИГАЕМ ПОЛЕ ВВОДА ДЛЯ КНОПКИ */
    .ai-input-editable {
        padding-left: 60px !important;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .mobile-header {
        display: flex;
    }

    .mobile-input-panel {
        display: block;
        /* Фиксируем панель внизу */
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
    }

    .main-content {
        margin-left: 0;
        margin-top: 56px;
        margin-bottom: 68px;
        height: calc(100vh - 124px);
    }

    .main-content.sidebar-collapsed {
        margin-left: 0;
    }

    .content-area {
        padding: 10px;
        grid-template-columns: 1fr;
    }

    .story-page {
        width: 100%;
        min-height: auto;
        padding: 15px;
    }

    .desktop-input-panel {
        display: none;
    }

    .ai-input-editable {
        padding: 14px 80px 14px 40px;
        font-size: 16px;
        min-height: 50px;
        max-height: 120px;
    }

    .ai-input-editable:focus {
        min-height: 65px;
        max-height: 150px;
    }

    .input-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .char-count {
        right: 60px;
        bottom: 6px;
        font-size: 10px;
    }

    .mobile-ai-input-editable {
        font-size: 17px; /* Увеличенный шрифт для мобильных */
        padding: 12px 45px 12px 40px;
        min-height: 44px;
        max-height: 120px;
    }

    .mobile-ai-input-editable:focus {
        min-height: 60px;
        max-height: 160px;
    }

    .mobile-ai-input-editable::first-letter {
        font-size: 24px;
    }

    .mobile-settings-toggle,
    .mobile-send-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
        /* Фиксируем кнопки внизу */
        align-self: flex-end;
        margin-bottom: 0;
        position: relative;
        top: 0;
    }

    .reading-content-container {
        padding: 10px;
    }

    .reading-content {
        padding: 15px;
        font-size: 16px;
    }

    .reading-footer {
        padding: 12px 16px;
        flex-wrap: wrap;
    }

    .reading-action-btn {
        padding: 8px 16px;
        font-size: 13px;
    }

    .reading-header {
        padding: 12px 16px;
    }

    .reading-controls {
        gap: 5px;
    }

    .speed-controls {
        display: none;
    }

    .continue-container {
        padding: 6px 0;
        margin-top: 8px;
        /* Галочка остается на своем месте */
        position: relative;
    }

    .continue-label {
        font-size: 12px;
    }

    .continue-tooltip {
        width: 180px;
        font-size: 10px;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .editor-content {
        padding: 10px;
    }

    .page-navigation {
        padding: 10px 16px;
    }

    .page-read-btn {
        padding: 5px 10px;
        font-size: 12px;
    }

    .mobile-input-panel {
        padding: 10px 12px;
    }

    .mobile-ai-input-editable {
        min-height: 44px;
        max-height: 100px;
        padding: 10px 40px 10px 36px;
        font-size: 16px; /* Не уменьшаем дальше */
    }

    .mobile-ai-input-editable:focus {
        min-height: 60px;
        max-height: 140px;
    }

    .mobile-ai-input-editable::first-letter {
        font-size: 22px;
    }

    .mobile-settings-toggle,
    .mobile-send-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
        /* Кнопки остаются фиксированными */
        position: relative;
        align-self: flex-end;
    }

    .main-content {
        margin-bottom: 62px;
        height: calc(100vh - 118px);
    }

    .continue-container {
        padding: 4px 0;
    }

    .continue-label {
        font-size: 11px;
    }

    .continue-checkbox {
        width: 14px;
        height: 14px;
    }

    .continue-tooltip {
        width: 160px;
        font-size: 9px;
        padding: 5px 8px;
    }
}

/* Плавный переход темы */
* {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* В style.css добавьте: */
.limit-chat-message {
    background: #fff5f5;
    border: 2px solid #fed7d7;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    color: #c53030;
    font-size: 16px;
    line-height: 1.5;
    animation: fadeIn 0.5s ease;
}

.limit-chat-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.limit-chat-content i {
    font-size: 20px;
    margin-top: 2px;
    color: #c53030;
}

.limit-chat-text {
    flex: 1;
    line-height: 1.5;
}

.limit-chat-text strong {
    color: #9b2c2c;
}

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

/* Исправление горизонтального скролла при средних размерах экрана */
@media (min-width: 1201px) and (max-width: 1522px) {
    .story-page {
        width: calc(100% - 40px) !important;
        max-width: 100%;
        min-height: auto;
        padding: 20px;
        margin: 0 auto;
        box-sizing: border-box;
    }

    .editor-content {
        overflow-x: hidden !important;
        padding: 10px !important;
    }

    .pages-container {
        width: 100%;
        max-width: 100%;
        padding: 10px 0;
    }

    /* Центрируем иллюстрации */
    .story-illustration {
        width: 90% !important;
        max-width: 500px;
    }

    /* Исправляем позицию номера страницы */
    .page-number {
        right: 20px;
        bottom: 10px;
    }
}

/* Модальное окно для изображения */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
}

/* Анимация появления */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.image-modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

/* ========== СТИЛИ ДЛЯ УВЕДОМЛЕНИЙ ========== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    max-width: 300px;
    animation: fadeIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-light);
}

.notification i {
    color: var(--success);
}

.notification.success i {
    color: var(--success);
}

.notification.error i {
    color: var(--error);
}

.notification.warning i {
    color: var(--warning);
}

.notification.info i {
    color: var(--primary);
}

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

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