<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ book }} {{ chapter }}:{{ verse_num }} (KJV)</title>
    <style>
        @page {
            size: letter;
            margin: 0.85in;
            @bottom-center {
                content: counter(page);
                font-family: "et-book", Georgia, serif;
                font-size: 10pt;
                color: #666;
            }
        }

        body {
            font-family: "et-book", Georgia, "Times New Roman", serif;
            font-size: 11.25pt;
            line-height: 1.65;
            color: #111;
        }

        h1 {
            font-weight: normal;
            letter-spacing: 0.05em;
            font-size: 22pt;
            margin: 0 0 0.1in 0;
        }

        .subtitle {
            font-style: italic;
            color: #666;
            margin-bottom: 0.3in;
        }

        .verse-text-main {
            font-size: 14pt;
            line-height: 1.8;
            margin: 0.3in 0;
            padding: 0.2in;
            border-left: 3px solid #4a7c59;
            background: #f9f9f9;
        }

        h2 {
            font-size: 14pt;
            font-weight: 600;
            margin: 0.3in 0 0.15in 0;
            color: #333;
            border-bottom: 1px solid #ddd;
            padding-bottom: 0.05in;
        }

        h3 {
            font-size: 12pt;
            font-weight: 600;
            margin: 0.2in 0 0.1in 0;
            color: #444;
        }

        p {
            margin: 0.1in 0;
            text-align: justify;
        }

        .cross-ref-group {
            margin: 0.15in 0;
        }

        .cross-ref-group strong {
            color: #333;
        }

        .cross-ref-list {
            margin-left: 0.2in;
            color: #555;
        }

        .word-study {
            margin: 0.15in 0;
            padding: 0.1in;
            background: #f5f5f5;
            border-radius: 3px;
        }

        .word-study-term {
            font-weight: 600;
            color: #4a7c59;
        }

        .word-study-original {
            font-style: italic;
        }

        .interlinear-section {
            margin: 0.2in 0;
        }

        .interlinear-flow {
            display: flex;
            flex-wrap: wrap;
            gap: 0.1in;
            margin: 0.1in 0;
        }

        .word-unit {
            text-align: center;
            padding: 0.05in;
        }

        .word-original {
            font-size: 14pt;
            display: block;
        }

        .word-original.hebrew {
            direction: rtl;
            font-family: "SBL Hebrew", "Ezra SIL", "Times New Roman", serif;
            font-size: 16pt;
        }

        .word-original.greek {
            font-family: "SBL Greek", "Gentium Plus", "Times New Roman", serif;
            font-size: 14pt;
        }

        .word-english {
            font-size: 9pt;
            color: #4a7c59;
            font-weight: 600;
            display: block;
        }

        .word-strongs {
            font-size: 7pt;
            color: #888;
            font-family: monospace;
            display: block;
        }

        .footer {
            margin-top: 0.4in;
            font-size: 9pt;
            color: #888;
            text-align: center;
            border-top: 1px solid #ddd;
            padding-top: 0.1in;
        }

        /* Style sidenotes as inline notes for PDF */
        .margin-toggle,
        .sidenote-number,
        input[type="checkbox"] {
            display: none !important;
        }

        .sidenote,
        .marginnote {
            display: block;
            float: none;
            width: 100%;
            margin: 0.15in 0;
            padding: 0.1in 0.15in;
            font-size: 9pt;
            font-style: italic;
            color: #555;
            background: #f9f9f9;
            border-left: 2px solid #ccc;
        }

        .sidenote::before {
            content: "Note: ";
            font-weight: 600;
            font-style: normal;
        }
    </style>
</head>
<body>
    <h1>{{ book }} {{ chapter }}:{{ verse_num }}</h1>
    <p class="subtitle">Authorized King James Version (KJV)</p>

    <div class="verse-text-main">
        {{ verse_text }}
    </div>

    {% if commentary %}
    {% if commentary.analysis %}
    <h2>Analysis</h2>
    <p>{{ commentary.analysis | safe }}</p>
    {% endif %}

    {% if commentary.historical %}
    <h2>Historical Context</h2>
    <p>{{ commentary.historical | safe }}</p>
    {% endif %}

    {% if commentary.cross_references %}
    <h2>Related Passages</h2>
    {% for ref in commentary.cross_references %}
    <div class="cross-ref-group">
        <strong>{{ ref.text }}</strong>{% if ref.context %} — {{ ref.context }}{% endif %}
        {% if ref.verse_text %}<br/><em style="color: #555; font-size: 10pt;">{{ ref.verse_text }}</em>{% endif %}
    </div>
    {% endfor %}
    {% endif %}

    {% if commentary.questions %}
    <h2>Study Questions</h2>
    <ol>
    {% for question in commentary.questions %}
        <li>{{ question }}</li>
    {% endfor %}
    </ol>
    {% endif %}
    {% endif %}

    {% if interlinear_words %}
    <h2>Interlinear Text</h2>
    <div class="interlinear-section">
        <div class="interlinear-flow">
            {% for word in interlinear_words %}
            <div class="word-unit">
                <span class="word-original {% if is_old_testament %}hebrew{% else %}greek{% endif %}">{{ word.original }}</span>
                <span class="word-english">{{ word.english }}</span>
                {% if word.strongs %}
                <span class="word-strongs">{{ word.strongs }}</span>
                {% endif %}
            </div>
            {% endfor %}
        </div>
    </div>
    {% endif %}

    {% if cross_references %}
    <h2>Additional Cross-References</h2>
    {% for xref in cross_references[:10] %}
    <p><strong>{{ xref.ref }}</strong>{% if xref.note %} ({{ xref.note }}){% endif %}{% if xref.text %}: <em>{{ xref.text }}</em>{% endif %}</p>
    {% endfor %}
    {% endif %}

    <div class="footer">
        From KJV Study &bull; kjvstudy.org
    </div>
</body>
</html>
