/* global */
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700');

:root {
    --bg: #101214;
    --panel: #171a1d;
    --text: #c9ccd1;
    --muted: #7a7c80;
    --heading: #ffffff;
    --border: #2a2f35;
    --accent: #79d3c8;
    --accent-strong: #91e6dc;
    --shadow: rgba(0, 0, 0, 0.24);
}

body.light-mode {
    --bg: #ffffff;
    --panel: #f6f7f8;
    --text: #111111;
    --muted: #4d535a;
    --heading: #000000;
    --border: #d8dde3;
    --accent: #146b63;
    --accent-strong: #0e514a;
    --shadow: rgba(17, 24, 39, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1,
h2,
h3,
.white {
    color: var(--heading);
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

a {
    color: var(--muted);
    text-decoration: none;
}

a:hover {
    color: var(--accent-strong);
}

.theme-toggle {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 10;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--panel);
    color: var(--heading);
    box-shadow: 0 12px 30px var(--shadow);
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle:hover {
    transform: translateY(-1px);
    border-color: var(--accent);
    color: var(--accent-strong);
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(260px, 0.9fr) minmax(420px, 1.1fr);
    min-height: 100vh;
}

/* section 1 */
.section-1 {
    position: sticky;
    top: 0;
    align-self: start;
    min-height: 100vh;
    padding: 38vh 2rem 4rem;
    text-align: center;
}

.section-1 p {
    font-size: 1.1rem;
    padding-bottom: 10px;
    margin: 0;
    color: var(--muted);
}

.section-1 h1 {
    font-size: 1.8rem;
    margin: 18px 0 10px;
    letter-spacing: 0;
}

.section-1 .chinese-name {
    color: var(--text);
    font-size: 1rem;
    padding-bottom: 8px;
}

.section-1 a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    padding: 10px;
}

.white {
    transition: transform 0.25s ease, color 0.25s ease;
}

.white:hover {
    transform: translateX(6px);
}

/* section 2 */
.section-2 {
    width: min(760px, calc(100% - 3rem));
    padding: 9vh 0 6rem;
}

.section-2 h2 {
    font-size: 1.7rem;
    margin: 42px 0 14px;
}

.section-2 h2:first-child {
    margin-top: 0;
}

.section-2 h3 {
    font-size: 1rem;
    margin: 18px 0 8px;
}

.section-2 p {
    font-size: 1.05rem;
    line-height: 1.68;
    padding-bottom: 12px;
    margin: 0;
}

.education-list {
    margin: 0 0 6px;
    padding-left: 1.2rem;
    color: var(--text);
}

.education-list li {
    margin-bottom: 8px;
    font-size: 1.02rem;
    line-height: 1.55;
}

.degree-name,
.school-name {
    display: block;
}

.degree-name {
    color: var(--text);
}

.school-name {
    margin-top: 2px;
    color: var(--text);
    font-size: 0.98rem;
    font-weight: 700;
}

body.light-mode .school-name {
    color: var(--accent-strong);
}

.patent-link {
    display: inline;
    border: 0;
    border-bottom: 1px solid var(--accent);
    padding: 0;
    background: transparent;
    color: var(--accent-strong);
    font: inherit;
    cursor: pointer;
}

.patent-link:hover,
.patent-link:focus-visible {
    color: var(--heading);
}

.patent-popover {
    display: none;
    position: fixed;
    top: 82px;
    right: 22px;
    z-index: 9;
    width: min(440px, calc(100vw - 32px));
    padding: 18px 18px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 22px 50px var(--shadow);
}

.patent-popover.is-open {
    display: block;
}

.patent-popover::before {
    content: "";
    position: absolute;
    top: -9px;
    right: 42px;
    width: 16px;
    height: 16px;
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    background: var(--panel);
    transform: rotate(45deg);
}

.patent-popover h3 {
    margin: 0 28px 10px 0;
}

.patent-popover ul {
    margin: 0;
    padding-left: 1.15rem;
}

.patent-popover li {
    margin-bottom: 9px;
    color: var(--text);
    line-height: 1.45;
}

.patent-popover a {
    display: grid;
    gap: 2px;
    color: var(--text);
    border-bottom: 1px solid transparent;
}

.patent-popover a:hover {
    color: var(--accent-strong);
    border-bottom-color: var(--accent);
}

.patent-number {
    color: var(--accent-strong);
    font-weight: 700;
}

.patent-chinese {
    color: var(--muted);
    font-size: 0.94rem;
}

.patent-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    color: var(--heading);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.patent-close:hover,
.patent-close:focus-visible {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.skills-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.skills-list span {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    font-size: 0.92rem;
}

.projects-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 42px;
    margin-bottom: 14px;
}

.projects-heading h2 {
    margin: 0;
}

.project-toggle-all {
    flex: 0 0 auto;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 13px;
    background: var(--panel);
    color: var(--heading);
    font: inherit;
    font-size: 0.94rem;
    cursor: pointer;
}

.project-toggle-all:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.project-list {
    display: grid;
    gap: 12px;
}

.project-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 34px var(--shadow);
    overflow: hidden;
}

.project-summary {
    display: grid;
    grid-template-columns: 96px 1fr 24px;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 108px;
    padding: 12px 14px;
    border: 0;
    background: transparent;
    color: var(--heading);
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.project-summary:hover .project-title,
.project-summary:focus-visible .project-title {
    color: var(--accent-strong);
}

.project-summary:focus-visible,
.project-toggle-all:focus-visible,
.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.project-thumb,
.project-placeholder {
    width: 96px;
    height: 76px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #ffffff;
}

.project-thumb {
    display: block;
    object-fit: cover;
}

.project-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    background:
        linear-gradient(135deg, rgba(121, 211, 200, 0.18), rgba(255, 255, 255, 0.04)),
        var(--bg);
    font-size: 1.55rem;
}

.project-title {
    color: var(--heading);
    font-size: 1.08rem;
    font-weight: 700;
    line-height: 1.35;
    transition: color 0.2s ease;
}

.project-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-weight: 700;
    transition: transform 0.2s ease;
}

.project-card.is-open .project-indicator {
    transform: rotate(90deg);
}

.project-details {
    display: none;
    padding: 0 18px 20px;
    border-top: 1px solid var(--border);
}

.project-card.is-open .project-details {
    display: block;
}

.project-gallery {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(128px, 1fr);
    gap: 10px;
    margin: 18px 0 16px;
    overflow-x: auto;
    padding-bottom: 4px;
    position: relative;
}

/* image popup overlay for gallery thumbnails */
.image-popup {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.75);
}

.image-popup.is-open {
    display: flex;
}

.image-popup-backdrop {
    position: absolute;
    inset: 0;
    background: transparent;
}

.image-popup-img {
    max-width: min(100%, 960px);
    max-height: min(100%, 90vh);
    width: auto;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
    position: relative;
    z-index: 1;
    object-fit: contain;
}

.image-popup-close {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--panel);
    color: var(--heading);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.image-popup-close:hover,
.image-popup-close:focus-visible {
    border-color: var(--accent);
    color: var(--accent-strong);
}

/* subtle scroll hint: right arrow in circle (stays fixed while scrolling) */
.project-gallery::after {
    content: '›';
    position: sticky;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--panel);
    color: var(--accent);
    font-size: 1.6rem;
    font-weight: 700;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

/* show arrow only when gallery has overflow */
.project-gallery.has-overflow::after {
    opacity: 0.6;
}

.project-gallery img {
    width: 100%;
    height: 118px;
    display: block;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    cursor: zoom-in;
}

.project-gallery-full-aspect {
    grid-auto-columns: minmax(160px, auto);
    align-items: start;
}

.project-gallery-full-aspect img {
    width: auto;
    height: auto;
    max-height: 220px;
    object-fit: contain;
    background: #ffffff;
}

/* anchor specific image crops to bottom for better framing */
.project-gallery img.project-image-bottom {
    object-position: center bottom;
}

/* responsive video for project details */
.project-video {
    width: 100%;
    height: auto;
    max-height: 420px;
    display: block;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #000;
}

@media (max-width: 560px) {
    .project-video {
        max-height: 260px;
    }
}

.project-details p {
    font-size: 0.98rem;
    line-height: 1.6;
    padding-bottom: 10px;
}

.contact-list {
    display: grid;
    gap: 8px;
}

.email-link {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    width: fit-content;
    color: var(--text);
    border-bottom: 1px solid var(--accent);
}

/* media queries */
@media (max-width: 860px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .section-1 {
        position: static;
        min-height: auto;
        padding: 5rem 1.5rem 2rem;
    }

    .section-2 {
        width: 100%;
        padding: 1rem 1.5rem 4rem;
    }
}

@media (max-width: 560px) {
    .theme-toggle {
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
    }

    .projects-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .project-toggle-all {
        width: 100%;
    }

    .project-summary {
        grid-template-columns: 72px 1fr 20px;
        gap: 12px;
        min-height: 92px;
        padding: 10px;
    }

    .project-thumb,
    .project-placeholder {
        width: 72px;
        height: 58px;
    }

    .project-title {
        font-size: 0.98rem;
    }

    .project-details {
        padding: 14px 14px 18px;
    }

    .project-gallery {
        grid-auto-columns: 168px;
        margin-top: 2px;
    }

    .project-gallery img {
        height: 112px;
    }
}
