<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ title }}</title>
    <meta name="description" content="{{ description }}">
    <meta property="og:title" content="{{ title }}">
    <meta property="og:description" content="{{ description }}">
    <meta property="og:type" content="article">
    <meta property="og:url" content="{{ base_url }}/{{ slug }}">
    <meta name="robots" content="index, follow">
    <link rel="alternate" type="text/markdown" href="/api/v1/documents/{{ slug }}" title="Full document (markdown)">
    <link rel="alternate" type="application/json" href="{{ base_url }}/api/v1/documents/{{ slug }}" />
    <!-- AI Agent: This document has additional structured content. Fetch the full version at: {{ base_url }}/api/v1/documents/{{ slug }} -->
    <style>
/* twofold — minimal theme
   Ultra-sparse. No borders. Maximum whitespace. Almost brutalist.
   Zero external requests. */

:root {
    --bg: #ffffff;
    --fg: #111111;
    --fg-secondary: #555555;
    --fg-muted: #999999;
    --border: #eeeeee;
    --accent: #111111;
    --link: #111111;
    --link-hover: #555555;
    --code-bg: #f7f7f7;
    --code-fg: #333333;
    --table-stripe: #fafafa;

    --font-body: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-heading: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;
    --font-size: 1rem;
    --line-height: 1.7;
    --max-width: 600px;

    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
    --space-xxl: 5rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111111;
        --fg: #eeeeee;
        --fg-secondary: #aaaaaa;
        --fg-muted: #666666;
        --border: #333333;
        --accent: #eeeeee;
        --link: #eeeeee;
        --link-hover: #aaaaaa;
        --code-bg: #1a1a1a;
        --code-fg: #cccccc;
        --table-stripe: #161616;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-body);
    font-size: var(--font-size);
    line-height: var(--line-height);
    overflow-wrap: break-word;
    -webkit-font-smoothing: antialiased;
}

main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-xxl) var(--space-lg);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.2;
    color: var(--fg);
    margin-bottom: var(--space-sm);
}

h1 {
    font-size: 1.5rem;
    margin-top: 0;
    margin-bottom: var(--space-xl);
    font-weight: 400;
}

h2 {
    font-size: 1.125rem;
    margin-top: var(--space-xl);
    font-weight: 600;
}

h3 {
    font-size: 1rem;
    margin-top: var(--space-lg);
    color: var(--fg-secondary);
}

h4, h5, h6 {
    font-size: 0.875rem;
    margin-top: var(--space-lg);
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

p { margin: 0 0 var(--space-md); }

strong { font-weight: 600; }

a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
}
a:hover { color: var(--link-hover); }

ul, ol { margin: 0 0 var(--space-md); padding-left: 1.2em; }
li { margin: 0.2em 0; }

blockquote {
    margin: var(--space-lg) 0;
    padding: 0 0 0 var(--space-lg);
    border-left: none;
    color: var(--fg-secondary);
    font-style: italic;
}
blockquote p:last-child { margin-bottom: 0; }

code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--code-bg);
    color: var(--code-fg);
    padding: 0.1em 0.3em;
    border-radius: 2px;
}

pre {
    background: var(--code-bg);
    padding: var(--space-md);
    overflow-x: auto;
    margin: var(--space-lg) 0;
    border-radius: 2px;
}

pre code {
    background: none;
    padding: 0;
    font-size: 0.8125rem;
    line-height: 1.6;
}

table {
    border-collapse: collapse;
    width: 100%;
    margin: var(--space-lg) 0;
    font-size: 0.875rem;
}
th {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fg-muted);
    border-bottom: 1px solid var(--border);
}
td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border);
}
tbody tr:nth-child(even) { background: var(--table-stripe); }
table { display: block; overflow-x: auto; }
thead, tbody, tr, th, td { display: revert; }

/* Code inside cells stays on one line; table scrolls horizontally instead */
td code, th code {
    white-space: nowrap;
    word-break: keep-all;
}

hr {
    border: none;
    height: 0;
    margin: var(--space-xxl) 0;
}

img { max-width: 100%; height: auto; }

footer {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
    text-align: center;
}
footer small {
    color: var(--fg-muted);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

footer small a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color 0.15s ease;
}

footer small a:hover {
    color: var(--link-hover);
}

@media (max-width: 600px) {
    main { padding: var(--space-xl) var(--space-md); }
    h1 { font-size: 1.25rem; }
}

::selection {
    background: rgba(0, 0, 0, 0.1);
}
@media (prefers-color-scheme: dark) {
    ::selection { background: rgba(255, 255, 255, 0.15); }
}

.doc-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.doc-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25em;
    padding: 0.2em 0.65em;
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 450;
    color: var(--fg-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s ease, border-color 0.15s ease;
    letter-spacing: 0.01em;
    white-space: nowrap;
    line-height: 1.6;
}

.doc-btn:hover {
    color: var(--fg-secondary);
    text-decoration: none;
}

.doc-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.doc-toast {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    padding: 0.4em 0.85em;
    background: var(--fg);
    color: var(--bg);
    font-family: var(--font-heading);
    font-size: 0.8rem;
    border-radius: 5px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 9999;
}

.doc-toast.doc-toast--visible {
    opacity: 1;
    transform: translateY(0);
}

/* Expiry countdown */
.doc-expiry {
    font-family: var(--font-heading);
    font-size: 0.72rem;
    color: var(--fg-muted);
    letter-spacing: 0.01em;
    white-space: nowrap;
    margin-right: auto;
}

.doc-expiry.expiry-urgent {
    color: #c0392b;
}

@media (prefers-color-scheme: dark) {
    .doc-expiry.expiry-urgent {
        color: #e57373;
    }
}

@media print {
    @page { margin: 2cm; }

    body {
        background: white !important;
        color: #111111 !important;
        font-size: 11pt;
    }

    main {
        max-width: none;
        padding: 0;
    }

    h1, h2, h3, h4, h5, h6 {
        color: #111111 !important;
        page-break-after: avoid;
    }

    a {
        color: #111111 !important;
        text-decoration: underline;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    /* Reset syntect inline styles if dark palette was used */
    pre[style] {
        background: #f7f7f7 !important;
        border: 1px solid #eee !important;
    }

    pre span[style] {
        color: #333 !important;
    }

    pre, code {
        background: #f7f7f7 !important;
        color: #333 !important;
        border: 1px solid #eee;
    }

    pre, blockquote, table {
        page-break-inside: avoid;
    }

    blockquote {
        color: #555 !important;
    }

    .doc-toolbar, .doc-toast, .doc-expiry { display: none; }
}
    </style>
</head>
<body>
    <main>
        <article>
            <div class="doc-toolbar">
                {% if let Some(exp) = expires_at %}
                <div class="doc-expiry" data-expires="{{ exp }}">
                    <span class="expiry-label">Expires in </span><span class="expiry-countdown"></span>
                </div>
                {% endif %}
                <button class="doc-btn" id="btn-copy-url" title="Copy link to clipboard">
                    Copy link
                </button>
                <button class="doc-btn" id="btn-copy-md" title="Copy markdown source to clipboard">
                    Copy markdown
                </button>
                <button class="doc-btn" id="btn-pdf" title="Save as PDF"{% if body_empty %} hidden{% endif %}>PDF</button>
                <a class="doc-btn" id="btn-view-raw" href="#" title="View raw markdown source">
                    View raw
                </a>
            </div>
            {{ content|safe }}
        </article>
    </main>
    <footer>
        <small>shared via <a href="https://github.com/gabaum10/twofold">twofold</a></small>
        <div style="margin-top: 3rem; padding-top: 1rem; border-top: 1px solid rgba(128,128,128,0.2); font-size: 0.75rem; color: rgba(128,128,128,0.5);">
            Full document: <a href="{{ base_url }}/api/v1/documents/{{ slug }}" style="color: inherit;">{{ base_url }}/api/v1/documents/{{ slug }}</a>
        </div>
    </footer>

    <div class="doc-toast" id="doc-toast" aria-live="polite"></div>

    <script>
    (function () {
        'use strict';

        var toast = document.getElementById('doc-toast');
        var toastTimer = null;

        function showToast(msg) {
            if (toastTimer) clearTimeout(toastTimer);
            toast.textContent = msg;
            toast.classList.add('doc-toast--visible');
            toastTimer = setTimeout(function () {
                toast.classList.remove('doc-toast--visible');
            }, 2000);
        }

        var pathParts = window.location.pathname.replace(/^\//, '').split('/');
        var slug = pathParts[0];
        var rawUrl = window.location.origin + '/' + slug + '?raw=1';

        document.getElementById('btn-view-raw').href = rawUrl;

        document.getElementById('btn-copy-url').addEventListener('click', function () {
            navigator.clipboard.writeText(window.location.href).then(function () {
                showToast('Copied!');
            }).catch(function () {
                showToast('Copy failed');
            });
        });

        document.getElementById('btn-copy-md').addEventListener('click', function () {
            fetch('/' + slug + '?raw=1')
                .then(function (r) { return r.text(); })
                .then(function (text) {
                    return navigator.clipboard.writeText(text);
                })
                .then(function () {
                    showToast('Copied markdown!');
                })
                .catch(function () {
                    showToast('Copy failed');
                });
        });

        var btnPdf = document.getElementById('btn-pdf');
        if (btnPdf) {
            btnPdf.addEventListener('click', function() {
                window.print();
            });
        }
    })();

    (function() {
        var el = document.querySelector('.doc-expiry');
        if (!el) return;
        var exp = new Date(el.dataset.expires);

        function update() {
            var now = new Date();
            var diff = exp - now;
            if (diff <= 0) {
                el.querySelector('.expiry-countdown').textContent = 'expired';
                el.classList.add('expired');
                return;
            }
            var days = Math.floor(diff / 86400000);
            var h = Math.floor((diff % 86400000) / 3600000);
            var m = Math.floor((diff % 3600000) / 60000);
            var text = '';
            if (days > 0) {
                text = days + (days === 1 ? ' day' : ' days');
                if (h > 0) text += ', ' + h + (h === 1 ? ' hour' : ' hours');
            } else if (h > 0) {
                text = h + (h === 1 ? ' hour' : ' hours');
                if (m > 0) text += ', ' + m + (m === 1 ? ' minute' : ' minutes');
            } else {
                text = (m > 0 ? m : 1) + (m === 1 ? ' minute' : ' minutes');
            }
            el.querySelector('.expiry-countdown').textContent = text;
            if (diff < 300000) el.classList.add('expiry-urgent');
        }
        update();
        setInterval(update, 1000);
    })();
    </script>
</body>
</html>
