html {
    overflow-y: scroll;
}

body {
    font-family: 'Averia Serif Libre', 'Noto Serif SC', 'Noto Serif', "Optima", "Roboto", serif;
    font-weight: light;
    color: #2B2B2B;
    font-size: 17.6px;
    line-height: 1.6;
    margin: 0;
    padding: 55px;
    background-color: #fff;
    /* -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale; */
}

:lang(zh),
:lang(zh-CN),
:lang(zh-TW),
:lang(zh-HK),
:lang(zh-SG) {
    font-family: 'Noto Serif', 'Averia Serif Libre', serif;
}

.zh-body-bold {
    font-weight: 600;
}

.page-container {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    gap: 66px;
}

nav {
    width: 154px;
    flex-shrink: 0;
    text-align: right;
    font-size: 15.5px;
    position: -webkit-sticky;
    position: sticky;
    top: 55px;
    align-self: flex-start;
    height: auto;
    z-index: 100;
}

.nav-container {
    display: flex;
    flex-direction: column;
}

.nav-stack {
    display: grid;
    grid-template-areas: "stack";
    margin-bottom: 0;
}


.nav-layer {
    grid-area: stack;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.75s ease, visibility 0.75s ease;
    pointer-events: none;

    padding-top: 70px;

    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

.nav-layer.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;


    position: relative;
    height: auto;
}

#nav-toggle-container {
    min-height: 20px;
    padding-top: 5px;
    border-top: 1px dashed #eee;
    display: none;

    margin-bottom: 5px;
}

#nav-toggle {
    cursor: pointer;
    font-style: italic;
    font-size: 14px;
    display: block;
    text-decoration: none;


    background: linear-gradient(to right, #c24f46 50%, #999 50%);
    background-size: 200% 100%;
    background-position: 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: background-position 1.2s cubic-bezier(0.22, 0.61, 0.36, 1);
}

#nav-toggle:hover {
    background-position: 0%;
}

.nav-section {
    margin-bottom: 10px;
}

/* TOC links specific style */
/* TOC links specific style */
#toc-list a {
    font-size: 14px;
    margin-bottom: 8px;
    line-height: 1.3;
    display: block;

    /* Gradient: Right 50% = Gray (#555), Left 50% = Red (#c24f46) */
    background: linear-gradient(to right, #c24f46 50%, #555 50%);
    background-size: 200% 100%;
    background-position: 100%;

    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: background 0.8s ease,
        background-position 1.2s cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 1.2s ease,
        font-weight 0.8s ease;
}



/* ... */

#toc-list a.current {

    background: linear-gradient(to right, #c24f46 50%, #7db9de 50%);
    background-size: 200% 100%;
    background-position: 100%;
    /* Start Blue */
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: bold;
    transition: background 0.8s ease,
        background-position 1.2s cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 1.2s ease,
        font-weight 0.8s ease;
}

#toc-list a:hover,
#toc-list a.current:hover {
    background-position: 100%;
}

.nav-label {
    display: block;
    margin-bottom: 5px;
    color: #777;
    font-size: 13px;
    font-weight: 700;
}

#email-link {
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
    color: #2B2B2B;
    transition: opacity 0.35s ease, color 0.2s ease;
}

#linkedin-link {
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
    color: #2B2B2B;
    transition: opacity 0.35s ease, color 0.2s ease;
}

#email-link.fade-out {
    opacity: 0;
}

#wechat-link {
    cursor: pointer;
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
    color: #2B2B2B;
    transition: opacity 0.35s ease, color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

#wechat-link.fade-out {
    opacity: 0;
}



nav a {
    display: block;
    text-decoration: none;
    margin-bottom: 4px;

    background: linear-gradient(to right, #c24f46 50%, #2B2B2B 50%);
    background-size: 200% 100%;
    background-position: 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: background-position 1.2s cubic-bezier(0.22, 0.61, 0.36, 1);
    font-weight: 700;
}

nav a:hover {
    text-decoration: none;
    background-position: 0%;
}

nav a.current,
nav a.current:visited {
    font-weight: bold;
    background: linear-gradient(to right, #c24f46 50%, #7db9de 50%);
    background-size: 200% 100%;
    background-position: 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

nav a.current:hover {
    background-position: 0%;
}

.nav-stack {
    display: grid;
    grid-template-areas: "stack";
    margin-bottom: 25px;
}

.copyright {
    margin-top: 0;
    font-size: 9px;
    line-height: 1.3;
    color: #999;
    font-weight: 700;
}

#nav-toggle-container {
    padding-top: 10px;
    border-top: 1px dashed #eee;
    display: none;
    margin-bottom: 0;
    width: 80px;
    margin-left: auto;
}

.home-link:hover {
    text-decoration: none;
}

main {
    flex-grow: 1;
    max-width: 880px;
}

.page-title {
    font-size: 32px;
    margin: 0 0 1.8rem;
    font-weight: 600;
}

.content-with-photo {
    display: flex;
    gap: 22px;
    align-items: flex-start;
    max-width: 880px;
}

.bio-text {
    flex: 1;
    min-width: 0;
}

.bio-text::after {
    content: "";
    display: block;
    clear: both;
}

.research-interests li::before {
    content: "•";
    color: #c24f46;
    position: absolute;
    left: 0;
}

#back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background-color: #f0f0f0;
    color: #444;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, background-color 0.2s ease, transform 0.2s ease;
    z-index: 999;
    text-decoration: none;
    font-family: 'Times New Roman', serif;
}

#back-to-top.visible {
    opacity: 0.8;
    pointer-events: auto;
}

#back-to-top:hover {
    background-color: #e0e0e0;
    opacity: 1;
    transform: translateY(-2px);
}

.profile-figure {
    width: 115px;
    margin: 0 1.6em 0.6em 0;
    float: left;
}

.profile-figure img {
    width: 100%;
    height: auto;
    display: block;
}

.profile-caption {
    margin-top: 8px;
    font-size: 11.3px;
    line-height: 1.35;
    color: #666;
    font-weight: light;
}

@media (max-width: 800px) {
    .content-with-photo {
        flex-direction: column;
    }

    .profile-figure {
        width: 40%;
        max-width: 125px;
        margin: 0 1.2em 0.8em 0;
        float: left;
    }

    .profile-caption {
        font-size: 9.8px;
    }
}

h1 {
    font-size: 30px;
    margin-top: 0;
    margin-bottom: 20px;
    font-weight: regular;
}

.name-block {
    margin-bottom: 18px;
}

.zh-name ruby {
    ruby-position: over;
    font-size: 1em;
}

.quote-section {
    font-family: 'Averia Serif Libre', serif;
    font-style: italic;
    font-size: 1.1em;
    color: #666;
    margin: 2em 0;
    padding-left: 1em;
    background-color: #fafafa;
    padding: 1em 1em 1em 1.5em;
    border-radius: 4px;
}

/* Mobile-only inline TOC */
.mobile-toc {
    display: none;
    /* Hidden on desktop */
}

@media (max-width: 768px) {
    .mobile-toc {
        display: block;
        background-color: #fafafa;
        padding: 1em 1em 1em 1.5em;
        /* Match quote-section padding exactly */
        border-radius: 4px;
        margin: 1.5em 0;
        text-align: left;
        width: 100%;
        box-sizing: border-box;
        pointer-events: auto;
    }

    .mobile-toc-title {
        font-family: 'Averia Serif Libre', serif;
        font-style: italic;
        color: #999;
        font-size: 0.9em;
        margin-bottom: 0.5em;
    }

    .mobile-toc a {
        display: block;
        color: #555 !important;
        text-decoration: none;
        padding: 0.3em 0;
        font-size: 0.95em;
        border-bottom: 1px solid #eee;
        background: none !important;
        -webkit-text-fill-color: currentColor !important;
        pointer-events: auto;
        cursor: pointer;
    }

    .mobile-toc a:last-child {
        border-bottom: none;
    }

    .mobile-toc a:hover,
    .mobile-toc a:active {
        color: #333 !important;
    }
}

.research-item h2 {
    border-left: 4px solid #c24f46;
    padding-left: 15px;
    color: #2B2B2B;
    font-weight: 600;
    line-height: 1.3;
}

.research-item h2 a {
    color: inherit !important;
    text-decoration: none;
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
    padding: 0;
}

.research-item h2 a:hover {
    color: #c24f46 !important;
}

.research-abstract {
    color: #2B2B2B;
}

/* Research Metadata Styles */
.research-meta {
    margin-top: 5px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.research-date {
    font-family: 'Averia Serif Libre', cursive;
    font-weight: 700;
    color: #555;
    font-size: 1.05em;
}

.research-tag {
    font-family: 'Averia Libre', cursive;
    font-size: 0.9em;
    color: #c24f46;
    background-color: rgba(194, 79, 70, 0.08);
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 700;
}

.zh-name rt {
    font-size: 0.4em;
    letter-spacing: 0;
    font-family: 'Noto Serif', 'Noto Serif SC', 'Noto Sans', serif;
    position: relative;
    top: -3.5px;
}

.ipa {
    font-family: 'Noto Serif', 'Noto Serif SC', 'Noto Sans', 'Averia Serif Libre', serif;
    font-size: 0.9em;
}

h2 {
    font-size: 20px;
    margin-top: 30px;
    margin-bottom: 15px;
    font-weight: bold;
}

p {
    margin-bottom: 15px;
    text-align: left;
}

ul {
    padding-left: 20px;
    margin-bottom: 20px;
}

li {
    margin-bottom: 5px;
}

main a {
    color: #c24f46;
    text-decoration: none;
    transition: background-color 0.2s ease;
    padding: 0 2px;
    border-radius: 2px;
}

main a:hover {
    text-decoration: none;
    background-color: rgba(194, 79, 70, 0.1);
}

/* MathJax Safari Fix: Isolate from global font settings */
mjx-container,
.MathJax {
    font-weight: normal !important;
    -webkit-font-smoothing: auto !important;
    font-family: unset !important;
    /* Prevent global font inheritance */
}

/* MathJax responsive - allow horizontal scroll on overflow */
.MathJax_Display,
mjx-container[jax="CHTML"][display="true"],
mjx-container[jax="SVG"][display="true"] {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    padding: 10px 0;
}

@media (max-width: 768px) {
    body {
        padding: 15px;
        font-size: 16px;
    }

    .page-container {
        flex-direction: column;
        gap: 30px;
    }

    nav {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        gap: 20px;
        padding: 8px 15px;
        flex-wrap: wrap;
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 1000;
        background-color: rgba(255, 255, 255, 0.98);
        border-bottom: 1px solid #eee;
        /* Full-width positioning */
        margin-left: -15px;
        margin-right: -15px;
        width: calc(100% + 30px);
        transition: transform 0.2s ease;
    }

    /* Hide nav when scrolling up */
    nav.nav-hidden {
        transform: translateY(-100%);
    }

    .nav-section {
        margin-bottom: 0;
        display: flex;
        flex-direction: row;
        gap: 15px;
        align-items: center;
        flex-wrap: wrap;
        transition: opacity 0.2s ease, max-height 0.2s ease;
    }

    /* Hide contact section when nav is collapsed (scrolled) */
    nav.nav-collapsed .nav-section:nth-child(2) {
        display: none;
    }

    nav.nav-collapsed {
        justify-content: flex-start;
        padding-left: 15px;
    }

    .nav-label {
        font-size: 13px;
        margin-bottom: 0;
        display: inline-block;
    }

    nav a {
        display: inline-block;
        margin-bottom: 0;
        font-size: 14px;
    }

    nav a.current,
    nav a.current:visited {
        font-weight: bold;
        color: #7db9de;
    }

    main {
        width: 100%;
        max-width: 100%;
    }

    .bio-text,
    .content-with-photo {
        width: 100%;
    }

    .profile-figure {
        width: 30%;
        max-width: 100px;
        margin: 0 1em 0.6em 0;
    }

    .copyright {
        display: none;
    }

    h1 {
        font-size: 30px;
        margin-top: 10px;
    }

    h2 {
        font-size: 18px;
    }

    #x2wrap {
        width: 100%;
        max-width: none;
        height: 300px !important;
        margin: 0;
    }

    /* Mobile Nav Layer Fixes */
    .nav-container {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
    }

    .nav-stack {
        display: contents;
        /* Children flow directly into parent */
    }

    .nav-layer {
        display: none;
        /* Completely hidden */
    }

    .nav-layer.active {
        display: contents;
        /* Children flow directly into parent - no wrapper */
        opacity: 1;
        visibility: visible;
    }

    /* Explicitly hide TOC layer on mobile - only site nav shows */
    #nav-layer-toc,
    #nav-layer-toc.active {
        display: none !important;
    }

    /* Force site layer to show if it's hidden */
    #nav-layer-site {
        display: contents !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    #nav-toggle-container {
        border-top: none;
        padding: 0;
        margin: 0;
        min-height: 0;
        width: auto;
        display: none !important;
        /* Always hidden on mobile */
    }
}

/* Disable red gradient hover on mobile */
@media (max-width: 768px) {

    nav a,
    #nav-toggle,
    #toc-list a,
    #toc-list a.current {
        background: none !important;
        -webkit-background-clip: unset !important;
        background-clip: unset !important;
        -webkit-text-fill-color: currentColor !important;
        transition: color 0.2s ease !important;
    }

    #email-link,
    #wechat-link {
        transition: opacity 0.35s ease, color 0.2s ease !important;
    }

    nav a {
        color: #2B2B2B;
    }

    nav a:hover {
        color: #777;
    }

    nav a.current,
    nav a.current:visited {
        color: #7db9de;
    }

    #toc-list a {
        color: #555;
    }

    #toc-list a:hover {
        color: #777;
    }

    #toc-list a.current {
        color: #7db9de;
    }

    #nav-toggle {
        color: #999;
    }

    #nav-toggle:hover {
        color: #777;
    }
}

footer {
    text-align: center;
    margin-top: 50px;
    padding-top: 20px;
    color: #777;
    font-size: 13px;
}

@media (max-width: 480px) {
    body {
        padding: 15px;
        font-size: 15px;
    }

    nav {
        flex-direction: column;
        gap: 15px;
    }

    h1 {
        font-size: 26px;
    }

    #x2wrap {
        width: 100%;
        max-width: none;
        height: 250px !important;
        margin: 0;
    }
}