<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <title>Today News — Daily Current Affairs & Top Headlines</title>

  <style>

    :root {

      --bg: #f8fafc;

      --card: #ffffff;

      --text: #0f172a;

      --muted: #64748b;

      --accent: #b91c1c;

      --border: #e2e8f0;

    }

    * { box-sizing: border-box; margin: 0; padding: 0; }

    body {

      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

      background: var(--bg);

      color: var(--text);

      line-height: 1.6;

      padding-bottom: 40px;

    }

    header {

      background: #111827;

      color: #fff;

      padding: 16px 20px;

      border-bottom: 3px solid var(--accent);

      position: sticky;

      top: 0;

      z-index: 10;

    }

    .header-top {

      max-width: 820px;

      margin: 0 auto;

      display: flex;

      justify-content: space-between;

      align-items: center;

      gap: 10px;

    }

    .brand {

      font-size: 1.4rem;

      font-weight: 800;

      letter-spacing: -0.5px;

      cursor: pointer;

      user-select: none;

    }

    .brand span { color: #f87171; }

    .date-line {

      font-size: 0.78rem;

      color: #9ca3af;

      margin-top: 2px;

    }

    .refresh-btn {

      background: #1f2937;

      color: #e5e7eb;

      border: 1px solid #374151;

      padding: 6px 12px;

      border-radius: 6px;

      font-size: 0.8rem;

      cursor: pointer;

    }

    .refresh-btn:active { background: #374151; }

    .tabs {

      max-width: 820px;

      margin: 12px auto 0;

      display: flex;

      gap: 8px;

      overflow-x: auto;

      padding-bottom: 4px;

    }

    .tab {

      background: #1f2937;

      color: #d1d5db;

      border: none;

      padding: 6px 14px;

      border-radius: 20px;

      font-size: 0.82rem;

      cursor: pointer;

      white-space: nowrap;

    }

    .tab.active {

      background: var(--accent);

      color: #fff;

      font-weight: 600;

    }

    main {

      max-width: 820px;

      margin: 20px auto;

      padding: 0 16px;

    }

    .status-bar {

      font-size: 0.8rem;

      color: var(--muted);

      margin-bottom: 14px;

      display: flex;

      justify-content: space-between;

      align-items: center;

    }

    .news-grid {

      display: grid;

      gap: 14px;

    }

    .news-card {

      background: var(--card);

      border: 1px solid var(--border);

      border-radius: 10px;

      padding: 16px;

      box-shadow: 0 1px 2px rgba(0,0,0,0.03);

    }

    .news-meta {

      font-size: 0.75rem;

      color: var(--accent);

      font-weight: 600;

      text-transform: uppercase;

      margin-bottom: 6px;

    }

    .news-title {

      font-size: 1.05rem;

      font-weight: 700;

      margin-bottom: 6px;

      color: var(--text);

    }

    .news-title a {

      text-decoration: none;

      color: inherit;

    }

    .news-title a:hover { color: var(--accent); }

    .news-desc {

      font-size: 0.88rem;

      color: #475569;

    }

    /* Setup Modal */

    .setup-box {

      display: none;

      background: #fffbeb;

      border: 1px solid #f59e0b;

      border-radius: 10px;

      padding: 16px;

      margin-bottom: 18px;

    }

    .setup-box h3 { font-size: 1rem; margin-bottom: 8px; color: #92400e; }

    .setup-box label { display: block; font-size: 0.8rem; font-weight: 600; margin-top: 8px; color: #78350f; }

    .setup-box input {

      width: 100%;

      padding: 8px 10px;

      margin-top: 4px;

      border: 1px solid #d97706;

      border-radius: 6px;

      font-size: 0.9rem;

    }

    .setup-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

    .btn-primary {

      background: #111827;

      color: #fff;

      border: none;

      padding: 8px 14px;

      border-radius: 6px;

      font-size: 0.85rem;

      cursor: pointer;

    }

    .generated-url {

      margin-top: 10px;

      padding: 8px;

      background: #fff;

      border: 1px dashed #d97706;

      border-radius: 6px;

      font-size: 0.78rem;

      word-break: break-all;

      display: none;

    }

    /* Reader Tip (Inbox) */

    .tip-section {

      margin-top: 28px;

      background: var(--card);

      border: 1px solid var(--border);

      border-radius: 10px;

      padding: 16px;

    }

    .tip-toggle {

      background: none;

      border: none;

      color: var(--muted);

      font-size: 0.85rem;

      font-weight: 600;

      cursor: pointer;

      display: flex;

      align-items: center;

      gap: 6px;

    }

    .tip-form {

      display: none;

      margin-top: 12px;

    }

    .tip-form textarea {

      width: 100%;

      height: 80px;

      padding: 10px;

      border: 1px solid #cbd5e1;

      border-radius: 8px;

      font-family: inherit;

      font-size: 0.9rem;

      resize: none;

    }

    .tip-footer {

      display: flex;

      justify-content: space-between;

      align-items: center;

      margin-top: 8px;

    }

    .tip-status { font-size: 0.8rem; color: #059669; }

    /* Footer & Disguised Outbox Trigger */

    footer {

      max-width: 820px;

      margin: 28px auto 0;

      padding: 16px;

      border-top: 1px solid var(--border);

      text-align: center;

      font-size: 0.78rem;

      color: var(--muted);

    }

    .disguised-trigger {

      cursor: pointer;

      user-select: none;

      text-decoration: underline dotted;

    }

    .hidden-reply-box {

      display: none;

      margin: 12px auto 0;

      max-width: 560px;

      background: #f1f5f9;

      border: 1px solid #cbd5e1;

      border-radius: 8px;

      padding: 12px;

      text-align: left;

      color: #0f172a;

      font-size: 0.88rem;

    }

    .hidden-reply-header {

      font-size: 0.72rem;

      color: #64748b;

      margin-bottom: 4px;

      display: flex;

      justify-content: space-between;

    }

  </style>

</head>

<body>

  <header>

    <div class="header-top">

      <div>

        <div class="brand" id="brandTitle">Today <span>News</span></div>

        <div class="date-line" id="todayDate">Loading live edition...</div>

      </div>

      <button class="refresh-btn" id="panicRefreshBtn">Refresh Feed</button>

    </div>

    <div class="tabs">

      <button class="tab active" data-feed="top">Top Headlines</button>

      <button class="tab" data-feed="india">National / भारत</button>

      <button class="tab" data-feed="tech">Economy & Tech</button>

      <button class="tab" data-feed="world">World Affairs</button>

    </div>

  </header>

  <main>

    <!-- Hidden Channel Relay Setup (Triple-Tap "Today News") -->

    <div class="setup-box" id="setupBox">

      <h3>Editorial Relay Configuration</h3>

      <p style="font-size:0.78rem;color:#78350f;">Configure ntfy.sh topics to generate a self-contained shareable link.</p>

      <label>Inbox Topic (Receive Reader Tips):</label>

      <input type="text" id="inTopic" placeholder="e.g. ind_weather_bulletin_84920" />

      <label>Outbox Topic (Publish Editorial Notes):</label>

      <input type="text" id="outTopic" placeholder="e.g. ind_market_updates_39104" />

      <div class="setup-actions">

        <button class="btn-primary" id="genLinkBtn">Generate Permanent Link</button>

        <button class="refresh-btn" id="closeSetupBtn">Close</button>

      </div>

      <div class="generated-url" id="generatedUrlBox"></div>

    </div>

    <div class="status-bar">

      <span id="feedLabel">Live Feed • Top Headlines</span>

      <span id="syncStatus">Updating...</span>

    </div>

    <div class="news-grid" id="newsContainer"></div>

    <!-- Disguised Inbox -->

    <div class="tip-section">

      <button class="tip-toggle" id="toggleTipBtn">+ Submit Reader Tip / Correction</button>

      <div class="tip-form" id="tipForm">

        <textarea id="tipInput" placeholder="Write news tip, source note, or feedback..."></textarea>

        <div class="tip-footer">

          <span class="tip-status" id="tipStatus"></span>

          <button class="btn-primary" id="sendTipBtn">Send Note</button>

        </div>

      </div>

    </div>

  </main>

  <footer>

    <div>© 2026 Today News Digital Network • ISSN: 2584-9102</div>

    <div style="margin-top:6px;">

      About Us • Privacy Policy • <span class="disguised-trigger" id="editorialTrigger">Editorial Guidelines</span> • Contact Desk

    </div>

    <!-- Disguised Outbox Viewer (Double-Tap "Editorial Guidelines") -->

    <div class="hidden-reply-box" id="hiddenReplyBox">

      <div class="hidden-reply-header">

        <span>EDITORIAL REVISION NOTE</span>

        <span id="replyTime"></span>

      </div>

      <div id="replyContent">Checking latest revision...</div>

    </div>

  </footer>

  <script>

    // Date display

    const dateEl = document.getElementById('todayDate');

    const now = new Date();

    dateEl.textContent = now.toLocaleDateString('en-IN', {

      weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'

    }) + ' • Live Digital Edition';

    // Decode channel config from URL hash (#c=base64)

    let config = { in: '', out: '' };

    function loadConfigFromHash() {

      try {

        const hash = window.location.hash;

        if (hash && hash.startsWith('#c=')) {

          const decoded = JSON.parse(atob(decodeURIComponent(hash.slice(3))));

          config.in = decoded.in || '';

          config.out = decoded.out || '';

        }

      } catch (e) {}

    }

    loadConfigFromHash();

    // Triple-tap title for setup

    let tapCount = 0;

    let tapTimer = null;

    document.getElementById('brandTitle').addEventListener('click', () => {

      tapCount++;

      clearTimeout(tapTimer);

      tapTimer = setTimeout(() => { tapCount = 0; }, 700);

      if (tapCount >= 3) {

        tapCount = 0;

        document.getElementById('inTopic').value = config.in;

        document.getElementById('outTopic').value = config.out;

        document.getElementById('setupBox').style.display = 'block';

      }

    });

    document.getElementById('closeSetupBtn').addEventListener('click', () => {

      document.getElementById('setupBox').style.display = 'none';

    });

    document.getElementById('genLinkBtn').addEventListener('click', () => {

      const inVal = document.getElementById('inTopic').value.trim();

      const outVal = document.getElementById('outTopic').value.trim();

      config = { in: inVal, out: outVal };

      const payload = encodeURIComponent(btoa(JSON.stringify(config)));

      const fullUrl = window.location.origin + window.location.pathname + '#c=' + payload;

      window.location.hash = 'c=' + payload;

      const box = document.getElementById('generatedUrlBox');

      box.style.display = 'block';

      box.innerHTML = '<strong>Permanent Link (Copy & Share):</strong><br>' + fullUrl;

      if (navigator.clipboard) {

        navigator.clipboard.writeText(fullUrl).catch(() => {});

      }

    });

    // Live RSS Feeds via rss2json public bridge with fallback

    const feeds = {

      top: 'https://news.google.com/rss?hl=en-IN&gl=IN&ceid=IN:en',

      india: 'https://news.google.com/rss/headlines/section/topic/NATION.en_in/India?hl=en-IN&gl=IN&ceid=IN:en',

      tech: 'https://news.google.com/rss/headlines/section/topic/BUSINESS.en_in/Business?hl=en-IN&gl=IN&ceid=IN:en',

      world: 'https://news.google.com/rss/headlines/section/topic/WORLD.en_in/World?hl=en-IN&gl=IN&ceid=IN:en'

    };

    const fallbackNews = [

      { title: 'Parliament Winter Session: Key Economic & Digital Infrastructure Bills Listed for Discussion', source: 'National Desk', desc: 'Lawmakers prepare for debates covering financial inclusion, telecom modernization, and public digital infrastructure.' },

      { title: 'RBI Monetary Policy Committee Reviews Liquidity Conditions Amid Steady Domestic Growth', source: 'Economy Bureau', desc: 'Analysts expect continued focus on inflation management and banking sector resilience across urban and rural markets.' },

      { title: 'ISRO Announces Next Phase of Satellite Launch Schedule for Earth Observation & Navigation', source: 'Science & Tech', desc: 'Upcoming missions aim to strengthen weather forecasting accuracy and disaster response systems.' },

      { title: 'Global Clean Energy Investment Reaches New Milestone as Solar Grid Capacity Expands', source: 'World Affairs', desc: 'Renewable energy adoption accelerates across Asia and Europe driven by lower storage costs.' }

    ];

    async function loadNews(category = 'top') {

      const container = document.getElementById('newsContainer');

      const status = document.getElementById('syncStatus');

      status.textContent = 'Syncing live headlines...';

      try {

        const rssUrl = encodeURIComponent(feeds[category] || feeds.top);

        const res = await fetch(`https://api.rss2json.com/v1/api.json?rss_url=${rssUrl}`);

        const data = await res.json();

        if (data.status === 'ok' && data.items && data.items.length > 0) {

          container.innerHTML = data.items.slice(0, 10).map(item => {

            const cleanDesc = (item.description || '').replace(/<[^>]*>?/gm, '').slice(0, 160);

            const pubTime = item.pubDate ? new Date(item.pubDate).toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit' }) : 'Today';

            return `

              <article class="news-card">

                <div class="news-meta">${item.author || 'Wire Desk'} • ${pubTime}</div>

                <h2 class="news-title"><a href="${item.link}" target="_blank" rel="noopener noreferrer">${item.title}</a></h2>

                <p class="news-desc">${cleanDesc ? cleanDesc + '...' : 'Click headline to read full wire report.'}</p>

              </article>

            `;

          }).join('');

          status.textContent = 'Live • Updated just now';

          return;

        }

        throw new Error('Fallback');

      } catch (err) {

        container.innerHTML = fallbackNews.map(item => `

          <article class="news-card">

            <div class="news-meta">${item.source} • Featured</div>

            <h2 class="news-title">${item.title}</h2>

            <p class="news-desc">${item.desc}</p>

          </article>

        `).join('');

        status.textContent = 'Edition Cached';

      }

    }

    document.querySelectorAll('.tab').forEach(btn => {

      btn.addEventListener('click', () => {

        document.querySelectorAll('.tab').forEach(b => b.classList.remove('active'));

        btn.classList.add('active');

        document.getElementById('feedLabel').textContent = 'Live Feed • ' + btn.textContent;

        loadNews(btn.dataset.feed);

      });

    });

    // Inbox: Toggle & Send Tip

    const tipForm = document.getElementById('tipForm');

    const tipInput = document.getElementById('tipInput');

    const tipStatus = document.getElementById('tipStatus');

    document.getElementById('toggleTipBtn').addEventListener('click', () => {

      tipForm.style.display = tipForm.style.display === 'block' ? 'none' : 'block';

    });

    document.getElementById('sendTipBtn').addEventListener('click', async () => {

      const msg = tipInput.value.trim();

      if (!msg) return;

      tipInput.value = '';

      tipStatus.textContent = 'Sending...';

      if (!config.in) {

        tipStatus.textContent = 'Note cleared (No relay linked).';

        setTimeout(() => { tipStatus.textContent = ''; tipForm.style.display = 'none'; }, 1500);

        return;

      }

      try {

        await fetch(`https://ntfy.sh/${encodeURIComponent(config.in)}`, {

          method: 'POST',

          body: msg,

          headers: { 'Title': 'News Alert' }

        });

        tipStatus.textContent = 'Submitted & cleared.';

      } catch (e) {

        tipStatus.textContent = 'Cleared.';

      }

      setTimeout(() => {

        tipStatus.textContent = '';

        tipForm.style.display = 'none';

      }, 1400);

    });

    // Outbox: Double-tap "Editorial Guidelines" to reveal, Single-tap to hide

    const editorialTrigger = document.getElementById('editorialTrigger');

    const hiddenReplyBox = document.getElementById('hiddenReplyBox');

    const replyContent = document.getElementById('replyContent');

    const replyTime = document.getElementById('replyTime');

    let edTapCount = 0;

    let edTapTimer = null;

    editorialTrigger.addEventListener('click', async () => {

      if (hiddenReplyBox.style.display === 'block') {

        hiddenReplyBox.style.display = 'none';

        replyContent.textContent = '';

        return;

      }

      edTapCount++;

      clearTimeout(edTapTimer);

      edTapTimer = setTimeout(() => { edTapCount = 0; }, 500);

      if (edTapCount >= 2) {

        edTapCount = 0;

        hiddenReplyBox.style.display = 'block';

        replyContent.textContent = 'Loading revision note...';

        if (!config.out) {

          replyContent.textContent = 'No editorial outbox configured.';

          return;

        }

        try {

          const res = await fetch(`https://ntfy.sh/${encodeURIComponent(config.out)}/json?poll=1&since=24h`);

          const text = await res.text();

          const lines = text.trim().split('\n').filter(Boolean);

          const messages = lines.map(l => JSON.parse(l)).filter(m => m.event === 'message');

          if (messages.length > 0) {

            const latest = messages[messages.length - 1];

            replyContent.textContent = latest.message;

            replyTime.textContent = new Date(latest.time * 1000).toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit' });

          } else {

            replyContent.textContent = 'No recent editorial updates.';

            replyTime.textContent = '';

          }

        } catch (e) {

          replyContent.textContent = 'Unable to fetch revision note.';

        }

      }

    });

    // Panic Wipe on Refresh Button or Tab Switch / Screen Lock

    function wipeAll() {

      tipInput.value = '';

      tipForm.style.display = 'none';

      tipStatus.textContent = '';

      hiddenReplyBox.style.display = 'none';

      replyContent.textContent = '';

      document.getElementById('setupBox').style.display = 'none';

    }

    document.getElementById('panicRefreshBtn').addEventListener('click', () => {

      wipeAll();

      loadNews('top');

    });

    document.addEventListener('visibilitychange', () => {

      if (document.hidden) wipeAll();

    });

    loadNews('top');

  </script>

</body>

</html>