:root {
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --accent-red: #ff0000;
    --accent-orange: #f97316;
    --accent-gold: #f59e0b;
    --accent-green: #00ff00;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid #334155;
    display: flex;
    flex-direction: column;
    height: 100%;
    flex-shrink: 0;
}
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #334155;
}
.back-btn {
    color: var(--accent-orange);
    text-decoration: none;
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 10px;
    display: inline-block;
    transition: color 0.2s;
}
.back-btn:hover { color: var(--accent-gold); }
.sidebar-title {
    font-family: 'Neucha', sans-serif;
    font-size: 28px;
    color: #ffffff;
    letter-spacing: 1px;
}
.toc-container {
    padding: 20px 10px 30px 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.toc-container::-webkit-scrollbar { width: 6px; }
.toc-container::-webkit-scrollbar-thumb {
    background-color: #475569;
    border-radius: 3px;
}

.toc-list { list-style: none; padding-left: 0; }
.toc-list a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 0;
    font-size: 16px;
    transition: color 0.2s, padding-left 0.2s;
}
.toc-list a:hover, .toc-list a.active {
    color: var(--accent-gold);
    padding-left: 4px;
}
.level-1 {
    font-weight: 600;
    margin-top: 15px;
    color: #ffffff !important;
    font-size: 18px;
    display: block;
    text-decoration: none;
}
.level-1:hover { color: var(--accent-orange) !important; }
.level-2 { margin-left: 20px; font-size: 16px; }

/* Основная область */
.content-area {
    flex-grow: 1;
    padding: 40px 60px;
    overflow-y: auto;
    height: 100%;
}

.content-area::-webkit-scrollbar { width: 8px; }
.content-area::-webkit-scrollbar-thumb {
    background-color: #334155;
    border-radius: 4px;
}

h1 {
    font-family: 'Neucha', sans-serif;
    font-size: 48px;
    color: var(--accent-orange);
    border-bottom: 2px solid #334155;
    padding-bottom: 10px;
    margin-bottom: 30px;
}

/* Галерея */
.bg-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.bg-item {
    background-color: rgba(15, 23, 42, 0.8);
    border: 1px solid #334155;
    border-radius: 6px;
    overflow: hidden;
    transition: all 0.25s ease;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    flex-direction: column;
}

.bg-item:hover {
    border-color: var(--accent-orange);
    transform: translateY(-6px);
    box-shadow: 0 12px 25px rgba(249, 115, 22, 0.2);
}

.bg-header {
    display: flex;
    gap: 8px;
    padding: 11px 16px;
    background-color: #1e293b;
    border-bottom: 1px solid #334155;
}
.folder-icon {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.bg-item .img-container {
    position: relative;
    padding-top: 56.25%;
    background-color: #0f172a;
    overflow: hidden;
    flex-grow: 1;
}

.bg-item img {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.bg-item:hover img { transform: scale(1.05); }

.bg-info {
    padding: 12px 14px;
    background-color: #1e293b;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bg-name {
    font-family: 'Neucha', sans-serif;
    font-size: 17px;
    color: var(--accent-gold);
    margin: 0;
    text-align: left;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
    font-family: 'Segoe UI', sans-serif;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    flex-shrink: 0;
}

.download-btn:hover {
    background: var(--accent-green);
    color: #0f172a;
}

/* Лайтбокс */
#lightbox {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.96);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    flex-direction: column;
}

#lightbox.active { display: flex; }

.lightbox-wrapper {
    position: relative;
    max-width: 95%;
    text-align: center;
}

#lightbox img {
    max-width: 100%;
    max-height: 82vh;
    border: 3px solid #f59e0b;
    box-shadow: 0 0 40px rgba(0,0,0,0.9);
    border-radius: 4px;
    margin-bottom: 15px;
}

#lightboxCaption {
    color: #e2e8f0;
    font-family: 'Neucha', sans-serif;
    font-size: 20px;
    padding: 10px 20px;
    background: rgba(30, 41, 59, 0.9);
    border-radius: 6px;
    max-width: 90%;
    margin: 0 auto;
    border: 1px solid #475569;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    width: 50px;
    height: 80px;
    font-size: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s;
}

.lightbox-nav:hover { background: rgba(249, 115, 22, 0.8); }
#prev { left: -60px; border-radius: 8px 0 0 8px; }
#next { right: -60px; border-radius: 0 8px 8px 0; }

/* Скрываем мобильные элементы на десктопе */
.mobile-menu-btn, .sidebar-overlay {
    display: none;
}

/* ================= MOBILE (Адаптивные стили) ================= */
@media (max-width: 768px) {
    body { 
        flex-direction: column; 
        overflow-x: hidden; 
        overflow-y: auto; 
        height: auto; 
    }

    /* Кнопка вызова оглавления */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1000;
        background-color: var(--accent-orange);
        color: #ffffff;
        border: none;
        padding: 12px 20px;
        border-radius: 50px;
        font-weight: bold;
        font-size: 16px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
        cursor: pointer;
        transition: transform 0.2s, background-color 0.2s;
    }

    .mobile-menu-btn:active {
        transform: scale(0.95);
    }

    /* Выдвижная левая панель */
    .sidebar { 
        position: fixed;
        top: 0;
        left: 0;
        width: 280px; 
        height: 100vh; 
        z-index: 1001;
        border-right: none; 
        border-bottom: 1px solid #334155; 
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 4px 0 15px rgba(0,0,0,0.5);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Затеняющая подложка */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.6);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease-in-out;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .content-area { 
        padding: 20px 16px 80px 16px; 
        height: auto; 
        overflow-y: visible; 
    }
    
    h1 {
        font-size: 34px;
        margin-bottom: 20px;
    }

    /* Адаптивная сетка карточек */
    .bg-gallery {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 15px;
    }

    /* Настройка лайтбокса для мобильных */
    #lightbox { padding: 10px; }
    #lightbox img { max-height: 70vh; }
    .lightbox-nav {
        width: 40px;
        height: 60px;
        font-size: 24px;
        background: rgba(0,0,0,0.7);
    }
    #prev { left: 5px; border-radius: 4px; }
    #next { right: 5px; border-radius: 4px; }
}