// legal-pages.jsx — Terms of Service + Privacy Policy
const { useState, useEffect } = React;

const LegalShell = ({ title, lastUpdated, onBack, children }) => {
  useEffect(() => { window.scrollTo(0, 0); }, []);
  return (
    <div style={{ minHeight: '100vh', background: 'var(--bg0)', color: 'var(--t1)', fontFamily: 'var(--font)' }}>
      {/* Nav */}
      <div style={{ borderBottom: '1px solid var(--border)', padding: '0 max(24px,5vw)' }}>
        <div style={{ maxWidth: 1080, margin: '0 auto', height: 60, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer' }} onClick={onBack}>
            <LogoMark size={26} />
            <span style={{ fontSize: 15, fontWeight: 700, letterSpacing: '-0.02em' }}>RoStealth</span>
          </div>
          <button onClick={onBack} style={{ background: 'none', border: '1px solid var(--border)', borderRadius: 8, color: 'var(--t2)', fontSize: 13, fontFamily: 'var(--font)', padding: '7px 14px', cursor: 'pointer', transition: 'all 0.15s' }}
            onMouseEnter={e => { e.currentTarget.style.borderColor = 'var(--border2)'; e.currentTarget.style.color = 'var(--t1)'; }}
            onMouseLeave={e => { e.currentTarget.style.borderColor = 'var(--border)'; e.currentTarget.style.color = 'var(--t2)'; }}>
            ← Back to home
          </button>
        </div>
      </div>

      {/* Header */}
      <div style={{ borderBottom: '1px solid var(--border)', padding: '56px max(24px,5vw) 48px' }}>
        <div style={{ maxWidth: 720, margin: '0 auto' }}>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, background: 'var(--p-dim)', border: '1px solid var(--border-bright)', borderRadius: 20, padding: '4px 12px', marginBottom: 20 }}>
            <span style={{ width: 5, height: 5, borderRadius: '50%', background: 'var(--p4)' }} />
            <span style={{ fontSize: 11, fontWeight: 600, color: 'var(--p4)', letterSpacing: '0.06em', textTransform: 'uppercase' }}>Legal</span>
          </div>
          <h1 style={{ fontSize: 'clamp(28px,4vw,40px)', fontWeight: 700, letterSpacing: '-0.04em', marginBottom: 12 }}>{title}</h1>
          <p style={{ fontSize: 14, color: 'var(--t3)' }}>Last updated: {lastUpdated}</p>
        </div>
      </div>

      {/* Body */}
      <div style={{ padding: '56px max(24px,5vw) 96px' }}>
        <div style={{ maxWidth: 720, margin: '0 auto' }}>
          {children}
        </div>
      </div>
    </div>
  );
};

const Section = ({ title, children }) => (
  <div style={{ marginBottom: 48 }}>
    <h2 style={{ fontSize: 18, fontWeight: 700, letterSpacing: '-0.03em', color: 'var(--t1)', marginBottom: 16, paddingBottom: 12, borderBottom: '1px solid var(--border)' }}>{title}</h2>
    <div style={{ fontSize: 14.5, color: 'var(--t2)', lineHeight: 1.8, display: 'flex', flexDirection: 'column', gap: 12 }}>
      {children}
    </div>
  </div>
);

const P = ({ children }) => <p style={{ margin: 0 }}>{children}</p>;

const Ul = ({ items }) => (
  <ul style={{ margin: 0, paddingLeft: 20, display: 'flex', flexDirection: 'column', gap: 8 }}>
    {items.map((item, i) => <li key={i} style={{ color: 'var(--t2)' }}>{item}</li>)}
  </ul>
);

const Callout = ({ children }) => (
  <div style={{ background: 'var(--p-dim)', border: '1px solid var(--border-bright)', borderRadius: 10, padding: '14px 16px', fontSize: 13.5, color: 'var(--p3)', lineHeight: 1.7 }}>
    {children}
  </div>
);

// ─── TERMS OF SERVICE ─────────────────────────────────────────────────────────
const TermsPage = ({ onBack }) => (
  <LegalShell title="Terms of Service" lastUpdated="June 14, 2026" onBack={onBack}>
    <Callout>
      RoStealth uses only publicly available data from Roblox's official APIs. We do not collect Roblox passwords, access private accounts, or deploy bots. We are not affiliated with, endorsed by, or partnered with Roblox Corporation.
    </Callout>

    <div style={{ marginTop: 40 }}>
      <Section title="1. Acceptance of Terms">
        <P>By accessing or using RoStealth ("the Service", "we", "us", "our"), you ("User", "you") agree to be legally bound by these Terms of Service ("Terms"). If you do not agree to all of these Terms, you must not use the Service.</P>
        <P>You must be at least 13 years of age to use RoStealth. If you are under 18, you represent that you have obtained verifiable parental or guardian consent. We reserve the right to terminate accounts of users found to be under 13.</P>
        <P>These Terms constitute the entire agreement between you and RoStealth with respect to the Service and supersede all prior agreements, whether written or oral.</P>
      </Section>

      <Section title="2. Description of Service">
        <P>RoStealth is a community intelligence platform that allows Roblox group owners, managers, and community administrators to monitor publicly available player presence data — including online/offline status and active game sessions — for Roblox accounts they choose to track.</P>
        <P>All data displayed by RoStealth is sourced exclusively from Roblox Corporation's publicly accessible presence and user APIs. No private account data, login credentials, or non-public information is accessed at any point. The Service acts as a data aggregation and alerting layer on top of information that is already publicly visible on the Roblox platform.</P>
        <P>We reserve the right to modify, suspend, or discontinue any part of the Service at any time with or without notice. We will not be liable to you or any third party for any modification, suspension, or discontinuation of the Service.</P>
      </Section>

      <Section title="3. User Accounts">
        <P>Account creation and authentication is handled by Clerk, Inc. ("Clerk"). You are responsible for maintaining the confidentiality of your account credentials and for all activities that occur under your account.</P>
        <P>You agree to: (a) provide accurate, current, and complete information; (b) maintain and promptly update your account information; (c) notify us immediately at <span style={{ color: 'var(--p4)' }}>support@rostealth.site</span> of any unauthorised use of your account; and (d) ensure you log out at the end of each session if using shared devices.</P>
        <P>We are not liable for any loss or damage arising from your failure to comply with these obligations. You may not transfer your account to another person without our prior written consent.</P>
      </Section>

      <Section title="4. Acceptable Use Policy">
        <P>You agree to use RoStealth solely for lawful purposes and in a manner consistent with these Terms. You agree not to use the Service to:</P>
        <Ul items={[
          'Stalk, harass, intimidate, threaten, or target any individual',
          'Monitor individuals without a legitimate group management or community administration purpose',
          'Systematically collect, store, or distribute data on Roblox users outside of personal group management use',
          'Violate any applicable local, national, or international law or regulation, including data protection laws',
          'Violate Roblox Corporation\'s Terms of Service or Community Standards',
          'Resell, sublicense, redistribute, or commercially exploit data obtained through RoStealth',
          'Attempt to gain unauthorised access to our systems, servers, or databases',
          'Reverse-engineer, decompile, or disassemble any part of the Service',
          'Transmit any malicious code, viruses, or harmful data',
          'Interfere with or disrupt the integrity or performance of the Service',
          'Use automated means to access or query the Service at rates that exceed normal human use',
        ]} />
        <P>Violation of this Acceptable Use Policy may result in immediate termination of your account without refund and, where appropriate, referral to law enforcement authorities.</P>
      </Section>

      <Section title="5. Subscriptions & Billing">
        <P>RoStealth offers a free tier with limited functionality and a Pro subscription ("RoStealth Pro") with full access. Subscription payments are processed securely by Stripe, Inc. ("Stripe").</P>
        <Ul items={[
          'Pro subscriptions are billed on a recurring monthly basis at the rate displayed at time of purchase',
          'Your subscription renews automatically each billing period unless cancelled',
          'You may cancel your subscription at any time — access to Pro features continues until the end of the current paid billing period',
          'We do not offer refunds for partial billing periods or unused subscription time, except where required by applicable law',
          'We reserve the right to change subscription pricing with at least 30 days\' advance notice via email or in-app notification',
          'Continued use of the Service after a price change constitutes acceptance of the new pricing',
          'We are not responsible for any fees charged by your payment provider',
        ]} />
        <P>If a payment fails, we may suspend access to Pro features until payment is successfully processed. Repeated payment failures may result in account suspension.</P>
      </Section>

      <Section title="6. Intellectual Property">
        <P>"Roblox" and the Roblox logo are registered trademarks of Roblox Corporation. RoStealth is an independent third-party service with no affiliation with, endorsement by, or sponsorship from Roblox Corporation. Use of the Roblox name is purely descriptive to indicate compatibility.</P>
        <P>All RoStealth branding, software, design, content, and code ("RoStealth IP") is owned by or licensed to RoStealth. You are granted a limited, non-exclusive, non-transferable, revocable licence to use the Service for its intended purpose. You may not copy, modify, distribute, sell, or create derivative works from RoStealth IP without our express written permission.</P>
        <P>Any feedback, suggestions, or ideas you provide regarding the Service may be used by us freely without any obligation to you.</P>
      </Section>

      <Section title="7. Data & Privacy">
        <P>We store only the data necessary to provide the Service: your account information (managed by Clerk), the Roblox usernames you choose to track, your alert configurations, and status history for tracked users. We do not sell your personal data.</P>
        <P>By using the Service, you consent to the collection and processing of data as described in our Privacy Policy, which is incorporated into these Terms by reference.</P>
      </Section>

      <Section title="8. Disclaimers">
        <P>THE SERVICE IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR UNINTERRUPTED, ERROR-FREE OPERATION.</P>
        <P>We do not warrant that: (a) data sourced from Roblox's API will be accurate, complete, or real-time — accuracy depends entirely on Roblox's own infrastructure; (b) the Service will be available at all times or free from errors or interruptions; or (c) any defects will be corrected.</P>
        <P>You acknowledge that Roblox may change or restrict access to its APIs at any time, which may affect the functionality of the Service. We accept no liability for any such changes.</P>
      </Section>

      <Section title="9. Limitation of Liability">
        <P>TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL ROSTEALTH, ITS OPERATORS, AFFILIATES, AGENTS, OR LICENSORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS, DATA, GOODWILL, OR OTHER INTANGIBLE LOSSES, ARISING OUT OF OR IN CONNECTION WITH YOUR USE OF OR INABILITY TO USE THE SERVICE.</P>
        <P>IN NO EVENT SHALL OUR TOTAL LIABILITY TO YOU FOR ALL CLAIMS ARISING OUT OF OR RELATING TO THESE TERMS OR THE SERVICE EXCEED THE GREATER OF (A) THE TOTAL AMOUNT YOU PAID TO ROSTEALTH IN THE TWELVE (12) MONTHS PRECEDING THE CLAIM, OR (B) FIFTY POUNDS STERLING (£50).</P>
        <P>Some jurisdictions do not allow the exclusion or limitation of certain warranties or liabilities. In such jurisdictions, our liability is limited to the maximum extent permitted by law.</P>
      </Section>

      <Section title="10. Indemnification">
        <P>You agree to indemnify, defend, and hold harmless RoStealth and its operators, affiliates, agents, and licensors from and against any claims, liabilities, damages, losses, costs, and expenses (including reasonable legal fees) arising out of or in connection with: (a) your use of or access to the Service; (b) your violation of these Terms; (c) your violation of any third-party rights, including Roblox's Terms of Service; or (d) any content you submit or transmit through the Service.</P>
      </Section>

      <Section title="11. Termination">
        <P>We reserve the right to suspend or terminate your access to the Service immediately, without prior notice or liability, for any reason, including if you breach these Terms.</P>
        <P>Upon termination, your right to use the Service ceases immediately. You may request deletion of your data by contacting us at <span style={{ color: 'var(--p4)' }}>support@rostealth.site</span> or via Settings if that option is available. Provisions of these Terms that by their nature should survive termination shall survive, including Sections 6, 9, 10, and 13.</P>
      </Section>

      <Section title="12. Changes to Terms">
        <P>We may update these Terms at any time. We will provide at least 14 days' notice of material changes via email to your registered address or via a prominent in-app notice. Your continued use of the Service after the effective date of changes constitutes your acceptance of the updated Terms. If you do not agree to the revised Terms, you must stop using the Service before the changes take effect.</P>
      </Section>

      <Section title="13. Governing Law & Dispute Resolution">
        <P>These Terms shall be governed by and construed in accordance with the laws of England and Wales, without regard to conflict of law principles.</P>
        <P>Any dispute, controversy, or claim arising out of or relating to these Terms or the Service shall first be attempted to be resolved through good-faith negotiation. If unresolved within 30 days, disputes shall be subject to the exclusive jurisdiction of the courts of England and Wales.</P>
        <P>Notwithstanding the foregoing, we reserve the right to seek injunctive or other equitable relief in any court of competent jurisdiction to prevent irreparable harm.</P>
      </Section>

      <Section title="14. General">
        <P><strong style={{ color: 'var(--t1)' }}>Severability</strong> — If any provision of these Terms is found to be invalid or unenforceable, the remaining provisions will continue in full force and effect.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Waiver</strong> — Our failure to enforce any right or provision of these Terms shall not constitute a waiver of that right or provision.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Force Majeure</strong> — We shall not be liable for any failure or delay in performance resulting from causes beyond our reasonable control, including acts of God, internet outages, third-party service failures (including Roblox API unavailability), or government actions.</P>
        <P><strong style={{ color: 'var(--t1)' }}>No Assignment</strong> — You may not assign or transfer these Terms or any rights hereunder without our prior written consent. We may assign these Terms freely.</P>
      </Section>

      <Section title="15. Contact">
        <P>For questions about these Terms: <span style={{ color: 'var(--p4)' }}>legal@rostealth.site</span></P>
      </Section>
    </div>
  </LegalShell>
);

// ─── PRIVACY POLICY ──────────────────────────────────────────────────────────
const PrivacyPage = ({ onBack }) => (
  <LegalShell title="Privacy Policy" lastUpdated="June 14, 2026" onBack={onBack}>
    <Callout>
      We built RoStealth to be as privacy-respecting as possible. We collect only what we need to operate the service, never sell your data, and give you full control over your information.
    </Callout>

    <div style={{ marginTop: 40 }}>
      <Section title="1. Who We Are">
        <P>RoStealth ("we", "us", "our") operates the service available at rostealth.site. For any privacy-related enquiries, contact us at <span style={{ color: 'var(--p4)' }}>privacy@rostealth.site</span>.</P>
        <P>This Privacy Policy explains how we collect, use, store, share, and protect your personal data when you use our Service. By using RoStealth, you acknowledge you have read and understood this policy.</P>
      </Section>

      <Section title="2. Data We Collect">
        <P><strong style={{ color: 'var(--t1)' }}>Account data</strong> — managed by Clerk, Inc., our authentication provider. This includes your email address, username, and any profile data provided via social login (e.g. Google). Clerk acts as a data processor on our behalf. See Clerk's Privacy Policy at clerk.com/privacy.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Tracking data</strong> — the Roblox usernames you add to your tracker, alert rules you configure, and status history (online / offline / in-game events with timestamps) generated from polling Roblox's public API for those usernames.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Payment data</strong> — subscription billing is handled by Stripe, Inc. We store only your Stripe Customer ID to link your account to your subscription status. We never receive, store, or process your card number, CVV, or billing address — these are handled exclusively by Stripe.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Technical data</strong> — server access logs including IP addresses, browser/OS type, referring URL, and request timestamps. Retained for up to 30 days for security and abuse prevention. Error and performance data is collected via Sentry (see Section 4).</P>
        <P><strong style={{ color: 'var(--t1)' }}>What we do NOT collect</strong> — Roblox passwords, private Roblox account data, location data beyond IP-level, or any sensitive personal information as defined under applicable data protection law.</P>
      </Section>

      <Section title="3. Legal Basis for Processing (GDPR)">
        <P>If you are located in the European Economic Area (EEA) or United Kingdom, we process your personal data on the following legal bases:</P>
        <Ul items={[
          'Contract performance — processing necessary to provide the Service you have signed up for (e.g. storing your tracked users, delivering alerts)',
          'Legitimate interests — processing necessary for our legitimate business interests (e.g. security monitoring, fraud prevention, service improvement), where these do not override your rights',
          'Legal obligation — processing required to comply with applicable law',
          'Consent — where we have obtained your explicit consent (e.g. optional marketing communications)',
        ]} />
      </Section>

      <Section title="4. Third-Party Services">
        <P><strong style={{ color: 'var(--t1)' }}>Clerk (clerk.com)</strong> — authentication and user account management. Processes your email and login credentials. Acts as a data processor under our instruction.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Stripe (stripe.com)</strong> — payment processing. Handles all card data independently. Stripe is an independent data controller for payment data. See stripe.com/privacy.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Roblox Corporation (roblox.com)</strong> — we query Roblox's publicly accessible presence API to retrieve status information for the usernames you track. No credentials or private data are sent to Roblox on your behalf.</P>
        <P><strong style={{ color: 'var(--t1)' }}>Sentry (sentry.io)</strong> — application monitoring and error tracking. When errors occur in our backend or frontend, anonymised diagnostic data (including stack traces and browser/OS type) is sent to Sentry to help us identify and fix bugs. We do not send personally identifiable information to Sentry beyond what may appear incidentally in error logs. Sentry's infrastructure is hosted in the EU (Germany). See sentry.io/privacy.</P>
        <P>We do not use advertising networks, social media trackers, or any third-party analytics that profile you across websites.</P>
      </Section>

      <Section title="5. How We Use Your Data">
        <Ul items={[
          'To provide, operate, and maintain the RoStealth service',
          'To authenticate your identity and manage your account',
          'To execute alert rules and deliver status notifications you have configured',
          'To process subscription payments and manage your billing status',
          'To detect, investigate, and prevent fraudulent or abusive activity',
          'To monitor service health, diagnose errors, and improve performance',
          'To respond to your support or legal enquiries',
          'To comply with applicable legal obligations',
        ]} />
        <P>We do not use your data for advertising, behavioural profiling, or any purpose beyond operating and improving the Service.</P>
      </Section>

      <Section title="6. Data Retention">
        <P>We retain your data only for as long as necessary for the purposes set out in this policy:</P>
        <Ul items={[
          'Account data — retained until you delete your account',
          'Tracked usernames and alert rules — retained until you delete them or close your account',
          'Status history snapshots — retained for 90 days then automatically purged',
          'Fired alert history — retained for 30 days',
          'Server access logs — retained for up to 30 days',
          'Stripe Customer ID — retained for up to 7 years to comply with financial record-keeping obligations',
        ]} />
        <P>Upon account deletion, all personal data we hold is permanently deleted within 30 days, except where retention is required by law.</P>
      </Section>

      <Section title="7. Data Sharing & Disclosure">
        <P>We do not sell, rent, or trade your personal data. We may share your data only in the following limited circumstances:</P>
        <Ul items={[
          'With our sub-processors (Clerk, Stripe, Sentry) as described in Section 4, under contractual obligations to protect your data',
          'If required by law, court order, or regulatory authority',
          'To protect the rights, property, or safety of RoStealth, our users, or the public',
          'In connection with a merger, acquisition, or sale of assets, where the acquiring party will be bound by this Privacy Policy',
        ]} />
      </Section>

      <Section title="8. International Data Transfers">
        <P>Our servers are located in the European Union (Germany). Some of our sub-processors (Clerk, Stripe) operate in the United States. Where personal data is transferred outside the UK/EEA, we ensure appropriate safeguards are in place, such as Standard Contractual Clauses (SCCs) approved by the European Commission or equivalent mechanisms.</P>
      </Section>

      <Section title="9. Your Rights">
        <P>Depending on your location, you have some or all of the following rights regarding your personal data:</P>
        <Ul items={[
          'Access — request a copy of the personal data we hold about you',
          'Rectification — request correction of inaccurate or incomplete data',
          'Erasure ("right to be forgotten") — request deletion of your data, subject to legal retention requirements',
          'Restriction — request that we restrict processing of your data in certain circumstances',
          'Portability — receive your data in a structured, machine-readable format',
          'Objection — object to processing based on legitimate interests',
          'Withdraw consent — where processing is based on consent, you may withdraw it at any time',
        ]} />
        <P>To exercise any of these rights, contact us at <span style={{ color: 'var(--p4)' }}>privacy@rostealth.site</span>. We will respond within 30 days. You also have the right to lodge a complaint with your local data protection authority (in the UK: the ICO at ico.org.uk).</P>
        <P><strong style={{ color: 'var(--t1)' }}>California residents (CCPA)</strong> — You have the right to know what personal information we collect, the right to delete it, and the right to opt out of its sale. We do not sell personal information. To submit a CCPA request, contact <span style={{ color: 'var(--p4)' }}>privacy@rostealth.site</span>.</P>
      </Section>

      <Section title="10. Cookies & Tracking Technologies">
        <P>RoStealth uses only strictly necessary cookies — specifically session tokens set by Clerk for authentication purposes. These are essential for the Service to function and cannot be disabled without breaking your login session.</P>
        <P>We do not use advertising cookies, social media pixels, cross-site tracking cookies, or any form of fingerprinting technology. No third-party cookies are set by RoStealth.</P>
      </Section>

      <Section title="11. Security">
        <P>We implement appropriate technical and organisational measures to protect your personal data against unauthorised access, alteration, disclosure, or destruction. These include:</P>
        <Ul items={[
          'All data transmitted over HTTPS with TLS encryption',
          'Authentication delegated to Clerk — we do not store passwords',
          'Database and server access restricted to authorised personnel only',
          'Regular dependency updates and security patching',
          'Error monitoring via Sentry to detect anomalies promptly',
        ]} />
        <P>No method of transmission over the internet or electronic storage is 100% secure. While we strive to use commercially acceptable means to protect your data, we cannot guarantee absolute security. In the event of a data breach that poses a risk to your rights, we will notify you and relevant authorities as required by applicable law.</P>
      </Section>

      <Section title="12. Children's Privacy">
        <P>RoStealth is not directed at children under the age of 13. We do not knowingly collect personal data from children under 13. If we become aware that a child under 13 has provided us with personal data, we will delete it promptly. If you believe a child under 13 has created an account, contact us at <span style={{ color: 'var(--p4)' }}>privacy@rostealth.site</span>.</P>
      </Section>

      <Section title="13. Changes to This Policy">
        <P>We may update this Privacy Policy from time to time to reflect changes in our practices, technology, legal requirements, or other factors. We will provide at least 14 days' advance notice of material changes via email to your registered address or via an in-app notice. The "Last updated" date at the top of this page reflects the date of the most recent revision.</P>
        <P>Your continued use of the Service after the effective date constitutes acceptance of the updated Privacy Policy.</P>
      </Section>

      <Section title="14. Contact">
        <P>For any privacy-related questions, requests, or complaints:</P>
        <P><span style={{ color: 'var(--p4)' }}>privacy@rostealth.site</span></P>
        <P>We aim to respond to all privacy enquiries within 30 days.</P>
      </Section>
    </div>
  </LegalShell>
);

Object.assign(window, { TermsPage, PrivacyPage });
