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

:root {
    --bg: #ffffff;
    --text: #000000;
    --text-muted: #555;
    --border: #f0f0f0;
    --border-strong: #000;
    --link: #000;
    --link-hover: #00008B;
    --citation-border: #eee;
    --shadow-dim: rgba(0, 0, 0, 0.1);
    --shadow-strong: rgba(0, 0, 0, 0.3);
    --overlay-dim: rgba(255, 255, 255, 0.8);
    --profile-edge: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root:not(.light-mode) {
        --bg: #1a1a1a;
        --text: #e8e8e8;
        --text-muted: #b0b0b0;
        --border: #333;
        --border-strong: #e8e8e8;
        --link: #e8e8e8;
        --link-hover: #7eb8ff;
        --citation-border: #444;
        --shadow-dim: rgba(0, 0, 0, 0.4);
        --shadow-strong: rgba(0, 0, 0, 0.6);
        --overlay-dim: rgba(0, 0, 0, 0.7);
        --profile-edge: #1a1a1a;
    }
}

html.dark-mode {
    --bg: #1a1a1a;
    --text: #e8e8e8;
    --text-muted: #b0b0b0;
    --border: #333;
    --border-strong: #e8e8e8;
    --link: #e8e8e8;
    --link-hover: #7eb8ff;
    --citation-border: #444;
    --shadow-dim: rgba(0, 0, 0, 0.4);
    --shadow-strong: rgba(0, 0, 0, 0.6);
    --overlay-dim: rgba(0, 0, 0, 0.7);
    --profile-edge: #1a1a1a;
}

html.light-mode {
    --bg: #ffffff;
    --text: #000000;
    --text-muted: #555;
    --border: #f0f0f0;
    --border-strong: #000;
    --link: #000;
    --link-hover: #00008B;
    --citation-border: #eee;
    --shadow-dim: rgba(0, 0, 0, 0.1);
    --shadow-strong: rgba(0, 0, 0, 0.3);
    --overlay-dim: rgba(255, 255, 255, 0.8);
    --profile-edge: #ffffff;
}

body {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: 300;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    display: flex;
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px;
}

/* Typography Weights */
h1,
h2,
h3 {
    font-weight: 500;
    /* Medium */
    margin-bottom: 1rem;
}

h3 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

p,
li,
span {
    font-weight: 300;
    /* Light */
}

strong,
b {
    font-weight: 400;
    /* Regular */
}

/* Sidebar Navigation */
.sidebar {
    width: 250px;
    padding-right: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid var(--border);
    /* Very subtle separator, optional */
}

.nav-header {
    margin-bottom: 40px;
}

.nav-links {
    list-style: none;
}

.nav-links li {
    cursor: pointer;
    padding: 10px 0;
    font-size: 1.1rem;
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 0.5;
}

.nav-links li:hover:not(.active) {
    opacity: 1;
    transform: translateX(5px) scale(1.1);
    color: var(--link-hover);
}

.nav-links li.active {
    opacity: 1;
    font-weight: 400;
    /* Regular */
}

.theme-toggle {
    margin-top: 1.5rem;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.theme-toggle:hover {
    opacity: 1;
    border-color: var(--link-hover);
    color: var(--link-hover);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle .theme-icon {
    display: none;
    line-height: 0;
}

.theme-toggle .theme-icon svg {
    display: block;
    vertical-align: middle;
}

.theme-toggle .theme-icon-moon {
    display: block;
}

.theme-toggle .theme-icon-sun {
    display: none;
}

.theme-toggle.dark-active .theme-icon-moon {
    display: none;
}

.theme-toggle.dark-active .theme-icon-sun {
    display: block;
}

/* Content Area */
.content {
    flex: 1;
    padding-left: 60px;
    display: block;
    /* Changed from flex to block to fix scrolling issues */
    position: relative;
    /* Enable scrolling for long content like projects */
    overflow-y: auto;
    height: 100%;
}

/* Hide scrollbar for Chrome, Safari and Opera */
.content::-webkit-scrollbar {
    display: none;
}

/* Hide scrollbar for IE, Edge and Firefox */
.content {
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

.tab-content {
    display: none;
    opacity: 0;
    transition: opacity 0.8s ease;
    /* Changed from absolute centering to be scroll-friendly */
    padding-top: 20px;
    padding-bottom: 40px;
    max-width: 800px;
    /* Readability */
}

.tab-content.active {
    display: block;
    opacity: 1;
    animation: fadeIn 0.8s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Profile Picture */
.profile-picture-wrapper {
    position: relative;
    width: 280px;
    margin-bottom: 2rem;
    /* Ensure wrapper fits content */
    display: inline-block;
    line-height: 0;
    flex-shrink: 0;
    /* Prevent shrinking in flex container */
    opacity: 0;
}

.profile-picture-wrapper.profile-picture-loaded {
    animation: fadeIn 0.8s ease forwards;
}

/* Landing Page Specifics */
#landing.active {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    /* Center vertically */
}

/* Bio Page Specifics */
#bio.active {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100%;
    margin: 0 auto;
}

.landing-text p {
    font-size: 1.5rem;
    font-weight: 300;
}

.landing-layout {
    display: flex;
    align-items: center;
    gap: 40px;
    width: 100%;
    /* Ensure it takes width to center horizontally if needed */
}

.landing-text {
    flex: 1;
}

.profile-picture-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Soft white inner glow to blur edges */
    box-shadow: inset 0 0 2px 2px var(--profile-edge);
    pointer-events: none;
}

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

/* Specific Content Styles */
.pub-list {
    list-style: none;
}

.pub-list li {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
}

.pub-list .year {
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
    font-weight: 400;
}

.pub-list .title {
    font-weight: 400;
    margin-bottom: 0.2rem;
    font-size: 1.1rem;
}

.pub-list .authors {
    margin-bottom: 0.2rem;
}

.pub-list .journal {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Project Styles */
.project-item {
    margin-bottom: 2.5rem;
}

.project-item .citation {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
    border-left: 3px solid var(--citation-border);
    padding-left: 10px;
}

/* Project Layout */
.project-content {
    display: flex;
    gap: 30px;
    align-items: center;
    /* Centered vertically */
    transition: all 0.5s ease;
}

.project-text {
    flex: 1;
}

.project-image {
    width: 250px;
    /* Increased from 200px */
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.5s ease;
}

.project-image img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 2px 5px var(--shadow-dim);
}

/* Portal for expanded project (full-page, outside tabs) */
#project-portal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    pointer-events: none;
}

#project-portal .expandable-project-item.expanded {
    pointer-events: auto;
}

/* Portal wrapper for animation */
.project-expanded-wrapper {
    position: fixed;
    inset: 0;
    z-index: 100000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.project-expanded-wrapper.visible {
    opacity: 1;
}

.project-expanded-overlay {
    position: absolute;
    inset: 0;
    background: var(--overlay-dim);
    backdrop-filter: blur(5px);
    z-index: 0;
    pointer-events: auto;
    /* Allow clicking overlay to close */
    cursor: pointer;
}

/* Hide original when expanded clone is shown */
.expandable-project-item.showing-expanded {
    /* visibility: hidden; */
}

/* Expanded State for Project */
.expandable-project-item.expanded {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90vw;
    max-width: 1000px;
    max-height: 95vh;
    background: var(--bg);
    color: var(--text);
    z-index: 100001;
    padding: 40px;
    box-shadow: 0 10px 40px var(--shadow-strong);
    border-radius: 8px;
    overflow-y: auto;
    overflow-x: visible;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    transition: transform 0.3s ease;
    pointer-events: auto;
}

.project-expanded-wrapper.visible .expandable-project-item.expanded {
    transform: translate(-50%, -50%) scale(1);
}

.expandable-project-item.expanded .project-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    overflow: visible;
}

/* Dim is now .project-expanded-overlay (real element) so mouseleave works on wrapper */
.expandable-project-item.expanded::before {
    content: none;
}

.expandable-project-item.expanded .project-image {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    flex-shrink: 0;
    overflow: visible;
    min-height: 0;
}

.expandable-project-item.expanded .project-image img {
    max-height: none;
    width: 100%;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    vertical-align: middle;
}

.expandable-project-item.expanded .project-text {
    font-size: 1.1rem;
}

/* Close button for expanded project */
.close-project-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    z-index: 100002;
    line-height: 1;
    padding: 5px;
    transition: color 0.3s ease;
}

.close-project-btn:hover {
    color: var(--link-hover);
}

a {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid var(--border-strong);
    padding-bottom: 2px;
    transition: border-bottom-color 0.3s ease, color 0.3s ease;
}

a:hover {
    border-bottom-color: transparent;
    color: var(--link-hover);
    font-size: 1.05em;
}

/* Hover Reveal Trigger */
.hover-reveal-trigger {
    cursor: help;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    text-decoration-color: var(--text-muted);
    padding: 2px 0; /* Slight padding */
    align-self: flex-start; /* Prevent full width in flex container */
    max-width: fit-content; /* Ensure it only takes up necessary width */
}

/* Improve hit area on touch devices */
body.is-touch-device .hover-reveal-trigger {
    padding: 10px 0; /* Larger vertical hit area */
    display: inline-block; /* Ensure padding works */
}

.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    mix-blend-mode: hard-light;
    /* Helps it blend nicely or just cover */
    background: #808080;
    /* Neutral gray background for the noise to sit on if needed */
}

/* Responsive */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .container {
        flex-direction: column;
        padding: 20px 20px 60px 20px;
        /* Add bottom padding for scroll */
        height: auto;
        overflow: visible;
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        margin-bottom: 20px;
        flex-direction: column;
        align-items: flex-start;
        padding-right: 0;
    }

    .nav-header {
        margin-bottom: 5px;
        width: 100%;
    }

    .nav-header h1 {
        font-size: 1.5rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 15px 25px;
    }

    .nav-links li {
        padding: 5px 0;
    }

    .content {
        padding-left: 0;
        display: block;
        height: auto;
        overflow-y: visible;
    }

    .tab-content {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        transform: none;
        opacity: 1;
    }

    .tab-content.active {
        animation: none;
    }

    .landing-layout {
        flex-direction: column;
        text-align: center;
        gap: 20px;
    }

    .profile-picture-wrapper {
        width: 250px;
        margin-bottom: 1.5rem;
    }

    .project-content {
        flex-direction: column;
    }

    .project-image {
        width: 100%;
        margin-top: 1rem;
    }
}