        // ===== 상태 표시 =====
        function setStatus(msg, connected = false) {
            document.getElementById('statusMessage').textContent = msg;
            document.getElementById('statusDot').classList.toggle('connected', connected);
        }
        
        // ===== 입력 상태 업데이트 =====
        function updateInputStatus() {
            const hasFolder = folderPath.length > 0;
            const hasLinks = referenceLinks.length > 0;
            const hasHtml = inputContent.length > 0;
            
            const pathEl = document.getElementById('folderPathDisplay');
            if (hasFolder) {
                pathEl.textContent = folderPath;
                pathEl.classList.remove('empty');
            } else {
                pathEl.textContent = '폴더 경로가 설정되지 않음';
                pathEl.classList.add('empty');
            }
            
            document.getElementById('linkCount').textContent = referenceLinks.length + '개';
            
            const htmlStatus = document.getElementById('htmlInputStatus');
            if (hasHtml) {
                htmlStatus.textContent = '✓ 입력됨';
                htmlStatus.classList.add('ok');
            } else {
                htmlStatus.textContent = '없음';
                htmlStatus.classList.remove('ok');
            }
            
            const canGenerate = hasHtml || hasFolder || hasLinks;
            document.getElementById('generateBtn').disabled = !canGenerate;
            // 버튼 텍스트: 폴더/링크 있으면 목차 확인, 아니면 생성하기
            const btnText = document.getElementById('generateBtnText');
            if (btnText) {
                if (hasFolder || (hasLinks && hasHtml)) {
                    btnText.textContent = '📋 목차 확인하기';
                } else {
                    btnText.textContent = '🚀 생성하기';
                }
            }            
            
            if (canGenerate) {
                updateStep(0, 'done');
            } else {
                updateStep(0, 'pending');
            }
        }

        // ===== 진행 상태 =====
        function updateStep(num, status) {
            const item = document.querySelector(`.step-item[data-step="${num}"]`);
            if (!item) return;
            item.classList.remove('pending', 'running', 'done', 'error');
            item.classList.add(status);
            item.querySelector('.status').textContent = 
                status === 'pending' ? '○' :
                status === 'running' ? '◐' :
                status === 'done' ? '●' : '✕';
        }

        function resetSteps() {
            for (let i = 0; i <= 9; i++) {
                updateStep(i, 'pending');
            }
        }

        // ===== 줌 =====
        function setZoom(value) {
            currentZoom = parseInt(value);
            document.getElementById('a4Wrapper').style.transform = `scale(${currentZoom / 100})`;
        }

        // ===== 작성 방식 선택 =====
        function selectWriteMode(mode) {
            currentWriteMode = mode;
            
            document.querySelectorAll('.write-mode-tab').forEach(tab => {
                tab.classList.remove('selected');
                tab.querySelector('input[type="radio"]').checked = false;
            });
            
            const selectedTab = document.querySelector(`.write-mode-tab input[value="${mode}"]`);
            if (selectedTab) {
                selectedTab.checked = true;
                selectedTab.closest('.write-mode-tab').classList.add('selected');
            }
        }

