function PrivacyModal() {
  const [open, setOpen] = React.useState(
    !!(window.OPEN_PRIVACY) || window.location.hash === '#privacy'
  );

  React.useEffect(() => {
    if (open) document.title = 'Privacy — Network of Time';
    else if (document.title === 'Privacy — 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 === 'privacy') setOpen(true); }
    function onPop() {
      const p = window.location.pathname;
      if (p !== '/privacy' && p !== '/privacy.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 === '/privacy' || p === '/privacy.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">Privacy Policy</h2>
          <p className="lgl-effective">Effective Date: June 14, 2025</p>

          <p>At Network Of Time ("we", "us", or "our"), accessible at https://www.networkoftime.com, we are committed to protecting your privacy and ensuring you understand how your personal information is handled. This Privacy Policy outlines what data we collect, how we use it, your rights, and how we keep your data secure.</p>

          <h3 className="lgl-h3">1. Information We Collect</h3>
          <p>We may collect the following categories of information:</p>

          <p><strong>Account Data</strong><br />When you create an account, we collect your name, email address, username, and any other information you choose to provide.</p>

          <p><strong>Uploaded Content</strong><br />If you submit photos or text, we collect that content and any associated metadata you provide (such as names, descriptions, and dates).</p>

          <p><strong>Log and Usage Data</strong><br />Like most websites, we automatically collect information about your visit, including IP address, browser type, referring/exit pages, date/time stamps, and pages viewed.</p>

          <p><strong>Cookies</strong><br />We use cookies to enhance user experience, analyze traffic, and personalize content. You may disable cookies via your browser settings, but this may affect site functionality.</p>

          <p><strong>Third-Party Tools</strong><br />We may use services like Google Analytics to understand how users interact with the site. These tools may use cookies or similar technologies to collect non-personally identifying data. We do not combine this data with any personally identifiable information.</p>

          <h3 className="lgl-h3">2. How We Use Your Information</h3>
          <p>We use your information to:</p>
          <ul className="lgl-list">
            <li>Provide and operate our services</li>
            <li>Moderate and publish user-submitted content</li>
            <li>Communicate with you, including for account or support purposes</li>
            <li>Improve and personalize our site and services</li>
            <li>Enforce our Terms of Use and protect against misuse or fraud</li>
            <li>Comply with legal obligations</li>
          </ul>

          <h3 className="lgl-h3">3. User-Submitted Photos</h3>
          <p>By uploading a photo, you affirm that:</p>
          <ul className="lgl-list">
            <li>You have the legal right to share and publish the image</li>
            <li>The image does not violate any copyright, privacy, or publicity rights</li>
            <li>You understand and agree the image may be reviewed, published, or rejected at our sole discretion</li>
            <li>You grant us a non-exclusive, royalty-free, worldwide, irrevocable, and perpetual license to use, display, store, modify, and share the image in connection with Network Of Time's services, promotion, and documentation</li>
          </ul>

          <h3 className="lgl-h3">4. Disclosure of Information</h3>
          <p>We do not sell your personal information. We may share it only in these circumstances:</p>
          <ul className="lgl-list">
            <li>With service providers acting on our behalf (e.g., web hosting, analytics)</li>
            <li>If required by law, regulation, subpoena, or court order</li>
            <li>If we believe disclosure is necessary to prevent harm, enforce our Terms, or address security or legal concerns</li>
            <li>As part of a merger, acquisition, or other business transition, with proper safeguards</li>
          </ul>

          <h3 className="lgl-h3">5. Data Retention</h3>
          <p>We retain personal information as long as necessary for the purposes outlined above, or as required by law. You may request deletion of your account or uploaded content at any time by contacting us at <a className="lgl-link" href="mailto:jesse@networkoftime.com">jesse@networkoftime.com</a>.</p>

          <h3 className="lgl-h3">6. Security</h3>
          <p>We use commercially reasonable measures to protect your data, including encrypted transmission (HTTPS), limited access controls, and regular review of data practices. However, no method of transmission over the internet is 100% secure.</p>

          <h3 className="lgl-h3">7. Children's Privacy</h3>
          <p>Our services are not intended for users under the age of 13. We do not knowingly collect personal information from children. If we become aware of such data, we will delete it.</p>

          <h3 className="lgl-h3">8. Your Rights</h3>
          <p>If you are a resident of Canada, the EU, or another jurisdiction with data access laws, you may have the right to:</p>
          <ul className="lgl-list">
            <li>Access the personal data we hold about you</li>
            <li>Request correction or deletion of your data</li>
            <li>Object to or restrict certain types of data processing</li>
            <li>Withdraw consent, where applicable</li>
          </ul>
          <p>To exercise these rights, contact us at <a className="lgl-link" href="mailto:jesse@networkoftime.com">jesse@networkoftime.com</a>.</p>

          <h3 className="lgl-h3">9. External Links</h3>
          <p>Our website may contain links to third-party sites. We are not responsible for the privacy practices or content of those sites.</p>

          <h3 className="lgl-h3">10. Updates to This Policy</h3>
          <p>We may update this Privacy Policy from time to time. When we do, we will update the "Effective Date" at the top of this page. Your continued use of the site constitutes your acceptance of the revised policy.</p>

          <h3 className="lgl-h3">11. Contact Us</h3>
          <div className="lgl-contact-box">
            <p>If you have any questions about this policy or your data, 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>
          </div>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { PrivacyModal });
