/* ============================================================
   Refined Minimalist Design - Chi Zhang's Personal Website
   Inspired by Andrej Karpathy's aesthetic with enhanced polish
   ============================================================ */

/* ============================================================
   CSS Custom Properties - Design System
   ============================================================ */
:root {
    /* Typography Scale */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Crimson Pro', Georgia, serif;

    /* Font Sizes */
    --text-xs: 0.75rem;      /* 12px */
    --text-sm: 0.875rem;     /* 14px */
    --text-base: 1rem;       /* 16px */
    --text-lg: 1.125rem;     /* 18px */
    --text-xl: 1.25rem;      /* 20px */
    --text-2xl: 1.5rem;      /* 24px */
    --text-3xl: 2rem;        /* 32px */
    --text-4xl: 2.5rem;      /* 40px */

    /* Colors - Sophisticated Monochrome Palette */
    --color-text-primary: #1a1a1a;
    --color-text-secondary: #4a4a4a;
    --color-text-tertiary: #737373;
    --color-text-quaternary: #a3a3a3;

    --color-bg-primary: #ffffff;
    --color-bg-secondary: #fafafa;
    --color-bg-tertiary: #f5f5f5;

    --color-border: #e5e5e5;
    --color-border-light: #f0f0f0;

    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;

    /* Spacing Scale */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-8: 2rem;      /* 32px */
    --space-10: 2.5rem;   /* 40px */
    --space-12: 3rem;     /* 48px */
    --space-16: 4rem;     /* 64px */
    --space-20: 5rem;     /* 80px */

    /* Layout */
    --max-width: 920px;
    --container-padding: var(--space-6);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-base: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* ============================================================
   Base Styles
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: 400;
    line-height: 1.65;
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    letter-spacing: -0.011em;
}

/* ============================================================
   Typography
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.025em;
    margin-bottom: var(--space-4);
}

h1 {
    font-size: var(--text-4xl);
}

h2 {
    font-size: var(--text-3xl);
}

h3 {
    font-size: var(--text-2xl);
}

p {
    margin-bottom: var(--space-5);
}

a {
    color: var(--color-text-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
    position: relative;
}

a:hover {
    color: var(--color-text-secondary);
}

/* ============================================================
   Layout Container
   ============================================================ */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--container-padding);
}

/* ============================================================
   Navigation
   ============================================================ */
.nav {
    padding: var(--space-8) 0 var(--space-6);
    border-bottom: 1px solid var(--color-border-light);
    background-color: var(--color-bg-primary);
}

.nav-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: var(--space-8);
}

.nav-item {
    display: inline-block;
}

.nav-link {
    font-size: var(--text-sm);
    font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--color-text-secondary);
    padding: var(--space-2) 0;
    position: relative;
    transition: color var(--transition-base);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background-color: var(--color-text-primary);
    transition: width var(--transition-base);
}

.nav-link:hover {
    color: var(--color-text-primary);
}

.nav-link:hover::after {
    width: 100%;
}

.nav-toggle {
    display: none;
}

/* ============================================================
   Profile Section
   ============================================================ */
.profile-section {
    padding: var(--space-20) 0 var(--space-16);
}

.profile-content {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: var(--space-16);
    align-items: start;
}

/* Profile Info */
.profile-info {
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.header {
    margin-bottom: var(--space-10);
}

.name {
    font-family: var(--font-serif);
    font-size: var(--text-4xl);
    font-weight: 600;
    letter-spacing: -0.03em;
    margin-bottom: var(--space-3);
    color: var(--color-text-primary);
    line-height: 1.1;
}

.title {
    font-size: var(--text-lg);
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
    letter-spacing: -0.01em;
}

.tagline {
    font-family: var(--font-serif);
    font-size: var(--text-base);
    font-style: italic;
    font-weight: 400;
    color: var(--color-text-tertiary);
    margin-bottom: 0;
}

/* Bio */
.bio {
    margin-bottom: var(--space-8);
}

.bio p {
    font-size: var(--text-base);
    line-height: 1.75;
    color: var(--color-text-secondary);
}

.bio a {
    color: var(--color-text-primary);
    border-bottom: 1px solid var(--color-border);
    transition: border-color var(--transition-base);
}

.bio a:hover {
    border-bottom-color: var(--color-text-primary);
}

/* Contact Links */
.contact-links {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    font-size: var(--text-sm);
}

.contact-link {
    font-weight: 500;
    color: var(--color-text-primary);
    padding: var(--space-1) 0;
    position: relative;
    letter-spacing: 0.01em;
    transition: color var(--transition-fast);
}

.contact-link::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: var(--color-text-primary);
    opacity: 0.3;
    transition: opacity var(--transition-fast);
}

.contact-link:hover {
    color: var(--color-text-primary);
}

.contact-link:hover::after {
    opacity: 1;
}

.separator {
    color: var(--color-text-quaternary);
    font-weight: 300;
    user-select: none;
}

/* Profile Image */
.profile-image {
    animation: fadeIn 0.8s ease-out 0.2s both;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.profile-image img {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 4px;
    transition: transform var(--transition-slow), box-shadow var(--transition-slow);
}

.profile-image img:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ============================================================
   Footer
   ============================================================ */
.footer {
    padding: var(--space-12) 0 var(--space-8);
    margin-top: var(--space-20);
    border-top: 1px solid var(--color-border-light);
}

.footer p {
    text-align: center;
    font-size: var(--text-sm);
    color: var(--color-text-quaternary);
    margin: 0;
    letter-spacing: 0.01em;
}

/* ============================================================
   Back to Top Button
   ============================================================ */
.back-to-top {
    position: fixed;
    bottom: var(--space-8);
    right: var(--space-8);
    width: 44px;
    height: 44px;
    background-color: var(--color-text-primary);
    color: var(--color-bg-primary);
    border: none;
    border-radius: 50%;
    font-size: var(--text-xl);
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-base);
    transition: all var(--transition-base);
    z-index: 100;
    opacity: 0;
}

.back-to-top.visible {
    display: flex;
    opacity: 1;
    animation: slideInUp 0.3s ease-out;
}

@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.back-to-top:hover {
    background-color: var(--color-text-secondary);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.back-to-top:active {
    transform: translateY(-2px);
}

/* ============================================================
   Research & Publications Styling
   ============================================================ */
.research-area,
.publication {
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    background-color: var(--color-bg-secondary);
    border-radius: 4px;
    border-left: 2px solid var(--color-text-primary);
    transition: all var(--transition-base);
}

.research-area:hover,
.publication:hover {
    background-color: var(--color-bg-tertiary);
    border-left-width: 3px;
}

.research-area h3,
.publication-title {
    color: var(--color-text-primary);
    margin-top: 0;
    font-size: var(--text-lg);
    font-weight: 600;
}

.conference {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-3);
}

.research-area ul {
    padding-left: var(--space-6);
    margin-top: var(--space-4);
}

.research-area li {
    margin-bottom: var(--space-3);
    color: var(--color-text-secondary);
}

/* ============================================================
   Responsive Design
   ============================================================ */

/* Tablet */
@media (max-width: 768px) {
    :root {
        --text-4xl: 2rem;      /* 32px */
        --text-3xl: 1.75rem;   /* 28px */
        --container-padding: var(--space-5);
    }

    .profile-content {
        grid-template-columns: 1fr;
        gap: var(--space-10);
    }

    .profile-image {
        order: -1;
        max-width: 240px;
        margin: 0 auto;
    }

    .header,
    .bio,
    .contact-links {
        text-align: center;
    }

    .bio p {
        text-align: left;
    }

    .contact-links {
        justify-content: center;
    }

    /* Mobile Navigation */
    .nav-toggle {
        display: flex;
        flex-direction: column;
        gap: 5px;
        background: none;
        border: none;
        cursor: pointer;
        padding: var(--space-2);
    }

    .nav-toggle span {
        display: block;
        width: 24px;
        height: 2px;
        background-color: var(--color-text-primary);
        transition: all var(--transition-base);
        border-radius: 2px;
    }

    .nav-toggle[aria-expanded="true"] span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .nav-toggle[aria-expanded="true"] span:nth-child(2) {
        opacity: 0;
    }

    .nav-toggle[aria-expanded="true"] span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    .nav-container {
        flex-direction: column;
        align-items: flex-start;
    }

    .nav-menu {
        flex-direction: column;
        width: 100%;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height var(--transition-slow);
    }

    .nav-menu.active {
        max-height: 400px;
        padding: var(--space-4) 0;
    }

    .nav-item {
        width: 100%;
        padding: var(--space-3) 0;
    }

    .nav-link {
        display: block;
        font-size: var(--text-base);
    }
}

/* Mobile */
@media (max-width: 480px) {
    :root {
        --text-4xl: 1.75rem;   /* 28px */
        --space-20: 3rem;      /* 48px */
        --space-16: 2.5rem;    /* 40px */
        --container-padding: var(--space-4);
    }

    .profile-section {
        padding: var(--space-12) 0 var(--space-10);
    }

    .back-to-top {
        bottom: var(--space-5);
        right: var(--space-5);
        width: 40px;
        height: 40px;
        font-size: var(--text-lg);
    }
}

/* High-resolution displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: subpixel-antialiased;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode support (optional, can be activated later) */
@media (prefers-color-scheme: dark) {
    /* Dark mode styles can be added here if desired */
}
