/* --- Global Variables & Reset --- */
:root {
    --primary: #5e3a80;   /* Rich Academic Purple - noticeably lighter and truly purple */
    /* --primary: #725192;   Uncomment this line instead if you want a softer Amethyst */
    
    --secondary: #347b98; /* Muted Teal */
    --text: #333333;
    --bg: #f8f9fa;
    --border: #e0e0e0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: #ffffff;
    margin: 0;
    overflow-x: hidden;
    width: 100%;
}

/* --- General Text Links --- */
a {
    color: var(--secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: #255d75; /* Darker teal for hover effect */
    text-decoration: underline;
}

/* Ensure this doesn't accidentally underline your navigation tabs or buttons on hover */
nav a:hover, 
.button-pdf:hover {
    text-decoration: none;
}

/* --- Navigation (Tab Style) --- */
nav {
    background: #ffffff;
    border-bottom: 2px solid var(--primary);
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    padding-top: 15px;
}

nav a {
    text-decoration: none;
    color: var(--text);
    padding: 10px 30px;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
    margin: 0 5px;
    border-radius: 8px 8px 0 0; 
    transition: all 0.3s ease;
    border: 1px solid transparent;
    border-bottom: none;
}

nav a:hover {
    color: var(--secondary);
    background: #f0f0f0;
    transform: translateY(-2px);
}

nav a.active {
    color: white;
    background: var(--secondary);
    border: 1px solid var(--secondary);
    border-bottom: 2px solid var(--secondary);
}

/* --- Header (No-Scale Building Background) --- */
header {
    width: 100%;
    background-color: var(--bg);
    background-image: 
        /* FIXED: Using fixed pixels (px) instead of percentages (%) ensures the gradient covers the right edge of the image on very wide screens */
        linear-gradient(to right, rgba(248, 249, 250, 0) 0px, rgba(248, 249, 250, 0.9) 500px, rgba(248, 249, 250, 1) 800px), 
        url('middlesex.jpg');
    background-size: auto 100%;
    background-position: left center;
    background-repeat: no-repeat;
    padding: 90px 0;
    border-bottom: 1px solid var(--border);
}

.header-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1.5rem;
    box-sizing: border-box;
    text-align: right;
}

header h1 { 
    margin: 0; 
    font-size: 3rem; 
    color: var(--primary); 
    font-weight: 700;
}

header p { 
    font-family: "Palatino Linotype", "Palatino", "Book Antiqua", serif;
    font-size: 1.4rem; 
    color: #555; 
    margin: 8px 0 0 0;
    font-style: italic;
}

/* --- Main Layout --- */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    box-sizing: border-box;
}
.container, main {
    width: 100%;
    max-width: 1200px; /* or your preferred desktop width */
    margin: 0 auto;
    overflow-x: hidden; /* Prevents horizontal scrolling */
    box-sizing: border-box;
}

section { margin-bottom: 3rem; }

h2 {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    display: inline-block;
    padding-right: 2rem;
    margin-bottom: 1.5rem;
}

/* --- Research Page Bibliography & Popups --- */
.paper-item { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.paper-title { color: var(--primary); font-weight: 600; cursor: pointer; text-decoration: none; }
.paper-title:hover { 
    color: var(--secondary);
    text-decoration: underline; 
}
.paper-meta { font-size: 0.9rem; color: #666; margin-top: 4px; }

.button-pdf {
    /* The ultimate centering combo */
    display: flex !important; 
    align-items: center;
    justify-content: center;
    width: max-content !important;
    margin: 15px auto !important;
    
    /* Reduced sizing */
    padding: 8px 16px !important;      
    font-size: 0.85rem !important;     
    
    /* Colors and shape */
    background-color: var(--secondary);
    color: white !important;
    text-decoration: none;
    border-radius: 5px;
    font-weight: bold;
    transition: background 0.3s ease;
}

/* --- ArXiv Button Variation --- */
.button-arxiv {
    /* Identical centering and sizing to the PDF button */
    display: flex !important; 
    align-items: center;
    justify-content: center;
    width: max-content !important;
    margin: 15px auto !important;
    padding: 8px 16px !important;      
    font-size: 0.85rem !important;     
    
    /* Uses the Oxford Purple instead of Teal */
    background-color: var(--primary);
    color: white !important;
    text-decoration: none;
    border-radius: 5px;
    font-weight: bold;
    transition: background 0.3s ease;
}

.button-arxiv:hover {
    background-color: #4a2e66; /* Slightly darker purple for hover state */
    text-decoration: none;
}

/* Ensure the icon inside is also white */
.button-arxiv i.fa-solid {
    color: white;
}

/* --- Modal Background Overlay --- */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.7); /* Darkens the background */
    backdrop-filter: blur(3px); /* Optional: adds a modern blur to the background */
}

/* --- The Popup Box --- */
.modal-content {
    background-color: #ffffff;
    position: relative; /* Crucial for pinning the X to the corner */
    margin: 5vh auto; /* Centers it vertically */
    padding: 35px 20px 20px 20px; /* Extra padding at the top so text doesn't hit the X */
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 85%; 
    max-width: 600px;
    
    /* The Scroll Fix */
    max-height: 85vh; /* Never gets taller than 85% of the screen */
    overflow-y: auto; /* Adds a scrollbar INSIDE the popup if text is too long */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iPhones */
    
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* --- The Close Button --- */
.close-x {
    position: absolute;
    top: 15px;      /* Pushed further down from the top edge */
    right: 20px;    /* Pushed further in from the right edge */
    color: var(--text);
    font-size: 1.5rem; /* Slightly larger for touch screens */
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 10;    /* Ensures it always sits on top of any scrolling text */
}

.close-x:hover {
    color: var(--secondary); /* Turns teal when clicked/hovered */
}


/* --- Footer --- */
footer {
    text-align: center;
    padding: 2rem;
    font-size: 0.8rem;
    color: #888;
    border-top: 1px solid var(--border);
    margin-top: 4rem;
}

/* --- Mobile Fixes --- */
@media (max-width: 768px) {
    /* Header Adjustments */
    header h1 { font-size: 2.2rem; }
    .header-container { text-align: center; }
    header { 
        background-image: linear-gradient(to bottom, rgba(248,249,250,0.4), rgba(248,249,250,0.9)), url('middlesex.jpg'); 
        background-size: cover; 
    }
    
    /* Navigation Tab Adjustments */
    nav { padding-top: 10px; }
    nav a {
        padding: 10px 12px;     
        font-size: 0.75rem;     
        margin: 0 2px;          
        letter-spacing: 0.5px;  
    }
    
    .profile-section {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1.5rem;
    }

    /* --- Responsive Table Fix --- */
    .term-box table, 
    .container table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; 
        border-collapse: collapse;
    }

    .term-box table th, 
    .term-box table td {
        padding: 6px 8px;
        font-size: 0.85rem;
    }
}

/* --- Profile Section (Side-by-Side) --- */
.profile-section {
    display: flex;
    align-items: flex-start; 
    gap: 3rem;              
    margin-bottom: 3rem;
}

.profile-photo {
    width: 250px;           
    height: auto;
    border-radius: 8px;     
    flex-shrink: 0;         
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.profile-text {
    flex: 1;                
}

/* Responsive: Stacks the photo on top of the text when the screen is narrow (mobile) */
@media (max-width: 768px) {
    .profile-section {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1.5rem;
    }
}

/* --- Teaching Section --- */
.teaching-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem; /* Reduced space between boxes */
}

.term-box {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.5rem; /* Reduced inner padding to save vertical space */
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
    flex: 1 1 300px; /* Grows, but base size is 300px */
    min-width: 0;    /* CRITICAL: allows flex items to shrink below content size */
}

.term-box h3 {
    margin-top: 0;
    color: var(--primary);
    border-bottom: 2px solid #eee;
    padding-bottom: 8px;
    margin-bottom: 10px;
    text-align: center; /* Pushes the term name to the right edge */
}

.course-list {
    list-style: none;
    padding: 0;
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word; /* Forces breaks in long names if necessary */
    max-width: 100%;
}

.course-list li {
    padding: 8px 0; /* Reduced padding between courses */
    border-bottom: 1px solid #f0f0f0;
    /* Removed 'flex-direction: column' so they share the same line */
    line-height: 1.5; 
}

.course-list li:last-child {
    border-bottom: none;
}

.course-code {
    font-weight: 700;
    color: var(--text);
    font-size: 1.05rem;
    margin-right: 12px; /* Space between code and description */
    min-width: 120px; /* Optional: perfectly aligns all descriptions in a neat vertical column */
    display: inline-block; /* Allows it to wrap if inside a small container */
    max-width: 100%;
}
/* --- Research Page & Modal --- */
.section-title { 
    border-bottom: 2px solid var(--primary); 
    display: inline-block; 
    margin: 2.5rem 0 1rem; 
    padding-right: 2rem; 
    font-size: 1.5rem; 
}

.modal-content {
    background: #ffffff;
    margin: 5% auto;
    padding: 0; 
    width: 90%;
    max-width: 600px;
    border-radius: 16px; 
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); 
    font-family: "Times New Roman", Times, serif; 
}

#modalInner {
    padding: 2rem 2.5rem;
    color: #000;
    line-height: 1.5;
}

#modalInner h3 {
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 1.2rem;
    margin-top: 0;
    border: none;
}

.modal-footer {
    border-top: 1px solid #ddd;
    padding: 10px 20px;
    text-align: right;
    background: #fff;
}

.close-x {
    cursor: pointer;
    font-family: 'Segoe UI', sans-serif;
    font-weight: bold;
    color: #666;
    text-transform: uppercase;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.close-x:hover {
    color: #000;
}

.close-btn { 
    display: none; 
}

.button-pdf {
    display: inline-block;
    background-color: var(--secondary);
    color: white !important;
    padding: 10px 20px;
    text-decoration: none;
    border-radius: 5px;
    font-weight: bold;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.button-pdf:hover {
    background-color: #255d75; /* A darker shade of the teal */
    text-decoration: none;
}

.pdf-link:hover {
    background: var(--primary);
    color: white;
}

/* --- Font Awesome Global Styling --- */
i.fa-solid {
    color: var(--primary);
    margin-right: 6px;
}

/* Specific fix for the contact list to prevent double spacing */
.contact-list i.fa-solid {
    margin-right: 0; 
}
/* --- Fix for icons inside buttons --- */
.button-pdf i.fa-solid {
    color: white;
}
/* --- Expandable Accordions --- */
.pub-accordion {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.pub-accordion summary {
    padding: 15px 20px;
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary);
    background: var(--light);
    cursor: pointer;
    list-style: none; /* Removes the default tiny triangle */
    transition: all 0.2s ease;
}

/* Hide the default triangle in Safari */
.pub-accordion summary::-webkit-details-marker {
    display: none; 
}

.pub-accordion summary:hover {
    color: var(--secondary);
    background: #f0f0f0;
}

/* Style when the accordion is OPEN */
.pub-accordion[open] summary {
    border-bottom: 1px solid var(--border);
    color: var(--secondary); /* Turns teal when open */
}

/* Swap the folder icon from closed to open when clicked */
.pub-accordion[open] summary i::before {
    content: "\f07c"; /* Font Awesome unicode for 'folder-open' */
}

/* Inner content spacing */
.accordion-content {
    padding: 0 20px;
}

/* Remove bottom border from the very last paper in the list */
.accordion-content .paper-item:last-child {
    border-bottom: none;
}

/* --- Photo Gallery --- */
.photo-gallery {
    display: grid;
    /* This automatically creates columns that are at least 250px wide, and fills the space */
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.gallery-item {
    margin: 0;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.gallery-item img {
    display: block;
    width: 100%;
    height: 200px;
    /* This forces a consistent 3:2 or 4:3 rectangle */
    aspect-ratio: 3 / 2;
    object-fit: cover; /* Ensures photos fill the box perfectly without stretching */
    transition: transform 0.4s ease;
    display: block;
    border-radius: 4px;
}

.gallery-item:hover img {
    transform: scale(1.05); /* Subtle zoom effect */
}

.gallery-item figcaption {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(94, 58, 128, 0.85); /* Your Deep Oxford Purple, slightly transparent */
    color: white;
    padding: 10px;
    font-size: 0.85rem;
    text-align: center;
    box-sizing: border-box;
    transform: translateY(100%); /* Hides the text initially */
    transition: transform 0.3s ease;
}

.gallery-item:hover figcaption {
    transform: translateY(0); /* Text slides up smoothly on hover */
}

#modalInner img {
    display: block;
    margin: 0 auto;
    
    /* Responsive sizing */
    width: auto;
    max-width: 95%;   /* Uses almost the full width of the modal */
    height: auto;
    max-height: 85vh; /* Prevents it from being taller than the screen */
    
    object-fit: contain; /* Keeps the aspect ratio perfect (no stretching) */
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

/* Special override for when an image is displayed */
.modal-photo-mode {
    width: 95% !important;
    max-width: 1200px !important;
    padding: 15px !important;
    
    /* Back to the black background */
    background-color: #000000 !important; 
    border: 1px solid #333;
    
    /* Keep the scrollbar fix */
    overflow: hidden !important; 
    
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-photo-mode #modalInner img {
    max-height: 75vh !important; 
    width: auto;
    max-width: 100%;
    object-fit: contain;
    display: block;
}

.modal-caption {
    color: #fff; /* White text on the dark background */
    text-align: center;
    margin-top: 10px;
    font-size: 1rem;
}
/* Ensure the caption and close button are visible on black */
.modal-photo-mode .modal-caption {
    color: #ffffff !important;
    margin-top: 15px;
}

/* Make sure the X is visible on the dark background */
.modal-photo-mode .close-x {
    color: #ffffff !important;
}

.race-card {
    background: #fdfdfd;
    border: 1px solid #e1e4e8;
    border-left: 5px solid #3e647e; 
    border-radius: 8px;
    padding: 20px;
    max-width: 500px;
    
    /* This adds the space you need between the cards */
    margin-top: 30px; 
    
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

/* Optional: remove the margin from the very first card 
   so it stays aligned with the <h2> header */
.race-card:first-of-type {
    margin-top: 15px;
}

/* Ensure all images stay within their parent container */
img {
    max-width: 100%;
    height: auto;
    display: block; /* Removes the tiny gap at the bottom of images */
}

/* Specific fix for your photo sections */
.personal-section img {
    border-radius: 8px; /* Optional: matches your race-card style */
    margin-bottom: 15px;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px 0; /* Adds vertical space around the photos */
}
/* If you are using a specific gallery container, ensure it doesn't have a fixed width */
.gallery-container {
    width: 100%;
    overflow: hidden;
}

/* --- Final Mobile Polish & Overflow Fix --- */
@media (max-width: 600px) {
    /* 1. Neutralize the fixed width on course codes */
    .course-code {
        min-width: 0 !important; 
        display: block !important; /* Puts the description on a new line if needed */
        margin-bottom: 4px;
    }

    /* 2. Fix the container padding */
    .container, main {
        padding-left: 15px !important;
        padding-right: 15px !important;
        overflow-x: hidden;
    }

    /* 3. Ensure term boxes don't hold onto desktop grid logic */
    .term-box {
        padding: 1rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 4. Force long student names to wrap */
    .course-list li {
        word-break: break-word;
        overflow-wrap: break-word;
    }
}
/* --- The "Force-to-Screen" Mobile Fix --- */
@media (max-width: 480px) {
    /* 1. Kill the Grid layout and force everything to a single stack */
    .teaching-grid {
        display: block !important;
        width: 100% !important;
    }

    /* 2. Remove any width constraints on the boxes */
    .term-box {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin-bottom: 20px !important;
        padding: 15px !important;
        box-sizing: border-box !important;
    }

    /* 3. Fix the specific "Calculus 1000" / Student name lines */
    .course-list li {
        display: block !important;
        width: 100% !important;
    }

    .course-code {
        display: block !important;
        min-width: 0 !important;
        width: 100% !important;
        margin-bottom: 5px !important;
    }

    /* 4. The Nuclear Option: ensure the container can't scroll right */
    .container, main, body, html {
        overflow-x: hidden !important;
        position: relative;
    }
}
/* --- Personal Page Mobile Image Fix --- */
@media (max-width: 480px) {
    /* Force the personal section to respect screen bounds */
    .personal-section {
        width: 100% !important;
        padding: 0 5px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    /* Ensure images and their captions never go wider than the phone screen */
    .personal-section img, 
    .gallery-item img,
    .race-card {
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    /* If you're using the grid for photos, force it to one column */
    .photo-gallery {
        display: block !important;
    }

    .gallery-item {
        margin-bottom: 20px !important;
        width: 100% !important;
    }

    /* Fix the "Upcoming Challenges" cards to prevent side-bleed */
    .race-card {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }
}
/* --- Full-Screen Mobile Modal Fix (UPDATED) --- */
@media (max-width: 480px) {
/* 1. Base Modal (For Research Abstracts) */
.modal-content {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    
    /* THE FIX: Top:50px, Right:10px, Bottom:15px, Left:10px */
    padding: 50px 10px 15px 10px !important; 
    
    box-sizing: border-box !important;
    background-color: #ffffff !important; 
    color: #333333 !important; 
    display: block !important; 
}

/* 2. Photo Mode Override (For Personal Page) */
.modal-photo-mode {
    background-color: #000000 !important; 
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    padding: 40px 10px 10px 10px !important;
    box-sizing: border-box !important; /* Matches the base modal constraint */
}


    /* 3. The Close 'X' Button Default (Research) */
    .close-x {
        position: absolute;
        top: 15px;
        right: 20px;
        font-size: 1.8rem !important;
        color: #333333 !important; /* Dark X on the white background */
        z-index: 9999;
    }

    /* 4. The Close 'X' Button for Photos */
    .modal-photo-mode .close-x {
        color: #ffffff !important; /* White X on the black background */
    }

    /* Make the image as large as possible without cropping */
    .modal-photo-mode #modalInner img {
        max-height: 80vh !important;
        width: auto !important;
        max-width: 100% !important;
        object-fit: contain;
    }

    /* Ensure the caption stays visible at the bottom */
    .modal-caption {
        margin-top: 20px;
        font-size: 1.1rem;
        color: #cccccc !important;
    }
}
/* --- Book Display Container --- */
.book-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-top: 15px;
}

.book-cover {
    flex-shrink: 0;
    width: 120px; /* Adjust for desired book size */
}

.book-cover img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    /* Adds a subtle shadow to mimic a physical book */
    box-shadow: 0 4px 8px rgba(0,0,0,0.15); 
    display: block;
}

/* Mobile override: Stack the image above the text */
@media (max-width: 480px) {
    .book-container {
        flex-direction: column;
        align-items: center; 
        text-align: center;
    }
    
    .book-cover {
        width: 140px; /* Slightly larger when centered on mobile */
        margin-bottom: 10px;
    }
}