<div id="restore-quiz-container">
  <div id="quiz-header">
    <h2 style="color:#C5A059; text-transform:uppercase; letter-spacing:2px; margin-bottom:5px;">Restore Skin Finder</h2>
    <p style="font-size:14px; color:#666;">Expert Dr-Led Clinical Guidance</p>
  </div>

  <form id="quiz-form">
    <input type="hidden" name="access_key" value="ab8236da-64b7-4d39-9fc3-66dee6cb5304">
    <input type="hidden" name="Recommended_Treatment" id="hidden-result">
    <input type="hidden" name="subject" value="New Quiz Lead - Restore Skin Clinic">
    <input type="hidden" name="from_name" value="Restore Skin Finder">

    <div class="quiz-step" id="step-1">
      <h3 style="margin-bottom:20px; font-size:18px;">1. What is your primary concern?</h3>
      <div class="quiz-opt" onclick="saveChoice('Polynucleotides (Eyes)', 2)">Dark Circles / Under-eye Hollowing</div>
      <div class="quiz-opt" onclick="saveChoice('Anti-Wrinkle (Smooth)', 2)">Fine Lines & Wrinkles</div>
      <div class="quiz-opt" onclick="saveChoice('Dermal Fillers (Lift)', 2)">Loss of Volume / Sagging</div>
      <div class="quiz-opt" onclick="saveChoice('Skin Boosters (Glow)', 2)">Dullness or "Tired" Skin</div>
    </div>

    <div class="quiz-step" id="step-2" style="display:none;">
      <h3 style="margin-bottom:10px; font-size:18px;">Almost there...</h3>
      <p style="font-size:14px; margin-bottom:20px; color:#555;">Enter your details to reveal your clinical roadmap  <strong>and complmentary consultation</strong>.</p>
      <input type="text" name="name" id="quiz-name" placeholder="Your Name" class="quiz-input" required>
      <input type="email" name="email" id="quiz-email" placeholder="Your Email Address" class="quiz-input" required>
      <button type="submit" id="submit-btn" class="submit-gate-btn">REVEAL MY RESULTS</button>
    </div>
  </form>

  <div id="quiz-results" style="display:none;">
    <div class="result-box">
      <div style="background:#C5A059; color:white; display:inline-block; padding:5px 15px; border-radius:50px; font-size:12px; margin-bottom:10px;">YOUR RECOMMENDATION</div>
      <h3 id="result-title" style="color:#333; margin-top:5px; font-size:22px;"></h3>
      <div class="dr-insight">
        <strong style="color:#C5A059;">Dr. Chi's Clinical Insight:</strong>
        <p id="result-insight" style="margin-top:8px; line-height:1.6; font-style:italic; color:#444;"></p>
      </div>
      <div class="promo-box">
        <p style="margin:0; font-size:16px;"><strong>Congratulations on completing the skin quiz</strong></p>
        <p style="font-size:12px; margin:5px 0 0 0; color:#666;">+ Complimentary Post-Treatment Skin Check</p>
      </div>
      <a href="/appointments" class="book-btn-quiz">BOOK FREE CONSULTATION (£50 VALUE)</a>
    </div>
  </div>
</div>

<style>
  #restore-quiz-container { max-width: 480px; margin: 40px auto; padding: 40px; background: #fff; border: 1px solid #C5A059; border-radius: 20px; text-align: center; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-shadow: 0 15px 40px rgba(0,0,0,0.08); }
  .quiz-opt { display: block; width: 100%; padding: 18px; margin: 12px 0; background: #fff; border: 1px solid #e5e5e5; border-radius: 12px; cursor: pointer; transition: all 0.3s ease; font-size: 15px; color: #333; box-sizing: border-box; font-weight: 500; }
  .quiz-opt:hover { border-color: #C5A059; background: #fdfaf4; transform: translateY(-2px); box-shadow: 0 4px 10px rgba(197, 160, 89, 0.1); }
  .quiz-input { width: 100%; padding: 15px; margin-bottom: 15px; border: 1px solid #ddd; border-radius: 10px; box-sizing: border-box; font-size: 16px; outline: none; }
  .quiz-input:focus { border-color: #C5A059; }
  .submit-gate-btn { background: #333; color: white; border: none; padding: 18px 30px; border-radius: 50px; cursor: pointer; font-weight: bold; width: 100%; letter-spacing: 1px; transition: background 0.3s; margin-top: 5px; }
  .submit-gate-btn:hover { background: #C5A059; }
  .dr-insight { background: #fcfcfc; padding: 22px; margin: 25px 0; border-radius: 12px; text-align: left; font-size: 14px; border-left: 4px solid #C5A059; }
  .promo-box { background: #fdfaf4; border: 1px dashed #C5A059; padding: 20px; margin: 20px 0; border-radius: 12px; }
  .book-btn-quiz { display: block; background: #C5A059; color: white !important; padding: 20px; text-decoration: none; border-radius: 50px; font-weight: bold; margin-top: 20px; transition: 0.3s; letter-spacing: 1px; }
  .book-btn-quiz:hover { filter: brightness(1.1); transform: scale(1.02); }
</style>

<script>
  let selectedResult = '';

  function saveChoice(choice, next) {
    selectedResult = choice;
    document.getElementById('hidden-result').value = choice;
    document.getElementById('step-1').style.display = 'none';
    document.getElementById('step-2').style.display = 'block';
  }

  const form = document.getElementById('quiz-form');
  form.addEventListener('submit', function(e) {
    e.preventDefault();
    const btn = document.getElementById('submit-btn');
    btn.innerText = "Generating Roadmap...";
    btn.disabled = true;
    
    const formData = new FormData(form);
    const object = Object.fromEntries(formData);
    const json = JSON.stringify(object);

    fetch('https://api.web3forms.com/submit', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
        body: json
    })
    .then(response => {
        if (response.status == 200) {
            showResults();
        } else {
            alert("Something went wrong. Please try again.");
            btn.innerText = "REVEAL MY RESULTS";
            btn.disabled = false;
        }
    })
    .catch(error => {
        console.log(error);
        showResults(); // Show results anyway if there is a network glitch
    });
  });

  function showResults() {
    document.getElementById('quiz-form').style.display = 'none';
    document.getElementById('quiz-header').style.display = 'none';
    document.getElementById('quiz-results').style.display = 'block';

    const title = document.getElementById('result-title');
    const insight = document.getElementById('result-insight');

    if (selectedResult.includes('Eyes')) {
      title.innerText = "The Regenerative Eye Restore";
      insight.innerText = "For hollowing and dark circles, Dr. Chi focuses on Polynucleotides. This sophisticated biological treatment repairs skin at a cellular level, thickening the delicate under-eye area naturally without the risks of puffiness associated with traditional fillers.";
    } else if (selectedResult.includes('Smooth')) {
      title.innerText = "The Smooth & Soften Roadmap";
      insight.innerText = "Dr. Chi prioritizes a 'refreshed' over a 'frozen' look. By precisely targeting expression lines, we can soften wrinkles while maintaining your natural movement and facial character.";
    } else if (selectedResult.includes('Lift')) {
      title.innerText = "The Structural Lift & Define";
      insight.innerText = "Using dermal fillers, Dr. Chi restores the structural 'scaffolding' of the face. By supporting the mid-face and jawline, we achieve a natural lift that respects your unique anatomy.";
    } else {
      title.innerText = "The Radiance & Refresh Plan";
      insight.innerText = "Healthy skin is hydrated skin. Dr. Chi recommends medical-grade skin boosters to flood the dermis with moisture, improving light reflection and creating a naturally glowing complexion.";
    }
    
    window.scrollTo({ top: document.getElementById('restore-quiz-container').offsetTop - 50, behavior: 'smooth' });
  }
</script>