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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fff;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Cookie Banner */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    z-index: 1000;
    display: none;
}

.cookie-banner.show {
    display: block;
}

.cookie-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.cookie-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.cookie-btn:hover {
    background: #2980b9;
}

/* Header */
.header {
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #2c3e50;
    font-weight: 600;
    font-size: 1.2rem;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-link {
    text-decoration: none;
    color: #666;
    font-weight: 500;
    transition: color 0.3s;
}

.nav-link:hover,
.nav-link.active {
    color: #3498db;
}

.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.mobile-menu-toggle span {
    width: 25px;
    height: 3px;
    background: #333;
    margin: 3px 0;
    transition: 0.3s;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 100px 0;
    text-align: center;
    position: relative;
}

.hero-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 20px;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.hero p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.cta-button {
    display: inline-block;
    background: #fff;
    color: #667eea;
    padding: 15px 30px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: 600;
    transition: transform 0.3s, box-shadow 0.3s;
}

.cta-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

/* Page Header */
.page-header {
    background: #f8f9fa;
    padding: 60px 0;
    text-align: center;
}

.page-header h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 1rem;
}

.page-header p {
    font-size: 1.1rem;
    color: #666;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
}

.book-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    padding: 1.5rem;
    transition: transform 0.3s, box-shadow 0.3s;
    text-decoration: none;
    color: inherit;
}

.book-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.book-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.book-card h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.book-author {
    color: #666;
    margin-bottom: 0.5rem;
    font-style: italic;
}

.book-category {
    background: #3498db;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    display: inline-block;
    margin-bottom: 1rem;
}

.book-description {
    color: #666;
    line-height: 1.5;
}

/* Categories */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
}

.categories-grid.large {
    grid-template-columns: 1fr;
    gap: 3rem;
}

.category-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    padding: 2rem;
    text-decoration: none;
    color: inherit;
    transition: transform 0.3s, box-shadow 0.3s;
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.category-card h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #2c3e50;
}

.category-section {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    padding: 2rem;
}

.category-header {
    margin-bottom: 2rem;
}

.category-header h2 {
    font-size: 1.8rem;
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.view-all-btn {
    background: #3498db;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    text-decoration: none;
    display: inline-block;
    margin-top: 1rem;
    transition: background 0.3s;
}

.view-all-btn:hover {
    background: #2980b9;
}

.books-preview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Filters */
.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.search-box input,
.category-filter select {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    min-width: 200px;
}

.search-box input:focus,
.category-filter select:focus {
    outline: none;
    border-color: #3498db;
}

/* Book Details */
.book-details {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 20px;
}

.book-detail-content {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 3rem;
    margin-bottom: 3rem;
}

.book-detail-image {
    width: 100%;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.book-info h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 1rem;
}

.book-meta {
    margin-bottom: 2rem;
}

.book-meta p {
    margin-bottom: 0.5rem;
    color: #666;
}

.book-meta strong {
    color: #2c3e50;
}

.purchase-links {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.purchase-link {
    background: #3498db;
    color: white;
    padding: 12px 24px;
    border-radius: 5px;
    text-decoration: none;
    transition: background 0.3s;
}

.purchase-link:hover {
    background: #2980b9;
}

.book-sections {
    display: grid;
    gap: 2rem;
}

.book-section {
    background: #f8f9fa;
    padding: 2rem;
    border-radius: 10px;
}

.book-section h2 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.takeaways-list {
    list-style: none;
}

.takeaways-list li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
}

.takeaways-list li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: #27ae60;
    font-weight: bold;
}

.disclaimer-notice {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    padding: 1rem;
    border-radius: 5px;
    margin: 2rem 0;
}

/* Contact */
.contact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    margin: 2rem 0;
}

.contact-info {
    background: #f8f9fa;
    padding: 2rem;
    border-radius: 10px;
}

.contact-details {
    margin-top: 2rem;
}

.contact-item {
    margin-bottom: 2rem;
}

.contact-item h3 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.contact-item a {
    color: #3498db;
    text-decoration: none;
}

.contact-item a:hover {
    text-decoration: underline;
}

.contact-form {
    background: #fff;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #2c3e50;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.submit-btn {
    background: #3498db;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

.submit-btn:hover {
    background: #2980b9;
}

.form-message {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 5px;
    display: none;
}

.form-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.form-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Legal Content */
.legal-content {
    padding: 2rem 0;
}

.content-wrapper {
    max-width: 800px;
    margin: 0 auto;
}

.content-wrapper h2 {
    color: #2c3e50;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.content-wrapper ul {
    margin-left: 2rem;
    margin-bottom: 1rem;
}

.content-wrapper li {
    margin-bottom: 0.5rem;
}

.content-wrapper a {
    color: #3498db;
    text-decoration: none;
}

.content-wrapper a:hover {
    text-decoration: underline;
}

/* About Content */
.about-content {
    padding: 2rem 0;
}

.content-grid {
    display: grid;
    gap: 2rem;
}

.content-section {
    background: #f8f9fa;
    padding: 2rem;
    border-radius: 10px;
}

.content-section h2 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.content-section ul {
    margin-left: 2rem;
    margin-top: 1rem;
}

.content-section li {
    margin-bottom: 0.5rem;
}

/* Featured Books Section */
.featured-books,
.categories-preview {
    padding: 4rem 0;
}

.featured-books {
    background: #f8f9fa;
}

.featured-books h2,
.categories-preview h2 {
    text-align: center;
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 3rem;
}

/* Footer */
.footer {
    background: #2c3e50;
    color: white;
    padding: 3rem 0 1rem;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-section h3,
.footer-section h4 {
    margin-bottom: 1rem;
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 0.5rem;
}

.footer-section a {
    color: #bdc3c7;
    text-decoration: none;
    transition: color 0.3s;
}

.footer-section a:hover {
    color: white;
}

.footer-bottom {
    border-top: 1px solid #34495e;
    margin-top: 2rem;
    padding-top: 1rem;
    text-align: center;
    color: #bdc3c7;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-menu {
        display: none;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
    
    .hero p {
        font-size: 1rem;
    }
    
    .books-grid {
        grid-template-columns: 1fr;
    }
    
    .book-detail-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .contact-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .filters {
        flex-direction: column;
    }
    
    .search-box input,
    .category-filter select {
        min-width: 100%;
    }
    
    .purchase-links {
        flex-direction: column;
    }
    
    .cookie-content {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    
    .books-preview {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 15px;
    }
    
    .hero {
        padding: 60px 0;
    }
    
    .page-header {
        padding: 40px 0;
    }
    
    .page-header h1 {
        font-size: 2rem;
    }
    
    .book-card,
    .category-card,
    .category-section,
    .contact-form,
    .contact-info {
        padding: 1rem;
    }
    
    .featured-books,
    .categories-preview {
        padding: 2rem 0;
    }
}

/* FILE: assets/app.js -->
// Book data
const BOOKS_DATA = {
    1: {
        id: 1,
        title: "Good to Great",
        author: "Jim Collins",
        category: "business",
        shortDesc: "Why some companies make the leap and others don't. A comprehensive study of what separates great companies from good ones.",
        longDesc: "Built to Last author Jim Collins and his team of researchers spent five years analyzing companies that made the leap from good to great. They discovered the key factors that distinguish truly great companies from merely good ones, providing a roadmap for transforming good companies into great ones.",
        keyTakeaways: [
            "Level 5 Leadership combines personal humility with professional will",
            "Get the right people on the bus before deciding where to drive it",
            "Confront brutal facts while maintaining unwavering faith",
            "Focus on what you can be best at in the world",
            "Build a culture of discipline rather than hierarchy"
        ],
        whoItsFor: "Business leaders, executives, entrepreneurs, and anyone interested in organizational excellence and sustainable business transformation.",
        publicationYear: 2001,
        externalLinks: {
            amazon: "https://amazon.com/Good-Great-Some-Companies-Others/dp/0066620996",
            audible: "https://audible.com/pd/Good-to-Great-Audiobook/B003VXI5MS",
            googleBooks: "https://books.google.com/books?id=yOhuCwAAQBAJ"
        },
        image: "/assets/book-01.svg"
    },
    2: {
        id: 2,
        title: "Thinking, Fast and Slow",
        author: "Daniel Kahneman",
        category: "economics",
        shortDesc: "A groundbreaking exploration of how the mind makes decisions, revealing the two systems that drive the way we think.",
        longDesc: "Nobel Prize winner Daniel Kahneman takes us on a groundbreaking tour of the mind and explains the two systems that drive the way we think. System 1 is fast, intuitive, and emotional; System 2 is slower, more deliberative, and more logical. The impact of overconfidence on corporate strategies, the difficulties of predicting what will make us happy in the future, the profound effect of cognitive biases on everything from playing the stock market to planning our next vacation—each of these can be understood only by knowing how the two systems shape our judgments and decisions.",
        keyTakeaways: [
            "We have two thinking systems: fast intuitive and slow deliberate",
            "Cognitive biases systematically affect our decision-making",
            "Loss aversion makes losses feel twice as powerful as gains",
            "Overconfidence leads to poor predictions and planning",
            "Anchoring effects influence our numerical estimates"
        ],
        whoItsFor: "Anyone interested in psychology, behavioral economics, decision-making, and understanding how the human mind works.",
        publicationYear: 2011,
        externalLinks: {
            amazon: "https://amazon.com/Thinking-Fast-Slow-Daniel-Kahneman/dp/0374533555",
            audible: "https://audible.com/pd/Thinking-Fast-and-Slow-Audiobook/B005Z9GAJG",
            googleBooks: "https://books.google.com/books?id=ZuKTvERuPG8C"
        },
        image: "/assets/book-02.svg"
    },
    3: {
        id: 3,
        title: "The Lean Startup",
        author: "Eric Ries",
        category: "business",
        shortDesc: "How today's entrepreneurs use continuous innovation to create radically successful businesses through validated learning.",
        longDesc: "The Lean Startup approach fosters companies that are both more capital efficient and that leverage human creativity more effectively. Inspired by lessons from lean manufacturing, it relies on 'validated learning,' rapid scientific experimentation, as well as a number of counter-intuitive practices that shorten product development cycles, measure actual progress without resorting to vanity metrics, and learn what customers really want.",
        keyTakeaways: [
            "Build-Measure-Learn feedback loop drives innovation",
            "Validated learning over elaborate business plans",
            "Minimum Viable Product (MVP) tests core assumptions",
            "Pivot or persevere based on customer feedback",
            "Innovation accounting measures true progress"
        ],
        whoItsFor: "Entrepreneurs, startup founders, product managers, and anyone involved in bringing new products or services to market.",
        publicationYear: 2011,
        externalLinks: {
            amazon: "https://amazon.com/Lean-Startup-Entrepreneurs-Continuous-Innovation/dp/0307887898",
            audible: "https://audible.com/pd/The-Lean-Startup-Audiobook/B005LXV0HI",
            googleBooks: "https://books.google.com/books?id=tvfyz-4JILwC"
        },
        image: "/assets/book-03.svg"
    },
    4: {
        id: 4,
        title: "Atomic Habits",
        author: "James Clear",
        category: "productivity",
        shortDesc: "An easy and proven way to build good habits and break bad ones through small changes that deliver remarkable results.",
        longDesc: "No matter your goals, Atomic Habits offers a proven framework for improving every day. James Clear, one of the world's leading experts on habit formation, reveals practical strategies that will teach you exactly how to form good habits, break bad ones, and master the tiny behaviors that lead to remarkable results.",
        keyTakeaways: [
            "Small changes compound into remarkable results over time",
            "Focus on systems rather than goals for lasting change",
            "The four laws of behavior change: Cue, Craving, Response, Reward",
            "Identity-based habits are more sustainable than outcome-based ones",
            "Environment design makes good habits easier and bad habits harder"
        ],
        whoItsFor: "Anyone looking to improve their habits, increase productivity, and create positive lasting change in their personal or professional life.",
        publicationYear: 2018,
        externalLinks: {
            amazon: "https://amazon.com/Atomic-Habits-Proven-Build-Break/dp/0735211299",
            audible: "https://audible.com/pd/Atomic-Habits-Audiobook/1524779261",
            googleBooks: "https://books.google.com/books?id=XfFvDwAAQBAJ"
        },
        image: "/assets/book-04.svg"
    },
    5: {
        id: 5,
        title: "The Innovator's Dilemma",
        author: "Clayton M. Christensen",
        category: "technology",
        shortDesc: "Why new technologies cause great firms to fail and how disruptive innovation reshapes industries.",
        longDesc: "The Innovator's Dilemma demonstrates why outstanding companies that had their competitive antennae up, listened astutely to customers, and invested aggressively in new technologies still lost their market leadership. Clayton Christensen explains how these companies were victims of the innovator's dilemma: they were so focused on satisfying their most profitable customers that they missed the disruptive innovations that opened up new customer segments.",
        keyTakeaways: [
            "Disruptive technologies initially serve different customer segments",
            "Sustaining vs. disruptive innovation require different strategies",
            "Market leaders often fail because they listen too well to customers",
            "Resource allocation processes favor sustaining innovations",
            "Small markets don't solve big companies' growth needs"
        ],
        whoItsFor: "Technology leaders, business strategists, entrepreneurs, and anyone interested in understanding how innovation disrupts established industries.",
        publicationYear: 1997,
        externalLinks: {
            amazon: "https://amazon.com/Innovators-Dilemma-Technologies-Management-Innovation/dp/1633691780",
            audible: "https://audible.com/pd/The-Innovators-Dilemma-Audiobook/B012VMLTW2",
            googleBooks: "https://books.google.com/books?id=SIexi_qgq2gC"
        },
        image: "/assets/book-05.svg"
    },
    6: {
        id: 6,
        title: "Freakonomics",
        author: "Steven D. Levitt and Stephen J. Dubner",
        category: "economics",
        shortDesc: "A rogue economist explores the hidden side of everything, revealing surprising connections in everyday life.",
        longDesc: "Freakonomics establishes this unconventional premise: if morality represents how we would like the world to work, then economics represents how it actually does work. Through forceful storytelling and wry insight, Levitt and Dubner show that economics is, at root, the study of incentives—how people get what they want, or need, especially when other people want or need the same thing.",
        keyTakeaways: [
            "Incentives are the cornerstone of modern life",
            "Conventional wisdom is often wrong",
            "Dramatic effects often have distant causes",
            "Data analysis can reveal surprising patterns",
            "Correlation doesn't imply causation"
        ],
        whoItsFor: "Readers interested in economics, social science, critical thinking, and understanding the hidden forces that shape our world.",
        publicationYear: 2005,
        externalLinks: {
            amazon: "https://amazon.com/Freakonomics-Economist-Explores-Hidden-Everything/dp/0060731338",
            audible: "https://audible.com/pd/Freakonomics-Audiobook/B002V8KYMI",
            googleBooks: "https://books.google.com/books?id=1PuYGgAACAAJ"
        },
        image: "/assets/book-06.svg"
    },
    7: {
        id: 7,
        title: "Deep Work",
        author: "Cal Newport",
        category: "productivity",
        shortDesc: "Rules for focused success in a distracted world. Learn to perform at your peak in an age of constant connectivity.",
        longDesc: "Deep work is the ability to focus without distraction on a cognitively demanding task. It's a skill that allows you to quickly master complicated information and produce better results in less time. In this book, Cal Newport provides four rules for transforming your mind and habits to support deep work, and offers practical strategies for integrating focused thinking into your professional life.",
        keyTakeaways: [
            "Deep work is becoming increasingly rare and valuable",
            "Shallow work fills time but creates little value",
            "Attention residue reduces cognitive performance",
            "Ritualize deep work with consistent schedules and environments",
            "Embrace boredom to strengthen your focus muscles"
        ],
        whoItsFor: "Knowledge workers, professionals, students, and anyone seeking to improve their focus and produce higher quality work.",
        publicationYear: 2016,
        externalLinks: {
            amazon: "https://amazon.com/Deep-Work-Focused-Success-Distracted/dp/1455586692",
            audible: "https://audible.com/pd/Deep-Work-Audiobook/B0189PVAWY",
            googleBooks: "https://books.google.com/books?id=lZpKDAAAQBAJ"
        },
        image: "/assets/book-07.svg"
    },
    8: {
        id: 8,
        title: "Mindset",
        author: "Carol S. Dweck",
        category: "personal-development",
        shortDesc: "The new psychology of success. How we can learn to fulfill our potential through the power of believing we can improve.",
        longDesc: "After decades of research, world-renowned Stanford University psychologist Carol S. Dweck discovered a simple but groundbreaking idea: the power of mindset. In this brilliant book, she shows how success in school, work, sports, the arts, and almost every area of human endeavor can be dramatically influenced by how we think about our talents and abilities.",
        keyTakeaways: [
            "Fixed mindset believes abilities are static traits",
            "Growth mindset sees abilities as developable through effort",
            "Praise effort and process rather than intelligence or talent",
            "Failure is information, not a judgment of worth",
            "The word 'yet' transforms challenges into opportunities"
        ],
        whoItsFor: "Educators, parents, leaders, students, and anyone interested in personal development and unlocking human potential.",
        publicationYear: 2006,
        externalLinks: {
            amazon: "https://amazon.com/Mindset-Psychology-Carol-S-Dweck/dp/0345472322",
            audible: "https://audible.com/pd/Mindset-Audiobook/B003WUYPPG",
            googleBooks: "https://books.google.com/books?id=fdjqz0TPL2wC"
        },
        image: "/assets/book-08.svg"
    }
};

// Utility functions
function getUrlParameter(name) {
    const urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(name);
}

function formatCategory(category) {
    return category.split('-').map(word => 
        word.charAt(0).toUpperCase() + word.slice(1)
    ).join(' ');
}

function createBookCard(book) {
    return `
        <a href="/book/?id=${book.id}" class="book-card">
            <img src="${book.image}" alt="${book.title}" class="book-image" width="200" height="200">
            <h3>${book.title}</h3>
            <p class="book-author">by ${book.author}</p>
            <span class="book-category">${formatCategory(book.category)}</span>
            <p class="book-description">${book.shortDesc}</p>
        </a>
    `;
}

function filterBooks(searchTerm = '', category = '') {
    const books = Object.values(BOOKS_DATA);
    return books.filter(book => {
        const matchesSearch = !searchTerm || 
            book.title.toLowerCase().includes(searchTerm.toLowerCase()) ||
            book.author.toLowerCase().includes(searchTerm.toLowerCase());
        const matchesCategory = !category || book.category === category;
        return matchesSearch && matchesCategory;
    });
}

function renderBooks(books, containerId) {
    const container = document.getElementById(containerId);
    if (!container) return;
    
    if (books.length === 0) {
        container.innerHTML = '<p>No books found matching your criteria.</p>';
        return;
    }
    
    container.innerHTML = books.map(createBookCard).join('');
}

function renderBookDetails(bookId) {
    const book = BOOKS_DATA[bookId];
    const container = document.getElementById('book-details');
    
    if (!book) {
        container.innerHTML = `
            <div class="container">
                <div class="book-section">
                    <h1>Book Not Found</h1>
                    <p>The requested book could not be found.</p>
                    <a href="/books/" class="cta-button">Browse All Books</a>
                </div>
            </div>
        `;
        return;
    }
    
    // Update page title and meta description
    document.getElementById('page-title').textContent = `${book.title} - Book Expert View`;
    document.getElementById('page-description').setAttribute('content', book.shortDesc);
    
    container.innerHTML = `
        <div class="container">
            <nav style="margin-bottom: 2rem;">
                <a href="/books/" style="color: #3498db; text-decoration: none;">&larr; Back to Books</a>
            </nav>
            
            <div class="book-detail-content">
                <div>
                    <img src="${book.image}" alt="${book.title}" class="book-detail-image" width="300" height="400">
                </div>
                
                <div class="book-info">
                    <h1>${book.title}</h1>
                    <div class="book-meta">
                        <p><strong>Author:</strong> ${book.author}</p>
                        <p><strong>Category:</strong> ${formatCategory(book.category)}</p>
                        <p><strong>Publication Year:</strong> ${book.publicationYear}</p>
                    </div>
                    
                    <div class="disclaimer-notice">
                        <strong>Important:</strong> This book is sold by third-party platforms. We do not sell or distribute books directly.
                    </div>
                    
                    <div class="purchase-links">
                        <a href="${book.externalLinks.amazon}" target="_blank" rel="noopener noreferrer" class="purchase-link">View on Amazon</a>
                        <a href="${book.externalLinks.audible}" target="_blank" rel="noopener noreferrer" class="purchase-link">Listen on Audible</a>
                        <a href="${book.externalLinks.googleBooks}" target="_blank" rel="noopener noreferrer" class="purchase-link">Google Books</a>
                    </div>
                </div>
            </div>
            
            <div class="book-sections">
                <div class="book-section">
                    <h2>About This Book</h2>
                    <p>${book.longDesc}</p>
                </div>
                
                <div class="book-section">
                    <h2>Key Takeaways</h2>
                    <ul class="takeaways-list">
                        ${book.keyTakeaways.map(takeaway => `<li>${takeaway}</li>`).join('')}
                    </ul>
                </div>
                
                <div class="book-section">
                    <h2>Who This Book Is For</h2>
                    <p>${book.whoItsFor}</p>
                </div>
            </div>
        </div>
    `;
}

function renderCategoryBooks(category, containerId, limit = 2) {
    const books = Object.values(BOOKS_DATA)
        .filter(book => book.category === category)
        .slice(0, limit);
    
    const container = document.getElementById(containerId);
    if (!container) return;
    
    if (books.length === 0) {
        container.innerHTML = '<p>No books available in this category.</p>';
        return;
    }
    
    container.innerHTML = books.map(book => `
        <a href="/book/?id=${book.id}" class="book-card" style="text-decoration: none;">
            <img src="${book.image}" alt="${book.title}" class="book-image" width="150" height="150">
            <h4>${book.title}</h4>
            <p style="font-size: 0.9rem; color: #666;">${book.author}</p>
        </a>
    `).join('');
}

function handleContactForm() {
    const form = document.getElementById('contact-form');
    if (!form) return;
    
    form.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const messageDiv = document.getElementById('form-message');
        messageDiv.style.display = 'block';
        messageDiv.className = 'form-message success';
        messageDiv.textContent = 'Thank you for your message! We will get back to you soon.';
        
        form.reset();
        
        setTimeout(() => {
            messageDiv.style.display = 'none';
        }, 5000);
    });
}

function handleCookieBanner() {
    const banner = document.getElementById('cookie-banner');
    const acceptBtn = document.getElementById('cookie-accept');
    
    if (!banner || !acceptBtn) return;
    
    // Check if user has already accepted cookies
    if (!localStorage.getItem('cookies-accepted')) {
        banner.classList.add('show');
    }
    
    acceptBtn.addEventListener('click', function() {
        localStorage.setItem('cookies-accepted', 'true');
        banner.classList.remove('show');
    });
}

function handleMobileMenu() {
    const toggle = document.querySelector('.mobile-menu-toggle');
    const menu = document.querySelector('.nav-menu');
    
    if (!toggle || !menu) return;
    
    toggle.addEventListener('click', function() {
        menu.classList.toggle('mobile-active');
    });
}

// Page-specific initialization
function initHomePage() {
    // Render featured books (first 6 books)
    const featuredBooks = Object.values(BOOKS_DATA).slice(0, 6);
    renderBooks(featuredBooks, 'featured-books-grid');
}

function initBooksPage() {
    const searchInput = document.getElementById('search-input');
    const categoryFilter = document.getElementById('category-filter');
    
    // Initial render - all books
    let currentBooks = Object.values(BOOKS_DATA);
    
    // Check for category parameter in URL
    const categoryParam = getUrlParameter('category');
    if (categoryParam && categoryFilter) {
        categoryFilter.value = categoryParam;
        currentBooks = filterBooks('', categoryParam);
    }
    
    renderBooks(currentBooks, 'books-results');
    
    // Search functionality
    if (searchInput) {
        searchInput.addEventListener('input', function() {
            const searchTerm = this.value;
            const category = categoryFilter ? categoryFilter.value : '';
            const filteredBooks = filterBooks(searchTerm, category);
            renderBooks(filteredBooks, 'books-results');
        });
    }
    
    // Category filter functionality
    if (categoryFilter) {
        categoryFilter.addEventListener('change', function() {
            const category = this.value;
            const searchTerm = searchInput ? searchInput.value : '';
            const filteredBooks = filterBooks(searchTerm, category);
            renderBooks(filteredBooks, 'books-results');
        });
    }
}

function initBookPage() {
    const bookId = getUrlParameter('id');
    if (bookId) {
        renderBookDetails(parseInt(bookId));
    } else {
        renderBookDetails(null);
    }
}

function initCategoriesPage() {
    // Render books for each category
    renderCategoryBooks('business', 'business-books');
    renderCategoryBooks('economics', 'economics-books');
    renderCategoryBooks('technology', 'technology-books');
    renderCategoryBooks('productivity', 'productivity-books');
    renderCategoryBooks('personal-development', 'personal-development-books');
}

// Initialize the appropriate page
document.addEventListener('DOMContentLoaded', function() {
    // Common initialization for all pages
    handleCookieBanner();
    handleMobileMenu();
    handleContactForm();
    
    // Page-specific initialization
    const path = window.location.pathname;
    
    if (path === '/' || path === '/index/' || path.includes('index')) {
        initHomePage();
    } else if (path.includes('/books/')) {
        initBooksPage();
    } else if (path.includes('/book/')) {
        initBookPage();
    } else if (path.includes('/categories/')) {
        initCategoriesPage();
    }
});