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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
}

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

header {
    background: white;
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    text-align: center;
}

h1 {
    color: #333;
    font-size: 1.5em;
}

.stats {
    display: flex;
    gap: 8px;
    color: #666;
    font-size: 0.85em;
    flex-wrap: wrap;
    justify-content: center;
}

.stats span {
    background: #f0f0f0;
    padding: 4px 12px;
    border-radius: 20px;
}

.controls {
    background: white;
    padding: 12px 15px;
    border-radius: 12px;
    margin-bottom: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.filter-toggle {
    padding: 8px 14px;
    border: 2px solid #667eea;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-toggle:hover,
.filter-toggle.active {
    background: #667eea;
    color: white;
}

.filters-container {
    background: white;
    border-radius: 12px;
    margin-bottom: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease-out;
}

.filters-container.show {
    max-height: 400px;
    transition: max-height 0.3s ease-in;
}

.filters-container .filters {
    padding: 15px;
}

.search-box {
    flex: 1;
    min-width: 200px;
}

.search-box input {
    width: 100%;
    padding: 10px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 30px;
    font-size: 14px;
    transition: all 0.3s;
}

.search-box input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.2);
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    width: 100%;
}

.filters select {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    width: 100%;
}

.filters select:hover,
.filters select:focus {
    border-color: #667eea;
    outline: none;
}

.view-toggle {
    display: flex;
    gap: 8px;
}

.view-toggle button {
    padding: 8px 14px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
}

.view-toggle button.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.view-toggle button:hover {
    transform: translateY(-2px);
}

/* Keyboard hint */
.keyboard-hint {
    text-align: center;
    margin-bottom: 12px;
    font-size: 0.8em;
    color: rgba(255,255,255,0.7);
}

.keyboard-hint kbd {
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.95em;
}

/* Grid/List views */
#booksContainer {
    padding: 0;
}

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

.list-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Book card */
.book-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    transition: all 0.3s;
    cursor: pointer;
    outline: none;
}

.book-card:hover,
.book-card:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.book-card.card-selected {
    box-shadow: 0 0 0 3px #667eea, 0 10px 30px rgba(0,0,0,0.2);
    transform: translateY(-3px);
}

.grid-view .book-card {
    display: flex;
    flex-direction: column;
}

.list-view .book-card {
    display: flex;
    flex-direction: row;
    min-height: 150px;
}

.book-cover {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.grid-view .book-cover {
    height: 220px;
}

.list-view .book-cover {
    width: 100px;
    flex-shrink: 0;
}

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

.cover-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.cover-loader::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.book-cover .no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 3em;
    opacity: 0.5;
}

.book-category-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.7em;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.book-id {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.9);
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 0.8em;
}

.book-info {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-title {
    font-size: 0.95em;
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-author {
    color: #666;
    margin-bottom: 4px;
    font-size: 0.85em;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-rating {
    color: #f5a623;
    font-size: 0.9em;
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.book-meta {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    color: #999;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    animation: fadeIn 0.3s;
}

.modal-content {
    background-color: white;
    margin: 3% auto;
    padding: 0;
    border-radius: 15px;
    width: 95%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    padding: 10px 20px;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
}

#modalBody {
    padding: 20px;
}

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.modal-cover {
    width: 160px;
    height: 240px;
    flex-shrink: 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.modal-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-info {
    text-align: center;
}

.modal-info h2 {
    color: #333;
    margin-bottom: 10px;
    font-size: 1.2em;
}

.modal-info p {
    margin: 6px 0;
    color: #666;
    font-size: 0.9em;
}

.modal-info strong {
    color: #333;
}

.modal-rating {
    color: #f5a623;
    font-size: 1.2em;
    letter-spacing: 1px;
}

.modal-category {
    background: #667eea;
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85em;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: white;
    font-size: 1.2em;
    grid-column: 1 / -1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Tablet */
@media (min-width: 520px) {
    body { padding: 15px; }

    header {
        flex-direction: row;
        justify-content: space-between;
        text-align: left;
        padding: 20px 25px;
    }

    h1 { font-size: 1.8em; }

    .grid-view {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }

    .grid-view .book-cover { height: 240px; }

    .modal-header {
        flex-direction: row;
        align-items: flex-start;
    }

    .modal-info { text-align: left; }
}

/* Desktop */
@media (min-width: 900px) {
    body { padding: 20px; }
    header { padding: 30px; }
    h1 { font-size: 2.2em; }
    .stats { font-size: 1em; }

    .grid-view {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 20px;
    }

    .grid-view .book-cover { height: 280px; }
    .book-info { padding: 14px; }
    .book-title { font-size: 1em; }

    .modal-cover { width: 200px; height: 300px; }
    .modal-info h2 { font-size: 1.4em; }
}

/* Large desktop */
@media (min-width: 1200px) {
    .grid-view {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 24px;
    }

    .grid-view .book-cover { height: 300px; }
}
