<?php
// Simple PHP website - All in one file

// Handle form submission
$message = '';
$success = false;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = htmlspecialchars($_POST['name'] ?? '');
    $email = htmlspecialchars($_POST['email'] ?? '');
    $msg = htmlspecialchars($_POST['message'] ?? '');

    if (empty($name) || empty($email) || empty($msg)) {
        $message = "❌ All fields are required!";
    } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $message = "❌ Invalid email address!";
    } else {
        // Send email
        $to = "your-email@example.com"; // Change this
        $subject = "New Message from $name";
        $headers = "From: $email\r\nReply-To: $email\r\n";
        
        if (mail($to, $subject, $msg, $headers)) {
            $message = "✅ Message sent successfully!";
            $success = true;
        } else {
            $message = "❌ Error sending message!";
        }
    }
}

// Get current page
$page = $_GET['page'] ?? 'home';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My PHP Website</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            color: #333;
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* Navigation */
        nav {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem 0;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }

        nav .container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-size: 1.8rem;
            font-weight: bold;
        }

        nav ul {
            list-style: none;
            display: flex;
            gap: 2rem;
        }

        nav a {
            color: white;
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 5px;
            transition: background 0.3s;
        }

        nav a:hover {
            background: rgba(255,255,255,0.2);
        }

        nav a.active {
            background: rgba(255,255,255,0.3);
            font-weight: bold;
        }

        /* Main Content */
        main {
            padding: 3rem 0;
            min-height: calc(100vh - 200px);
        }

        section {
            display: none;
        }

        section.active {
            display: block;
        }

        h1 {
            color: #667eea;
            margin-bottom: 1.5rem;
            font-size: 2.5rem;
        }

        h2 {
            color: #667eea;
            margin: 1.5rem 0 1rem 0;
        }

        p {
            margin-bottom: 1rem;
            font-size: 1.1rem;
            line-height: 1.8;
        }

        /* Cards */
        .card-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 2rem;
            margin: 2rem 0;
        }

        .card {
            background: white;
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            transition: transform 0.3s;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .card h3 {
            color: #667eea;
            margin-bottom: 0.5rem;
        }

        /* Form */
        form {
            background: #f4f4f4;
            padding: 2rem;
            border-radius: 8px;
            max-width: 600px;
        }

        form input,
        form textarea {
            width: 100%;
            padding: 12px;
            margin: 1rem 0;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-family: Arial, sans-serif;
            font-size: 1rem;
        }

        form input:focus,
        form textarea:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 5px rgba(102, 126, 234, 0.3);
        }

        form button {
            background: #667eea;
            color: white;
            padding: 12px 30px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1rem;
            transition: background 0.3s;
        }

        form button:hover {
            background: #764ba2;
        }

        /* Message */
        .message {
            padding: 1rem;
            border-radius: 5px;
            margin: 1rem 0;
            font-weight: bold;
            font-size: 1.1rem;
        }

        .message.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .message.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        /* Footer */
        footer {
            background: #333;
            color: white;
            text-align: center;
            padding: 2rem 0;
            margin-top: 3rem;
        }

        /* Responsive */
        @media (max-width: 768px) {
            nav ul {
                gap: 1rem;
            }

            nav a {
                padding: 0.3rem 0.7rem;
                font-size: 0.9rem;
            }

            h1 {
                font-size: 1.8rem;
            }

            .card-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <!-- Navigation -->
    <nav>
        <div class="container">
            <div class="logo">🚀 MyPHP Site</div>
            <ul>
                <li><a href="?page=home" class="<?= $page === 'home' ? 'active' : '' ?>">Home</a></li>
                <li><a href="?page=about" class="<?= $page === 'about' ? 'active' : '' ?>">About</a></li>
                <li><a href="?page=services" class="<?= $page === 'services' ? 'active' : '' ?>">Services</a></li>
                <li><a href="?page=contact" class="<?= $page === 'contact' ? 'active' : '' ?>">Contact</a></li>
            </ul>
        </div>
    </nav>

    <!-- Main Content -->
    <main>
        <div class="container">*