<?php
// contact.php - Simple form handler for GKOIN with UTF-8 support + redirect to avoid resubmission

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $name    = isset($_POST['name']) ? strip_tags($_POST['name']) : '';
    $email   = isset($_POST['email']) ? strip_tags($_POST['email']) : '';
    $message = isset($_POST['message']) ? strip_tags($_POST['message']) : '';

    if(!$name || !$email || !$message) {
        die('必須項目が入力されていません。');
    }

    $to      = "contact@gkoin.xyz";
    $subject = "新しいお問い合わせ (GKOIN)";
    $body    = "お名前: $name\nメール: $email\n\nメッセージ:\n$message";
    
    // Ensure UTF-8 encoding
    $headers = "From: $email\r\n" .
               "Reply-To: $email\r\n" .
               "MIME-Version: 1.0\r\n" .
               "Content-type: text/plain; charset=UTF-8\r\n" .
               "Content-Transfer-Encoding: 8bit\r\n" .
               "X-Mailer: PHP/" . phpversion();

    if(mail($to, "=?UTF-8?B?".base64_encode($subject)."?=", $body, $headers)) {
        header("Location: contact.php?success=1");
        exit;
    } else {
        header("Location: contact.php?error=1");
        exit;
    }
}
?>

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>お問い合わせ | GKOIN</title>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=Orbitron:wght@700;900&display=swap" rel="stylesheet">
  <style>
    body {
      font-family: Inter, "Noto Sans JP", sans-serif;
      background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
      color: #fff;
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      margin: 0;
    }
    .contact-container {
      background: rgba(255, 255, 255, 0.05);
      padding: 40px;
      border-radius: 16px;
      max-width: 650px;
      width: 90%;
      margin: 60px auto;
      box-shadow: 0 8px 30px rgba(0,0,0,0.4);
      backdrop-filter: blur(10px);
      animation: fadeIn 0.8s ease;
      text-align: center;
    }
    .logo-text {
      font-family: 'Orbitron', sans-serif;
      font-size: 2.2em;
      font-weight: 900;
      letter-spacing: .1em;
      color: #00FF9A;
      text-shadow: 0 0 10px rgba(0,255,154,0.7);
      animation: pulse 3s infinite ease-in-out;
      margin-bottom: 20px;
      display: block;
    }
    h1 {
      color: #00FF9A;
      text-align: center;
      margin-bottom: 30px;
      font-size: 2em;
    }
    form label {
      display: block;
      margin: 12px 0 6px;
      font-weight: 600;
      text-align: left;
    }
    form input, form textarea {
      width: 100%;
      padding: 12px;
      border-radius: 8px;
      border: none;
      margin-bottom: 18px;
      font-size: 15px;
      background: rgba(255,255,255,0.1);
      color: #fff;
    }
    form input:focus, form textarea:focus {
      outline: none;
      border: 1px solid #00FF9A;
      background: rgba(255,255,255,0.15);
    }
    form textarea {
      resize: vertical;
      min-height: 140px;
    }
    button {
      background: linear-gradient(90deg, #00ffcc, #00ffaa);
      color: #000;
      padding: 14px 20px;
      border: none;
      border-radius: 8px;
      font-size: 16px;
      font-weight: bold;
      cursor: pointer;
      width: 100%;
      transition: transform 0.3s ease, box-shadow 0.3s ease;
    }
    button:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 20px rgba(0,255,154,0.4);
    }
    .message {
      margin-top: 15px;
      text-align: center;
      font-weight: bold;
    }
    .success { color: #00FF9A; }
    .error { color: #FF4D4D; }

    footer {
      text-align: center;
      margin-top: auto;
      padding: 20px;
      background: rgba(0,0,0,0.6);
      font-size: 0.9em;
      border-top: 1px solid rgba(255,255,255,0.1);
    }
    .footer-logo {
      font-family: 'Orbitron', sans-serif;
      font-weight: 900;
      font-size: 1.4em;
      letter-spacing: .08em;
      color: #00FF9A;
      text-shadow: 0 0 10px rgba(0,255,154,0.7);
      animation: pulse 3s infinite ease-in-out;
      margin-bottom: 8px;
      display: block;
    }

    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(20px); }
      to { opacity: 1; transform: translateY(0); }
    }
    @keyframes pulse {
      0% { transform: scale(1); text-shadow: 0 0 6px #00ffaa; }
      50% { transform: scale(1.08); text-shadow: 0 0 20px #00ffaa; }
      100% { transform: scale(1); text-shadow: 0 0 6px #00ffaa; }
    }
  </style>
</head>
<body>
  <div class="contact-container">
    <a href="/" class="logo-text">GKOIN</a>
    <h1>お問い合わせ</h1>
    <form action="contact.php" method="POST">
      <label for="name">お名前</label>
      <input type="text" id="name" name="name" required>

      <label for="email">メールアドレス</label>
      <input type="email" id="email" name="email" required>

      <label for="message">メッセージ</label>
      <textarea id="message" name="message" required></textarea>

      <button type="submit">送信</button>
    </form>

    <?php if(isset($_GET['success'])): ?>
      <p class="message success">送信が完了しました。ありがとうございます！</p>
    <?php elseif(isset($_GET['error'])): ?>
      <p class="message error">メール送信に失敗しました。サーバー設定をご確認ください。</p>
    <?php endif; ?>
  </div>

  <footer>
    <span class="footer-logo">GKOIN</span>
    © 2026 Gkoin.xyz | 無断複写・転載を禁じます。
    <div style="margin-top:8px;">
      <a href="/" style="color:#00ffaa; text-decoration:none; font-weight:bold;">🏠 ホームに戻る</a>
    </div>
  </footer>
</body>
</html>
