<!-- Signup Modal -->
<div class="modal-overlay" id="signupModal" role="dialog" aria-label="Sign up for API key">
  <div class="modal">
    <button class="close" id="btn-close-signup" aria-label="Close">&times;</button>

    <div id="signupInitial" class="active">
      <h2>Get your free API key</h2>
      <p>Enter your email to get started. No credit card required.</p>
      <div class="signup-error" id="signupError"></div>
      <label for="signupEmail" class="sr-only">Email address</label>
      <input type="email" id="signupEmail" placeholder="your.email@example.com" style="width:100%;padding:12px;border:1px solid var(--border);background:var(--bg);color:var(--fg);border-radius:8px;font-size:0.9rem;margin-bottom:16px;" required>
      <button class="btn btn-primary" style="width:100%" id="signupBtn">Generate API Key →</button>
      <p style="margin-top:16px;color:var(--muted);font-size:0.8rem;text-align:center;">100 free PDFs/month • All endpoints included<br><a href="#" class="open-recover" style="color:var(--muted)">Lost your API key? Recover it →</a></p>
    </div>

    <div id="signupLoading">
      <div class="spinner"></div>
      <p style="color:var(--muted);margin:0">Generating your API key…</p>
    </div>

    <div id="signupVerify">
      <h2>Enter verification code</h2>
      <p>We sent a 6-digit code to <strong id="verifyEmailDisplay"></strong></p>
      <div class="signup-error" id="verifyError"></div>
      <label for="verifyCode" class="sr-only">Verification code</label>
      <input type="text" id="verifyCode" placeholder="123456" maxlength="6" pattern="[0-9]{6}" inputmode="numeric" style="width:100%;padding:14px;border:1px solid var(--border);background:var(--bg);color:var(--fg);border-radius:8px;font-size:1.4rem;letter-spacing:0.3em;text-align:center;margin-bottom:16px;font-family:monospace;" required>
      <button class="btn btn-primary" style="width:100%" id="verifyBtn">Verify →</button>
      <p style="margin-top:16px;color:var(--muted);font-size:0.8rem;text-align:center;">Code expires in 15 minutes</p>
    </div>

    <div id="signupResult" aria-live="polite">
      <h2>🚀 Your API key is ready!</h2>
      <div class="warning-box">
        <span class="icon">⚠️</span>
        <span>Save your API key securely. Lost it? <a href="#" class="open-recover" style="color:#fbbf24">Recover via email</a></span>
      </div>
      <div style="background:var(--bg);border:1px solid var(--accent);border-radius:8px;padding:14px;font-family:monospace;font-size:0.82rem;word-break:break-all;margin:16px 0;position:relative;">
        <span id="apiKeyText"></span>
        <button onclick="copyKey()" id="copyBtn" style="position:absolute;top:8px;right:8px;background:var(--accent);color:var(--bg);border:none;border-radius:4px;padding:4px 12px;cursor:pointer;font-size:0.8rem;">Copy</button>
      </div>
      <p style="margin-top:20px;color:var(--muted);font-size:0.9rem;">100 free PDFs/month • <a href="/docs">Read the docs →</a></p>
    </div>
  </div>
</div>