/* ---------- Reset & Box-Sizing ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ---------- Theme Colors ---------- */
:root {
    --gold: #D4AF37;
    --dark-gold: #B8941F;
    --burgundy: #800020;
    --deep-blue: #1B2838;
    --cream: #FFF8E7;
    --light-gold: #F4E4C1;
    --shadow: rgba(0, 0, 0, 0.15);
    --card-radius: 12px;
    --card-height: 500px;
    --fade-duration: 0.5s;
}

/* ---------- Body ---------- */
body {
    font-family: 'Georgia', serif;
    background: linear-gradient(135deg, var(--deep-blue) 0%, #2c3e50 100%);
    min-height: 100vh;
    padding: 10px;
    color: var(--cream);
}

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

/* ---------- Header ---------- */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, var(--burgundy) 0%, #5c0016 100%);
    border-radius: 15px;
    border: 3px solid var(--gold);
    box-shadow: 0 10px 30px var(--shadow);
    position: relative;
    animation: headerFade 1.2s ease-out both;
}

@keyframes headerFade {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

h1 {
    font-size: 2em;
    color: var(--gold);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 8px;
    font-weight: normal;
    letter-spacing: 2px;
}

.subtitle {
    color: var(--light-gold);
    font-style: italic;
    font-size: 1em;
}

/* ---------- Admin Link ---------- */
.admin-link {
    margin-top: 15px;
}

.admin-link a {
    color: var(--light-gold);
    text-decoration: none;
    font-size: 0.9em;
    transition: color 0.3s;
}

.admin-link a:hover {
    color: var(--gold);
}

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--gold);
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--light-gold);
}

.tab.active {
    background: var(--gold);
    color: var(--deep-blue);
    font-weight: bold;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ---------- Books Grid ---------- */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    margin-top: 20px;
}

/* ---------- Book Card Container ---------- */
.book-card-container {
    min-height: 450px;
    height: var(--card-height);
    opacity: 0;
    transform: translateY(20px);
    transition: transform var(--fade-duration) ease, opacity var(--fade-duration) ease;
    cursor: pointer;
    outline: none;
}

.book-card-container.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- Staggered Fade (CSS Only) ---------- */
.books-grid .book-card-container:nth-child(1)  { transition-delay: 0s; }
.books-grid .book-card-container:nth-child(2)  { transition-delay: 0.05s; }
.books-grid .book-card-container:nth-child(3)  { transition-delay: 0.1s; }
.books-grid .book-card-container:nth-child(4)  { transition-delay: 0.15s; }
.books-grid .book-card-container:nth-child(5)  { transition-delay: 0.2s; }
.books-grid .book-card-container:nth-child(6)  { transition-delay: 0.25s; }
.books-grid .book-card-container:nth-child(7)  { transition-delay: 0.3s; }
.books-grid .book-card-container:nth-child(8)  { transition-delay: 0.35s; }
.books-grid .book-card-container:nth-child(9)  { transition-delay: 0.4s; }
.books-grid .book-card-container:nth-child(10) { transition-delay: 0.45s; }
.books-grid .book-card-container:nth-child(11) { transition-delay: 0.5s; }
.books-grid .book-card-container:nth-child(12) { transition-delay: 0.55s; }

/* ---------- Book Card ---------- */
.book-card {
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--card-radius);
    overflow: hidden;
    box-shadow: 0 8px 20px var(--shadow);
    border: 3px solid var(--gold);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.book-card-container:hover .book-card {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px var(--shadow);
}

/* ---------- Favorited Book Styles ---------- */
/* Bookmark ribbon hanging from top - positioned LEFT */
.book-card.favorited::before {
    content: '⭐';
    position: absolute;
    top: -3px;
    left: 5px;
    width: 50px;
    height: 80px;
    background: linear-gradient(135deg, var(--burgundy) 0%, #a00028 100%);
    color: var(--gold);
    font-size: 1.5em;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 8px;
    z-index: 15;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    border-left: 2px solid var(--gold);
    border-right: 2px solid var(--gold);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 85%, 0 100%);
}

.book-card.favorited::after {
    content: '';
    position: absolute;
    top: -3px;
    left: 5px;
    width: 50px;
    height: 80px;
    background: rgba(0, 0, 0, 0.1);
    z-index: 14;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 85%, 0 100%);
    transform: translateX(3px);
}

.book-card.favorited .book-cover-container {
    filter: brightness(1.05);
}

.book-card-container:hover .book-card.favorited {
    box-shadow: 0 12px 30px var(--shadow), 0 0 20px rgba(212, 175, 55, 0.4);
}

/* ---------- Book Cover ---------- */
.book-cover-container {
    width: 100%;
    height: 300px;
    background: linear-gradient(135deg, var(--light-gold) 0%, var(--cream) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    position: relative;
    flex-shrink: 0;
}

.book-cover {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.book-cover-placeholder {
    font-size: 80px;
    color: var(--gold);
}

/* ---------- Book Info ---------- */
.book-info {
    display: flex;
    flex-direction: column;
    padding: 0 15px 50px 15px;
    flex: 1;
    gap: 0;
}

.book-title {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--burgundy);
    margin-bottom: 0;
    text-align: center;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-author {
    color: var(--deep-blue);
    text-align: center;
    font-style: italic;
    font-size: 0.95em;
    margin-top: -10px;
    margin-bottom: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.book-status {
    padding: 8px;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    margin-top: auto;
}

.status-available {
    background: linear-gradient(135deg, #f7e27c, #d4af37, #b8941f);
    color: #3b2f00;
    text-shadow: 0 1px 0 rgba(255,255,255,0.6);
}

.status-borrowed {
    background: linear-gradient(135deg, #d8cfc0, #bfae90);
    color: #5b4a2d;
}

/* ---------- Summary Button ---------- */
.summary-button {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--burgundy) 0%, #5c0016 100%);
    color: var(--gold);
    font-size: 0.75em;
    font-style: normal;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-top: 2px solid var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 5;
}

.summary-button::before {
    content: 'Click for Details';
}

.summary-button::after {
    content: '📖';
    font-size: 1.2em;
}

.summary-button:hover {
    background: linear-gradient(135deg, #a00028 0%, var(--burgundy) 100%);
    color: var(--light-gold);
}

/* ---------- Modal Overlay ---------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 20px;
}

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

/* ---------- Modal Content ---------- */
.modal-content {
    background: linear-gradient(135deg, var(--cream) 0%, var(--light-gold) 100%);
    border: 4px solid var(--gold);
    border-radius: 20px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.9) translateY(30px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    position: relative;
}

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

/* ---------- Modal Close Button ---------- */
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: var(--burgundy);
    border: 2px solid var(--gold);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--cream);
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.modal-close:hover {
    background: var(--gold);
    color: var(--burgundy);
    transform: rotate(90deg) scale(1.1);
}

.modal-close::before {
    content: '×';
    line-height: 1;
}

/* ---------- Modal Header ---------- */
.modal-header {
    padding: 30px 30px 20px;
    border-bottom: 3px solid var(--gold);
    background: linear-gradient(135deg, var(--burgundy) 0%, #5c0016 100%);
    flex-shrink: 0;
}

/* Modal favorite indicator */
.modal-header.favorited::after {
    content: '⭐ Favorite';
    position: absolute;
    top: 15px;
    right: 70px;
    background: linear-gradient(135deg, var(--burgundy) 0%, #a00028 100%);
    color: var(--gold);
    font-size: 0.7em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 2px solid var(--gold);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.modal-book-title {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--gold);
    margin-bottom: 8px;
    padding-right: 50px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.modal-book-author {
    font-size: 1.2em;
    color: var(--light-gold);
    font-style: italic;
}

.modal-book-meta {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.modal-book-pages,
.modal-book-status {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: bold;
}

.modal-book-pages {
    background: rgba(212, 175, 55, 0.3);
    color: var(--cream);
    border: 1px solid var(--gold);
}

.modal-book-status.status-available {
    background: linear-gradient(135deg, #f7e27c, #d4af37);
    color: #3b2f00;
}

.modal-book-status.status-borrowed {
    background: linear-gradient(135deg, #d8cfc0, #bfae90);
    color: #5b4a2d;
}

/* ---------- Modal Body ---------- */
.modal-body {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

.modal-summary-label {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--burgundy);
    margin-bottom: 15px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-summary-text {
    color: var(--deep-blue);
    line-height: 1.8;
    font-size: 1.05em;
    text-align: justify;
    white-space: pre-line;
}

/* ---------- Modal Footer ---------- */
.modal-footer {
    padding: 20px 30px;
    border-top: 2px solid var(--gold);
    background: linear-gradient(135deg, var(--burgundy) 0%, #5c0016 100%);
    flex-shrink: 0;
    text-align: center;
}

.modal-link {
    display: inline-block;
    color: var(--gold);
    text-decoration: none;
    font-weight: bold;
    padding: 10px 20px;
    border: 2px solid var(--gold);
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 1em;
    font-family: 'Georgia', serif;
}

.modal-link:hover {
    background: var(--gold);
    color: var(--burgundy);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Favorite button styling */
.modal-footer button.modal-link {
    background: transparent;
    cursor: pointer;
    font-family: 'Georgia', serif;
}

.modal-footer button.modal-link.favorite-active {
    background: rgba(212, 175, 55, 0.2);
}

.modal-footer button.modal-link:hover {
    background: var(--gold);
    color: var(--burgundy);
}

/* ---------- Modal Scrollbar ---------- */
.modal-body::-webkit-scrollbar {
    width: 10px;
}

.modal-body::-webkit-scrollbar-track {
    background: rgba(212, 175, 55, 0.1);
    border-radius: 5px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 5px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--dark-gold);
}

/* ---------- Responsive Adjustments ---------- */
@media (max-width: 768px) {
    .summary-button::before { content: 'Tap for Details'; }
    .books-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    h1 { font-size: 1.5em; }
    .book-card-container { height: 450px; }
    .book-cover-container { height: 250px; }
    
    .modal-content {
        border-radius: 15px;
        max-height: 95vh;
    }
    
    .modal-header {
        padding: 20px 20px 15px;
    }
    
    .modal-book-title {
        font-size: 1.4em;
    }
    
    .modal-book-author {
        font-size: 1em;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-summary-text {
        font-size: 1em;
    }
}

@media (min-width: 769px) {
    .summary-button::before { content: 'Click for Details'; }
}

@media (max-width: 480px) {
    .books-grid { grid-template-columns: 1fr; }
    
    .modal-overlay {
        padding: 10px;
    }
    
    .modal-content {
        border-radius: 12px;
    }
}

/* ---------- Pagination Disabled ---------- */
.tab.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ---------- Focus Style ---------- */
.tab:focus {
    outline: 3px solid var(--gold);
    outline-offset: 3px;
    transform: scale(1.05);
}

.book-card-container:focus {
    outline: 3px solid var(--gold);
    outline-offset: 5px;
}

.modal-close:focus {
    outline: 3px solid var(--cream);
    outline-offset: 3px;
}

/* ---------- Empty State ---------- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--light-gold);
}

.empty-state p {
    font-size: 1.2em;
    margin-bottom: 10px;
}

/* ---------- Smooth Transitions ---------- */
.book-card-container * {
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Prevent Body Scroll When Modal Open ---------- */
body.modal-open {
    overflow: hidden;
}

/* ---------- Accessibility ---------- */
.modal-overlay[aria-hidden="true"] {
    display: none;
}

/* ---------- Print Styles ---------- */
@media print {
    .modal-overlay {
        display: none !important;
    }
}