Enhance  the below python code to provide a modern html experience:

import praw
import os
from datetime import datetime
import webbrowser  # Import the webbrowser module
import time        # Import time module to add a slight delay if needed
import collections # Import collections for Counter

# Function to safely retrieve environment variables
def get_env_variable(var_name):
    value = os.environ.get(var_name)
    if not value:
        print(f"Error: The environment variable '{var_name}' is not set.")
        print("Please set it before running the script.")
        exit(1)
    return value

# Retrieve environment variables with error handling
client_id = get_env_variable('REDDIT_CLIENT_ID')
client_secret = get_env_variable('REDDIT_CLIENT_SECRET')
user_agent = get_env_variable('REDDIT_USER_AGENT')

# Initialize Reddit instance with your credentials
reddit = praw.Reddit(
    client_id=client_id,
    client_secret=client_secret,
    user_agent=user_agent
)

# Get keyword(s) from user input
keyword_input = input("Enter the keyword(s) to search for: ").strip()

# Define two separate search queries
# 1. Search Only in Titles
keyword_title_only = f'title:"{keyword_input}"'

# 2. Search in Titles and Body
keyword_title_body = keyword_input  # Defaults to searching anywhere in title and body

# Function to perform Reddit search
def perform_search(query, sort='new', syntax='lucene', time_filter='day', limit=100):
    return list(reddit.subreddit('all').search(
        query,
        sort=sort,
        syntax=syntax,
        time_filter=time_filter,
        limit=limit
    ))

# Perform both searches
print("\nPerforming search: Titles Only...")
submissions_title_only = perform_search(keyword_title_only)
print(f"Found {len(submissions_title_only)} submissions in titles only.\n")

print("Performing search: Titles and Body...")
submissions_title_body = perform_search(keyword_title_body)
print(f"Found {len(submissions_title_body)} submissions in titles and body.\n")

# Function to count subreddits from a list of submissions
def count_subreddits(submissions):
    subreddit_counts = collections.Counter()
    for submission in submissions:
        subreddit_counts[submission.subreddit.display_name] += 1
    return subreddit_counts

# Count the occurrences of each subreddit for both search categories
subreddit_counts_title_only = count_subreddits(submissions_title_only)
subreddit_counts_title_body = count_subreddits(submissions_title_body)

# Get the top 10 subreddits for both search categories
top_subreddits_title_only = subreddit_counts_title_only.most_common(10)
top_subreddits_title_body = subreddit_counts_title_body.most_common(10)

# Define the filename for the HTML file
html_filename = 'reddit_search_results.html'

# Open an HTML file to write the output
with open(html_filename, 'w', encoding='utf-8') as html_file:
    # Write the initial HTML structure
    html_file.write('<!DOCTYPE html>\n')
    html_file.write('<html lang="en">\n')
    html_file.write('<head>\n')
    html_file.write('    <meta charset="UTF-8">\n')
    html_file.write('    <meta name="viewport" content="width=device-width, initial-scale=1.0">\n')
    html_file.write(f'    <title>Reddit Search Results for "{keyword_input}"</title>\n')
    html_file.write('    <style>\n')
    html_file.write('        body { font-family: Arial, sans-serif; margin: 20px; }\n')
    html_file.write('        h1, h2 { color: #FF4500; }\n')
    html_file.write('        ul { list-style-type: none; padding: 0; }\n')
    html_file.write('        li { margin-bottom: 15px; }\n')
    html_file.write('        hr { border: 0; border-top: 1px solid #ccc; margin: 10px 0; }\n')
    html_file.write('        a { text-decoration: none; color: #1a0dab; }\n')
    html_file.write('        a:hover { text-decoration: underline; }\n')
    html_file.write('    </style>\n')
    html_file.write('</head>\n')
    html_file.write('<body>\n')
    html_file.write(f'    <h1>Reddit Search Results for "{keyword_input}"</h1>\n')
    
    # Add a section for Top Subreddits - Titles Only
    html_file.write('    <h2>Top Subreddits (Titles Only)</h2>\n')
    html_file.write('    <ul>\n')
    if top_subreddits_title_only:
        for subreddit, count in top_subreddits_title_only:
            subreddit_url = f'https://www.reddit.com/r/{subreddit}/'
            html_file.write(f'        <li><strong><a href="{subreddit_url}" target="_blank">{subreddit}</a></strong>: {count} post(s)</li>\n')
    else:
        html_file.write('        <li>No subreddits found for Titles Only search.</li>\n')
    html_file.write('    </ul>\n')
    html_file.write('    <hr>\n')
    
    # Add a section for Submissions - Titles Only
    html_file.write('    <h2>Submissions (Titles Only)</h2>\n')
    html_file.write('    <ul>\n')
    if submissions_title_only:
        for submission in submissions_title_only:
            title = submission.title
            url = f'https://www.reddit.com{submission.permalink}'
            subreddit = submission.subreddit.display_name
            created_at = submission.created_utc

            # Convert the timestamp to a readable format
            created_at_readable = datetime.fromtimestamp(
                created_at
            ).strftime('%Y-%m-%d %H:%M:%S')

            # Write the submission details to the HTML file
            html_file.write('        <li>\n')
            html_file.write(f'            <a href="{url}" target="_blank">{title}</a><br>\n')
            html_file.write(f'            <em>Subreddit:</em> <a href="https://www.reddit.com/r/{subreddit}/" target="_blank">{subreddit}</a><br>\n')
            html_file.write(f'            <em>Created at:</em> {created_at_readable}\n')
            html_file.write('        </li>\n')
            html_file.write('        <hr>\n')
    else:
        html_file.write('        <li>No submissions found for Titles Only search.</li>\n')
    html_file.write('    </ul>\n')
    html_file.write('    <hr>\n')
    
    # Add a section for Top Subreddits - Titles and Body
    html_file.write('    <h2>Top Subreddits (Titles and Body)</h2>\n')
    html_file.write('    <ul>\n')
    if top_subreddits_title_body:
        for subreddit, count in top_subreddits_title_body:
            subreddit_url = f'https://www.reddit.com/r/{subreddit}/'
            html_file.write(f'        <li><strong><a href="{subreddit_url}" target="_blank">{subreddit}</a></strong>: {count} post(s)</li>\n')
    else:
        html_file.write('        <li>No subreddits found for Titles and Body search.</li>\n')
    html_file.write('    </ul>\n')
    html_file.write('    <hr>\n')
    
    # Add a section for Submissions - Titles and Body
    html_file.write('    <h2>Submissions (Titles and Body)</h2>\n')
    html_file.write('    <ul>\n')
    if submissions_title_body:
        for submission in submissions_title_body:
            title = submission.title
            url = f'https://www.reddit.com{submission.permalink}'
            subreddit = submission.subreddit.display_name
            created_at = submission.created_utc

            # Convert the timestamp to a readable format
            created_at_readable = datetime.fromtimestamp(
                created_at
            ).strftime('%Y-%m-%d %H:%M:%S')

            # Write the submission details to the HTML file
            html_file.write('        <li>\n')
            html_file.write(f'            <a href="{url}" target="_blank">{title}</a><br>\n')
            html_file.write(f'            <em>Subreddit:</em> <a href="https://www.reddit.com/r/{subreddit}/" target="_blank">{subreddit}</a><br>\n')
            html_file.write(f'            <em>Created at:</em> {created_at_readable}\n')
            html_file.write('        </li>\n')
            html_file.write('        <hr>\n')
    else:
        html_file.write('        <li>No submissions found for Titles and Body search.</li>\n')
    html_file.write('    </ul>\n')
    html_file.write('</body>\n')
    html_file.write('</html>\n')

print(f'Search results have been saved to "{html_filename}".')

# Optional: Wait for a moment to ensure the file is saved
time.sleep(1)

# Get the absolute path to the HTML file
html_file_path = os.path.abspath(html_filename)

# Open the HTML file in Chrome

# Option 1: Open with default browser
# webbrowser.open_new_tab(html_file_path)

# Option 2: Open with Chrome specifically
# Replace the path below with the actual path to your Chrome executable

chrome_exe_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe'

# Check if Chrome exists at the specified path
if os.path.exists(chrome_exe_path):
    # Enclose the path in quotes to handle spaces
    try:
        browser = webbrowser.get(f'"{chrome_exe_path}" %s')
        browser.open_new_tab(html_file_path)
    except webbrowser.Error as e:
        print(f"Failed to open Chrome specifically: {e}")
        print("Opening with the default browser.")
        webbrowser.open_new_tab(html_file_path)
else:
    print("Chrome browser not found at the specified path. Opening with the default browser.")
    webbrowser.open_new_tab(html_file_path)