:root {
    --bg-color: #0d1117;
    --card-bg: #161b22;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --border: #30363d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    padding: 2rem;
}

/* ===== HEADER ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    /* Mobile friendly */
    gap: 1rem;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    width: 250px;
}

.btn,
.toolbar-btn,
.toolbar-select,
.theme-select {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover,
.toolbar-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.stats {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ===== TABS ===== */
.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    overflow-x: auto;
    /* Scroll on mobile */
    padding-bottom: 5px;
}

.tabs2 {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    overflow-x: auto;
    /* Scroll on mobile */
    margin-left: 700px;
    padding-bottom: 5px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    padding: 0.5rem 0;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
}

.tab-btn.active {
    font-weight: 600;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent);
}

/* ===== LAYOUT ===== */
main {
    display: grid;
    grid-template-columns: 250px 1fr;
    grid-template-areas: "sidebar viewer";
    gap: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* SIDEBAR */
#sidebar {
    grid-area: sidebar;
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border);
    height: fit-content;
    max-height: 80vh;
    overflow-y: auto;
    position: sticky;
    top: 2rem;
}

#viewer {
    grid-area: viewer;
}

.author-group {
    margin-bottom: 0.5rem;
}

.author-header {
    font-size: 0.95rem;
    color: var(--text-muted);
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    border-radius: 4px;
}

.author-header:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.painting-items {
    list-style: none;
    display: none;
    padding-left: 0.5rem;
}

.author-group.expanded .painting-items {
    display: block;
}

.painting-item {
    padding: 0.4rem 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.painting-item:hover {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent);
}

.painting-item.active {
    background: var(--accent);
}

/* GALLERY GRID */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--grid-size, 250px), 1fr));
    gap: 1.5rem;
    align-content: start;
}

.grid-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
}

.grid-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--accent);
}

.grid-item img {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    display: block;
}

.grid-item span {
    /* Title */
    padding: 0.8rem;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.fav-star {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    padding: 5px;
    cursor: pointer;
    z-index: 10;
    font-size: 1rem;
    line-height: 1;
}

.fav-star.active {
    color: gold;
}

/* DETAIL VIEW */
.frame-container {
    padding: 1rem;
    border-radius: 8px;
    max-width: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.p-info {
    max-width: 800px;
    margin: 0 auto;
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.p-info h2 {
    margin-bottom: 1rem;
    color: var(--accent);
}

.detail-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
}

.detail-btn {
    padding: 0.5rem 1rem;
    background: var(--border);
    color: var(--text-main);
    text-decoration: none;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
}

.detail-btn:hover {
    background: var(--accent);
    color: #fff;
}

/* BOOKS GRID */
.books-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 800px;
}

.book-item {
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.book-item:hover {
    border-color: var(--accent);
}

.book-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: var(--text-main);
}

.book-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    gap: 1rem;
}

/* RESPONSIVE */
@media (max-width: 800px) {
    main {
        grid-template-columns: 1fr;
        grid-template-areas:
            "sidebar"
            "viewer";
    }

    #sidebar {
        max-height: 40vh;
        position: relative;
        top: 0;
        margin-bottom: 2rem;
    }
}

/* LIGHTBOX & READER */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.lightbox.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.lightbox-img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

.close-btn,
.lightbox-close {
    /* mapped just in case */
    position: absolute;
    top: 2rem;
    right: 2rem;
    color: #fff;
    font-size: 3rem;
    cursor: pointer;
    opacity: 0.7;
    border: none;
    background: none;
}

.prev-btn,
.next-btn,
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: none;
    padding: 1rem;
    cursor: pointer;
    font-size: 2rem;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.prev-btn,
.lightbox-nav.prev {
    left: 2rem;
}

.next-btn,
.lightbox-nav.next {
    right: 2rem;
}

.reader-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.reader-modal.active {
    display: flex;
}

.reader-content {
    background: #fff;
    width: 100%;
    max-width: 600px;
    height: 90vh;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #333;
    font-family: 'Merriweather', serif;
}

.reader-header {
    padding: 1rem;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9f9f9;
}

.reader-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    line-height: 1.6;
    font-size: 1.1rem;
}

.reader-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== THEMES ===== */
body.theme-light {
    --bg-color: #ffffff;
    --card-bg: #f6f8fa;
    --text-main: #24292f;
    --text-muted: #57606a;
    --border: #d0d7de;
    --accent: #0969da;
}

body.theme-light .book-title {
    color: #0550ae;
}

body.theme-light .painting-item:hover {
    background: #e6f2ff;
}

/* Space Theme */
body.theme-space {
    --bg-color: #0b0c15;
    --card-bg: rgba(22, 27, 34, 0.7);
    --text-main: #e6edf3;
    --text-muted: #8b949e;
    --border: rgba(48, 54, 61, 0.7);
    --accent: #58a6ff;
    background-image: radial-gradient(circle at 50% 50%, #1b1f2e 0%, #0b0c15 100%);
    background-attachment: fixed;
}

body.theme-space .grid-item,
body.theme-space .p-info,
body.theme-space #sidebar {
    backdrop-filter: blur(10px);
}



.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s;
}