#!/usr/bin/env python3
"""
Fix prompt button position - version 2
Use simple string replacement
"""

import os

# Process each HTML file
success_count = 0
for i in range(1, 101):
    filename = f"{i:02d}.html"

    if not os.path.exists(filename):
        print(f"❌ Skipping {filename} - does not exist")
        continue

    with open(filename, 'r', encoding='utf-8') as f:
        content = f.read()

    # Find and replace the prompt-btn style section
    # Look for the opening of .prompt-btn { and replace until the closing }

    old_style = '''    .prompt-btn {
        display: inline-block;
        margin-left: 16px;'''

    new_style = '''    .prompt-btn {
        position: fixed;
        top: 20px;
        left: 180px;'''

    if old_style in content:
        content = content.replace(old_style, new_style)
    else:
        # Try alternative format (might have different whitespace)
        # Just add position, top, left after the opening brace
        import re
        pattern = r'(\.prompt-btn \{\s*)'
        replacement = r'\1\n        position: fixed;\n        top: 20px;\n        left: 180px;\n        '
        content = re.sub(pattern, replacement, content, count=1)

    # Also add z-index if not present
    if '.prompt-btn {' in content and 'z-index:' not in content.split('.prompt-btn:hover')[0]:
        # Add z-index before the closing brace of .prompt-btn
        content = content.replace(
            '        font-family: inherit;\n    }',
            '        font-family: inherit;\n        z-index: 100;\n    }',
            1
        )

    # Update mobile responsive CSS
    # Change the mobile prompt-btn to position right side
    old_mobile = '''        .prompt-btn {
            margin-left: 0;
            margin-top: 12px;'''

    new_mobile = '''        .prompt-btn {
            left: auto;
            right: 20px;'''

    if old_mobile in content:
        content = content.replace(old_mobile, new_mobile)

    # Write back
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(content)

    print(f"✓ Updated {filename}")
    success_count += 1

print(f"\n✅ Done! Successfully updated {success_count}/100 pages.")
print("📝 Prompt 버튼이 이제 화면 상단 좌측에 고정됩니다!")
print("   - 데스크톱: 목록으로 버튼 옆 (left: 180px)")
print("   - 모바일: 화면 우측 상단 (right: 20px)")
