# -*- coding: utf-8 -*-
"""Round 251: batch add 5 Physics PhD (first batch of basic-science PhD sweep)
- MIT Physics PhD (Dec 15, 11:59pm EST; GRE General+PGRE recommended but NOT required; TOEFL 100 iBT / IELTS 7.0 / Duolingo 135; ETS 3514 dept 76; $90 fee; opens Sept 15)
- Princeton Physics PhD (Dec 15, 11:59pm EST; GRE General+Subject optional/not required; no minimum TOEFL but below 28 speaking requires English placement; ETS 2672 no dept code; $75 fee; 5-year program)
- Harvard Physics PhD (Dec 15, 2026 5pm ET; GRE General+Subject both optional; TOEFL/IELTS required per GSAS; Personal Statement NOT accepted; list 6 most advanced courses 4 physics + 2 math)
- Stanford Physics PhD (Dec 14, 2026 11:59pm PST hard deadline; **TREND REVERSAL: GRE General + Physics Subject BOTH REQUIRED for Fall 2027-28 cycle**; KHS applicants Dec 1, 2026; separate from Applied Physics)
- Berkeley Physics PhD (Dec 15, 2026; **TREND REVERSAL: Fall 2027 Physics GRE REQUIRED + General strongly recommended; Fall 2028+ BOTH required**; GPA 3.0 min; no standalone MA; TOEFL/IELTS only - Duolingo/ITP/MyBest not accepted)
Key finding: Physics PhD GRE policy split between GRE-free (MIT/Princeton/Harvard) and required (Stanford/Berkeley - both trend reversals). Stanford 2025-26 cycle was optional but Fall 2027-28 reverts to required. Berkeley has explicit two-stage policy: Fall 2027 Physics required, General strongly recommended; Fall 2028+ both required.
"""
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-physics-phd",
        "s": "mit",
        "n": "物理博士",
        "en": "PhD in Physics (Massachusetts Institute of Technology, School of Science, Department of Physics; research spans experimental and theoretical physics; located in Cambridge, MA; the PhD and ScD degrees are awarded interchangeably in the School of Science except in biology, cognitive science, neuroscience, medical engineering, and medical physics)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Cambridge, MA); Fall admission only (no spring enrollment)",
        "ddl": "Fall 2027: application opens September 15, 2026. **Deadline December 15, 2026, 11:59 p.m. Eastern Time**. No spring-term enrollment cycle. Application fee $90.00.",
        "lang": "TOEFL iBT minimum 100 (iBT26 minimum 5); IELTS Academic minimum overall 7.0; Duolingo English Test minimum 135; Cambridge English Qualification minimum 190 overall (C1/C2 only); ETS school code 3514; department code 76 (Physics). Waiver available for eligible applicants.",
        "test": {"cls": "GRE GENERAL AND PHYSICS SUBJECT RECOMMENDED BUT NOT REQUIRED (MIT Physics: 'GRE Tests: The Physics GRE (PGRE) is recommended but not required for graduate applications. All applications will be given full consideration with or without GRE scores.' MIT OGE: 'Graduate Record Examination (GRE): General test and subject test are recommended but not required; Institute code 3514.' Self-reported scores sufficient for initial screening; official scores required only if admitted. 3 LOR; Statement of Objectives; transcripts.)"},
        "tui": "MIT School of Physics typically offers multi-year fully-funded support to admitted PhD students, including tuition scholarship and stipend through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, MIT Presidential Fellowship, etc.).",
        "url": "details/mit-physics-phd.html",
    },
    {
        "id": "princeton-physics-phd",
        "s": "princeton",
        "n": "物理博士",
        "en": "PhD in Physics (Princeton University, Graduate School, Department of Physics; strongly focused on research leading to the PhD; located in Princeton, NJ; students may choose research in experiment, theory, or combination; separate Program in Plasma Physics has its own December 1 deadline)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Program length 5 years; coursework; preliminary examination typically January of Year 1; general examination; thesis proposal; dissertation and Final Public Oral (FPO); on-campus residential (Princeton, NJ); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 11:59 p.m. Eastern Standard Time**. Admissions decisions announced mid-February to mid-March; offer acceptance deadline mid-April; program start August. Application fee $75.",
        "lang": "No minimum TOEFL or IELTS score required to apply. However, if admitted and applicant has below 28 on TOEFL iBT Speaking sub-section or below 8.0 on IELTS Speaking sub-section, they must take an English placement test at the start of the fall term. ETS institution code 2672 (no department code needed).",
        "test": {"cls": "GRE GENERAL AND PHYSICS SUBJECT OPTIONAL/NOT REQUIRED (Princeton Graduate School: 'GRE General Test optional/not required; Physics Subject Test optional/not required.' The department notes standardized test results are only one of many components; top scores are not a requirement. ETS institution 2672, no department code. 3 LOR; Statement of Academic Purpose; CV; transcripts.)"},
        "tui": "Princeton Graduate School typically offers multi-year fully-funded support to admitted Physics PhD students, including full tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards. The department does not offer admission to applicants seeking a second PhD in the same or similar field.",
        "url": "details/princeton-physics-phd.html",
    },
    {
        "id": "harvard-physics-phd",
        "s": "harvard",
        "n": "物理博士",
        "en": "PhD in Physics (Harvard University, Kenneth C. Griffin Graduate School of Arts and Sciences, Department of Physics; typically applicants have devoted approximately half of their undergraduate work to physics, mathematics, and chemistry; at least one year of introductory quantum mechanics is desirable; located in Cambridge, MA)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Cambridge, MA); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 5:00 p.m. ET** (GSAS program page). Note: Harvard Astronomy PhD has a separate December 1 deadline and GRE Not Accepted policy - this entry is for Physics, NOT Astronomy.",
        "lang": "TOEFL iBT / IELTS Academic required for all applicants who have not received a BA from an English-speaking undergraduate institution; exemptions granted only in extreme circumstances per GSAS policy. GSAS does not accept alternative forms of verification (e.g., letter from undergraduate faculty).",
        "test": {"cls": "GRE GENERAL OPTIONAL, PHYSICS SUBJECT OPTIONAL (GSAS: 'Physics: GRE General Optional; GRE Subject Test Optional.' Department note: 'Physics & General GRE scores will remain optional for the upcoming admissions cycle. The admission committee looks for all indications that an applicant will be successful... We recommend (but not require) that international applicants, students from less familiar schools, and students who believe their transcripts do not accurately reflect their underlying academic strengths submit a Physics GRE score.' Personal Statement NOT accepted - only Statement of Purpose. 3 LOR.)"},
        "tui": "Harvard GSAS typically offers multi-year fully-funded support to admitted Physics PhD students, including full tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Fellowships, and fellowship awards (NSF GRFP, Harvard Graduate Society Fellowship, etc.).",
        "url": "details/harvard-physics-phd.html",
    },
    {
        "id": "stanford-physics-phd",
        "s": "stanford",
        "n": "物理博士",
        "en": "PhD in Physics (Stanford University, School of Humanities and Sciences, Department of Physics; admission based on comprehensive review of academic performance, research experience, letters of recommendation, statement of purpose, and Physics GRE scores; located in Stanford, CA; separate from the Department of Applied Physics which has its own PhD program)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; autumn quarter admission only; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Stanford, CA); no late applications accepted",
        "ddl": "Fall 2027: **Deadline December 14, 2026, 11:59 p.m. Pacific Standard Time (PST)** - hard deadline, no late applications accepted, no exceptions. Knight-Hennessy Scholars (KHS) applicants: KHS application by October 6, 2026, and Physics PhD application by December 1, 2026. Admission decisions by March 15, 2027 at the latest.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers per Stanford Graduate Admissions policy; minimum scores set by the Graduate School of Humanities and Sciences.",
        "test": {"cls": "TREND REVERSAL - GRE GENERAL AND PHYSICS SUBJECT BOTH REQUIRED FOR FALL 2027-28 CYCLE (Stanford Physics: 'For the Fall 2026-27 admissions cycle [i.e., entering Fall 2027], the GRE General Test and the Physics GRE Subject Test are required for all applicants, as they help us fairly assess problem-solving skills. If you are unable to take one or both examinations due to extenuating circumstances, please explain your situation in the Additional Information section... applications submitted without the required GRE scores may not receive full consideration.' NOTE: 2025-26 cycle was optional - this is a policy reversal. Separate from Applied Physics which also requires GRE for Fall 2027.)"},
        "tui": "Stanford School of Humanities and Sciences typically offers multi-year fully-funded support to admitted Physics PhD students, including tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, Stanford Graduate Fellowship, Knight-Hennessy Scholars).",
        "url": "details/stanford-physics-phd.html",
    },
    {
        "id": "berkeley-physics-phd",
        "s": "berkeley",
        "n": "物理博士",
        "en": "PhD in Physics (University of California Berkeley, Graduate Division, Department of Physics; holistic evaluation including recommendation letters, academic achievements, research experience, leadership and outreach activities, personal history; located in Berkeley, CA; no standalone MA - MA only awarded en route to PhD)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; normative time to degree 6 years per department; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Berkeley, CA); Fall admission only",
        "ddl": "Fall 2027: application opens September 24, 2026 at 12:00 p.m. Pacific Time. **Deadline December 15, 2026** (Fall term). Note: Berkeley Astrophysics PhD (Department of Astronomy) has a separate December 4, 2026 deadline and requires Subject test - this entry is for Physics, NOT Astrophysics.",
        "lang": "TOEFL iBT or IELTS Academic required for applicants who have completed a bachelor's degree or equivalent in a country or region where English is not the primary language. **UC Berkeley does NOT accept Duolingo, TOEFL ITP, MyBest Scores, IELTS Indicator, or IELTS One Test Retake.** Minimum 3.0 GPA on 4.0 scale.",
        "test": {"cls": "TREND REVERSAL - TWO-STAGE POLICY: Fall 2027 Physics GRE REQUIRED, General GRE strongly recommended but NOT required; Fall 2028+ BOTH General and Physics GRE REQUIRED (Berkeley Physics: 'For the upcoming admissions cycle (applying in Fall 2026 for Fall 2027 entry): The Physics GRE is required, and the General GRE is strongly recommended but not required. For future cycles (applying in Fall 2027 for Fall 2028 entry and beyond): Both the General and Physics GRE will be required.' Berkeley Graduate Division catalog lists Physics PhD as 'Yes, subject test.' 3 LOR required.)"},
        "tui": "UC Berkeley Graduate Division typically offers multi-year fully-funded support to admitted Physics PhD students, including tuition, stipend, and health insurance through a combination of Research Assistantships, Graduate Student Researcher (GSR) positions, Teaching Assistantships, and fellowship awards (NSF GRFP, Berkeley Fellowship, etc.).",
        "url": "details/berkeley-physics-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> First batch of Physics PhD sweep (MIT, Princeton, Harvard, Stanford, Berkeley). Key finding: Physics PhD GRE policy splits between GRE-free (MIT/Princeton/Harvard) and required (Stanford/Berkeley - both trend reversals). MIT Physics: General and PGRE recommended but not required; all applications given full consideration with or without scores. Princeton: General and Subject optional/not required; no minimum TOEFL. Harvard: General and Subject both optional; GSAS recommends PGRE for international applicants and students from less familiar schools; Personal Statement NOT accepted. Stanford: TREND REVERSAL - 2025-26 cycle was optional but Fall 2027-28 (applying Dec 2026) BOTH General and Physics Subject are REQUIRED; hard deadline Dec 14, 2026 11:59pm PST. Berkeley: TWO-STAGE policy - Fall 2027 Physics GRE required, General strongly recommended but not required; Fall 2028+ BOTH required; no standalone MA; does not accept Duolingo/TOEFL ITP/MyBest/IELTS Indicator. Important distinctions: (1) Stanford Physics is NOT the same as Stanford Applied Physics (separate department, also requires GRE for Fall 2027). (2) Harvard Physics (Dec 15, optional) is NOT the same as Harvard Astronomy (Dec 1, GRE Not Accepted). (3) Berkeley Physics (Dec 15, subject required) is NOT the same as Berkeley Astrophysics (Dec 4, subject required). (4) Princeton Physics (Dec 15) is NOT the same as Princeton Plasma Physics (Dec 1, separate Program in Plasma Physics). (5) MIT Physics PhD and ScD are awarded interchangeably in the School of Science.
</div>
</body>
</html>
"""

PAGES = {
    "mit-physics-phd": {
        "school": "Massachusetts Institute of Technology, School of Science, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus (Cambridge, MA); Fall admission only",
        "ddl": "Fall 2027: opens Sept 15, 2026. **Deadline December 15, 2026, 11:59 p.m. ET**. Fee $90. No spring enrollment.",
        "lang": "TOEFL iBT 100 min (iBT26 min 5); IELTS 7.0 min; Duolingo 135; Cambridge English 190 (C1/C2). ETS 3514; dept 76.",
        "test_cls": "GRE General + Physics Subject RECOMMENDED BUT NOT REQUIRED (MIT Physics: 'The Physics GRE (PGRE) is recommended but not required. All applications will be given full consideration with or without GRE scores.' Self-reported scores sufficient for initial screening; official scores required only if admitted.)",
        "tui": "Multi-year fully-funded support: tuition + stipend + health insurance through RA/TA/fellowship (NSF GRFP, MIT Presidential Fellowship).",
        "overview": "The MIT Department of Physics offers the Doctor of Philosophy (PhD) degree. In the School of Science, the PhD and Doctor of Science (ScD) degrees are awarded interchangeably except in the fields of biology, cognitive science, neuroscience, medical engineering, and medical physics; students may choose which degree they wish to complete. For the Fall 2027 application cycle, the application opens September 15, 2026, and the deadline is December 15, 2026 at 11:59 p.m. Eastern Time. The application fee is $90.00. There is no admission cycle for spring-term enrollment. Required application materials include: online application, Statement of Objectives, three letters of recommendation, transcripts, and English proficiency exam scores for international applicants. Critically, GRE tests (both General and Physics Subject Test) are recommended but not required for graduate applications; all applications will be given full consideration with or without GRE scores. Self-reported scores are sufficient for initial application screening; official scores are required for admitted students as a condition of their offer. Applicants should attach a scanned copy of their test score report. For international applicants, IELTS minimum required score is 7; TOEFL minimum required score is 100 (iBT); the iBT26 minimum score is 5; the PBT minimum is 600. MIT's TOEFL school code is 3514; the code for the Department of Physics is 76. IELTS does not require a code. Cambridge English Qualification minimum overall score is 190 (C1/C2); Duolingo English Test minimum is 135. Waivers of TOEFL/IELTS may be available for eligible applicants per the department's FAQ. The MIT Physics Department is located in Cambridge, Massachusetts.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>GRE General Test recommended but NOT required</li><li>GRE Physics Subject Test recommended but NOT required</li><li>Self-reported scores sufficient for initial screening; official scores required only if admitted</li><li>ETS school code 3514; dept code 76 (Physics)</li><li>TOEFL iBT 100 minimum (iBT26 5 min; PBT 600)</li><li>IELTS Academic 7.0 minimum</li><li>Duolingo English Test 135 minimum</li><li>Cambridge English Qualification 190 overall (C1/C2 only)</li><li>Waiver available for eligible applicants</li><li>MIT online application (opens September 15, 2026)</li><li>Statement of Objectives</li><li>Three letters of recommendation</li><li>Transcripts</li><li>Application fee $90.00</li><li>**Deadline December 15, 2026, 11:59 p.m. ET**</li><li>Fall admission only (no spring enrollment)</li><li>PhD and ScD awarded interchangeably in School of Science</li><li>On-campus residential (Cambridge, MA)</li></ul>",
        "research": "<ul><li>Experimental physics (atomic, molecular, optical; condensed matter; nuclear; particle)</li><li>Theoretical physics (quantum field theory; condensed matter theory; cosmology; gravitation; string theory)</li><li>Astrophysics and gravitational waves</li><li>Biophysics (interdisciplinary with Biology, EECS, Media Lab)</li><li>Plasma physics and fusion science</li><li>Quantum information science</li><li>Interdisciplinary research with LIGO, RLE, IRG, and other MIT centers</li></ul>",
        "source": '<a href="https://physics.mit.edu/academic-programs/graduate-students/graduate-admissions/" target="_blank">MIT Physics Graduate Admissions (Dec 15 deadline; GRE General+PGRE recommended but not required; all applications given full consideration; TOEFL/IELTS/Cambridge/Duolingo; ETS 3514 dept 76; self-reported scores sufficient)</a> | <a href="https://oge.mit.edu/programs/physics/" target="_blank">MIT OGE: Physics program (opens Sept 15; deadline Dec 15 11:59pm ET; fee $90; GRE recommended not required; TOEFL 100 iBT / IELTS 7.0; 3 LOR; Statement of Objectives; transcripts)</a> | <a href="https://physics.mit.edu/academic-programs/graduate-students/graduate-admissions-additional-guidance/" target="_blank">MIT Physics Additional Guidance (iBT26 min 5; PBT 600; Cambridge/Duolingo accepted; waiver may be available)</a> | <a href="https://oge.mit.edu/graduate-admissions/admissions-policies/elp-test-requirement/" target="_blank">MIT ELP Test Requirement (IELTS 7; TOEFL iBT 100; DET 135; Cambridge 190; department minimums supersede recommended)</a>',
    },
    "princeton-physics-phd": {
        "school": "Princeton University, Graduate School, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Program length 5 years; preliminary exam typically January of Year 1; general exam; thesis proposal; dissertation and FPO; on-campus (Princeton, NJ); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 11:59 p.m. EST**. Decisions mid-Feb to mid-Mar; offer acceptance mid-April; start August. Fee $75.",
        "lang": "No minimum TOEFL/IELTS to apply. Below 28 TOEFL speaking or 8.0 IELTS speaking requires English placement test at start of fall. ETS 2672 no dept code.",
        "test_cls": "GRE General + Physics Subject OPTIONAL/NOT REQUIRED (Princeton Graduate School: 'GRE General Test optional/not required; Physics Subject Test optional/not required.' Standardized test results are only one of many components; top scores are not a requirement. ETS 2672 no dept code.)",
        "tui": "Multi-year fully-funded: full tuition + stipend + health insurance through RA/TA/fellowship. No admission to applicants seeking a second PhD in the same or similar field.",
        "overview": "Princeton University Department of Physics offers a graduate program strongly focused on research leading to the Doctor of Philosophy (PhD) degree. In evaluating each applicant, the department looks primarily for the potential to perform forefront research in experiment, theory, or some combination. For the 2026-27 application cycle, the application deadline is December 15, 2026 at 11:59 p.m. Eastern Standard Time. Admissions decisions are announced mid-February to mid-March; offer acceptance deadline is mid-April; program starts in August. The program length is 5 years. The application fee is $75. Critically, GRE General Test and Physics Subject Test are both optional/not required for the 2023/2024 admission cycle and subsequent cycles. The department notes that in most years it has required both the GRE general test and the physics subject GRE test, but standardized test results are only one of many components taken into consideration; top scores are not a requirement. The department recognizes the ongoing debate about the usefulness of the GRE exam in graduate admissions decisions. One advantage is that it provides students from less traditional backgrounds an opportunity to stand out in the admissions process. The department recommends studying for the Physics GRE exam well in advance, but it is not required. The Graduate School will not offer admission to an applicant seeking a second PhD in the same or similar field. A bachelor's degree (or its foreign equivalent) is required. Application materials: resume or CV, statement of academic purpose, transcripts (in English) from each academic institution from which a degree was earned or expected, and three letters of recommendation. For English language, Princeton has no minimum TOEFL or IELTS score to apply; however, if admitted and the applicant scored below 28 on the TOEFL iBT Speaking sub-section or below 8.0 on the IELTS Speaking sub-section, they will be required to take an English placement test at the start of the fall term. ETS institution code for Princeton is 2672; no department code is required. Applicants must indicate at least one choice from a menu of the Department's current Areas of Research. Note: Princeton Program in Plasma Physics is a separate PhD program with a December 1, 2026 deadline.",
        "requirements": "<ul><li>Bachelor's degree (or foreign equivalent) in physics or related field</li><li>No minimum TOEFL or IELTS to apply</li><li>Below 28 TOEFL speaking / 8.0 IELTS speaking requires English placement test</li><li>ETS institution 2672 (no department code needed)</li><li>GRE General Test optional/not required</li><li>GRE Physics Subject Test optional/not required</li><li>Princeton Graduate School online application</li><li>Resume or CV</li><li>Statement of Academic Purpose (focus on research interests at Princeton and relevant research experience)</li><li>Three letters of recommendation</li><li>Transcripts (in English) from each degree-granting institution</li><li>Indicate at least one choice from Department's current Areas of Research</li><li>Application fee $75</li><li>**Deadline December 15, 2026, 11:59 p.m. EST**</li><li>Fall admission only (start August)</li><li>Program length 5 years</li><li>No admission to applicants seeking a second PhD in same/similar field</li><li>Preliminary exam typically January of Year 1; general exam Year 2</li><li>On-campus residential (Princeton, NJ)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics and cosmology</li><li>Atomic, molecular, and optical physics</li><li>Biophysics</li><li> Gravitational physics and general relativity</li><li>Plasma physics (separate Program in Plasma Physics)</li><li>Mathematical physics</li><li>Geophysics</li></ul>",
        "source": '<a href="https://phy.princeton.edu/academics/graduate-program/graduate-admissions" target="_blank">Princeton Physics Graduate Admissions (Dec 15 deadline; decisions mid-Feb to mid-Mar; 5-year program; research in experiment/theory/combination; GRE optional)</a> | <a href="https://gradschool.princeton.edu/academics/degrees-requirements/fields-study/physics" target="_blank">Princeton Graduate School: Physics (PhD; deadline Dec 15; fee $75; GRE General optional/not required; Physics Subject optional/not required; indicate research area; Statement of Purpose focus on research interests)</a> | <a href="https://phy.princeton.edu/academics/graduate-program/graduate-admissions/faqs" target="_blank">Princeton Physics FAQ (no minimum TOEFL; below 28 speaking requires placement test; GRE optional; no physics major required but core coursework needed: mechanics, E&M, thermal/statistical, quantum, lab)</a> | <a href="https://gradschool.princeton.edu/admission-onboarding/prepare/required-tests" target="_blank">Princeton Required Tests (ETS institution 2672; no department code; scores may take up to two weeks to arrive; 7 days to match application)</a>',
    },
    "harvard-physics-phd": {
        "school": "Harvard University, Kenneth C. Griffin Graduate School of Arts and Sciences, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus (Cambridge, MA); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 5:00 p.m. ET**. Note: Harvard Astronomy PhD has separate December 1 deadline and GRE Not Accepted - this entry is Physics, NOT Astronomy.",
        "lang": "TOEFL iBT / IELTS required for all applicants who have not received a BA from an English-speaking undergraduate institution; exemptions only in extreme circumstances per GSAS policy.",
        "test_cls": "GRE General OPTIONAL, Physics Subject OPTIONAL (GSAS: 'Physics: GRE General Optional; GRE Subject Test Optional.' Department recommends PGRE for international applicants and students from less familiar schools. Personal Statement NOT accepted - only Statement of Purpose.)",
        "tui": "Multi-year fully-funded: full tuition + stipend + health insurance through RA/TA/fellowship (NSF GRFP, Harvard Graduate Society Fellowship).",
        "overview": "The Harvard Kenneth C. Griffin Graduate School of Arts and Sciences (GSAS) offers the Doctor of Philosophy (PhD) in Physics through the Department of Physics. The application deadline is December 15, 2026 at 5:00 p.m. ET. Applicants should be well versed in undergraduate-level physics and mathematics. Typically, applicants will have devoted approximately half of their undergraduate work to physics and related subjects such as mathematics and chemistry. It is desirable for every applicant to have completed at least one year of introductory quantum mechanics classes. An applicant who has a marked interest in a particular branch of physics should include this information in the application. If possible, applicants should also indicate whether they are inclined toward experimental or theoretical (mathematical) research. This statement of preference will not be treated as a binding commitment to any course of study and research. In the Advanced Coursework section of the online application, prospective students must indicate the six most advanced courses (four in physics and two in mathematics) they completed or will complete at their undergraduate institution. Critically, for the Physics PhD, GRE General is Optional and GRE Subject Test is Optional. The department notes that Physics & General GRE scores will remain optional for the upcoming admissions cycle. The admission committee looks for all indications that an applicant will be successful at Harvard; no single factor will be used as a filter. A note for international applicants, and for students from smaller schools that may be less familiar to the admissions committee: the Physics GRE score may contain information that adds to what can be learned from other parts of the application. The department recommends (but does not require) that international applicants, students from less familiar schools, and students who believe their transcripts do not accurately reflect their underlying academic strengths submit a Physics GRE score. IMPORTANT: Personal Statement is NOT accepted for the Physics PhD - only the Statement of Purpose. For English proficiency, GSAS requires TOEFL/IELTS scores for all applicants who have not received a BA from an English-speaking undergraduate institution, with exemptions granted only in extreme circumstances. GSAS does not accept alternative forms of verification such as a letter from a faculty member at a student's undergraduate institution. Note: Harvard Astronomy PhD is a separate program with a December 1 deadline and GRE Not Accepted policy - this entry is for Physics, NOT Astronomy.",
        "requirements": "<ul><li>Bachelor's degree; well versed in undergraduate physics and mathematics</li><li>~half of undergraduate work in physics/mathematics/chemistry</li><li>At least one year of introductory quantum mechanics (desirable)</li><li>Indicate branch of physics interest and experimental vs theoretical preference</li><li>List 6 most advanced courses: 4 in physics + 2 in mathematics</li><li>GRE General Test Optional</li><li>GRE Physics Subject Test Optional (recommended for international/less-familiar-school applicants)</li><li>TOEFL iBT / IELTS Academic required for non-English BA holders</li><li>No exemption for later master's from English-speaking institution - only BA counts</li><li>Personal Statement NOT accepted - only Statement of Purpose</li><li>Three letters of recommendation</li><li>Transcripts</li><li>GSAS online application</li><li>**Deadline December 15, 2026, 5:00 p.m. ET**</li><li>Fall admission only</li><li>On-campus residential (Cambridge, MA)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy theory / particle physics</li><li>Astrophysics (separate Astronomy PhD program)</li><li>Atomic, molecular, and optical physics</li><li>Biophysics (interdisciplinary with FAS, HMS, SEAS)</li><li>Soft condensed matter and statistical physics</li><li>Quantum optics and quantum information</li><li>Interdisciplinary research with Broad Institute, Rowland Institute, and other centers</li></ul>",
        "source": '<a href="https://gsas.harvard.edu/program/physics" target="_blank">Harvard GSAS: Physics (PhD; GRE General Optional; GRE Subject Optional; deadline Dec 15 5pm ET; Personal Statement NOT accepted; list 6 most advanced courses 4 physics + 2 math; at least one year of quantum mechanics desirable)</a> | <a href="https://www.physics.harvard.edu/grad/faqs" target="_blank">Harvard Physics Graduate Admissions FAQ (GSAS requires TOEFL/IELTS for non-English BA holders; exemptions only extreme; no alternative verification; later master does not exempt)</a> | <a href="https://www.physics.harvard.edu/grad/admissions" target="_blank">Harvard Physics Graduate Admissions (GRE optional for upcoming cycle; PGRE recommended for international/less-familiar-school applicants; committee looks for all indicators of success; no single filter factor)</a> | <a href="https://gsas.harvard.edu/programs" target="_blank">Harvard GSAS Programs list (Physics Optional Dec 15 5pm; Astronomy Not Accepted Dec 1 - separate; Applied Physics Optional Dec 15 - separate SEAS program)</a>',
    },
    "stanford-physics-phd": {
        "school": "Stanford University, School of Humanities and Sciences, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; autumn quarter admission only; hard deadline no late applications; on-campus (Stanford, CA); separate from Applied Physics",
        "ddl": "Fall 2027: **Deadline December 14, 2026, 11:59 p.m. Pacific Standard Time (PST)** - hard deadline, no late applications, no exceptions. KHS applicants: KHS by Oct 6, 2026 + Physics PhD by Dec 1, 2026. Decisions by March 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers per Stanford Graduate Admissions policy.",
        "test_cls": "TREND REVERSAL - GRE General + Physics Subject BOTH REQUIRED FOR FALL 2027-28 CYCLE (Stanford Physics: 'For the Fall 2026-27 admissions cycle [entering Fall 2027], the GRE General Test and the Physics GRE Subject Test are required for all applicants, as they help us fairly assess problem-solving skills. If unable to take due to extenuating circumstances, explain in Additional Information... applications without required GRE scores may not receive full consideration.' NOTE: 2025-26 cycle was optional - this is a policy reversal.)",
        "tui": "Multi-year fully-funded: tuition + stipend + health insurance through RA/TA/fellowship (NSF GRFP, Stanford Graduate Fellowship, Knight-Hennessy Scholars).",
        "overview": "The Stanford University Department of Physics offers a PhD program. Admission to the PhD program in Physics is based on a comprehensive and individualized review of each application, including academic performance, research experience, letters of recommendation, statement of purpose, and Physics GRE scores. Applicants are primarily evaluated on the strength of their accomplishments, demonstrated commitment to and enthusiasm for research, intellectual creativity, and talent for research in physics. CRITICAL POLICY CHANGE: For the Fall 2026-27 admissions cycle (i.e., entering Fall 2027), the GRE General Test and the Physics GRE Subject Test are required for all applicants, as they help the department fairly assess problem-solving skills. If an applicant is unable to take one or both examinations due to extenuating circumstances, they should explain their situation in the Additional Information section of the application and include any supporting documents. Requests for exceptions will be reviewed on a case-by-case basis, but applications submitted without the required GRE scores may not receive full consideration. Note: this is a reversal - for the 2025-26 application cycle, both General and Physics GRE scores were accepted but not a required component; the Physics GRE subject test was strongly recommended but not absolutely required. Applications must be submitted by the deadline in mid-December to be considered for the following Autumn Quarter. The application deadline for the 2026-27 academic year (2027-28 admissions cycle) is 11:59 p.m. Pacific Standard Time, Monday, December 14, 2026. The application submission deadline is a hard deadline and no late applications are accepted, no exceptions. The department strongly suggests applicants do not wait until the last day to submit in case they encounter any difficulties. For Knight-Hennessy Scholars (KHS) applicants, students must submit their KHS application by October 6, 2026, and their application for the Physics PhD program by December 1, 2026. Stanford PhD students may also apply to KHS during their first year of PhD enrollment. The Department of Admissions Committee reviews applications during January and notifies applicants of admissions decisions by March 15, 2027 at the latest. IMPORTANT: Stanford Physics is NOT the same as Stanford Applied Physics - they are distinct departments within the School of Humanities & Sciences; Applied Physics also requires GRE for Fall 2027.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>**GRE General Test REQUIRED for Fall 2027-28 cycle** (policy reversal from 2025-26 optional)</li><li>**GRE Physics Subject Test REQUIRED for Fall 2027-28 cycle**</li><li>Extenuating-circumstances waiver: explain in Additional Information with supporting documents; case-by-case review</li><li>Applications without required GRE scores may not receive full consideration</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers</li><li>Stanford online application</li><li>Statement of Purpose</li><li>Three letters of recommendation</li><li>Transcripts</li><li>CV/Resume</li><li>**Hard deadline December 14, 2026, 11:59 p.m. PST** - no late applications</li><li>KHS applicants: KHS by Oct 6, 2026 + Physics PhD by Dec 1, 2026</li><li>Autumn quarter admission only</li><li>Decisions by March 15, 2027</li><li>Separate from Stanford Applied Physics</li><li>On-campus residential (Stanford, CA)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics and cosmology</li><li>Atomic, molecular, and optical physics</li><li>Biophysics (interdisciplinary with Biology, Bioengineering)</li><li>Quantum science and quantum information</li><li>Gravitational physics and experimental gravity</li><li>Plasma physics</li><li>Interdisciplinary research with SLAC National Accelerator Laboratory</li></ul>",
        "source": '<a href="https://physics.stanford.edu/graduate/graduate-admissions" target="_blank">Stanford Physics Graduate Admissions (Dec 14, 2026 11:59pm PST hard deadline; GRE General + Physics Subject BOTH REQUIRED for Fall 2027-28; extenuating-circumstances waiver; no late applications; decisions by March 15)</a> | <a href="https://physics.stanford.edu/graduate/graduate-admissions/application-faqs" target="_blank">Stanford Physics Application FAQs (Dec 14, 2026 11:59pm PST; KHS Dec 1, 2026; KHS deadline Oct 6, 2026 1pm PT; GRE General + Physics Subject required for Fall 2027-28; case-by-case exception review)</a> | <a href="https://appliedphysics.stanford.edu/admissions/overview" target="_blank">Stanford Applied Physics Admissions (separate department; Dec 14, 2026; GRE General + Physics Subject both required for Fall 2027; financial-hardship explanation accepted; decisions by March 15)</a> | <a href="https://gradadmissions.stanford.edu/node/66" target="_blank">Stanford Graduate Admissions Test Scores (each program sets own policy: required/optional/not considered; self-reported scores accepted; official scores required if program requires)</a>',
    },
    "berkeley-physics-phd": {
        "school": "University of California Berkeley, Graduate Division, Department of Physics",
        "en": "PhD in Physics (no standalone MA; MA awarded en route to PhD only)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Normative time to degree 6 years; coursework; preliminary and qualifying exams; dissertation; on-campus (Berkeley, CA); Fall admission only; no standalone MA",
        "ddl": "Fall 2027: application opens September 24, 2026 at 12:00 p.m. PT. **Deadline December 15, 2026** (Fall term). Note: Berkeley Astrophysics PhD (Astronomy dept) has separate December 4, 2026 deadline - this entry is Physics, NOT Astrophysics.",
        "lang": "TOEFL iBT or IELTS Academic required for non-English BA holders. **UC Berkeley does NOT accept Duolingo, TOEFL ITP, MyBest Scores, IELTS Indicator, or IELTS One Test Retake.** Minimum 3.0 GPA on 4.0 scale.",
        "test_cls": "TREND REVERSAL - TWO-STAGE POLICY: Fall 2027 Physics GRE REQUIRED + General strongly recommended but NOT required; Fall 2028+ BOTH required (Berkeley Physics: 'For the upcoming admissions cycle (applying in Fall 2026 for Fall 2027 entry): The Physics GRE is required, and the General GRE is strongly recommended but not required. For future cycles (applying in Fall 2027 for Fall 2028 entry and beyond): Both the General and Physics GRE will be required.' Graduate Division catalog: 'Physics PhD: Yes, subject test.' 3 LOR required.)",
        "tui": "Multi-year fully-funded: tuition + stipend + health insurance through GSR/TA/fellowship (NSF GRFP, Berkeley Fellowship).",
        "overview": "The UC Berkeley Department of Physics offers a PhD program. The graduate admissions committee conducts a holistic evaluation of all applications, which takes into consideration recommendation letters, academic achievements, research experience, a record of leadership and outreach activities, personal history, and more. The department requires a minimum of three letters of recommendation. Applicants will invite their recommenders to submit their letters through the online application; all letters should be uploaded by the application deadline. Applicants should NOT send updated transcripts, publications, etc. after the application deadline. Applications will not be updated after the December 15th deadline with transcripts showing fall grades. Letter writers are still able to upload letters of recommendation via the Slate submission links, but the department cannot guarantee that the committee will have them available for review since the application deadline has passed. CRITICAL POLICY CHANGE: For the upcoming admissions cycle (applying in Fall 2026 for Fall 2027 entry), the Physics GRE is required, and the General GRE is strongly recommended but not required. For future cycles (applying in Fall 2027 for Fall 2028 entry and beyond), both the General and Physics GRE will be required. The Berkeley Graduate Division catalog lists Physics PhD as 'Yes, subject test.' The minimum graduate admissions requirements are: a bachelor's degree or recognized equivalent from an accredited institution; a satisfactory scholastic average, usually a minimum grade-point average (GPA) of 3.0 (B) on a 4.0 scale; and enough undergraduate training to do research work in the chosen field. The Berkeley Physics graduate program does not offer a standalone M.A. degree. Only students in the physics doctoral program may apply for the M.A. degree after completing certain requirements. At Berkeley, applicants may apply to only one graduate or concurrent degree program. For English language, UC Berkeley accepts scores from two standardized exams: TOEFL and IELTS. The university does NOT accept the Duolingo exam, TOEFL ITP, My Best Scores, IELTS Indicator, or IELTS One Test Retake. Applicants who have completed a bachelor's degree or equivalent in a country or region where English is not the primary language used in both daily life and academic instruction must submit official proof of English language proficiency, unless they qualify for a TOEFL/IELTS exemption. The application opens September 24, 2026 at 12:00 p.m. Pacific Time for Fall 2027 admissions. Note: Berkeley Astrophysics PhD (Department of Astronomy) is a separate program with a December 4, 2026 deadline and also requires Subject test - this entry is for Physics, NOT Astrophysics.",
        "requirements": "<ul><li>Bachelor's degree or recognized equivalent from accredited institution</li><li>Minimum 3.0 GPA (B) on 4.0 scale</li><li>Sufficient undergraduate training in physics to do graduate research</li><li>**Fall 2027: Physics GRE REQUIRED; General GRE strongly recommended but NOT required**</li><li>**Fall 2028 and beyond: BOTH General and Physics GRE required**</li><li>Berkeley Graduate Division catalog lists Physics PhD as 'Yes, subject test'</li><li>TOEFL iBT or IELTS Academic required for non-English BA holders</li><li>**NOT accepted: Duolingo, TOEFL ITP, MyBest Scores, IELTS Indicator, IELTS One Test Retake**</li><li>UC Berkeley online application (opens Sept 24, 2026 12:00 p.m. PT)</li><li>Statement of Purpose</li><li>Three letters of recommendation (minimum)</li><li>Transcripts (unofficial with application; official upon admission)</li><li>No materials after December 15 deadline (no updated fall transcripts)</li><li>**Deadline December 15, 2026** (Fall term)</li><li>Fall admission only</li><li>No standalone MA - MA awarded en route to PhD only</li><li>May apply to only one graduate/concurrent degree program</li><li>Normative time to degree 6 years</li><li>On-campus residential (Berkeley, CA)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics (separate Astronomy PhD program)</li><li>Atomic, molecular, and optical physics</li><li>Biophysics (interdisciplinary with MCB, Bioengineering)</li><li>Nuclear physics</li><li>Plasma physics</li><li>Mathematical physics</li><li>Quantum information science</li><li>Interdisciplinary research with LBNL, Space Sciences Lab, and other centers</li></ul>",
        "source": '<a href="https://physics.berkeley.edu/academic/graduate-degree/graduate-admissions" target="_blank">Berkeley Physics Graduate Admissions (Dec 15 deadline; Fall 2027 Physics GRE required + General strongly recommended; Fall 2028+ both required; 3 LOR; no updated materials after deadline; holistic review)</a> | <a href="https://grad.berkeley.edu/admissions/our-programs/" target="_blank">Berkeley Graduate Division Programs (Physics PhD: deadline Dec 15, 2026; Degree Type Doctoral/PhD; GRE Requirements: Yes, subject test; Astrophysics PhD: Dec 4, 2026 separate)</a> | <a href="https://physics.berkeley.edu/sites/default/files/physics_grad_admissions_faq_0.pdf" target="_blank">Berkeley Physics FAQ (GPA 3.0 minimum; no standalone MA; only one graduate program; General GRE not reviewed per older FAQ - superseded by 2026-27 policy reversal; holistic review)</a> | <a href="https://grad.berkeley.edu/admissions/application-process/requirements/" target="_blank">Berkeley Graduate Division Requirements (application opens Sept 24, 2026 12pm PT; TOEFL/IELTS only; does NOT accept Duolingo, TOEFL ITP, MyBest, IELTS Indicator, IELTS One Test Retake)</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)}")
