/* ===== БАЗОВЫЕ СТИЛИ ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.7;
    color: #333;
    background-color: #f8f9fa;
    font-size: 18px;
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 25px;
    transition: font-size 0.3s ease;
    font-style: normal;
}

/* ===== ШАПКА ===== */
.fragment-header {
    background: linear-gradient(135deg, #2c3e50 0%, #597d89 100%);
    color: white;
    padding: 50px 0;
    text-align: center;
    margin-bottom: 40px;
    border-radius: 0 0 20px 20px;
}

.fragment-header h1 {
    font-size: 2.5rem;
    margin-bottom: 15px;
    font-weight: 700;
    font-style: normal;
}

.fragment-header .subtitle {
    font-size: 1.3rem;
    opacity: 0.9;
    margin-bottom: 20px;
    font-style: normal;
}

.fragment-header h2 {
    font-size: 2rem;
    margin-bottom: 25px;
    font-weight: 600;
    font-style: normal;
}

.book-meta {
    display: flex;
    justify-content: center;
    gap: 25px;
    flex-wrap: wrap;
    margin-top: 25px;
    font-size: 1rem;
}

.meta-item {
    background: rgba(255,255,255,0.15);
    padding: 10px 20px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
    font-style: normal;
}

/* ===== ПЛАВАЮЩАЯ КНОПКА СОДЕРЖАНИЯ ===== */
.floating-toc-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    background: #597d89;
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    z-index: 1000;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    font-style: normal;
}

.floating-toc-btn:hover {
    background: #4a6a75;
    transform: scale(1.1);
}

/* ===== ВЫЕЗЖАЮЩЕЕ СОДЕРЖАНИЕ ===== */
.toc-sidebar {
    position: fixed;
    top: 0;
    left: -400px;
    width: 350px;
    height: 100vh;
    background: white;
    box-shadow: 5px 0 25px rgba(0,0,0,0.2);
    z-index: 999;
    transition: left 0.3s ease;
    overflow-y: auto;
    padding: 80px 25px 25px;
}

.toc-sidebar.active {
    left: 0;
}

.toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 998;
    display: none;
}

.toc-overlay.active {
    display: block;
}

.toc-header {
    color: #597d89;
    margin-bottom: 25px;
    font-size: 1.4rem;
    text-align: center;
    border-bottom: 2px solid #597d89;
    padding-bottom: 15px;
    font-style: normal;
}

.toc-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toc-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    text-decoration: none;
    color: #333;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
    font-style: normal;
}

.toc-link.toc-part {
    background: #597d89;
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    justify-content: center;
    border-left: 4px solid #2c3e50;
    font-style: normal;
}

.toc-link:hover {
    background: #e9ecef;
    border-left-color: #597d89;
    transform: translateX(5px);
}

.toc-link.toc-part:hover {
    background: #4a6a75;
    transform: translateX(5px);
}

.toc-link i {
    color: #597d89;
    font-size: 1.2rem;
    width: 25px;
    text-align: center;
}

.toc-link.active {
    background: #597d89;
    color: white;
}

.toc-link.active i {
    color: white;
}

/* ===== СОДЕРЖАНИЕ КНИГИ ===== */
.book-content {
    background: white;
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.1);
    margin-bottom: 50px;
    line-height: 1.8;
    font-style: normal;
}

/* Стили для частей */
.part {
    margin: 60px 0 40px 0;
    text-align: center;
    scroll-margin-top: 30px;
}

.part-header {
    border-top: 3px solid #597d89;
    border-bottom: 3px solid #597d89;
    padding: 40px 0;
}

.part-title {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 15px;
    font-weight: 700;
    font-style: normal;
}

.part-subtitle {
    font-size: 1.4rem;
    color: #597d89;
    font-style: normal;
}

/* Стили для глав */
.chapter {
    margin-bottom: 80px;
    scroll-margin-top: 30px;
}

.chapter:last-child {
    margin-bottom: 0;
}

.chapter-header {
    border-bottom: 3px solid #597d89;
    padding-bottom: 20px;
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.chapter-icon {
    background: #597d89;
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.chapter-title {
    font-size: 2rem;
    color: #2c3e50;
    margin: 0;
    font-style: normal;
}

/* Стили для текста глав */
.chapter-text {
    font-size: 1.15rem;
    line-height: 1.9;
    font-style: normal;
}

/* ВНИМАНИЕ: Каждый абзац должен быть обернут в <p></p> */
.chapter-text p {
    margin-bottom: 1.2rem;
    text-align: justify;
    text-indent: 0;
    font-style: normal;
}

/* ===== РАДИКАЛЬНО ИСПРАВЛЕННЫЕ СТИЛИ БУКВИЦЫ ===== */
.book-content .chapter .chapter-text p:first-of-type {
    position: relative;
    text-indent: 0 !important;
}

.book-content .chapter .chapter-text p:first-of-type::first-letter {
    font-size: 3.8em;
    font-weight: bold;
    color: #597d89;
    float: left;
    line-height: 0.75;
    margin-right: 8px;
    margin-top: 6px;
    margin-bottom: 2px;
    margin-left: 0 !important;
    font-family: 'Times New Roman', Georgia, serif;
    padding: 0 !important;
    shape-outside: none;
    display: block;
    position: relative;
    font-style: normal;
}

/* Принудительно убираем все возможные отступы */
.book-content .chapter .chapter-text p:first-of-type {
    overflow: visible !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
}

/* Стили для абзацев без отступа */
.chapter-text p.no-indent {
    text-indent: 0;
    font-style: normal;
}

/* ВНИМАНИЕ: Диалоги должны быть в <p class="dialogue"></p> */
.dialogue {
    margin-left: 1.5em !important;
    text-align: left !important;
    padding-left: 0.5em !important;
    text-indent: 0 !important;
    font-style: normal;
}

.dialogue + .dialogue {
    margin-top: -0.8rem !important;
}

/* ВНИМАНИЕ: Разделители сцен должны быть в <div class="scene-break">* * *</div> */
.scene-break {
    text-align: center;
    margin: 2.5rem 0;
    color: #597d89;
    font-size: 1.5rem;
    letter-spacing: 0.5em;
    font-weight: bold;
    line-height: 1;
    opacity: 0.7;
    font-style: normal;
}

/* Стили для выделенных цитат */
.chapter-text blockquote {
    margin: 2rem 0;
    padding: 1.5rem 2rem;
    background: #f8f9fa;
    border-left: 4px solid #597d89;
    color: #555;
    font-style: normal;
}

.chapter-text blockquote p {
    margin-bottom: 0.5rem;
    text-indent: 0;
    font-style: normal;
}

/* Стили для списков */
.chapter-text ul, 
.chapter-text ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

.chapter-text li {
    margin-bottom: 0.5rem;
    text-align: left;
    font-style: normal;
}

/* Стили для акцентированного текста */
.chapter-text strong {
    color: #2c3e50;
    font-weight: bold;
    font-style: normal;
}

.chapter-text em {
    color: #597d89;
    font-style: normal;
}

/* Стили для подчёркнутого текста */
.chapter-text u {
    text-decoration: underline;
    text-decoration-color: #597d89;
}

/* Стили для маленького текста */
.chapter-text small {
    font-size: 0.9em;
    color: #666;
    font-style: normal;
}

/* Стили для горизонтальной линии */
.chapter-text hr {
    border: none;
    height: 2px;
    background: linear-gradient(to right, transparent, #597d89, transparent);
    margin: 2.5rem 0;
}

/* Стили для кода */
.chapter-text code {
    background: #f8f9fa;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #2c3e50;
    font-style: normal;
}

/* Стили для предварительно отформатированного текста */
.chapter-text pre {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5rem 0;
    border-left: 4px solid #597d89;
    font-style: normal;
}

.chapter-text pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-style: normal;
}

/* ===== ПАНЕЛЬ ЧТЕНИЯ ===== */
.reading-controls {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    display: flex;
    gap: 12px;
    z-index: 1000;
}

.control-btn {
    width: 50px;
    height: 50px;
    border: none;
    background: #597d89;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    font-style: normal;
}

.control-btn:hover {
    background: #4a6a75;
    transform: scale(1.1);
}

/* ===== СЕКЦИЯ ПОКУПКИ ===== */
.purchase-section {
    background: white;
    padding: 50px;
    border-radius: 20px;
    text-align: center;
    margin-bottom: 50px;
    border: 3px solid #597d89;
    box-shadow: 0 15px 40px rgba(89, 125, 137, 0.15);
    position: relative;
    font-style: normal;
}

.purchase-section::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: linear-gradient(135deg, #597d89 0%, #2c3e50 100%);
    border-radius: 23px;
    z-index: -1;
}

.purchase-section h2 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 2rem;
    font-style: normal;
}

.purchase-section p {
    margin-bottom: 30px;
    font-size: 1.2rem;
    color: #666;
    line-height: 1.6;
    font-style: normal;
}

.formats-list {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin: 25px 0;
}

.format-item {
    background: #f8f9fa;
    padding: 12px 25px;
    border-radius: 30px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 2px solid #e9ecef;
    color: #597d89;
    font-weight: 600;
    font-style: normal;
}

.btn-buy-full {
    display: inline-block;
    background: #597d89;
    color: white;
    padding: 18px 50px;
    border-radius: 35px;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.3rem;
    transition: all 0.3s ease;
    border: 3px solid #597d89;
    box-shadow: 0 5px 20px rgba(89, 125, 137, 0.3);
    font-style: normal;
}

.btn-buy-full:hover {
    background: white;
    color: #597d89;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(89, 125, 137, 0.4);
}

/* ===== ПОДВАЛ ===== */
.fragment-footer {
    text-align: center;
    padding: 40px 0;
    color: #666;
    font-size: 1rem;
    border-top: 1px solid #eaeaea;
    margin-top: 30px;
    font-style: normal;
}

.back-to-books {
    display: inline-block;
    margin-top: 20px;
    color: #597d89;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    padding: 12px 25px;
    border: 2px solid #597d89;
    border-radius: 25px;
    transition: all 0.3s ease;
    font-style: normal;
}

.back-to-books:hover {
    background: #597d89;
    color: white;
    transform: translateY(-2px);
}

/* Улучшенные стили для диалогов */
.dialogue {
    margin-left: 1.5em !important;
    text-align: left !important;
    padding-left: 0.5em !important;
    font-style: normal;
}

.dialogue + .dialogue {
    margin-top: -0.8rem !important;
}

/* Улучшенные стили для разделителей сцен */
.scene-break {
    text-align: center !important;
    margin: 2.5rem 0 !important;
    color: #597d89 !important;
    font-size: 1.5rem !important;
    letter-spacing: 0.5em !important;
    font-weight: bold !important;
    line-height: 1 !important;
    opacity: 0.7 !important;
    font-style: normal;
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 1200px) {
    body {
        max-width: 900px;
    }
}

@media (max-width: 768px) {
    body {
        font-size: 17px;
        padding: 0 20px;
        max-width: 100%;
    }

    .fragment-header h1 {
        font-size: 2rem;
    }

    .chapter-title {
        font-size: 1.7rem;
    }

    .part-title {
        font-size: 2rem;
    }

    .book-content {
        padding: 35px;
    }

    .chapter-header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    .reading-controls {
        bottom: 20px;
        right: 20px;
        padding: 15px;
    }

    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }

    .purchase-section {
        padding: 40px 30px;
    }

    .floating-toc-btn {
        width: 55px;
        height: 55px;
        font-size: 1.2rem;
    }

    .toc-sidebar {
        width: 300px;
        left: -300px;
    }

    .book-meta {
        gap: 15px;
    }

    .dialogue {
        margin-left: 1em !important;
        padding-left: 0.5em !important;
    }

    .chapter-text p {
        text-indent: 0;
    }

    .scene-break {
        margin: 2rem 0;
        font-size: 1.3rem;
    }

    /* Адаптивная буквица для мобильных */
    .book-content .chapter .chapter-text p:first-of-type::first-letter {
        font-size: 3.2em;
        margin-right: 6px;
        margin-top: 4px;
        line-height: 0.8;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0 15px;
        font-size: 16px;
    }

    .fragment-header {
        padding: 40px 0;
    }

    .fragment-header h1 {
        font-size: 1.8rem;
    }

    .book-meta {
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    .book-content {
        padding: 25px 20px;
    }

    .chapter-text {
        font-size: 1.1rem;
        text-align: left;
    }

    .chapter-text p {
        text-indent: 0;
    }

    .formats-list {
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    .toc-sidebar {
        width: 280px;
        left: -280px;
        padding: 70px 20px 20px;
    }

    .floating-toc-btn {
        width: 50px;
        height: 50px;
        font-size: 1.1rem;
        top: 15px;
        left: 15px;
    }

    .dialogue {
        margin-left: 0.5em !important;
        padding-left: 0.3em !important;
    }

    .scene-break {
        margin: 2rem 0;
        font-size: 1.3rem;
    }

    /* Буквица для очень маленьких экранов */
    .book-content .chapter .chapter-text p:first-of-type::first-letter {
        font-size: 2.8em;
        margin-right: 4px;
        margin-top: 3px;
        line-height: 0.85;
    }
}

/* ===== ДОПОЛНИТЕЛЬНЫЕ СТИЛИ ===== */
.book-content {
    animation: fadeInUp 0.8s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chapter:target {
    background: linear-gradient(90deg, rgba(89, 125, 137, 0.1) 0%, transparent 100%);
    border-radius: 10px;
    padding: 20px;
    margin: -20px;
    transition: all 0.3s ease;
}

.chapter-text p {
    hyphens: auto;
    hyphenate-limit-chars: 6 3 2;
    hyphenate-limit-lines: 2;
    hyphenate-limit-last: always;
    hyphenate-limit-zone: 8%;
}

/* Стили для тёмной темы */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }
    
    .book-content {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .chapter-text {
        color: #e0e0e0;
    }
    
    .chapter-title {
        color: #ffffff;
    }
    
    .part-title {
        color: #ffffff;
    }
    
    .dialogue {
        border-left-color: #597d89;
    }
    
    .toc-sidebar {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .toc-link {
        background: #3d3d3d;
        color: #e0e0e0;
    }
    
    .toc-link:hover {
        background: #4d4d4d;
    }
    
    .reading-controls {
        background: #2d2d2d;
    }
    
    .purchase-section {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .format-item {
        background: #3d3d3d;
        color: #e0e0e0;
        border-color: #4d4d4d;
    }
    
    .book-content .chapter .chapter-text p:first-of-type::first-letter {
        color: #8bb4c4;
    }
}

/* Стили для режима уменьшения движения */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    html {
        scroll-behavior: auto;
    }
}

/* Стили для выделения текста */
::selection {
    background: rgba(89, 125, 137, 0.3);
    color: inherit;
}

::-moz-selection {
    background: rgba(89, 125, 137, 0.3);
    color: inherit;
}