{% extends "base.html" %}

{% block title %}Biblical Festivals - KJV Study{% endblock %}
{% block description %}Explore the sacred feasts and festivals of Israel, their historical significance, and their prophetic fulfillment in Christ.{% endblock %}

{% block head %}
<style>
.festival-section {
    margin: 1.5rem 0;
    padding-top: 1rem;
}

.festival-section:not(:first-of-type) {
    border-top: 1px solid var(--border-color);
}

.festival-entry {
    margin: 1.5rem 0 2rem 0;
}

.festival-name {
    font-size: 1.8rem;
    font-weight: 400;
    margin-bottom: 0.25rem;
}

.festival-name a {
    color: var(--link-color);
    text-decoration: none;
}

.festival-name a:hover {
    color: var(--link-hover);
    border-bottom: 1px solid var(--link-hover);
}

.festival-title {
    font-size: 1.1rem;
    color: #666;
    font-style: italic;
    margin-bottom: 1rem;
}

.festival-description {
    max-width: 60%;
    font-size: 1.2rem;
    line-height: 1.9;
    margin: 1.5rem 0;
}

.verse-list {
    margin: 1.5rem 0 0 0;
}

.verse-item {
    margin: 1.2rem 0;
    padding-left: 1.5rem;
    border-left: 2px solid #ddd;
}

.verse-ref {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.verse-ref a {
    color: #333;
    text-decoration: none;
    border-bottom: 1px solid #ddd;
}

.verse-ref a:hover {
    border-bottom-color: #333;
}

.verse-text {
    max-width: 60%;
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.8;
}

.festivals-actions {
    margin: 1rem 0 1.5rem;
}

.festivals-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary, #666);
    background: var(--code-bg, #f8f8f8);
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.2s;
}

.festivals-download-btn:hover {
    background: var(--bg-color, #fff);
    border-color: var(--link-color);
    color: var(--link-color);
}

.festivals-download-btn svg {
    width: 14px;
    height: 14px;
}

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

.toc {
    max-width: 55%;
    margin: 2rem 0;
    padding: 1.5rem;
    border-left: 3px solid var(--border-color-darker);
}

.toc h2 {
    margin-top: 0;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc li {
    margin: 0.5rem 0;
    line-height: 1.6;
}

.toc a {
    color: var(--text-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.toc a:hover {
    color: var(--link-color);
    border-bottom-color: var(--link-color);
}

.toc li.toc-h3 {
    padding-left: 1.5rem;
    font-size: 0.95rem;
}

@media print {
    .festivals-actions,
    .festivals-download-btn,
    .toc {
        display: none !important;
    }

    .festival-description,
    .verse-text,
    .intro-text {
        max-width: 100% !important;
    }

    .festival-entry {
        page-break-inside: avoid;
    }

    .sidenote,
    .marginnote {
        display: block;
        float: none;
        width: 100%;
        margin: 0.5rem 0;
        font-size: 0.9rem;
        color: #666;
    }
}
</style>
{% endblock %}

<script>
document.body.dataset.resourceReader = 'true';
</script>

{% block content %}
<h1>Biblical Festivals</h1>
<p class="subtitle">The Sacred Feasts of Israel and Their Prophetic Significance</p>

{% if pdf_available %}
<div class="festivals-actions">
    <a class="festivals-download-btn" href="/biblical-festivals/pdf">
        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
        </svg>
        Download All Festivals (PDF)
    </a>
</div>
{% endif %}

<nav class="toc" id="toc">
    <h2>Contents</h2>
    <ul id="toc-list"></ul>
</nav>

<section>
    <p class="intro-text"><span class="newthought">The appointed feasts</span> of Israel, ordained by God in Leviticus 23, constitute far more than commemorations of historical events. These sacred assemblies (Hebrew מוֹעֲדִים, <em>mo'adim</em>—"appointed times") formed the liturgical calendar around which Israel's worship revolved, and each contains rich typological significance pointing to the Messiah.<label for="sn-feasts" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-feasts" class="margin-toggle"/>
    <span class="sidenote">The Hebrew word חַג (<em>chag</em>) denotes a pilgrim feast requiring attendance at the sanctuary—Passover, Pentecost, and Tabernacles. Lesser feasts (Trumpets, Atonement) still demanded holy convocation. These festivals structured Israel's year and maintained covenant relationship through corporate worship.</span></p>

    <p class="intro-text">The festal calendar divides into spring and fall observances, separated by the agricultural work of summer. The spring feasts—Passover through Pentecost—find clear fulfillment in Christ's first advent. The fall feasts—Trumpets through Tabernacles—anticipate events connected with His second coming and millennial reign.<label for="sn-fulfillment" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-fulfillment" class="margin-toggle"/>
    <span class="sidenote\">Christ fulfilled the spring feasts with remarkable precision: crucified on Passover, buried during Unleavened Bread, resurrected on Firstfruits, and sending the Spirit on Pentecost. This exact correspondence strengthens confidence that the fall feasts will likewise find literal fulfillment in end-time events.</span></p>
</section>

{% for category, festivals in festivals_data.items() %}
<section class="festival-section">
    <h2>{{ category }}</h2>

    {% for festival_name, festival in festivals.items() %}
    <article class="festival-entry">
        <h3 class="festival-name">
          <a href="/biblical-festivals/{{ festival_name|slugify }}">{{ festival_name }}</a>
        </h3>
        <p class="festival-title">{{ festival.title }}</p>

        <div class="festival-description">
            <p>{{ festival.description | link_verses | link_names | safe }}</p>
        </div>

        {% if festival.verses %}
        <div class="verse-list">
            {% for verse in festival.verses %}
            <div class="verse-item">
                <div class="verse-ref">
                    {% set ref_parts = verse.reference.split(' ') %}
                    {% if ref_parts|length >= 2 %}
                        {% set chapter_verse = ref_parts[-1] %}
                        {% if ':' in chapter_verse %}
                            {% set chapter = chapter_verse.split(':')[0] %}
                            {% set verse_num = chapter_verse.split(':')[1] %}
                            {% set book = ' '.join(ref_parts[:-1]) %}
                            <a href="/book/{{ book }}/chapter/{{ chapter }}/verse/{{ verse_num }}">{{ verse.reference }}</a>
                        {% endif %}
                    {% endif %}
                </div>
                <div class="verse-text">{{ verse.text | link_names | safe }}</div>
            </div>
            {% endfor %}
        </div>
        {% endif %}
    </article>
    {% endfor %}
</section>
{% endfor %}

<section>
    <h2>The Significance of the Festivals</h2>
    <p class="intro-text">Understanding these appointed times enriches biblical interpretation and deepens appreciation for God's redemptive plan:</p>

    <p class="intro-text"><span class="newthought">Divine precision</span>, for God commanded these observances centuries before their fulfillment in Christ. The exact correspondence between festival requirements and Messianic events demonstrates supernatural design, providing powerful evidence for inspiration.</p>

    <p class="intro-text"><span class="newthought">Covenant remembrance</span>, as the festivals kept God's mighty acts perpetually before Israel. Each generation relived the Exodus through Passover, recalled Sinai at Pentecost, and remembered wilderness wanderings during Tabernacles. Corporate memory maintained covenant identity.<label for="sn-remembrance" class="margin-toggle sidenote-number\"></label>
    <input type="checkbox" id="sn-remembrance" class="margin-toggle"/>
    <span class="sidenote\">The command to tell children about Passover's meaning (Exodus 12:26-27) illustrates how festivals transmitted faith across generations. These annual celebrations educated each new generation in covenant history and theology through participatory ritual rather than mere abstract instruction.</span></p>

    <p class="intro-text"><span class="newthought">Prophetic preview</span>, for the festivals outlined redemptive history in advance. Christ fulfilled the spring feasts at His first coming—dying as the Passover Lamb, rising as the Firstfruits, sending the Spirit at Pentecost. The unfulfilled fall feasts point to His return, national Israel's repentance (Trumpets, Atonement), and millennial blessing (Tabernacles).</p>

    <p class="intro-text"><span class="newthought">Worship structure</span>, as these festivals provided rhythm and pattern for Israel's religious year. Modern believers, while not bound to observe these feasts, benefit from structured worship and corporate remembrance of God's redemptive acts—principles embodied in the Lord's Day and ordinances of baptism and communion.<label for="sn-application" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-application" class="margin-toggle"/>
    <span class="sidenote">Colossians 2:16-17 clarifies that festivals were "a shadow of things to come; but the body is of Christ." Believers need not observe Jewish feast days, yet studying them illuminates Christ's work and God's purposes. The shadow points to the substance; knowing both enriches understanding.</span></p>
</section>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // Generate TOC from h2 and h3 headings
    const tocList = document.getElementById('toc-list');
    const headings = document.querySelectorAll('section h2, section h3, section article h3');

    headings.forEach((heading) => {
        if (!heading.id) {
            heading.id = 'section-' + heading.textContent.toLowerCase().replace(/[^a-z0-9]+/g, '-');
        }
        const li = document.createElement('li');
        if (heading.tagName === 'H3') li.classList.add('toc-h3');
        const a = document.createElement('a');
        a.href = '#' + heading.id;
        a.textContent = heading.textContent;
        li.appendChild(a);
        tocList.appendChild(li);
    });

    // Simple keyboard navigation
    KJVNav.initSimpleNav('.festivals-download-btn, .intro-text, .festival-name, .festival-description > p, .verse-item');
});
</script>
{% endblock %}
