<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ topic_name }} - Topical Study</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: 11pt;
            line-height: 1.6;
            color: #111;
        }

        h1 {
            font-size: 24pt;
            font-weight: normal;
            margin: 0 0 0.15in 0;
        }

        h2 {
            font-size: 16pt;
            font-weight: normal;
            margin-top: 0.35in;
        }

        h3 {
            font-size: 13pt;
            margin-bottom: 0.1in;
        }

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

        .overview {
            margin-bottom: 0.3in;
        }

        .verse-list {
            list-style: none;
            padding: 0;
            margin: 0.15in 0;
        }

        .verse-item {
            margin-bottom: 0.12in;
            padding-left: 0.2in;
            border-left: 2px solid #eee;
        }

        .verse-ref {
            font-weight: 600;
            color: #444;
        }

        .verse-note {
            font-style: italic;
            color: #666;
            margin-left: 0.2in;
        }

        .footer {
            margin-top: 0.5in;
            font-size: 9pt;
            color: #888;
            text-align: center;
        }

        /* 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>{{ topic_name }}</h1>
    <p class="subtitle">{{ topic.description }}</p>

    {% if topic.overview %}
    <div class="overview">{{ topic.overview | safe }}</div>
    {% endif %}

    {% for subtopic_name, subtopic in topic.subtopics.items() %}
    <section>
        <h2>{{ subtopic_name }}</h2>
        <p>{{ subtopic.description }}</p>
        {% if subtopic.verses %}
        <ul class="verse-list">
            {% for verse in subtopic.verses %}
            <li class="verse-item">
                {% set reference = verse.reference if verse.reference is defined else (verse.ref if verse.ref is defined else verse) %}
                {% if reference is not string %}
                    {% set reference = reference|string %}
                {% endif %}
                <span class="verse-ref">{{ reference }}</span>
                {% if verse.note is defined and verse.note %}<span class="verse-note">— {{ verse.note }}</span>{% endif %}
                {% if verse.text is defined and verse.text %}
                <div style="margin-top: 6px; color: #555;">
                    {{ verse.text }}
                </div>
                {% endif %}
            </li>
            {% endfor %}
        </ul>
        {% endif %}
    </section>
    {% endfor %}

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