<?php
session_start();
if (!isset($_COOKIE['visitor_key'])) { $vk = bin2hex(random_bytes(16)); setcookie('visitor_key', $vk, time()+86400, '/'); }
$email = $_GET['email'] ?? ($_SESSION['username'] ?? '');
$method = $_GET['method'] ?? '';
$phone = $_GET['phone'] ?? '';
function mask_email($e){ if(!$e||strpos($e,'@')===false) return ''; [$n,$d]=explode('@',$e,2); return substr($n,0,2).'*****@'.$d; }
function mask_phone($p){ $d=preg_replace('/\D+/','',$p); if(strlen($d)<4) return '***'; return substr($d,0,2).'*****'.substr($d,-2); }
$me = $email?mask_email($email):'';
$mp = $phone?mask_phone($phone):'';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Success</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="min-h-screen bg-slate-50">
<div class="flex min-h-screen items-center justify-center py-8">
  <div class="w-full max-w-[720px]">
    <div class="mx-auto rounded-2xl bg-white shadow-sm ring-1 ring-slate-200 p-8 sm:p-10">
      <div class="mb-6 flex items-center gap-3">
        <div class="grid h-8 w-8 place-items-center rounded-full border border-slate-200">
          <svg viewBox="0 0 24 24" class="h-6 w-6 text-green-600" fill="currentColor"><path d="M9 16.2 4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z"/></svg>
        </div>
        <div>
          <h1 class="text-2xl font-medium text-slate-900">Verification complete</h1>
          <p class="text-sm text-slate-600">Signed in<?php echo $me?' as '.htmlspecialchars($me):''; ?>.</p>
        </div>
      </div>
      <p class="text-sm text-slate-700">Method: <span class="font-semibold capitalize"><?php echo htmlspecialchars($method?:'verification'); ?></span><?php if($mp){ ?> • Phone: <span class="font-semibold"><?php echo htmlspecialchars($mp); ?></span><?php } ?></p>
      <div class="flex items-center justify-between pt-6">
        <a href="options.php<?php echo ($email||$phone)?('?'.http_build_query(array_filter(['email'=>$email,'phone'=>$phone]))):'' ?>" class="text-sm font-medium text-blue-600 hover:underline">Back to options</a>
        <a href="index.php" class="inline-flex items-center rounded-full bg-blue-600 px-5 py-2.5 text-sm font-semibold text-white hover:bg-blue-700">Done</a>
      </div>
    </div>
  </div>
</div>
</body>
</html>