make the best looks and chenge this page fully: <?php
session_start();
require 'db.php';

$login_error = '';
$register_error = '';

// Handle login
if (isset($_POST['login'])) {
    $username = trim($_POST['username']);
    $password = $_POST['password'];

    // Fetch user by username
    $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
    $stmt->execute([$username]);
    $user = $stmt->fetch();

    if ($user && password_verify($password, $user['password'])) {
        // Set session variables
        $_SESSION['user_id'] = $user['id'];
        $_SESSION['username'] = $user['username'];
        $_SESSION['full_name'] = $user['full_name'];
        $_SESSION['is_admin'] = $user['is_admin'] ?? 0;

        // Redirect based on admin status
        if ($_SESSION['is_admin'] == 1) {
            header("Location: admin.php");
        } else {
            header("Location: dashboard.php");
        }
        exit;
    } else {
        // Login failed
        $login_error = "نام کاربری یا رمزعبور اشتباه است.";
    }
}

// Handle registration
if (isset($_POST['register'])) {
  $full_name = trim($_POST['full_name']);
  $username = trim($_POST['username']);
  $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
  $email = filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL);

  // Input validation
  if (empty($full_name) || empty($username) || empty($_POST['password']) || !$email) {
      $register_error = "لطفاً تمام فیلدها را پر کنید.";
  } else {
      // Check if email exists
      $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
      $stmt->execute([$email]);
      if ($stmt->rowCount() > 0) {
          $register_error = "این ایمیل قبلاً ثبت شده است.";
      } else {
          // Check if username exists
          $stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
          $stmt->execute([$username]);

          if ($stmt->rowCount() > 0) {
              $register_error = "این نام کاربری قبلاً گرفته شده است.";
          } else {
              // Insert new user with email
              $stmt = $pdo->prepare("INSERT INTO users 
                  (full_name, username, password, email, max_students, students_uploaded)
                  VALUES (?, ?, ?, ?, 400, 0)");
              
              if ($stmt->execute([$full_name, $username, $password, $email])) {
                  $userId = $pdo->lastInsertId();

                  // Generate token & set expiration
                  $token = bin2hex(random_bytes(50));
                  $expires = date('Y-m-d H:i:s', strtotime('+1 hour'));

                  // Save token to DB
                  $stmt = $pdo->prepare("UPDATE users SET verification_token = ?, verification_expires = ? WHERE id = ?");
                  $stmt->execute([$token, $expires, $userId]);

                  // Build verification URL
                  $verifyUrl = "http://yourdomain.com/verify_email.php?token=$token";

                  // Compose message
                  $subject = "تایید ایمیل - سامانه دانش آموزان";
                  $message = "سلام $full_name,\n\nلطفاً ایمیل خود را با کلیک روی لینک زیر تایید کنید:\n$verifyUrl\n\nاین لینک بعد از یک ساعت منقضی می‌شود.";
                  $headers = "From: <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>\r\n";
                  $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

                  // Send email
                  if (mail($email, $subject, $message, $headers)) {
                      echo "<p style='color:green;text-align:center;'>✅ ایمیل تایید برای شما ارسال شد.</p>";
                  } else {
                      $register_error = "ثبت نام موفقیت‌آمیز بود، اما ایمیل ارسال نشد. لطفاً با پشتیبانی تماس بگیرید.";
                  }
              } else {
                  $register_error = "ثبت نام با خطا مواجه شد.";
              }
          }
      }
  }
}
?>
<!-- From Uiverse.io by andrew-demchenk0 --> 
 <!DOCTYPE html>
 <html lang="en">
 <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <Style rel="stylesheet" href="style.css"></style>
    <style>
     @font-face {
  font-family: 'IranSans';
  src: url('IranSans.woff2') format('woff2'),
       url('IranSans.woff') format('woff'),
       url('IranSans.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

* {
  font-family: 'IranSans' !important;
} 
     body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background-color: #1a202c;
            font-family: Arial, sans-serif;
        }
        .error-message {
            color: #ff3333;
            font-size: 14px;
            margin-top: -15px;
            margin-bottom: 10px;
            text-align: center;
        }
        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            padding: 20px;
        }
        .wrapper {
            --input-focus: #2d8cf0;
            --font-color: #323232;
            --font-color-sub: #666;
            --bg-color: #fff;
            --bg-color-alt: #666;
            --main-color: #323232;
        }
        
/* switch card */
.switch {
            transform: translateY(-200px);
            position: relative;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 30px;
            width: 50px;
            height: 20px;
        }

.card-side::before {
  position: absolute;
  content: 'وارد شدن';
  left: -90px;
  top: 0;
  width: 100px;
  text-decoration: underline;
  color: white;
  font-weight: 600;
}

.card-side::after {
  position: absolute;
  content: 'ثبت نام';
  left: 70px;
  top: 0;
  width: 100px;
  text-decoration: none;
  color: white;
  font-weight: 600;
}

.toggle {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  box-sizing: border-box;
  border-radius: 5px;
  border: 2px solid var(--main-color);
  box-shadow: 4px 4px var(--main-color);
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: white;
  transition: 0.4s;
}

.slider:before {
  box-sizing: border-box;
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  border: 2px solid var(--main-color);
  border-radius: 5px;
  left: -2px;
  bottom: 2px;
  background-color: var(--bg-color);
  box-shadow: 0 3px 0 var(--main-color);
  transition: 0.3s;
}

.toggle:checked + .slider {
  background-color: var(--input-focus);
}

.toggle:checked + .slider:before {
  transform: translateX(30px);
}

.toggle:checked ~ .card-side:before {
  text-decoration: none;
}

.toggle:checked ~ .card-side:after {
  text-decoration: underline;
}

/* card */ 

.flip-card__inner {
  width: 300px;
  height: 350px;
  position: relative;
  background-color: transparent;
  perspective: 1000px;
    /* width: 100%;
    height: 100%; */
  text-align: center;
  transition: transform 0.8s;
  transform-style: preserve-3d;
}

.toggle:checked ~ .flip-card__inner {
  transform: rotateY(180deg);
}

.toggle:checked ~ .flip-card__front {
  box-shadow: none;
}

.flip-card__front, .flip-card__back {
  padding: 20px;
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: center;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
 background-color:rgb(80, 147, 223);
  gap: 20px;
  border-radius: 5px;
  border: 2px solid black;
  box-shadow: 4px 4px var(--main-color);
}

.flip-card__back {
  width: 100%;
  transform: rotateY(180deg);
}

.flip-card__form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.title {
  margin: 20px 0 20px 0;
  font-size: 25px;
  font-weight: 900;
  text-align: center;
  color: var(--main-color);
}

.flip-card__input {
  width: 250px;
  height: 40px;
  border-radius: 5px;
  border: 2px solid var(--main-color);
  background-color: var(--bg-color);
  box-shadow: 4px 4px var(--main-color);
  font-size: 15px;
  font-weight: 600;
  color: var(--font-color);
  padding: 5px 10px;
  outline: none;
}

.flip-card__input::placeholder {
  color: var(--font-color-sub);
  opacity: 0.8;
}

.flip-card__input:focus {
  border: 2px solid var(--input-focus);
}

.flip-card__btn:active, .button-confirm:active {
  box-shadow: 0px 0px var(--main-color);
  transform: translate(3px, 3px);
}

.flip-card__btn {
            margin: 20px 0 20px 0;
            width: 120px;
            height: 40px;
            border-radius: 5px;
            border: 2px solid var(--main-color);
            background-color: var(--bg-color);
            box-shadow: 4px 4px var(--main-color);
            font-size: 17px;
            font-weight: 600;
            color: var(--font-color);
            cursor: pointer;
        }
        .slider.slider-error {
  background-color: whtie !important; /* bright red */
  border-color: #ff0000 !important;
  box-shadow: 4px 4px #ff0000 !important;
}

.slider.slider-error:before {
  background-color: #ffcccc !important;
  border-color: #ff0000 !important;
  box-shadow: 0 3px 0 #ff0000 !important;
}
        </style>
 </head>
 <body>
 <div id="particles-js" style="position: fixed; width: 100%; height: 100%; top: 0; left: 0; z-index: 0;"></div>
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>

    <div class="container">
        <div class="wrapper">
            <div class="card-switch">
                <label class="switch">
                    <input type="checkbox" class="toggle">
                    <span class="slider <?php echo isset($login_error) ? 'slider-error' : ''; ?>"></span>
                    <span class="card-side"></span>
                    <div class="flip-card__inner">
                        <!-- Login Form -->
                        <div class="flip-card__front">
                            <div class="title">ورود</div>
                            <?php if (isset($login_error)): ?>
                                <div class="error-message"><?php echo $login_error; ?></div>
                            <?php endif; ?>
                            <form class="flip-card__form" method="post">
                                <input class="flip-card__input" name="username" placeholder="نام کاربری" required>
                                <input class="flip-card__input" name="password" placeholder="گذرواژه" type="password" required>
                                
                                <button class="flip-card__btn" type="submit" name="login">ورود</button>
                            </form>
                        </div>
                        
                        <!-- Register Form -->
                        <div class="flip-card__back">
                            <div class="title">ثبت نام</div>
                            <?php if (isset($register_error)): ?>
                                <div class="error-message"><?php echo $register_error; ?></div>
                            <?php endif; ?>
                            <form class="flip-card__form" method="post">
                                <input class="flip-card__input" name="full_name" placeholder="نام و نام خانوادگی" required>
                                <input class="flip-card__input" name="username" placeholder="نام کاربری" required>
                                <input class="flip-card__input" name="password" placeholder="گذرواژه" type="password" required>
                                <input class="flip-card__input" name="email" type="email" placeholder="ایمیل" required>
                                <button class="flip-card__btn" type="submit" name="register">تایید</button>
                            </form>
                        </div>
                    </div>
                </label>
            </div>   
        </div>
    </div>
  
        <script>
    particlesJS('particles-js',
    {
      "particles": {
        "number": {
          "value": 60,
          "density": {
            "enable": true,
            "value_area": 800
          }
        },
        "color": {
          "value": "#ffffff"
        },
        "shape": {
          "type": "circle"
        },
        "opacity": {
          "value": 0.5,
          "random": false
        },
        "size": {
          "value": 3,
          "random": true
        },
        "line_linked": {
          "enable": true,
          "distance": 150,
          "color": "#ffffff",
          "opacity": 0.4,
          "width": 1
        },
        "move": {
          "enable": true,
          "speed": 2,
          "direction": "none",
          "random": false,
          "straight": false,
          "out_mode": "out"
        }
      },
      "interactivity": {
        "detect_on": "canvas",
        "events": {
          "onhover": {
            "enable": true,
            "mode": "grab"
          },
          "onclick": {
            "enable": true,
            "mode": "push"
          },
          "resize": true
        },
        "modes": {
          "grab": {
            "distance": 200,
            "line_linked": {
              "opacity": 1
            }
          },
          "push": {
            "particles_nb": 4
          }
        }
      },
      "retina_detect": true
    });
  </script>
  
</body>
</html>