:root {
    /* Paper, ink + oxblood palette */
    --bg-color: #F4EEE0; /* Warm uncoated paper */
    --sidebar-bg: #F4EEE0;
    --card-bg: #FAF6EC;
    --text-primary: #1C1A16; /* Ink */
    --text-secondary: #3C3830;
    --text-muted: #7A7260;
    --accent-color: #6B2018; /* Muted oxblood */
    --accent-hover: #8E2B20;
    --accent-tint: rgba(107, 32, 24, 0.07);
    --border-color: #D8CDB4;
    --card-shadow: none;
    --transition-speed: 0.3s;
    --toggle-bg: #ECE3CE;
    --plate-bg: #F4EEE0; /* Backdrop behind project thumbnails */

    /* Typography */
    --font-heading: 'Fraunces', 'Times New Roman', serif;
    --font-body: 'Crimson Pro', Georgia, serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

[data-theme="dark"] {
    --bg-color: #17140F;
    --sidebar-bg: #17140F;
    --card-bg: #1F1B15;
    --text-primary: #ECE4D2;
    --text-secondary: #C4B9A2;
    --text-muted: #8E846F;
    --accent-color: #D9907F;
    --accent-hover: #EBB2A4;
    --accent-tint: rgba(217, 144, 127, 0.12);
    --border-color: #3A332A;
    --toggle-bg: #2A251E;
    --plate-bg: #E9E1CE;
}

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

html {
    font-size: 17.5px;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.55;
    display: flex;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    font-feature-settings: "kern" 1, "liga" 1, "onum" 1; /* Old-style figures */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Dark Mode Toggle --- */
.theme-toggle {
    background: var(--toggle-bg);
    border: none;
    color: var(--text-primary);
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px auto;
    transition: transform 0.3s, background 0.3s;
    width: 40px;
    height: 40px;
}

.theme-toggle:hover {
    background: var(--accent-tint);
    color: var(--accent-color);
}

/* --- Sidebar Navigation --- */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    padding: 40px 30px;
    border-right: 1px solid var(--text-primary);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 100;
    transition: background 0.3s, border-color 0.3s;
}

.profile-header {
    text-align: center;
    margin-bottom: 40px;
}

.profile-img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 20px;
    box-shadow: 0 0 0 1px var(--text-primary);
    border: 4px solid var(--sidebar-bg);
}

.profile-name {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 400;
    font-variation-settings: "opsz" 72;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.profile-role {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

nav ul {
    list-style: none;
}

nav li {
    margin-bottom: 6px;
}

nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    display: block;
    padding: 10px 15px;
    border-left: 2px solid transparent;
    transition: var(--transition-speed);
}

nav a:hover, nav a.active {
    color: var(--accent-color);
    border-left-color: var(--accent-color);
}


.sidebar-bottom {
    margin-top: auto;
    text-align: center;
}

.copyright {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 15px;
    opacity: 0.8;
}

.social-links {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.social-icon {
    color: var(--text-secondary);
    transition: var(--transition-speed);
}

.social-icon:hover {
    color: var(--accent-color);
    transform: translateY(-3px);
}

/* --- Main Content Area --- */
.main-content {
    flex: 1;
    margin-left: 280px; /* Match sidebar width */
    padding: 60px 80px;
    max-width: 1200px; /* Prevent stretching on huge screens */
}

/* --- Section Switching --- */
section {
    display: none;
    opacity: 0;
    animation: fadeIn 0.4s ease-in-out forwards;
    padding-bottom: 50px;
}

section.active-section {
    display: block;
}

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

h1, h2, h3 {
    font-family: var(--font-heading);
    font-weight: 400;
    font-variation-settings: "opsz" 72;
    color: var(--text-primary);
}

h2 {
    font-size: 2.6rem;
    font-variation-settings: "opsz" 144;
    letter-spacing: -0.015em;
    margin-bottom: 40px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--text-primary);
}

p {
    margin-bottom: 20px;
    color: var(--text-secondary);
    font-size: 1.12rem;
}

.main-content p em, .pub-list em, .teaching-card em, .current-work em {
    color: var(--text-primary);
    font-style: italic;
}

/* --- Links: visible accent at rest, hover deepens --- */
.main-content p a, .teaching-card li a, .pub-list a, .current-work li a {
    color: var(--accent-color);
    text-decoration: none;
    background-image: linear-gradient(var(--accent-color), var(--accent-color));
    background-size: 100% 1px;
    background-repeat: no-repeat;
    background-position: left 95%;
    transition: background-size 0.3s ease, color 0.2s ease;
    padding-bottom: 1px;
}

.main-content p a:hover, .teaching-card li a:hover, .pub-list a:hover, .current-work li a:hover {
    background-size: 100% 2px;
    color: var(--accent-hover);
}

/* Regular links elsewhere (like "Link" buttons) */
a {
    color: var(--accent-color);
    text-decoration: none;
    transition: var(--transition-speed);
}

/* --- Projects Section Headers --- */
#projects h3 {
    font-size: 1.5rem;
    font-family: var(--font-heading);
    color: var(--text-primary);
    margin-top: 50px;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
}

#projects h3:first-of-type {
    margin-top: 10px; /* Less space for the first one */
}

/* --- Projects Grid --- */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
}

.project-card {
    background: var(--card-bg);
    border-radius: 2px;
    overflow: hidden;
    transition: all 0.4s ease;
    cursor: pointer;
    position: relative;
    border: 1px solid var(--border-color);
    padding: 15px; /* Restored padding logic */
}

.project-card:hover {
    border-color: var(--accent-color);
}

.project-img-wrapper {
    height: 250px; /* Restored height */
    overflow: hidden;
    background: var(--plate-bg); /* Paper plate so logos, scans, and photos read as one set */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 1px;
}

.project-card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    mix-blend-mode: multiply; /* Drop white image backgrounds into the plate */
    transition: transform 0.5s ease;
}

.project-card:hover img {
    transform: scale(1.05);
}

.project-info {
    padding: 15px; /* Consistent padding all around */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70px; /* Ensure 2-line titles fit comfortably */
}

.project-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    margin-bottom: 0; /* No bottom margin needed if no desc */
    font-weight: 400;
    text-align: center; /* Center the title */
}

.project-desc {
    display: none; /* Hide descriptions in the grid */
}

/* --- Tools Grid --- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.tool-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 2px;
    transition: border-color 0.3s ease;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    text-decoration: none; /* Remove underline from the whole card */
    color: inherit; /* Inherit text color */
}

.tool-card:hover {
    border-color: var(--accent-color);
}

/* .tool-card h3 is now handled by .project-title class for consistency */
.tool-card .project-title {
    padding-bottom: 10px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    transition: border-color 0.3s ease;
}

.tool-card:hover .project-title {
    border-color: var(--accent-color); /* Highlight line on hover too */
    color: var(--accent-color);
}

.tool-card p {
    flex-grow: 1;
    margin-bottom: 0; /* No need for bottom margin now */
    font-size: 0.95rem;
    color: var(--text-secondary);
}

/* --- Publications (Accordion Style) --- */
.pub-category {
    background: var(--card-bg);
    border-radius: 2px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    overflow: hidden;
}

.pub-header {
    padding: 20px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: var(--card-bg);
    transition: background 0.2s;
}

.pub-header:hover {
    background: var(--accent-tint);
}

.pub-header:hover h3 {
    color: var(--accent-color);
}

.pub-header h3 {
    transition: color 0.2s;
}

.pub-header h3 {
    font-size: 1.35rem;
    margin: 0;
}

.pub-icon {
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.pub-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
    background: var(--card-bg);
    border-top: 1px solid transparent;
}

.pub-content.open {
    border-top-color: var(--border-color);
}

.pub-list {
    padding: 25px;
    list-style: none;
    counter-reset: pub;
}

/* Numbered entries with a hanging indent */
.pub-list li {
    counter-increment: pub;
    margin-bottom: 15px;
    padding-left: 2.6em;
    position: relative;
    font-size: 1.08rem;
    line-height: 1.5;
}

.pub-list li::before {
    content: counter(pub, decimal-leading-zero);
    position: absolute;
    left: 0;
    top: 0.3em;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* --- Teaching Section --- */
.teaching-card {
    background: var(--card-bg);
    padding: 32px 36px;
    border-radius: 2px;
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
}

.teaching-card h3 {
    font-size: 1.45rem;
    font-family: var(--font-heading);
    margin-bottom: 22px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.teaching-card ul {
    list-style: none;
    padding: 0;
}

.teaching-card li {
    padding: 10px 0 10px 18px;
    position: relative;
    line-height: 1.55;
}

.teaching-card li::before {
    content: '';
    position: absolute;
    left: 0;
    top: calc(10px + 0.775em); /* centre on first line: padding + half line-height */
    width: 8px;
    height: 1px;
    background: var(--accent-color);
    border-radius: 1px;
}

/* --- Current Work (About) --- */
.current-work {
    background: var(--card-bg);
    padding: 28px 36px;
    border-radius: 2px;
    border: 1px solid var(--border-color);
    margin-top: 40px;
}

.current-work h3 {
    font-size: 1.45rem;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.current-work ul {
    list-style: none;
    padding: 0;
}

.current-work li {
    padding: 12px 0;
    line-height: 1.55;
    color: var(--text-secondary);
}

.current-work li a em {
    color: inherit;
}

.current-work li + li {
    border-top: 1px solid var(--border-color);
}

/* --- Mobile Responsiveness --- */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    background: var(--card-bg);
    border: none;
    padding: 10px;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    color: var(--text-primary);
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 260px;
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 40px 20px;
    }

    .mobile-menu-btn {
        display: block;
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 90;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 600px) {
    .lightbox-content {
        padding: 20px;
        width: 95%;
        max-height: 85vh; /* Leave room for bars */
    }
    
    .lightbox-img {
        height: auto;
        max-height: 180px; /* Much smaller on mobile */
        object-fit: contain;
        margin-bottom: 10px;
    }
    
    .lightbox h3 { /* Target the title */
        font-size: 1.2rem;
        margin-bottom: 10px;
    }
    
    .lightbox p { /* Target the desc */
        font-size: 0.9rem;
    }
}

/* Headshot overlay */
.profile-img-btn {
    display: inline-block;
    padding: 0;
    border: none;
    background: none;
    border-radius: 50%;
    cursor: zoom-in;
}

.profile-img-btn .profile-img {
    display: block;
    transition: transform 0.3s ease;
}

.profile-img-btn:hover .profile-img {
    transform: rotate(-4deg) scale(1.04);
}

.profile-img-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 4px;
}

.portrait-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 16px;
    justify-content: center;
    align-items: center;
    background: color-mix(in srgb, var(--bg-color) 94%, transparent);
    backdrop-filter: blur(4px);
}

.portrait-overlay.active {
    display: flex;
}

.portrait-print {
    margin: 0;
    width: min(880px, 100%);
    padding: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 0 var(--border-color), 0 18px 40px -18px rgba(28, 26, 22, 0.45);
    animation: print-drop 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.portrait-frame {
    position: relative;
}

.portrait-frame img {
    display: block;
    width: 100%;
    max-height: 72vh;
    object-fit: cover;
    animation: print-develop 1.6s ease-out 0.2s both;
}

.portrait-close {
    position: absolute;
    top: 12px;
    right: 18px;
    font-size: 2.5rem;
    line-height: 1;
    padding: 0;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
}

@keyframes print-drop {
    from { opacity: 0; transform: translateY(-40px) rotate(-6deg) scale(0.92); }
    to   { opacity: 1; transform: translateY(0) rotate(-1deg); }
}

@keyframes print-develop {
    from { filter: sepia(1) contrast(0.6) brightness(1.35) blur(3px); }
    to   { filter: none; }
}

@media (prefers-reduced-motion: reduce) {
    .portrait-print,
    .portrait-frame img {
        animation-duration: 0.01s;
        animation-delay: 0s;
    }
    .profile-img-btn:hover .profile-img {
        transform: none;
    }
}

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    backdrop-filter: blur(5px);
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    max-width: 800px;
    width: 100%;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.lightbox-img {
    width: 100%;
    height: 300px;
    object-fit: contain;
    background: #f9f9f9;
    border-radius: 8px;
    margin-bottom: 20px;
}

.lightbox-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2.5rem;
    cursor: pointer;
    color: #333; /* Dark for visibility on white */
    background: none;
    border: none;
    line-height: 1;
    padding: 0;
    z-index: 10;
}

/* Lightbox Navigation */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: white;
    font-size: 3rem;
    cursor: pointer;
    padding: 20px;
    z-index: 1002;
    opacity: 0.7;
    transition: opacity 0.3s;
}

.lightbox-nav:hover {
    opacity: 1;
}

.lightbox-nav.prev { left: 10px; }
.lightbox-nav.next { right: 10px; }

@media (max-width: 600px) {
    .lightbox-nav {
        font-size: 2rem;
        padding: 10px;
    }
}
@media (max-width: 600px) {
    .current-work {
        padding: 22px 20px;
    }
}

.btn-primary {
    display: inline-block;
    background: var(--accent-color);
    color: white;
    padding: 10px 25px;
    border-radius: 6px;
    margin-top: 15px;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: white;
    text-decoration: none;
}


/* --- Print / CV Styles --- */
@media print {
    /* Hide navigation and interactive elements */
    .sidebar, 
    .mobile-menu-btn, 
    .sidebar-overlay, 
    .lightbox, 
    .social-links,
    .pub-icon { 
        display: none !important; 
    }

    /* Reset layout for full width */
    body { 
        display: block; 
        background: white; 
        color: black;
    }

    .main-content { 
        margin: 0 !important; 
        padding: 0 !important; 
        max-width: 100% !important; 
    }

    /* Show all sections */
    section { 
        display: block !important; 
        opacity: 1 !important; 
        margin-bottom: 40px !important; 
        page-break-inside: avoid;
        animation: none !important;
    }

    /* Expand accordions */
    .pub-content { 
        max-height: none !important; 
        border-top: 1px solid #ccc; 
        margin-top: 10px;
        padding-top: 10px;
    }

    /* Typography tweaks for print */
    h1 { font-size: 24pt; margin-bottom: 10px; }
    h2 { font-size: 18pt; border-bottom: 2px solid black; padding-bottom: 5px; margin-bottom: 20px; }
    
    a { 
        text-decoration: none; 
        color: black !important; 
    }
    
    /* Add URL after links for reference */
    .teaching-card a::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    .project-card, .tool-card {
        border: 1px solid #ccc;
        box-shadow: none;
        page-break-inside: avoid;
    }
}