/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/*
 * Library Amber colour system
 * ---------------------------
 * These five values are the site's complete core palette. If you want to
 * recolour the website in the future, change these values first. The rest of
 * the stylesheet refers to their descriptive names instead of repeating hex
 * codes in dozens of places.
 *
 * The second group contains role names such as "text-on-dark". These are not
 * extra unrelated colours: they are aliases or transparent versions of the
 * same five palette colours. Giving colours a job makes the CSS much easier for
 * one person to understand and maintain.
 */
:root {
    --palette-page: #171512;
    --palette-surface: #2a251f;
    --palette-paper: #fcfaf5;
    --palette-primary: #d9a441;
    --palette-secondary: #8c6a3c;

    --text-on-dark: var(--palette-paper);
    --text-on-light: var(--palette-surface);
    --muted-on-dark: rgba(252, 250, 245, 0.72);
    --muted-on-light: rgba(42, 37, 31, 0.68);
    /* 64% keeps secondary card text above the 4.5:1 readability target. */
    --faint-on-light: rgba(42, 37, 31, 0.64);
    --border-on-dark: rgba(252, 250, 245, 0.18);
    --hover-on-dark: rgba(252, 250, 245, 0.09);
    --strong-hover-on-dark: rgba(252, 250, 245, 0.14);
    --card-shadow: rgba(23, 21, 18, 0.24);
    --card-shadow-hover: rgba(23, 21, 18, 0.36);
}

body {
    font-family: 'Podkova', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--palette-page);
    min-height: 100vh;
    color: var(--text-on-light);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 3rem;
    color: var(--text-on-dark);
}

.title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.title i {
    font-size: 2.5rem;
    color: var(--palette-primary);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Status Buttons */
.status-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 3rem;
}

.status-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--palette-surface);
    border: 1px solid var(--border-on-dark);

    /*
     * These are the four main navigation buttons: Read, Reading, Want to Read,
     * and All Books. They used to have a 20px radius, which made them look like
     * rounded pills. A small 6px radius gives them a clearly rectangular shape
     * while keeping the corners slightly soft and consistent with the search
     * box and filter controls elsewhere on the page.
     *
     * Change this one value if you ever want a different button shape:
     *   0     = completely square corners
     *   6px   = the current rectangular design
     *   20px  = the old pill-shaped design
     */
    border-radius: 6px;
    color: var(--muted-on-dark);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.status-btn:hover {
    background: var(--strong-hover-on-dark);
    color: var(--text-on-dark);
    border-color: var(--palette-secondary);
}

.status-btn.active {
    background: var(--palette-primary);
    color: var(--palette-page);
    border-color: var(--palette-primary);
    font-weight: 600;
}

/* Make the selected button obvious when navigating with the Tab key. */
.status-btn:focus-visible {
    outline: 2px solid var(--palette-primary);
    outline-offset: 3px;
}

.status-btn i {
    font-size: 0.8rem;
}

.sidebar-toggle {
    display: none;
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 250px;
    gap: 2rem;
    align-items: start;
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 2rem;
    width: 100%;
    max-height: calc(100vh - 4rem);
    background: transparent;
    padding: 8px;
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-on-dark);
}

.sidebar-header h3 {
    color: var(--text-on-dark);
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-header i {
    color: var(--palette-primary);
}

.filter-section {
    margin-bottom: 1rem;
}

.filter-section h4 {
    color: var(--muted-on-dark);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.checkbox-group.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    flex-direction: row;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
    color: var(--muted-on-dark);
    font-size: 14px;
}

.checkbox-group.tags .checkbox-label {
    padding: 3px 6px;
    font-size: 12px;
    white-space: nowrap;
}

.checkbox-label:hover {
    background: var(--hover-on-dark);
    color: var(--text-on-dark);
}

.filter-checkbox {
    display: none;
}

.checkmark {
    width: 14px;
    height: 14px;
    border: 2px solid var(--palette-secondary);
    border-radius: 3px;
    position: relative;
    transition: all 0.3s ease;
    background: transparent;
}

.filter-checkbox:checked + .checkmark {
    background: var(--palette-primary);
    border-color: var(--palette-primary);
}

.filter-checkbox:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--palette-page);
    font-size: 12px;
    font-weight: bold;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
    color: var(--muted-on-dark);
    font-size: 14px;
}

.radio-label:hover {
    background: var(--hover-on-dark);
    color: var(--text-on-dark);
}

.sort-radio {
    display: none;
}

.radio-button {
    width: 14px;
    height: 14px;
    border: 2px solid var(--palette-secondary);
    border-radius: 50%;
    position: relative;
    transition: all 0.3s ease;
}

.sort-radio:checked + .radio-button {
    border-color: var(--palette-primary);
}

.sort-radio:checked + .radio-button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--palette-primary);
    border-radius: 50%;
}

.search-bar {
    position: relative;
    margin-bottom: 1rem;
}

.search-bar input {
    width: 100%;
    padding: 8px 8px 8px 32px;
    background: var(--palette-surface);
    border: 1px solid var(--border-on-dark);
    border-radius: 6px;
    color: var(--text-on-dark);
    font-size: 14px;
    transition: all 0.3s ease;
}

.search-bar input::placeholder {
    color: var(--muted-on-dark);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--palette-primary);
    background: var(--hover-on-dark);
}

.search-bar i {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    color: var(--palette-primary);
    font-size: 14px;
}

/*
 * Collapsible filter options
 * --------------------------
 * The HTML <details> element performs all opening and closing behaviour. These
 * rules change only its appearance; there is intentionally no JavaScript here.
 */
.filter-dropdown {
    border: 1px solid var(--border-on-dark);
    border-radius: 8px;
    background: var(--palette-surface);
}

.filter-dropdown-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    color: var(--text-on-dark);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;

    /* Remove the browser's small default triangle; ::after supplies a larger one. */
    list-style: none;
}

/* Chrome and Safari use a special marker that needs its own rule. */
.filter-dropdown-summary::-webkit-details-marker {
    display: none;
}

.filter-dropdown-summary::after {
    content: '▾';
    margin-left: auto;
    color: var(--palette-primary);
    transition: transform 0.2s ease;
}

/* Turn the arrow upward while the dropdown is open. */
.filter-dropdown[open] .filter-dropdown-summary::after {
    transform: rotate(180deg);
}

.filter-dropdown-summary:hover {
    background: var(--hover-on-dark);
}

/* Make keyboard navigation as obvious as mouse hover. */
.filter-dropdown-summary:focus-visible {
    outline: 2px solid var(--palette-primary);
    outline-offset: 2px;
}

.filter-dropdown-content {
    padding: 1rem 0.75rem 0.75rem;
    border-top: 1px solid var(--border-on-dark);
}

.clear-filters-btn {
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border-on-dark);
    border-radius: 6px;
    color: var(--muted-on-dark);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.clear-filters-btn:hover {
    background: var(--hover-on-dark);
    color: var(--text-on-dark);
    border-color: var(--palette-secondary);
}

/*
 * Sidebar statistics
 * ------------------
 * The four totals used to sit below hundreds of book cards, where most people
 * would never reach them. They now form a compact two-by-two panel at the top
 * of the sidebar, immediately before search.
 *
 * A grid is simpler than calculating widths by hand: two equal columns work in
 * both the 250px desktop sidebar and the full-width sidebar shown on phones.
 */
.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 1.25rem;
    padding: 0.75rem;
    background: var(--palette-surface);
    border: 1px solid var(--border-on-dark);
    border-radius: 8px;
}

.stat {
    text-align: center;
    color: var(--text-on-dark);
}

.stat-number {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--palette-primary);
}

.stat-label {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.7rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
    /*
     * Book descriptions have different lengths. Keep each card at its natural
     * height instead of stretching shorter cards to match the tallest card in
     * the same row.
     */
    align-items: start;
}

/*
 * A book card is an information container, not a button.
 *
 * Older versions hid all text until the mouse hovered over the cover. That made
 * titles, authors, ratings, dates, and review links difficult or impossible to
 * reach on phones, tablets, and keyboards. The card is now a simple vertical
 * layout: cover first, permanently visible information underneath.
 *
 * We intentionally do not add `tabindex` to the whole card. A non-clickable card
 * should not create an extra keyboard stop. Real actions such as "Read Review"
 * are normal links and remain keyboard-focusable by default.
 */
.book-card {
    display: flex;
    flex-direction: column;
    background: var(--palette-paper);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 25px var(--card-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

/*
 * Devices with a real mouse may show a small decorative lift. There is no zoom,
 * so a card cannot cover its neighbours. Touch devices skip this rule entirely
 * because they do not have a reliable hover state.
 */
@media (hover: hover) and (pointer: fine) {
    .book-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 12px 30px var(--card-shadow-hover);
    }

    .book-card:hover .book-cover {
        filter: brightness(0.95);
    }
}

.book-cover {
    /*
     * Every cover gets the same rectangular display area so the card grid stays
     * tidy, even though the original image files have many different shapes.
     *
     * `object-fit: contain` is the important part of this rule. It asks the
     * browser to shrink or enlarge the image until the WHOLE cover fits inside
     * the rectangle. Nothing is cut off. A particularly tall or wide cover may
     * leave a little empty space at its sides or above and below; that is the
     * unavoidable trade-off for showing the complete artwork.
     *
     * Do not change this back to `object-fit: cover`. Despite its confusing
     * name, `cover` fills the rectangle by cropping parts of the image, which is
     * exactly the problem this rule fixes.
     */
    display: block;
    width: 100%;
    height: 280px;
    object-fit: contain;

    /* Keep each image centred when its proportions leave some empty space. */
    object-position: center;

    /*
     * The subtle background makes that empty space look intentional. It also
     * avoids a harsh white flash while a lazily loaded image is arriving.
     */
    background: var(--palette-paper);
    transition: filter 0.2s ease;
}

.book-info {
    /*
     * `position: static` keeps this section in the normal page layout directly
     * below the cover. Opacity and hover tricks are deliberately avoided: if the
     * card exists on screen, its information should be readable too.
     *
     * The text used to be very small while this section had 16 pixels of empty
     * space on every side. We now spend that space on larger, easier-to-read
     * text: 0.65rem is about 10 pixels with the site's normal font settings.
     * Keeping this value here (instead of repeating different padding values in
     * the phone rules) makes future changes much easier for one maintainer.
     */
    position: static;
    flex: 1;
    padding: 0.65rem;
    background: var(--palette-paper);
    opacity: 1;
}

.book-title {
    /* 1rem normally equals 16px. The old title size was only 14px. */
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text-on-light);
    line-height: 1.3;
}

.book-author {
    /* About 14px: readable, but still visually secondary to the title. */
    font-size: 0.875rem;
    color: var(--muted-on-light);
    margin-bottom: 0.4rem;
    font-style: italic;
    line-height: 1.35;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.book-details {
    display: flex;
    flex-direction: column;
    /*
     * A smaller gap lets the larger detail text fit in roughly the same card
     * height. The information remains separated without looking wasteful.
     */
    gap: 0.2rem;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.book-rating {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.stars {
    color: var(--palette-primary);
    font-size: 0.875rem;
}

/* Make an intentionally missing rating look different from a numeric score. */
.rating-not-set {
    color: var(--faint-on-light);
    font-style: italic;
}

.book-date {
    font-size: 0.8125rem;
    color: var(--muted-on-light);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.format-icon {
    margin-left: 0.5rem;
    font-size: 1.2em;
    color: var(--muted-on-light);
}

.book-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-top: 0.3rem;
}

.tag {
    background: var(--palette-secondary);
    color: var(--palette-paper);
    padding: 0.18em 0.55em;
    border-radius: 10px;
    /* The old 9px tag text was especially difficult to read. */
    font-size: 0.6875rem;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.4;
}

.book-language {
    font-size: 0.8125rem;
    color: var(--muted-on-light);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.book-review {
    margin-top: 0.2rem;
}

.review-link {
    color: var(--palette-secondary);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: color 0.3s ease;
}

.review-link:hover {
    color: var(--palette-surface);
}

/* Give keyboard users a strong, visible indication of the selected link. */
.review-link:focus-visible {
    outline: 2px solid var(--palette-secondary);
    outline-offset: 3px;
    border-radius: 2px;
}

.book-status {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--palette-surface);
    color: var(--palette-paper);
    border: 1px solid transparent;
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 10;
    /* Status is useful information on touchscreens too, so never hide it. */
    opacity: 1;
}

.status-read {
    background: var(--palette-primary);
    color: var(--palette-page);
    border-color: var(--palette-primary);
}

.status-reading {
    background: var(--palette-secondary);
    color: var(--palette-paper);
    border-color: var(--palette-secondary);
}

.status-want-to-read {
    background: var(--palette-surface);
    color: var(--palette-paper);
    border-color: var(--palette-primary);
}

/* No results */
.no-results {
    text-align: center;
    color: var(--text-on-dark);
    padding: 3rem;
}

.no-results i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.no-results h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.no-results p {
    opacity: 0.6;
}

/* Responsive Design */
@media (max-width: 768px) {
    /*
     * Four buttons in one row are wider than a phone screen. A two-column grid
     * gives us two tidy rows and does not depend on the exact length of each
     * label. `minmax(0, 1fr)` is important: the zero allows a column to shrink
     * when the screen is narrow, while `1fr` makes both columns equally wide.
     */
    .status-buttons {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
        margin-bottom: 2rem;
    }

    .status-btn {
        /* Fill one grid cell and centre the icon plus label inside it. */
        width: 100%;
        min-width: 0;
        justify-content: center;

        /* Every current label fits on one line, even on a 320px-wide phone. */
        white-space: nowrap;
    }

    .main-content {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: block;
        position: static;
        max-height: none;
        overflow-y: visible;
        grid-row: 2;
    }

    /*
     * Only the named controls wrapper is collapsible. The .stats element is a
     * separate sibling, so it remains visible without relying on selector tricks
     * or duplicating the statistics markup.
     */
    .sidebar-controls {
        display: none;
    }

    .sidebar-controls.open {
        display: block;
    }

    .sidebar-toggle {
        display: block;
        margin-bottom: 1rem;
        padding: 0.5rem 1rem;
        background: var(--palette-surface);
        border: 1px solid var(--border-on-dark);
        border-radius: 20px;
        color: var(--muted-on-dark);
        font-size: 0.85rem;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.3s ease;
        backdrop-filter: blur(10px);
    }
    
    .container {
        padding: 1rem;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 1rem;
    }
    
    .book-cover {
        height: 220px;
    }
}

@media (max-width: 480px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    
    .book-cover {
        height: 180px;
    }
}

/* Loading animation */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    color: var(--text-on-dark);
}

.spinner {
    border: 3px solid var(--border-on-dark);
    border-radius: 50%;
    border-top: 3px solid var(--palette-primary);
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-right: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
