{% extends "base.html" %}

{% block title %}Books of the Bible - KJV Study{% endblock %}
{% block description %}Browse all 66 books of the Authorized King James Version Bible{% endblock %}

{% block head %}
<style>
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    max-width: 90%;
    margin: 2rem 0;
}

.book-card {
    display: block;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text-color);
}

.book-card:hover {
    border-color: var(--border-color-darker);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
}

.book-card.selected {
    border-color: #4a7c59;
    box-shadow: 0 0 0 2px rgba(74, 124, 89, 0.3);
    outline: none;
}

.book-card.selected .book-name {
    color: #4a7c59;
}

[data-theme="dark"] .book-card.selected {
    border-color: #6b9b7a;
    box-shadow: 0 0 0 2px rgba(107, 155, 122, 0.3);
}

[data-theme="dark"] .book-card.selected .book-name {
    color: #6b9b7a;
}

.book-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--link-color);
}

.book-card:hover .book-name {
    color: var(--link-hover);
}

.book-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

.testament-section {
    margin: 2rem 0;
}

.testament-header {
    font-size: 1.6rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.intro-text {
    max-width: 60%;
    font-size: 1.2rem;
    line-height: 1.9;
    margin: 1rem 0;
}

/* Book type color coding - works in both light and dark modes */
.book-card.law {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(59, 130, 246, 0.03));
    border-left: 3px solid rgba(59, 130, 246, 0.4);
}

.book-card.historical {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.08), rgba(34, 197, 94, 0.03));
    border-left: 3px solid rgba(34, 197, 94, 0.4);
}

.book-card.wisdom {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.08), rgba(168, 85, 247, 0.03));
    border-left: 3px solid rgba(168, 85, 247, 0.4);
}

.book-card.major-prophets {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.08), rgba(249, 115, 22, 0.03));
    border-left: 3px solid rgba(249, 115, 22, 0.4);
}

.book-card.minor-prophets {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.08), rgba(239, 68, 68, 0.03));
    border-left: 3px solid rgba(239, 68, 68, 0.4);
}

.book-card.gospels {
    background: linear-gradient(135deg, rgba(234, 179, 8, 0.08), rgba(234, 179, 8, 0.03));
    border-left: 3px solid rgba(234, 179, 8, 0.4);
}

.book-card.acts {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.08), rgba(20, 184, 166, 0.03));
    border-left: 3px solid rgba(20, 184, 166, 0.4);
}

.book-card.pauline {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(99, 102, 241, 0.03));
    border-left: 3px solid rgba(99, 102, 241, 0.4);
}

.book-card.general {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.08), rgba(236, 72, 153, 0.03));
    border-left: 3px solid rgba(236, 72, 153, 0.4);
}

.book-card.apocalyptic {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.08), rgba(220, 38, 38, 0.03));
    border-left: 3px solid rgba(220, 38, 38, 0.4);
}

/* Legend styles */
.legend {
    margin: 1.5rem 0 2rem 0;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.legend-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.legend-color {
    width: 24px;
    height: 24px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-color.law {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(59, 130, 246, 0.03));
    border-left: 3px solid rgba(59, 130, 246, 0.4);
}

.legend-color.historical {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.08), rgba(34, 197, 94, 0.03));
    border-left: 3px solid rgba(34, 197, 94, 0.4);
}

.legend-color.wisdom {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.08), rgba(168, 85, 247, 0.03));
    border-left: 3px solid rgba(168, 85, 247, 0.4);
}

.legend-color.major-prophets {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.08), rgba(249, 115, 22, 0.03));
    border-left: 3px solid rgba(249, 115, 22, 0.4);
}

.legend-color.minor-prophets {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.08), rgba(239, 68, 68, 0.03));
    border-left: 3px solid rgba(239, 68, 68, 0.4);
}

.legend-color.gospels {
    background: linear-gradient(135deg, rgba(234, 179, 8, 0.08), rgba(234, 179, 8, 0.03));
    border-left: 3px solid rgba(234, 179, 8, 0.4);
}

.legend-color.acts {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.08), rgba(20, 184, 166, 0.03));
    border-left: 3px solid rgba(20, 184, 166, 0.4);
}

.legend-color.pauline {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(99, 102, 241, 0.03));
    border-left: 3px solid rgba(99, 102, 241, 0.4);
}

.legend-color.general {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.08), rgba(236, 72, 153, 0.03));
    border-left: 3px solid rgba(236, 72, 153, 0.4);
}

.legend-color.apocalyptic {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.08), rgba(220, 38, 38, 0.03));
    border-left: 3px solid rgba(220, 38, 38, 0.4);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .book-grid {
        max-width: 100%;
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 0.75rem;
    }

    .book-card {
        padding: 0.9rem;
        min-height: 70px;
    }

    .book-name {
        font-size: 1.05rem;
    }

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

    .testament-header {
        font-size: 1.3rem;
    }

    .intro-text {
        max-width: 100%;
        font-size: 1.1rem;
    }

    .legend {
        padding: 0.75rem;
    }

    .legend-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }

    .legend-item {
        font-size: 0.75rem;
    }

    .legend-color {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 480px) {
    .book-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .book-card {
        padding: 0.75rem;
    }

    .book-name {
        font-size: 0.95rem;
    }

    .legend-grid {
        grid-template-columns: 1fr 1fr;
    }
}
</style>
{% endblock %}

{% block content %}
<h1>Books of the Bible</h1>
<p class="subtitle">The Authorized King James Version</p>

<section id="old-testament" class="testament-section">
    <h2 class="testament-header">Old Testament</h2>
    <div class="book-grid">
        {% for book in old_testament %}
        {% if book.available %}
        <a href="/book/{{ book.name }}" class="book-card {{ book.type }}">
            <div class="book-name">{{ book.name }}</div>
            <div class="book-info">{{ book.chapters }} {% if book.chapters == 1 %}chapter{% else %}chapters{% endif %}</div>
        </a>
        {% endif %}
        {% endfor %}
    </div>
</section>

<section id="new-testament" class="testament-section">
    <h2 class="testament-header">New Testament</h2>
    <div class="book-grid">
        {% for book in new_testament %}
        {% if book.available %}
        <a href="/book/{{ book.name }}" class="book-card {{ book.type }}">
            <div class="book-name">{{ book.name }}</div>
            <div class="book-info">{{ book.chapters }} {% if book.chapters == 1 %}chapter{% else %}chapters{% endif %}</div>
        </a>
        {% endif %}
        {% endfor %}
    </div>
</section>

<div id="book-categories" class="legend">
    <div class="legend-title">Book Categories</div>
    <div class="legend-grid">
        <div class="legend-item">
            <div class="legend-color law"></div>
            <span>Law</span>
        </div>
        <div class="legend-item">
            <div class="legend-color historical"></div>
            <span>Historical</span>
        </div>
        <div class="legend-item">
            <div class="legend-color wisdom"></div>
            <span>Wisdom</span>
        </div>
        <div class="legend-item">
            <div class="legend-color major-prophets"></div>
            <span>Major Prophets</span>
        </div>
        <div class="legend-item">
            <div class="legend-color minor-prophets"></div>
            <span>Minor Prophets</span>
        </div>
        <div class="legend-item">
            <div class="legend-color gospels"></div>
            <span>Gospels</span>
        </div>
        <div class="legend-item">
            <div class="legend-color acts"></div>
            <span>Acts</span>
        </div>
        <div class="legend-item">
            <div class="legend-color pauline"></div>
            <span>Pauline Epistles</span>
        </div>
        <div class="legend-item">
            <div class="legend-color general"></div>
            <span>General Epistles</span>
        </div>
        <div class="legend-item">
            <div class="legend-color apocalyptic"></div>
            <span>Apocalyptic</span>
        </div>
    </div>
</div>

<script>
// Use standardized grid navigation from base.js
document.addEventListener('DOMContentLoaded', function() {
    if (window.KJVNav && KJVNav.initGridNav) {
        KJVNav.initGridNav('.book-card', { gridSelector: '.book-grid' });
    }
});
</script>
{% endblock %}
