<?php require_once 'includes/config.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Privacy Policy — <?= SITE_NAME ?></title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@700;800;900&family=Poppins:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="<?= SITE_URL ?>/assets/css/style.css">
<link rel="icon" type="image/png" href="https://studytrack.edurx.icu/studytrack/images/studytrack.png">
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth}
body{background:#08080f;color:#e2e8f0;font-family:'Poppins',sans-serif;overflow-x:hidden}
a{text-decoration:none;color:inherit}
:root{--vi:#7c6af0;--vi2:#a78bfa;--cy:#22d3ee;--card:#13131f;--card2:#1a1a2e;--border:rgba(255,255,255,.07);--border2:rgba(255,255,255,.12);--ink:#e2e8f0;--ink-dim:#94a3b8;--ink-ghost:#475569;--glow-vi:rgba(124,106,240,.35);--r:14px;--r2:20px}
/* NAV */
.nav{position:sticky;top:0;z-index:999;background:rgba(8,8,15,.92);backdrop-filter:blur(20px);border-bottom:1px solid var(--border);padding:0 24px}
.nav-inner{max-width:1100px;margin:0 auto;display:flex;align-items:center;justify-content:space-between;height:68px}
.nav-logo{display:flex;align-items:center;gap:10px}
.nav-logo img{width:34px;height:34px;border-radius:9px}
.nav-logo-text{font-family:'Nunito',sans-serif;font-size:18px;font-weight:800;background:linear-gradient(135deg,#fff 30%,var(--vi2));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
.nav-logo-by{font-size:9px;font-weight:500;color:var(--ink-ghost);letter-spacing:.5px;text-transform:uppercase;display:block;line-height:1}
.nav-links{display:flex;align-items:center;gap:4px}
.nav-links a{padding:7px 14px;border-radius:9px;font-size:14px;font-weight:500;color:var(--ink-dim);transition:all .2s}
.nav-links a:hover{color:var(--ink);background:rgba(255,255,255,.05)}
.nav-pill{background:linear-gradient(135deg,var(--vi),#9333ea)!important;color:#fff!important;box-shadow:0 0 24px var(--glow-vi);font-weight:600!important}
/* HERO */
.legal-hero{padding:72px 24px 52px;text-align:center;position:relative;overflow:hidden;background:linear-gradient(180deg,rgba(34,211,238,.07) 0%,transparent 100%);border-bottom:1px solid var(--border)}
.legal-eyebrow{display:inline-block;font-size:12px;font-weight:700;color:var(--cy);text-transform:uppercase;letter-spacing:2px;margin-bottom:16px}
.legal-title{font-family:'Nunito',sans-serif;font-size:clamp(30px,5vw,48px);font-weight:900;color:var(--ink);letter-spacing:-.5px;margin-bottom:14px}
.legal-title span{background:linear-gradient(110deg,var(--cy),var(--vi2));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
.legal-sub{font-size:15px;color:var(--ink-dim);line-height:1.75;max-width:560px;margin:0 auto 22px}
.legal-meta{display:flex;gap:20px;justify-content:center;flex-wrap:wrap;font-size:12px;color:var(--ink-ghost)}
/* PRIVACY SUMMARY CARDS */
.priv-summary{background:var(--card2);border-top:1px solid var(--border);border-bottom:1px solid var(--border);padding:32px 24px}
.priv-summary-inner{max-width:900px;margin:0 auto;display:grid;grid-template-columns:repeat(4,1fr);gap:16px}
.priv-sc{background:var(--card);border:1px solid var(--border2);border-radius:var(--r2);padding:20px;text-align:center}
.priv-sc-icon{width:44px;height:44px;border-radius:13px;display:flex;align-items:center;justify-content:center;font-size:20px;margin:0 auto 12px}
.priv-sc h4{font-family:'Nunito',sans-serif;font-size:14px;font-weight:800;color:var(--ink);margin-bottom:6px}
.priv-sc p{font-size:12px;color:var(--ink-ghost);line-height:1.6}
/* LEGAL BODY */
.legal-wrap{max-width:1060px;margin:0 auto;padding:48px 24px 100px;display:grid;grid-template-columns:200px 1fr;gap:32px;align-items:start}
.toc-panel{position:sticky;top:88px;background:var(--card);border:1px solid var(--border2);border-radius:var(--r2);padding:20px 16px;overflow:hidden}
.toc-panel::before{content:'';position:absolute;top:0;left:0;right:0;height:3px;background:linear-gradient(90deg,var(--cy),var(--vi2))}
.toc-heading{font-size:10px;font-weight:700;letter-spacing:1.5px;text-transform:uppercase;color:var(--ink-ghost);margin-bottom:13px}
.toc-list{list-style:none;display:flex;flex-direction:column;gap:1px}
.toc-list a{display:block;padding:7px 10px;border-radius:8px;font-size:12px;color:var(--ink-ghost);transition:all .18s;line-height:1.4}
.toc-list a:hover{color:var(--cy);background:rgba(34,211,238,.08);padding-left:14px}
.toc-list a.active{color:var(--cy);background:rgba(34,211,238,.09);font-weight:600}
.legal-body{min-width:0;display:flex;flex-direction:column;gap:12px}
.legal-section{background:var(--card);border:1px solid var(--border2);border-radius:var(--r2);padding:30px;transition:border-color .2s;scroll-margin-top:100px}
.legal-section:hover{border-color:rgba(34,211,238,.2)}
.sec-top{display:flex;align-items:center;gap:13px;margin-bottom:18px}
.sec-badge{width:36px;height:36px;border-radius:11px;flex-shrink:0;background:rgba(34,211,238,.08);border:1px solid rgba(34,211,238,.18);display:flex;align-items:center;justify-content:center;font-size:17px}
.sec-title{font-family:'Nunito',sans-serif;font-size:17px;font-weight:800;color:var(--ink)}
.legal-section p{font-size:14px;line-height:1.85;color:var(--ink-dim);margin-bottom:12px}
.legal-section p:last-child{margin-bottom:0}
.legal-section ul{list-style:none;display:flex;flex-direction:column;gap:8px;margin:12px 0}
.legal-section ul li{font-size:14px;line-height:1.75;color:var(--ink-dim);padding-left:20px;position:relative}
.legal-section ul li::before{content:'';position:absolute;left:2px;top:9px;width:7px;height:7px;border-radius:50%;background:linear-gradient(135deg,var(--cy),var(--vi2));opacity:.75}
.note{background:rgba(34,211,238,.06);border:1px solid rgba(34,211,238,.18);border-left:3px solid var(--cy);border-radius:10px;padding:13px 15px;margin:13px 0;font-size:13px;line-height:1.7;color:var(--ink-dim)}
.warn{background:rgba(245,158,11,.07);border:1px solid rgba(245,158,11,.18);border-left:3px solid #f59e0b;border-radius:10px;padding:13px 15px;margin:13px 0;display:flex;gap:9px;align-items:flex-start;font-size:13px;line-height:1.7;color:var(--ink-dim)}
.warn-icon{font-size:15px;flex-shrink:0;margin-top:1px}
strong.hi{color:var(--ink)}
/* Data table */
.data-table-wrap{width:100%;overflow-x:auto;border-radius:10px;margin:14px 0}
.data-table{width:100%;min-width:480px;border-collapse:collapse;font-size:13px}
.data-table thead tr{background:rgba(34,211,238,.06)}
.data-table th{padding:10px 13px;text-align:left;font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.6px;color:var(--ink-dim);border-bottom:1px solid var(--border2)}
.data-table td{padding:11px 13px;color:var(--ink-dim);border-bottom:1px solid var(--border);vertical-align:top;line-height:1.6}
.data-table tr:last-child td{border-bottom:none}
/* FOOTER */
.st-footer{background:#0f0f1a;border-top:1px solid var(--border);padding:48px 24px 24px}
.st-footer-inner{max-width:1100px;margin:0 auto}
.st-footer-grid{display:grid;grid-template-columns:1.6fr repeat(3,1fr);gap:40px;margin-bottom:36px}
.st-footer-desc{font-size:13px;color:var(--ink-ghost);line-height:1.75;margin-top:12px;max-width:220px}
.st-footer-col h5{font-size:11px;font-weight:700;color:var(--ink-ghost);text-transform:uppercase;letter-spacing:1.5px;margin-bottom:13px}
.st-footer-col a{display:block;font-size:13px;color:var(--ink-dim);margin-bottom:8px;transition:color .15s}
.st-footer-col a:hover{color:var(--vi2)}
.st-footer-bottom{border-top:1px solid var(--border);padding-top:20px;display:flex;align-items:center;justify-content:space-between;font-size:12px;color:var(--ink-ghost);flex-wrap:wrap;gap:8px}
@media(max-width:780px){.legal-wrap{grid-template-columns:1fr}.toc-panel{display:none}.priv-summary-inner{grid-template-columns:1fr 1fr}}
@media(max-width:768px){.nav-links{display:none!important}.st-footer-grid{grid-template-columns:1fr 1fr}}
@media(max-width:480px){.st-footer-grid{grid-template-columns:1fr}.priv-summary-inner{grid-template-columns:1fr}}
</style>
</head>
<body>

<nav class="nav">
  <div class="nav-inner">
    <a href="<?= SITE_URL ?>/home" class="nav-logo">
      <img src="https://studytrack.edurx.icu/studytrack/images/studytrack.png" alt="StudyTrack">
      <div><div class="nav-logo-text">StudyTrack</div><span class="nav-logo-by">by EduRx</span></div>
    </a>
    <div class="nav-links">
      <?php if(isLoggedIn()): ?>
        <a href="<?= SITE_URL ?>/dashboard">Dashboard</a>
        <a href="<?= SITE_URL ?>/logout">Sign Out</a>
      <?php else: ?>
        <a href="<?= SITE_URL ?>/login">Sign In</a>
        <a href="<?= SITE_URL ?>/register" class="nav-pill">Get Started Free</a>
      <?php endif; ?>
    </div>
  </div>
</nav>

<div class="legal-hero">
  <div class="legal-eyebrow">🔒 Privacy</div>
  <h1 class="legal-title">Privacy <span>Policy</span></h1>
  <p class="legal-sub">Your data belongs to you. This policy explains exactly what we collect, how we use it, and the rights you hold. We believe in full transparency.</p>
  <div class="legal-meta">
    <span>📅 Effective: January 1, 2025</span>
    <span>🔄 Updated: March 1, 2026</span>
    <span>⏱️ 6 min read</span>
  </div>
</div>

<!-- Summary cards -->
<div class="priv-summary">
  <div class="priv-summary-inner">
    <div class="priv-sc">
      <div class="priv-sc-icon" style="background:rgba(16,185,129,.1)">🚫</div>
      <h4>We Never Sell Data</h4>
      <p>Your personal data is never sold or shared with advertisers.</p>
    </div>
    <div class="priv-sc">
      <div class="priv-sc-icon" style="background:rgba(124,106,240,.1)">🔒</div>
      <h4>Passwords Hashed</h4>
      <p>Stored with bcrypt — your password is never readable.</p>
    </div>
    <div class="priv-sc">
      <div class="priv-sc-icon" style="background:rgba(34,211,238,.1)">🍃</div>
      <h4>Zero Trackers</h4>
      <p>No cookies, no analytics, no ads. Ever.</p>
    </div>
    <div class="priv-sc">
      <div class="priv-sc-icon" style="background:rgba(245,158,11,.1)">🗑️</div>
      <h4>Full Deletion</h4>
      <p>Request complete data removal at any time.</p>
    </div>
  </div>
</div>

<div class="legal-wrap">
  <aside class="toc-panel" aria-label="Table of contents">
    <div class="toc-heading">Contents</div>
    <ul class="toc-list">
      <li><a href="#p1">1. Overview</a></li>
      <li><a href="#p2">2. Data We Collect</a></li>
      <li><a href="#p3">3. How We Use Data</a></li>
      <li><a href="#p4">4. Data Sharing</a></li>
      <li><a href="#p5">5. Security</a></li>
      <li><a href="#p6">6. Cookies</a></li>
      <li><a href="#p7">7. Your Rights</a></li>
      <li><a href="#p8">8. Children's Privacy</a></li>
      <li><a href="#p9">9. Data Retention</a></li>
      <li><a href="#p10">10. Policy Changes</a></li>
      <li><a href="#p11">11. Contact Us</a></li>
    </ul>
  </aside>

  <div class="legal-body">
    <div class="legal-section" id="p1">
      <div class="sec-top"><div class="sec-badge">📋</div><div class="sec-title">1. Overview</div></div>
      <p><strong class="hi"><?= SITE_NAME ?></strong> is committed to protecting your privacy. This Privacy Policy describes how we collect, use, and safeguard information when you use our free A/L study tracking platform, designed specifically for Sri Lankan students.</p>
      <p>We collect only the minimum data necessary to provide you with a personalised and functional study tracking experience. We do not monetise your data in any way.</p>
      <div class="note">🇱🇰 <?= SITE_NAME ?> is operated from Sri Lanka and complies with applicable data protection principles. For any privacy concerns, please contact us directly.</div>
    </div>
    <div class="legal-section" id="p2">
      <div class="sec-top"><div class="sec-badge">📊</div><div class="sec-title">2. Data We Collect</div></div>
      <p>We collect two types of information: data you provide directly when registering and using the platform, and data generated automatically through your activity.</p>
      <div class="data-table-wrap">
        <table class="data-table">
          <thead><tr><th>Data Type</th><th>What We Collect</th><th>Purpose</th></tr></thead>
          <tbody>
            <tr><td><strong class="hi">Account</strong></td><td>Name, email, bcrypt-hashed password</td><td>Account creation and authentication</td></tr>
            <tr><td><strong class="hi">Study Data</strong></td><td>Sessions, subjects, durations, notes</td><td>Study tracking and analytics</td></tr>
            <tr><td><strong class="hi">Exam Results</strong></td><td>Marks, exam names, dates</td><td>Performance analytics and charts</td></tr>
            <tr><td><strong class="hi">Tasks</strong></td><td>Titles, descriptions, due dates</td><td>Task management features</td></tr>
            <tr><td><strong class="hi">Activity</strong></td><td>Login timestamps, streak data</td><td>Platform improvement</td></tr>
          </tbody>
        </table>
      </div>
      <p>We do <strong class="hi">not</strong> collect or store card, bank account, or mobile wallet details, device location, camera or microphone data, or any sensitive personal information beyond what is listed above. If you subscribe to <?= SITE_NAME ?> Pro, your payment is handled entirely by PayHere — see Section 4 below.</p>
    </div>
    <div class="legal-section" id="p3">
      <div class="sec-top"><div class="sec-badge">⚙️</div><div class="sec-title">3. How We Use Your Data</div></div>
      <p>Your data is used exclusively to operate and improve <?= SITE_NAME ?>. We use it to:</p>
      <ul>
        <li>Authenticate you and maintain your secure login session</li>
        <li>Store and display your study sessions, marks, subjects, and tasks</li>
        <li>Generate personalised charts, analytics, and progress reports</li>
        <li>Calculate study streaks, daily goals, and heatmap data</li>
        <li>Send OTP verification and password reset emails when requested</li>
        <li>Display A/L exam countdowns and admin announcements</li>
        <li>Improve platform features using anonymised, aggregated usage patterns</li>
      </ul>
      <p style="margin-top:14px">We will <strong class="hi">never</strong> use your data to send marketing emails, build advertising profiles, or share individual data with any third party for commercial purposes.</p>
    </div>
    <div class="legal-section" id="p4">
      <div class="sec-top"><div class="sec-badge">🤝</div><div class="sec-title">4. Data Sharing</div></div>
      <p>We do not sell, rent, or trade your personal data to anyone. We share data only in these strictly limited circumstances:</p>
      <ul>
        <li><strong class="hi">Email delivery (Brevo SMTP):</strong> Your email address is passed to Brevo's transactional email service solely to deliver OTP and password reset messages. They receive no academic data.</li>
        <li><strong class="hi">Payment processing (PayHere):</strong> If you purchase a Pro subscription, your name, email, and the order details (plan, amount) are passed to PayHere, a licensed Sri Lankan payment gateway, to process your payment. Your card, bank, or wallet details are entered directly on PayHere's secure checkout page and are never seen or stored by <?= SITE_NAME ?>. PayHere confirms successful payments back to us so we can activate your Pro access.</li>
        <li><strong class="hi">Legal requirements:</strong> We may disclose data if required by valid Sri Lankan legal process.</li>
        <li><strong class="hi">Platform transfer:</strong> If ownership of the platform changes, all users will be notified at least 30 days in advance.</li>
      </ul>
      <div class="note">📧 Brevo is used only for transactional email (OTP codes, password resets). They do not receive your study data, marks, or tasks under any circumstances.</div>
      <div class="note">💳 PayHere only receives what's needed to process a Pro subscription payment (name, email, order amount). They do not receive your study sessions, marks, notes, or tasks.</div>
    </div>
    <div class="legal-section" id="p5">
      <div class="sec-top"><div class="sec-badge">🔐</div><div class="sec-title">5. Data Security</div></div>
      <p>We implement multiple technical safeguards to protect your data:</p>
      <ul>
        <li>Passwords are hashed using <strong class="hi">bcrypt</strong> (cost factor 12) and are never stored in plain text</li>
        <li>Email OTP verification is required before any account becomes active</li>
        <li>Password reset tokens expire after 1 hour and are single-use only</li>
        <li>All database queries use prepared statements to prevent SQL injection</li>
        <li>PHP native session handling with server-side session storage</li>
        <li>Input sanitisation applied to all user-submitted data</li>
      </ul>
      <div class="warn"><span class="warn-icon">⚠️</span><span>While we implement strong security practices, no online system is completely immune to threats. We encourage you to use a unique, strong password and to log out when using shared or public devices.</span></div>
    </div>
    <div class="legal-section" id="p6">
      <div class="sec-top"><div class="sec-badge">🍃</div><div class="sec-title">6. Cookies &amp; Tracking</div></div>
      <p><?= SITE_NAME ?> uses an absolute minimum approach to cookies:</p>
      <ul>
        <li><strong class="hi">Session cookie only:</strong> A single PHP session cookie keeps you logged in during your browser session. This contains only a random session ID — no personal data whatsoever.</li>
      </ul>
      <p>We do not use tracking cookies, analytics tools (Google Analytics, Hotjar, etc.), advertising networks (Google Ads, Facebook Pixel, etc.), or any third-party tracking scripts of any kind.</p>
      <div class="note">🚫 <?= SITE_NAME ?> is completely ad-free and tracker-free. We do not track your behaviour, sell your browsing data, or monetise your usage in any way.</div>
    </div>
    <div class="legal-section" id="p7">
      <div class="sec-top"><div class="sec-badge">⚖️</div><div class="sec-title">7. Your Rights</div></div>
      <p>You have the following rights regarding your personal data at all times:</p>
      <ul>
        <li><strong class="hi">Access:</strong> View all your data directly in your dashboard at any time — no request needed</li>
        <li><strong class="hi">Correction:</strong> Update your name and password in the Profile page at any time</li>
        <li><strong class="hi">Deletion:</strong> Delete individual sessions, marks, subjects, and tasks directly in the platform. For full account deletion, contact us.</li>
        <li><strong class="hi">Portability:</strong> Contact us to request a structured export of all your study data</li>
        <li><strong class="hi">Objection:</strong> Object to any data processing by contacting us — we will respond within 14 days</li>
      </ul>
      <p>To exercise any of these rights, contact us at <a href="mailto:support@studytrack.lk" style="color:var(--cy)">support@studytrack.lk</a>.</p>
    </div>
    <div class="legal-section" id="p8">
      <div class="sec-top"><div class="sec-badge">🎓</div><div class="sec-title">8. Children's Privacy</div></div>
      <p><?= SITE_NAME ?> is specifically designed for A/L students, many of whom are under 18. We take this responsibility very seriously:</p>
      <ul>
        <li>We collect only the minimum data needed for the service to function</li>
        <li>We display no advertising to any users, including minors</li>
        <li>We never share any student's data with third parties for marketing</li>
        <li>Students under 18 should inform a parent or guardian before registering</li>
      </ul>
      <p>If you are a parent or guardian and believe your child has registered without your knowledge, please contact us and we will promptly delete the account and all associated data.</p>
    </div>
    <div class="legal-section" id="p9">
      <div class="sec-top"><div class="sec-badge">📁</div><div class="sec-title">9. Data Retention</div></div>
      <p>We retain your data for as long as your account remains active. Inactive accounts are not automatically deleted — your data persists so you can return at any time.</p>
      <p>Upon an account deletion request, the following timeline applies:</p>
      <ul>
        <li>Personal information (name, email) removed within <strong class="hi">7 days</strong></li>
        <li>Academic data (sessions, marks, tasks) removed within <strong class="hi">30 days</strong></li>
        <li>Anonymised aggregate statistics may be retained indefinitely</li>
        <li>Unverified accounts (incomplete OTP) are automatically purged after <strong class="hi">24 hours</strong></li>
      </ul>
    </div>
    <div class="legal-section" id="p10">
      <div class="sec-top"><div class="sec-badge">🔄</div><div class="sec-title">10. Policy Changes</div></div>
      <p>We may update this Privacy Policy to reflect changes in our practices or applicable legal requirements. We will update the "Updated" date at the top of this page when changes occur.</p>
      <p>For significant changes that affect your rights, we will display a notice on the platform. Continued use of <?= SITE_NAME ?> after the effective date of any changes constitutes your acceptance of the updated policy.</p>
    </div>
    <div class="legal-section" id="p11">
      <div class="sec-top"><div class="sec-badge">📬</div><div class="sec-title">11. Contact Us</div></div>
      <p>If you have questions, concerns, or requests regarding this Privacy Policy or your personal data, please contact us:</p>
      <ul>
        <li>Platform: <strong class="hi"><?= SITE_NAME ?></strong></li>
        <li>Website: <a href="<?= SITE_URL ?>/home" style="color:var(--cy)"><?= SITE_URL ?></a></li>
        <li>Email: <a href="mailto:support@edurx.icu" style="color:var(--cy)">support@edurx.icu<</a></li>
      </ul>
      <p style="margin-top:12px">We respond to all privacy-related enquiries within <strong class="hi">14 business days</strong>.</p>
      <div class="note" style="margin-top:16px">🔒 We built <?= SITE_NAME ?> to genuinely help students — not to profit from their information. Your trust means everything to us.</div>
    </div>
  </div>
</div>

<footer class="st-footer">
  <div class="st-footer-inner">
    <div class="st-footer-grid">
      <div>
        <a href="<?= SITE_URL ?>/home" class="nav-logo"><img src="https://studytrack.edurx.icu/studytrack/images/studytrack.png" alt="" style="width:30px;height:30px;border-radius:8px"><div><div class="nav-logo-text" style="font-size:16px">StudyTrack</div><span class="nav-logo-by">by EduRx</span></div></a>
        <p class="st-footer-desc">Free study tracker for Sri Lankan A/L students.</p>
      </div>
      <div class="st-footer-col"><h5>Platform</h5><a href="<?= SITE_URL ?>/register">Register</a><a href="<?= SITE_URL ?>/login">Sign In</a><a href="<?= SITE_URL ?>/home">Home</a></div>
      <div class="st-footer-col"><h5>Legal</h5><a href="<?= SITE_URL ?>/terms">Terms & Conditions</a><a href="<?= SITE_URL ?>/privacy" style="color:var(--vi2)">Privacy Policy</a><a href="<?= SITE_URL ?>/refund-policy">Refund &amp; Return Policy</a></div>
      <div class="st-footer-col"><h5>Support</h5><a href="<?= SITE_URL ?>/forgot-password">Forgot Password</a><a href="<?= SITE_URL ?>/contact">Contact Us</a></div>
    </div>
    <div class="st-footer-bottom"><span>© <?= date('Y') ?> <?= SITE_NAME ?>. All rights reserved.</span><span>Built with ❤️ for Sri Lankan A/L students</span></div>
  </div>
</footer>

<script>
(function(){
  var sections=document.querySelectorAll('.legal-section[id]');
  var links=document.querySelectorAll('.toc-list a');
  if(!sections.length) return;
  var io=new IntersectionObserver(function(entries){
    entries.forEach(function(e){
      if(!e.isIntersecting) return;
      links.forEach(function(l){l.classList.remove('active')});
      var a=document.querySelector('.toc-list a[href="#'+e.target.id+'"]');
      if(a) a.classList.add('active');
    });
  },{rootMargin:'-15% 0px -75% 0px'});
  sections.forEach(function(s){io.observe(s)});
  links.forEach(function(a){a.addEventListener('click',function(e){e.preventDefault();var t=document.querySelector(a.getAttribute('href'));if(t)t.scrollIntoView({behavior:'smooth',block:'start'})})});
})();
</script>
</body>
</html>