rameshmoorthy commited on
Commit
1fdcdce
·
verified ·
1 Parent(s): 3baf594

Update app.html

Browse files
Files changed (1) hide show
  1. app.html +86 -154
app.html CHANGED
@@ -4,7 +4,49 @@
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
  <style>
7
- :root{--g:#138808;--s:#ff9933;--n:#17365d;--ink:#203040}*{box-sizing:border-box}body{margin:0;font-family:system-ui,-apple-system,Segoe UI,sans-serif;background:linear-gradient(135deg,#fff7e8,#eef9f0 55%,#edf5ff);color:var(--ink)}.wrap{max-width:1180px;margin:auto;padding:18px}.header{background:linear-gradient(100deg,#138808,#0b6e34);color:#fff;border-radius:24px;padding:20px 24px;box-shadow:0 12px 30px #0002;display:flex;align-items:center;gap:18px}.logo{width:64px;height:64px;border-radius:50%;background:#fff;display:grid;place-items:center;font-size:34px;border:4px solid #ff9933}.title{font-size:34px;font-weight:900}.sub{font-size:15px;opacity:.94}.school{margin-left:auto;text-align:right;font-weight:800}.school small{display:block;font-weight:500}.panel{margin-top:16px;background:#ffffffdf;border-radius:24px;padding:20px;box-shadow:0 10px 30px #17365d18}.avatar-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:12px}.avatar-btn{border:3px solid transparent;border-radius:20px;padding:12px;background:#fff;cursor:pointer;font-size:15px;font-weight:800;box-shadow:0 5px 16px #0001}.avatar-btn.active{border-color:var(--s);background:#fff5e8}.avatar{font-size:55px}.voice-badge{font-size:11px;color:#666}.main{display:grid;grid-template-columns:360px 1fr;gap:18px}.avatar-stage{background:linear-gradient(#e9f8ff,#fff);border-radius:22px;min-height:480px;display:flex;flex-direction:column;align-items:center;justify-content:center;border:1px solid #dceaf0}.big-avatar{font-size:170px;filter:drop-shadow(0 10px 5px #0002);animation:float 2.5s ease-in-out infinite}@keyframes float{50%{transform:translateY(-8px)}}.talk{animation:talk .18s infinite alternate}@keyframes talk{to{transform:scale(1.035)}}.status{margin-top:12px;padding:10px 18px;border-radius:999px;background:#e9f6eb;color:#17652b;font-weight:800}.question{font-size:28px;font-weight:850;line-height:1.25;margin:12px 0}.tamil{font-size:22px;color:#5a3b8c;margin-bottom:15px;line-height:1.35}.listen{border:0;border-radius:18px;padding:17px 24px;background:linear-gradient(135deg,#ff9933,#ffb84d);color:#fff;font-size:20px;font-weight:900;cursor:pointer;box-shadow:0 8px 18px #ff993355}.listen.listening{background:linear-gradient(135deg,#d93025,#ef5350)}.transcript{margin-top:14px;background:#f4f8fb;border-radius:16px;padding:12px;min-height:48px;font-size:18px}.progress{height:12px;background:#e5ece8;border-radius:20px;overflow:hidden;margin:14px 0}.bar{height:100%;background:linear-gradient(90deg,#138808,#ff9933);width:0;transition:.4s}.scheme-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:14px}.card{border-radius:20px;padding:16px;background:#fff;border-left:7px solid var(--accent);box-shadow:0 7px 20px #0001}.card-top{display:flex;gap:12px;align-items:center}.icon{font-size:45px}.card h3{margin:0;font-size:19px}.why{font-weight:700;margin:8px 0}.benefit{font-size:14px;color:#46535c}.gov{font-size:11px;color:#667}.link{display:inline-block;margin-top:10px;background:#17365d;color:white;text-decoration:none;padding:9px 12px;border-radius:10px;font-weight:800}.hidden{display:none}.footer{text-align:center;color:#65716a;font-size:12px;padding:18px}.note{background:#fff6df;border-left:5px solid #ff9933;padding:12px;border-radius:12px;font-size:14px}@media(max-width:850px){.main{grid-template-columns:1fr}.avatar-grid{grid-template-columns:repeat(2,1fr)}.scheme-grid{grid-template-columns:1fr}.school{display:none}.title{font-size:27px}.question{font-size:24px}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  </style>
9
  </head>
10
  <body>
@@ -26,11 +68,11 @@
26
  <div id="interaction" class="panel">
27
  <div class="main">
28
  <div class="avatar-stage">
29
- <div id="bigAvatar" class="big-avatar"></div>
30
  <div id="status" class="status">Ready / தயாராக உள்ளது</div>
31
  </div>
32
  <div>
33
- <div class="note"> <b>Voice only:</b> Speak your answer. There are no YES/NO buttons. Say Yes/ஆம், No/இல்லை, or I don't know/தெரியாது.</div>
34
  <div class="progress"><div id="bar" class="bar"></div></div>
35
  <div id="qEn" class="question"></div>
36
  <div id="qTa" class="tamil"></div>
@@ -46,7 +88,7 @@
46
  <p id="resultIntro"></p>
47
  <div id="cards" class="scheme-grid"></div>
48
  <div class="note" style="margin-top:15px">ℹ️ These are <b>possible matches, not a final eligibility decision</b>. Verify eligibility, documents and current rules on the official Government of India website.</div>
49
- <button id="restart" class="listen" style="margin-top:16px"> Start again / மீண்டும் தொடங்குங்கள்</button>
50
  </div>
51
 
52
  <div class="footer">Designed as a school-level awareness prototype • No Aadhaar, OTP, bank or other sensitive personal information is requested.</div>
@@ -58,37 +100,21 @@
58
  (function initGSM() {
59
  function start() {
60
  const dataElem = document.getElementById('app-data');
61
- if (!dataElem) {
62
- console.error('app-data element not found');
63
- return;
64
- }
65
  let DATA;
66
- try {
67
- DATA = JSON.parse(dataElem.textContent);
68
- } catch (err) {
69
- console.error("Failed to parse app data:", err);
70
- return;
71
- }
72
 
73
- let avatar = DATA.avatars[0];
74
- let qi = 0;
75
- let answers = {};
76
- let listening = false;
77
- let recognition = null;
78
  const $ = id => document.getElementById(id);
79
 
80
- function lang() {
81
- return (navigator.language && navigator.language.toLowerCase().startsWith('ta')) ? 'ta' : 'en';
82
- }
83
 
84
  function pickVoice(language, profile) {
85
  const vs = window.speechSynthesis ? speechSynthesis.getVoices() : [];
86
  const pool = vs.filter(v => v.lang.toLowerCase().startsWith(language === 'ta' ? 'ta' : 'en'));
87
  if (!pool.length) return null;
88
- const f = /(female|woman|zira|heera|kalpana|samantha)/i;
89
- const m = /(male|man|david|ravi)/i;
90
- const isFemale = (profile === 'female' || profile === 'girl');
91
- return pool.find(v => isFemale ? f.test(v.name) : m.test(v.name)) || pool[0];
92
  }
93
 
94
  function speak(text, language, done) {
@@ -98,54 +124,35 @@
98
  u.lang = language === 'ta' ? 'ta-IN' : 'en-IN';
99
  const v = pickVoice(language, avatar.voice);
100
  if (v) u.voice = v;
101
- u.rate = 0.9;
102
- u.pitch = (avatar.voice === 'girl' || avatar.voice === 'boy') ? 1.15 : 1.0;
103
-
104
  const bigAv = $('bigAvatar');
105
  if (bigAv) bigAv.classList.add('talk');
106
- u.onend = () => {
107
- if (bigAv) bigAv.classList.remove('talk');
108
- if (done) done();
109
- };
110
  speechSynthesis.speak(u);
111
  }
112
 
113
- function speakCurrent() {
114
- const q = DATA.questions[qi];
115
- if (q) speak(lang() === 'ta' ? q.ta : q.en, lang());
116
- }
117
 
118
  function renderAvatars() {
119
  const grid = $('avatarGrid');
120
- if (!grid) return;
121
- grid.innerHTML = DATA.avatars.map((a, i) => `
122
- <button class="avatar-btn ${i === 0 ? 'active' : ''}" data-i="${i}">
123
- <div class="avatar">${a.emoji}</div>
124
- <div>${a.label} / ${a.ta}</div>
125
- <div class="voice-badge">Voice: ${a.voice}</div>
126
- </button>
127
- `).join('');
128
  grid.querySelectorAll('.avatar-btn').forEach(btn => {
129
  btn.onclick = () => {
130
  avatar = DATA.avatars[+btn.dataset.i];
131
  grid.querySelectorAll('.avatar-btn').forEach(x => x.classList.remove('active'));
132
  btn.classList.add('active');
133
- if ($('bigAvatar'))$('bigAvatar').textContent = avatar.emoji;
134
  speakCurrent();
135
  };
136
  });
137
  }
138
 
139
  function showQuestion() {
140
- if (qi >= DATA.questions.length) {
141
- finish();
142
- return;
143
- }
144
  const q = DATA.questions[qi];
145
- if ($('qEn'))$('qEn').textContent = q.en;
146
- if ($('qTa'))$('qTa').textContent = q.ta;
147
- if ($('bar'))$('bar').style.width = ((qi / DATA.questions.length) * 100) + '%';
148
- if ($('transcript'))$('transcript').textContent = 'Your spoken answer will appear here…';
149
  setTimeout(speakCurrent, 250);
150
  }
151
 
@@ -161,139 +168,64 @@
161
  }
162
 
163
  function handleSpeech(text) {
164
- if ($('transcript'))$('transcript').textContent = '"' + text + '"';
165
  const ans = normalize(text);
166
- if (!ans) {
167
- speak(lang() === 'ta' ? 'மன்னிக்கவும். ஆம், இல்லை அல்லது தெரியாது என்று சொல்லுங்கள்.' : 'Sorry. Please say Yes, No, or I don't know.', lang());
168
- return;
169
- }
170
  answers[DATA.questions[qi].kind] = ans;
171
- setTimeout(() => {
172
- qi++;
173
- showQuestion();
174
- }, 600);
175
  }
176
 
177
  function startListening() {
178
  const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
179
- if (!SR) {
180
- alert('Speech recognition is not available. Please open this in Google Chrome and allow microphone access.');
181
- return;
182
- }
183
- if (listening) {
184
- if (recognition) recognition.stop();
185
- return;
186
- }
187
  recognition = new SR();
188
  recognition.lang = lang() === 'ta' ? 'ta-IN' : 'en-IN';
189
- recognition.interimResults = true;
190
- recognition.continuous = false;
191
  listening = true;
192
  const btn = $('listenBtn');
193
- if (btn) {
194
- btn.classList.add('listening');
195
- btn.textContent = '🔴 Listening… speak now';
196
- }
197
- if ($('status'))$('status').textContent = 'Listening / கேட்கிறது…';
198
  recognition.onresult = e => {
199
  let text = '';
200
- for (let i = e.resultIndex; i < e.results.length; i++) {
201
- text += e.results[i][0].transcript;
202
- }
203
- if ($('transcript'))$('transcript').textContent = text;
204
- if (e.results[e.results.length - 1].isFinal) {
205
- handleSpeech(text);
206
- }
207
  };
208
  recognition.onerror = () => {
209
- listening = false;
210
- if (btn) {
211
- btn.classList.remove('listening');
212
- btn.textContent = '🎤 Start listening / பேசத் தொடங்குங்கள்';
213
- }
214
- if ($('status'))$('status').textContent = 'Recognition error';
215
  };
216
  recognition.onend = () => {
217
- listening = false;
218
- if (btn) {
219
- btn.classList.remove('listening');
220
- btn.textContent = '🎤 Start listening / பேசத் தொடங்குங்கள்';
221
- }
222
- if ($('status'))$('status').textContent = 'Ready / தயாராக உள்ளது';
223
  };
224
  recognition.start();
225
  }
226
 
227
  function finish() {
228
- if ($('interaction'))$('interaction').classList.add('hidden');
229
- if ($('results'))$('results').classList.remove('hidden');
230
- if ($('bar'))$('bar').style.width = '100%';
231
  const matched = DATA.schemes.filter(s => {
232
  const a = answers[s.trigger[0]];
233
  if (!a) return false;
234
  if (s.trigger[0] === 'lpg' || s.trigger[0] === 'bank') return a === 'no';
235
  return a === 'yes';
236
  });
237
- const intro = lang() === 'ta'
238
- ? `உங்கள் பதில்களின் அடிப்படையில் ${matched.length} திட்டங்களை சரிபார்க்கலாம்.`
239
- : `Based on your answers, ${matched.length} scheme(s) may be worth checking.`;
240
- if ($('resultIntro'))$('resultIntro').textContent = intro;
241
- if ($('cards')) {
242
- $('cards').innerHTML = matched.length ? matched.map(s => `
243
- <div class="card" style="--accent:${themeColor(s.theme)}">
244
- <div class="card-top">
245
- <div class="icon">${s.icon}</div>
246
- <div>
247
- <h3>${lang() === 'ta' ? s.name_ta : s.name_en}</h3>
248
- <div class="gov">${s.source}</div>
249
- </div>
250
- </div>
251
- <div class="why">${lang() === 'ta' ? s.why_ta : s.why_en}</div>
252
- <div class="benefit">${lang() === 'ta' ? s.benefit_ta : s.benefit_en}</div>
253
- <a class="link" href="${s.url}" target="_blank" rel="noopener">🌐 Official Government Website</a>
254
- </div>
255
- `).join('') : `
256
- <div class="card" style="--accent:#138808">
257
- <div class="icon">🌱</div>
258
- <h3>${lang() === 'ta' ? 'மேலும் தகவல் தேவை' : 'More information may be needed'}</h3>
259
- <div class="benefit">${lang() === 'ta' ? 'பெற்றோர் அல்லது ஆசிரியரிடம் மேலும் தகவல் கேட்டு மீண்டும் முயற்சிக்கலாம்.' : 'Ask a parent/teacher for more information and try again.'}</div>
260
- </div>
261
- `;
262
- }
263
  speak(intro, lang());
264
  }
265
 
266
- function themeColor(t) {
267
- return {
268
- pink: '#e83e8c', gold: '#d99b00', violet: '#7952b3',
269
- blue: '#2589bd', green: '#138808', orange: '#ff7a00',
270
- red: '#d93025', teal: '#008c95', indigo: '#405de6', purple: '#8e44ad'
271
- }[t] || '#138808';
272
- }
273
-
274
- // Attach button listeners safely
275
- if ($('listenBtn'))$('listenBtn').onclick = startListening;
276
- if ($('againBtn'))$('againBtn').onclick = speakCurrent;
277
- if ($('restart'))$('restart').onclick = () => {
278
- qi = 0;
279
- answers = {};
280
- if ($('results'))$('results').classList.add('hidden');
281
- if ($('interaction'))$('interaction').classList.remove('hidden');
282
- showQuestion();
283
- };
284
 
285
- // Initialize UI
286
- renderAvatars();
287
- showQuestion();
 
288
  }
289
 
290
- // Ensure DOM is ready even inside Gradio iframe/Blocks
291
- if (document.readyState === 'loading') {
292
- document.addEventListener('DOMContentLoaded', start);
293
- } else {
294
- setTimeout(start, 50);
295
- }
296
  })();
297
  </script>
298
  </body>
299
- </html>
 
 
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
  <style>
7
+ :root{--g:#138808;--s:#ff9933;--n:#17365d;--ink:#203040}
8
+ *{box-sizing:border-box}
9
+ body{margin:0;font-family:system-ui,-apple-system,Segoe UI,sans-serif;background:linear-gradient(135deg,#fff7e8,#eef9f0 55%,#edf5ff);color:var(--ink)}
10
+ .wrap{max-width:1180px;margin:auto;padding:18px}
11
+ .header{background:linear-gradient(100deg,#138808,#0b6e34);color:#fff;border-radius:24px;padding:20px 24px;box-shadow:0 12px 30px #0002;display:flex;align-items:center;gap:18px}
12
+ .logo{width:64px;height:64px;border-radius:50%;background:#fff;display:grid;place-items:center;font-size:34px;border:4px solid #ff9933}
13
+ .title{font-size:34px;font-weight:900}
14
+ .sub{font-size:15px;opacity:.94}
15
+ .school{margin-left:auto;text-align:right;font-weight:800}
16
+ .school small{display:block;font-weight:500}
17
+ .panel{margin-top:16px;background:#ffffffdf;border-radius:24px;padding:20px;box-shadow:0 10px 30px #17365d18}
18
+ .avatar-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:12px}
19
+ .avatar-btn{border:3px solid transparent;border-radius:20px;padding:12px;background:#fff;cursor:pointer;font-size:15px;font-weight:800;box-shadow:0 5px 16px #0001}
20
+ .avatar-btn.active{border-color:var(--s);background:#fff5e8}
21
+ .avatar{font-size:55px}
22
+ .voice-badge{font-size:11px;color:#666}
23
+ .main{display:grid;grid-template-columns:360px 1fr;gap:18px}
24
+ .avatar-stage{background:linear-gradient(#e9f8ff,#fff);border-radius:22px;min-height:480px;display:flex;flex-direction:column;align-items:center;justify-content:center;border:1px solid #dceaf0}
25
+ .big-avatar{font-size:170px;filter:drop-shadow(0 10px 5px #0002);animation:float 2.5s ease-in-out infinite}
26
+ @keyframes float{50%{transform:translateY(-8px)}}
27
+ .talk{animation:talk .18s infinite alternate}
28
+ @keyframes talk{to{transform:scale(1.035)}}
29
+ .status{margin-top:12px;padding:10px 18px;border-radius:999px;background:#e9f6eb;color:#17652b;font-weight:800}
30
+ .question{font-size:28px;font-weight:850;line-height:1.25;margin:12px 0}
31
+ .tamil{font-size:22px;color:#5a3b8c;margin-bottom:15px;line-height:1.35}
32
+ .listen{border:0;border-radius:18px;padding:17px 24px;background:linear-gradient(135deg,#ff9933,#ffb84d);color:#fff;font-size:20px;font-weight:900;cursor:pointer;box-shadow:0 8px 18px #ff993355}
33
+ .listen.listening{background:linear-gradient(135deg,#d93025,#ef5350)}
34
+ .transcript{margin-top:14px;background:#f4f8fb;border-radius:16px;padding:12px;min-height:48px;font-size:18px}
35
+ .progress{height:12px;background:#e5ece8;border-radius:20px;overflow:hidden;margin:14px 0}
36
+ .bar{height:100%;background:linear-gradient(90deg,#138808,#ff9933);width:0;transition:.4s}
37
+ .scheme-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:14px}
38
+ .card{border-radius:20px;padding:16px;background:#fff;border-left:7px solid var(--accent);box-shadow:0 7px 20px #0001}
39
+ .card-top{display:flex;gap:12px;align-items:center}
40
+ .icon{font-size:45px}
41
+ .card h3{margin:0;font-size:19px}
42
+ .why{font-weight:700;margin:8px 0}
43
+ .benefit{font-size:14px;color:#46535c}
44
+ .gov{font-size:11px;color:#667}
45
+ .link{display:inline-block;margin-top:10px;background:#17365d;color:white;text-decoration:none;padding:9px 12px;border-radius:10px;font-weight:800}
46
+ .hidden{display:none}
47
+ .footer{text-align:center;color:#65716a;font-size:12px;padding:18px}
48
+ .note{background:#fff6df;border-left:5px solid #ff9933;padding:12px;border-radius:12px;font-size:14px}
49
+ @media(max-width:850px){.main{grid-template-columns:1fr}.avatar-grid{grid-template-columns:repeat(2,1fr)}.scheme-grid{grid-template-columns:1fr}.school{display:none}.title{font-size:27px}.question{font-size:24px}}
50
  </style>
51
  </head>
52
  <body>
 
68
  <div id="interaction" class="panel">
69
  <div class="main">
70
  <div class="avatar-stage">
71
+ <div id="bigAvatar" class="big-avatar">👨</div>
72
  <div id="status" class="status">Ready / தயாராக உள்ளது</div>
73
  </div>
74
  <div>
75
+ <div class="note">🎤 <b>Voice only:</b> Speak your answer. There are no YES/NO buttons. Say Yes/ஆம், No/இல்லை, or I don't know/தெரியாது.</div>
76
  <div class="progress"><div id="bar" class="bar"></div></div>
77
  <div id="qEn" class="question"></div>
78
  <div id="qTa" class="tamil"></div>
 
88
  <p id="resultIntro"></p>
89
  <div id="cards" class="scheme-grid"></div>
90
  <div class="note" style="margin-top:15px">ℹ️ These are <b>possible matches, not a final eligibility decision</b>. Verify eligibility, documents and current rules on the official Government of India website.</div>
91
+ <button id="restart" class="listen" style="margin-top:16px">🔄 Start again / மீண்டும் தொடங்குங்கள்</button>
92
  </div>
93
 
94
  <div class="footer">Designed as a school-level awareness prototype • No Aadhaar, OTP, bank or other sensitive personal information is requested.</div>
 
100
  (function initGSM() {
101
  function start() {
102
  const dataElem = document.getElementById('app-data');
103
+ if (!dataElem) { console.error('app-data not found'); return; }
 
 
 
104
  let DATA;
105
+ try { DATA = JSON.parse(dataElem.textContent); } catch (err) { console.error("Failed to parse app data:", err); return; }
 
 
 
 
 
106
 
107
+ let avatar = DATA.avatars[0], qi = 0, answers = {}, listening = false, recognition = null;
 
 
 
 
108
  const $ = id => document.getElementById(id);
109
 
110
+ function lang() { return (navigator.language && navigator.language.toLowerCase().startsWith('ta')) ? 'ta' : 'en'; }
 
 
111
 
112
  function pickVoice(language, profile) {
113
  const vs = window.speechSynthesis ? speechSynthesis.getVoices() : [];
114
  const pool = vs.filter(v => v.lang.toLowerCase().startsWith(language === 'ta' ? 'ta' : 'en'));
115
  if (!pool.length) return null;
116
+ const f = /(female|woman|zira|heera|kalpana|samantha)/i, m = /(male|man|david|ravi)/i;
117
+ return pool.find(v => (profile === 'female' || profile === 'girl') ? f.test(v.name) : m.test(v.name)) || pool[0];
 
 
118
  }
119
 
120
  function speak(text, language, done) {
 
124
  u.lang = language === 'ta' ? 'ta-IN' : 'en-IN';
125
  const v = pickVoice(language, avatar.voice);
126
  if (v) u.voice = v;
127
+ u.rate = 0.9; u.pitch = (avatar.voice === 'girl' || avatar.voice === 'boy') ? 1.15 : 1.0;
 
 
128
  const bigAv = $('bigAvatar');
129
  if (bigAv) bigAv.classList.add('talk');
130
+ u.onend = () => { if (bigAv) bigAv.classList.remove('talk'); if (done) done(); };
 
 
 
131
  speechSynthesis.speak(u);
132
  }
133
 
134
+ function speakCurrent() { const q = DATA.questions[qi]; if (q) speak(lang() === 'ta' ? q.ta : q.en, lang()); }
 
 
 
135
 
136
  function renderAvatars() {
137
  const grid = $('avatarGrid');
138
+ grid.innerHTML = DATA.avatars.map((a, i) => `<button class="avatar-btn ${i === 0 ? 'active' : ''}" data-i="${i}"><div class="avatar">${a.emoji}</div><div>${a.label} / ${a.ta}</div><div class="voice-badge">Voice: ${a.voice}</div></button>`).join('');
 
 
 
 
 
 
 
139
  grid.querySelectorAll('.avatar-btn').forEach(btn => {
140
  btn.onclick = () => {
141
  avatar = DATA.avatars[+btn.dataset.i];
142
  grid.querySelectorAll('.avatar-btn').forEach(x => x.classList.remove('active'));
143
  btn.classList.add('active');
144
+ $('bigAvatar').textContent = avatar.emoji;
145
  speakCurrent();
146
  };
147
  });
148
  }
149
 
150
  function showQuestion() {
151
+ if (qi >= DATA.questions.length) { finish(); return; }
 
 
 
152
  const q = DATA.questions[qi];
153
+ $('qEn').textContent = q.en; $('qTa').textContent = q.ta;
154
+ $('bar').style.width = ((qi / DATA.questions.length) * 100) + '%';
155
+ $('transcript').textContent = 'Your spoken answer will appear here…';
 
156
  setTimeout(speakCurrent, 250);
157
  }
158
 
 
168
  }
169
 
170
  function handleSpeech(text) {
171
+ $('transcript').textContent = '"' + text + '"';
172
  const ans = normalize(text);
173
+ if (!ans) { speak(lang() === 'ta' ? 'மன்னிக்கவும். ஆம், இல்லை அல்லது தெரியாது என்று சொல்லுங்கள்.' : 'Sorry. Please say Yes, No, or I don\'t know.', lang()); return; }
 
 
 
174
  answers[DATA.questions[qi].kind] = ans;
175
+ setTimeout(() => { qi++; showQuestion(); }, 600);
 
 
 
176
  }
177
 
178
  function startListening() {
179
  const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
180
+ if (!SR) { alert('Speech recognition is not available. Please use Google Chrome and allow microphone access.'); return; }
181
+ if (listening) { if (recognition) recognition.stop(); return; }
 
 
 
 
 
 
182
  recognition = new SR();
183
  recognition.lang = lang() === 'ta' ? 'ta-IN' : 'en-IN';
184
+ recognition.interimResults = true; recognition.continuous = false;
 
185
  listening = true;
186
  const btn = $('listenBtn');
187
+ btn.classList.add('listening'); btn.textContent = '🔴 Listening… speak now';
188
+ $('status').textContent = 'Listening / கேட்கிறது…';
 
 
 
189
  recognition.onresult = e => {
190
  let text = '';
191
+ for (let i = e.resultIndex; i < e.results.length; i++) text += e.results[i][0].transcript;
192
+ $('transcript').textContent = text;
193
+ if (e.results[e.results.length - 1].isFinal) handleSpeech(text);
 
 
 
 
194
  };
195
  recognition.onerror = () => {
196
+ listening = false; btn.classList.remove('listening'); btn.textContent = '🎤 Start listening / பேசத் தொடங்குங்கள்'; $('status').textContent = 'Recognition error';
 
 
 
 
 
197
  };
198
  recognition.onend = () => {
199
+ listening = false; btn.classList.remove('listening'); btn.textContent = '🎤 Start listening / பேசத் தொடங்குங்கள்'; $('status').textContent = 'Ready / தயாராக உள்ளது';
 
 
 
 
 
200
  };
201
  recognition.start();
202
  }
203
 
204
  function finish() {
205
+ $('interaction').classList.add('hidden'); $('results').classList.remove('hidden'); $('bar').style.width = '100%';
 
 
206
  const matched = DATA.schemes.filter(s => {
207
  const a = answers[s.trigger[0]];
208
  if (!a) return false;
209
  if (s.trigger[0] === 'lpg' || s.trigger[0] === 'bank') return a === 'no';
210
  return a === 'yes';
211
  });
212
+ const intro = lang() === 'ta' ? `உங்கள் பதில்களின் அடிப்படையில் ${matched.length} திட்டங்களை சரிபார்க்கலாம்.` : `Based on your answers, ${matched.length} scheme(s) may be worth checking.`;
213
+ $('resultIntro').textContent = intro;
214
+ $('cards').innerHTML = matched.length ? matched.map(s => `<div class="card" style="--accent:${themeColor(s.theme)}"><div class="card-top"><div class="icon">${s.icon}</div><div><h3>${lang() === 'ta' ? s.name_ta : s.name_en}</h3><div class="gov">${s.source}</div></div></div><div class="why">${lang() === 'ta' ? s.why_ta : s.why_en}</div><div class="benefit">${lang() === 'ta' ? s.benefit_ta : s.benefit_en}</div><a class="link" href="${s.url}" target="_blank" rel="noopener">🌐 Official Government Website</a></div>`).join('') : `<div class="card" style="--accent:#138808"><div class="icon"></div><h3>${lang() === 'ta' ? 'மேலும் தகவல் தேவை' : 'More information may be needed'}</h3><div class="benefit">${lang() === 'ta' ? 'பெற்றோர் அல்லது ஆசிரியரிடம் மேலும் தகவல் கேட்டு மீண்டும் முயற்சிக்கலாம்.' : 'Ask a parent/teacher for more information and try again.'}</div></div>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  speak(intro, lang());
216
  }
217
 
218
+ function themeColor(t) { return { pink: '#e83e8c', gold: '#d99b00', violet: '#7952b3', blue: '#2589bd', green: '#138808', orange: '#ff7a00', red: '#d93025', teal: '#008c95', indigo: '#405de6', purple: '#8e44ad' }[t] || '#138808'; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
+ $('listenBtn').onclick = startListening;
221
+ $('againBtn').onclick = speakCurrent;
222
+ $('restart').onclick = () => { qi = 0; answers = {}; $('results').classList.add('hidden'); $('interaction').classList.remove('hidden'); showQuestion(); };
223
+ renderAvatars(); showQuestion();
224
  }
225
 
226
+ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', start); } else { setTimeout(start, 50); }
 
 
 
 
 
227
  })();
228
  </script>
229
  </body>
230
+ </html>
231
+