.books-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    text-align: left;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #D1D5DB;
}

.books-container h1 {
    font-size: 2em;
    color: white;
    margin-top: max(48px, env(safe-area-inset-top, 48px));
    padding-top: 20px;
    position: relative;
    z-index: 1;
}

.books-container p {
    font-size: 1em;
    margin-bottom: 30px; /* Increased space after the intro text */
    color: #D1D5DB;
}

.latest-reads, .favorite-reads {
    margin: 0; /* Remove negative margins */
    padding: 0 20px; /* Add padding instead */
}

.latest-reads h2, .favorite-reads h2 {
    font-size: 1.5em;
    color: white;
    font-weight: 300;
    margin: 30px 20px 15px; /* Added horizontal padding to align with container */
} 

.back-button {
    position: fixed;
    top: max(20px, env(safe-area-inset-top, 20px));
    left: max(20px, env(safe-area-inset-left, 20px));
    color: #666;
    text-decoration: none;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s ease;
    z-index: 2;
}

.back-button:hover {
    color: white;
}

.scroll-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0 40px; /* Add margin to make space for arrows */
}

.scroll-container {
    display: flex;
    overflow-x: auto;
    gap: 5px;
    flex-grow: 1;
    scroll-behavior: smooth;
    padding: 10px 0; /* Remove horizontal padding */
    scrollbar-width: none;
    -ms-overflow-style: none;
    min-height: 240px;
    /* Add padding to prevent books from touching arrows */
    padding-left: 5px;
    padding-right: 5px;
    /* Ensure content doesn't overflow */
    scroll-padding: 0 40px;
}

.scroll-container::-webkit-scrollbar {
    display: none;
}

.book {
    flex: 0 0 auto;
    width: 120px;
    text-align: center;
    color: #D1D5DB;
    transition: transform 0.2s ease;
    padding: 5px;
}

.book:hover {
    transform: translateY(-5px);
}

.book-cover {
    width: 100px;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: box-shadow 0.2s ease;
    margin-bottom: 8px;
}

.book:hover .book-cover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-top: 8px;
}

.book-tag {
    font-size: 0.7rem;
    color: white;
    padding: 4px 0;
    border-radius: 4px;
    display: inline-block;
    font-weight: 500;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.scroll-arrow {
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    padding: 12px;
    cursor: pointer;
    z-index: 10;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
    position: absolute;
    /* Ensure arrows are outside the scroll area */
    top: 50%;
    transform: translateY(-50%);
}

.scroll-arrow.left {
    left: -40px; /* Position further outside */
}

.scroll-arrow.right {
    right: -40px; /* Position further outside */
}

/* Add a gradient fade effect on the edges */
.scroll-wrapper::before,
.scroll-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    pointer-events: none;
    z-index: 1;
}

.scroll-wrapper::before {
    left: 0;
    background: linear-gradient(to right, #18181B 0%, transparent 100%);
}

.scroll-wrapper::after {
    right: 0;
    background: linear-gradient(to left, #18181B 0%, transparent 100%);
}

/* Add smooth transitions for hover states */
.book, .book-cover, .book-tag, .scroll-arrow {
    transition: all 0.2s ease-in-out;
}

/* Media query for smaller screens */
@media (max-width: 640px) {
    .book {
        width: 100px;
    }
    
    .book-cover {
        width: 80px;
        height: 120px;
    }
    
    .book-tag {
        width: 70px;
        font-size: 0.65rem;
    }
}

/* Media queries for iPhone 10 and up (375px and above) */
@media screen and (max-width: 767px) {
    .books-container {
        max-width: 100%;
        padding: 16px;
        margin-top: 20px;
    }

    .books-container h1 {
        font-size: 1.75em;
        margin-bottom: 16px;
    }

    .books-container p {
        font-size: 0.95em;
        margin-bottom: 24px;
        padding-right: 16px;
    }

    .latest-reads, .favorite-reads {
        padding: 0 8px;
    }

    .latest-reads h2, .favorite-reads h2 {
        font-size: 1.25em;
        margin: 24px 12px 12px;
    }

    .scroll-wrapper {
        margin: 0 32px; /* Slightly reduced margin for arrows */
    }

    .scroll-container {
        gap: 4px;
        min-height: 200px; /* Reduced height */
        padding: 8px 0;
    }

    .book {
        width: 100px; /* Smaller book width */
        padding: 4px;
    }

    .book-cover {
        width: 85px; /* Smaller cover width */
        height: 128px; /* Maintain aspect ratio */
        margin-bottom: 6px;
    }

    .tags-container {
        gap: 3px;
        margin-top: 6px;
    }

    .book-tag {
        font-size: 0.65rem;
        width: 70px; /* Slightly smaller tags */
        padding: 3px 0;
    }

    .scroll-arrow {
        width: 32px; /* Smaller arrows */
        height: 32px;
        padding: 8px;
    }

    .scroll-arrow.left {
        left: -32px;
    }

    .scroll-arrow.right {
        right: -32px;
    }

    .scroll-wrapper::before,
    .scroll-wrapper::after {
        width: 32px; /* Smaller gradient area */
    }

    /* Adjust back button for mobile */
    .back-button {
        top: 16px;
        left: 16px;
        font-size: 0.85rem;
        gap: 0.4rem;
    }

    /* Optimize touch targets */
    .scroll-arrow, .book-cover {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    /* Improve scrolling experience */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    .book {
        scroll-snap-align: start;
    }
}

/* Additional optimizations for larger iPhones (390px and above) */
@media screen and (min-width: 390px) and (max-width: 767px) {
    .book {
        width: 105px;
    }

    .book-cover {
        width: 90px;
        height: 135px;
    }

    .book-tag {
        width: 75px;
    }
}

/* Landscape orientation adjustments */
@media screen and (max-width: 767px) and (orientation: landscape) {
    .scroll-container {
        min-height: 180px;
    }

    .book-cover {
        height: 120px;
    }

    .books-container {
        margin-top: 10px;
    }
}

/* Handle notch/dynamic island area */
@supports (padding-top: env(safe-area-inset-top)) {
    .books-container {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .back-button {
        top: max(16px, env(safe-area-inset-top));
        left: max(16px, env(safe-area-inset-left));
    }
}

/* Specific iOS adjustments */
@supports (-webkit-touch-callout: none) {
    .books-container h1 {
        margin-top: max(60px, env(safe-area-inset-top, 60px));
    }
}

.book-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.book-modal.show {
    opacity: 1;
}

.book-modal-content {
    background: #1a1a1a;
    padding: 2rem;
    border-radius: 12px;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s ease;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.book-modal.show .book-modal-content {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: background-color 0.2s ease;
    z-index: 1001;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.modal-book-cover {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.modal-book-tag {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    color: white;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .book-modal-content {
        padding: 1.5rem;
        width: 95%;
    }
    
    .modal-close {
        top: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        font-size: 24px;
    }
}

/* Enhanced tag styles */
.book-tag {
    display: inline-block;
    margin: 4px 6px;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    background: gray; /* fallback */
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: default;
    text-align: center;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.book-tag:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Topic-specific color classes */
.tag-philosophy       { background: #5A4E42; }
.tag-social-issues    { background: #A05260; }
.tag-business         { background: #3A506B; }
.tag-entrepreneurship { background: #51727E; }
.tag-economics        { background: #6A4E4E; }
.tag-politics         { background: #7C5E7D; }
.tag-geopolitics      { background: #5B4C9D; }
.tag-photography      { background: #4A4E69; }
.tag-strategy         { background: #3F3D56; }
.tag-history          { background: #7D8597; }
.tag-science          { background: #4E8D7C; }
.tag-self-improvement { background: #C0865E; }
.tag-mathematics      { background: #4C6CA0; }