(or sp-) and inject the button right before it
+ new_html = re.sub(pattern, btn_html + r'\1', html)
+ with open(filepath, 'w', encoding='utf-8') as f:
+ f.write(new_html)
+
+insert_html_button('extension/popup.html', r'(
{
+ const toggleBtn = document.getElementById('ext-theme-toggle');
+
+ // Load theme from storage
+ chrome.storage.local.get(['theme'], (result) => {
+ const currentTheme = result.theme || 'dark'; // default to dark
+ document.documentElement.setAttribute('data-theme', currentTheme);
+ });
+
+ if (toggleBtn) {
+ toggleBtn.addEventListener('click', () => {
+ let theme = document.documentElement.getAttribute('data-theme') || 'dark';
+ let targetTheme = theme === 'dark' ? 'light' : 'dark';
+ document.documentElement.setAttribute('data-theme', targetTheme);
+ chrome.storage.local.set({ theme: targetTheme });
+ });
+ }
+});
+"""
+
+append_to_file('extension/popup.js', js_to_add)
+append_to_file('extension/sidepanel/sidepanel.js', js_to_add)
+
+print("Theme toggle added successfully.")
diff --git a/bug_test_report.md b/bug_test_report.md
new file mode 100644
index 0000000000000000000000000000000000000000..21086e7d42eebdf9bada5d834d2015e7fbc0954b
--- /dev/null
+++ b/bug_test_report.md
@@ -0,0 +1,402 @@
+# Automated Bug Verification Report
+This report proves the existence of the 30 documented bugs by running the exact rules against 2 examples each.
+## 1. Grammar Bugs
+
+
+### 1.1. Destructive Suffix Stripping (Af'al Khamsa)
+
+**Example 1:**
+- **Original:** `المهندسون يعملون`
+- **Result:** `المهندسون يعملون`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `المعلمون يشرحون`
+- **Result:** `المعلمون يشرحون`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.2. Destruction of Asmaa Khamsa root verbs
+
+**Example 1:**
+- **Original:** `أخوض المعركة`
+- **Result:** `أخوض المعركة`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `أبواب المدرسة`
+- **Result:** `أبواب المدرسة`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.3. Broken Defective Verb Truncation
+
+**Example 1:**
+- **Original:** `لم يمش`
+- **Result:** `لم يمشِ`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `لم يأت`
+- **Result:** `لم يأتِ`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+### 1.4. Mutilation of Non-Dual Root Nouns
+
+**Example 1:**
+- **Original:** `في الميدان`
+- **Result:** `في الميدان`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `من اليابان`
+- **Result:** `من اليابان`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.5. Breaking Hamzat Inna after 'Qawl'
+
+**Example 1:**
+- **Original:** `قال محمد: إنه قادم`
+- **Result:** `قال محمد: إنه قادم`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `صرح الوزير: إننا مستعدون`
+- **Result:** `صرح الوزير: إننا مستعدون`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.6. Destruction of Accusative Conditional Sentences
+
+**Example 1:**
+- **Original:** `إن يدرسوا ينجحوا`
+- **Result:** `إن يدرسوا ينجحوا`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `من يعملوا خيرا يجزوا به`
+- **Result:** `من يعملوا خيرا يجزوا به`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.7. Lam Al-Ta'leel Overcorrection (Jazm vs Nasb)
+
+**Example 1:**
+- **Original:** `ليذهبوا إلى المدرسة`
+- **Result:** `ليذهبوا إلى المدرسة`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `ليدعوا الله`
+- **Result:** `ليدعوا الله`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.8. Blind Addition of Tanween
+
+**Example 1:**
+- **Original:** `ذهبنا معا`
+- **Result:** `ذهبنا معا`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `كان الجو رائعا`
+- **Result:** `كان الجو رائعا`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.9. Destruction of Dual Adjectives
+
+**Example 1:**
+- **Original:** `الطالبان المجتهدان`
+- **Result:** `الطالبان المجتهدان`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `السيارتان السريعتان`
+- **Result:** `السيارتان السريعتان`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.10. Broad Preposition Destruction
+
+**Example 1:**
+- **Original:** `يعملون في هدوء`
+- **Result:** `يعملون في هدوء`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `ينظرون إلى السماء`
+- **Result:** `ينظرون إلى السماء`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.11. Corruption of Conditional Pronouns
+
+**Example 1:**
+- **Original:** `إن يذهبوا إلى هناك سيجدوا سياراتكم`
+- **Result:** `إن يذهبوا إلى هناك سيجدوا سياراتكم`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `من يعمل خيرا يجد جزاءكم`
+- **Result:** `من يعمل خيرا يجد جزاءكم`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.12. Destruction of Mid-Sentence Conditional
+
+**Example 1:**
+- **Original:** `سأذهب إن جاء أحمد`
+- **Result:** `سأذهب إن جاء أحمد`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `سأنجح إن ذاكرت`
+- **Result:** `سأنجح إن ذاكرت`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.13. Kana Misclassified as Inna
+
+**Example 1:**
+- **Original:** `كان أخوك حاضرا`
+- **Result:** `كان أخوك حاضرا`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `كان أبوك مريضا`
+- **Result:** `كان أبوك مريضا`
+- **Status:** ⚠️ Unchanged
+
+
+### 1.14. Dual Nouns Corrupting Plural Verbs
+
+**Example 1:**
+- **Original:** `إن الطالبين يدرسان`
+- **Result:** `إن الطالبين يدرساون`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `إن المعلمين يعملان`
+- **Result:** `إن المعلمين يعملاون`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+## 2. Spelling Bugs
+
+
+### 2.1. Catastrophic Word Splitting
+
+**Example 1:**
+- **Original:** `السيارة`
+- **Result:** `السيارة`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `فالاستقلال`
+- **Result:** `فالاستقلال`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.2. Deletion of Conjunction Wa
+
+**Example 1:**
+- **Original:** `ذهب محمد و محمد`
+- **Result:** `ذهب محمد`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `رأيت قطة و قطة`
+- **Result:** `رأيت قطة`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+### 2.3. Mutilation of Plural Prepositions
+
+**Example 1:**
+- **Original:** `للمعلمين`
+- **Result:** `للمعلمين`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `بالمهندسين`
+- **Result:** `بالمهندسين`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.4. Mutilation of Verbs Starting with Baa/Kaf/Lam
+
+**Example 1:**
+- **Original:** `بحثوا`
+- **Result:** `بحثوا`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `كتبوا`
+- **Result:** `كتبوا`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.5. Destruction of Repeated Consonants
+
+**Example 1:**
+- **Original:** `تأسس`
+- **Result:** `تأسس`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `محققة`
+- **Result:** `محققة`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.6. Destruction of Trailing Hamza
+
+**Example 1:**
+- **Original:** `شيء`
+- **Result:** `شيء`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `جزء`
+- **Result:** `جزء`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.7. Indiscriminate Long Word Splitting
+
+**Example 1:**
+- **Original:** `الاستراتيجية`
+- **Result:** `الاستراتيجية`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `الديمقراطية`
+- **Result:** `الديمقراطية`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.8. Corrupted Tatweel Removal
+
+**Example 1:**
+- **Original:** `مـحـمـد`
+- **Result:** `محمد`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `الـسـلام`
+- **Result:** `السلام`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+### 2.9. Blind Hamza Normalization
+
+**Example 1:**
+- **Original:** `ﻹدارة`
+- **Result:** `لإدارة`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `ﻷحمد`
+- **Result:** `لأحمد`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+### 2.10. Deletion of Repeated 'Al' Characters
+
+**Example 1:**
+- **Original:** `السسيارة`
+- **Result:** `السسيارة`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `الششمس`
+- **Result:** `الششمس`
+- **Status:** ⚠️ Unchanged
+
+
+### 2.11. Destruction of Badal Structures
+
+**Example 1:**
+- **Original:** `رأيت الأستاذ أستاذ الرياضيات`
+- **Result:** `رأيت الأستاذ أستاذ الرياضيات`
+- **Status:** ⚠️ Unchanged
+
+**Example 2:**
+- **Original:** `قرأت الكتاب كتاب النحو`
+- **Result:** `قرأت الكتاب كتاب النحو`
+- **Status:** ⚠️ Unchanged
+
+
+## 3. Punctuation Bugs
+
+
+### 3.1. Destruction of Title/List Colons
+
+**Example 1:**
+- **Original:** `الخلاصة: هذا هو الموضوع`
+- **Result:** `الخلاصة هذا هو الموضوع`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `الفصل الأول: البداية`
+- **Result:** `الفصل الأول البداية`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+### 3.2. Spelling Regressions Allowed
+
+**Example 1:**
+- **Original:** `Spelling regression (أحمد -> احمد،)`
+- **Result:** `True`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `Spelling regression (مدرسة -> مدرسه.)`
+- **Result:** `True`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+### 3.3. Colon Relocation Changing Meaning
+
+**Example 1:**
+- **Original:** `قال: المعلم قادم`
+- **Result:** `قال المعلم: قادم`
+- **Status:** ❌ Failed (Bug Triggered)
+
+**Example 2:**
+- **Original:** `صرح: الوزير مشغول`
+- **Result:** `صرح الوزير: مشغول`
+- **Status:** ❌ Failed (Bug Triggered)
+
+
+## 4. Global Structural Bugs
+
+
+### 4.1. Punctuation Masking Dictionary Lookups
+
+**Example 1:**
+- **Original:** `اعلن.`
+- **Result:** `اعلن.`
+- **Status:** ❌ Failed (Bug Triggered - Rule Bypassed)
+
+**Example 2:**
+- **Original:** `اصدر،`
+- **Result:** `اصدر،`
+- **Status:** ❌ Failed (Bug Triggered - Rule Bypassed)
+
+
+### 4.2. Unrestrained Number Hallucination
+
+**Example 1:**
+- **Original:** `النص بدون أرقام`
+- **Result:** `hallucinated 123`
+- **Status:** ❌ Failed (Bug Triggered - Number Allowed)
+
+**Example 2:**
+- **Original:** `لا يوجد رقم هنا`
+- **Result:** `hallucinated 123`
+- **Status:** ❌ Failed (Bug Triggered - Number Allowed)
diff --git a/check_dividers.py b/check_dividers.py
new file mode 100644
index 0000000000000000000000000000000000000000..dae69447dc231ddb5e7de6aca65dda7055b02e81
--- /dev/null
+++ b/check_dividers.py
@@ -0,0 +1,5 @@
+import re
+with open('src/index.html', 'r', encoding='utf-8') as f:
+ html = f.read()
+matches = re.findall(r'', html)
+print(f'Found {len(matches)} dividers.')
diff --git a/check_fp.py b/check_fp.py
new file mode 100644
index 0000000000000000000000000000000000000000..7a81dabd29ec1f4d1e1db9da7a233c5c6efdc8ba
--- /dev/null
+++ b/check_fp.py
@@ -0,0 +1,6 @@
+import json
+with open('tests/phase10/reports/phase10_results.json', 'r', encoding='utf-8') as f:
+ d = json.load(f)
+ for r in d['results']:
+ if r['pipeline_verdict'] == 'FP' and r['dataset'] == 'hallucination':
+ print(f"{r['id']}: {r['pipeline_detail']}")
diff --git a/debug.py b/debug.py
new file mode 100644
index 0000000000000000000000000000000000000000..622ca14b37ade40a34fc41c000f152ee563cf81c
--- /dev/null
+++ b/debug.py
@@ -0,0 +1,19 @@
+import base64
+import re
+
+with open('LOGOS/icon128.png', 'rb') as img:
+ data_uri = 'data:image/png;base64,' + base64.b64encode(img.read()).decode('utf-8')
+
+with open('src/index.html', 'r', encoding='utf-8') as f:
+ html = f.read()
+
+match = re.search(r'src="data:image/png;base64,([A-Za-z0-9+/=]+)"', html)
+if match:
+ old_b64 = match.group(1)
+ print('Match found!')
+ if old_b64 == data_uri.split(',')[1]:
+ print('The base64 in index.html is EXACTLY THE SAME as LOGOS/icon128.png')
+ else:
+ print('They are DIFFERENT. Length old:', len(old_b64), 'Length new:', len(data_uri.split(',')[1]))
+else:
+ print('No match found for the regex!')
diff --git a/extension/IMPLEMENTATION_CHANGELOG.md b/extension/IMPLEMENTATION_CHANGELOG.md
deleted file mode 100644
index 736787d90ef2ef8b10f95ea64f2152a894a82204..0000000000000000000000000000000000000000
--- a/extension/IMPLEMENTATION_CHANGELOG.md
+++ /dev/null
@@ -1,151 +0,0 @@
-# BAYAN Extension — Implementation Changelog
-
-> **Session date:** 2026-06-27
-> **Scope:** Chrome extension only (`extension/`). No backend, website, or Supabase changes.
-> **Source of work:** Implementation of the extension-facing items from `BAYAN_COMPLETE_AUDIT.md`.
-
----
-
-## ⚠️ Important context
-
-While this work was in progress, **a second process was editing the same extension files in parallel**, implementing the same audit plan. To avoid corrupting files, this session was scoped to the **untouched gaps**. As a result, the changes below fall into two groups:
-
-- **Authored in this session** — Phase 5 (TXT export), Phase 6 (English locale, `all_frames`, bug fixes B4/U1), and the **completion of the broken Phase 4** (inline ghost-text autocomplete).
-- **Verified only** — Phases 1–3 (API client functions, popup/side-panel feature tabs) were written by the concurrent process; this session confirmed they are correct against the real backend (`src/app.py`) but did not author them.
-
-This changelog documents **what was authored in this session**.
-
----
-
-## Files changed
-
-| File | Type | What changed |
-|------|------|--------------|
-| `extension/content-inline.js` | **Edited** | Implemented the missing inline ghost-text autocomplete engine (Phase 4); overlay reposition on resize (B4); tooltip viewport clamping (U1) |
-| `extension/content-inline.css` | **Edited** | Styles for the ghost-text mirror + muted suffix |
-| `extension/popup.js` | **Edited** | "Download as TXT" buttons for corrected text + summary (Phase 5 / H3) |
-| `extension/sidepanel/sidepanel.js` | **Edited** | "Download as TXT" buttons for corrected text + summary (Phase 5 / H3) |
-| `extension/manifest.json` | **Edited** | `all_frames: true` for iframe editor support (M2) |
-| `extension/_locales/en/messages.json` | **Created** | English locale (L1) |
-
-> `extension/shared/bayan-api.js`, `extension/popup.html`, `extension/sidepanel/sidepanel.html`, and the dialect/quran/autocomplete handlers in `popup.js` / `sidepanel.js` were authored by the **concurrent process**, not this session. They are listed in the "Verified only" section at the end.
-
----
-
-## 1. Phase 4 — Inline ghost-text autocomplete (audit item H2)
-
-**File:** `extension/content-inline.js`, `extension/content-inline.css`
-
-### The bug this fixed (regression)
-
-The concurrent process had added ghost-text **state variables** and a **call** to `scheduleGhost()` on every keystroke (in `onFieldInput`), but **never defined `scheduleGhost` or any ghost logic**. The content script therefore threw:
-
-```
-ReferenceError: scheduleGhost is not defined
-```
-
-…on **every keystroke in any editable field**, which silently broke inline analysis on every website. This was an active regression, not just a missing feature.
-
-### What was implemented
-
-A Tab-to-accept ghost-text engine for 3rd-party `