/* --- Modern CSS Variables & Theming --- */
:root {
    --primary: #ea580c; /* Orange 600 */
    --primary-hover: #c2410c;
    --secondary: #d97706;
    --bg-main: #f8fafc;
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --text-main: #1e293b;
    --text-muted: #475569;
    --border-color: rgba(148, 163, 184, 0.3);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --primary: #f97316; /* Orange 500 */
    --primary-hover: #fb923c;
    --secondary: #f59e0b;
    --bg-main: #18181b; /* Dark Gray */
    --bg-gradient: linear-gradient(135deg, #18181b 0%, #27272a 100%);
    --glass-bg: rgba(39, 39, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.05);
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    --border-color: rgba(255, 255, 255, 0.1);
    --nav-bg: rgba(24, 24, 27, 0.85);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* --- Global Reset & Typography --- */
html {
    background-color: var(--bg-main); 
    overscroll-behavior-y: auto; 
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}

/* Bulletproof fixed gradient background */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-gradient);
    z-index: -2; /* Keeps it safely behind your moving blobs (which are -1) */
}

body {
    /* Background is now handled by the ::before pseudo-element */
    background: transparent;
    color: var(--text-main);
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

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

/* --- Fancy Animations --- */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.8s cubic-bezier(0.5, 0, 0, 1);
}
.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

@keyframes blobBounce {
    0% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.05); }
    100% { transform: translateY(0) scale(1); }
}

.bg-blob {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.5;
    animation: blobBounce 10s infinite ease-in-out;
}
.blob-1 { top: -10%; left: -10%; width: 50vw; height: 50vw; background: rgba(249, 115, 22, 0.15); }
.blob-2 { bottom: -10%; right: -10%; width: 40vw; height: 40vw; background: rgba(234, 88, 12, 0.15); animation-delay: -5s; }

/* --- Navigation --- */
nav {
    position: fixed;
    top: 0;
    width: 100%;
    background: var(--nav-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    z-index: 10000;
    transition: transform 0.3s cubic-bezier(0.3, 0, 0.2, 1), background-color 0.4s ease; 
}

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

.logo {
    font-weight: 800;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    cursor: pointer;
}

.nav-links {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav-link {
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    position: relative;
}

.nav-link::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: -4px;
    left: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    transition: width 0.3s;
}

.nav-link:hover::after, .nav-link.active::after { width: 100%; }
.nav-link:hover, .nav-link.active { color: var(--text-main); }

/* Controls: Theme & Lang */
.controls { display: flex; gap: 0.8rem; align-items: center; border-left: 1px solid var(--border-color); padding-left: 2.5rem; margin-left: 1rem; }
.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 38px; height: 38px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-weight: 700; font-size: 0.85rem;
    transition: all 0.3s;
}
.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

/* --- Main Content Area --- */
main {
    flex: 1;
    max-width: 1000px;
    margin: 120px auto 0;
    padding: 0 2rem 4rem;
    width: 100%;
}

.page-section { display: none; }
.page-section.active { display: block; animation: fadeIn 0.5s ease-out; }

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

/* --- Hero Section & Typography --- */
.hero-header { margin-bottom: 3rem; text-align: center; position: relative; z-index: 9999; }
h1 { font-size: 3.5rem; font-weight: 800; letter-spacing: -1px; margin-bottom: 0.5rem; background: linear-gradient(135deg, var(--text-main), var(--primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
h2 { font-size: 1.75rem; margin-top: 2.5rem; margin-bottom: 1.5rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }
.subtitle { font-size: 1.4rem; color: var(--secondary); font-weight: 600; margin-bottom: 1.5rem; }
.lead-text { font-size: 1.15rem; color: var(--text-muted); max-width: 800px; margin: 0 auto 2rem; }

/* --- Glassmorphism Cards --- */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative; z-index: 10;
}
.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px 0 rgba(31, 38, 135, 0.15);
}

.pub-card { padding: 1.5rem; }
.pub-card h3 { font-size: 1.15rem; margin-bottom: 0.4rem; }

/* --- Social Links & Email Button Menu --- */
.social-links { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin-top: 2rem; position: relative; z-index: 101; }
.social-item {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1.2rem;
    background: var(--glass-bg); border: 1px solid var(--border-color); border-radius: 99px;
    font-weight: 600; color: var(--text-main); font-size: 0.9rem;
    transition: all 0.3s ease; box-shadow: var(--shadow); cursor: pointer;
    font-family: 'Inter', sans-serif; text-decoration: none;
}
.social-item:hover { background: var(--primary); color: white; border-color: var(--primary); transform: translateY(-2px); }

/* Email Menu Dropdown Logic */
.email-menu {
    position: absolute; top: calc(100% + 5px); left: 50%; transform: translateX(-50%) scale(0.9); opacity: 0; pointer-events: none;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.4rem; display: flex; flex-direction: column; gap: 0.3rem; box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 9999; min-width: auto; width: max-content;
}
.email-menu.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) scale(1); }
.email-menu a {
    padding: 0.5rem 0.8rem; color: var(--text-main); font-size: 0.85rem; font-weight: 500;
    border-radius: 6px; transition: background 0.2s; display: block; text-align: center;
    background: var(--glass-bg);
}
.email-menu a:hover { background: rgba(249, 115, 22, 0.2); color: var(--primary); }

/* --- Skills & Tags --- */
.skills-container { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; justify-content: flex-start; }
.tag {
    padding: 0.4rem 1.2rem;
    background: rgba(249, 115, 22, 0.1);
    border: 1px solid rgba(249, 115, 22, 0.2);
    color: var(--primary);
    border-radius: 999px; font-size: 0.9rem; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
}

/* --- Enhanced CV Timeline --- */
.timeline { position: relative; padding-left: 2rem; margin-top: 2rem; }
.timeline::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
    background: linear-gradient(to bottom, var(--primary), var(--secondary));
    border-radius: 2px; opacity: 0.3;
}
.timeline-item { position: relative; margin-bottom: 2.5rem; }
.timeline-item::before {
    content: ''; position: absolute; left: -35px; top: 5px; width: 14px; height: 14px;
    border-radius: 50%; background: var(--bg-main); border: 3px solid var(--primary);
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.5); z-index: 1;
}
.timeline-date { font-size: 0.9rem; color: var(--secondary); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.5rem; display: inline-block; background: rgba(249, 115, 22, 0.1); padding: 0.2rem 0.8rem; border-radius: 4px; }

/* DOI Button */
.doi-btn {
    display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.4rem 0.8rem;
    background: rgba(249, 115, 22, 0.1); color: var(--primary);
    border: 1px solid var(--primary); border-radius: 8px;
    font-size: 0.8rem; font-weight: 600; text-decoration: none;
    transition: all 0.3s ease;
}
.doi-btn:hover { background: var(--primary); color: white; transform: translateY(-2px); box-shadow: 0 4px 10px rgba(249, 115, 22, 0.3); }

/* --- Abstract Accordion CSS --- */
.abstract-btn {
    background: var(--glass-bg); color: var(--text-main); border: 1px solid var(--border-color);
    padding: 0.4rem 0.8rem; border-radius: 8px; font-size: 0.8rem; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 0.4rem; transition: all 0.3s ease;
}
.abstract-btn svg { transition: transform 0.3s ease; }
.abstract-btn:hover { border-color: var(--primary); color: var(--primary); }
.abstract-btn.active svg { transform: rotate(180deg); }
.abstract-btn.active { border-color: var(--primary); color: var(--primary); }

/* CSS Grid Trick for Smooth Height Transitions */
.abstract-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease-in-out, margin-top 0.3s ease;
    margin-top: 0;
}
.abstract-wrapper.open {
    grid-template-rows: 1fr;
    margin-top: 1rem;
}
.abstract-inner {
    overflow: hidden;
    padding-left: 1rem;
    border-left: 3px solid var(--primary);
}
.abstract-inner p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.6;
    padding-bottom: 0.5rem;
}

/* --- Language Toggle CSS --- */
body.en .lang-it { display: none !important; }
body.it .lang-en { display: none !important; }

/* Perfectly Centered Footer */
footer { text-align: center; padding: 2rem; border-top: 1px solid var(--border-color); display: flex; justify-content: center; align-items: center; width: 100%; margin-top: 3rem; }

/* --- Mobile Adjustments --- */
@media (max-width: 768px) {
    .nav-container { 
        padding: 1rem; 
        flex-direction: column; /* Stacks the Logo above the menu */
        gap: 0.8rem;
    }
    .nav-container > div {
        display: flex;
        flex-wrap: nowrap; /* Forces links and controls to stay on one row */
        justify-content: center;
        align-items: center;
        width: 100%;
        margin-top: 0;
    }
    .nav-links { 
        width: auto; /* Removes the 100% width that pushed controls down */
        justify-content: center;
        gap: 0.8rem; /* Tighter gap to fit smaller phone screens */
        order: unset; /* Removes the re-ordering */
        margin-top: 0;
        font-size: 0.85rem; /* Slightly smaller text for long words like 'Pubblicazioni' */
    }
    .controls { 
        order: unset;
        /* Restores the separator for mobile */
        border-left: 1px solid var(--border-color); 
        padding-left: 0.8rem; 
        margin-left: 0.8rem; 
        gap: 0.5rem;
    }
    .icon-btn {
        width: 32px; /* Slightly smaller buttons to save horizontal space */
        height: 32px;
    }
    main { margin-top: 140px; }
    h1 { font-size: 2.5rem; }
}