:root {
    --bg: #f9f9f9; --text: #2c3e50; --text-soft: #334155; --heading: #1e293b; --muted: #64748b;
    --bar: #2c3e50; --link: #2980b9; --link-strong: #2563eb;
    --card: #ffffff; --border: #e2e8f0; --border-strong: #cbd5e1; --thumb-bg: #f8fafc;
    --pill-text: #1d4ed8; --pill-bg: #eff6ff; --pill-border: #bfdbfe;
    --tag-bg: #eef2f6; --tag-text: #4b5563; --tag-border: #d1d5db;
    --btn-hover-bg: #2c3e50; --btn-hover-text: #ffffff;
    --code-bg: #eef2f6; --pre-bg: #f1f5f9; --notice-bg: #eff6ff; --notice-border: #3498db;
    color-scheme: light;
}
:root[data-theme="dark"] {
    --bg: #0f172a; --text: #e2e8f0; --text-soft: #cbd5e1; --heading: #f1f5f9; --muted: #94a3b8;
    --bar: #020617; --link: #60a5fa; --link-strong: #93c5fd;
    --card: #1e293b; --border: #334155; --border-strong: #475569; --thumb-bg: #f8fafc;
    --pill-text: #bfdbfe; --pill-bg: #1e3a8a; --pill-border: #1d4ed8;
    --tag-bg: #273449; --tag-text: #cbd5e1; --tag-border: #3b4a63;
    --btn-hover-bg: #e2e8f0; --btn-hover-text: #0f172a;
    --code-bg: #273449; --pre-bg: #111c33; --notice-bg: #172554; --notice-border: #60a5fa;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 0;
    line-height: 1.7;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Header */
header { background-color: var(--bar); color: #fff; padding: 1.25rem 0; }
.header-content, .footer-content { max-width: 880px; margin: 0 auto; padding: 0 1.25rem; }
header h1 { margin: 0 0 0.75rem 0; font-size: 1.6rem; font-weight: 600; }
nav { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; }
.nav-links { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.nav-links a {
    color: #ecf0f1; text-decoration: none; font-weight: 500;
    padding-bottom: 2px; border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.nav-links a:hover { color: #3498db; }
.nav-links a.active { color: #3498db; border-bottom-color: #3498db; font-weight: 600; }
.nav-icons { display: flex; align-items: center; gap: 0.85rem; }
.nav-icons a { color: #ecf0f1; text-decoration: none; font-size: 1.25rem; transition: opacity 0.15s, transform 0.15s; }
.nav-icons a:hover { opacity: 0.8; transform: translateY(-1px); }

/* Main */
main { flex: 1; padding: 2rem 1.25rem; max-width: 880px; margin: 0 auto; width: 100%; }
main a { color: var(--link); text-decoration: none; }
main a:hover { text-decoration: underline; }
main ul { padding-left: 1.25rem; }
main li { margin-bottom: 0.5rem; }
main h2 { font-size: 1.35rem; font-weight: 600; margin: 2.25rem 0 0.75rem; color: var(--heading); }
main h3 { font-size: 1.15rem; font-weight: 600; color: var(--heading); }
main img { max-width: 100%; height: auto; }

img.profile {
    float: right;
    height: 260px;
    max-width: 45%;
    margin: 0 0 15px 20px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

/* News card */
.news-container {
    clear: both;
    margin: 1.75rem 0;
    padding: 1.25rem 1.4rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.news-container h3 { margin: 0 0 1rem 0; }
main .news-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.85rem; }
main .news-list li { display: flex; align-items: baseline; gap: 0.85rem; margin: 0; font-size: 0.95rem; line-height: 1.55; }
.news-date {
    flex: 0 0 72px;
    font-size: 0.76rem; font-weight: 600;
    color: var(--pill-text); background-color: var(--pill-bg); border: 1px solid var(--pill-border);
    padding: 0.15rem 0.45rem; border-radius: 4px;
    text-align: center; white-space: nowrap;
}
.news-content { flex: 1; color: var(--text-soft); }
.news-content a { color: var(--link-strong); font-weight: 500; }

/* Project cards */
.project {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    margin: 0 0 1.25rem 0;
    padding: 1.1rem 1.25rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.project-thumb {
    flex: 0 0 190px;
    width: 190px;
    height: 135px;
    object-fit: contain;
    background: var(--thumb-bg);
    border-radius: 6px;
}
.project-body { flex: 1; min-width: 0; }
.project-body h3 { margin: 0 0 0.35rem 0; line-height: 1.35; }
.project-body p { margin: 0 0 0.6rem 0; font-size: 0.95rem; color: var(--text-soft); }
.project-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
main .project-links a {
    font-size: 0.8rem; font-weight: 600;
    color: var(--text); border: 1px solid var(--border-strong); border-radius: 4px;
    padding: 0.1rem 0.55rem; text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}
main .project-links a:hover { background-color: var(--btn-hover-bg); color: var(--btn-hover-text); border-color: var(--btn-hover-bg); text-decoration: none; }

/* Tags / badges */
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag {
    background-color: var(--tag-bg); color: var(--tag-text); border: 1px solid var(--tag-border);
    border-radius: 14px; padding: 0.05rem 0.6rem; font-size: 0.74rem; font-weight: 500;
}

/* Full write-ups on the projects page */
.writeup { clear: both; padding-top: 0.5rem; margin-bottom: 2.5rem; border-top: 1px solid var(--border); }
.writeup figure { margin: 1.25rem auto; text-align: center; }
.writeup figure img { max-width: 85%; border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.writeup figcaption { font-size: 0.88rem; color: var(--muted); font-style: italic; margin-top: 0.4rem; }

/* Footer */
footer { background-color: var(--bar); color: #ecf0f1; text-align: center; padding: 1.25rem 0; margin-top: 2rem; font-size: 0.95rem; }

@media (max-width: 640px) {
    img.profile { float: none; display: block; margin: 0 auto 1.25rem; max-width: 70%; }
    .project { flex-direction: column; }
    .project-thumb { width: 100%; flex-basis: auto; height: 180px; }
    main .news-list li { flex-direction: column; gap: 0.3rem; }
    .news-date { flex: none; }
}

/* Light / dark toggle */
.theme-toggle {
    background: none; border: 1px solid rgba(236, 240, 241, 0.35); border-radius: 6px;
    color: #ecf0f1; cursor: pointer; font-size: 1rem; line-height: 1;
    width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center;
    transition: border-color 0.15s, transform 0.15s;
}
.theme-toggle:hover { border-color: #ecf0f1; transform: translateY(-1px); }
.theme-toggle .fa-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .fa-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .fa-moon { display: none; }

/* Plots on white backgrounds stay readable in dark mode */
:root[data-theme="dark"] main img:not(.profile):not(.only-dark):not(.no-bg) { background: #ffffff; border-radius: 4px; }
/* Pages that ship separate dark-mode figures */
.only-dark { display: none; }
:root[data-theme="dark"] .only-dark { display: initial; }
:root[data-theme="dark"] .only-light { display: none; }

/* General content (project, notes and solutions pages) */
.page-title { font-size: 1.7rem; font-weight: 650; line-height: 1.3; margin: 0 0 1.25rem; color: var(--heading); }
main h1 { font-size: 1.5rem; font-weight: 650; margin: 2.25rem 0 0.75rem; color: var(--heading); }
main h4 { font-size: 1.02rem; font-weight: 600; color: var(--heading); }
main hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
main p[align="center"] { text-align: center; }
main code {
    background: var(--code-bg); color: var(--text); padding: 0.1rem 0.35rem;
    border-radius: 4px; font-size: 0.88em;
}
main pre {
    background: var(--pre-bg); border: 1px solid var(--border); border-radius: 6px;
    padding: 0.9rem 1rem; overflow-x: auto; font-size: 0.86rem; line-height: 1.5;
}
main pre code { background: none; padding: 0; font-size: inherit; }
main blockquote { margin: 1.25rem 0; padding: 0.25rem 1rem; border-left: 4px solid var(--border-strong); color: var(--text-soft); }
main .notice {
    background: var(--notice-bg); border-left: 4px solid var(--notice-border);
    padding: 0.75rem 1rem; border-radius: 4px;
}
main table { border-collapse: collapse; margin: 1.25rem 0; display: block; overflow-x: auto; font-size: 0.92rem; }
main th, main td { border: 1px solid var(--border); padding: 0.4rem 0.7rem; text-align: left; }
main th { background: var(--pre-bg); font-weight: 600; }
main details { margin: 1rem 0; }
main summary { cursor: pointer; font-weight: 600; }
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; }

/* Notes page */
.note-card {
    margin: 0 0 1rem 0; padding: 1rem 1.25rem;
    background: var(--card); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.note-card h3 { margin: 0 0 0.4rem 0; line-height: 1.35; }
main .note-card h3 a { color: var(--heading); }
.note-card p { margin: 0 0 0.6rem 0; font-size: 0.95rem; color: var(--text-soft); }
.note-card .project-links { margin-bottom: 0.4rem; }

/* ---------- Project detail pages ---------- */
main.wide { max-width: 1180px; }

.project-hero {
    display: flex; gap: 2rem; align-items: center;
    padding: 0.5rem 0 2rem; margin-bottom: 2rem; border-bottom: 1px solid var(--border);
}
.project-hero-text { flex: 1; min-width: 0; }
.project-title { font-size: 2.1rem; line-height: 1.2; font-weight: 700; margin: 0 0 0.6rem; color: var(--heading); }
.project-tagline { font-size: 1.15rem; line-height: 1.5; color: var(--text-soft); margin: 0 0 0.6rem; }
.project-meta { font-size: 0.92rem; color: var(--muted); margin: 0 0 1rem; }
.project-hero-links { margin-bottom: 1.25rem; }
main .project-hero-links a { font-size: 0.9rem; padding: 0.3rem 0.8rem; }
.project-hero-figure { flex: 0 0 300px; margin: 0; }
.project-hero-figure img { width: 100%; border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.project-hero-figure figcaption { font-size: 0.82rem; color: var(--muted); text-align: center; margin-top: 0.5rem; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }
.stat-tile {
    background: var(--card); border: 1px solid var(--border); border-radius: 8px;
    padding: 0.75rem 0.9rem; display: flex; flex-direction: column;
}
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.15; color: var(--link-strong); }
.stat-label { font-size: 0.82rem; color: var(--muted); line-height: 1.35; margin-top: 0.2rem; }

.project-grid { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 3rem; align-items: start; }
.project-content { max-width: 780px; }

/* Sticky contents sidebar */
.project-toc { position: sticky; top: 1.25rem; max-height: calc(100vh - 2.5rem); overflow-y: auto; font-size: 0.88rem; }
.project-toc summary {
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 0.5rem; list-style: none;
}
.project-toc summary::-webkit-details-marker { display: none; }
.project-toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
main .project-toc li { margin: 0; }
main .project-toc a {
    display: block; padding: 0.22rem 0 0.22rem 0.85rem; margin-left: -2px;
    border-left: 2px solid transparent; color: var(--muted); line-height: 1.4;
}
main .project-toc li.toc-top > a { color: var(--text-soft); font-weight: 600; margin-top: 0.35rem; }
main .project-toc li.toc-sub > a { padding-left: 1.6rem; font-size: 0.84rem; }
main .project-toc a:hover { color: var(--link); text-decoration: none; }
main .project-toc a.active { color: var(--link-strong); border-left-color: var(--link-strong); }

/* Abstract */
.abstract-box {
    background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--link-strong);
    border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 2rem;
}
.abstract-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--link-strong); }
.abstract-box p { margin: 0.4rem 0 0; }

/* Section headings inside the write-up */
.project-content h2 {
    font-size: 1.55rem; margin: 3rem 0 1rem; padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border); scroll-margin-top: 1rem;
}
.project-content h3 { font-size: 1.2rem; margin: 2rem 0 0.6rem; scroll-margin-top: 1rem; }
.project-content h4 { font-size: 1.02rem; margin: 1.5rem 0 0.4rem; scroll-margin-top: 1rem; }

/* Numbered figures */
.project-content { counter-reset: fig; }
.project-content figure.fig { counter-increment: fig; margin: 2rem auto; text-align: center; }
.project-content figure.fig img { max-width: 100%; border-radius: 6px; }
.project-content figure.fig figcaption {
    max-width: 42em; margin: 0.6rem auto 0; font-size: 0.9rem; line-height: 1.55;
    color: var(--text-soft); text-align: left;
}
.project-content figure.fig figcaption::before { content: "Figure " counter(fig) ". "; font-weight: 700; color: var(--heading); }

/* Algorithm boxes */
.algorithm {
    background: var(--card); border: 1px solid var(--border); border-top: 3px solid var(--heading);
    border-radius: 6px; padding: 0.9rem 1.25rem; margin: 1.5rem 0; font-size: 0.95rem;
}
.algorithm .algorithm-title { font-weight: 700; margin: 0 0 0.4rem; }
.algorithm ol { margin: 0.4rem 0 0; padding-left: 1.6rem; }
main .algorithm li { margin-bottom: 0.25rem; }
.algorithm .indent { padding-left: 1.5rem; }

/* Callout (e.g. AI usage) */
.callout {
    background: var(--notice-bg); border-left: 4px solid var(--notice-border);
    border-radius: 4px; padding: 0.75rem 1rem; margin: 1.5rem 0; font-size: 0.93rem;
}
.callout strong:first-child { display: block; margin-bottom: 0.2rem; }

/* Copy buttons on code blocks */
.copy-btn {
    position: absolute; top: 0.5rem; right: 0.5rem; z-index: 1;
    font-size: 0.75rem; font-weight: 600; padding: 0.15rem 0.55rem; cursor: pointer;
    color: var(--text); background: var(--card); border: 1px solid var(--border-strong); border-radius: 4px;
}
.copy-btn:hover { background: var(--btn-hover-bg); color: var(--btn-hover-text); }

/* References */
.references p { font-size: 0.9rem; line-height: 1.55; margin: 0 0 0.75rem; padding-left: 2rem; text-indent: -2rem; }

/* Previous / next */
.project-pager { display: flex; justify-content: space-between; gap: 1rem; margin: 3rem 0 1rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
main .project-pager a {
    flex: 1; max-width: 48%; display: flex; flex-direction: column; padding: 0.75rem 1rem;
    background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--heading); font-weight: 600;
}
main .project-pager a:hover { border-color: var(--link); text-decoration: none; }
.project-pager a span { font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.project-pager .pager-next { text-align: right; margin-left: auto; }
.back-to-projects { font-size: 0.9rem; }

@media (max-width: 1000px) {
    .project-grid { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
    .project-toc {
        position: static; max-height: none; background: var(--card);
        border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem;
    }
    .project-toc summary { cursor: pointer; margin-bottom: 0; }
    .project-toc details[open] summary { margin-bottom: 0.5rem; }
    .project-content { max-width: none; }
}
@media (max-width: 760px) {
    .project-hero { flex-direction: column-reverse; align-items: stretch; }
    .project-hero-figure { flex-basis: auto; max-width: 280px; margin: 0 auto; }
    .project-title { font-size: 1.65rem; }
}
.wide-page .header-content, .wide-page .footer-content { max-width: 1180px; }
@media (max-width: 1000px) {
    .project-toc summary::after { content: " ▾"; }
    .project-toc details[open] summary::after { content: " ▴"; }
}

/* Project pages: extras */
.project-hero-tags { margin: -0.4rem 0 1rem; }
.hero-wide .project-hero-figure { flex-basis: 420px; }
.code-fold { margin: 1.25rem 0; border: 1px solid var(--border); border-radius: 6px; background: var(--card); }
.code-fold > summary {
    padding: 0.55rem 0.9rem; font-size: 0.88rem; font-weight: 600; color: var(--link-strong);
    list-style: none;
}
.code-fold > summary::before { content: "▸ "; }
.code-fold[open] > summary::before { content: "▾ "; }
.code-fold > summary::-webkit-details-marker { display: none; }
.code-fold > .highlighter-rouge { margin: 0 0.6rem 0.6rem; }
.code-fold pre { margin: 0; }
.project-content .footnotes { font-size: 0.9rem; }
.project-content .footnotes ol { padding-left: 1.5rem; }
.project-content sup[role="doc-noteref"] a, .project-content a.footnote { font-size: 0.8em; }
@media (max-width: 760px) { .hero-wide .project-hero-figure { max-width: 100%; } }
