# -*- coding: utf-8 -*-
"""Round 246: batch add 5 Materials Science and Engineering PhD (fourth-tier U.S. + first Canadian)
- Vanderbilt Interdisciplinary Materials Science PhD (Jan 15; GRE Exempt; TOEFL 89 / IELTS 7.0 / DET 130)
- Brown MSE PhD (Dec 1; GRE optional; TOEFL iBT 90; PhD360; 5-6 yrs guaranteed funding)
- Rice MSNE PhD (Dec 4 2026 11:59pm CT priority; late through Dec 31; GRE recommended not required; GPA 3.0; $85 fee)
- Notre Dame Interdisciplinary MSE PhD (cross 7 departments; apply through home dept; 9 MSE credits; interdisciplinary mentor)
- UofT MSE PhD (Feb 1; GRE NOT required; research master's B+ 78%+ required; 2 FCE + thesis; base support up to 4 yrs)
"""
import os, re

BASE = os.path.dirname(os.path.abspath(__file__))
DET = os.path.join(BASE, "details")
os.makedirs(DET, exist_ok=True)

PROGRAMS = [
    {
        "id": "vanderbilt-ims-phd",
        "s": "vanderbilt",
        "n": "跨学科材料科学博士",
        "en": "PhD in Interdisciplinary Materials Science (Vanderbilt University, School of Engineering, Interdisciplinary Materials Science program, IMS; draws from engineering, chemistry, physics, and medicine; interdisciplinary research across VINSE shared facilities; 2026 entering cohort 10 PhD students)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; interdisciplinary coursework across engineering/chemistry/physics/medicine; dissertation; VINSE shared core facilities; full funding for PhD",
        "ddl": "Fall 2027 admission: application opens August 1, 2026. **PhD deadline January 15, 2027** (MS also January 15). Most programs release initial Fall offers by March 31 with response due April 15, 2027. Spring entry available (deadline per program).",
        "lang": "TOEFL iBT minimum 89 (Vanderbilt School of Engineering); IELTS Academic minimum 7.0; Duolingo English Test minimum 130; TOEFL iBT Home Edition and Duolingo accepted as alternatives; waivers for English-instructed degree in native-English country",
        "test": {"cls": "GRE EXEMPT (Vanderbilt School of Engineering: 'For Spring and Fall 2027 entry, the School of Engineering does not require GRE scores for admission consideration.' Graduate School institution code 1871; scores valid 5 years but not required. 3 LOR; SOP; CV; transcripts; bachelor's in engineering/physical science/chemistry/physics.)"},
        "tui": "PhD candidates receive full funding (Vanderbilt School of Engineering: 'full funding provided for PhD candidates'). Tuition scholarships available for MS/MEng students. Funding through fellowships, research assistantships, and teaching assistantships.",
        "url": "details/vanderbilt-ims-phd.html",
    },
    {
        "id": "brown-mse-phd",
        "s": "brown",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (Brown University, School of Engineering; engineering doctoral program alongside BME/CEE/ECE/Fluids & Thermal/Mechanics of Solids; PhD360 Experience supports research, teaching, travel, leadership; 5-6 years guaranteed financial support)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework + qualifying exam + prospectus + dissertation; incoming doctoral students receive 5 or 6 years guaranteed support including summers, stipend, tuition remission, health-services fee, health and dental insurance",
        "ddl": "Fall 2027 admission: **PhD deadline December 1, 2026 (EST)**. Brown Engineering PhD programs (BME, CEE, ECE, Fluids & Thermal, MSE, Mechanics of Solids) all share December 1 deadline. Decisions typically by February-March; response by April 15.",
        "lang": "TOEFL iBT minimum 90 (Brown School of Engineering; paper-based 577, computer-based 233); IELTS accepted; ETS Brown 3094; scores must arrive by department deadline",
        "test": {"cls": "GRE OPTIONAL (Brown School of Engineering: 'For all engineering doctoral and master's degree programs, GRE scores are optional.' ETS Brown 3094. 3 LOR; SOP; CV; transcripts; bachelor's in engineering/physical science. Supplemental Essay required by Graduate School, 300 words max.)"},
        "tui": "Incoming doctoral students receive five or six years of guaranteed financial support, including summers, a stipend, tuition remission, health-services fee, and health and dental insurance. Brown PhD360 Experience provides research, teaching, travel, and leadership opportunities.",
        "url": "details/brown-mse-phd.html",
    },
    {
        "id": "rice-msne-phd",
        "s": "rice",
        "n": "材料科学与纳米工程博士",
        "en": "PhD in Materials Science and NanoEngineering (Rice University, Department of Materials Science and NanoEngineering, MSNE; interdisciplinary research across nanomaterials, quantum materials, energy, biomaterials, electronics; all PhD candidates considered for financial aid; MMSNE professional master's not eligible for departmental support)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework + candidacy exam + dissertation; all PhD candidates considered for financial aid; committee review begins after deadline and continues until early April",
        "ddl": "Fall 2027 admission: opens September 1, 2026. **PhD priority deadline December 4, 2026, 11:59 pm CT** (first Friday of December; applications due for full initial review and priority funding consideration). Late applications accepted through December 31, 2026 but priority/funding consideration reduced. Spring admission deadline November 15.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test required for non-native English speakers; ETS Rice 6609; Duolingo minimum 115; waivers per Rice international policy",
        "test": {"cls": "GRE RECOMMENDED BUT NOT REQUIRED (Rice MSNE: 'General GRE is recommended but not required... PhD in Materials Science and NanoEngineering.' No minimum GRE score; absence not penalized. GPA minimum 3.0/4.0; GRE valid within 5 years. 3 LOR; SOP; CV; transcripts; application fee $85; doctoral fee waived for Texas/border-state residents.)"},
        "tui": "All PhD candidates are considered for financial aid (Rice MSNE: 'All PhD candidates are considered for financial aid.'). MMSNE professional master's students are not eligible for departmental funds. Support through research assistantships, teaching assistantships, and fellowships.",
        "url": "details/rice-msne-phd.html",
    },
    {
        "id": "notre-mse-phd",
        "s": "notre",
        "n": "跨学科材料科学与工程博士",
        "en": "Interdisciplinary PhD in Materials Science and Engineering (University of Notre Dame, College of Engineering and College of Science; students apply through one of seven participating home departments/programs - Aerospace & Mechanical Engineering, Bioengineering, Chemical & Biomolecular Engineering, Chemistry & Biochemistry, Civil & Environmental Engineering & Earth Sciences, Electrical Engineering, Physics & Astronomy; earn interdisciplinary (not dual) PhD such as 'Chemistry: Materials Science and Engineering')",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; meet home department PhD requirements; complete 9 credit hours from MSE course list; select interdisciplinary mentor; doctoral thesis with significant materials component approved by MSE Steering Committee; one-page advisor-approved research overview; candidacy and dissertation materials statements to Steering Committee",
        "ddl": "Fall 2027 admission: deadline governed by home department (typically December 15 for College of Engineering / College of Science PhD programs). Virtual Information Session for MSE PhD program December 2, 2026. Students may transfer into the MSE interdisciplinary program any semester (fall, spring, summer) after matriculation in home department.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test per Notre Dame Graduate School; minimum English language proficiency scores depend on test type; waivers for English-instructed degree",
        "test": {"cls": "GRE per home department (Notre Dame Graduate School: 'Some graduate programs require the GRE; for more details, please see the Degree Programs page.' No minimum GRE scores - only one of several criteria. 3 LOR; SOP; CV; transcripts; students holding PhD/JD/MD/other doctoral degree exempt from GRE.)"},
        "tui": "Competitive one-year MSE fellowships available. Home department PhD funding packages typically include full tuition, stipend, and health insurance through RA/TA/fellowships.",
        "url": "details/notre-mse-phd.html",
    },
    {
        "id": "uoft-mse-phd",
        "s": "ut",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (University of Toronto, Faculty of Applied Science and Engineering, Department of Materials Science and Engineering, MSE; requires prior research master's degree B+ 78%+; 2.0 FCE coursework including weekly Graduate Research Seminar and Graduate Ethics Seminar; Qualifying Exam within 12 months; guaranteed base support funding up to 4 years; collaborative specializations in Biomedical Engineering and Neuromodulation)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 2-6 years; 2.0 FCE (four half-courses) including weekly Graduate Research Seminar and Graduate Ethics Seminar; thesis; general Qualifying Exam within 12 months of initial enrollment; two-day occupational health and safety training before classes; only full-time study available",
        "ddl": "Fall 2027 (September) admission: **MASc/PhD recommended deadline February 1, 2027** (MEng: May 1 international / June 1 domestic). MEng Winter entry August 31. Applicants strongly encouraged to contact potential supervisors prior to applying. SGS application fee $125 CAD.",
        "lang": "TOEFL iBT minimum (per UofT Engineering; paper-based 580 + TWE 4); IELTS Academic minimum; MELAB accepted; waivers for English-instructed degree; only official test results forwarded directly from testing institution considered",
        "test": {"cls": "GRE NOT REQUIRED - DO NOT SUBMIT (UofT MSE: 'No. GRE scores are not required for application to graduate studies in Materials Science & Engineering at the University of Toronto. Note that while the online application provides a field for GRE scores, do not submit GRE scores.' 2 academic references required (professors who taught or supervised research); SOP; CV; transcripts; research master's B+ 78%+.)"},
        "tui": "PhD students receive guaranteed base support funding for up to four years of study (UofT MSE: 'As a PhD student, you'll receive guaranteed base support funding for up to four years of study.'). Collaborative specializations available in Biomedical Engineering and Neuromodulation. Only full-time study available.",
        "url": "details/uoft-mse-phd.html",
    },
]

DETAIL_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{school} - {en}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;max-width:960px;margin:24px auto;padding:0 20px;color:#222;line-height:1.6}}
h1{{font-size:24px;border-bottom:2px solid #1a73e8;padding-bottom:8px}}
h2{{font-size:18px;color:#1a73e8;margin-top:24px}}
.card{{background:#f8f9fa;border-left:4px solid #1a73e8;padding:12px 16px;margin:12px 0;border-radius:4px}}
.meta{{display:grid;grid-template-columns:120px 1fr;gap:6px 12px;font-size:14px}}
.meta b{{color:#555}}
ul{{margin:6px 0;padding-left:20px}}
.note{{background:#fff3cd;border-left-color:#ffc107;padding:10px 14px;margin-top:16px;font-size:13px}}
a{{color:#1a73e8}}
</style>
</head>
<body>
<h1>{school} - {en}</h1>
<div class="card">
<div class="meta">
<b>Degree</b><span>{deg}</span>
<b>Level</b><span>Research Doctorate (PhD)</span>
<b>STEM</b><span>{stem_label}</span>
<b>Duration</b><span>{dur}</span>
<b>Deadline</b><span>{ddl}</span>
<b>Language</b><span>{lang}</span>
<b>Standardized</b><span>{test_cls}</span>
<b>Funding</b><span>{tui}</span>
</div>
</div>

<h2>Program Overview</h2>
<div class="card">
{overview}
</div>

<h2>Admissions Requirements</h2>
<div class="card">
{requirements}
</div>

<h2>Research Areas</h2>
<div class="card">
{research}
</div>

<h2>Official Source</h2>
<div class="card">
{source}
</div>

<div class="note">
<strong>Note:</strong> Fourth batch of Materials Science and Engineering PhD sweep (Vanderbilt IMS, Brown MSE, Rice MSNE, Notre Dame interdisciplinary MSE, UofT MSE). Continuation from rounds 243-245 (15 U.S. programs). This round brings the MSE PhD sweep to 20 programs including the first Canadian school (UofT). GRE policy: Vanderbilt Exempt, Brown optional, Rice recommended-not-required, Notre Dame follows home department, UofT explicitly NOT required (do not submit). Deadlines: Dec 1 (Brown), Dec 4 (Rice priority), Dec 15 (Notre Dame via home dept), Jan 15 (Vanderbilt), Feb 1 (UofT). Note UofT MSE requires a prior research master's degree (B+ 78%+) - different from U.S. BS-to-PhD model. Notre Dame and Princeton both operate as interdisciplinary PhD programs where students apply through a home department. Remaining Canadian MSE PhD programs to be added next round: UBC MSE, McGill MSE, Waterloo MSE.
</div>
</body>
</html>
"""

PAGES = {
    "vanderbilt-ims-phd": {
        "school": "Vanderbilt University, School of Engineering, Interdisciplinary Materials Science (IMS)",
        "en": "PhD in Interdisciplinary Materials Science",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 5-6 years; interdisciplinary coursework across engineering/chemistry/physics/medicine; dissertation; VINSE shared core facilities; full funding for PhD",
        "ddl": "Fall 2027: application opens August 1, 2026. **PhD deadline January 15, 2027** (MS also January 15). Initial Fall offers by March 31; response due April 15, 2027. Spring entry available per program.",
        "lang": "TOEFL iBT minimum 89; IELTS Academic minimum 7.0; Duolingo English Test minimum 130; TOEFL iBT Home Edition and Duolingo accepted as alternatives",
        "test_cls": "GRE EXEMPT for Spring and Fall 2027 (Vanderbilt School of Engineering: 'does not require GRE scores for admission consideration'). Graduate School institution code 1871; scores valid 5 years but not required.",
        "tui": "PhD candidates receive full funding. Tuition scholarships for MS/MEng. Support through fellowships, RA, TA.",
        "overview": "Vanderbilt's Interdisciplinary Materials Science (IMS) graduate program draws from engineering, chemistry, physics, and medicine to offer breadth and collaboration across disciplines. The program is administered through the Vanderbilt School of Engineering and leverages VINSE (Vanderbilt Institute for Nanoscale Science and Engineering) shared core facilities. The 2026 entering cohort welcomed 10 new PhD students from diverse backgrounds including physics, chemistry, mechanical engineering, nanoengineering, and nanotechnology. The School of Engineering does not require GRE scores for Spring and Fall 2027 entry. International students must demonstrate English proficiency with TOEFL iBT minimum 89, IELTS 7.0, or Duolingo 130. The PhD deadline is January 15, 2027. PhD candidates receive full funding.",
        "requirements": "<ul><li>Bachelor's degree in engineering, physics, chemistry, materials science, or related field</li><li>GRE EXEMPT (not required for Spring/Fall 2027)</li><li>TOEFL iBT minimum 89; IELTS 7.0; Duolingo 130</li><li>TOEFL iBT Home Edition and Duolingo accepted as alternatives</li><li>Vanderbilt Graduate School online application (opens August 1)</li><li>3 letters of recommendation</li><li>Statement of purpose</li><li>CV/resume</li><li>Transcripts</li><li>**PhD deadline January 15, 2027** (Fall 2027)</li><li>MS deadline also January 15, 2027</li><li>Initial Fall offers by March 31; response due April 15</li><li>Spring entry available per program</li><li>On-campus residential (Nashville, TN)</li></ul>",
        "research": "<ul><li>Interdisciplinary materials science across engineering, chemistry, physics, medicine</li><li>Nanomaterials and nanoscale science (VINSE shared facilities)</li><li>Biomaterials and medical materials</li><li>Electronic and photonic materials</li><li>Energy materials</li><li>Thin films, membranes, polymers</li><li>Optics and photonics (SPIE scholarship recipients in program)</li></ul>",
        "source": '<a href="https://gradschool.vanderbilt.edu/admissions/apply/application-requirements-by-program/" target="_blank">Vanderbilt Graduate School: Application Requirements by Program (Interdisciplinary Materials Science MS/PhD; GRE Exempt; Fall Jan 15; Mechanical Engineering PhD Exempt Jan 1; CBE MS Exempt Mar 15)</a> | <a href="https://engineering.vanderbilt.edu/academics/graduate/?program=1128" target="_blank">Vanderbilt School of Engineering Graduate Programs (Spring/Fall 2027 no GRE required; TOEFL 89 / IELTS 7.0 / Duolingo 130; TOEFL Home and Duolingo accepted; holistic review; applications open Aug 1)</a> | <a href="https://www.vanderbilt.edu/vinse/2026/06/21/interdisciplinary-materials-science-program-welcomes-10-new-phd-students/" target="_blank">VINSE: IMS Program Welcomes 10 New PhD Students (June 2026 cohort; backgrounds in physics, chemistry, mechanical engineering, nanoengineering, nanotechnology)</a>',
    },
    "brown-mse-phd": {
        "school": "Brown University, School of Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 5-6 years; coursework + qualifying exam + prospectus + dissertation; incoming doctoral students receive 5-6 years guaranteed support including summers, stipend, tuition remission, health-services fee, health and dental insurance",
        "ddl": "Fall 2027: **PhD deadline December 1, 2026 (EST)**. Brown Engineering PhD programs (BME, CEE, ECE, Fluids & Thermal, MSE, Mechanics of Solids) all share December 1 deadline. Decisions by February-March; response by April 15.",
        "lang": "TOEFL iBT minimum 90 (paper-based 577, computer-based 233); IELTS accepted; ETS Brown 3094; scores must arrive by department deadline",
        "test_cls": "GRE OPTIONAL (Brown School of Engineering: 'For all engineering doctoral and master's degree programs, GRE scores are optional.' ETS Brown 3094. Supplemental Essay required by Graduate School, 300 words max.)",
        "tui": "Incoming doctoral students receive 5-6 years guaranteed financial support including summers, stipend, tuition remission, health-services fee, health and dental insurance. Brown PhD360 Experience: research, teaching, travel, leadership opportunities.",
        "overview": "Brown's School of Engineering offers PhD programs in Biomedical Engineering, Chemical and Environmental Engineering, Electrical and Computer Engineering, Fluids and Thermal Sciences, Materials Science and Engineering, and Mechanics of Solids and Structures - all with a December 1 deadline. The MSE PhD program offers thesis and non-thesis MS tracks as well as a 5-year integrated Sc.B./Sc.M. for Brown undergraduates. GRE scores are optional for all engineering doctoral and master's programs. The Graduate School requires a 300-word Supplemental Essay on diversity. Brown's innovative PhD360 Experience supports students both personally and professionally, providing opportunities to pursue research, teaching, travel, and leadership. Incoming doctoral students receive five or six years of guaranteed financial support including summers, stipend, tuition remission, health-services fee, and health and dental insurance. TOEFL iBT minimum is 90.",
        "requirements": "<ul><li>Bachelor's degree in engineering, physics, chemistry, materials science, or related field</li><li>GRE OPTIONAL for all engineering doctoral programs</li><li>TOEFL iBT minimum 90 (paper 577, computer 233); IELTS accepted</li><li>ETS Brown 3094</li><li>Brown Graduate School online application</li><li>3 letters of recommendation (uploaded online)</li><li>Statement of purpose</li><li>CV/resume</li><li>Transcripts (uploaded for evaluation; official upon admission)</li><li>Supplemental Essay (300 words max, diversity prompt)</li><li>**PhD deadline December 1, 2026 (EST)**</li><li>MS MSE deadline: February 1 priority / April 1 regular / November 1 spring</li><li>5-year integrated Sc.B./Sc.M. deadline May 1</li><li>On-campus residential (Providence, RI)</li></ul>",
        "research": "<ul><li>Materials science and engineering (interdisciplinary)</li><li>Biomedical engineering</li><li>Chemical and environmental engineering</li><li>Electrical and computer engineering</li><li>Fluids and thermal sciences</li><li>Mechanics of solids and structures</li><li>Electronic and magnetic materials; kinetic processes; electron microscopy; atomistic modeling</li></ul>",
        "source": '<a href="https://engineering.brown.edu/graduate/programs-and-deadlines" target="_blank">Brown Engineering Programs and Deadlines (PhD MSE Dec 1; PhD BME/CEE/ECE/Fluids/Mechanics all Dec 1; MS MSE Feb 1 priority / Apr 1 regular / Nov 1 spring; 5-year ScB/SM May 1)</a> | <a href="https://engineering.brown.edu/graduate/admissions/frequently-asked-questions" target="_blank">Brown Engineering Graduate FAQ (GRE optional for all engineering doctoral/master\'s; ETS code 3094; TOEFL 577 paper / 233 computer / 90 iBT; transcripts evaluation then official upon admission)</a> | <a href="https://graduateschool.brown.edu/?page=34" target="_blank">Brown Graduate School (PhD360 Experience; incoming doctoral students receive 5-6 years guaranteed support including summers, stipend, tuition remission, health-services fee, health/dental insurance; Office of University Postdoctoral Affairs)</a>',
    },
    "rice-msne-phd": {
        "school": "Rice University, Department of Materials Science and NanoEngineering (MSNE)",
        "en": "PhD in Materials Science and NanoEngineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 5-6 years; coursework + candidacy exam + dissertation; all PhD candidates considered for financial aid; committee review begins after deadline and continues until early April",
        "ddl": "Fall 2027: opens September 1, 2026. **PhD priority deadline December 4, 2026, 11:59 pm CT** (first Friday of December; for full initial review and priority funding). Late applications accepted through December 31, 2026 but priority/funding reduced. Spring admission deadline November 15.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test required for non-native English speakers; ETS Rice 6609; Duolingo minimum 115",
        "test_cls": "GRE RECOMMENDED BUT NOT REQUIRED (Rice MSNE: 'General GRE is recommended but not required... PhD in Materials Science and NanoEngineering.' No minimum GRE score; valid within 5 years. GPA minimum 3.0/4.0. Application fee $85; doctoral fee waived for Texas/border-state residents.)",
        "tui": "All PhD candidates are considered for financial aid. MMSNE professional master's students are not eligible for departmental funds. Support through RA/TA/fellowships.",
        "overview": "Rice University's Department of Materials Science and NanoEngineering (MSNE) offers MMSNE (professional master's) and PhD programs. The PhD program is research-oriented; all PhD candidates are considered for financial aid. The MMSNE professional master's students are not eligible for financial support from department funds. The priority application deadline is December 4, 2026 at 11:59 pm Central Time (first Friday of December), for full initial review and priority funding consideration. Late applications are accepted through December 31, 2026 but receive lower priority for funding. The GRE is recommended but not required. Minimum GPA is 3.0/4.0. The application fee is $85; doctoral program fee is waived for residents of Texas and bordering states (Arkansas, Louisiana, Oklahoma, New Mexico). Review begins after the deadline and continues until early April; decisions sent by email.",
        "requirements": "<ul><li>Bachelor's degree in engineering, physics, chemistry, materials science, or related field</li><li>GPA minimum 3.0/4.0 (or equivalent)</li><li>GRE RECOMMENDED BUT NOT REQUIRED (no minimum score; valid within 5 years)</li><li>TOEFL iBT / IELTS / Duolingo required for non-native English speakers</li><li>Duolingo minimum 115; ETS Rice 6609</li><li>Rice Graduate and Postdoctoral Studies online application (opens ~September 1)</li><li>3 letters of recommendation</li><li>Statement of purpose</li><li>CV/resume</li><li>Transcripts</li><li>Application fee $85 (doctoral fee waived for Texas/border-state residents)</li><li>**PhD priority deadline December 4, 2026, 11:59 pm CT**</li><li>Late applications through December 31, 2026 (lower funding priority)</li><li>Spring admission deadline November 15</li><li>On-campus residential (Houston, TX)</li></ul>",
        "research": "<ul><li>Materials science and nanoengineering (interdisciplinary)</li><li>Nanomaterials and nanodevices</li><li>Quantum materials</li><li>Energy materials (batteries, solar, thermoelectrics)</li><li>Biomaterials and biomedical materials</li><li>Electronic materials and 2D materials</li><li>Computational materials science</li></ul>",
        "source": '<a href="https://msne.rice.edu/academics/graduate-programs/graduate-admissions" target="_blank">Rice MSNE Graduate Admissions (Fall opens Sep 1 / closes Dec 4 11:59pm CT priority; late through Dec 31; Spring opens Sep 1 / closes Nov 15; GPA 3.0/4.0; GRE recommended not required; TOEFL as required)</a> | <a href="https://graduate.rice.edu/admissions/application-faq" target="_blank">Rice Graduate Application FAQ (General GRE recommended but not required for PhD in Materials Science and NanoEngineering; strongly recommended for MCEE/MME/MS Environmental Analysis/ME/PhD Chemistry/Civil/Environmental/Statistics; required only for PhD Economics and Political Science)</a> | <a href="https://graduate.rice.edu/admissions/qualifications" target="_blank">Rice Graduate Qualifications (GPA minimum 3.0/4.0; ETS Rice 6609; GRE valid 5 years; Duolingo minimum 115; application fee $85; doctoral fee waived for Texas/border-state residents)</a>',
    },
    "notre-mse-phd": {
        "school": "University of Notre Dame, Interdisciplinary Materials Science and Engineering PhD",
        "en": "Interdisciplinary PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 5-6 years; meet home department PhD requirements; complete 9 credit hours from MSE course list; select interdisciplinary mentor; doctoral thesis with significant materials component approved by MSE Steering Committee; one-page advisor-approved research overview; candidacy and dissertation materials statements to Steering Committee",
        "ddl": "Fall 2027: deadline governed by home department (typically December 15 for College of Engineering / College of Science PhD programs). Virtual Information Session December 2, 2026. Students may transfer into MSE interdisciplinary program any semester (fall, spring, summer) after matriculation in home department.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo per Notre Dame Graduate School; minimum English proficiency scores depend on test; waivers for English-instructed degree",
        "test_cls": "GRE per home department (Notre Dame Graduate School: 'Some graduate programs require the GRE; for more details, please see the Degree Programs page.' No minimum GRE scores - one of several criteria. Applicants holding PhD/JD/MD/other doctoral degree exempt from GRE.)",
        "tui": "Competitive one-year MSE fellowships available. Home department PhD funding typically includes full tuition, stipend, health insurance through RA/TA/fellowships.",
        "overview": "Notre Dame's Materials Science and Engineering doctoral program is a distinctive interdisciplinary program representing seven departments and programs in the College of Engineering and College of Science: Aerospace & Mechanical Engineering, Bioengineering, Chemical & Biomolecular Engineering, Chemistry & Biochemistry, Civil & Environmental Engineering & Earth Sciences, Electrical Engineering, and Physics & Astronomy. Students apply through one of these home departments and follow that department's application process and deadline. After matriculation, they may transfer into the interdisciplinary MSE program any semester. The MSE requirements include: meeting home department PhD requirements, completing 9 credit hours from the MSE course list, selecting an interdisciplinary mentor, and completing a doctoral thesis with a significant materials component approved by the MSE Steering Committee. Students earn an interdisciplinary (not dual) PhD such as 'Chemistry: Materials Science and Engineering' or 'Electrical Engineering: Materials Science and Engineering'. Research areas include semiconductors, quantum matter, polymers, biomaterials, and actinides.",
        "requirements": "<ul><li>Bachelor's or master's degree in engineering, physics, chemistry, materials science, or related field</li><li>Apply through one of 7 home departments: Aerospace & Mechanical, Bioengineering, Chemical & Biomolecular, Chemistry & Biochemistry, CEEES, Electrical Engineering, Physics & Astronomy</li><li>GRE per home department (no minimum; some programs require)</li><li>TOEFL iBT / IELTS / Duolingo per Graduate School</li><li>Notre Dame Graduate School online application</li><li>3 letters of recommendation</li><li>Statement of purpose</li><li>CV/resume</li><li>Transcripts</li><li>**Deadline per home department** (typically December 15 for Fall 2027)</li><li>After matriculation: 9 credit hours MSE courses; interdisciplinary mentor; thesis with materials component</li><li>One-page advisor-approved research overview to Steering Committee</li><li>Candidacy and dissertation materials statements to Steering Committee</li><li>Virtual Information Session December 2, 2026</li><li>On-campus residential (Notre Dame, IN)</li></ul>",
        "research": "<ul><li>Semiconductor materials (laser-based characterization)</li><li>Quantum matter and quantum materials</li><li>Polymers and soft matter</li><li>Biomaterials</li><li>Actinides and nuclear materials</li><li>Interdisciplinary collaboration across 7 departments</li><li>Materials for energy, electronics, healthcare</li></ul>",
        "source": '<a href="https://mse.nd.edu/doctoral-program/" target="_blank">Notre Dame MSE Doctoral Program (interdisciplinary across 7 departments; 9 credit hours MSE courses; interdisciplinary mentor; thesis with materials component approved by Steering Committee; interdisciplinary not dual PhD; one-year MSE fellowships)</a> | <a href="https://mse.nd.edu/doctoral-program/faqs/" target="_blank">Notre Dame MSE FAQ (apply through participating home department; deadlines vary by department; transfer into MSE any semester; degree e.g. Chemistry: Materials Science and Engineering)</a> | <a href="https://research.nd.edu/news-and-events/events/2026/11/13/information-session-for-materials-science-and-engineering-phd-program/" target="_blank">Notre Dame Research: MSE PhD Information Session (Nov 13, 2026; 7 participating departments; transfer while staying in home department; contact mse-list@nd.edu)</a>',
    },
    "uoft-mse-phd": {
        "school": "University of Toronto, Department of Materials Science and Engineering (MSE)",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 2-6 years; 2.0 FCE (four half-courses) including weekly Graduate Research Seminar and Graduate Ethics Seminar; thesis; general Qualifying Exam within 12 months of initial enrollment; two-day occupational health and safety training; only full-time study available",
        "ddl": "Fall 2027 (September): **MASc/PhD recommended deadline February 1, 2027**. MEng: May 1 international / June 1 domestic. MEng Winter entry August 31. Applicants strongly encouraged to contact potential supervisors prior to applying. SGS application fee $125 CAD.",
        "lang": "TOEFL iBT minimum (paper-based 580 + TWE 4); IELTS Academic minimum; MELAB accepted; waivers for English-instructed degree; only official test results forwarded directly from testing institution considered",
        "test_cls": "GRE NOT REQUIRED - DO NOT SUBMIT (UofT MSE: 'No. GRE scores are not required for application to graduate studies in Materials Science & Engineering at the University of Toronto. Note that while the online application provides a field for GRE scores, do not submit GRE scores.' 2 academic references; SOP; CV; transcripts; research master's B+ 78%+.)",
        "tui": "PhD students receive guaranteed base support funding for up to four years of study. Collaborative specializations available in Biomedical Engineering and Neuromodulation. Only full-time study available.",
        "overview": "The University of Toronto's Department of Materials Science and Engineering (MSE) offers MEng (professional), MASc (research master's), and PhD degrees. The PhD program requires successful completion of a research master's degree in engineering with an overall average of at least B+ (78%+) from an accredited institution. Current MASc students within the department may fast-track into the PhD before completing MASc requirements. The PhD program of study normally includes 2.0 FCE (four half-courses) including the weekly Graduate Research Seminar and the Graduate Ethics Seminar, plus a thesis. Within 12 months of initial enrollment, all PhD students must pass a general Qualifying Exam based on coursework and background knowledge. PhD candidates typically take between two and six years to complete. Only full-time study is available. All students must complete a two-day intensive occupational health and safety training program before classes begin. GRE scores are not required and should not be submitted. The recommended application deadline for MASc/PhD is February 1. PhD students receive guaranteed base support funding for up to four years. Collaborative specializations are available in Biomedical Engineering and Neuromodulation.",
        "requirements": "<ul><li>Successful completion of a research master's degree in engineering, overall average at least B+ (78%+) from accredited institution</li><li>Current UofT MASc students may fast-track into PhD</li><li>GRE NOT REQUIRED - do not submit GRE scores</li><li>TOEFL iBT / IELTS / MELAB required for non-native English speakers</li><li>Paper-based TOEFL minimum 580 + TWE 4</li><li>Only official test results forwarded directly from testing institution considered</li><li>SGS online application (fee $125 CAD)</li><li>2 academic references (professors who taught or supervised research; colleagues/employers/other students not acceptable)</li><li>Statement of purpose</li><li>CV/resume</li><li>Transcripts</li><li>**MASc/PhD recommended deadline February 1, 2027** (Fall 2027 September entry)</li><li>MEng deadline: May 1 international / June 1 domestic</li><li>Contact potential supervisors prior to applying</li><li>Two-day occupational health and safety training before classes</li><li>Qualifying Exam within 12 months of initial enrollment</li><li>Only full-time study available</li><li>On-campus residential (Toronto, Ontario, Canada)</li></ul>",
        "research": "<ul><li>Sustainable energy (emphasis area)</li><li>Biomaterials and biomedical materials (collaborative specialization)</li><li>Neuromodulation (collaborative specialization)</li><li>Metals, ceramics, polymers, electronic materials</li><li>Materials for energy and sustainability</li><li>Computational materials science</li><li>Interdisciplinary collaboration across Engineering and Medicine</li></ul>",
        "source": '<a href="http://mse.utoronto.ca/future/graduate/admissions/" target="_blank">UofT MSE Admission Requirements (PhD requires research master\'s B+ 78%+; GRE NOT required - do not submit; 2 academic references; English language facility; TOEFL paper 580/TWE 4; MEng BASc B 73%+; MASc BASc B+ 78%+)</a> | <a href="http://mse.utoronto.ca/future/graduate/phd/" target="_blank">UofT MSE Doctor of Philosophy (research master\'s required; fast-track for current MASc; 2.0 FCE incl. weekly Graduate Research Seminar and Graduate Ethics Seminar; Qualifying Exam within 12 months; thesis; 2-6 years; guaranteed base support up to 4 years; full-time only)</a> | <a href="https://www.sgs.utoronto.ca/programs/materials-science-and-engineering/" target="_blank">UofT SGS: Materials Science and Engineering (MASc/PhD Fall entry Feb 1; MEng Winter Aug 31 / Fall May 1 / Fall Jun 1; minimum admission average per SGS; TOEFL iBT minimum per department)</a> | <a href="https://gradstudies.engineering.utoronto.ca/admissions/how-to-apply/" target="_blank">UofT Engineering Graduate How to Apply (SGS application fee $125 CAD; MASc/PhD recommend contacting supervisor before applying; MEng May 1 international / Jun 1 domestic)</a>',
    },
}

# Write detail pages
for p in PROGRAMS:
    key = p["id"]
    d = PAGES[key]
    html = DETAIL_TEMPLATE.format(
        school=d["school"], en=d["en"], deg=d["deg"], stem_label=d["stem_label"],
        dur=d["dur"], ddl=d["ddl"], lang=d["lang"], test_cls=d["test_cls"], tui=d["tui"],
        overview=d["overview"], requirements=d["requirements"],
        research=d["research"], source=d["source"],
    )
    path = os.path.join(DET, key + ".html")
    with open(path, "w", encoding="utf-8") as f:
        f.write(html)
    print(f"Wrote: {key}.html")

# Append PROGRAMS
idx_path = os.path.join(BASE, "index_main.html")
with open(idx_path, "r", encoding="utf-8") as f:
    html = f.read()

def build_entry(p):
    return ('{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},'
            'dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test_cls}"}},'
            'tui:"{tui}",url:"{url}"}}').format(
        id=p["id"], s=p["s"], n=p["n"], en=p["en"], deg=p["deg"], lvl=p["lvl"],
        stem=p["stem"], dur=p["dur"], ddl=p["ddl"], lang=p["lang"],
        test_cls=p["test"]["cls"].replace('"', "'"),
        tui=p["tui"].replace('"', "'"), url=p["url"],
    )

new_entries = ",\n".join(build_entry(p) for p in PROGRAMS)

m = re.search(r'const\s+PROGRAMS\s*=\s*\[', html)
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[': depth += 1
    elif c == ']': depth -= 1
    i += 1
insert_pos = i - 1
prefix = html[:insert_pos].rstrip()
suffix = html[insert_pos:]
if prefix.endswith('{'):
    new_block = prefix + "\n" + new_entries + "\n" + suffix
else:
    new_block = prefix + ",\n" + new_entries + "\n" + suffix

# Append VD on new_block (re-locate to avoid offset)
vd_entries = ",\n".join(f'"{p["url"]}"' for p in PROGRAMS)
m2 = re.search(r'VERIFIED_DETAILS\s*=\s*new\s+Set\s*\(\s*\[', new_block)
vstart = m2.end()
vdepth = 1
j = vstart
while j < len(new_block) and vdepth > 0:
    c = new_block[j]
    if c == '[': vdepth += 1
    elif c == ']': vdepth -= 1
    j += 1
vinsert_pos = j - 1
vprefix = new_block[:vinsert_pos].rstrip()
vsuffix = new_block[vinsert_pos:]
if vprefix.endswith(','):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
elif vprefix.endswith('['):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
else:
    new_block = vprefix + ",\n" + vd_entries + "\n" + vsuffix

with open(idx_path, "w", encoding="utf-8") as f:
    f.write(new_block)

print(f"Appended {len(PROGRAMS)} PROGRAMS entries and {len(PROGRAMS)} VD entries")
print(f"Done. File size: {os.path.getsize(idx_path)}")
