*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f6f8fa;
    --card-bg: #ffffff;
    --text: #2c2c2c;
    --text-secondary: #6b6b6b;
    --accent: #8b6914;
    --accent-light: #c4a35a;
    --border: #e0dbd4;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 12px 32px rgba(0, 0, 0, 0.15);
    --radius: 8px;
    --transition: 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Header ────────────────────────────────── */

header {
    background: var(--card-bg);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.search-container {
    flex: 1;
    min-width: 200px;
    max-width: 480px;
}

#search {
    width: 100%;
    padding: 10px 18px;
    border: 2px solid var(--border);
    border-radius: 24px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
    background: #ffffff;
    color: var(--text);
}

#search:focus {
    border-color: var(--accent);
}

#search::placeholder {
    color: #a09888;
}

/* ── Main ──────────────────────────────────── */

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ── Filters ───────────────────────────────── */

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.filter-chip {
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: var(--card-bg);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.filter-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.filter-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── Book count ────────────────────────────── */

.book-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ── Gallery grid ──────────────────────────── */

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 24px;
}

/* ── Book card ─────────────────────────────── */

.book-card {
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--card-bg);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    animation: fadeIn 0.4s ease both;
}

.book-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-hover);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.book-cover {
    aspect-ratio: 2 / 3;
    overflow: hidden;
    background: linear-gradient(135deg, #e8e4de, #d4cfc8);
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.book-info {
    padding: 10px 12px 12px;
}

.book-title {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Cover placeholder ─────────────────────── */

.cover-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.8);
    user-select: none;
}

/* ── Empty state ───────────────────────────── */

.empty-state {
    text-align: center;
    padding: 100px 24px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.empty-hint {
    font-size: 0.9rem !important;
    margin-top: 8px !important;
}

.empty-state code {
    background: var(--card-bg);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
}

/* ── No results ────────────────────────────── */

.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 24px;
    color: var(--text-secondary);
    font-size: 1rem;
}

/* ── Modal ─────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    max-width: 640px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    gap: 28px;
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    transition: color var(--transition);
    z-index: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-cover {
    width: 180px;
    flex-shrink: 0;
}

.modal-cover img {
    width: 100%;
    border-radius: 6px;
    box-shadow: var(--shadow);
}

.modal-details {
    flex: 1;
    min-width: 0;
}

.modal-details h2 {
    font-size: 1.3rem;
    line-height: 1.3;
    margin-bottom: 4px;
    padding-right: 24px;
}

.modal-author {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.modal-description {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.modal-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-meta span {
    display: inline-block;
    margin-right: 16px;
    margin-bottom: 4px;
}

.modal-link {
    display: inline-block;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: opacity var(--transition);
}

.modal-link:hover {
    opacity: 0.85;
}

/* ── Responsive ────────────────────────────── */

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 12px;
    }

    h1 {
        text-align: center;
    }

    .search-container {
        max-width: none;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 16px;
    }

    .modal {
        flex-direction: column;
        padding: 24px;
        gap: 20px;
    }

    .modal-cover {
        width: 140px;
        margin: 0 auto;
    }
}

@media (max-width: 480px) {
    main {
        padding: 16px;
    }

    .gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    h1 {
        font-size: 1.25rem;
    }

    .book-info {
        padding: 8px 10px 10px;
    }

    .book-title {
        font-size: 0.8rem;
    }
}
