/* ===== CSS Custom Properties (Light Theme) ===== */
:root {
    --color-bg: #ffffff;
    --color-bg-secondary: #f8f9fa;
    --color-text: #000000;
    --color-text-secondary: #000000;
    --color-link: #1772d0;
    --color-link-hover: #f09228;
    --color-highlight: #a4133c;
    --color-border: #e0e0e0;
    --color-card-bg: #ffffff;
    --color-card-shadow: rgba(0, 0, 0, 0.08);
    --color-card-shadow-hover: rgba(0, 0, 0, 0.15);
    --color-control-bg: rgba(255, 255, 255, 0.95);
    --color-heading: #000000;
    --color-particle: rgba(23, 114, 208, 0.25);
    --color-particle-line: rgba(23, 114, 208, 0.08);
    --color-pill-bg: #f0f4f8;
    --color-pill-text: #1772d0;
    --img-drop-shadow: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.8));
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
    --color-bg: #0d1117;
    --color-bg-secondary: #161b22;
    --color-text: #c9d1d9;
    --color-text-secondary: #8b949e;
    --color-link: #58a6ff;
    --color-link-hover: #f0a868;
    --color-highlight: #f2718f;
    --color-border: #30363d;
    --color-card-bg: #161b22;
    --color-card-shadow: rgba(0, 0, 0, 0.5);
    --color-card-shadow-hover: rgba(0, 0, 0, 0.7);
    --color-control-bg: rgba(22, 27, 34, 0.85);
    --color-heading: #f0f6fc;
    --color-particle: rgba(88, 166, 255, 0.30);
    --color-particle-line: rgba(88, 166, 255, 0.10);
    --color-pill-bg: #1f2933;
    --color-pill-text: #58a6ff;
    --img-drop-shadow: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6));
}

/* Smooth theme transition (skipped under reduced-motion further below) */
body {
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== Reset + Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Titillium Web', Verdana, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: 400;
    color: var(--color-text);
    background-color: var(--color-bg);
    line-height: 1.6;
}

a {
    color: var(--color-link);
    text-decoration: none;
    transition: color 0.2s ease;
}

strong {
    font-weight: 600;
}

a:focus, a:hover {
    color: var(--color-link-hover);
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
}

ul {
    padding-left: 1.2em;
}

/* ===== Particle Canvas ===== */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* ===== Site Container ===== */
.site-container {
    position: relative;
    z-index: 1;
    max-width: 1060px;
    margin: 0 auto;
    padding: 0 1.5rem 2rem;
}

/* ===== Hero Section ===== */
.hero {
    padding: 2.5rem 0 1.5rem;
}

.hero-name {
    text-align: center;
    font-size: 2.8rem;
    font-weight: 600;
    margin: 0 0 0.3rem;
    color: var(--color-heading);
}

.hero-name img {
    height: 55px;
    vertical-align: middle;
    margin-left: 0.3rem;
}

.hero-contact {
    text-align: center;
    margin: 0.5rem 0 1rem;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

.hero-links {
    text-align: center;
    margin: 0.8rem 0 2rem;
    font-size: 1.1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.hero-links img {
    width: 18px;
    height: 18px;
    vertical-align: middle;
}

.hero-links .link-sep {
    color: var(--color-text-secondary);
}

.hero-bio {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.hero-bio-text p:first-child {
    margin-top: 0;
}

.hero-bio-text {
    flex: 1;
    text-align: justify;
}

.hero-bio-photo {
    flex: 0 0 180px;
}

.hero-bio-photo img {
    width: 100%;
    border: 1px solid #201f1f;
    filter: var(--img-drop-shadow);
}

/* ===== Section Headings ===== */
.section-heading {
    font-family: 'Titillium Web', Verdana, Helvetica, sans-serif;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--color-heading);
    margin: 2.5rem 0 1rem;
}

.section-heading-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 2.5rem 0 1rem;
}

.section-heading-row .section-heading {
    margin: 0;
    padding: 0;
    border: none;
}

.equal-contrib-note {
    font-size: 0.9rem;
    font-weight: 700;
}

/* ===== Publication Cards ===== */
.pub-card {
    display: flex;
    gap: 4rem;
    padding: 1.2rem 0;
}

.pub-card-thumb {
    flex: 0 0 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
}

/* A lone thumb centers vertically against tall text (e.g. long author lists) */
.pub-card-thumb:has(> :only-child) {
    justify-content: center;
}

.pub-card-thumb img,
.pub-card-thumb video {
    width: 100%;
    border: none;
    filter: var(--img-drop-shadow);
    display: block;
}

.pub-card-info {
    flex: 1;
}

.pub-title {
    font-family: 'Titillium Web', Verdana, Helvetica, sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.4rem;
    color: var(--color-heading);
    line-height: 1.3;
}

.pub-authors {
    margin: 0 0 0.3rem;
    line-height: 1.5;
}

.pub-venue {
    font-style: italic;
    margin: 0 0 0.5rem;
    color: var(--color-text-secondary);
}

/* Award / selection highlights (e.g. Oral, Technical Papers Trailer) */
.pub-highlight {
    color: var(--color-highlight);
    font-style: normal;
}

.pub-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.pub-links a {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 999px;
    background: var(--color-pill-bg);
    color: var(--color-pill-text);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.pub-links a:hover {
    background: var(--color-link);
    color: #ffffff;
}

.pub-note {
    font-size: 0.9rem;
    margin-top: 0.3rem;
    color: var(--color-text-secondary);
}

/* ===== Education Items ===== */
.edu-list {
    list-style: none;
    padding: 0;
}

.edu-item {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    padding: 0.8rem 0;
}

.edu-item img {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    margin-top: 0.2rem;
}

.edu-item-content {
    flex: 1;
}

.edu-item-row {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.edu-item-row .date {
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* ===== Teaching / Tutorial Items ===== */
.teaching-list {
    list-style: disc;
    padding-left: 1.5em;
}

.teaching-list li {
    margin-bottom: 0.5rem;
}

.teaching-item-row {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.teaching-item-row .date {
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* ===== About Myself ===== */
.about-section p {
    text-align: left;
}

.about-section .poem-img {
    height: 50px;
    vertical-align: middle;
}

.poem-translation {
    display: block;
    text-align: right;
    font-style: italic;
    margin-top: 0.5rem;
    color: var(--color-text-secondary);
}

/* ===== Footer ===== */
.site-footer {
    text-align: right;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    padding: 1.5rem 0;
    margin-top: 2rem;
    line-height: 1.7;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
    position: fixed;
    top: 1.2rem;
    right: 1.2rem;
    z-index: 200;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-control-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px var(--color-card-shadow);
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--color-link);
    color: var(--color-link);
}

.theme-toggle svg {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 20px;
    height: 20px;
    transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sun = midday (light), Moon = midnight (dark); they rotate-crossfade on toggle */
.theme-toggle .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
.theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.4); }
[data-theme="dark"] .theme-toggle .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(0.4); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }

/* Black brush-art images (name calligraphy, poem) inverted to read on dark */
[data-theme="dark"] img[src$="tingwu.png"],
[data-theme="dark"] img[src$="poem.png"] {
    filter: invert(1);
}

[data-theme="dark"] .hero-bio-photo img {
    border-color: var(--color-border);
}

/* Logos/icons ship with baked-in (usually white) backgrounds that turn into
   boxes on a dark page. Sit them on a uniform white tile so every one reads
   correctly. Uses an outward box-shadow rather than padding, so the logo keeps
   its full size (the white extends outward instead of shrinking it inward). */
[data-theme="dark"] .edu-item img {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 0 0 4px #fff;
}

[data-theme="dark"] .hero-links img {
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 0 0 3px #fff;
}

/* ===== Back-to-Top Button ===== */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-control-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px var(--color-card-shadow);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease,
                background-color 0.2s ease;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top::before {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    border-top: 2px solid var(--color-text);
    border-left: 2px solid var(--color-text);
    transform: rotate(45deg) translate(2px, 2px);
    margin: auto;
}

.back-to-top:hover {
    background: var(--color-link);
    border-color: var(--color-link);
}

.back-to-top:hover::before {
    border-color: #ffffff;
}

/* ===== Scroll Animations ===== */
.animate-on-scroll {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s ease-out var(--anim-delay, 0ms),
                transform 0.6s ease-out var(--anim-delay, 0ms);
}

.animate-on-scroll.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ===== Typing Robot ===== */
.typing-word {
    opacity: 0;
    transition: opacity 0.05s ease;
}

.typing-word.revealed {
    opacity: 1;
}

.typing-robot {
    display: inline-block;
    vertical-align: middle;
    margin-left: 2px;
}

@keyframes typing-robot-blink {
    0%, 45% { opacity: 1; }
    50%, 95% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes typing-robot-celebrate {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    30% { transform: translateY(-12px) rotate(0deg); }
    50% { transform: translateY(-12px) rotate(360deg); }
    70% { transform: translateY(0) rotate(360deg); }
    100% { transform: translateY(0) rotate(360deg); opacity: 0; }
}

.typing-robot.celebrate {
    animation: typing-robot-celebrate 1s ease forwards;
}

/* ===== Easter egg: G1 rescue-breathing video overlay ===== */
.egg-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    animation: egg-in 0.3s ease forwards;
}

@keyframes egg-in { to { opacity: 1; } }

.egg-caption {
    margin: 0;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.egg-overlay video {
    max-width: min(90vw, 900px);
    max-height: 72vh;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    background: #000;
}

.egg-close {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.egg-close:hover { background: rgba(255, 255, 255, 0.3); }

.egg-hint {
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
}

/* ===== 3D tilt on publication thumbnails ===== */
.pub-card-thumb {
    transition: transform 0.18s ease;
    transform-style: preserve-3d;
}

/* ===== Responsive: Tablet (768px) ===== */
@media (max-width: 768px) {
    .hero-name {
        font-size: 2.2rem;
    }

    .hero-bio {
        flex-direction: column;
        align-items: center;
    }

    .hero-bio-photo {
        flex: 0 0 auto;
        width: 150px;
        order: -1;
    }

    .hero-bio-text {
        text-align: left;
    }

    .pub-card {
        flex-direction: column;
    }

    .pub-card-thumb {
        flex: none;
        width: 60%;
        margin: 0 auto;
    }
}

/* ===== Responsive: Mobile (480px) ===== */
@media (max-width: 480px) {
    .hero-name {
        font-size: 1.8rem;
    }

    .hero-name img {
        height: 40px;
    }

    .hero-links {
        font-size: 0.95rem;
        gap: 0.3rem;
    }

    .pub-card-thumb {
        width: 80%;
    }

    .pub-title {
        font-size: 1rem;
    }

    .site-container {
        padding: 0 1rem 1.5rem;
    }

    .edu-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-heading {
        font-size: 1.2rem;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    body {
        transition: none;
    }

    .animate-on-scroll {
        opacity: 1;
        transform: none;
        transition: none;
    }


    #particle-canvas {
        display: none;
    }

    .back-to-top {
        transition: none;
    }

    .typing-word {
        opacity: 1 !important;
        transition: none;
    }

    .typing-robot {
        display: none;
    }

    .theme-toggle svg,
    .pub-card-thumb {
        transition: none;
    }

    .egg-overlay {
        animation: none;
        opacity: 1;
    }
}

/* ===== Print ===== */
@media print {
    #particle-canvas,
    .theme-toggle,
    .back-to-top,
    .typing-robot {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    a {
        color: #1772d0;
    }

    .pub-card {
        break-inside: avoid;
    }

    .animate-on-scroll {
        opacity: 1;
        transform: none;
    }
}
