/* =========================================
 *  1. БАЗОВЫЕ НАСТРОЙКИ И ПЕРЕМЕННЫЕ
 *  ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --paper-bg: #f4ecd8;
    --paper-content: #fdf6e3;
    --ink-color: #2c241b;
    --accent-red: #800000;
    --highlight-yellow: #ffd54f;
}

body {
    background-color: var(--paper-bg);
    color: var(--ink-color);
    font-family: 'Merriweather', serif;
    line-height: 1.8;
    margin: 0;
    padding: 20px;
    background-image: url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="4" stitchTiles="stitch"/></filter><rect width="100" height="100" filter="url(%23noise)" opacity="0.05"/></svg>');
}

/* =========================================
 *  2. КАСТОМНЫЙ СКРОЛЛБАР
 *  ========================================= */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(128, 0, 0, 0.5) rgba(128, 0, 0, 0.05);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(128, 0, 0, 0.05);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(128, 0, 0, 0.4);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 0, 0, 0.8);
}

/* =========================================
 *  3. ЕДИНОЕ МЕНЮ НАВИГАЦИИ
 *  ========================================= */
.unified-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 0 auto 30px auto;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(128, 0, 0, 0.2);
    max-width: 800px;
}

.nav-link {
    text-decoration: none;
    color: var(--accent-red);
    font-weight: bold;
    font-family: 'Playfair Display', serif;
    font-size: 1.2rem;
    transition: opacity 0.3s, transform 0.2s;
}

.nav-link:hover {
    opacity: 0.7;
    transform: scale(1.05);
}

.nav-separator {
    color: var(--ink-color);
    font-size: 1.2rem;
    opacity: 0.5;
}

/* =========================================
 *  4. ОБЩИЕ ЭЛЕМЕНТЫ
 *  ========================================= */
.book-title-container {
    text-align: center;
    font-family: 'Playfair Display', serif;
    margin-bottom: 40px;
    line-height: 1.3;
}

.title-main {
    font-size: 2.8rem;
    font-weight: bold;
    color: var(--accent-red);
    margin-bottom: 15px;
}

.title-sub {
    font-size: 1.3rem;
    color: var(--ink-color);
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.title-author {
    font-size: 1.2rem;
    font-style: italic;
    color: var(--ink-color);
}

.book-decoration {
    text-align: center;
    font-size: 1.5rem;
    color: var(--accent-red);
    margin-bottom: 40px;
}

.read-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 10px 20px;
    background-color: var(--accent-red);
    color: var(--paper-bg);
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
    font-family: sans-serif;
    transition: opacity 0.2s;
}

.read-btn:hover {
    opacity: 0.8;
}

.btn-small {
    font-size: 0.9rem;
    padding: 6px 12px;
}

/* =========================================
 *  5. СТРАНИЦА СЛОВАРЯ (index.html)
 *  ========================================= */
body.dictionary-page {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.unified-nav, .dict-header {
    flex-shrink: 0;
}

.dict-header {
    text-align: center;
    margin-bottom: 30px;
}

.dict-header h1 {
    font-family: 'Playfair Display', serif;
    color: var(--accent-red);
    margin: 0 0 10px 0;
    font-size: 2.5rem;
}

.dict-header h2 {
    font-size: 1.2rem;
    font-weight: normal;
    color: var(--ink-color);
    margin-top: 0;
}

#search-input {
width: 100%;
max-width: 600px;
padding: 12px 25px;
font-size: 1.1rem;
font-family: 'Merriweather', serif;
border: 2px solid var(--accent-red);
border-radius: 25px;
background-color: var(--paper-content);
color: var(--ink-color);
outline: none;
margin-top: 15px;
transition: box-shadow 0.3s;
}

#search-input:focus {
box-shadow: 0 0 10px rgba(128, 0, 0, 0.3);
}

.dict-container {
    display: flex;
    flex-grow: 1;
    min-height: 0;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto 20px auto;
    background-color: var(--paper-content);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(128, 0, 0, 0.2);
}

.dict-sidebar {
    width: 35%;
    height: 100%;
    border-right: 1px solid rgba(128, 0, 0, 0.2);
    overflow-y: auto;
    background-color: rgba(253, 246, 227, 0.5);
}

.word-item {
    padding: 15px 20px;
    cursor: pointer;
    border-bottom: 1px solid rgba(128, 0, 0, 0.1);
    transition: background-color 0.2s, padding-left 0.2s;
    font-weight: bold;
}

.word-item:hover {
    background-color: rgba(218, 165, 32, 0.2);
    padding-left: 25px;
}

.word-item.active {
    background-color: var(--accent-red);
    color: var(--paper-bg);
}

.dict-detail {
    width: 65%;
    height: 100%;
    padding: 40px;
    overflow-y: auto;
}

.empty-state {
    text-align: center;
    color: rgba(44, 36, 27, 0.5);
    margin-top: 20%;
    font-style: italic;
}

.detail-title {
    font-family: 'Playfair Display', serif;
    font-size: 2.5rem;
    color: var(--accent-red);
    margin-top: 0;
    border-bottom: 2px solid var(--highlight-yellow);
    padding-bottom: 10px;
}

.detail-definition {
    font-size: 1.2rem;
    line-height: 1.6;
    margin-bottom: 30px;
}

.example-box {
    background-color: rgba(218, 165, 32, 0.1);
    padding: 15px 20px;
    border-left: 4px solid var(--accent-red);
    margin-bottom: 15px;
    font-style: italic;
}

.example-box p {
    margin-top: 0;
    margin-bottom: 10px;
}

/* =========================================
 *  6. СТРАНИЦА ОРИГИНАЛА (reader.html)
 *  ========================================= */
.manuscript-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 50px 60px;
    background-color: var(--paper-content);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.rule-block {
    text-align: justify;
    margin-bottom: 25px;
    font-size: 1.1rem;
    padding: 15px;
    border-radius: 5px;
    transition: background-color 1s ease;
}

.drop-cap {
    font-family: 'Playfair Display', serif;
    font-size: 3.5rem;
    float: left;
    line-height: 0.9;
    margin-right: 10px;
    margin-top: 5px;
    color: var(--accent-red);
}

.active-rule {
    background-color: rgba(218, 165, 32, 0.15);
    box-shadow: inset 4px 0 0 var(--accent-red);
}

mark.highlighted-word {
    background-color: var(--highlight-yellow);
    color: #000;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
}

/* =========================================
 *  7. СТРАНИЦА АНАЛИТИКИ (analytics.html)
 *  ========================================= */
.analytics-container {
    max-width: 900px;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.chart-card {
    background-color: rgba(253, 246, 227, 0.8);
    border: 1px solid rgba(128, 0, 0, 0.2);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.chart-card h3 {
    font-family: 'Playfair Display', serif;
    color: var(--accent-red);
    text-align: center;
    margin-top: 0;
    border-bottom: 1px solid rgba(128, 0, 0, 0.1);
    padding-bottom: 10px;
}

.chart-wrapper {
    position: relative;
    height: 360px;
    width: 100%;
    margin-top: 15px;
}

/* ЗАЩИТА ОТ ВЫЛЕЗАНИЯ ГРАФИКОВ ЗА РАМКИ */
.chart-wrapper canvas {
    max-width: 100% !important;
}

.wordcloud-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9; /* Жестко держим пропорции для заполнения */
    max-height: 550px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#wordCloudCanvas {
width: 100%;
height: 100%;
display: block;
}

/* =========================================
 *  8. АДАПТИВНОСТЬ (Для телефонов)
 *  ========================================= */
@media (max-width: 768px) {
    body.dictionary-page {
        height: auto;
        overflow: auto;
    }
    .dict-container {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    .dict-sidebar {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 2px solid var(--accent-red);
    }
    .dict-detail {
        width: 100%;
        padding: 20px;
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .manuscript-container {
        padding: 20px;
    }
}
