"""GTA VI Loading Screen Simulator — the game loads faster than Rockstar ships it."""

import sys
import time
import random


def load_game():
    """Run the full GTA VI loading screen experience."""
    _clear_line()
    _print_banner()
    _loading_bar()
    _post_load_sequence()


# ── internal helpers ────────────────────────────────────────────────────────


def _clear_line():
    """Print a blank line for visual breathing room."""
    print()


def _print_banner():
    """Show the iconic title card."""
    banner = r"""
   ██████╗ ████████╗ █████╗     ██╗   ██╗██╗
  ██╔════╝ ╚══██╔══╝██╔══██╗    ██║   ██║██║
  ██║  ███╗   ██║   ███████║    ██║   ██║██║
  ██║   ██║   ██║   ██╔══██║    ╚██╗ ██╔╝██║
  ╚██████╔╝   ██║   ██║  ██║     ╚████╔╝ ██║
   ╚═════╝    ╚═╝   ╚═╝  ╚═╝      ╚═══╝  ╚═╝
    """
    print(banner)


def _loading_bar(total: int = 30, fill: str = "█", empty: str = "░"):
    """Animate a progress bar that *almost* feels real."""
    print("  Loading GTA VI...\n")

    # Percentage → pause mapping (longer waits at dramatic moments)
    checkpoints = {
        24: 1.0,   # stall at 24 % — feels like a real Rockstar launcher
        57: 1.2,
        83: 1.5,   # the classic "almost there" hang
        99: 0.8,
    }

    for pct in range(101):
        filled = int(total * pct / 100)
        bar = fill * filled + empty * (total - filled)
        sys.stdout.write(f"\r  {bar}  {pct:>3}%")
        sys.stdout.flush()

        if pct in checkpoints:
            time.sleep(checkpoints[pct])
        else:
            time.sleep(random.uniform(0.01, 0.04))

    # Final 100 %
    sys.stdout.write(f"\r  {fill * total}  100%\n")
    sys.stdout.flush()
    print()


def _slow_print(text: str, delay: float = 0.04):
    """Print text character-by-character for dramatic effect."""
    for char in text:
        sys.stdout.write(char)
        sys.stdout.flush()
        time.sleep(delay)
    print()


def _post_load_sequence():
    """The punchline everybody came for."""
    messages = [
        ("  Connecting to Rockstar servers...", 1.5),
        ("  Verifying license...", 1.0),
        ("  Checking release date...", 1.8),
    ]
    for msg, pause in messages:
        _slow_print(msg)
        time.sleep(pause)

    print()
    print("  ╔══════════════════════════════════════════╗")
    print("  ║                                          ║")
    print("  ║     🎮  NEW RELEASE DATE:  2032  🎮      ║")
    print("  ║                                          ║")
    print("  ╚══════════════════════════════════════════╝")
    print()

    time.sleep(1.0)
    _slow_print("  Thanks for installing GTA VI.")
    _slow_print("  You installed it faster than Rockstar released it 😂")
    print()
