const PHASES=[
{key:'p1',phase:'Phase 1',range:[1,45],genre:'Newspapers & editorials',level:'Easy → Easy–Moderate',builds:'Reading speed, current affairs, argumentative prose; core editorial vocabulary.'},
{key:'p2',phase:'Phase 2',range:[46,90],genre:'Magazines & science journalism',level:'Moderate',builds:'1,500–3,000-word features; para-summary, tone, assumption-spotting.'},
{key:'p3',phase:'Phase 3',range:[91,120],genre:'Essays & long-form',level:'Moderate–Hard',builds:"Abstract humanities RC — philosophy, psychology, culture (CAT's favourite zone)."},
{key:'p4',phase:'Phase 4',range:[121,150],genre:'Books',level:'Moderate–Hard',builds:'Reading stamina, note-making, sustained arguments across chapters.'},
{key:'p5',phase:'Phase 5',range:[151,168],genre:'Encyclopedias & reference',level:'Hard',builds:'Dense technical prose; precision vocabulary.'},
{key:'p6',phase:'Phase 6',range:[169,180],genre:'Academic sources & mocks',level:'Hard',builds:'Research articles, timed RC sets, full vocabulary revision.'},
];
function shuffle(arr){const a=arr.slice();for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;}
const STOP=new Set(['the','a','an','of','to','and','or','in','on','for','as','is','that','with','by','from','be','or','at','it','one','into','from','which','this']);
function keywords(def){ return (def||'').toLowerCase().replace(/[^a-z\s]/g,' ').split(/\s+/).filter(t=>t.length>3&&!STOP.has(t)); }
function overlapScore(a,b){ const kb=new Set(keywords(b)); return keywords(a).filter(k=>kb.has(k)).length; }

function WordDetail({w,pool}){
const {posOf,pronounce,hindiOf,antonymsOf}=window.WordEnrich;
const hindi=hindiOf(w.word);
const synonyms=pool?shuffle(pool.filter(o=>o.word!==w.word).map(o=>({o,score:overlapScore(w.def,o.def)})).filter(r=>r.score>0).sort((a,b)=>b.score-a.score).slice(0,6)).slice(0,3).map(r=>r.o.word):[];
const antonyms=antonymsOf(w.word).slice(0,3);
return React.createElement('div',{style:{padding:'10px 12px',background:'var(--white)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-sm)'}},
React.createElement('div',{style:{display:'flex',alignItems:'baseline',gap:8,flexWrap:'wrap',marginBottom:4}},
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:14,color:'var(--text-heading)'}},w.word),
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontSize:12,color:'var(--text-muted)'}},'/'+pronounce(w.word)+'/'),
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontStyle:'italic',fontSize:12,color:'var(--text-muted)'}},posOf(w.word)),
hindi&&React.createElement('span',{style:{fontFamily:'var(--font-body)',fontWeight:600,fontSize:12.5,color:'var(--brand-primary)'}},'('+hindi+')')),
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.5,marginBottom:6}},w.def),
synonyms.length>0&&React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--text-success)',marginBottom:2}},'Synonyms: '+synonyms.join(', ')),
antonyms.length>0&&React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--red-500)'}},'Antonyms: '+antonyms.join(', ')));
}

const sbGuard=()=>!window.SBAuth||window.SBAuth.guard();
/* Students may skip questions: submitting asks once when some are unanswered. */
const okToSubmit=(left)=>left<=0||window.confirm(left+(left===1?' question is':' questions are')+' not answered. Submit anyway? Skipped questions count as not attempted.');
const sbRecord=(page,score,total,questions)=>(window.SBAuth&&page)?window.SBAuth.recordAttempt(page,score,total,questions?{questions}:undefined).then(r=>r&&r.id).catch(()=>null):Promise.resolve(null);
const LETTERS4=['A','B','C','D'];
const AnalysisLink=({id})=>id?React.createElement('a',{href:'analysis.html?id='+encodeURIComponent(id),style:{display:'inline-flex',alignItems:'center',padding:'7px 16px',borderRadius:'var(--radius-pill)',background:'var(--brand-accent)',color:'var(--on-dark)',fontFamily:'var(--font-body)',fontWeight:700,fontSize:13,textDecoration:'none'}},'Detailed analysis →'):null;
function FillerQuiz({title,note,directions,rounds,tone,pool,page}){
const {Button,Badge}=window.ScorebuddyDesignSystem_ee75f2;
const [answers,setAnswers]=React.useState({});
const [checked,setChecked]=React.useState(false);
const [aid,setAid]=React.useState(null);
if(rounds.length===0) return null;
const score=rounds.filter(r=>checked&&answers[r.key]===r.answer).length;
const header=React.createElement('div',{style:{display:'flex',justifyContent:'space-between',alignItems:'center',marginBottom:4}},
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontWeight:800,fontSize:13,color:'var(--text-heading)'}},title),
checked?React.createElement(Badge,{tone:'brand'},score+' / '+rounds.length+' correct'):null);
const noteEl=note?React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:12,color:'var(--text-muted)',margin:'0 0 10px'}},note):null;
const directionsEl=directions?React.createElement('div',{style:{background:'var(--white)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-sm)',padding:'10px 14px',marginBottom:16,display:'flex',flexDirection:'column',gap:4}},directions.map((line,li)=>React.createElement('div',{key:li,style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.5}},line))):null;
const roundEls=rounds.map((r,i)=>{
const optionButtons=r.options.map(opt=>{
const picked=answers[r.key]===opt;
const isRight=opt===r.answer;
let bg='var(--white)',border='var(--border-default)',color='var(--text-body)';
if(checked&&isRight){bg='var(--color-bg-success)';border='var(--text-success)';color='var(--text-success)';}
else if(checked&&picked&&!isRight){bg='var(--red-100)';border='var(--red-500)';color='var(--red-500)';}
else if(picked){bg='var(--navy-100)';border='var(--border-brand)';color='var(--brand-primary)';}
const style={fontFamily:'var(--font-body)',fontWeight:600,fontSize:13,padding:'8px 14px',borderRadius:'var(--radius-pill)',border:'1.5px solid '+border,background:bg,color,cursor:checked?'default':'pointer'};
return React.createElement('button',{key:opt,disabled:checked,onClick:()=>sbGuard()&&setAnswers(a=>Object.assign({},a,{[r.key]:opt})),style},opt);
});
const optionsRow=React.createElement('div',{style:{display:'flex',gap:8,flexWrap:'wrap'}},optionButtons);
const question=r.passage?React.createElement('div',{style:{marginBottom:8}},r.passage.map((line,li)=>React.createElement('div',{key:li,style:{fontFamily:'var(--font-body)',fontSize:13,color:li===r.passage.length-1?'var(--text-heading)':'var(--text-body)',fontWeight:li===r.passage.length-1?600:400,lineHeight:1.6,marginBottom:2}},line))):React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-body)',marginBottom:8}},(i+1)+'. Fill in the blank — ____ : \u201c'+r.def+'\u201d');
const detailGrid=checked?React.createElement('div',{style:{marginTop:10,display:'grid',gridTemplateColumns:'repeat(auto-fit,minmax(220px,1fr))',gap:8}},r.optionDetails.map(w=>React.createElement(WordDetail,{key:w.word,w,pool}))):null;
return React.createElement('div',{key:r.key},question,optionsRow,detailGrid);
});
const roundsBlock=React.createElement('div',{style:{display:'flex',flexDirection:'column',gap:16}},roundEls);
const actionBtn=checked?React.createElement(Button,{variant:'secondary',size:'sm',onClick:()=>{setChecked(false);setAnswers({});setAid(null);}},'Retry'):React.createElement(Button,{variant:'primary',size:'sm',onClick:()=>{if(!sbGuard())return;if(!okToSubmit(rounds.filter(r=>!answers[r.key]).length))return;setChecked(true);const tp=/:advanced$/.test(page||'')?'Contextual fill (near-synonyms)':'Word meaning';sbRecord(page,rounds.filter(r=>answers[r.key]===r.answer).length,rounds.length,rounds.map((r,i)=>({q:String(r.key).slice(0,80),n:i+1,t:tp,a:answers[r.key]||null,k:r.answer,c:answers[r.key]?(answers[r.key]===r.answer?1:0):null}))).then(setAid);}},'Check Answers ('+Object.keys(answers).length+'/'+rounds.length+' answered)');
const actionsRow=React.createElement('div',{style:{marginTop:16,display:'flex',gap:8,flexWrap:'wrap',alignItems:'center'}},actionBtn,checked?React.createElement(AnalysisLink,{id:aid}):null);
return React.createElement('div',{style:{background:tone,border:'1px solid var(--border-brand)',borderRadius:'var(--radius-md)',padding:'18px 20px',marginTop:12}},header,noteEl,directionsEl,roundsBlock,actionsRow);
}

function DocFillerQuiz({fq,page}){
const {Button,Badge}=window.ScorebuddyDesignSystem_ee75f2;
const [answers,setAnswers]=React.useState({});
const [checked,setChecked]=React.useState(false);
const [aid,setAid]=React.useState(null);
const letters=['a','b','c','d'];
const score=fq.qs.filter(q=>checked&&answers[q.n]===q.a).length;
const qEls=fq.qs.map(q=>{
const optionRows=q.o.map((opt,oi)=>{
const picked=answers[q.n]===oi;
const isRight=oi===q.a;
let bg='var(--white)',border='var(--border-default)',color='var(--text-body)',weight=500;
if(checked&&isRight){bg='var(--color-bg-success)';border='var(--text-success)';color='var(--text-success)';weight=700;}
else if(checked&&picked&&!isRight){bg='var(--red-100)';border='var(--red-500)';color='var(--red-500)';weight=700;}
else if(picked){bg='var(--navy-100)';border='var(--border-brand)';color='var(--brand-primary)';weight=700;}
return React.createElement('button',{key:oi,disabled:checked,onClick:()=>sbGuard()&&setAnswers(a=>Object.assign({},a,{[q.n]:oi})),style:{display:'flex',alignItems:'baseline',gap:10,textAlign:'left',fontFamily:'var(--font-body)',fontWeight:weight,fontSize:13,padding:'8px 12px',borderRadius:'var(--radius-sm)',border:'1px solid '+border,background:bg,color,cursor:checked?'default':'pointer',width:'100%'}},
React.createElement('span',{style:{fontWeight:700,flexShrink:0}},'('+letters[oi]+')'),opt,
checked&&isRight?React.createElement('span',{style:{marginLeft:'auto',fontWeight:800}},'✔'):null);
});
return React.createElement('div',{key:q.n,style:{marginBottom:16}},
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-body)',marginBottom:8}},
React.createElement('b',{style:{color:'var(--brand-primary)'}},q.n+'. '),
React.createElement('span',{style:{fontWeight:700,fontSize:10.5,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--brand-primary)',background:'var(--navy-100)',borderRadius:'var(--radius-sm)',padding:'2px 6px',marginRight:6}},q.t),q.p),
React.createElement('div',{style:{display:'flex',flexDirection:'column',gap:6,maxWidth:560}},optionRows));
});
const solutionsEl=checked?React.createElement('div',{style:{marginTop:18}},
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontWeight:800,fontSize:13,color:'var(--text-heading)',borderTop:'2px solid var(--brand-primary)',paddingTop:12,marginBottom:10}},'Detailed Solutions — today’s 10 words'),
React.createElement('div',{style:{display:'grid',gridTemplateColumns:'repeat(auto-fit,minmax(260px,1fr))',gap:8}},
fq.words.map((w,i)=>React.createElement('div',{key:w.w,style:{padding:'10px 12px',background:'var(--white)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-sm)'}},
React.createElement('div',{style:{display:'flex',alignItems:'baseline',gap:8,flexWrap:'wrap',marginBottom:4}},
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:14,color:'var(--text-heading)'}},(i+1)+'. '+w.w),
w.h&&React.createElement('span',{style:{fontFamily:'var(--font-body)',fontWeight:600,fontSize:12.5,color:'var(--brand-primary)'}},'('+w.h+')')),
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.55,marginBottom:6}},w.m.map(m=>'('+m.pos+') '+m.text).join('; ')),
w.s.length>0&&React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--text-success)',marginBottom:2}},'Synonyms: '+w.s.join(', ')),
w.an.length>0&&React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--red-500)'}},'Antonyms: '+w.an.join(', ')))))):null;
const actionBtn=checked?React.createElement(Button,{variant:'secondary',size:'sm',onClick:()=>{setChecked(false);setAnswers({});setAid(null);}},'Retry'):React.createElement(Button,{variant:'primary',size:'sm',onClick:()=>{if(!sbGuard())return;if(!okToSubmit(fq.qs.filter(q=>answers[q.n]===undefined).length))return;setChecked(true);sbRecord(page,fq.qs.filter(q=>answers[q.n]===q.a).length,fq.qs.length,fq.qs.map(q=>({q:String(q.n),n:q.n,t:q.t||'Vocabulary',a:answers[q.n]===undefined?null:LETTERS4[answers[q.n]],k:LETTERS4[q.a],c:answers[q.n]===undefined?null:(answers[q.n]===q.a?1:0)}))).then(setAid);}},'Check Answers ('+Object.keys(answers).length+'/'+fq.qs.length+' answered)');
return React.createElement('div',{style:{background:'var(--lavender-100)',border:'1px solid var(--border-brand)',borderRadius:'var(--radius-md)',padding:'18px 20px',marginTop:12}},
React.createElement('div',{style:{display:'flex',justifyContent:'space-between',alignItems:'center',marginBottom:4}},
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontWeight:800,fontSize:13,color:'var(--text-heading)'}},'🧩 Word Filler Quiz — this day’s 10 words'),
checked?React.createElement(Badge,{tone:'brand'},score+' / '+fq.qs.length+' correct'):null),
React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:12,color:'var(--text-muted)',margin:'0 0 14px'}},'10 questions — synonym, antonym, second-meaning and definition types, all from today’s own words. Full solutions with Hindi, synonyms and antonyms unlock after you submit.'),
qEls,solutionsEl,
React.createElement('div',{style:{marginTop:16,display:'flex',gap:8,flexWrap:'wrap',alignItems:'center'}},actionBtn,checked?React.createElement(AnalysisLink,{id:aid}):null));
}

function BasicQuiz({day,pool}){
const {Button}=window.ScorebuddyDesignSystem_ee75f2;
const words=day.words.filter(w=>w.word&&w.def);
const rounds=React.useMemo(()=>{
const other=pool.filter(w=>!words.some(dw=>dw.word===w.word));
return words.map(w=>{
const distractors=shuffle(other).slice(0,3);
const optionDetails=shuffle([w,...distractors]);
return {key:w.word,def:w.def,answer:w.word,options:optionDetails.map(o=>o.word),optionDetails};
});
},[day.day]);
return React.createElement(FillerQuiz,{page:"daily-reads:day"+day.day+":filler",title:'🧩 Word Filler Quiz — this day’s 10 words',note:'Fill each blank with the matching word. Full detail for every option \u2014 meaning, Hindi, pronunciation, synonyms, antonyms \u2014 unlocks after you submit.',rounds,tone:'var(--lavender-100)',pool});
}

function AdvancedQuiz({day,pool}){
const {Button}=window.ScorebuddyDesignSystem_ee75f2;
const words=day.words.filter(w=>w.word&&w.def);
const rounds=React.useMemo(()=>{
const source=shuffle(words.length>=10?words:shuffle(pool).slice(0,10)).slice(0,10);
return source.map((w,idx)=>{
const ranked=pool.filter(o=>o.word!==w.word).map(o=>({o,score:overlapScore(w.def,o.def)})).sort((a,b)=>b.score-a.score);
const topSimilar=ranked.filter(r=>r.score>0).slice(0,6).map(r=>r.o);
const useSimilarAsAnswer=idx%2===0&&topSimilar.length>0;
const target=useSimilarAsAnswer?topSimilar[0]:w;
const remainingPool=topSimilar.filter(o=>o.word!==target.word);
let distractors=shuffle(remainingPool).slice(0,2);
if(!useSimilarAsAnswer||!distractors.some(d=>d.word===w.word)){ if(target.word!==w.word) distractors=[w,...distractors].slice(0,3); }
while(distractors.length<3){ const extra=shuffle(pool.filter(o=>o.word!==target.word&&!distractors.some(d=>d.word===o.word))).slice(0,3-distractors.length); distractors=distractors.concat(extra); }
distractors=distractors.slice(0,3);
const optionDetails=shuffle([target,...distractors]);
const opener=idx%3===0?'have long argued':idx%3===1?'continue to insist':'now openly claim';
const cleanDef=w.def.replace(/^to\s+/,'');
const passage=['This short scenario builds context around one idea from today’s reading.','Critics of the policy '+opener+' that its stated aim — to '+cleanDef+' — hides a very different intent.','Supporters counter that the reform is being judged too harshly, and that early results already tell a fuller story.','Whichever side is right, the word below captures how observers describe the disputed claim.','\u201c...officials ____ that the numbers speak for themselves.\u201d'];
return {key:'adv-'+idx+'-'+w.word,def:target.def,answer:target.word,options:optionDetails.map(o=>o.word),optionDetails,passage};
});
},[day.day]);
const directions=['Directions: each question gives a short passage building context around one idea.','Read it, then choose the word from the 4 options that best fits the final blank.','Options mix in close, tricky near-synonyms from across the whole 180-day plan — the right answer is often a different word from the one that inspired the passage, not necessarily one of today’s original 10.','After you submit, every option shows its full meaning, Hindi translation, pronunciation, part of speech, and 3 close synonyms + 3 antonyms.'];
return React.createElement(FillerQuiz,{page:"daily-reads:day"+day.day+":advanced",title:'🔥 Advanced Word Challenge — 10 tougher fillers',note:'',directions,rounds,tone:'var(--magenta-100)',pool});
}

function WordsTable({words}){
const rows=words.map((w,i)=>React.createElement('tr',{key:i,style:{borderTop:'1px solid var(--border-default)'}},
React.createElement('td',{style:{padding:'8px 12px',fontFamily:'var(--font-display)',fontWeight:700,fontSize:13.5,color:'var(--text-heading)',whiteSpace:'nowrap'}},w.word),
React.createElement('td',{style:{padding:'8px 12px',fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.5}},w.meaning)));
return React.createElement('div',{style:{border:'1px solid var(--border-default)',borderRadius:'var(--radius-md)',overflow:'hidden',marginTop:10}},
React.createElement('table',{style:{width:'100%',borderCollapse:'collapse'}},
React.createElement('thead',null,React.createElement('tr',{style:{background:'var(--gray-50)'}},
React.createElement('th',{style:{textAlign:'left',padding:'8px 12px',fontFamily:'var(--font-body)',fontSize:11,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--text-muted)'}},'Word'),
React.createElement('th',{style:{textAlign:'left',padding:'8px 12px',fontFamily:'var(--font-body)',fontSize:11,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--text-muted)'}},'Meaning'))),
React.createElement('tbody',null,rows)));
}

function rcForms(w){w=w.toLowerCase();const f=[w,w+'s',w+'es',w+'d',w+'ed',w+'ing',w+'ly',w+'ment',w+'ments',w+'er',w+'ers',w+'ness'];
if(/e$/.test(w)){const s=w.slice(0,-1);['ing','ed','es','er','ers','ion','ions','y'].forEach(x=>f.push(s+x));}
if(/y$/.test(w)){const t=w.slice(0,-1);['ies','ied','ier','ily','iness'].forEach(x=>f.push(t+x));}
if(/[^aeiou][aeiou][bdglmnprt]$/.test(w)){const c=w.slice(-1);['ed','ing','er'].forEach(x=>f.push(w+c+x));}
return f;}
function RCPassage({day,words}){
const text=(window.DAILY_RC||{})[day.day];
if(!text) return null;
const map={};const alts=[];
words.forEach(w=>{const word=w.word;if(!word)return;rcForms(word).forEach(f=>{if(!map[f]){map[f]={word,def:w.def||w.meaning||''};alts.push(f);}});});
alts.sort((a,b)=>b.length-a.length);
const re=alts.length?new RegExp('(^|[^A-Za-z])('+alts.join('|')+')(?![A-Za-z])','gi'):null;
const renderPara=(para,pi)=>{
if(!re) return para;
const out=[];let last=0;let m;re.lastIndex=0;
while((m=re.exec(para))){const start=m.index+m[1].length;out.push(para.slice(last,start));const hit=map[m[2].toLowerCase()];
out.push(React.createElement('mark',{key:pi+'-'+start,title:hit.word+': '+hit.def,style:{background:'var(--lavender-100)',color:'var(--text-heading)',fontWeight:700,borderRadius:3,padding:'0 2px',cursor:'help'}},m[2]));
last=start+m[2].length;}
out.push(para.slice(last));return out;};
const wc=text.split(/\s+/).filter(Boolean).length;
return React.createElement('div',{style:{marginTop:14,padding:'16px 20px',background:'var(--white)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-lg)'}},
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontWeight:800,fontSize:13,color:'var(--text-heading)',borderBottom:'2px solid var(--brand-primary)',paddingBottom:8,marginBottom:12}},'📖 RC Passage — Day '+day.day+' · '+wc+' words · today’s 10 words are highlighted'),
text.split(/\n\s*\n/).map((para,pi)=>React.createElement('p',{key:pi,style:{fontFamily:'var(--font-body)',fontSize:14.5,color:'var(--text-body)',lineHeight:1.75,margin:'0 0 12px'}},renderPara(para.trim(),pi))),
React.createElement('div',{style:{borderTop:'1px solid var(--border-default)',paddingTop:10,marginTop:6,fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-muted)',lineHeight:1.6}},
React.createElement('strong',{style:{color:'var(--text-heading)'}},'Source: '),
day.href?React.createElement('a',{href:day.href,target:'_blank',rel:'noopener',style:{color:'var(--brand-primary)',textDecoration:'underline'}},day.title,' ↗'):day.title,
React.createElement('div',null,'This passage is an original text written by Scorebuddy on the theme of the source above, not an extract from it. All rights in the original work belong to its publisher.')));
}
function RealOptionGloss({g}){
return React.createElement('div',{style:{padding:'10px 12px',background:g.isCorrect?'var(--color-bg-success)':'var(--white)',border:'1px solid '+(g.isCorrect?'var(--text-success)':'var(--border-default)'),borderRadius:'var(--radius-sm)'}},
React.createElement('div',{style:{display:'flex',alignItems:'baseline',gap:8,flexWrap:'wrap',marginBottom:4}},
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:14,color:g.isCorrect?'var(--text-success)':'var(--text-heading)'}},g.word+(g.isCorrect?' ✔':'')),
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontStyle:'italic',fontSize:12,color:'var(--text-muted)'}},g.pos),
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--text-muted)'}},g.pron)),
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.5,marginBottom:6}},g.meaning),
g.synonyms&&g.synonyms.length>0&&React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--text-success)',marginBottom:2}},'Synonyms: '+g.synonyms.join(', ')),
g.antonyms&&g.antonyms.length>0&&React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11.5,color:'var(--red-500)'}},'Antonyms: '+g.antonyms.join(', ')));
}

function RealAdvancedQuiz({realDay}){
const {Button,Badge}=window.ScorebuddyDesignSystem_ee75f2;
const [answers,setAnswers]=React.useState({});
const [checked,setChecked]=React.useState(false);
const [aid,setAid]=React.useState(null);
const allQs=realDay.sections.flatMap(s=>s.questions);
const score=allQs.filter(q=>checked&&answers[q.qnum]===q.correctWord).length;
const newWordCount=allQs.filter(q=>q.isNewWord).length;
const serif={fontFamily:'var(--font-body)'};
const m=realDay.meta;
const metaLine=(label,val)=>val?React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.6}},React.createElement('b',null,label+': '),val):null;
const headerBlock=React.createElement('div',{style:{borderBottom:'2px solid var(--brand-primary)',paddingBottom:12,marginBottom:16}},
React.createElement('div',{style:{display:'flex',justifyContent:'space-between',alignItems:'center',flexWrap:'wrap',gap:8}},
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:16,color:'var(--text-heading)',letterSpacing:'.01em'}},'DAY '+realDay.day+'  —  '+(realDay.isMega?'MEGA REVISION QUIZ':'Advanced Vocabulary Quiz')),
checked?React.createElement(Badge,{tone:'brand'},score+' / '+allQs.length+' correct'):null),
React.createElement('div',{style:{marginTop:8}},metaLine('Reading',m.reading),metaLine('Genre',m.genre),metaLine('Skill focus',m.skill),metaLine('Level',m.level),metaLine('Revision of',m.revisionOf)));
const sectionEls=realDay.sections.map((sec,si)=>{
const secHeader=React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:13.5,color:'var(--on-dark)',background:'var(--brand-primary)',borderRadius:'var(--radius-sm)',padding:'8px 14px',letterSpacing:'.02em',marginBottom:10}},sec.title);
const instructionEl=sec.instruction?React.createElement('p',{style:{fontFamily:'var(--font-body)',fontStyle:'italic',fontSize:12.5,color:'var(--text-muted)',margin:'0 0 10px'}},sec.instruction):null;
const sourceEl=sec.source?React.createElement('div',{style:{fontFamily:'var(--font-body)',fontStyle:'italic',fontSize:12,color:'var(--text-muted)',marginBottom:8}},'Source: '+sec.source):null;
const passageEl=sec.passage&&sec.passage.length>0?React.createElement('div',{style:{background:'var(--gray-50)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-sm)',padding:'14px 16px',marginBottom:14}},sourceEl,sec.passage.map((line,li)=>React.createElement('p',{key:li,style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-body)',lineHeight:1.7,margin:li<sec.passage.length-1?'0 0 10px':'0'}},line))):sourceEl;
const qEls=sec.questions.map(q=>{
const letters=['a','b','c','d'];
const optionRows=q.options.map((opt,oi)=>{
const picked=answers[q.qnum]===opt;
const isRight=opt===q.correctWord;
let bg='var(--white)',border='var(--border-default)',color='var(--text-body)',weight=500;
if(checked&&isRight){bg='var(--color-bg-success)';border='var(--text-success)';color='var(--text-success)';weight=700;}
else if(checked&&picked&&!isRight){bg='var(--red-100)';border='var(--red-500)';color='var(--red-500)';weight=700;}
else if(picked){bg='var(--navy-100)';border='var(--border-brand)';color='var(--brand-primary)';weight=700;}
return React.createElement('button',{key:opt,disabled:checked,onClick:()=>sbGuard()&&setAnswers(a=>Object.assign({},a,{[q.qnum]:opt})),style:{display:'flex',alignItems:'baseline',gap:10,textAlign:'left',fontFamily:'var(--font-body)',fontWeight:weight,fontSize:13,padding:'8px 12px',borderRadius:'var(--radius-sm)',border:'1px solid '+border,background:bg,color,cursor:checked?'default':'pointer',width:'100%'}},
React.createElement('span',{style:{fontWeight:700,flexShrink:0}},'('+letters[oi]+')'),opt,
checked&&isRight?React.createElement('span',{style:{marginLeft:'auto',fontWeight:800}},'✔'):null);
});
const contextEl=q.context?React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-body)',lineHeight:1.7,margin:'0 0 6px'}},q.context):null;
const promptEl=React.createElement('div',{style:{fontFamily:'var(--font-body)',fontWeight:700,fontSize:13,color:'var(--text-heading)',margin:'0 0 8px'}},q.prompt);
return React.createElement('div',{key:q.qnum,style:{marginBottom:18}},
React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:13,color:'var(--brand-primary)',marginBottom:6}},'Q'+q.qnum+'.'),
contextEl,promptEl,
React.createElement('div',{style:{display:'flex',flexDirection:'column',gap:6,maxWidth:560}},optionRows));
});
return React.createElement('div',{key:si,style:{marginBottom:24}},secHeader,instructionEl,passageEl,React.createElement('div',null,qEls));
});
const answerKeyEl=checked?React.createElement('div',{style:{marginBottom:20}},
React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:13.5,color:'var(--text-heading)',borderTop:'2px solid var(--brand-primary)',paddingTop:14,marginBottom:10}},'ANSWER KEY  —  Day '+realDay.day),
React.createElement('div',{style:{display:'flex',gap:6,flexWrap:'wrap'}},
allQs.map(q=>React.createElement('span',{key:q.qnum,style:{fontFamily:'var(--font-body)',fontWeight:700,fontSize:12,color:'var(--text-body)',background:'var(--gray-100)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-sm)',padding:'5px 10px'}},'Q'+q.qnum+': ('+q.correctLetter+') '+q.correctWord))),
React.createElement('p',{style:{fontFamily:'var(--font-body)',fontStyle:'italic',fontSize:12.5,color:'var(--text-muted)',margin:'10px 0 0'}},'FINAL CHECK — correct answers that are listed words: '+(allQs.length-newWordCount)+'/'+allQs.length+' · correct answers NOT in the word table: '+newWordCount+'/'+allQs.length+'. Recognising the words is not enough — the context decides.')):null;
const solutionsEl=checked?React.createElement('div',null,
React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:13.5,color:'var(--text-heading)',borderTop:'2px solid var(--brand-primary)',paddingTop:14,marginBottom:4}},'DETAILED SOLUTIONS  —  Day '+realDay.day),
React.createElement('p',{style:{fontFamily:'var(--font-body)',fontStyle:'italic',fontSize:12.5,color:'var(--text-muted)',margin:'0 0 14px'}},'Every option is glossed in full. Read all four.'),
React.createElement('div',{style:{display:'flex',flexDirection:'column',gap:18}},
allQs.map(q=>React.createElement('div',{key:'sol'+q.qnum},
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontWeight:800,fontSize:13,color:'var(--text-heading)',marginBottom:8}},'Q'+q.qnum+'  · Answer: ('+q.correctLetter+') '+q.correctWord+'   ',
React.createElement('span',{style:{fontWeight:700,fontSize:11.5,color:q.isNewWord?'var(--red-500)':'var(--text-success)'}},q.isNewWord?'▸ NEW WORD — not in the word table':'▸ LISTED WORD')),
React.createElement('div',{style:{display:'grid',gridTemplateColumns:'repeat(auto-fit,minmax(240px,1fr))',gap:8,marginBottom:8}},(q.optionGlosses||[]).map(g=>React.createElement(RealOptionGloss,{key:g.word,g}))),
q.explanation?React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-body)',lineHeight:1.65,margin:0}},React.createElement('b',null,'Why ('+q.correctLetter+'): '),q.explanation):null)))):null;
const actionBtn=checked?React.createElement(Button,{variant:'secondary',size:'sm',onClick:()=>{setChecked(false);setAnswers({});setAid(null);}},'Retry'):React.createElement(Button,{variant:'primary',size:'sm',onClick:()=>{if(!sbGuard())return;if(!okToSubmit(allQs.filter(q=>!answers[q.qnum]).length))return;setChecked(true);const secOf={};realDay.sections.forEach(s=>s.questions.forEach(q=>{secOf[q.qnum]=String(s.title||'').replace(/\s*\(Questions?[^)]*\)\s*$/,'').replace(/^SECTION\s+[A-Z]\s*[—-]\s*/,'').trim()||'Advanced quiz';}));sbRecord("daily-reads:day"+realDay.day+":advanced",allQs.filter(q=>answers[q.qnum]===q.correctWord).length,allQs.length,allQs.map(q=>({q:String(q.qnum),n:q.qnum,t:secOf[q.qnum],a:answers[q.qnum]||null,k:q.correctWord,c:answers[q.qnum]?(answers[q.qnum]===q.correctWord?1:0):null}))).then(setAid);}},'Submit — Check Answers ('+Object.keys(answers).length+'/'+allQs.length+' answered)');
return React.createElement('div',{style:{background:'var(--white)',border:'1px solid var(--border-brand)',borderRadius:'var(--radius-md)',padding:'22px 24px',marginTop:12,boxShadow:'var(--shadow-md)'}},headerBlock,sectionEls,answerKeyEl,solutionsEl,React.createElement('div',{style:{marginTop:16,display:'flex',gap:8,flexWrap:'wrap',alignItems:'center'}},actionBtn,checked?React.createElement(AnalysisLink,{id:aid}):null));
}

function DailyReadsPage(){
const {Badge,Button,Tag}=window.ScorebuddyDesignSystem_ee75f2;
const [active,setActive]=React.useState(()=>{const m=+(new URLSearchParams(location.search).get('phase')||0);return m>=1&&m<=6?m-1:0;});
const [query,setQuery]=React.useState('');
const [openQuiz,setOpenQuiz]=React.useState({});
const [openAdv,setOpenAdv]=React.useState({});
const [openRC,setOpenRC]=React.useState({});
const p=PHASES[active];
const allDays=window.DAILY_READS_DAYS;
const allWords=React.useMemo(()=>allDays.flatMap(d=>d.words.filter(w=>w.word&&w.def)),[]);
let days=allDays.filter(d=>d.day>=p.range[0]&&d.day<=p.range[1]);
if(query.trim()){
const q=query.trim().toLowerCase();
days=days.filter(d=>String(d.day)===q||d.title.toLowerCase().includes(q)||d.words.some(w=>w.word.toLowerCase().includes(q)));
}
const dayVocab=React.useMemo(()=>{
const map={};
allDays.forEach(d=>{
const set=new Set();
d.words.forEach(w=>{ if(w.word) set.add(w.word.toLowerCase()); });
const realDay=(window.REAL_QUIZ_DAYS||[]).find(rd=>rd.day===d.day);
if(realDay){
realDay.words.forEach(w=>{ if(w.word) set.add(w.word.toLowerCase()); });
realDay.sections.forEach(sec=>sec.questions.forEach(q=>{ (q.options||[]).forEach(o=>{ if(o) set.add(o.toLowerCase()); }); }));
}
map[d.day]=set;
});
return map;
},[]);
const totalWords=Object.values(dayVocab).reduce((s,set)=>s+set.size,0);
const phaseWords=allDays.filter(d=>d.day>=p.range[0]&&d.day<=p.range[1]).reduce((s,d)=>s+(dayVocab[d.day]?dayVocab[d.day].size:0),0);
const allUniqueWords=React.useMemo(()=>{
const set=new Set();
Object.values(dayVocab).forEach(s=>s.forEach(w=>set.add(w)));
return set;
},[dayVocab]);
return React.createElement('div',null,
React.createElement('section',{style:{padding:'56px 48px 32px',maxWidth:1180,margin:'0 auto'}},
React.createElement(Badge,{tone:'brand'},'180-DAY PLAN'),
React.createElement('h1',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:36,color:'var(--text-heading)',margin:'16px 0 12px'}},'Daily Reads for RC'),
React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:15.5,color:'var(--text-body)',lineHeight:1.6,maxWidth:760,margin:'0 0 8px'}},"60–75 minutes a day: ~40 minutes of reading with that day's skill focus, 15 minutes on 10 exam words, and time for notes. Built for CAT VARC and IPMAT Verbal — difficulty rises phase by phase, from newspaper editorials to academic and reference prose."),
React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-muted)',lineHeight:1.6,maxWidth:760,margin:'0 0 24px'}},"Every 4th day is a revision day; days 169–180 are full revision. Word counts include every quiz option, so \"new\" words not on a day's own list still count."),
React.createElement('div',{style:{display:'flex',gap:32,flexWrap:'wrap'}},
[['180','Total days'],[totalWords.toLocaleString()+'','Words in quizzes'],['6','Phases'],[allUniqueWords.size.toLocaleString(),'Unique words']].map(s=>React.createElement('div',{key:s[1]},
React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:26,color:'var(--brand-primary)'}},s[0]),
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:12,color:'var(--text-muted)'}},s[1])))) ),
React.createElement('section',{style:{padding:'0 48px 24px',maxWidth:1180,margin:'0 auto'}},
React.createElement('div',{style:{display:'flex',gap:8,flexWrap:'wrap',marginBottom:16}},
PHASES.map((ph,i)=>React.createElement(Tag,{key:ph.key,active:active===i,onClick:()=>{setActive(i);setQuery('');}},ph.phase+' · '+ph.range[0]+'–'+ph.range[1]))),
React.createElement('input',{value:query,onChange:e=>setQuery(e.target.value),placeholder:'Search this phase by day #, title, or word…',style:{width:'100%',maxWidth:420,padding:'10px 14px',borderRadius:'var(--radius-pill)',border:'1px solid var(--border-default)',fontFamily:'var(--font-body)',fontSize:13.5,marginBottom:20}}),
React.createElement('div',{style:{background:'var(--white)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-lg)',padding:'20px 24px',display:'flex',gap:32,flexWrap:'wrap',marginBottom:28}},
React.createElement('div',null,React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--text-muted)',marginBottom:4}},'Genre'),React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:15,color:'var(--text-heading)'}},p.genre)),
React.createElement('div',null,React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--text-muted)',marginBottom:4}},'Level'),React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:15,color:'var(--text-heading)'}},p.level)),
React.createElement('div',null,React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--text-muted)',marginBottom:4}},'Words in phase'),React.createElement('div',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:15,color:'var(--text-heading)'}},phaseWords.toLocaleString())),
React.createElement('div',{style:{flex:1,minWidth:220}},React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:11,letterSpacing:'.04em',textTransform:'uppercase',color:'var(--text-muted)',marginBottom:4}},'What it builds'),React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:14,color:'var(--text-body)'}},p.builds))),
React.createElement('div',{style:{display:'flex',flexDirection:'column'}},
days.length===0&&React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:14,color:'var(--text-muted)',padding:'24px 4px'}},'No days match your search in this phase.'),
days.map(d=>{
const realDay=(window.REAL_QUIZ_DAYS||[]).find(rd=>rd.day===d.day);
const fillerDay=(window.FILLER_QUIZ_DAYS||[]).find(f=>f.day===d.day);
return React.createElement('div',{key:d.day,style:{padding:'18px 4px',borderBottom:'1px solid var(--border-default)'}},
React.createElement('div',{className:'drd-row',style:{display:'flex',gap:18}},
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:13,color:'var(--brand-primary)',background:'var(--navy-100)',borderRadius:'var(--radius-pill)',padding:'4px 10px',width:70,textAlign:'center',flexShrink:0,height:'fit-content'}},'Day '+d.day),
React.createElement('div',{className:'drd-body',style:{flex:1,minWidth:0}},
(window.DAILY_RC||{})[d.day]?React.createElement(React.Fragment,null,React.createElement('a',{id:'rc-day-'+d.day,href:'#rc-day-'+d.day,role:'button','aria-expanded':!!openRC[d.day],title:openRC[d.day]?'Hide the RC passage':'Show the RC passage',onClick:e=>{e.preventDefault();setOpenRC(o=>({...o,[d.day]:!o[d.day]}));},style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:15.5,color:'var(--brand-primary)',textDecoration:'underline',cursor:'pointer'}},d.title,openRC[d.day]?' ▴':' ▾'),openRC[d.day]&&React.createElement(RCPassage,{day:d,words:(realDay&&realDay.words.length?realDay.words:d.words.length?d.words:(fillerDay&&fillerDay.words||[]).map(fw=>({word:fw.w,def:(fw.m&&fw.m[0]&&fw.m[0].text)||''})))})):d.href?React.createElement('a',{href:d.href,target:'_blank',rel:'noopener',style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:15.5,color:'var(--brand-primary)',textDecoration:'underline'}},d.title,' ↗'):React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:15.5,color:'var(--text-heading)'}},d.title),
React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-muted)',marginTop:4}},d.focus),
realDay&&realDay.words.length>0?React.createElement(WordsTable,{words:realDay.words}):null,
(d.words.length>0||realDay||fillerDay)&&React.createElement('div',{style:{display:'flex',gap:10,alignItems:'center',marginTop:10,flexWrap:'wrap'}},
!realDay&&d.words.length>0&&React.createElement('div',{style:{display:'flex',gap:6,flexWrap:'wrap'}},
d.words.map(w=>React.createElement('span',{key:w.word,title:w.def,style:{fontFamily:'var(--font-body)',fontWeight:600,fontSize:11,color:'var(--text-body)',background:'var(--gray-100)',border:'1px solid var(--border-default)',borderRadius:'var(--radius-sm)',padding:'4px 9px',cursor:'help'}},w.word))),
(fillerDay||d.words.length>0)&&React.createElement(Button,{variant:'accent',size:'sm',onClick:()=>{setOpenQuiz(o=>({...o,[d.day]:!o[d.day]}))}},'🧩 '+(openQuiz[d.day]?'Hide Filler Quiz':'Take Filler Quiz')),
React.createElement(Button,{variant:'primary',size:'sm',onClick:()=>{setOpenAdv(o=>({...o,[d.day]:!o[d.day]}))}},'🔥 '+(openAdv[d.day]?'Hide Advanced':(realDay&&realDay.isMega?'Mega Revision Quiz':'Advanced Quiz'))))),
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:12,color:'var(--on-dark)',background:'var(--brand-primary)',borderRadius:'var(--radius-pill)',padding:'4px 10px',flexShrink:0,height:'fit-content'}},d.level)),
openQuiz[d.day]&&(fillerDay?React.createElement(DocFillerQuiz,{page:"daily-reads:day"+d.day+":filler",fq:fillerDay}):React.createElement(BasicQuiz,{day:d,pool:allWords})),
openAdv[d.day]&&(realDay?React.createElement(RealAdvancedQuiz,{realDay}):React.createElement(AdvancedQuiz,{day:d,pool:allWords})));
}))));
}
window.DailyReadsPage=DailyReadsPage;
