{% extends "base.html" %}

{% block title %}Decode Message - Stegasoo{% endblock %}

{% block content %}
<style>
/* Glowing passphrase input */
.passphrase-input {
    background: rgba(30, 40, 50, 0.8) !important;
    border: 2px solid rgba(99, 179, 237, 0.3) !important;
    color: #63b3ed !important;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
    padding: 12px 16px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.passphrase-input:focus {
    border-color: rgba(99, 179, 237, 0.8) !important;
    box-shadow: 0 0 20px rgba(99, 179, 237, 0.4), 0 0 40px rgba(99, 179, 237, 0.2) !important;
    background: rgba(30, 40, 50, 0.95) !important;
}

.passphrase-input::placeholder {
    color: rgba(99, 179, 237, 0.4);
}

/* Glowing PIN input */
.pin-input-container .form-control {
    background: rgba(30, 40, 50, 0.8) !important;
    border: 2px solid rgba(246, 173, 85, 0.3) !important;
    color: #f6ad55 !important;
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    letter-spacing: 3px;
    text-align: center;
    transition: all 0.3s ease;
}

.pin-input-container .form-control:focus {
    border-color: rgba(246, 173, 85, 0.8) !important;
    box-shadow: 0 0 20px rgba(246, 173, 85, 0.4), 0 0 40px rgba(246, 173, 85, 0.2) !important;
    background: rgba(30, 40, 50, 0.95) !important;
}

.pin-input-container .form-control::placeholder {
    color: rgba(246, 173, 85, 0.4);
    letter-spacing: 1px;
}

/* QR Crop Animation */
.qr-crop-container {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
}

.qr-crop-container img {
    display: block;
    max-height: 120px;
    width: auto;
    margin: 0 auto;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.qr-crop-container .qr-original {
    opacity: 1;
}

.qr-crop-container .qr-cropped {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0;
    max-height: 100px;
}

.qr-crop-container.animating .qr-original {
    opacity: 0;
    transform: scale(1.1);
    filter: blur(4px);
}

.qr-crop-container.animating .qr-cropped {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.qr-crop-container .crop-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 0.65rem;
    opacity: 0;
    transition: opacity 0.3s ease 0.4s;
}

.qr-crop-container.animating .crop-badge {
    opacity: 1;
}
</style>

<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-unlock-fill me-2"></i>Decode Secret Message or File</h5>
            </div>
            <div class="card-body">
                {% if decoded_message %}
                <!-- Text Message Result -->
                <div class="alert alert-success">
                    <h6><i class="bi bi-check-circle me-2"></i>Message Decrypted Successfully!</h6>
                </div>
               
                <label class="form-label text-muted">Decoded Message:</label>
                <div class="alert-message p-3 rounded bg-dark border border-secondary mb-2" id="decodedContent" style="white-space: pre-wrap;">{{ decoded_message }}</div>
                <div class="d-flex justify-content-end mb-3">
                    <button class="btn btn-sm btn-outline-light" onclick="navigator.clipboard.writeText(document.getElementById('decodedContent').innerText).then(() => { this.innerHTML = '<i class=\'bi bi-check\'></i> Copied!'; setTimeout(() => this.innerHTML = '<i class=\'bi bi-clipboard\'></i> Copy', 2000); }).catch(() => alert('Failed to copy'))">
                        <i class="bi bi-clipboard"></i> Copy
                    </button>
                </div>

                <a href="/decode" class="btn btn-outline-light w-100">
                    <i class="bi bi-arrow-repeat me-2"></i>Decode Another
                </a>
                
                {% elif decoded_file %}
                <!-- File Result -->
                <div class="alert alert-success">
                    <h6><i class="bi bi-check-circle me-2"></i>File Decrypted Successfully!</h6>
                </div>
                
                <div class="text-center mb-4">
                    <i class="bi bi-file-earmark-check text-success" style="font-size: 4rem;"></i>
                    <h5 class="mt-3">{{ filename }}</h5>
                    <p class="text-muted mb-1">{{ file_size }}</p>
                    {% if mime_type %}
                    <small class="text-muted">Type: {{ mime_type }}</small>
                    {% endif %}
                </div>
                
                <a href="{{ url_for('decode_download', file_id=file_id) }}" class="btn btn-primary btn-lg w-100 mb-3">
                    <i class="bi bi-download me-2"></i>Download File
                </a>
                
                <div class="alert alert-warning small">
                    <i class="bi bi-clock me-1"></i>
                    <strong>File expires in 5 minutes.</strong> Download now.
                </div>
                
                <a href="/decode" class="btn btn-outline-light w-100">
                    <i class="bi bi-arrow-repeat me-2"></i>Decode Another
                </a>
                
                {% else %}
                <!-- Decode Form -->
                <form method="POST" enctype="multipart/form-data" id="decodeForm">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="form-label">
                                <i class="bi bi-image me-1"></i> Reference Photo
                            </label>
                            <div class="drop-zone">
                                <input type="file" name="reference_photo" accept="image/*" required>
                                <div class="drop-zone-label">
                                    <i class="bi bi-cloud-arrow-up fs-3 d-block mb-2 text-muted"></i>
                                    <span class="text-muted">Drop image or click to browse</span>
                                </div>
                                <img class="drop-zone-preview d-none">
                            </div>
                            <div class="form-text">
                                The same reference photo used for encoding
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <label class="form-label">
                                <i class="bi bi-file-earmark-image me-1"></i> Stego Image
                            </label>
                            <div class="drop-zone" id="stegoDropZone">
                                <input type="file" name="stego_image" accept="image/*" required>
                                <div class="drop-zone-label">
                                    <i class="bi bi-cloud-arrow-up fs-3 d-block mb-2 text-muted"></i>
                                    <span class="text-muted">Drop image or click to browse</span>
                                </div>
                                <img class="drop-zone-preview d-none">
                            </div>
                            <div class="form-text">
                                The image containing the hidden message/file
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">
                            <i class="bi bi-chat-quote me-1"></i> Passphrase
                        </label>
                        <input type="text" name="passphrase" id="passphraseInput" class="form-control passphrase-input" 
                               placeholder="e.g., correct horse battery staple" required>
                        <div class="form-text">
                            The passphrase used during encoding (typically 4 words)
                        </div>
                    </div>
                    
                    <hr class="my-4">
                    
                    <h6 class="text-muted mb-3">
                        SECURITY FACTORS 
                        <span class="text-warning small">(provide same factors used during encoding)</span>
                    </h6>
                    
                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <label class="form-label"><i class="bi bi-123 me-1"></i> PIN</label>
                            <div class="input-group pin-input-container">
                                <input type="password" name="pin" class="form-control" id="pinInput" placeholder="••••••" maxlength="9" style="max-width: 180px;">
                                <button class="btn btn-outline-secondary" type="button" id="togglePin">
                                    <i class="bi bi-eye"></i>
                                </button>
                            </div>
                            <div class="form-text">If PIN was used during encoding</div>
                        </div>
                        
                        <div class="col-md-8 mb-3">
                            <label class="form-label">
                                <i class="bi bi-file-earmark-lock me-1"></i> RSA Key
                            </label>
                            
                            <!-- RSA Input Method Toggle -->
                            <div class="btn-group w-100 mb-2" role="group">
                                <input type="radio" class="btn-check" name="rsa_input_method" id="rsaMethodFile" value="file" checked>
                                <label class="btn btn-outline-secondary btn-sm" for="rsaMethodFile">
                                    <i class="bi bi-file-earmark me-1"></i>.pem File
                                </label>
                                
                                <input type="radio" class="btn-check" name="rsa_input_method" id="rsaMethodQr" value="qr">
                                <label class="btn btn-outline-secondary btn-sm" for="rsaMethodQr">
                                    <i class="bi bi-qr-code me-1"></i>QR Code
                                </label>
                            </div>
                            
                            <!-- .pem File Input -->
                            <div id="rsaFileSection">
                                <input type="file" name="rsa_key" class="form-control form-control-sm" id="rsaKeyInput" accept=".pem,.key,application/x-pem-file">
                            </div>
                            
                            <!-- QR Code Input -->
                            <div id="rsaQrSection" class="d-none">
                                <div class="drop-zone p-3" id="qrDropZone">
                                    <input type="file" name="rsa_key_qr" accept="image/*" id="rsaKeyQrInput">
                                    <div class="drop-zone-label text-center">
                                        <i class="bi bi-qr-code-scan fs-4 d-block text-muted mb-1"></i>
                                        <span class="text-muted small">Drop QR image or click to browse</span>
                                    </div>
                                    <!-- Crop animation container -->
                                    <div class="qr-crop-container d-none" id="qrCropContainer">
                                        <img class="qr-original" id="qrOriginal" alt="Original">
                                        <img class="qr-cropped" id="qrCropped" alt="Cropped QR">
                                        <span class="crop-badge badge bg-success"><i class="bi bi-crop me-1"></i>Detected</span>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Key Password (always visible) -->
                            <div class="input-group input-group-sm mt-2">
                                <input type="password" name="rsa_password" class="form-control" id="rsaPasswordInput" placeholder="Key password (if encrypted)">
                                <button class="btn btn-outline-secondary" type="button" id="toggleRsaPassword">
                                    <i class="bi bi-eye"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <!-- ================================================================
                         ADVANCED OPTIONS (v3.0) - Extraction Mode
                         ================================================================ -->
                    <div class="mb-4">
                        <a class="btn btn-sm btn-outline-secondary w-100" data-bs-toggle="collapse" href="#advancedOptionsDec" role="button" aria-expanded="false">
                            <i class="bi bi-gear me-1"></i> Advanced Options
                            <i class="bi bi-chevron-down ms-1" id="advancedChevronDec"></i>
                        </a>
                        
                        <div class="collapse" id="advancedOptionsDec">
                            <div class="card card-body mt-2 bg-dark border-secondary">
                                
                                <!-- Extraction Mode Selection -->
                                <div class="mb-0">
                                    <label class="form-label">
                                        <i class="bi bi-cpu me-1"></i> Extraction Mode
                                        <span class="badge bg-info ms-1">v3.0</span>
                                    </label>
                                    
                                    <div class="row g-2">
                                        <!-- Auto Mode -->
                                        <div class="col-4">
                                            <div class="form-check card p-2 text-center h-100" id="autoModeCard">
                                                <input class="form-check-input mx-auto" type="radio" name="embed_mode" id="modeAuto" value="auto" checked>
                                                <label class="form-check-label w-100" for="modeAuto">
                                                    <i class="bi bi-magic text-success fs-4 d-block mb-1"></i>
                                                    <strong>Auto</strong>
                                                    <div class="small text-muted">Try both</div>
                                                </label>
                                            </div>
                                        </div>
                                        
                                        <!-- LSB Mode -->
                                        <div class="col-4">
                                            <div class="form-check card p-2 text-center h-100" id="lsbModeCardDec">
                                                <input class="form-check-input mx-auto" type="radio" name="embed_mode" id="modeLsbDec" value="lsb">
                                                <label class="form-check-label w-100" for="modeLsbDec">
                                                    <i class="bi bi-grid-3x3-gap text-primary fs-4 d-block mb-1"></i>
                                                    <strong>LSB</strong>
                                                    <div class="small text-muted">Spatial only</div>
                                                </label>
                                            </div>
                                        </div>
                                        
                                        <!-- DCT Mode -->
                                        <div class="col-4">
                                            <div class="form-check card p-2 text-center h-100 {% if not has_dct %}opacity-50{% endif %}" id="dctModeCardDec">
                                                <input class="form-check-input mx-auto" type="radio" name="embed_mode" id="modeDctDec" value="dct" {% if not has_dct %}disabled{% endif %}>
                                                <label class="form-check-label w-100" for="modeDctDec">
                                                    <i class="bi bi-soundwave text-info fs-4 d-block mb-1"></i>
                                                    <strong>DCT</strong>
                                                    <div class="small text-muted">
                                                        {% if has_dct %}Frequency only{% else %}N/A{% endif %}
                                                    </div>
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="form-text mt-2">
                                        <i class="bi bi-lightbulb me-1"></i>
                                        <strong>Auto</strong> tries LSB first, then DCT. Use specific mode if you know how it was encoded.
                                        {% if not has_dct %}
                                        <br><span class="text-warning"><i class="bi bi-exclamation-triangle me-1"></i>DCT requires scipy: <code>pip install scipy</code></span>
                                        {% endif %}
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                    </div>
                    
                    <button type="submit" class="btn btn-primary btn-lg w-100" id="decodeBtn">
                        <i class="bi bi-unlock me-2"></i>Decode
                    </button>
                </form>
                
                {% endif %}
            </div>
        </div>
        
        {% if not decoded_message and not decoded_file %}
        <div class="card mt-4">
            <div class="card-body">
                <h6 class="text-muted mb-3"><i class="bi bi-question-circle me-2"></i>Troubleshooting</h6>
                <ul class="list-unstyled text-muted small mb-0">
                    <li class="mb-2">
                        <i class="bi bi-check-circle-fill text-success me-1"></i>
                        Use the <strong>exact same reference photo</strong> file (byte-for-byte identical)
                    </li>
                    <li class="mb-2">
                        <i class="bi bi-check-circle-fill text-success me-1"></i>
                        Enter the <strong>exact passphrase</strong> used during encoding (case-sensitive, spacing matters)
                    </li>
                    <li class="mb-2">
                        <i class="bi bi-check-circle-fill text-success me-1"></i>
                        Provide the <strong>same security factors</strong> (PIN and/or RSA key) used during encoding
                    </li>
                    <li class="mb-2">
                        <i class="bi bi-exclamation-triangle-fill text-warning me-1"></i>
                        Ensure the stego image hasn't been <strong>resized, cropped, or recompressed</strong>
                    </li>
                    <li class="mb-2">
                        <i class="bi bi-exclamation-triangle-fill text-warning me-1"></i>
                        <strong>Format compatibility:</strong> v4.0 cannot decode messages from v3.1 or earlier (different format)
                    </li>
                    <li class="mb-2">
                        <i class="bi bi-info-circle-fill text-info me-1"></i>
                        If using an RSA key, verify the <strong>password is correct</strong> (if key is encrypted)
                    </li>
                    <li class="mb-0">
                        <i class="bi bi-info-circle-fill text-info me-1"></i>
                        If auto-detection fails, try specifying <strong>LSB or DCT mode</strong> in Advanced Options
                    </li>
                </ul>
            </div>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
// Form submit loading state
document.getElementById('decodeForm')?.addEventListener('submit', function() {
    const btn = document.getElementById('decodeBtn');
    const selectedMode = document.querySelector('input[name="embed_mode"]:checked')?.value || 'auto';
    btn.innerHTML = `<span class="spinner-border spinner-border-sm me-2"></span>Decoding (${selectedMode.toUpperCase()})...`;
    btn.disabled = true;
});

// PIN Toggle
document.getElementById('togglePin')?.addEventListener('click', function() {
    const input = document.getElementById('pinInput');
    const icon = this.querySelector('i');
    if (input.type === 'password') {
        input.type = 'text';
        icon.classList.replace('bi-eye', 'bi-eye-slash');
    } else {
        input.type = 'password';
        icon.classList.replace('bi-eye-slash', 'bi-eye');
    }
});

// RSA Password Toggle
document.getElementById('toggleRsaPassword')?.addEventListener('click', function() {
    const input = document.getElementById('rsaPasswordInput');
    const icon = this.querySelector('i');
    if (input.type === 'password') {
        input.type = 'text';
        icon.classList.replace('bi-eye', 'bi-eye-slash');
    } else {
        input.type = 'password';
        icon.classList.replace('bi-eye-slash', 'bi-eye');
    }
});

// RSA Input Method Toggle (File vs QR)
const rsaMethodFile = document.getElementById('rsaMethodFile');
const rsaMethodQr = document.getElementById('rsaMethodQr');
const rsaFileSection = document.getElementById('rsaFileSection');
const rsaQrSection = document.getElementById('rsaQrSection');

function updateRsaInputMethod() {
    if (!rsaMethodFile || !rsaFileSection || !rsaQrSection) return;
    const isFile = rsaMethodFile.checked;
    rsaFileSection.classList.toggle('d-none', !isFile);
    rsaQrSection.classList.toggle('d-none', isFile);
}

rsaMethodFile?.addEventListener('change', updateRsaInputMethod);
rsaMethodQr?.addEventListener('change', updateRsaInputMethod);

// Mode card highlighting
const autoModeCard = document.getElementById('autoModeCard');
const lsbModeCardDec = document.getElementById('lsbModeCardDec');
const dctModeCardDec = document.getElementById('dctModeCardDec');
const modeAuto = document.getElementById('modeAuto');
const modeLsbDec = document.getElementById('modeLsbDec');
const modeDctDec = document.getElementById('modeDctDec');

function updateModeCardHighlightDec() {
    autoModeCard?.classList.toggle('border-success', modeAuto?.checked);
    autoModeCard?.classList.toggle('border-2', modeAuto?.checked);
    lsbModeCardDec?.classList.toggle('border-primary', modeLsbDec?.checked);
    lsbModeCardDec?.classList.toggle('border-2', modeLsbDec?.checked);
    dctModeCardDec?.classList.toggle('border-info', modeDctDec?.checked);
    dctModeCardDec?.classList.toggle('border-2', modeDctDec?.checked);
}

modeAuto?.addEventListener('change', updateModeCardHighlightDec);
modeLsbDec?.addEventListener('change', updateModeCardHighlightDec);
modeDctDec?.addEventListener('change', updateModeCardHighlightDec);
updateModeCardHighlightDec(); // Initial state

// Advanced options chevron rotation
document.getElementById('advancedOptionsDec')?.addEventListener('show.bs.collapse', function() {
    document.getElementById('advancedChevronDec').classList.add('bi-chevron-up');
    document.getElementById('advancedChevronDec').classList.remove('bi-chevron-down');
});
document.getElementById('advancedOptionsDec')?.addEventListener('hide.bs.collapse', function() {
    document.getElementById('advancedChevronDec').classList.remove('bi-chevron-up');
    document.getElementById('advancedChevronDec').classList.add('bi-chevron-down');
});

// Paste from Clipboard
document.addEventListener('paste', function(e) {
    if (!document.getElementById('decodeForm')) return;

    const items = e.clipboardData.items;
    for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
            const blob = items[i].getAsFile();
            
            const stegoInput = document.querySelector('input[name="stego_image"]');
            const refInput = document.querySelector('input[name="reference_photo"]');
            
            const targetInput = (!stegoInput.files.length) ? stegoInput : refInput;
            
            const container = new DataTransfer();
            container.items.add(blob);
            targetInput.files = container.files;
            
            targetInput.dispatchEvent(new Event('change'));
            break;
        }
    }
});

// Drag & drop with preview
document.querySelectorAll('.drop-zone').forEach(zone => {
    const input = zone.querySelector('input[type="file"]');
    const label = zone.querySelector('.drop-zone-label');
    const preview = zone.querySelector('.drop-zone-preview');
    
    ['dragenter', 'dragover'].forEach(evt => {
        zone.addEventListener(evt, e => {
            e.preventDefault();
            zone.classList.add('drag-over');
        });
    });
    
    ['dragleave', 'drop'].forEach(evt => {
        zone.addEventListener(evt, e => {
            e.preventDefault();
            zone.classList.remove('drag-over');
        });
    });
    
    zone.addEventListener('drop', e => {
        if (e.dataTransfer.files.length) {
            input.files = e.dataTransfer.files;
            const file = e.dataTransfer.files[0];
            showPreview(file);
        }
    });
    
    input.addEventListener('change', function() {
        if (this.files && this.files[0]) {
            showPreview(this.files[0]);
        }
    });
    
    function showPreview(file) {
        if (!file.type.startsWith('image/')) return;
        
        const reader = new FileReader();
        reader.onload = e => {
            if (preview) {
                preview.src = e.target.result;
                preview.classList.remove('d-none');
            }
            label.innerHTML = '<i class="bi bi-check-circle text-success me-1"></i>' + file.name;
        };
        reader.readAsDataURL(file);
    }
});

// QR Code RSA Key scanning with crop animation
const rsaKeyQrInput = document.getElementById('rsaKeyQrInput');
const qrCropContainer = document.getElementById('qrCropContainer');
const qrOriginal = document.getElementById('qrOriginal');
const qrCropped = document.getElementById('qrCropped');

if (rsaKeyQrInput) {
    rsaKeyQrInput.addEventListener('change', function() {
        if (this.files && this.files[0]) {
            const file = this.files[0];
            
            if (!file.type.startsWith('image/')) return;
            
            // Reset animation state
            qrCropContainer.classList.remove('animating');
            qrCropContainer.classList.add('d-none');
            
            // Show original image first
            const reader = new FileReader();
            reader.onload = e => {
                qrOriginal.src = e.target.result;
                qrCropContainer.classList.remove('d-none');
                
                // Hide the label
                document.querySelector('#qrDropZone .drop-zone-label').classList.add('d-none');
                
                // Now fetch cropped version and animate
                const formData = new FormData();
                formData.append('image', file);
                
                fetch('/qr/crop', {
                    method: 'POST',
                    body: formData
                })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('No QR code detected');
                    }
                    return response.blob();
                })
                .then(blob => {
                    // Load cropped image
                    const croppedUrl = URL.createObjectURL(blob);
                    qrCropped.src = croppedUrl;
                    
                    // Wait a moment to show original, then animate
                    setTimeout(() => {
                        qrCropContainer.classList.add('animating');
                    }, 400);
                    
                    // Also verify key extraction works
                    const keyFormData = new FormData();
                    keyFormData.append('qr_image', file);
                    
                    return fetch('/extract-key-from-qr', {
                        method: 'POST',
                        body: keyFormData
                    });
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        document.querySelector('#qrDropZone .drop-zone-label').innerHTML = 
                            '<i class="bi bi-check-circle text-success me-1"></i>RSA Key loaded';
                        document.querySelector('#qrDropZone .drop-zone-label').classList.remove('d-none');
                    }
                })
                .catch(err => {
                    // Crop failed - just show original with error
                    console.log('QR crop/extract error:', err);
                    document.querySelector('#qrDropZone .drop-zone-label').innerHTML = 
                        '<i class="bi bi-exclamation-triangle text-warning me-1"></i>No QR detected';
                    document.querySelector('#qrDropZone .drop-zone-label').classList.remove('d-none');
                });
            };
            reader.readAsDataURL(file);
        }
    });
}

// Auto-resize passphrase input font to fit long passphrases
const passphraseInput = document.getElementById('passphraseInput');
if (passphraseInput) {
    // Stepped font sizes (characters -> rem)
    const fontSizeSteps = [
        { maxChars: 30, size: 1.1 },
        { maxChars: 45, size: 1.0 },
        { maxChars: 60, size: 0.95 },
        { maxChars: Infinity, size: 0.9 }
    ];
    
    function adjustPassphraseFontSize() {
        const len = passphraseInput.value.length;
        
        for (const step of fontSizeSteps) {
            if (len <= step.maxChars) {
                passphraseInput.style.fontSize = step.size + 'rem';
                break;
            }
        }
    }
    
    passphraseInput.addEventListener('input', adjustPassphraseFontSize);
    adjustPassphraseFontSize(); // Initial call in case of pre-filled value
}
</script>
{% endblock %}
