:root {
    --bg: #ffffff;
    --text: #000000;
    --accent: #f0f0f0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'EB Garamond', 'Georgia', serif;
    margin: 0; padding: 20px;
}

header { text-align: center; margin-bottom: 40px; }

h1 { font-size: 4rem; letter-spacing: -2px; margin: 0; }

.subtitle {
    font-family: 'Inter', sans-serif;
    font-style: italic;
    font-size: 1.1rem;
    color: #666;
    margin-top: -10px;
    margin-bottom: 30px;
    letter-spacing: 1px;
    text-transform: lowercase;
}

.search-container { margin: 20px 0; text-align: center; }

#search-bar {
    width: 60%;
    padding: 10px;
    border: none;
    border-bottom: 2px solid var(--text);
    font-family: inherit;
    font-size: 1.2rem;
    outline: none;
    text-align: center;
}

/* --- Navigation & Filters --- */
#filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin: 30px auto;
    max-width: 1000px;
    padding: 0 20px;
}

.filter-btn {
    background: transparent;
    color: #000;
    border: 1px solid #000;
    padding: 8px 18px;
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.filter-btn:hover { background: #f0f0f0; transform: translateY(-1px); }
.filter-btn.active { background: #000; color: #fff; border-color: #000; }
.filter-btn:active { transform: scale(0.96); }

/* --- Layout Structure --- */
.main-layout {
    display: flex;
    gap: 20px;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* --- Desktop Grid (5 Columns) --- */
.masonry-grid {
    flex: 1;
    column-count: 5;
    column-gap: 15px;
    width: 100%;
}

.book-pill {
    display: inline-block;
    width: 100%;
    margin-bottom: 15px;
    border: 1px solid var(--text);
    padding: 15px;
    box-sizing: border-box;
    cursor: pointer;
    break-inside: avoid;
    transition: 0.2s;
}

.book-pill:hover { background: var(--text); color: var(--bg); }
.book-pill h3 { margin: 0; font-size: 1rem; text-transform: uppercase; line-height: 1.2; }

/* --- Sidebar Styling --- */
#desktop-sidebar {
    width: 200px;
    height: 90vh;
    position: sticky;
    top: 20px;
    overflow-y: auto;
    padding-left: 15px;
    border-left: 1px solid #ddd;
    display: none; /* Hidden on mobile by default */
}

@media (min-width: 1200px) {
    #desktop-sidebar { display: block; }
}

.sidebar-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }

.random-btn {
    background: #000; color: #fff; border: 1px solid #000;
    font-size: 0.65rem; padding: 8px; cursor: pointer;
    text-transform: uppercase; letter-spacing: 1px; transition: 0.2s;
}

.random-btn:hover { background: #fff; color: #000; }
.random-btn.alt { background: #fff; color: #000; }
.random-btn.alt:hover { background: #000; color: #fff; }

.sidebar-section h4 {
    font-family: 'Inter', sans-serif; font-size: 0.8rem;
    text-transform: uppercase; margin-bottom: 10px; border-bottom: 1px solid #000;
}

.side-filter {
    display: block; font-size: 0.6rem; color: #666;
    padding: 2px 0; cursor: pointer; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; transition: 0.2s;
}

.side-filter:hover, .side-filter.active { color: #000; font-weight: bold; }

/* --- Modal Logic --- */
#summary-modal, #summary-modal * { box-sizing: border-box; }

.modal {
    display: none; position: fixed; z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    overflow-y: auto; padding: 10px;
}

.modal-content {
    background-color: #fff; margin: 2vh auto; padding: 60px;
    border: 2px solid #000; width: 100%; max-width: 700px;
    position: relative; box-shadow: 0 20px 50px rgba(0,0,0,0.1);
    animation: slideIn 0.4s ease;
}

.close-modal {
    position: absolute; top: 20px; right: 30px;
    font-size: 2.5rem; font-weight: 200; cursor: pointer; line-height: 1;
}

.meta-data {
    font-family: 'Inter', sans-serif; font-size: 0.85rem;
    letter-spacing: 2px; text-transform: uppercase;
    border-bottom: 1px solid #eee; padding-bottom: 15px; margin-bottom: 25px;
}

.buy-btn {
    display: block; width: 100%; text-align: center; background: #000;
    color: #fff; padding: 20px; text-decoration: none;
    letter-spacing: 2px; font-weight: bold; margin-top: 40px; transition: 0.3s;
}

/* --- RESPONSIVE OVERRIDES --- */

/* Desktop & Tablet: Tall/Narrow Modal Logic */
@media (min-width: 769px) {
    .modal-content {
        max-width: 500px;    /* Narrower for reading elegance */
        min-height: 80vh;    /* Taller vertical profile */
        margin: 5vh auto;
        display: flex;
        flex-direction: column;
    }
}

/* Tablet: 4 Columns (up to 1024px) */
@media (max-width: 1024px) {
    .masonry-grid { column-count: 4; }
    .book-pill h3 { font-size: 0.9rem; } 
    #search-bar { width: 80%; }
    
    .modal-content { 
        width: 60%;          /* Narrower on tablet */
        padding: 40px; 
    }
}

/* Small Tablet: 3 Columns (up to 768px) */
@media (max-width: 768px) {
    .masonry-grid { column-count: 3; }
    h1 { font-size: 3rem; }
    .book-pill h3 { font-size: 0.85rem; }
    
    .modal-content { 
        width: 80%;          /* Slight width increase for smaller tablets */
        padding: 30px; 
    }
}

/* Mobile: 2 Columns (up to 480px) */
@media (max-width: 480px) {
    .masonry-grid {
        column-count: 2;
        column-gap: 8px;
        padding: 0 5px;
    }

    .book-pill { padding: 12px; margin-bottom: 10px; }
    .book-pill h3 { font-size: 0.8rem; }
    h1 { font-size: 2.2rem; }
    
    #search-bar { width: 95%; font-size: 1rem; }

    .modal-content {
        padding: 40px 20px 20px 20px;
        width: 100%;         /* Full width on mobile for readability */
        margin: 10px auto;
        border-width: 2px;
        min-height: auto;    /* Allow natural flow on small screens */
    }

    .close-modal { top: 10px; right: 15px; font-size: 2rem; }
    #modal-title { font-size: 1.6rem !important; word-wrap: break-word; }
    #modal-body { font-size: 1rem !important; line-height: 1.5; }
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}