* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Charter', 'Iowan Old Style', 'Source Serif Pro', ui-serif, Georgia, serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

html {
    scroll-behavior: smooth;
}

body, html {
    font-family: var(--font-sans);
    background-color: #ffffff;
    /* Prevent scroll bounce on iOS */
    overscroll-behavior: none;
}

/* Minimal top navigation */
.site-nav {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(150%) blur(6px);
    -webkit-backdrop-filter: saturate(150%) blur(6px);
    overflow: hidden; /* prevent underline overflow causing tiny scroll */
}

.nav-inner {
    max-width: 780px;
    margin: 0 auto;
    padding: 1rem 2.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-links {
    display: flex;
    gap: 1.25rem;
    position: relative;
}

.nav-link {
    color: #666;
    font-size: 0.95rem;
}

.nav-link:hover {
    color: #0077cc;
    text-decoration: none;
}

.nav-link.active {
    color: #0077cc;
    font-weight: 600;
    border-bottom: 2px solid #0077cc;
    padding-bottom: 2px;
}

.container {
    max-width: 780px;
    margin: 0 auto;
    padding: 3rem 2.5rem;
    z-index: 1;
    position: relative;
    min-height: calc(100vh - 56px); /* subtract nav height to avoid tiny scroll */
}

h1 {
    font-family: var(--font-serif);
    font-size: 2.4rem;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 0.3rem;
    line-height: 1.15;
    letter-spacing: -0.01em;
}

/* Typewriter heading on the home page. */
h1 .typed {
    white-space: pre;
}

h1 .cursor {
    display: inline-block;
    width: 3px;
    height: 0.82em;
    background: #1a1a1a;
    margin-left: 4px;
    vertical-align: -0.03em;
    animation: cursor-blink 1.05s steps(2, end) infinite;
    transition: opacity 450ms ease;
}

h1 .cursor.is-fading {
    animation: none;
    opacity: 0;
}

@keyframes cursor-blink {
    0%, 49%   { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* Waving hand emoji — animates once when first attached after the typewriter
   finishes. Pivot at the lower-right (the "wrist") gives a natural gesture. */
h1 .wave {
    display: inline-block;
    transform-origin: 70% 80%;
    animation: wave 1.6s ease-in-out;
}

@keyframes wave {
    0%   { transform: rotate(0deg); }
    10%  { transform: rotate(14deg); }
    20%  { transform: rotate(-8deg); }
    30%  { transform: rotate(14deg); }
    40%  { transform: rotate(-4deg); }
    50%  { transform: rotate(10deg); }
    60%, 100% { transform: rotate(0deg); }
}

/* Elements that fade in once the typewriter finishes. Default = visible
   (no-JS / no-CSS fallback); the `.js` gate hides them only when JS is on. */
.js .reveal-after-type {
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 700ms ease, transform 700ms ease;
}

.js .reveal-after-type.is-revealed {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    h1 .cursor { animation: none; opacity: 0; }
    h1 .wave { animation: none; }
    .js .reveal-after-type { opacity: 1; transform: none; transition: none; }
}

.bio {
    font-size: 1rem;
    color: #666;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    max-width: none;
}

.section {
    margin-bottom: 1.5rem;
}

h2 {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
    letter-spacing: -0.005em;
}

h2.research-title {
    font-size: 1.35rem;
}

ul {
    list-style: none;
    margin-left: 0;
}

li {
    font-size: 0.95rem;
    color: #666;
    line-height: 1.5;
    margin-bottom: 0.3rem;
}

.contact {
    margin-top: 1.5rem;
    font-size: 0.95rem;
}

a {
    color: #0077cc;
    text-decoration: none;
    cursor: pointer;
}

a:hover {
    text-decoration: underline;
}

/* Persistent subtle underline on prose links — appears scannable without being noisy. */
.bio a,
.post-content a,
.item-desc a {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    text-decoration-color: rgba(0, 119, 204, 0.35);
    transition: text-decoration-color 150ms ease;
}

.bio a:hover,
.post-content a:hover,
.item-desc a:hover {
    text-decoration-color: #0077cc;
}

/* Publications Section */
.publications {
    margin-top: 0.5rem;
}

.publication {
    margin-bottom: 1.2rem;
    line-height: 1.4;
}

.publication:last-child {
    margin-bottom: 0;
}

.pub-title {
    font-family: var(--font-serif);
    font-weight: 600;
    color: #1a1a1a;
    font-size: 1rem;
    margin-bottom: 0.2rem;
}

.pub-authors {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
}

.pub-venue {
    font-family: var(--font-mono);
    color: #666;
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
}

.pub-links {
    font-size: 0.9rem;
}

.pub-links a {
    color: #0077cc;
    text-decoration: none;
    margin-right: 0.8rem;
}

.pub-links a:hover {
    text-decoration: underline;
}

/* Awards Section */
.awards {
    margin-top: 0.5rem;
}

.award {
    margin-bottom: 0.4rem;
    line-height: 1.5;
    font-size: 0.95rem;
}

.award:last-child {
    margin-bottom: 0;
}

.award-title {
    font-weight: 600;
    color: #333;
    display: inline;
}

.award-org {
    color: #666;
    display: inline;
    margin-left: 0.5rem;
}

.award-year {
    color: #666;
    font-style: italic;
    display: inline;
    margin-left: 0.5rem;
}

/* Neural Network Canvas */
#neural-network {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    /* Hardware acceleration for better performance */
    transform: translateZ(0);
    will-change: contents;
}

/* Hide the canvas on any touch-only device (mobile, tablet in any orientation). */
@media (hover: none) {
    #neural-network {
        display: none;
    }
}

/* Generic list items used in Projects and Blog */
.items {
    margin-top: 0.75rem;
}

.items .item {
    padding: 0.7rem 0;
    border-bottom: 1px solid #eee;
}

.items .item:last-child {
    border-bottom: none;
}

.item-title {
    font-family: var(--font-serif);
    font-weight: 600;
    color: #1a1a1a;
    font-size: 1.1rem;
    letter-spacing: -0.005em;
}

.item-title:hover {
    text-decoration: underline;
}

.item-meta {
    font-family: var(--font-mono);
    color: #999;
    font-size: 0.82rem;
    margin-top: 0.15rem;
}

/* Prose-style metadata (e.g. author lists) — keep in body font, not mono. */
.item-authors {
    color: #777;
    font-size: 0.9rem;
    margin-top: 0.25rem;
    line-height: 1.5;
}

.item-desc {
    color: #555;
    font-size: 0.95rem;
    margin-top: 0.35rem;
}

.item-links {
    margin-top: 0.45rem;
    display: flex;
    gap: 0.5rem;
}

.pill {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    font-size: 0.85rem;
    color: #666;
    transition: color 200ms ease, border-color 200ms ease, background-color 200ms ease;
}

.pill:hover {
    color: #0077cc;
    border-color: #c7d7ea;
    background-color: #f7fbff;
    text-decoration: none;
}

@media (max-width: 768px) {
    .container {
        padding: 2rem 3rem;
        max-width: 100%;
        min-height: calc(100vh - 52px);
    }
    .nav-inner {
        padding: 0.75rem 3rem;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .bio {
        font-size: 0.95rem;
    }
    
    li {
        font-size: 0.9rem;
    }
    
    .contact {
        font-size: 0.9rem;
    }
    
    /* Mobile-specific canvas optimizations (also gated on hover capability
       below so tablets in landscape stay quiet too). */
    #neural-network {
        display: none;
    }
    
    /* Prevent text selection during touch interactions */
    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        /* Enable momentum scrolling on iOS */
        /* -webkit-overflow-scrolling: touch; */
    }
    
    /* Re-enable text selection for content */
    .container {
        -webkit-user-select: text;
        -khtml-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
}

/* Blog post layout & typography */
.post {
    margin-top: 0.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: #999;
    font-size: 0.9rem;
}

.back-link:hover {
    color: #0077cc;
    text-decoration: none;
}

.post-header {
    margin-top: 0.25rem;
    margin-bottom: 1rem;
}

.post-title {
    font-family: var(--font-serif);
    font-size: 2.2rem;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin: 0.25rem 0 0.35rem;
}

.post-meta {
    font-family: var(--font-mono);
    color: #999;
    font-size: 0.82rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.post-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: #666;
    background: #fafafa;
}

.post-content {
    margin-top: 1.2rem;
    font-size: 1rem;
    line-height: 1.75;
    color: #444;
}

.post-content p {
    margin-top: 0.75rem;
}

.post-content h2 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 600;
    color: #1a1a1a;
    margin-top: 1.5rem;
    letter-spacing: -0.005em;
}

.post-content ul,
.post-content ol {
    margin-top: 0.5rem;
    margin-left: 1.2rem;
    list-style: disc;
}

.post-content ol {
    list-style: decimal;
}

.post-content li {
    margin-bottom: 0.35rem;
    font-size: 1rem;
    color: #333;
    line-height: 1.75;
}

.post-content hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 1rem 0;
}

.post-content blockquote {
    border-left: 3px solid #e5e7eb;
    padding-left: 0.75rem;
    color: #666;
    margin: 0.8rem 0;
}

.post-content code {
    background: #f7f7f9;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.95em;
}

.post-content pre {
    background: #0b1220;
    color: #e6edf3;
    border-radius: 6px;
    padding: 0.85rem 1rem;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.92em;
}

.post-content pre code {
    background: transparent;
    border: 0;
    padding: 0;
    color: inherit;
}

/* Responsive images in posts */
.post-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.75rem auto;
    border-radius: 6px;
}

/* Responsive videos in posts */
.post-content video {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.75rem auto;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #000;
}

/* Figure and caption styles */
.post-content figure {
    margin: 1.25rem 0;
    text-align: center;
}

/* Side-by-side video grid */
.video-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin: 1.25rem 0;
}

.post-content .video-grid video {
    width: 100%;
    height: auto;
    border-radius: 6px;
    display: block;
    margin: 0;
    border: none;
}

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

.post-content figure img {
    margin-bottom: 0.5rem;
}

.post-content figcaption {
    font-size: 0.9rem;
    color: #666;
    font-style: italic;
    margin-top: 0.25rem;
}

/* Favorites — section header sits above, then list flows into two balanced columns. */
.fav-intro {
    color: #555;
    font-size: 1.02rem;
    line-height: 1.65;
    margin: 0.5rem 0 0;
    max-width: 56ch;
}

.fav-section {
    margin-top: 2rem;
    scroll-margin-top: 4.5rem;
}

.fav-section:first-of-type {
    margin-top: 1.5rem;
}

.fav-section-meta {
    margin-bottom: 0.75rem;
}

.fav-section h2 {
    font-family: var(--font-serif);
    font-size: 1.55rem;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.15;
    margin: 0 0 0.2rem;
    padding: 0;
    letter-spacing: -0.005em;
    border: 0;
}

.fav-section-desc {
    font-family: var(--font-serif);
    font-style: italic;
    color: #9a9a9a;
    font-size: 0.95rem;
    line-height: 1.4;
    margin: 0;
}

/* Two balanced columns. CSS multi-column auto-balances item distribution. */
.fav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    column-count: 2;
    column-gap: 2.75rem;
}

.fav-list li {
    break-inside: avoid;
    padding: 0.4rem 0;
    margin: 0;
    font-size: 1rem;
    color: #1a1a1a;
    line-height: 1.5;
    border: 0;
}

.fav-meta {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: #b8b8b8;
    letter-spacing: 0.02em;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.fav-section-more {
    margin: 0.6rem 0 0;
}

.fav-section-more p {
    margin: 0;
}

.fav-section-more a {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: #999;
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color 150ms ease;
}

.fav-section-more a:hover {
    color: #0077cc;
    text-decoration: none;
}

@media (max-width: 768px) {
    .fav-section {
        margin-top: 1.75rem;
    }
    .fav-section h2 {
        font-size: 1.4rem;
    }
    .fav-list {
        column-count: 1;
    }
}