/* DESIGN SYSTEM & VARIABLES */
:root {
    /* Light Theme */
    --bg-primary: #FAF9F6;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F0EFEA;
    --text-primary: #2C313A;
    --text-secondary: #5C626F;
    --accent: #E63946;
    --accent-hover: #D62828;
    --border: #E5E4DE;
    --nav-bg: rgba(250, 249, 246, 0.85);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.12);
    --overlay: rgba(0,0,0,0.5);
    
    /* Typography */
    --font-heading: 'Libre Baskerville', serif;
    --font-body: 'Source Sans Pro', sans-serif;
    
    /* Transitions */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark-mode {
    --bg-primary: #121212;
    --bg-secondary: #1E1E1E;
    --bg-tertiary: #2D2D2D;
    --text-primary: #E8E8E8;
    --text-secondary: #A0A0A0;
    --accent: #FCA311;
    --accent-hover: #FFB703;
    --border: #333333;
    --nav-bg: rgba(18, 18, 18, 0.85);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.6);
    --overlay: rgba(0,0,0,0.8);
}

/* RESET & BASE */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color var(--transition-smooth), color var(--transition-smooth);
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.3;
}

button {
    font-family: var(--font-body);
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* NAVIGATION */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    transition: all var(--transition-smooth);
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.brand {
    font-size: 1.25rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.brand:hover {
    color: var(--accent);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-btn {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.5rem;
    position: relative;
    transition: color var(--transition-fast);
}

.nav-btn:hover {
    color: var(--text-primary);
}

.nav-btn.active {
    color: var(--accent);
}

.nav-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 2px;
    background-color: var(--accent);
    transition: width var(--transition-fast);
}

.nav-btn.active::after {
    width: 100%;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color var(--transition-fast);
}

.icon-btn:hover {
    background-color: var(--bg-tertiary);
}

/* HEADER / HERO */
.catalog-header {
    padding: 4rem 2rem;
    text-align: center;
    background: linear-gradient(135deg, rgba(230, 57, 70, 0.05) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border);
}

body.dark-mode .catalog-header {
    background: linear-gradient(135deg, rgba(252, 163, 17, 0.05) 0%, var(--bg-primary) 100%);
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
}

.page-title {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.search-wrapper {
    position: relative;
    max-width: 500px;
    margin: 0 auto;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

#searchInput {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border-radius: 50px;
    border: 1px solid var(--border);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-smooth);
}

#searchInput:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.1);
}

body.dark-mode #searchInput:focus {
    box-shadow: 0 0 0 3px rgba(252, 163, 17, 0.1);
}

/* MAIN CONTENT */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 60vh;
}

/* FILTERS */
.mood-bar-wrapper, .genre-nav-wrapper {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
}

.mood-bar-wrapper::-webkit-scrollbar, .genre-nav-wrapper::-webkit-scrollbar {
    display: none;
}

.filter-label {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mood-bar, .genre-nav {
    display: flex;
    gap: 0.75rem;
}

.mood-btn, .genre-btn {
    padding: 0.5rem 1rem;
    border-radius: 50px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.mood-btn:hover, .genre-btn:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
}

.genre-btn.active {
    background-color: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.mood-btn.active {
    background-color: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.mood-btn[data-mood="Rainy"].active { background-color: #3b82f6; border-color: #3b82f6; color: #fff; }
.mood-btn[data-mood="Deep Thinking"].active { background-color: #8b5cf6; border-color: #8b5cf6; color: #fff; }
.mood-btn[data-mood="Romantic"].active { background-color: #ec4899; border-color: #ec4899; color: #fff; }
.mood-btn[data-mood="Dark"].active { background-color: #374151; border-color: #374151; color: #fff; }
.mood-btn[data-mood="Epic"].active { background-color: #f59e0b; border-color: #f59e0b; color: #fff; }
.mood-btn[data-mood="Reflective"].active { background-color: #0d9488; border-color: #0d9488; color: #fff; }

/* BOOK GRID */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 2.5rem 2rem;
    margin-top: 2rem;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.book-card {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-smooth);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    cursor: pointer;
    position: relative;
    animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

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

.book-cover-container {
    position: relative;
    width: 100%;
    padding-top: 150%; /* 2:3 aspect ratio */
    overflow: hidden;
    background-color: var(--bg-tertiary);
}

.book-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.book-card:hover .book-cover {
    transform: scale(1.05);
}

.fav-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e74c3c;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}
body.dark-mode .fav-badge { background: rgba(30,30,30,0.9); }

.book-info {
    padding: 1.25rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.book-title {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.book-tags {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.mood-tag {
    background-color: rgba(230, 57, 70, 0.1);
    color: var(--accent);
}
body.dark-mode .mood-tag {
    background-color: rgba(252, 163, 17, 0.15);
}

.genre-tag {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-state h3 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* GOALS PAGE */
.goals-page {
    animation: fadeIn var(--transition-smooth);
}

.goals-header {
    text-align: center;
    margin-bottom: 3rem;
}

.goals-header h2 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.goals-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.goals-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}

@media (max-width: 768px) {
    .goals-container {
        grid-template-columns: 1fr;
    }
}

.chart-wrapper {
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.stats-cards {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.stat-card {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    text-align: center;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
}

.stat-card:nth-child(1)::before { background-color: #3b82f6; }
.stat-card:nth-child(2)::before { background-color: #10b981; }
.stat-card:nth-child(3)::before { background-color: #f59e0b; }

.stat-card h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2.5rem;
    font-family: var(--font-heading);
    color: var(--accent);
}

/* MODAL */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay);
    z-index: 1000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-smooth);
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background-color: var(--bg-secondary);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform var(--transition-smooth);
    border: 1px solid var(--border);
}

.modal.show .modal-content {
    transform: translateY(0);
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 2rem;
    line-height: 1;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    z-index: 10;
    transition: background-color var(--transition-fast);
}

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

.modal-body {
    display: flex;
    max-height: 90vh;
    overflow-y: auto;
}

@media (max-width: 768px) {
    .modal-body {
        flex-direction: column;
    }
}

.modal-img-container {
    flex: 0 0 40%;
    padding: 2rem;
    background-color: var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

#modalImg {
    width: 100%;
    max-width: 300px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
}

.fav-action-btn {
    width: 100%;
    max-width: 300px;
    padding: 1rem;
    border-radius: 8px;
    background-color: var(--text-primary);
    color: var(--bg-primary);
    font-weight: 600;
    font-size: 1rem;
    transition: background-color var(--transition-fast);
    cursor: pointer;
}

.fav-action-btn:hover {
    background-color: var(--accent);
    color: #fff;
}

.fav-action-btn.is-fav {
    background-color: transparent;
    border: 2px solid var(--text-primary);
    color: var(--text-primary);
}

.fav-action-btn.is-fav:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

.modal-info {
    flex: 1;
    padding: 3rem 2rem;
}

.modal-tags {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
}

#modalTitle {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

#modalAuthor {
    font-size: 1.2rem;
    color: var(--text-secondary);
    font-style: italic;
}

.divider {
    height: 1px;
    background-color: var(--border);
    margin: 1.5rem 0;
}

#modalDesc {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: 2rem;
}

.modal-meta {
    display: flex;
    gap: 2rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meta-val {
    font-weight: 600;
    font-size: 1.1rem;
}

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

/* AUTH SCREEN */
.auth-screen {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-primary);
    position: relative;
    animation: fadeIn var(--transition-smooth);
}

.auth-box {
    background-color: var(--bg-secondary);
    padding: 4rem 3rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    max-width: 400px;
    width: 90%;
}

/* RATING */
.book-rating {
    margin-bottom: 0.5rem;
    color: #f59e0b;
    font-size: 0.9rem;
    letter-spacing: 2px;
}
.rating-widget .star {
    font-size: 1.5rem;
    color: var(--border);
    cursor: pointer;
    transition: color var(--transition-fast);
}
.rating-widget .star.active,
.rating-widget .star:hover {
    color: #f59e0b;
}

/* DRAG AND DROP SHELF */
.shelf-drawer {
    position: fixed;
    bottom: -100px;
    left: 0;
    width: 100%;
    height: 80px;
    background-color: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 2px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    transition: bottom var(--transition-smooth), background-color var(--transition-fast);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
}

.shelf-drawer.show {
    bottom: 0;
}

.shelf-drawer.drag-over {
    background-color: rgba(230, 57, 70, 0.1);
}

body.dark-mode .shelf-drawer.drag-over {
    background-color: rgba(252, 163, 17, 0.15);
}

.shelf-content {
    display: flex;
    align-items: center;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1rem;
    pointer-events: none; /* Let drag events hit the parent */
}

.book-card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    box-shadow: none;
}

.book-card.dropped {
    animation: dropIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes dropIn {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); box-shadow: var(--shadow-lg); }
    100% { transform: scale(1); }
}

/* QUIZ PAGE */
.quiz-page {
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn var(--transition-smooth);
}
.quiz-container {
    background-color: var(--bg-secondary);
    border-radius: 16px;
    padding: 3rem 2rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    text-align: center;
}
.quiz-question {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    font-family: var(--font-heading);
}
.quiz-answers {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 500px;
    margin: 0 auto;
}
.quiz-btn {
    padding: 1rem;
    border-radius: 8px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    font-size: 1.1rem;
    transition: all var(--transition-fast);
}
.quiz-btn:hover {
    background-color: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: translateY(-2px);
}
.quiz-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.quiz-reward-badge {
    background: #f59e0b;
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: bold;
    display: inline-block;
}

/* RESPONSIVE & ADAPTIVE STYLES */
@media (max-width: 1024px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 2rem 1.5rem;
    }
}

@media (max-width: 768px) {
    .nav-content {
        flex-direction: column;
        text-align: center;
        padding: 1rem;
    }
    .nav-links {
        width: 100%;
        justify-content: center;
    }
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 1.5rem 1rem;
    }
    .catalog-header {
        padding: 3rem 1rem;
    }
    .page-title {
        font-size: 2rem;
    }
    .modal-meta {
        flex-direction: column;
        gap: 1rem;
    }
    .modal-info {
        padding: 2rem 1.5rem;
    }
    .stats-cards {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .stat-card {
        flex: 1 1 calc(50% - 1.5rem);
    }
    .shelf-drawer {
        padding-bottom: env(safe-area-inset-bottom);
        height: auto;
        min-height: 80px;
    }
    .shelf-content {
        font-size: 1rem;
        padding: 1rem;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .nav-content {
        padding: 0.5rem;
    }
    .nav-links {
        gap: 0.5rem;
    }
    .nav-btn {
        font-size: 0.85rem;
        padding: 0.4rem;
    }
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 1rem;
    }
    .page-title {
        font-size: 1.75rem;
    }
    .stat-card {
        flex: 1 1 100%;
    }
    .book-title {
        font-size: 1rem;
    }
    .book-info {
        padding: 1rem;
    }
}
