{% extends "base.html" %}

{% block title %}Women of the Bible - KJV Study{% endblock %}
{% block description %}Explore the lives, faith, and legacies of notable women throughout Scripture.{% endblock %}

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

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

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

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

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

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

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

.woman-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;
}

.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;
}

.women-actions {
    display: flex;
    gap: 0.75rem;
    margin: 1rem 0 1.5rem;
}

.action-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;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

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

    .woman-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>Women of the Bible</h1>
<p class="subtitle">Faithful Witnesses Throughout Redemptive History</p>

<div class="women-actions">
    <button class="action-btn" id="listen-btn">
        <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="M15.536 8.464a5 5 0 010 7.072m2.828-9.9a9 9 0 010 12.728M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z" />
        </svg>
        Listen
    </button>
    {% if pdf_available %}
    <a class="action-btn" href="/women-of-the-bible/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 PDF
    </a>
    {% endif %}
</div>

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

<section>
    <p class="intro-text"><span class="newthought">The biblical narrative</span> features numerous women whose faith, courage, and devotion shaped Israel's history and the church's foundation. From Eden's first mother to the women who followed Christ, these accounts demonstrate that God uses both men and women to accomplish His purposes.<label for="sn-women" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-women" class="margin-toggle"/>
    <span class="sidenote">Ancient Near Eastern culture typically marginalized women, making Scripture's attention to their stories remarkable. The biblical text neither idealizes nor denigrates women but presents them realistically—displaying both their faith and their failures, their wisdom and their weaknesses.</span></p>

    <p class="intro-text">Scripture affirms both the equal dignity of men and women as divine image-bearers and their distinct roles in God's order. These women exemplify godliness not by conforming to modern expectations but by faithfully fulfilling their callings within their historical and cultural contexts.<label for="sn-roles" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-roles" class="margin-toggle"/>
    <span class="sidenote">The biblical complementarity of men and women appears in creation's order, the Fall's effects, and redemption's restoration. While roles differ, value remains equal—a truth often obscured by both ancient patriarchy and modern egalitarianism.</span></p>
</section>

{% for category, women in women_data.items() %}
<section class="woman-section">
    <h2>{{ category }}</h2>

    {% for woman_name, woman in women.items() %}
    <article class="woman-entry">
        <h3 class="woman-name">
          <a href="/women-of-the-bible/{{ woman_name|slugify }}">{{ woman_name }}</a>
        </h3>
        <p class="woman-title">{{ woman.title }}</p>

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

        {% if woman.verses %}
        <div class="verse-list">
            {% for verse in woman.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 Biblical Women</h2>
    <p class="intro-text">These accounts instruct contemporary believers in several ways:</p>

    <p class="intro-text"><span class="newthought">Faithful service</span>, for these women served God within their spheres of influence—whether as mothers training children in godliness, as prophets declaring divine truth, or as benefactors supporting Christ's ministry. Faithfulness, not prominence, characterizes biblical heroines.</p>

    <p class="intro-text"><span class="newthought">Sovereign grace</span>, as God included unlikely candidates in His redemptive plan—a Moabite widow, a Canaanite harlot, an adulteress. The presence of Tamar, Rahab, Ruth, and Bathsheba in Christ's genealogy demonstrates that grace, not merit, determines inclusion in God's purposes.<label for="sn-genealogy" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-genealogy" class="margin-toggle"/>
    <span class="sidenote">Matthew's inclusion of four women (plus Mary) in Christ's genealogy was highly unusual. Three were Gentiles; most had questionable backgrounds. This deliberate emphasis on grace anticipates the gospel's universal offer to all who believe, regardless of ethnic or moral background.</span></p>

    <p class="intro-text"><span class="newthought">Covenantal faithfulness</span>, for many biblical women demonstrated remarkable faith in God's promises. Sarah, despite her laughter, believed God's impossible promise. Ruth chose Israel's God over Moab's deities. Mary submitted to bearing the Messiah despite social scandal. Their faith overcame fear and doubt.</p>

    <p class="intro-text"><span class="newthought">Redemptive hope</span>, as the protevangelium promised the woman's seed would crush the serpent. Every godly woman in Israel potentially participated in this promise, culminating in Mary's conception of Christ. The virgin birth fulfilled this ancient hope, demonstrating God's faithfulness across millennia.<label for="sn-seed" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-seed" class="margin-toggle"/>
    <span class="sidenote">Genesis 3:15's unusual phrase 'her seed' (rather than 'his seed') finds ultimate explanation in the virgin birth. Christ, born of woman without human father, crushed Satan through His death and resurrection—fulfilling the first gospel promise given to fallen humanity.</span></p>
</section>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // Listen button handler
    var listenBtn = document.getElementById('listen-btn');
    var isListening = false;
    if (listenBtn) {
        listenBtn.addEventListener('click', function() {
            if (isListening) {
                if (window.KJVSpeech) window.KJVSpeech.stop();
                listenBtn.innerHTML = '<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="M15.536 8.464a5 5 0 010 7.072m2.828-9.9a9 9 0 010 12.728M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z" /></svg> Listen';
                isListening = false;
                return;
            }
            var paragraphs = document.querySelectorAll('.intro-text, .woman-description p, .verse-text');
            var text = Array.from(paragraphs).map(function(p) {
                return p.textContent.trim();
            }).join(' ');
            if (window.KJVSpeech && text) {
                window.KJVSpeech.speak(text);
                listenBtn.innerHTML = '<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="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 10a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z" /></svg> Stop';
                isListening = true;
            }
        });
    }

    // 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('.action-btn, .intro-text, .woman-name, .woman-description > p, .verse-item');
});
</script>
{% endblock %}
