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

html, body {
    height: 100%;
}

body {
    font-family: 'Georgia', serif;
    background: #0a0a1a;
    color: #e8e8f0;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Хедер */
.site-header {
    padding: 15px 0;
    margin-top: 15px;
    margin-bottom: -5px;
    position: relative;
    z-index: 997;
    flex-shrink: 0;
    background: rgba(15, 15, 35, 0.98);
    border-bottom: 1px solid #44446a;
    backdrop-filter: blur(10px);
}

.site-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(135deg, rgba(138, 122, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    text-align: right;
    padding-right: 50px;
}

.header-content em {
    font-size: 16px;
    font-style: italic;
    color: #d8d8ff;
    opacity: 1;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.5px;
}

/* Боковое меню */
.sidebar {
    position: fixed;
    top: 0;
    left: -380px;
    width: 380px;
    height: 100vh;
    background: linear-gradient(135deg, #1a1a2a 0%, #2a2a3a 100%);
    transition: left 0.4s ease;
    z-index: 1000;
    padding: 80px 30px 40px 30px;
    border-right: 1px solid #44446a;
    box-shadow: 2px 0 25px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
}

.sidebar.active {
    left: 0;
}

.sidebar.active ~ .menu-toggle {
    left: 400px;
}

/* Затемнение сайдбара */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

/* Кнопка оглавление */
.menu-toggle {
    position: fixed;
    top: 20px;
    left: 30px;
    z-index: 1001;
    background: rgba(138, 122, 255, 0.95);
    border: none;
    color: white;
    padding: 12px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Georgia', serif;
    font-size: 16px;
    transition: all 0.3s ease;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(138, 122, 255, 0.3);
    min-width: 140px;
    height: auto;
    line-height: 1.4;
}

/* Кнопка переключения темы */
.theme-toggle {
    position: fixed;
    top: 20px;
    left: 190px;
    z-index: 1001;
    background: rgba(138, 122, 255, 0.95);
    border: none;
    color: white;
    padding: 0;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Georgia', serif;
    font-size: 20px;
    transition: all 0.3s ease;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(138, 122, 255, 0.3);
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.menu-toggle:hover,
.theme-toggle:hover {
    background: rgba(138, 122, 255, 1);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(138, 122, 255, 0.4);
}

/* Сдвигаем кнопки при активном сайдбаре */
.sidebar.active ~ .menu-toggle {
    left: 400px;
}

.sidebar.active ~ .theme-toggle {
    left: 560px;
}

.menu-header {
    margin-bottom: 40px;
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid #44446a;
}

.menu-title {
    font-size: 28px;
    font-weight: 700;
    color: #b8b8ff;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.menu-subtitle {
    font-size: 16px;
    color: #d8d8f0;
    opacity: 0.9;
    line-height: 1.4;
}

.toc-section {
    margin-bottom: 35px;
}

.toc-title {
    font-size: 16px;
    font-weight: 600;
    color: #a0a0ff;
    margin-bottom: 18px;
    border-left: 3px solid #8a7aff;
    padding-left: 15px;
    text-transform: none;
    letter-spacing: 0.5px;
    line-height: 1.4;
    white-space: normal;
    word-wrap: break-word;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.toc-list {
    list-style: none;
}

.toc-item {
    margin-bottom: 15px;
}

.toc-link {
    color: #e8e8f0;
    text-decoration: none;
    font-size: 16px;
    transition: all 0.3s ease;
    display: block;
    padding: 12px 18px;
    border-radius: 8px;
    line-height: 1.5;
    white-space: normal;
    word-wrap: break-word;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toc-link:hover {
    color: #ffffff;
    background: rgba(138, 122, 255, 0.2);
    transform: translateX(8px);
    border-color: #8a7aff;
    box-shadow: 0 4px 12px rgba(138, 122, 255, 0.2);
}

.toc-link.active {
    color: #ffffff;
    background: rgba(138, 122, 255, 0.25);
    border-left: 4px solid #8a7aff;
    box-shadow: 0 4px 12px rgba(138, 122, 255, 0.15);
}

/* Основной контент */
.main-content {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    z-index: 2;
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
}

.page-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at 20% 80%, #1a1a3a 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, #2a1a4a 0%, transparent 50%),
        linear-gradient(135deg, #0a0a1a 0%, #1a1a2a 100%);
    border: 1px solid #33334a;
    box-shadow: 0 0 50px rgba(100, 80, 255, 0.1);
    margin: 5px auto 20px;
    padding: 25mm 20mm;
    min-height: auto;
    overflow: hidden;
}

/* Декоративные космические элементы */
.cosmic-element {
    position: absolute;
    background: radial-gradient(circle, #4a3aff 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0.1;
}

.cosmic-element:nth-child(1) {
    width: 300px;
    height: 300px;
    top: -150px;
    right: -100px;
}

.cosmic-element:nth-child(2) {
    width: 200px;
    height: 200px;
    bottom: -50px;
    left: -50px;
    background: radial-gradient(circle, #ff3a8c 0%, transparent 70%);
}

/* Основной контент */
.content-wrapper {
    position: relative;
    z-index: 2;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chapter-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Футер сайта */
.site-footer {
    padding: 25px 0;
    border-top: 1px solid #44446a;
    background: rgba(15, 15, 35, 0.98);
    position: relative;
    z-index: 3;
    width: 100%;
    flex-shrink: 0;
    backdrop-filter: blur(10px);
}

.site-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(135deg, transparent 0%, rgba(138, 122, 255, 0.1) 100%);
    pointer-events: none;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    color: #d8d8f0;
    opacity: 1;
    font-weight: 500;
}

.footer-left, .footer-right {
    opacity: 1;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Эффекты при наведении */
.footer-left:hover,
.footer-right:hover {
    color: #a0a0ff;
    transition: color 0.3s ease;
}

.header-content em:hover {
    color: #ffffff;
    transition: color 0.3s ease;
}

/* Стили для Telegram ссылки в футере */
.footer-right a {
    color: #d8d8f0 !important;
    font-size: 16px !important;
    text-decoration: none !important;
    opacity: 1;
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    white-space: nowrap !important;
}

.footer-right a:hover {
    color: #a0a0ff !important;
    transform: translateY(-1px);
}

/* Левый логотип */
.footer-left-logo {
    height: 25px;
    width: auto;
    margin-right: 6px !important;
    vertical-align: middle;
}

/* Правый логотип - БОЛЬШОЙ */
.footer-right-logo {
    height: 40px !important;
    width: auto !important;
    margin-left: 2px !important;
    vertical-align: middle !important;
    filter: none !important;
}

/* Иконка Telegram */
.footer-right a img:first-child {
    width: 20px !important;
    height: 20px !important;
    filter: brightness(0) invert(1);
    opacity: 0.9;
    transition: all 0.3s ease;
}

.footer-right a:hover img {
    opacity: 1;
    transform: scale(1.1);
}

/* Адаптивность */
@media (max-width: 1024px) {
    .page-container {
        padding: 20mm 15mm;
    }
    .header-content em {
        font-size: 15px;
    }
    .footer-content {
        font-size: 15px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 320px;
        left: -320px;
        padding: 70px 20px 30px 20px;
    }
    .menu-title {
        font-size: 24px;
    }
    .menu-subtitle {
        font-size: 14px;
    }
    .toc-title {
        font-size: 15px;
    }
    .toc-link {
        font-size: 15px;
        padding: 10px 15px;
    }
    .site-header {
        padding: 12px 0;
        margin-top: 10px;
    }
    .header-content {
        text-align: center;
        padding-right: 20px;
        padding-left: 60px;
    }
    .header-content em {
        font-size: 14px;
    }
    .site-footer {
        padding: 20px 0;
    }
    .footer-content {
        font-size: 14px;
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    .toc-title {
        font-size: 13px;
    }
    .toc-link {
        font-size: 13px;
        padding: 8px 12px;
    }
    .main-content {
        padding: 0 15px 15px;
    }
    .page-container {
        padding: 15mm 10mm;
        margin: 5px auto 15px;
    }
    .header-content {
        text-align: center;
        padding-right: 20px;
        padding-left: 180px;
    }
    .menu-toggle {
        top: 17px;
        left: 20px;
        padding: 10px 15px;
        font-size: 13px;
        min-width: 120px;
    }
    .theme-toggle {
        top: 17px;
        left: 150px;
        font-size: 18px;
        width: 40px;
        height: 40px;
    }
    .sidebar.active ~ .menu-toggle {
        left: 340px;
    }
    .sidebar.active ~ .theme-toggle {
        left: 470px;
    }

    /* Адаптивность футера */
    .footer-right-logo {
        height: 35px !important;
        margin-left: 4px !important;
    }

    .footer-left-logo {
        height: 22px;
        margin-right: 4px !important;
    }

    .footer-right a {
        font-size: 14px !important;
        gap: 4px !important;
    }

    .footer-right a img:first-child {
        width: 16px !important;
        height: 16px !important;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 280px;
        left: -280px;
        padding: 60px 15px 25px 15px;
    }
    .sidebar.active ~ .menu-toggle {
        left: 295px;
    }
    .menu-title {
        font-size: 22px;
    }
    .menu-subtitle {
        font-size: 13px;
    }
    .toc-title {
        font-size: 14px;
    }
    .toc-link {
        font-size: 14px;
        padding: 8px 12px;
    }
    .page-container {
        padding: 10mm 8mm;
        margin: 5px auto 10px;
    }
    .header-content {
        text-align: center;
        padding-right: 15px;
        padding-left: 150px;
    }
    .header-content em {
        font-size: 13px;
    }
    .site-header {
        margin-top: 10px;
    }
    .site-footer {
        padding: 15px 0;
    }
    .menu-toggle {
        top: 12px;
        left: 15px;
        padding: 8px 12px;
        font-size: 14px;
        min-width: 100px;
    }
    .main-content {
        padding: 0 10px 10px;
    }
    .theme-toggle {
        top: 12px;
        left: 125px;
        font-size: 16px;
        width: 35px;
        height: 35px;
    }
    .sidebar.active ~ .menu-toggle {
        left: 295px;
    }
    .sidebar.active ~ .theme-toggle {
        left: 405px;
    }

    /* Адаптивность футера */
    .footer-left-logo {
        margin-right: 3px !important;
        height: 20px;
    }

    .footer-right-logo {
        height: 30px !important;
        margin-left: 3px !important;
    }

    .footer-right a {
        gap: 3px !important;
    }
}

/* ========================================================================= */
/* СВЕТЛАЯ ТЕМА */
/* ========================================================================= */

body.light-theme {
    background: #e8eaf6;
    color: #2a2a2a;
}

body.light-theme .site-header {
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid #d1d1e0;
}

body.light-theme .site-header::before {
    background: linear-gradient(135deg, rgba(138, 122, 255, 0.15) 0%, transparent 50%);
}

body.light-theme .header-content em {
    color: #5a5a7a;
}

body.light-theme .page-container {
    background:
        radial-gradient(circle at 20% 80%, #ffffff 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, #fafaff 0%, transparent 50%),
        linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
    border: 1px solid #d1d1e0;
    box-shadow: 0 0 50px rgba(100, 80, 255, 0.1);
}

body.light-theme .site-footer {
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid #d1d1e0;
}

body.light-theme .site-footer::before {
    background: linear-gradient(135deg, transparent 0%, rgba(138, 122, 255, 0.15) 100%);
}

body.light-theme .footer-content {
    color: #5a5a7a;
}

body.light-theme .footer-left,
body.light-theme .footer-right a {
    color: #5a5a7a !important;
}

body.light-theme .footer-right a:hover {
    color: #8a7aff !important;
}

/* СВЕТЛАЯ ТЕМА: левый лого темнеет */
body.light-theme .footer-left-logo {
    filter: brightness(0) saturate(100%) opacity(0.8);
}

/* СВЕТЛАЯ ТЕМА: Telegram иконка темная */
body.light-theme .footer-right a img:first-child {
    filter: brightness(0) saturate(100%) opacity(0.8);
}

/* Правый логотип ВСЕГДА без фильтров */
body.light-theme .footer-right-logo {
    filter: none !important;
}

/* Кнопка переключения темы в светлой теме */
body.light-theme .theme-toggle {
    background: rgba(138, 122, 255, 0.9);
    box-shadow: 0 4px 12px rgba(138, 122, 255, 0.25);
}

body.light-theme .theme-toggle:hover {
    background: rgba(138, 122, 255, 1);
    box-shadow: 0 6px 16px rgba(138, 122, 255, 0.35);
}

/* Светлая тема для сайдбара */
body.light-theme .sidebar {
    background: linear-gradient(135deg, #ffffff 0%, #f5f5ff 100%);
    border-right: 1px solid #d1d1e0;
}

body.light-theme .menu-header {
    border-bottom: 1px solid #e0e0f0;
}

body.light-theme .menu-title {
    color: #6a5acd;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body.light-theme .menu-subtitle {
    color: #5a5a7a;
}

body.light-theme .toc-title {
    color: #8a7aff;
    border-left: 3px solid #8a7aff;
}

body.light-theme .toc-link {
    color: #5a5a7a;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(138, 122, 255, 0.2);
}

body.light-theme .toc-link:hover {
    color: #6a5acd;
    background: rgba(138, 122, 255, 0.1);
    border-color: #8a7aff;
}

body.light-theme .toc-link.active {
    color: #6a5acd;
    background: rgba(138, 122, 255, 0.15);
    border-left: 4px solid #8a7aff;
}
