<?php
// cupp.php - Common User Password Profiler with Hacker UI (FIXED)
@ini_set('zlib.output_compression', 0);
@ini_set('output_buffering', 0);
@ini_set('implicit_flush', 1);
ob_implicit_flush(true);
while (ob_get_level() > 0) { ob_end_flush(); }

set_time_limit(0);
ini_set('max_execution_time', '0');
ini_set('memory_limit', '512M');

require_once 'config.php';
requireLogin();

// Create passwords directory
$passwordsDir = __DIR__ . '/passwords';
if (!is_dir($passwordsDir)) {
    mkdir($passwordsDir, 0755, true);
}

$message = '';
$generatedFile = '';
$passwordCount = 0;
$passwords = array();
$generating = false;
$generationComplete = false;
$firstName = '';

// Handle form submission - DO GENERATION FIRST before any HTML
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['generate'])) {
    $generating = true;
    $firstName = isset($_POST['first_name']) ? trim($_POST['first_name']) : '';
    $lastName = isset($_POST['last_name']) ? trim($_POST['last_name']) : '';
    $nickname = isset($_POST['nickname']) ? trim($_POST['nickname']) : '';
    $birthdate = isset($_POST['birthdate']) ? trim($_POST['birthdate']) : '';
    $partnerName = isset($_POST['partner_name']) ? trim($_POST['partner_name']) : '';
    $partnerBirthdate = isset($_POST['partner_birthdate']) ? trim($_POST['partner_birthdate']) : '';
    $petName = isset($_POST['pet_name']) ? trim($_POST['pet_name']) : '';
    $company = isset($_POST['company']) ? trim($_POST['company']) : '';
    $keywords = isset($_POST['keywords']) ? trim($_POST['keywords']) : '';
    $specialChars = isset($_POST['special_chars']);
    $addNumbers = isset($_POST['add_numbers']);
    $leetMode = isset($_POST['leet_mode']);
    
    if (empty($firstName) && empty($lastName) && empty($nickname)) {
        $message = "❌ Please enter at least a first name, last name, or nickname.";
        $generating = false;
    } else {
        // ============================================
        // GENERATE PASSWORDS FIRST (before HTML output)
        // ============================================
        $words = array();
        
        // Extract base words
        if (!empty($firstName)) {
            $words[] = $firstName;
            $words[] = strtolower($firstName);
            $words[] = strtoupper($firstName);
            $words[] = ucfirst(strtolower($firstName));
            if (strlen($firstName) > 0) $words[] = substr($firstName, 0, 1);
        }
        
        if (!empty($lastName)) {
            $words[] = $lastName;
            $words[] = strtolower($lastName);
            $words[] = strtoupper($lastName);
            $words[] = ucfirst(strtolower($lastName));
        }
        
        if (!empty($nickname)) {
            $words[] = $nickname;
            $words[] = strtolower($nickname);
            $words[] = strtoupper($nickname);
        }
        
        // Dates
        if (!empty($birthdate)) {
            $dateParts = explode('-', $birthdate);
            if (count($dateParts) == 3) {
                $words[] = $dateParts[0];
                $words[] = $dateParts[1];
                $words[] = $dateParts[2];
                $words[] = $dateParts[1] . $dateParts[2];
                $words[] = $dateParts[2] . $dateParts[1];
                $words[] = substr($dateParts[0], 2) . $dateParts[1] . $dateParts[2];
            }
        }
        
        if (!empty($partnerBirthdate)) {
            $dateParts = explode('-', $partnerBirthdate);
            if (count($dateParts) == 3) {
                $words[] = $dateParts[1] . $dateParts[2];
                $words[] = $dateParts[2] . $dateParts[1];
            }
        }
        
        if (!empty($partnerName)) {
            $words[] = $partnerName;
            $words[] = strtolower($partnerName);
        }
        
        if (!empty($petName)) {
            $words[] = $petName;
            $words[] = strtolower($petName);
        }
        
        if (!empty($company)) {
            $words[] = $company;
            $words[] = strtolower($company);
            $words[] = str_replace(' ', '', strtolower($company));
        }
        
        if (!empty($keywords)) {
            $kwList = explode(',', $keywords);
            foreach ($kwList as $kw) {
                $kw = trim($kw);
                if (!empty($kw)) {
                    $words[] = $kw;
                    $words[] = strtolower($kw);
                }
            }
        }
        
        $words = array_unique(array_filter($words));
        
        // Generate passwords
        $passwords = array();
        
        // Single words
        foreach ($words as $w) {
            $passwords[] = $w;
        }
        
        // Two-word combinations
        foreach ($words as $w1) {
            foreach ($words as $w2) {
                if ($w1 != $w2) {
                    $passwords[] = $w1 . $w2;
                    $passwords[] = $w1 . '_' . $w2;
                    $passwords[] = $w1 . '-' . $w2;
                    $passwords[] = $w1 . '.' . $w2;
                }
            }
        }
        
        // Three-word combinations (limited)
        $wordSlice = array_slice($words, 0, 10);
        foreach ($wordSlice as $w1) {
            foreach ($wordSlice as $w2) {
                foreach ($wordSlice as $w3) {
                    if ($w1 != $w2 && $w2 != $w3 && $w1 != $w3) {
                        $passwords[] = $w1 . $w2 . $w3;
                        if (count($passwords) > 50000) break 3;
                    }
                }
            }
        }
        
        // Add numbers
        if ($addNumbers) {
            $commonNums = array('123', '1234', '12345', '123456', '1', '12', '0', '01', '00', '007', '69', '666', '777', '888', '999', '2024', '2025', '2026');
            $numPasswords = array();
            foreach (array_slice($passwords, 0, 1000) as $p) {
                foreach ($commonNums as $num) {
                    $numPasswords[] = $p . $num;
                }
            }
            $passwords = array_merge($passwords, $numPasswords);
        }
        
        // Special chars
        if ($specialChars) {
            $specials = array('!', '@', '#', '$', '%', '&', '*', '?');
            $spPasswords = array();
            foreach (array_slice($passwords, 0, 2000) as $p) {
                foreach ($specials as $sp) {
                    $spPasswords[] = $p . $sp;
                }
            }
            $passwords = array_merge($passwords, $spPasswords);
        }
        
        // Leet mode
        if ($leetMode) {
            $leetMap = array('a'=>'4','e'=>'3','i'=>'1','o'=>'0','s'=>'5','t'=>'7','l'=>'1');
            $leetPasswords = array();
            foreach (array_slice($passwords, 0, 2000) as $p) {
                $leet = str_replace(array_keys($leetMap), array_values($leetMap), strtolower($p));
                if ($leet != $p) {
                    $leetPasswords[] = $leet;
                }
            }
            $passwords = array_merge($passwords, $leetPasswords);
        }
        
        // Remove duplicates and sort
        $passwords = array_unique($passwords);
        sort($passwords);
        $passwordCount = count($passwords);
        
        // Save to file
        $timestamp = date('Ymd_His');
        $filename = strtolower($firstName . '_' . $lastName . '_' . $timestamp);
        $filename = preg_replace('/[^a-z0-9_]/', '', $filename);
        if (empty($filename)) $filename = 'cupp_' . $timestamp;
        $filename .= '.txt';
        
        $filepath = $passwordsDir . '/' . $filename;
        file_put_contents($filepath, implode("\n", $passwords));
        
        $generatedFile = 'passwords/' . $filename;
        $generationComplete = true;
        $message = "✅ Generated " . number_format($passwordCount) . " passwords! Saved as: {$filename}";
        
        // Log
        try {
            $pdo = getDBConnection();
            $stmt = $pdo->prepare("INSERT INTO malware_logs (file_hash, file_name, virus_total_report, ai_analysis, malicious_count, total_engines) VALUES (?, ?, ?, ?, ?, ?)");
            $stmt->execute([md5($filename), $filename, json_encode(['type'=>'CUPP','passwords'=>$passwordCount]), 'CUPP generated password list from user profiling', 0, 0]);
        } catch (Exception $e) {}
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>🔑 CUPP - Password Profiler | <?php echo APP_NAME; ?></title>
    <style>
        *{margin:0;padding:0;box-sizing:border-box}
        body{font-family:'Courier New',monospace;background:#000;color:#0f0;min-height:100vh;overflow-x:hidden}
        .matrix-bg{position:fixed;top:0;left:0;right:0;bottom:0;background:#000;opacity:0.95;z-index:0}
        .container{position:relative;z-index:1;max-width:1000px;margin:0 auto;padding:20px}
        
        .header{text-align:center;padding:20px;border:2px solid #ff4500;border-radius:10px;margin-bottom:20px;animation:borderGlow 1.5s infinite}
        @keyframes borderGlow{0%,100%{border-color:#ff4500;box-shadow:0 0 20px rgba(255,69,0,0.5)}50%{border-color:#ff0;box-shadow:0 0 40px rgba(255,255,0,0.7)}}
        .header h1{font-size:24px;color:#ff4500;text-shadow:0 0 10px #ff4500}
        .header .subtitle{color:#ff0;font-size:12px;margin-top:5px}
        
        .warning-lights{display:flex;justify-content:center;gap:15px;margin:15px 0}
        .warning-light{width:16px;height:16px;border-radius:50%;animation:blinkRed 0.8s infinite}
        .warning-light:nth-child(odd){animation-delay:0.4s}
        .warning-light:nth-child(3n){animation-delay:0.2s}
        @keyframes blinkRed{0%,100%{background:#ff0000;box-shadow:0 0 10px #ff0000,0 0 20px #ff0000}50%{background:#330000;box-shadow:0 0 5px #330000}}
        
        .navbar{background:rgba(255,69,0,0.05);border:1px solid rgba(255,69,0,0.3);border-radius:8px;padding:12px 20px;display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:10px;margin-bottom:20px}
        .navbar span{color:#ff4500;font-weight:bold;font-size:14px}
        .nav-links{display:flex;gap:6px;flex-wrap:wrap}
        .nav-links a{color:#a1a1aa;text-decoration:none;padding:6px 12px;border:1px solid #333;border-radius:4px;font-size:11px;transition:all 0.2s}
        .nav-links a:hover{background:rgba(255,69,0,0.1);border-color:#ff4500;color:#ff4500}
        .nav-links a.active{background:rgba(255,69,0,0.2);border-color:#ff4500;color:#ff4500}
        
        .card{background:rgba(255,69,0,0.02);border:1px solid rgba(255,69,0,0.2);border-radius:8px;padding:20px;margin-bottom:20px}
        .card h3{color:#ff4500;margin-bottom:15px;padding-bottom:10px;border-bottom:1px solid rgba(255,69,0,0.2)}
        
        .form-row{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:10px}
        @media(max-width:600px){.form-row{grid-template-columns:1fr}}
        
        .form-group{margin-bottom:10px}
        .form-group label{display:block;margin-bottom:4px;color:#ff8c00;font-size:10px;text-transform:uppercase;letter-spacing:1px}
        .form-group input{width:100%;padding:10px;background:#0a0a0a;border:1px solid #333;color:#0f0;font-family:'Courier New',monospace;font-size:13px;border-radius:4px}
        .form-group input:focus{outline:none;border-color:#ff4500;box-shadow:0 0 10px rgba(255,69,0,0.3)}
        
        .checkbox-group{display:flex;gap:15px;flex-wrap:wrap;margin:12px 0}
        .checkbox-item{display:flex;align-items:center;gap:6px;color:#ff8c00;font-size:11px;cursor:pointer}
        .checkbox-item input[type="checkbox"]{width:14px;height:14px;accent-color:#ff4500;cursor:pointer}
        
        .btn-generate{background:linear-gradient(135deg,#ff4500,#cc3700);color:#fff;border:2px solid #ff4500;padding:14px 30px;border-radius:8px;font-size:15px;font-weight:bold;cursor:pointer;width:100%;font-family:'Courier New',monospace;text-transform:uppercase;letter-spacing:2px;transition:all 0.3s}
        .btn-generate:hover{box-shadow:0 0 40px rgba(255,69,0,0.6);transform:scale(1.02)}
        
        /* Progress Bar - shown after generation */
        .progress-container{background:#0a0a0a;border:1px solid rgba(255,69,0,0.3);border-radius:8px;padding:20px;margin-top:20px}
        .progress-header{display:flex;justify-content:space-between;margin-bottom:10px;font-size:12px}
        .progress-phase{color:#ff0}
        .progress-percent{color:#ff4500;font-weight:bold;font-size:18px}
        .progress-bar{height:20px;background:#1a1a1a;border:1px solid #333;border-radius:10px;overflow:hidden}
        .progress-fill{height:100%;background:linear-gradient(90deg,#ff4500,#ff0,#ff4500);width:100%;border-radius:10px;animation:shimmer 1.5s infinite}
        @keyframes shimmer{0%{transform:translateX(-100%)}100%{transform:translateX(100%)}}
        .progress-info{display:flex;justify-content:space-between;margin-top:8px;font-size:10px;color:#888}
        
        /* Terminal */
        .terminal{background:#000;border:1px solid #333;border-radius:5px;padding:15px;max-height:300px;overflow-y:auto;font-family:'Courier New',monospace;font-size:12px;line-height:1.6;margin-top:15px}
        .terminal .line{margin:1px 0}
        .terminal .line.success{color:#0f0}
        .terminal .line.warning{color:#ff0}
        .terminal .line.cupp{color:#ff8c00}
        
        /* Results */
        .results-box{background:#0a0a0a;border:1px solid #0f0;border-radius:8px;padding:20px;margin-top:20px;animation:slideUp 0.5s}
        @keyframes slideUp{from{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}
        .results-box h4{color:#0f0;margin-bottom:10px}
        .password-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:2px;max-height:350px;overflow-y:auto;font-size:11px}
        .password-grid span{display:block;padding:3px 8px;color:#0f0;border-left:2px solid rgba(0,255,0,0.2)}
        .password-grid span:hover{background:rgba(0,255,0,0.1);border-left-color:#0f0}
        
        .btn-group{display:flex;gap:10px;flex-wrap:wrap;margin-top:15px}
        .btn-download{background:#0f0;color:#000;border:none;padding:10px 20px;border-radius:5px;font-size:12px;font-weight:bold;cursor:pointer;text-decoration:none;font-family:'Courier New',monospace;display:inline-block}
        .btn-print{background:#ff4500;color:#fff;border:none;padding:10px 20px;border-radius:5px;font-size:12px;font-weight:bold;cursor:pointer;font-family:'Courier New',monospace}
        .btn-clear{background:#333;color:#ff4500;border:1px solid #ff4500;padding:10px 20px;border-radius:5px;font-size:12px;cursor:pointer;font-family:'Courier New',monospace}
        
        .alert{padding:10px 15px;border-radius:5px;margin:10px 0;font-size:12px;font-family:'Courier New',monospace}
        .alert-success{background:rgba(0,255,0,0.1);border:1px solid #0f0;color:#0f0}
        .alert-error{background:rgba(255,0,0,0.1);border:1px solid #f00;color:#f00}
        
        .gen-stats{display:flex;gap:20px;flex-wrap:wrap;justify-content:center;margin:10px 0}
        .gen-stat{text-align:center;padding:8px 15px;background:rgba(255,69,0,0.05);border:1px solid rgba(255,69,0,0.2);border-radius:5px}
        .gen-stat .val{color:#ff4500;font-size:18px;font-weight:bold;display:block}
        .gen-stat .lbl{color:#888;font-size:9px;text-transform:uppercase;letter-spacing:1px}
        
        .terminal-log{background:#000;border:1px solid #333;border-radius:5px;padding:15px;font-family:'Courier New',monospace;font-size:11px;line-height:1.8;max-height:400px;overflow-y:auto;margin-top:15px}
        .log-line{margin:2px 0;padding:2px 5px}
        .log-line.info{color:#0ff;border-left:2px solid #0ff}
        .log-line.success{color:#0f0;border-left:2px solid #0f0}
        .log-line.warning{color:#ff0;border-left:2px solid #ff0}
        .log-line.error{color:#ff4500;border-left:2px solid #ff4500}
    </style>
</head>
<body>
    <div class="matrix-bg" id="matrixBg"></div>
    <div class="container">
        <!-- Header -->
        <div class="header">
            <h1>🔑 CUPP - PASSWORD PROFILER</h1>
            <p class="subtitle">[ COMMON USER PASSWORD PROFILER v3.0 ]</p>
            <div class="warning-lights">
                <div class="warning-light"></div><div class="warning-light"></div>
                <div class="warning-light"></div><div class="warning-light"></div>
                <div class="warning-light"></div><div class="warning-light"></div>
                <div class="warning-light"></div>
            </div>
        </div>
        
        <!-- Navigation -->
        <div class="navbar">
            <span>⚡ CUPP_TERMINAL://</span>
            <div class="nav-links">
                <a href="index.php">[Dashboard]</a>
                <a href="attack.php">[Attack]</a>
                <a href="defense.php">[Defense]</a>
                <a href="cupp.php" class="active">[CUPP]</a>
                <a href="reports.php">[Reports]</a>
                <a href="index.php?logout=1" style="color:#f00">[Logout]</a>
            </div>
        </div>
        
        <?php if($message): ?>
        <div class="alert <?php echo strpos($message,'✅')!==false?'alert-success':'alert-error'; ?>"><?php echo $message; ?></div>
        <?php endif; ?>
        
        <!-- Form -->
        <div class="card">
            <h3>👤 TARGET PROFILE DATA</h3>
            <form method="POST" id="cuppForm">
                <div class="form-row">
                    <div class="form-group">
                        <label>[*] First Name *</label>
                        <input type="text" name="first_name" value="<?php echo htmlspecialchars($firstName); ?>" placeholder="John" required>
                    </div>
                    <div class="form-group">
                        <label>[*] Last Name</label>
                        <input type="text" name="last_name" value="<?php echo isset($lastName)?htmlspecialchars($lastName):''; ?>" placeholder="Doe">
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label>[*] Nickname / Username</label>
                        <input type="text" name="nickname" value="<?php echo isset($nickname)?htmlspecialchars($nickname):''; ?>" placeholder="johnd1985">
                    </div>
                    <div class="form-group">
                        <label>[*] Birthdate</label>
                        <input type="date" name="birthdate" value="<?php echo isset($birthdate)?$birthdate:''; ?>">
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label>[*] Partner/Spouse</label>
                        <input type="text" name="partner_name" value="<?php echo isset($partnerName)?htmlspecialchars($partnerName):''; ?>" placeholder="Jane">
                    </div>
                    <div class="form-group">
                        <label>[*] Partner Birthdate</label>
                        <input type="date" name="partner_birthdate" value="<?php echo isset($partnerBirthdate)?$partnerBirthdate:''; ?>">
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label>[*] Pet Name</label>
                        <input type="text" name="pet_name" value="<?php echo isset($petName)?htmlspecialchars($petName):''; ?>" placeholder="Rex">
                    </div>
                    <div class="form-group">
                        <label>[*] Company</label>
                        <input type="text" name="company" value="<?php echo isset($company)?htmlspecialchars($company):''; ?>" placeholder="Acme Corp">
                    </div>
                </div>
                
                <div class="form-group">
                    <label>[*] Keywords (comma-separated)</label>
                    <input type="text" name="keywords" value="<?php echo isset($keywords)?htmlspecialchars($keywords):''; ?>" placeholder="hobby, team, city, car, color">
                </div>
                
                <div class="checkbox-group">
                    <label class="checkbox-item"><input type="checkbox" name="special_chars" <?php echo !isset($specialChars)||$specialChars?'checked':''; ?>> [!] Special Chars</label>
                    <label class="checkbox-item"><input type="checkbox" name="add_numbers" <?php echo !isset($addNumbers)||$addNumbers?'checked':''; ?>> [#] Numbers</label>
                    <label class="checkbox-item"><input type="checkbox" name="leet_mode" <?php echo isset($leetMode)&&$leetMode?'checked':''; ?>> [L33T] Leet Mode</label>
                </div>
                
                <button type="submit" name="generate" class="btn-generate" id="generateBtn">
                    ⚡ INITIALIZE PASSWORD GENERATION ⚡
                </button>
            </form>
        </div>
        
        <!-- Generation Log (shown after generation) -->
        <?php if($generationComplete): ?>
        <div class="progress-container">
            <div class="warning-lights" style="margin-bottom:10px">
                <div class="warning-light"></div><div class="warning-light"></div><div class="warning-light"></div>
            </div>
            <div class="progress-header">
                <span class="progress-phase" style="color:#0f0">[✓] GENERATION COMPLETE</span>
                <span class="progress-percent" style="color:#0f0">100%</span>
            </div>
            <div class="progress-bar">
                <div class="progress-fill"></div>
            </div>
            <div class="progress-info">
                <span>Total: <?php echo number_format($passwordCount); ?> passwords</span>
                <span>File: <?php echo basename($generatedFile); ?></span>
            </div>
            
            <!-- Generation Log -->
            <div class="terminal-log">
                <div class="log-line info">╔══════════════════════════════════╗</div>
                <div class="log-line info">║   CUPP Password Profiler v3.0   ║</div>
                <div class="log-line info">╚══════════════════════════════════╝</div>
                <div class="log-line info">[+] Initializing password generation engine...</div>
                <div class="log-line info">[+] Loading user profile data...</div>
                <div class="log-line success">    → First Name: <?php echo htmlspecialchars($firstName); ?></div>
                <?php if(!empty($lastName)): ?><div class="log-line success">    → Last Name: <?php echo htmlspecialchars($lastName); ?></div><?php endif; ?>
                <?php if(!empty($nickname)): ?><div class="log-line success">    → Nickname: <?php echo htmlspecialchars($nickname); ?></div><?php endif; ?>
                <?php if(!empty($birthdate)): ?><div class="log-line success">    → Birthdate: <?php echo $birthdate; ?></div><?php endif; ?>
                <div class="log-line warning">[*] Phase 1: Extracting base words...</div>
                <div class="log-line success">    → <?php echo count($words ?? []); ?> unique base words extracted</div>
                <div class="log-line warning">[*] Phase 2: Generating combinations...</div>
                <div class="log-line success">    → Single + double + triple combinations</div>
                <?php if($addNumbers): ?><div class="log-line warning">[*] Phase 3: Adding number suffixes...</div>
                <div class="log-line success">    → 17 common number patterns applied</div><?php endif; ?>
                <?php if($specialChars): ?><div class="log-line warning">[*] Phase 4: Adding special characters...</div>
                <div class="log-line success">    → 8 special characters applied</div><?php endif; ?>
                <?php if($leetMode): ?><div class="log-line warning">[*] Phase 5: L33T transformations...</div>
                <div class="log-line success">    → a→4, e→3, i→1, o→0, s→5, t→7, l→1</div><?php endif; ?>
                <div class="log-line warning">[*] Finalizing: Removing duplicates...</div>
                <div class="log-line success">[✓] Generation complete!</div>
                <div class="log-line success">[✓] Total unique passwords: <?php echo number_format($passwordCount); ?></div>
                <div class="log-line success">[✓] Saved to: <?php echo basename($generatedFile); ?></div>
                <div class="log-line warning">╔══════════════════════════════════╗</div>
                <div class="log-line warning">║   GENERATION SUCCESSFUL          ║</div>
                <div class="log-line warning">╚══════════════════════════════════╝</div>
            </div>
        </div>
        
        <!-- Results -->
        <div class="results-box">
            <h4>📋 GENERATED PASSWORD LIST</h4>
            <div class="gen-stats">
                <div class="gen-stat"><span class="val"><?php echo number_format($passwordCount); ?></span><span class="lbl">Total Passwords</span></div>
                <div class="gen-stat"><span class="val"><?php echo round(filesize($passwordsDir.'/'.$filename)/1024,1); ?> KB</span><span class="lbl">File Size</span></div>
                <div class="gen-stat"><span class="val"><?php echo basename($generatedFile); ?></span><span class="lbl">Filename</span></div>
            </div>
            <div class="btn-group">
                <a href="<?php echo $generatedFile; ?>" download class="btn-download">📥 DOWNLOAD FULL LIST</a>
                <button onclick="window.print()" class="btn-print">🖨️ PRINT</button>
                <a href="cupp.php" class="btn-clear">🔄 NEW PROFILE</a>
            </div>
            <div class="password-grid" style="margin-top:15px">
                <?php foreach(array_slice($passwords,0,200) as $p): ?>
                <span><?php echo htmlspecialchars($p); ?></span>
                <?php endforeach; ?>
                <?php if($passwordCount > 200): ?>
                <span style="color:#ff4500;grid-column:1/-1;text-align:center;padding:10px;font-size:12px">
                    ⚡ ... and <?php echo number_format($passwordCount - 200); ?> more passwords (download for full list)
                </span>
                <?php endif; ?>
            </div>
        </div>
        <?php endif; ?>
    </div>
    
    <script>
    // Matrix rain effect
    const canvas=document.createElement('canvas');const ctx=canvas.getContext('2d');
    document.getElementById('matrixBg').appendChild(canvas);canvas.width=window.innerWidth;canvas.height=window.innerHeight;
    const chars='01';const drops=Array(Math.floor(canvas.width/14)).fill(1);
    function draw(){ctx.fillStyle='rgba(0,0,0,0.05)';ctx.fillRect(0,0,canvas.width,canvas.height);ctx.fillStyle='#ff4500';ctx.font='14px monospace';for(let i=0;i<drops.length;i++){ctx.fillText(chars[Math.floor(Math.random()*chars.length)],i*14,drops[i]*14);if(drops[i]*14>canvas.height&&Math.random()>0.975)drops[i]=0;drops[i]++;}}
    setInterval(draw,50);
    window.addEventListener('resize',()=>{canvas.width=window.innerWidth;canvas.height=window.innerHeight;});
    </script>
</body>
</html>