<?php
$response = null;
$error = null;

if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["phone"])) {
    $phone = urlencode(trim($_POST["phone"]));
    $apiUrl = "https://tmphpscripts.xyz/TajammalAPIv16/Hamza.php?num=" . $phone;

    // Fetch data using file_get_contents or cURL
    $apiResponse = @file_get_contents($apiUrl);
    if ($apiResponse) {
        $data = json_decode($apiResponse, true);
        if ($data && isset($data[0])) {
            $user = $data[0];
        } else {
            $error = "❌ No data found for this number.";
        }
    } else {
        $error = "❌ Error fetching data. Server might be down.";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>AM - SIM DATA-BASE</title>
  
    /* ... same CSS as before ... */
    * { box-sizing: border-box; margin: 0; padding: 0; }
    html, body {
      height: 100%; font-family: 'Segoe UI', sans-serif;
      background: black; color: #fff; overflow: hidden;
    }
    canvas { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 0; }
    .container {
      position: absolute; top: 50%; left: 50%;
      transform: translate(-50%, -50%); z-index: 2;
      backdrop-filter: blur(10px); background: rgba(0,0,0,0.6);
      border-radius: 20px; padding: 30px;
      width: 90%; max-width: 420px; box-shadow: 0 0 30px #00f2ff;
    }
    h2 { color: #00f2ff; text-align: center; margin-bottom: 20px; }
    input, button {
      width: 100%; padding: 12px; margin: 10px 0;
      border: none; border-radius: 10px; font-size: 16px;
    }
    input { background: #111; color: white; }
    .btn { background: #00f2ff; color: black; font-weight: bold; cursor: pointer; transition: 0.3s; }
    .btn:hover { background: #00c2d4; }
    .result-box {
      background: rgba(255,255,255,0.05); padding: 20px; margin-top: 20px;
      border-radius: 12px; font-size: 14px; box-shadow: 0 0 10px #00f2ff;
    }
    .result-box h3 { text-align: center; color: #0ff; margin-bottom: 10px; }
    .result-box p { margin: 6px 0; }
    .error {
      margin-top: 20px; padding: 12px; text-align: center;
      border-radius: 10px; background: #400; color: red;
    }
  
</head>
<body>

<canvas id="matrixCanvas"></canvas>

<div class="container">
  <h2>🔍 AM - SIM DATA-BASE</h2>
  <form method="POST">
    <input type="text" name="phone" placeholder="Enter phone number" required />
    <button type="submit" class="btn">🔎 Search</button>
  </form>

  <?php if (isset($user)): ?>
    <div class="result-box">
      <h3>🔎 SIM Data Found</h3>
     
      <p><strong>👤 Name:</strong> <?= htmlspecialchars($user['Name'] ?? 'Not found') ?></p>
      <p><strong>🆔 CNIC:</strong> <?= htmlspecialchars($user['CNIC'] ?? 'Not found') ?></p>
      <p><strong>📍 Address:</strong> <?= htmlspecialchars($user['Address'] ?? 'Not found') ?></p>
      <p><strong>📶 Operator:</strong> <?= htmlspecialchars($user['Operator'] ?? 'Not found') ?></p>
    </div>
  <?php elseif ($error): ?>
    <div class="error"><?= $error ?></div>
  <?php endif; ?>

  <a href="https://whatsapp.com/channel/0029VajZpqL7T8bRvUqAU23A" target="_blank">
    <button class="btn">💬 Contact Developer</button>
  </a>
</div>

<script>
  // Matrix background effect (unchanged)
  const canvas = document.getElementById("matrixCanvas");
  const ctx = canvas.getContext("2d");
  canvas.height = window.innerHeight;
  canvas.width = window.innerWidth;
  const chars = "01";
  const fontSize = 16;
  const columns = canvas.width / fontSize;
  const drops = Array(Math.floor(columns)).fill(1);

  function drawMatrix() {
    ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = "#00f2ff";
    ctx.font = fontSize + "px monospace";

    for (let i = 0; i < drops.length; i++) {
      const text = chars[Math.floor(Math.random() * chars.length)];
      ctx.fillText(text, i * fontSize, drops[i] * fontSize);
      if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {
        drops[i] = 0;
      }
      drops[i]++;
    }
  }

  setInterval(drawMatrix, 30);
</script>

</body>
</html>