# -*- coding: utf-8 -*-
"""Round 243: batch add 5 Materials Science and Engineering PhD (top-tier U.S. sweep)
- MIT DMSE PhD (Dec 1, $90; GRE NOT accepted since Fall 2024; TOEFL 100/IELTS 7/DET 135)
- Stanford MSE PhD (Dec 1 2026; $125; GRE not required and not reviewed; TOEFL PhD 100)
- UC Berkeley MSE PhD (Dec 1 2026 8:59pm PST; GRE Optional for 2026-27, REQUIRED starting 2027-28 entry)
- UIUC MatSE PhD (Dec 1; $70/$90; GRE optional/waived; TOEFL 103/IELTS 7.5; Grainger 5-yr guarantee)
- Georgia Tech MSE PhD (Dec 15; $75/$85; GRE not required; TOEFL 100 w/ 26 speaking; 3 core courses)
"""
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": "mit-mse-phd",
        "s": "mit",
        "n": "材料科学与工程博士",
        "en": "PhD / ScD in Materials Science and Engineering (Massachusetts Institute of Technology, School of Engineering, Department of Materials Science and Engineering, DMSE; thesis-based; MS may be earned en route; interdisciplinary programs: Archaeology & Archaeological Materials, Program in Polymers and Soft Matter, Technology and Policy, Computational Science and Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5 years typical; PhD/ScD awarded interchangeably by School of Engineering; qualifying procedure; master's may be bypassed; interdisciplinary tracks: AAM / PPSM / TPP / CSE; admission criteria same for MS and PhD",
        "ddl": "Fall (September) 2027 admission: application opens September 1, 2026. **Application deadline December 1, 2026, 23:59 EST**. Application fee $90. Decisions late Jan-early Feb 2027; Visit Days late Feb-early March; decision deadline April 15, 2027.",
        "lang": "TOEFL iBT minimum 100 (iBT MyBest 5) / IELTS Academic minimum 7.0 / Duolingo DET minimum 135; ETS MIT Graduate code 3514; scores must be less than 2 years old by application deadline; automatic exemption per MIT eligibility rules",
        "test": {"cls": "GRE NOT ACCEPTED (MIT DMSE: 'Effective the Fall 2024 admissions cycle, the department will not accept GRE scores as supplementary material.' The Department does not accept GRE scores and will not consider them in evaluation; if scores were shared in other MIT applications, they will not be visible to the review committee. 3 LOR; short-answer essays (150 words each: why materials science / why DMSE); transcripts; research/teaching/work experience; awards/fellowships; publications/presentations)."},
        "tui": "MIT DMSE PhD students in good standing receive full funding (tuition + stipend + health insurance) through research assistantships, teaching assistantships, and fellowships. Application fee $90. DAAP volunteer mentor program for underrepresented applicants.",
        "url": "details/mit-mse-phd.html",
    },
    {
        "id": "stanford-mse-phd",
        "s": "stanford",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (Stanford University, School of Engineering, Department of Materials Science and Engineering, MSE; terminal MS is a separate degree; PhD focuses on advanced coursework + in-depth thesis research; no thesis required for MS)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years typical; PhD program: advanced coursework + in-depth thesis research; students with undergrad or master's in materials science, physics, chemistry, or engineering welcome; all PhD students in good standing receive financial support",
        "ddl": "Autumn (Fall) 2027 admission: application opens mid-September 2026. **PhD application deadline December 1, 2026** (MS deadline January 12, 2027). Application fee $125. PhD decisions released by end of January 2027; Visit Days February 25-27, 2027; decision deadline April 15, 2027.",
        "lang": "TOEFL iBT required for international applicants whose first language is not English; Stanford PhD minimum TOEFL iBT 100 (MS minimum 89); ETS Stanford 4701; scores must be sent by application deadline; Stanford central Graduate Admissions processes waivers (department does not process)",
        "test": {"cls": "GRE NOT REQUIRED AND NOT REVIEWED (Stanford MSE: 'Students who wish to apply for admission to our graduate (PhD and MS) program are not required to take the GRE or submit a GRE score report as part of their application process. We will not review any GRE scores submitted.' 3-6 LOR (minimum 3, maximum 6); SOP; unofficial transcripts; resume; identify four faculty of interest; fee $125)."},
        "tui": "All PhD students in good standing receive financial support including living stipend/salary, full tuition, and health insurance subsidy. Application fee $125; fee waivers processed by Stanford central Graduate Admissions, not by MSE.",
        "url": "details/stanford-mse-phd.html",
    },
    {
        "id": "berkeley-mse-phd",
        "s": "berkeley",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (UC Berkeley, College of Engineering, Department of Materials Science and Engineering; MS/PhD track; MEng is a separate professional master's; 5th-year BS/MS is restricted to current UCB undergrads; designated emphases available: CCS, CGB, CSE, Energy Science, Nanoscale Science)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "PhD typically ~5-6 years (3 years after MS); core courses: Thermodynamics 201A, Kinetics/Phase Diagrams 201B, Structure and Bonding 202 (12 units minimum); minor 6 units minimum; elective 3 units minimum; total 21 units minimum; GSI teaching requirement; Preliminary Exam; Qualifying Exam; dissertation",
        "ddl": "Fall 2027 admission: **December 1, 2026, 8:59 pm Pacific Standard Time** (MS/PhD track and PhD; MEng deadline January 14, 2027; 5th-year BS/MS December 1, 2026). Application available early September; all materials must be submitted by deadline.",
        "lang": "TOEFL exam scores required for international applicants whose native language is not English; minimum Berkeley Graduate Division requirements; ETS UC Berkeley 4833; scores valid 2 years",
        "test": {"cls": "GRE OPTIONAL FOR 2026-27 CYCLE (entering Fall 2027). **IMPORTANT: Starting with admissions cycle 2027-28 (entering Fall 2028), the GRE will be required.** No minimum GRE score; no statistics kept on average GRE scores; holistic review. Minimum GPA 3.2 (B) in undergraduate; 3 LOR; SOP; resume; transcripts; bachelor's degree conferred prior to enrollment."},
        "tui": "Vast majority of Berkeley MSE PhD students working toward PhD have tuition, campus fees, insurance, and stipend covered by research/teaching assistantships and fellowships. MEng is self-funded professional degree. Designated emphases in CCS / CGB / CSE / Energy Science / Nanoscale Science available.",
        "url": "details/berkeley-mse-phd.html",
    },
    {
        "id": "uiuc-matse-phd",
        "s": "illinois",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (University of Illinois Urbana-Champaign, Grainger College of Engineering, Department of Materials Science and Engineering, MatSE; direct BS-to-PhD entry allowed; MS may be earned en route; 5-year funding guarantee under Grainger Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years typical; direct BS-to-PhD entry allowed; MS may be earned en route; Qualifying Exam (first-semester planning document; must be passed by end of 4th semester); Preliminary Exam (by end of 6th semester); dissertation; minimum GPA 3.0; students choose advisor within first month (by end of September)",
        "ddl": "Fall 2027 admission: **PhD deadline December 1, 2026** (MS deadline February 1, 2027). Spring admission only by MatSE faculty request. Application fee $70 domestic / $90 international. Program code: PhD 10KS0130PHD, MS 10KS0130MS. Decisions Feb-March for PhD, March-April for MS.",
        "lang": "TOEFL iBT minimum 103 / IELTS Academic minimum 7.5 (full status admission); ETS UIUC 1836; limited-status admission rarely offered and requires EPT test + ESL courses in first two semesters; scores valid 2 years",
        "test": {"cls": "GRE OPTIONAL (WAIVED). 'The GRE Score is optional (waived). GRE scores can be submitted if you feel it will help your overall application; however, submission will not give review priority; not submitting will not negatively impact application.' No minimum score; typical admitted scores above 80th percentile Quant, 70th Verbal, 90th Analytical (admission distribution, not threshold). 3 LOR; 1-page SOP; resume; transcripts; minimum GPA 3.0; average incoming GPA 3.65."},
        "tui": "Grainger Engineering Five-Year PhD Funding Guarantee: PhD students in first five years of enrollment are guaranteed a funded appointment for fall and spring (full tuition waiver + stipend); summer appointments based on eligibility. RA/TA/fellowship packages; 98% of PhD students secure employment or additional education post-graduation. Application fee $70 domestic / $90 international; department does not provide fee waivers in most cases.",
        "url": "details/uiuc-matse-phd.html",
    },
    {
        "id": "gatech-mse-phd",
        "s": "gatech",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (Georgia Institute of Technology, College of Engineering, School of Materials Science and Engineering; PhD admits direct from BS or MS; MS thesis requires faculty advisor; Bioengineering and Computational Science and Engineering dual doctorates available)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "31 credit hours for direct-from-BS PhD; 25 credit hours for direct-from-MS PhD; 3 required core courses: MSE 6411 Thermodynamics, MSE 6402, MSE 6768; 12 hours MSE electives (BS track) or 6 hours (MS track); 9 hours in approved minor; Technical Communications (1 credit); qualifying exam; dissertation defense; minimum GPA 3.0; TA duties required of all GRA students",
        "ddl": "Fall 2027 admission: **December 15, 2026**. Spring admission only by special circumstance (September 15). Application fee $75 domestic / $85 international. Decisions March-April 2027; majority admitted for fall; no transfer students accepted.",
        "lang": "TOEFL iBT minimum 100 with minimum 19 in each category AND minimum 26 in speaking; IELTS Academic minimum overall 7.0 (Reading 6.5, Listening 6.5, Speaking 6.5, Writing 5.5); ETS Georgia Tech 5248; scores must be no more than 2 years old; U.S. degree may be exempted",
        "test": {"cls": "GRE NOT REQUIRED (Georgia Tech MSE: 'MSE no longer requires the Graduate Record Exam (GRE) general test scores of graduate applicants.' 3 LOR; resume; transcripts; minimum undergraduate GPA 3.2 for PhD (3.0 for MS); average admitted GPA 3.6 over past 10 years. No transfer students. International students without funding must show ~$70,000 USD first-year cost for I-20.)"},
        "tui": "PhD admissions generally granted with tuition waivers and financial assistance in the form of graduate research assistantships (GRA). MS thesis students must first identify a faculty advisor willing to advise the thesis and cover research costs before being considered. Application fee $75 domestic / $85 international.",
        "url": "details/gatech-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> Research-oriented PhD in Materials Science and Engineering at five top-tier U.S. universities (MIT DMSE, Stanford MSE, UC Berkeley MSE, UIUC MatSE, Georgia Tech MSE). Key trend: four of five do not require or review GRE (MIT DMSE does not accept GRE since Fall 2024; Stanford MSE not required and not reviewed; UIUC MatSE optional/waived; Georgia Tech MSE no longer requires GRE). UC Berkeley MSE is the outlier: GRE is optional for 2026-27 cycle (entering Fall 2027) but will be REQUIRED starting 2027-28 cycle (entering Fall 2028). All five programs offer full funding to PhD students (tuition + stipend + health insurance) through RA/TA/fellowships. Deadlines cluster December 1 (MIT/Stanford/Berkeley/UIUC) with Georgia Tech December 15. Combined with rounds 240-242 (14 Chemical Engineering PhDs), this round begins the Materials Science PhD sweep.
</div>
</body>
</html>
"""

PAGES = {
    "mit-mse-phd": {
        "school": "MIT Department of Materials Science and Engineering (DMSE)",
        "en": "PhD / ScD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD) / Doctor of Science (ScD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "5 years typical; PhD/ScD awarded interchangeably by School of Engineering; qualifying procedure; master's may be bypassed; interdisciplinary tracks: AAM / PPSM / TPP / CSE; admission criteria same for MS and PhD",
        "ddl": "Fall 2027 admission: opens September 1, 2026. **Deadline December 1, 2026, 23:59 EST**. Fee $90. Decisions late Jan-early Feb 2027; Visit Days late Feb-early March; decision deadline April 15, 2027.",
        "lang": "TOEFL iBT minimum 100 / IELTS Academic minimum 7.0 / Duolingo DET minimum 135; ETS MIT Graduate 3514; scores less than 2 years old; automatic exemption per MIT eligibility",
        "test_cls": "GRE NOT ACCEPTED (MIT DMSE since Fall 2024: 'will not accept GRE scores as supplementary material.' Scores not visible to review committee. 3 LOR; short-answer essays; transcripts; research/teaching/work experience; awards; publications).",
        "tui": "MIT DMSE PhD students in good standing receive full funding (tuition + stipend + health insurance) through RA/TA/fellowships. Fee $90. DAAP volunteer mentor program for underrepresented applicants.",
        "overview": "The MIT Department of Materials Science and Engineering (DMSE) offers SM, PhD, and ScD degrees. The PhD and ScD are awarded interchangeably by the School of Engineering; except in biology, cognitive science, neuroscience, medical engineering, and medical physics, the coursework and expectations are the same. DMSE graduate students can pursue interdisciplinary programs: Archaeology and Archaeological Materials (AAM), Program in Polymers and Soft Matter (PPSM), Technology and Policy Program (TPP), and Computational Science and Engineering (CSE). MIT has a qualifying procedure for the doctoral degree: even if a student has already earned an SM elsewhere, they are admitted as an SM student with the option to bypass the master's and proceed to the PhD. Admission criteria are the same for MS and PhD. The application opens September 1 and is due December 1 at 23:59 EST. A DMSE Application Assistance Program (DAAP) pairs underrepresented applicants with graduate student mentors.",
        "requirements": "<ul><li>Bachelor's degree in materials science, physics, chemistry, or engineering</li><li>GRE NOT ACCEPTED (MIT DMSE since Fall 2024; scores will not be visible to review committee)</li><li>TOEFL iBT 100 / IELTS 7.0 / Duolingo DET 135; ETS 3514; scores less than 2 years old</li><li>MIT online application</li><li>$90 application fee</li><li>3 letters of recommendation (notify recommenders by October 1)</li><li>Short-answer essays (150 words each: why materials science / why DMSE)</li><li>Transcripts</li><li>Research/teaching/work experience</li><li>Awards/fellowships/honors</li><li>Publications (published or in progress)</li><li>Presentations at scientific conferences</li><li>**Deadline December 1, 2026, 23:59 EST**</li><li>Interdisciplinary applicants (TPP, CSE) must also complete that program's application</li><li>On-campus residential (Cambridge, MA)</li></ul>",
        "research": "<ul><li>Archaeological materials</li><li>Biomedical materials</li><li>Computational materials science and engineering</li><li>Electronic, photonic, and magnetic materials</li><li>High-performance structural materials and alloys</li><li>Materials for energy and the environment</li><li>Materials economics</li><li>Molecular and polymeric materials</li><li>Nanotechnology, nanodevices, and nanomaterials</li><li>Interdisciplinary: AAM, PPSM, TPP, CSE</li></ul>",
        "source": '<a href="https://dmse.mit.edu/education/graduate-program/applying/" target="_blank">MIT DMSE Applying (Dec 1 deadline 23:59 EST; $90 fee; 3 LOR; short-answer essays; GRE not accepted since Fall 2024; DAAP mentor program; Dec-Feb review, Jan faculty interviews, late Jan-early Feb decisions, late Feb-early March visit days, April 15 decision deadline)</a> | <a href="https://oge.mit.edu/programs/materials-science-and-engineering/" target="_blank">MIT OGE: Materials Science and Engineering (opens Sep 1; Dec 1 deadline; $90; STEM-eligible; TOEFL iBT 100 / IELTS 7 / DET 135; ETS 3514; interdisciplinary AAM/PPSM/TPP/CSE; research areas listed)</a> | <a href="https://oge.mit.edu/graduate-admissions/programs/doctoral-degrees/" target="_blank">MIT OGE Doctoral Degrees list (Materials Science and Engineering Sep 1 / Dec 1; PhD/ScD interchangeable in School of Engineering)</a>',
    },
    "stanford-mse-phd": {
        "school": "Stanford University, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "5-6 years typical; advanced coursework + in-depth thesis research; students with undergrad or master's in materials science, physics, chemistry, or engineering welcome; all PhD students in good standing receive financial support",
        "ddl": "Autumn 2027 admission: opens mid-September 2026. **PhD deadline December 1, 2026** (MS deadline January 12, 2027). Fee $125. PhD decisions by end of January 2027; Visit Days February 25-27, 2027; decision deadline April 15, 2027.",
        "lang": "TOEFL iBT required for international applicants; PhD minimum 100 (MS minimum 89); ETS Stanford 4701; waivers processed by Stanford central Graduate Admissions (department does not process)",
        "test_cls": "GRE NOT REQUIRED AND NOT REVIEWED (Stanford MSE: 'not required to take the GRE or submit a GRE score report... We will not review any GRE scores submitted.' 3-6 LOR; SOP; unofficial transcripts; resume; identify four faculty of interest; fee $125).",
        "tui": "All PhD students in good standing receive financial support: living stipend/salary, full tuition, health insurance subsidy. Fee $125; fee waivers processed by Stanford central Graduate Admissions, not MSE.",
        "overview": "The Stanford Department of Materials Science and Engineering (MSE) offers a terminal Master of Science (45 units, ~1 year, no thesis) and a Doctor of Philosophy (PhD). The PhD program provides training through advanced coursework and an in-depth thesis research experience. Applicants with an undergraduate degree or a Master's degree in Materials Science or a related field (e.g., physics, chemistry, engineering) are welcome to apply. The department accepts applications once per year for Fall quarter entry only; the PhD deadline is December 1 and the MS deadline is January 12. The PhD application requires identifying four faculty of interest. Late applications are not accepted except under very rare extenuating circumstances. Admission decisions are released by end of January, and admitted PhD students are invited to Visit Days on February 25-27, 2027. The MS is a terminal degree and not intended as preparation for the PhD; however, a petition procedure allows exceptional first-year MS students to transfer to the PhD with support from two faculty members (one willing to act as PhD research advisor and provide funding).",
        "requirements": "<ul><li>Bachelor's degree in materials science, physics, chemistry, engineering, or related field (broader backgrounds welcome)</li><li>GRE NOT REQUIRED AND NOT REVIEWED (Stanford MSE explicitly will not review submitted GRE scores)</li><li>TOEFL iBT required for international applicants; PhD minimum 100 (MS minimum 89); ETS 4701</li><li>Stanford online application</li><li>$125 application fee</li><li>3 letters of recommendation (minimum 3, maximum 6)</li><li>Statement of purpose (SOP) including specific faculty of interest</li><li>Unofficial transcripts from all post-secondary institutions attended for at least one year</li><li>Resume/CV (research experience, publications, presentations, posters)</li><li>Identify four faculty of interest (PhD only)</li><li>**PhD deadline December 1, 2026** (Fall 2027 entry)</li><li>MS deadline January 12, 2027</li><li>Late applications not accepted</li><li>On-campus residential (Stanford, CA)</li></ul>",
        "research": "<ul><li>Structural materials and alloys</li><li>Electronic and photonic materials</li><li>Energy materials (batteries, solar cells, thermoelectrics)</li><li>Biomaterials and medical materials</li><li>Nanoscale materials and devices</li><li>Polymers and soft matter</li><li>Computational materials science</li><li>Ceramics and glasses</li><li>Corrosion and degradation</li><li>Materials genetics and data-driven discovery</li></ul>",
        "source": '<a href="https://mse.stanford.edu/academics-admissions/how-to-apply" target="_blank">Stanford MSE How to Apply (Fall 2027 opens mid-September; PhD deadline Dec 1, 2026; MS deadline Jan 12, 2027; GRE not required and not reviewed; TOEFL required; SOP; 3 LOR; resume; 4 faculty of interest for PhD)</a> | <a href="https://mse.stanford.edu/academics-admissions/graduate-admissions" target="_blank">Stanford MSE Graduate Admissions (PhD deadline Dec 1, 2026; MS deadline Jan 12, 2027; fee $125; PhD decisions end of January; Visit Days Feb 25-27, 2027; decision deadline April 15, 2027)</a> | <a href="https://mse.stanford.edu/academics-admissions/student-services-office/admissions-faq" target="_blank">Stanford MSE Admissions FAQ (GRE not required; TOEFL MS 89 / PhD 100; 3-6 LOR; MS terminal 45 units; petition procedure for MS-to-PhD transfer with 2 faculty support)</a>',
    },
    "berkeley-mse-phd": {
        "school": "UC Berkeley, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "PhD typically ~5-6 years (3 years after MS); core: Thermodynamics 201A, Kinetics/Phase Diagrams 201B, Structure and Bonding 202 (12 units min); minor 6 units min; elective 3 units min; total 21 units min; GSI teaching requirement; Preliminary Exam; Qualifying Exam; dissertation",
        "ddl": "Fall 2027 admission: **December 1, 2026, 8:59 pm PST** (MS/PhD and PhD; MEng deadline January 14, 2027; 5th-year BS/MS December 1, 2026). Application available early September.",
        "lang": "TOEFL exam scores required for international applicants whose native language is not English; minimum Berkeley Graduate Division requirements; ETS UC Berkeley 4833; scores valid 2 years",
        "test_cls": "GRE OPTIONAL for 2026-27 cycle (entering Fall 2027). **REQUIRED starting 2027-28 cycle (entering Fall 2028).** No minimum score; holistic review. Minimum GPA 3.2 (B) in undergraduate; 3 LOR; SOP; resume; transcripts; bachelor's degree conferred prior to enrollment.",
        "tui": "Vast majority of Berkeley MSE PhD students working toward PhD have tuition, campus fees, insurance, and stipend covered by RA/TA/fellowships. MEng is self-funded professional degree. Designated emphases: CCS / CGB / CSE / Energy Science / Nanoscale Science.",
        "overview": "The UC Berkeley Department of Materials Science and Engineering offers three graduate degrees: Master of Engineering (MEng, professional, 1-year or part-time), 5th-Year BS/MS (restricted to current UCB undergrads), and Doctor of Philosophy (PhD). The PhD is a research degree. PhD students may declare a Designated Emphasis (DE) in Communication, Computation, and Statistics (CCS); Computational and Genomic Biology (CGB); Computational Science and Engineering (CSE); Energy Science and Technology; or Nanoscale Science and Engineering. The doctoral program requires core courses: Thermodynamics 201A, Kinetics/Phase Diagrams 201B, and Structure and Bonding 202 (12 units minimum), plus a minor (6 units minimum), elective (3 units minimum), GSI teaching requirement, Preliminary Exam, Qualifying Exam, and dissertation (21 units total minimum). The GRE is optional for the 2026-27 admissions cycle (entering August 2027); starting with the 2027-28 cycle (entering August 2028), the GRE will be required. The minimum GPA is 3.2 (B). The vast majority of PhD students have tuition, campus fees, insurance, and stipend covered.",
        "requirements": "<ul><li>Bachelor's degree (BS or BA) from accredited institution, conferred prior to enrollment</li><li>Sufficient undergraduate training in materials science, physics, chemistry, or engineering</li><li>Minimum GPA 3.2 (B) in undergraduate</li><li>**GRE OPTIONAL for 2026-27 cycle (entering Fall 2027)**; no minimum; no average score statistics; holistic review</li><li>**GRE REQUIRED starting 2027-28 cycle (entering Fall 2028)** per department announcement</li><li>TOEFL exam scores for international applicants whose native language is not English; ETS 4833</li><li>Berkeley Graduate Division online application</li><li>3 letters of recommendation</li><li>Statement of purpose</li><li>Resume</li><li>Transcripts</li><li>**Deadline December 1, 2026, 8:59 pm PST**</li><li>MEng deadline January 14, 2027 (separate professional degree)</li><li>5th-year BS/MS restricted to current UCB undergrads</li><li>Designated emphases available: CCS, CGB, CSE, Energy Science, Nanoscale Science</li><li>On-campus residential (Berkeley, CA)</li></ul>",
        "research": "<ul><li>Structural materials and alloys</li><li>Electronic, photonic, and magnetic materials</li><li>Energy storage and conversion materials</li><li>Biomaterials and soft materials</li><li>Nanoscale science and engineering</li><li>Computational materials science and informatics</li><li>Ceramics and glasses</li><li>Polymers and biomaterials</li><li>Extreme environments materials</li><li>Design, manufacturing, and characterization</li></ul>",
        "source": '<a href="https://grad.berkeley.edu/program/materials-science-and-engineering-phd/" target="_blank">Berkeley Graduate Division: Materials Science and Engineering PhD (Dec 1, 2026 deadline; Fall admission; PhD; GRE Optional; contact MSE GSAO; 210 Hearst Memorial Mining Building; designated emphases listed)</a> | <a href="https://mse.berkeley.edu/graduate-admissions/" target="_blank">Berkeley MSE Graduate Admissions (PhD deadline Dec 1, 2026 8:59 pm PST; MEng Jan 14, 2027; 5th-year BS/MS Dec 1, 2026; GRE optional but highly recommended for 2026-27 entering August 2027; **GRE required starting 2027-28 entering August 2028**; minimum GPA 3.2; TOEFL for international; PhD typically 3 years after MS)</a> | <a href="https://mse.berkeley.edu/wp-content/uploads/2025/08/FINAL-PROGRAM-OF-STUDY-FOR-DOCTORAL-CANDIDATES-WHITE-CARD_REV-2025.pdf" target="_blank">Berkeley MSE Doctoral Program of Study (White Card, revised July 2025) - core: Thermo 201A, Kinetics/Phase Diagrams 201B, Structure and Bonding 202; minor 6 units; elective 3 units; 21 units total min; GSI teaching; Preliminary Exam; Qualifying Exam; dissertation committee</a>',
    },
    "uiuc-matse-phd": {
        "school": "University of Illinois Urbana-Champaign, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering (MatSE)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "5-6 years typical; direct BS-to-PhD entry allowed; MS may be earned en route; Qualifying Exam (first-semester planning document; must pass by end of 4th semester); Preliminary Exam (by end of 6th semester); dissertation; minimum GPA 3.0; choose advisor within first month",
        "ddl": "Fall 2027 admission: **PhD deadline December 1, 2026** (MS deadline February 1, 2027). Spring admission only by MatSE faculty request. Fee $70 domestic / $90 international. Program code: PhD 10KS0130PHD, MS 10KS0130MS. Decisions Feb-March (PhD), March-April (MS).",
        "lang": "TOEFL iBT minimum 103 / IELTS Academic minimum 7.5 (full status); ETS UIUC 1836; limited-status rarely offered + EPT test + ESL courses first two semesters; scores valid 2 years",
        "test_cls": "GRE OPTIONAL (WAIVED). 'The GRE Score is optional (waived). Submission will not give review priority; not submitting will not negatively impact application.' No minimum; typical admitted above 80th Quant / 70th Verbal / 90th Analytical (admission distribution, not threshold). 3 LOR; 1-page SOP; resume; transcripts; minimum GPA 3.0; average incoming GPA 3.65.",
        "tui": "Grainger Engineering Five-Year PhD Funding Guarantee: PhD students in first five years guaranteed funded appointment for fall and spring (full tuition waiver + stipend); summer appointments based on eligibility. RA/TA/fellowship; 98% PhD placement. Fee $70 domestic / $90 international; department generally does not provide fee waivers.",
        "overview": "The UIUC Department of Materials Science and Engineering (MatSE) in the Grainger College of Engineering offers MS and PhD degrees. The PhD is directed at students hoping to pursue a research career in academics, industry, or national labs. The curriculum is flexible and tailored to individual research interests. Students may enter directly from a bachelor's degree (without a master's) and earn the MS en route. Incoming PhD students are admitted at large and choose a research advisor within their first month (by end of September). The Grainger College of Engineering offers a Five-Year PhD Funding Guarantee: PhD students in their first five years of enrollment are guaranteed a funded appointment for fall and spring that includes a full tuition waiver and stipend. The Qualifying Exam planning document must be submitted with advisor and Associate Head approval one month before finals week of the first semester; the Qualifying Exam must be passed by the end of the fourth semester. The Preliminary Exam must be completed by the end of the sixth semester. Post-graduation stats (2014-2021 PhDs): 44% academia, 38% industry, 18% national/international laboratory.",
        "requirements": "<ul><li>Bachelor's or master's degree in materials science, chemistry, chemical engineering, physics, mechanical engineering, or related field</li><li>Minimum cumulative GPA 3.0/4.0; average successful applicant GPA 3.7+; average incoming GPA 3.65</li><li>GRE OPTIONAL (waived); submission does not give review priority; not submitting does not hurt application</li><li>Typical admitted GRE (if submitted): 80th Quant / 70th Verbal / 90th Analytical (admission distribution, not threshold)</li><li>TOEFL iBT minimum 103 / IELTS Academic minimum 7.5; ETS 1836</li><li>UIUC Graduate College online application</li><li>$70 domestic / $90 international application fee</li><li>Program code: PhD 10KS0130PHD</li><li>3 letters of reference</li><li>1-page statement of purpose (within 1000 words per academic SOP instructions)</li><li>Resume</li><li>Transcripts</li><li>**PhD deadline December 1, 2026** (Fall 2027)</li><li>MS deadline February 1, 2027</li><li>Spring admission only by MatSE faculty request</li><li>On-campus residential (Urbana, IL)</li></ul>",
        "research": "<ul><li>Advanced manufacturing</li><li>Data-driven materials discovery</li><li>Energy and the environment</li><li>Electronic, quantum, and communications materials</li><li>Health and medicine (biomaterials)</li><li>Infrastructure and extreme conditions</li><li>Materials Research Laboratory (MRL) - condensed matter physics and materials chemistry</li><li>Collaboration with Argonne National Lab, Lawrence Berkeley, Los Alamos, NIST, Oak Ridge, Pacific Northwest</li></ul>",
        "source": '<a href="https://matse.illinois.edu/admissions/graduate/phd" target="_blank">UIUC MatSE PhD Program (Dec 1 deadline; direct BS-to-PhD entry allowed; MS en route; minimum GPA 3.0, average 3.7; GRE optional/waived; TOEFL/IELTS; Grainger 5-year funding guarantee; choose advisor by end of September; 98% PhD placement; post-grad 44% academia / 38% industry / 18% national lab)</a> | <a href="https://matse.illinois.edu/admissions/graduate/apply" target="_blank">UIUC MatSE Application & Deadlines (PhD Dec 1; MS Feb 1; fee $70/$90; program code 10KS0130PHD; 1-page SOP; 3 LOR; resume; transcripts; spring only by faculty request)</a> | <a href="https://matse.illinois.edu/admissions/graduate/frequently-asked-questions" target="_blank">UIUC MatSE Graduate FAQ (PhD Dec 1; MS Feb 1; average GPA 3.65; GRE optional/waived; no minimum score; typical 80th Quant / 70th Verbal / 90th Analytical; TOEFL 103 / IELTS 7.5; choose advisor after arrival)</a>',
    },
    "gatech-mse-phd": {
        "school": "Georgia Institute of Technology, School of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "31 credit hours for direct-from-BS PhD; 25 credit hours for direct-from-MS PhD; 3 core courses: MSE 6411 Thermodynamics, MSE 6402, MSE 6768; 12 hours MSE electives (BS) or 6 hours (MS); 9 hours minor; Technical Communications (1 credit); qualifying exam; dissertation; minimum GPA 3.0; TA duties required of all GRA students",
        "ddl": "Fall 2027 admission: **December 15, 2026**. Spring admission by special circumstance (September 15). Fee $75 domestic / $85 international. Decisions March-April 2027; majority admitted for fall; no transfer students accepted.",
        "lang": "TOEFL iBT minimum 100 with minimum 19 each category AND minimum 26 in speaking; IELTS Academic minimum overall 7.0 (R6.5/L6.5/S6.5/W5.5); ETS Georgia Tech 5248; scores no more than 2 years old; U.S. degree may be exempted",
        "test_cls": "GRE NOT REQUIRED (Georgia Tech MSE: 'MSE no longer requires the GRE general test scores of graduate applicants.' 3 LOR; resume; transcripts; minimum undergraduate GPA 3.2 for PhD (3.0 for MS); average admitted GPA 3.6 over past 10 years. No transfer students. International students without funding must show ~$70,000 USD first-year cost for I-20.)",
        "tui": "PhD admissions generally granted with tuition waivers and financial assistance in the form of graduate research assistantships (GRA). MS thesis students must first identify faculty advisor willing to advise thesis and cover research costs before consideration. Fee $75 domestic / $85 international.",
        "overview": "The Georgia Tech School of Materials Science and Engineering offers MS and PhD degrees. The PhD is directed at attaining proficiency in independent scholarly work. Admission is competitive; each year there are more outstanding applicants than places. The school's primary recruitment focus is on students who will stay through doctoral studies, because faculty research requires long-term commitment. Students may enter with a BS or MS in Materials Science and Engineering, Polymer Science and Engineering, Ceramic Engineering, Metallurgical Engineering, Chemical Engineering, Mechanical Engineering, Textile Engineering, Chemistry, Biomedical Engineering, Biology, Physics, or related fields. The PhD requires 31 credit hours if direct from BS or 25 credit hours if direct from MS, including 3 required core courses (MSE 6411 Thermodynamics of Materials, MSE 6402, MSE 6768), MSE electives, 9 hours in an approved minor, Technical Communications (1 credit), qualifying exam, and dissertation defense. All GRA students participate in TA activities. The GRE is no longer required. The minimum undergraduate GPA is 3.2 for PhD (3.0 for MS); the average admitted GPA over the past 10 years is 3.6. No transfer students are accepted. Dual doctorates are available in Bioengineering and Computational Science and Engineering.",
        "requirements": "<ul><li>BS or MS degree in materials science, polymer science, ceramic engineering, metallurgical engineering, chemical engineering, mechanical engineering, textile engineering, chemistry, biomedical engineering, biology, physics, or related field</li><li>Minimum undergraduate GPA 3.2 for PhD (3.0 for MS); average admitted GPA 3.6 over past 10 years (admission distribution, not threshold)</li><li>GRE NOT REQUIRED (Georgia Tech MSE no longer requires GRE general test)</li><li>TOEFL iBT minimum 100 with minimum 19 each category AND minimum 26 in speaking</li><li>IELTS Academic minimum overall 7.0 (R6.5/L6.5/S6.5/W5.5); ETS 5248</li><li>Georgia Tech Graduate Education online application</li><li>$75 domestic / $85 international application fee</li><li>3 letters of recommendation</li><li>Resume</li><li>Transcripts</li><li>**Fall deadline December 15, 2026**</li><li>Spring admission by special circumstance (September 15)</li><li>No transfer students accepted</li><li>International students without funding must show ~$70,000 USD first-year cost for I-20</li><li>MS thesis students must identify faculty advisor before consideration</li><li>On-campus residential (Atlanta, GA)</li></ul>",
        "research": "<ul><li>Functional materials (electronic, optical, magnetic)</li><li>Soft and biomaterials</li><li>Structural materials</li><li>Biologically enabled and bioinspired materials</li><li>Multi-scale structural and chemical characterization</li><li>Biomaterials and medical materials</li><li>Nanotechnology and thin films</li><li>Computational materials science</li><li>Polymers and polymer process simulation</li><li>Corrosion, fracture, and mechanical properties</li><li>Electronic and optical microscopy; surface analysis</li><li>Dual doctorates in Bioengineering and Computational Science and Engineering</li></ul>",
        "source": '<a href="https://grad.gatech.edu/degree-programs/materials-science-and-engineering" target="_blank">Georgia Tech Graduate Education: Materials Science and Engineering (Fall Dec 15; Spring Sep 15; GRE general not required; TOEFL 100 w/ 19 each and 26 speaking; IELTS 7.0 (R6.5/L6.5/S6.5/W5.5); minimum GPA 3.2 PhD / 3.0 MS; avg admitted 3.6; dual Bioengineering and CSE doctorates; no transfer students)</a> | <a href="https://www.mse.gatech.edu/graduate/app-requirements" target="_blank">Georgia Tech MSE Graduate Application Requirements (primary recruitment focus on PhD-track; 3 LOR; resume; GRE no longer required; GPA 3.2 PhD / 3.0 MS; TOEFL 100 with 26 speaking; fee $75/$85; no transfer; international students without funding ~$70,000 for I-20)</a> | <a href="https://catalog.gatech.edu/programs/materials-science-phd/" target="_blank">Georgia Tech Catalog: PhD in Materials Science and Engineering (31 hours BS track / 25 hours MS track; core MSE 6411 Thermodynamics / MSE 6402 / MSE 6768; 9 hours minor; Technical Communications 1 hour; qualifying exam; dissertation; minimum GPA 3.0; TA duties required of all GRA students)</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)}")
