#!/usr/bin/env python3
"""
Fix prompt button position to be fixed next to back-link
"""

import os
import re

# New CSS for prompt-btn (fixed position)
new_prompt_btn_css = '''    .prompt-btn {
        position: fixed;
        top: 20px;
        left: 180px;
        padding: 12px 24px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border-radius: 8px;
        text-decoration: none;
        color: white;
        font-weight: 600;
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
        transition: all 200ms ease;
        cursor: pointer;
        border: none;
        font-size: 16px;
        font-family: inherit;
        z-index: 100;
    }'''

new_prompt_btn_hover = '''    .prompt-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    }'''

# Mobile responsiveness update
new_mobile_css = '''    @media (max-width: 768px) {
        .prompt-btn {
            position: fixed;
            top: 20px;
            left: auto;
            right: 20px;
        }'''

# 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()

    # Replace .prompt-btn { ... }
    pattern1 = r'\.prompt-btn \{[^}]+\}'
    content = re.sub(pattern1, new_prompt_btn_css, content, count=1)

    # Replace .prompt-btn:hover { ... }
    pattern2 = r'\.prompt-btn:hover \{[^}]+\}'
    content = re.sub(pattern2, new_prompt_btn_hover, content, count=1)

    # Update mobile media query for prompt-btn
    # Find the media query section and update it
    pattern3 = r'(@media \(max-width: 768px\) \{[\s\S]*?)\.prompt-btn \{[^}]+\}'

    def replacer(match):
        before = match.group(1)
        return before + new_mobile_css.strip().split('{', 1)[1].rstrip('}') + '\n        }'

    content = re.sub(pattern3, replacer, content)

    # 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 버튼이 이제 화면 상단에 고정됩니다!")
