function TermsModal() {
  const [open, setOpen] = React.useState(
    !!(window.OPEN_TERMS) || window.location.hash === '#terms'
  );

  React.useEffect(() => {
    if (open) document.title = 'Terms — Network of Time';
    else if (document.title === 'Terms — Network of Time')
      document.title = 'Network of Time — an interactive archive';
  }, [open]);

  React.useEffect(() => {
    function onKey(e) { if (e.key === 'Escape' && open) handleClose(); }
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, [open]);

  React.useEffect(() => {
    function onModal(e) { if (e.detail === 'terms') setOpen(true); }
    function onPop() {
      const p = window.location.pathname;
      if (p !== '/terms' && p !== '/terms.html') setOpen(false);
    }
    window.addEventListener('not:modal', onModal);
    window.addEventListener('popstate',  onPop);
    return () => {
      window.removeEventListener('not:modal', onModal);
      window.removeEventListener('popstate',  onPop);
    };
  }, []);

  function handleClose() {
    setOpen(false);
    const p = window.location.pathname;
    if (p === '/terms' || p === '/terms.html') {
      if (window.history.state && window.history.state.notModal) {
        history.back();
      } else {
        history.pushState({}, '', '/');
      }
    }
  }

  if (!open) return null;

  return (
    <div className="abt-overlay" onClick={e => { if (e.target === e.currentTarget) handleClose(); }}>
      <div className="abt-panel lgl-panel">
        <div className="abt-head">
          <span className="abt-label mono">Legal</span>
          <button className="abt-close" onClick={handleClose}>✕</button>
        </div>
        <div className="abt-body lgl-body">
          <h2 className="abt-section-head">Terms and Conditions</h2>
          <p className="lgl-effective">Effective Date: June 14, 2025</p>

          <p>Welcome to Network Of Time (https://www.networkoftime.com). By using this website, you agree to the terms outlined below. If you do not agree, please do not use this website.</p>

          <h3 className="lgl-h3">1. About Network Of Time</h3>
          <p>Network Of Time is a public platform that documents verifiable photographic encounters between notable individuals, spanning history to present day. Users may explore, contribute, and engage with this curated archive.</p>

          <h3 className="lgl-h3">2. Use of the Site</h3>
          <p>You may browse, share, and reference materials on the site for personal, educational, and non-commercial purposes. You may not use Network Of Time:</p>
          <ul className="lgl-list">
            <li>To infringe on the intellectual property, privacy, or publicity rights of others</li>
            <li>To upload or submit misleading, defamatory, illegal, or harmful content</li>
            <li>To attempt unauthorized access to user data, backend systems, or accounts</li>
            <li>To scrape or systematically extract content from the platform without permission</li>
          </ul>

          <h3 className="lgl-h3">3. User Accounts</h3>
          <p>To upload photos or contribute to the site, you may need to create an account. You agree to:</p>
          <ul className="lgl-list">
            <li>Provide accurate and current information</li>
            <li>Keep your login credentials secure</li>
            <li>Accept responsibility for all activity under your account</li>
            <li>Notify us immediately if you suspect unauthorized use</li>
          </ul>
          <p>We reserve the right to suspend or terminate accounts for violations of these Terms or disruptive behavior.</p>

          <h3 className="lgl-h3">4. User-Submitted Photos and Content</h3>
          <p>You may upload photos for moderation and potential inclusion. By uploading, you confirm that:</p>
          <ul className="lgl-list">
            <li>You own the image or have obtained necessary rights and permissions</li>
            <li>The image does not contain nudity, hate speech, unlawful material, or deceptive representations</li>
            <li>You understand inclusion is not guaranteed and is subject to editorial discretion</li>
            <li>You grant us a non-exclusive, royalty-free, worldwide license to use, display, distribute, and adapt the image as part of our platform, publications, and promotional efforts</li>
          </ul>
          <p>You retain ownership of your uploads. We may remove any submission at any time, for any reason, with or without notice.</p>

          <h3 className="lgl-h3">5. Intellectual Property</h3>
          <p>All original content on the site—including site structure, branding, data visualizations, metadata curation, and commentary—is the intellectual property of Network Of Time and may not be copied, mirrored, or reused without explicit permission.</p>
          <p>We respect copyright. If you believe content on the site infringes your rights, contact us at jesse@networkoftime.com.</p>

          <h3 className="lgl-h3">6. Privacy</h3>
          <p>Your use of this site is subject to our <a className="lgl-link" href="/privacy.html">Privacy Policy</a>, which outlines how we collect, store, and use personal information.</p>

          <h3 className="lgl-h3">7. Cookies and Analytics</h3>
          <p>Network Of Time uses cookies and analytics tools to improve the site and understand visitor behavior. By using the site, you consent to this use as described in our Privacy Policy.</p>

          <h3 className="lgl-h3">8. Disclaimer and Limitation of Liability</h3>
          <p>Network Of Time is a curated project and may contain errors, omissions, or outdated information. All content is provided "as is" without warranties of any kind.</p>
          <p>To the fullest extent permitted by law, we disclaim all liability for:</p>
          <ul className="lgl-list">
            <li>Inaccuracies or omissions</li>
            <li>Damages resulting from use or inability to use the site</li>
            <li>Third-party content linked or referenced</li>
          </ul>

          <h3 className="lgl-h3">9. Changes to These Terms</h3>
          <p>We may revise these Terms from time to time. The latest version will always be available at this URL, with the effective date listed above. By continuing to use the site after any updates, you agree to the revised Terms.</p>

          <h3 className="lgl-h3">10. Contact and Copyright Complaints</h3>
          <div className="lgl-contact-box">
            <p>If you have any questions about these Terms, or if you believe that content hosted on Network Of Time infringes your copyright or other rights, please contact:</p>
            <p><strong>Network Of Time</strong><br />Email: <a className="lgl-link" href="mailto:jesse@networkoftime.com">jesse@networkoftime.com</a><br />Website: https://www.networkoftime.com</p>
            <p>Please include the following in any copyright complaint:</p>
            <ul className="lgl-list">
              <li>Your full name and contact information</li>
              <li>A clear description of the copyrighted work you believe has been infringed</li>
              <li>The exact URL or location of the allegedly infringing content</li>
              <li>A statement that you believe in good faith that the use is unauthorized</li>
              <li>A statement, under penalty of perjury, that the information you provide is accurate and that you are authorized to act on behalf of the copyright owner</li>
            </ul>
            <p>We will review all complaints promptly and take appropriate action, which may include removing or restricting access to the material in question.</p>
          </div>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { TermsModal });
