/* ============================================================
   Xin (Eric) Wang — Personal Website
   Modern redesign
   ============================================================ */

:root {
    /* Light theme (default) */
    --bg: #fafaf8;
    --bg-elevated: #ffffff;
    --bg-soft: #f3f3ef;
    --surface: #ffffff;
    --border: #e6e6e0;
    --border-strong: #d4d4cc;

    --text: #15171a;
    --text-soft: #3a3d44;
    --text-muted: #6b6f78;

    --accent: #003660;        /* UCSB navy */
    --accent-hover: #0a4d80;
    --accent-soft: #e8eef5;
    --gold: #FEBC11;          /* UCSB gold */
    --highlight: #c0392b;

    --radius-sm: 6px;
    --radius: 12px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10), 0 4px 8px rgba(15, 23, 42, 0.06);

    --nav-blur: saturate(180%) blur(14px);

    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Newsreader", "Source Serif 4", Georgia, "Times New Roman", serif;
    --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;

    --max-width: 1100px;
    --content-padding: 24px;
}

[data-theme="dark"] {
    --bg: #0e0f12;
    --bg-elevated: #16181d;
    --bg-soft: #1a1d22;
    --surface: #16181d;
    --border: #262a31;
    --border-strong: #353a44;

    --text: #ecedef;
    --text-soft: #c4c7cc;
    --text-muted: #888d96;

    --accent: #6aa0d6;
    --accent-hover: #8fbce8;
    --accent-soft: #1c2937;
    --highlight: #ff7a6b;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.55);
}

/* ============================================================
   Reset / base
   ============================================================ */

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.65;
    font-feature-settings: "ss01", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease, opacity 0.15s ease;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
}

p {
    margin: 0 0 0.9em 0;
}

h1, h2, h3, h4 {
    color: var(--text);
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin: 0 0 0.5em 0;
}

h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); letter-spacing: -0.025em; }
h2 { font-size: clamp(1.5rem, 3vw, 1.9rem); }
h3 { font-size: 1.15rem; font-weight: 600; }

::selection {
    background: var(--accent);
    color: #fff;
}

/* ============================================================
   Navigation
   ============================================================ */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    backdrop-filter: var(--nav-blur);
    -webkit-backdrop-filter: var(--nav-blur);
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    border-bottom: 1px solid var(--border);
    transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.navbar-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 14px var(--content-padding);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.nav-brand {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--text);
    white-space: nowrap;
}

.nav-brand:hover {
    color: var(--accent);
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
    flex-wrap: wrap;
}

.nav-links a {
    display: inline-block;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-links a:hover {
    background: var(--accent-soft);
    color: var(--accent);
    text-decoration: none;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-soft);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    transform: rotate(15deg);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.nav-mobile-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    width: 36px;
    height: 36px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

@media (max-width: 800px) {
    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 8px;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow);
    }
    .nav-links.open { display: flex; }
    .nav-links a {
        padding: 12px 16px;
        border-radius: var(--radius-sm);
    }
    .nav-mobile-toggle { display: inline-flex; }
}

/* ============================================================
   Layout
   ============================================================ */

.container {
    max-width: var(--max-width);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--content-padding);
    padding-right: var(--content-padding);
}

main {
    padding-top: 80px;
}

section {
    padding: 28px 0 20px 0;
    scroll-margin-top: 70px;
}

section.hero {
    padding-top: 32px;
    padding-bottom: 12px;
}

.section-title {
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin-bottom: 0.9em;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.section-title h2 {
    margin: 0;
}

.section-title .accent-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, var(--border), transparent);
}

.section-title .meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ============================================================
   Hero
   ============================================================ */

.hero {
    position: relative;
    padding: 40px 0 12px 0;
    overflow: hidden;
}

.hero::before {
    content: "";
    position: absolute;
    top: -120px;
    right: -100px;
    width: 480px;
    height: 480px;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent) 18%, transparent), transparent 65%);
    pointer-events: none;
    z-index: 0;
}

[data-theme="dark"] .hero::before {
    background: radial-gradient(circle, color-mix(in srgb, var(--accent) 25%, transparent), transparent 65%);
}

.hero-grid {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 36px;
}

.hero-content {
    flex: 1;
    min-width: 0;
    max-width: 70ch;
}

@media (max-width: 720px) {
    .hero-grid {
        flex-direction: column;
        align-items: flex-start;
        gap: 24px;
    }
    .hero-image { order: -1; }
}

.hero-name {
    font-family: var(--font-display);
    font-weight: 600;
    margin: 0 0 14px 0;
    font-size: clamp(1.8rem, 3.5vw, 2.4rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.hero-roles {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.role {
    font-size: 1.02rem;
    color: var(--text-soft);
    line-height: 1.5;
}

.role strong {
    color: var(--text);
    font-weight: 600;
}

.hero-contact {
    margin: 18px 0 14px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-family: var(--font-mono);
}

.hero-socials {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.social-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-soft);
    transition: all 0.2s ease;
}

.social-icon:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
    transform: translateY(-2px);
    text-decoration: none;
}

.social-icon img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

[data-theme="dark"] .social-icon img[src$=".svg"] {
    filter: invert(1) brightness(1.4);
}

.social-icon svg {
    width: 18px;
    height: 18px;
}

.hero-image {
    position: relative;
    width: 180px;
    height: 180px;
    justify-self: start;
    flex-shrink: 0;
}

@media (max-width: 720px) {
    .hero-image {
        width: 140px;
        height: 140px;
    }
}

.hero-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 4px solid var(--bg-elevated);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
}

.hero-image::after {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: conic-gradient(from 180deg, var(--accent), var(--gold), var(--accent));
    z-index: -1;
    opacity: 0.5;
    filter: blur(12px);
    animation: rotate 8s linear infinite;
}

@keyframes rotate {
    to { transform: rotate(360deg); }
}

.hero-image:hover img {
    transform: scale(1.03);
}

/* ============================================================
   Bio
   ============================================================ */

.bio-text {
    font-size: 1.02rem;
    color: var(--text-soft);
    max-width: 75ch;
    line-height: 1.75;
}

.bio-text b, .bio-text strong {
    color: var(--text);
    font-weight: 600;
}

/* ============================================================
   News (timeline)
   ============================================================ */

.news-wrapper {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 4px 8px;
    max-height: 380px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.news-wrapper::-webkit-scrollbar { width: 8px; }
.news-wrapper::-webkit-scrollbar-track { background: transparent; }
.news-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}
.news-wrapper::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.news-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

.news-table tr {
    border-bottom: 1px solid var(--border);
}

.news-table tr:last-child { border-bottom: none; }

.news-table td {
    padding: 12px 8px;
    line-height: 1.55;
    vertical-align: top;
    color: var(--text-soft);
    font-size: 0.93rem;
}

.news-table td:first-child {
    width: 90px;
    white-space: nowrap;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
}

.news-table td:first-child b {
    display: inline-block;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.06em;
    font-weight: 700;
    font-size: 0.7rem;
}

@media (max-width: 600px) {
    .news-table tr { display: block; padding: 8px 0; }
    .news-table td { display: block; padding: 4px 8px; }
    .news-table td:first-child { width: auto; }
}

/* ============================================================
   Awards (grid)
   ============================================================ */

.awards-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.award-row {
    display: grid;
    grid-template-columns: 70px 1fr;
    gap: 18px;
    padding: 11px 18px;
    align-items: baseline;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}

.award-row:last-child { border-bottom: none; }

.award-row:hover {
    background: var(--accent-soft);
}

.award-year {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.award-row:hover .award-year {
    color: var(--accent);
}

.award-text {
    color: var(--text);
    font-size: 0.94rem;
    line-height: 1.45;
}

.award-text .award-highlight {
    color: var(--gold);
    font-weight: 600;
}

[data-theme="dark"] .award-text .award-highlight { color: #ffd246; }

@media (max-width: 540px) {
    .award-row {
        grid-template-columns: 60px 1fr;
        gap: 12px;
        padding: 10px 14px;
    }
}

/* ============================================================
   Publications
   ============================================================ */

.year-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.year-tab {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-soft);
    cursor: pointer;
    transition: all 0.15s ease;
    font-weight: 500;
}

.year-tab:hover, .year-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pub-year {
    margin: 22px 0 10px 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.pub-year::before {
    content: "";
    width: 4px;
    height: 22px;
    background: var(--accent);
    border-radius: 2px;
}

.pub-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pub-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    transition: all 0.2s ease;
    line-height: 1.6;
}

.pub-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.pub-card b { color: var(--text); font-weight: 600; }
.pub-card em {
    color: var(--accent);
    font-style: normal;
    font-weight: 500;
    font-size: 0.93rem;
}
.pub-card u { text-decoration: none; font-weight: 600; color: var(--text); }
.pub-card font[color="red"] {
    color: var(--highlight) !important;
    font-size: 0.88rem;
    font-weight: 500;
}

.pub-card a {
    display: inline-block;
    padding: 1px 0;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 500;
}

.pub-card p { margin: 0; }

/* override any "[ ]" in publication links to look better */
.pub-links {
    margin-top: 6px;
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-size: 0.88rem;
}

/* ============================================================
   Products
   ============================================================ */

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 20px;
}

@media (max-width: 600px) {
    .products-grid { grid-template-columns: 1fr; }
}

.product-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
}

.product-card img {
    width: 100%;
    aspect-ratio: 16 / 8;
    object-fit: cover;
    border-bottom: 1px solid var(--border);
}

.product-body {
    padding: 16px 18px;
    line-height: 1.6;
    color: var(--text-soft);
    font-size: 0.94rem;
}

.product-body b { color: var(--text); }

/* ============================================================
   Experience timeline
   ============================================================ */

.experience-list {
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
}

.experience-list::before {
    content: "";
    position: absolute;
    left: 18px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: linear-gradient(to bottom, var(--accent), transparent);
}

.experience-item {
    position: relative;
    display: grid;
    grid-template-columns: 50px 1fr auto;
    gap: 16px;
    padding: 14px 0;
    align-items: center;
}

.experience-item::before {
    content: "";
    position: absolute;
    left: 11px;
    top: 50%;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg);
    border: 3px solid var(--accent);
    transform: translateY(-50%);
    z-index: 1;
}

.experience-meta {
    grid-column: 2;
    line-height: 1.45;
}

.experience-org {
    font-weight: 600;
    color: var(--text);
    font-size: 1rem;
}

.experience-role {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 2px;
}

.experience-logo {
    grid-column: 3;
    width: 70px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.experience-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

@media (max-width: 600px) {
    .experience-item {
        grid-template-columns: 50px 1fr;
    }
    .experience-logo { display: none; }
}

/* ============================================================
   Service
   ============================================================ */

.service-block {
    margin-bottom: 22px;
}

.service-label {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    font-size: 1rem;
}

.service-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.service-list li {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-soft);
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.88rem;
    line-height: 1.5;
    transition: all 0.15s ease;
}

.service-list li:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.service-list a {
    color: inherit;
}

.service-block.detail .service-list {
    flex-direction: column;
    gap: 6px;
}

.service-block.detail .service-list li {
    background: transparent;
    border: none;
    border-left: 2px solid var(--border);
    border-radius: 0;
    padding: 4px 0 4px 14px;
    font-size: 0.93rem;
}

.service-block.detail .service-list li:hover {
    border-left-color: var(--accent);
    background: transparent;
    color: var(--text-soft);
}

/* ============================================================
   Footer
   ============================================================ */

.site-footer {
    margin-top: 80px;
    padding: 28px 0 40px 0;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.site-footer p { margin: 4px 0; }

/* ============================================================
   Reveal-on-scroll animation
   ============================================================ */

.reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 0.55s ease, transform 0.55s ease;
}

.reveal.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1; transform: none; transition: none; }
    .hero-image::after { animation: none; }
    * { transition: none !important; animation: none !important; }
}

/* ============================================================
   Reset legacy jemdoc styles that leak through
   ============================================================ */

#layout-content { max-width: none; padding: 0; border: none; background: transparent; }
#layout-menu { display: none; } /* old nav hidden */

/* The original markup uses tables for publications: keep them but reset visual styles */
table#tbPublications {
    border-collapse: collapse;
    width: 100% !important;
    background: transparent;
    display: block;
}

table#tbPublications tbody {
    display: block;
    width: 100%;
}

table#tbPublications tr {
    display: block;
    width: 100%;
    margin-bottom: 10px;
}

table#tbPublications td {
    display: block;
    width: 100% !important;
    padding: 0;
}

table#tbPublications tr td p {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 0;
    line-height: 1.55;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

/* Hide browser-auto-inserted empty <p> tags (caused by <div> inside <p>) */
table#tbPublications tr td p:empty,
table#tbPublications tr td p:not(:has(b, em, a, font, u, br, span, img, *)):not([class]) {
    display: none;
}

table#tbPublications tr td p:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

table#tbPublications tr td p b {
    color: var(--text);
    font-weight: 600;
    font-size: 1rem;
}

table#tbPublications tr td p em {
    color: var(--accent);
    font-style: normal;
    font-weight: 500;
    font-size: 0.93rem;
}

table#tbPublications tr td p u {
    text-decoration: none;
    font-weight: 600;
    color: var(--text);
    border-bottom: 2px solid var(--accent);
}

table#tbPublications tr td p font[color="red"] {
    color: var(--highlight);
    font-size: 0.88rem;
    font-weight: 500;
}

table#tbPublications tr td p a {
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 500;
    margin-right: 2px;
}

/* Hide bibtex toggles that aren't visible */
div[id$="_bibtex"] {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-soft);
}

/* Force img-circle */
.img-circle { border-radius: 50%; }
