/* ========================================
   CSS Variables & Theme System
   ======================================== */
:root {
    /* Light theme — refined academic elegance */
    --bg: #ffffff;
    --bg-secondary: #f8fafc; /* Cool gray 50 */
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-sidebar: rgba(248, 250, 252, 0.8);
    --bg-code: #f1f5f9;
    --bg-hover: #f1f5f9;
    
    --text: #0f172a; /* Slate 900 */
    --text-secondary: #475569; /* Slate 600 */
    --text-muted: #94a3b8; /* Slate 400 */
    
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    /* Primary Accent: Deep Indigo/Science Blue */
    --primary: #4f46e5; /* Indigo 600 */
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --primary-bg: rgba(79, 70, 229, 0.08);
    --primary-border: rgba(79, 70, 229, 0.2);

    /* Tags & Badges */
    --tag-bg: #f1f5f9;
    --tag-text: #475569;
    --tag-border: #e2e8f0;

    /* Shadows — layered & soft */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(15, 23, 42, 0.06), 0 4px 6px -2px rgba(15, 23, 42, 0.03);
    --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.06), 0 10px 10px -5px rgba(15, 23, 42, 0.02);
    --shadow-card: 0 4px 6px -1px rgba(15, 23, 42, 0.02), 0 2px 4px -1px rgba(15, 23, 42, 0.02);

    /* Layout & Glass */
    --header-bg: rgba(255, 255, 255, 0.85);
    --glass-blur: blur(20px);
    --sidebar-width: 320px;
    --header-height: 64px;
    
    --radius: 10px;
    --radius-lg: 16px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-serif: 'Crimson Pro', Georgia, serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    /* Visuals */
    --hero-gradient: linear-gradient(135deg, rgba(79, 70, 229, 0.04) 0%, rgba(255, 255, 255, 0) 100%);
    --canvas-molecule: #4f46e5;
    --canvas-bond: rgba(79, 70, 229, 0.15);
    --ticker-bg: #f8fafc;
    --ticker-border: #e2e8f0;
    --psf-center: #4f46e5;
    --psf-ring: rgba(79, 70, 229, 0.08);
}

[data-theme="dark"] {
    --bg: #020617; /* Slate 950 */
    --bg-secondary: #0f172a; /* Slate 900 */
    --bg-card: rgba(15, 23, 42, 0.6);
    --bg-sidebar: rgba(2, 6, 23, 0.8);
    --bg-code: #1e293b;
    --bg-hover: #1e293b;

    --text: #f8fafc; /* Slate 50 */
    --text-secondary: #94a3b8; /* Slate 400 */
    --text-muted: #64748b; /* Slate 500 */

    --border: #1e293b;
    --border-light: #0f172a;

    --primary: #818cf8; /* Indigo 400 */
    --primary-light: #a5b4fc;
    --primary-dark: #6366f1;
    --primary-bg: rgba(129, 140, 248, 0.1);
    --primary-border: rgba(129, 140, 248, 0.2);

    --tag-bg: #1e293b;
    --tag-text: #94a3b8;
    --tag-border: #334155;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5);

    --header-bg: rgba(2, 6, 23, 0.85);
    --hero-gradient: linear-gradient(135deg, rgba(129, 140, 248, 0.06) 0%, rgba(2, 6, 23, 0) 100%);
    
    --canvas-molecule: #818cf8;
    --canvas-bond: rgba(129, 140, 248, 0.15);
    --ticker-bg: #0f172a;
    --ticker-border: #1e293b;
    --psf-center: #818cf8;
    --psf-ring: rgba(129, 140, 248, 0.08);
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-height) + 24px);
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
    background-image: 
        radial-gradient(circle at 15% 50%, var(--primary-bg), transparent 25%),
        radial-gradient(circle at 85% 30%, var(--primary-bg), transparent 25%);
    background-attachment: fixed;
}

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

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover {
    color: var(--primary-light);
}

img {
    max-width: 100%;
    display: block;
}

    /* Custom Scrollbar */
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }
    ::-webkit-scrollbar-track {
        background: transparent;
    }
    ::-webkit-scrollbar-thumb {
        background: var(--text-muted);
        border-radius: 4px;
        opacity: 0.5;
        border: 2px solid transparent;
        background-clip: content-box;
    }
    ::-webkit-scrollbar-thumb:hover {
        background: var(--text-secondary);
        border: 2px solid transparent;
        background-clip: content-box;
    }

    /* ========================================
       Top Header
       ======================================== */
    .top-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 200;
        height: var(--header-height);
        background: var(--header-bg);
        backdrop-filter: var(--glass-blur);
        -webkit-backdrop-filter: var(--glass-blur);
        border-bottom: 1px solid var(--border);
        transition: all var(--transition);
    }
    
    .top-header.scrolled {
        box-shadow: var(--shadow-sm);
        background: rgba(255, 255, 255, 0.95);
    }
    [data-theme="dark"] .top-header.scrolled {
        background: rgba(2, 6, 23, 0.95);
    }

    .header-inner {
        max-width: 1400px;
        margin: 0 auto;
        padding: 0 32px;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 24px;
    }
    
    .site-title {
        font-family: var(--font-serif);
        font-size: 1.35rem;
        font-weight: 700;
        color: var(--text);
        white-space: nowrap;
        letter-spacing: -0.02em;
    }

    .top-nav-link {
        font-size: 0.9rem;
        font-weight: 500;
        color: var(--text-secondary);
        padding: 8px 16px;
        border-radius: 8px;
        transition: all var(--transition);
        position: relative;
    }
    .top-nav-link:hover,
    .top-nav-link.active {
        color: var(--primary);
        background: var(--primary-bg);
    }
    .top-nav-link.active::after {
        display: none; /* Remove underline, stick to pill shape */
    }

    /* ========================================
       Sidebar
       ======================================== */
    .sidebar {
        width: var(--sidebar-width);
        flex-shrink: 0;
        border-right: 1px solid var(--border);
        background: var(--bg-sidebar);
        backdrop-filter: var(--glass-blur);
        -webkit-backdrop-filter: var(--glass-blur);
        transition: background var(--transition), border-color var(--transition);
    }
    
    .sidebar-sticky {
        position: sticky;
        top: var(--header-height);
        padding: 40px 32px;
        max-height: calc(100vh - var(--header-height));
        overflow-y: auto;
    }

    .profile-name {
        font-family: var(--font-serif);
        font-size: 1.75rem;
        font-weight: 700;
        color: var(--text);
        margin-bottom: 8px;
        letter-spacing: -0.03em;
        line-height: 1.2;
    }
    
    .profile-title {
        font-size: 0.95rem;
        color: var(--text-secondary);
        font-weight: 400;
        margin-bottom: 4px;
    }

    /* Cards - Glass & Shadow */
    .r-card, .pub-entry, .proj-card, .proj-card-sm, .c-card {
        background: var(--bg-card);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid var(--border);
        box-shadow: var(--shadow-xs);
        transition: all var(--transition);
    }
    .r-card:hover, .pub-entry:hover, .proj-card:hover, .proj-card-sm:hover, .c-card:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-lg);
        border-color: var(--primary-border);
    }

    /* Typography refinements */
    h1, h2, h3, h4, h5, h6 {
        color: var(--text);
        line-height: 1.3;
    }
    p {
        color: var(--text-secondary);
        line-height: 1.75;
    }
    
    .hero-headline {
        font-family: var(--font-serif);
        font-size: clamp(2rem, 4vw, 3rem);
        font-weight: 700;
        line-height: 1.15;
        color: var(--text);
        margin-bottom: 24px;
        letter-spacing: -0.03em;
    }
    
    .section-heading {
        font-size: 1.8rem;
        margin-bottom: 16px;
        letter-spacing: -0.02em;
    }
    
    .btn {
        font-weight: 500;
        letter-spacing: 0.01em;
        padding: 10px 24px;
        border-radius: 8px;
        box-shadow: var(--shadow-sm);
    }
    .btn:hover {
        box-shadow: var(--shadow-md);
    }

/* ========================================
   Footer
   ======================================== */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 20px 32px;
    text-align: center;
    background: var(--bg-secondary);
    transition: background var(--transition), border-color var(--transition);
}
.footer-inner p {
    font-size: 0.82rem;
    color: var(--text-muted);
}
.footer-inner a {
    color: var(--primary);
    font-weight: 500;
}

/* ========================================
   Back to Top
   ======================================== */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--transition);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    z-index: 100;
}
.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.back-to-top:hover {
    color: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px);
}

/* ========================================
   Scroll Animations
   ======================================== */
.reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}
.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 1100px) {
    .hero-visual {
        display: none;
    }
    .research-mosaic {
        grid-template-columns: 1fr;
    }
    .r-featured .r-card-body {
        display: block;
    }
    .r-featured .r-card-icon {
        margin-bottom: 14px;
    }
    .r-featured p,
    .r-featured .r-tags {
        grid-column: auto;
    }
    .proj-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    :root {
        --sidebar-width: 260px;
    }
    .content-section,
    .hero-banner {
        padding: 32px 28px;
    }
    .contact-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .top-nav {
        display: none;
    }
    .mobile-toggle {
        display: flex;
    }

    .page-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-sticky {
        position: static;
        max-height: none;
        padding: 24px 20px;
        display: grid;
        grid-template-columns: auto 1fr;
        gap: 0 24px;
        align-items: start;
    }
    .profile {
        grid-row: 1 / 4;
    }
    .profile-avatar {
        width: 100px;
        height: 100px;
    }
    .profile-avatar canvas {
        width: 110px;
        height: 110px;
    }
    .avatar-inner {
        width: 85px;
        height: 85px;
        font-size: 2rem;
        margin: 7px auto;
    }
    .profile-name {
        font-size: 1.2rem;
    }
    .sidebar-bio,
    .sidebar-keywords {
        grid-column: 2;
    }
    .sidebar-info,
    .sidebar-social {
        grid-column: 2;
    }

    .content-section,
    .hero-banner {
        padding: 24px 16px;
    }

    .hero-headline {
        font-size: 1.5rem;
    }

    .proj-grid {
        grid-template-columns: 1fr;
    }

    .tool-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .pub-year-group {
        flex-direction: column;
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .sidebar-sticky {
        display: block;
    }
    .hero-actions {
        flex-direction: column;
    }
    .hero-actions .btn {
        text-align: center;
        justify-content: center;
    }
    .tool-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .cv-download {
        flex-direction: column;
        text-align: center;
    }
}
