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

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --accent: #3b82f6;
    --border: #475569;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Navigation */
.navbar {
    position: fixed;
    top: 0;
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    padding: 1rem 0;
    min-height: 70px;
    max-height: 70px;
    height: 70px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    /* Prevent layout shifts */
    will-change: auto;
    transform: translateZ(0);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.nav-logo a {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
    position: relative;
}

.nav-link:hover,
.nav-link.active {
    color: var(--accent);
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent);
}

.hamburger {
    display: none;
    flex-direction: column;
    cursor: pointer;
    gap: 4px;
}

.hamburger span {
    width: 25px;
    height: 3px;
    background: var(--text-primary);
    transition: all 0.3s ease;
}

/* Sections */
.section {
    /* Use visibility instead of display to keep sidebars in render tree */
    visibility: hidden;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    /* Prevent layout shifts */
    contain: layout;
    /* Ensure section doesn't create containing block for fixed children */
    transform: none;
    will-change: auto;
}

.section.active {
    visibility: visible;
    position: relative;
    height: auto;
    opacity: 1;
    pointer-events: auto;
    animation: fadeIn 0.5s ease;
    /* Ensure active section doesn't create containing block for fixed children */
    transform: none;
    will-change: auto;
}

/* Project sections (not home) */
#pathfinder.active,
#snackfinder.active,
#universe.active {
    display: flex;
    height: calc(100vh - 70px);
    margin-top: 70px;
    overflow: hidden;
    position: relative;
    /* Ensure section doesn't affect fixed sidebar positioning */
    contain: layout style;
    /* Critical: Don't create containing block for fixed children */
    transform: none !important;
    will-change: auto !important;
    /* Remove any properties that could create containing block */
    filter: none !important;
    perspective: none !important;
    backdrop-filter: none !important;
}

/* Home section */
#home.active {
    min-height: calc(100vh - 70px);
    margin-top: 70px;
    padding: 50px 0;
}

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 4rem 0;
}

.hero h1 {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.5rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.description {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 700px;
    margin: 0 auto 3rem;
    line-height: 1.8;
}

/* Project Grid */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 3rem;
}

.project-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.project-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 10px 30px var(--shadow);
}

.card-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.project-card h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.project-card p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.card-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.card-link:hover {
    color: #60a5fa;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    position: fixed;
    top: 85px;
    left: 20px;
    z-index: 1002; /* Higher than sidebar (1000) to appear on top */
    display: none; /* Hidden by default, shown by JS when section is active */
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 45px;
    height: 45px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: left 0.3s ease, background-color 0.3s ease, transform 0.2s ease;
    box-shadow: 0 4px 12px var(--shadow);
    /* Prevent jumping by ensuring stable positioning */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translate3d(0, 0, 0);
}

#home .sidebar-toggle {
    display: none;
}

.sidebar-toggle:hover {
    background: var(--surface-light);
    transform: scale(1.05);
}

.sidebar-toggle.active {
    left: 320px;
}

.project-sidebar.active ~ .sidebar-toggle {
    left: 320px;
}

/* Project Sidebar */
.project-sidebar {
    position: fixed !important; /* Force fixed positioning to prevent parent margin from affecting it */
    left: 0;
    top: 70px; /* Default, will be overridden by JS to match navbar bottom */
    width: 350px;
    height: calc(100vh - 70px); /* Default, will be overridden by JS */
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    /* Only transition left property, not top or height to prevent jumps */
    transition: left 0.3s ease;
    z-index: 1000;
    box-shadow: 2px 0 10px var(--shadow);
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--surface);
    /* Prevent jumping by ensuring stable positioning */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translate3d(0, 0, 0);
    will-change: left;
    /* Prevent layout shifts and ensure sidebar is positioned relative to viewport, not parent */
    contain: layout;
    /* Ensure sidebar is not affected by parent transforms or margins */
    isolation: isolate;
}

.project-sidebar:not(.active) {
    left: -350px;
}

.project-sidebar::-webkit-scrollbar {
    width: 8px;
}

.project-sidebar::-webkit-scrollbar-track {
    background: var(--surface);
}

.project-sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.project-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--surface-light);
}

.project-sidebar.active {
    left: 0;
}

/* Sidebars are now outside sections, so they're controlled by JavaScript */
/* Default: hide all sidebars, JavaScript will show the active one */
.project-sidebar {
    display: none;
}

.project-sidebar:not(.active) ~ .project-embed {
    margin-left: 0;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.project-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.sidebar-content {
    padding: 1.5rem;
}

.sidebar-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    margin-top: 1.5rem;
    color: var(--text-primary);
}

.sidebar-content h2:first-of-type {
    margin-top: 0;
}

.sidebar-content h3 {
    font-size: 1.2rem;
    margin: 1.5rem 0 1rem;
    color: var(--text-primary);
}

.sidebar-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.8;
    font-size: 0.95rem;
}

.sidebar-content ul {
    list-style: none;
    padding-left: 0;
    margin-bottom: 1.5rem;
}

.sidebar-content li {
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
    padding-left: 1.5rem;
    position: relative;
    font-size: 0.9rem;
}

.sidebar-content li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--accent);
}

/* Tech Tags */
.tech-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.tech-tag {
    background: var(--surface-light);
    color: var(--accent);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid var(--border);
}

/* Project Embed */
.project-embed {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    background: var(--background);
    overflow: hidden;
    margin-left: 350px;
    transition: margin-left 0.3s ease;
}

.project-sidebar:not(.active) ~ .project-embed {
    margin-left: 0;
}

.project-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.frame-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
}

.open-fullscreen {
    background: var(--accent);
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px var(--shadow);
}

.open-fullscreen:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow);
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    text-align: center;
    color: var(--text-secondary);
    margin-top: 4rem;
}

/* Responsive Design */
@media (max-width: 968px) {
    .project-sidebar {
        width: 300px;
        left: -300px;
    }

    .project-sidebar.active ~ .project-embed {
        margin-left: 300px;
    }

    .sidebar-toggle.active {
        left: 270px;
    }

    .hero h1 {
        font-size: 2.5rem;
    }

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

@media (max-width: 768px) {
    .hamburger {
        display: flex;
    }

    .nav-menu {
        position: fixed;
        left: -100%;
        top: 70px;
        flex-direction: column;
        background: var(--surface);
        width: 100%;
        text-align: center;
        transition: 0.3s;
        box-shadow: 0 10px 27px var(--shadow);
        padding: 2rem 0;
        border-top: 1px solid var(--border);
    }

    .nav-menu.active {
        left: 0;
    }

    .nav-menu li {
        margin: 1rem 0;
    }

    .container {
        padding: 0 1rem;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1.2rem;
    }

    .project-sidebar {
        width: 100%;
        left: -100%;
    }

    .project-sidebar.active {
        left: 0;
    }

    .project-sidebar.active ~ .project-embed {
        margin-left: 0;
        display: none;
    }

    .sidebar-toggle {
        top: 80px;
        left: 10px;
    }

    .sidebar-toggle.active {
        left: 10px;
    }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Selection */
::selection {
    background: var(--accent);
    color: white;
}

