/* ---------------------------------- */
/* --- 0. SETUP & CUSTOM PROPERTIES --- */
/* ---------------------------------- */
:root {
    /* --- Semantic Color Tokens --- */
    --bg: #0d0d1a;
    --fg: #e0e0e0;
    --accent: #00ff9d;
    --accent-alt: #ff00ff;
    --muted: #b0b0d0;
    --overlay-bg: rgba(13, 13, 26, 0.85);
    --border: rgba(0, 255, 157, 0.3);
    --shadow-main: rgba(0, 255, 157, 0.7);
    --shadow-accent: rgba(255, 0, 255, 0.7);
    --icon-color: var(--muted);
    --icon-hover-color: var(--accent);

    /* --- Fonts --- */
    --font-main: 'Consolas', 'Menlo', 'Monaco', 'Courier New', monospace;
    --font-display: 'Orbitron', 'Turret Road', var(--font-main);

    /* --- Fluid Typography Scale --- */
    --step--1: clamp(0.875rem, 0.8rem + 0.2vw, 0.95rem);
    --step-0:  clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --step-1:  clamp(1.125rem, 1rem + 0.6vw, 1.4rem);
    --step-2:  clamp(1.25rem, 1.1rem + 1vw, 1.75rem);
    --step-3:  clamp(1.8rem, 1.2rem + 3vw, 2.6rem);
    --step-4:  clamp(2.5rem, 1.5rem + 5vw, 4rem);
    --step-5:  clamp(3rem, 1.5rem + 7vw, 6rem);

    /* --- Spacing Scale --- */
    --space-1: 0.5rem;
    --space-2: 1rem;
    --space-3: 1.5rem;
    --space-4: 2rem;
    --space-5: 2.5rem;
    --space-6: 3rem;
}

[data-theme="light"] {
    --bg: #f0f0f5;
    --fg: #1a1a2e;
    --accent: #00804e;
    --accent-alt: #c400c4;
    --overlay-bg: rgba(240, 240, 245, 0.9);
    --border: rgba(0, 128, 78, 0.3);
    --shadow-main: rgba(0, 128, 78, 0.5);
    --shadow-accent: rgba(196, 0, 196, 0.5);
    --icon-color: #43436B;
    --icon-hover-color: var(--accent);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg);
    color: var(--fg);
    font-family: var(--font-main);
    font-size: var(--step-0);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1,
h2,
h3 {
    font-family: var(--font-display);
    font-weight: 400;
    text-shadow: 0 0 5px var(--shadow-main);
}

h1 {
    font-size: var(--step-4);
}

/* ---------------------------------- */
/* --- 1. HERO & GLITCH TITLE --- */
/* ---------------------------------- */

.hero {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    width: 100%;
    min-height: 100vh;
    background: transparent; /* Background is now handled by body/vignette */
    border: 1px solid var(--border);
    padding: 2rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1.5s ease, transform 1.5s ease;
}

body.loaded .hero {
    opacity: 1;
    transform: translateY(0);
    animation: neon-pulse 1.5s ease-out forwards;
}

/* Vignette and Scanlines from new example */
.fx-vignette::before, .fx-vignette::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -2; /* Behind canvas */
}

.fx-vignette::before {
    background: radial-gradient(120% 120% at 50% 50%, transparent 60%, rgba(0,0,0,.7) 100%);
    mix-blend-mode: multiply;
    opacity: .85;
}

.fx-vignette::after {
    background: linear-gradient(180deg, rgba(255,255,255,.06), transparent 15% 85%, rgba(255,255,255,.04));
    mix-blend-mode: overlay;
    opacity: .6;
}

.scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1; /* Above hero content but below modals/overlays */
    opacity: .08;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        rgba(255, 255, 255, .06) 1px,
        transparent 2px,
        transparent 3px
    );
    animation: slFade 4.5s ease-in-out infinite;
}

@keyframes slFade {
    0%, 100% { opacity: .06; }
    50% { opacity: .12; }
}


/* New Glitch Effect */
.stage {
    position: relative;
    width: 100%;
    max-width: 1200px;
    height: 300px; /* Fixed height */
    display: flex; /* Use flexbox for centering */
    justify-content: center; /* Center horizontally */
    align-items: center; /* Center vertically */
    padding: 2rem;
    filter: drop-shadow(0 8px 40px rgba(0,0,0,.45));
}

.glitch {
    position: relative;
    line-height: 1.1;
    letter-spacing: .02em;
    font-weight: 900;
    font-stretch: 110%;
    font-size: clamp(40px, 13vw, 180px);
    text-transform: uppercase;
    will-change: transform, filter;
    transform: perspective(1000px) rotateX(.5deg) skewX(-1deg);
    text-shadow: 0 0 20px var(--shadow-main);
    font-family: var(--font-display);
    text-align: center; /* Ensure text inside is centered if it wraps */
}

.glitch .layer {
    position: absolute;
    inset: 0;
    will-change: transform;
}

.glitch .base {
    position: relative;
    z-index: 3;
    color: var(--fg);
}

.glitch .r {
    z-index: 2;
    color: var(--accent-alt); /* Using theme variable */
    mix-blend-mode: screen;
    filter: blur(.5px);
    animation: jitterR 2.2s steps(24) infinite, slice 4s steps(20) infinite;
}

.glitch .b {
    z-index: 1;
    color: var(--accent); /* Using theme variable */
    mix-blend-mode: screen;
    filter: blur(.5px);
    animation: jitterB 2.6s steps(24) infinite, slice 3.3s steps(18) infinite;
}

.glitch .base {
    animation: shimmer 6s ease-in-out infinite;
}

.glitch.glitching {
    animation: burst 350ms steps(16) 1 both;
}

.glitch.glitching .r {
    animation-duration: 900ms, 1000ms;
}

.glitch.glitching .b {
    animation-duration: 900ms, 1000ms;
}

.glitch.glitching .base {
    filter: brightness(1.3) contrast(1.2) saturate(1.15);
}


/* Keyframes from new example */
@keyframes jitterR {
    0% { transform: translate(0,0); }
    10% { transform: translate(-1px, 0); }
    20% { transform: translate(-2px, 1px); }
    30% { transform: translate(1px, -1px); }
    40% { transform: translate(-1px, 1px); }
    50% { transform: translate(0,0); }
    60% { transform: translate(-2px, -1px); }
    70% { transform: translate(1px, 1px); }
    80% { transform: translate(-1px, 0); }
    90% { transform: translate(0,1px); }
    100% { transform: translate(0,0); }
}

@keyframes jitterB {
    0% { transform: translate(0,0); }
    10% { transform: translate(1px, 0); }
    20% { transform: translate(2px, -1px); }
    30% { transform: translate(-1px, 1px); }
    40% { transform: translate(1px, -1px); }
    50% { transform: translate(0,0); }
    60% { transform: translate(2px, 1px); }
    70% { transform: translate(-1px, -1px); }
    80% { transform: translate(1px, 0); }
    90% { transform: translate(0,-1px); }
    100% { transform: translate(0,0); }
}

@keyframes slice {
    0% { clip-path: inset(0 0 0 0); }
    10% { clip-path: inset(5% 0 60% 0); }
    20% { clip-path: inset(10% 0 20% 0); }
    30% { clip-path: inset(35% 0 40% 0); }
    40% { clip-path: inset(65% 0 15% 0); }
    50% { clip-path: inset(0 0 0 0); }
    60% { clip-path: inset(20% 0 50% 0); }
    70% { clip-path: inset(45% 0 25% 0); }
    80% { clip-path: inset(70% 0 10% 0); }
    90% { clip-path: inset(10% 0 70% 0); }
    100% { clip-path: inset(0 0 0 0); }
}

@keyframes shimmer {
    0%, 100% { filter: brightness(1) contrast(1); }
    50% { filter: brightness(1.05) contrast(1.08); }
}

@keyframes burst {
    0% {
        filter: drop-shadow(0 0 0 rgba(0,255,255,0.0)) drop-shadow(0 0 0 rgba(255,0,76,0.0));
        transform: scale(1) rotate(0deg);
    }
    50% {
        filter: drop-shadow(0 0 28px var(--shadow-main)) drop-shadow(0 0 28px var(--shadow-accent));
        transform: scale(1.01) rotate(.2deg);
    }
    100% {
        filter: drop-shadow(0 0 0 rgba(0,255,255,0.0)) drop-shadow(0 0 0 rgba(255,0,76,0.0));
        transform: scale(1) rotate(0);
    }
}

/* Keep the scroll indicator styles */

h3 {
    font-size: var(--step-3);
    margin-bottom: var(--space-3);
    color: var(--accent);
}

p {
    font-size: var(--step-0);
    max-width: 70ch;
}

a {
    color: var(--accent-alt);
    text-decoration: none;
}

        a:hover {
            text-decoration: underline;
        }

        /* Profile Picture */
        .profile-pic {
            width: 200px; /* Increased size */
            height: 200px; /* Increased size */
            border-radius: 50%;
            object-fit: cover;
            display: block;
            /* Margin handled by bio-content gap and media query */
            border: 2px solid var(--accent);
            box-shadow: 0 0 10px var(--shadow-main), 0 0 20px var(--shadow-accent);
            opacity: 0; /* Initially hidden */
            transition: opacity 3s ease-out; /* Only opacity transition for fade-in */
        }

        .profile-pic:hover {
            transform: scale(1.05);
            box-shadow: 0 0 15px var(--shadow-main), 0 0 30px var(--shadow-accent);
            transition: transform 0.3s ease, box-shadow 0.3s ease; /* Explicit hover transitions */
        }

        /* Bio Section Layout */
        #bio-section { /* Added min-height to the section itself */
            min-height: 600px; /* Prevent layout shift during typewriter effect */
        }

        .bio-content {
            display: flex;
            flex-direction: column; /* Stacked by default for mobile */
            align-items: center; /* Center items horizontally in column layout */
            gap: var(--space-3); /* Space between image and text */
            text-align: center; /* Center text for mobile */
        }

        @media (min-width: 768px) { /* Adjust breakpoint as needed */
            .bio-content {
                flex-direction: row; /* Side-by-side for desktop */
                align-items: flex-start; /* Align items to the top */
                text-align: left; /* Align text to the left */
            }

            .profile-pic {
                margin: 0 var(--space-4) 0 0; /* Space to the right of the image */
                flex-shrink: 0; /* Prevent image from shrinking */
            }

            #bio-text {
                flex-grow: 1; /* Allow text to take up remaining space */
            }
        }

        /* Layout & Background */
        #background-canvas {    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

body.fallback-mode {
    background: linear-gradient(-45deg, #0d0d1a, #1a0d1a, #0d1a1a, #1a1a0d);
    background-size: 400% 400%;
    animation: gradient-fallback 15s ease infinite;
}

@keyframes gradient-fallback {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-4);
    width: 100%;
}

/* Hero & Scroll Indicator */
.hero {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    width: 100%;
    min-height: 100vh;
    background: var(--overlay-bg);
    border: 1px solid var(--border);
    padding: var(--space-4);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1.5s ease, transform 1.5s ease;
}

body.loaded .hero {
    opacity: 1;
    transform: translateY(0);
    animation: neon-pulse 1.5s ease-out forwards;
}

@keyframes neon-pulse {
    0% {
        box-shadow: 0 0 5px var(--shadow-main), inset 0 0 5px var(--shadow-main);
    }

    50% {
        box-shadow: 0 0 20px var(--shadow-accent), inset 0 0 10px var(--shadow-accent);
    }

    100% {
        box-shadow: 0 0 10px var(--shadow-main), inset 0 0 5px var(--shadow-main);
    }
}

.hero h1 {
    color: var(--accent-alt);
    letter-spacing: 0.2em;
}

#glitch-morph-title {
    color: var(--accent);
    position: relative;
}

#glitch-morph-title-container {
    position: relative;
    text-align: center;
}

@keyframes glitch-anim-1 {
    0% { clip-path: inset(29px 0 69px 0); }
    10% { clip-path: inset(42px 0 55px 0); }
    20% { clip-path: inset(7px 0 85px 0); }
    30% { clip-path: inset(48px 0 50px 0); }
    40% { clip-path: inset(37px 0 58px 0); }
    50% { clip-path: inset(55px 0 38px 0); }
    60% { clip-path: inset(40px 0 59px 0); }
    70% { clip-path: inset(18px 0 78px 0); }
    80% { clip-path: inset(50px 0 46px 0); }
    90% { clip-path: inset(72px 0 23px 0); }
    100% { clip-path: inset(33px 0 65px 0); }
}

@keyframes glitch-anim-2 {
    0% { clip-path: inset(85px 0 10px 0); }
    10% { clip-path: inset(55px 0 35px 0); }
    20% { clip-path: inset(90px 0 5px 0); }
    30% { clip-path: inset(30px 0 60px 0); }
    40% { clip-path: inset(10px 0 80px 0); }
    50% { clip-path: inset(75px 0 20px 0); }
    60% { clip-path: inset(45px 0 50px 0); }
    70% { clip-path: inset(80px 0 15px 0); }
    80% { clip-path: inset(25px 0 70px 0); }
    90% { clip-path: inset(65px 0 25px 0); }
    100% { clip-path: inset(95px 0 2px 0); }
}

.glitch-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.glitch-layer:nth-child(1) {
    color: var(--accent-alt);
    animation: glitch-anim-1 2s infinite linear alternate;
}

.glitch-layer:nth-child(2) {
    color: var(--accent);
    animation: glitch-anim-2 1.5s infinite linear alternate;
}

.glitch-layer:nth-child(3) {
    color: var(--bg);
    opacity: 0.7;
}

#glitch-morph-title.morphed .glitch-layer {
    display: none;
}

#glitch-morph-title.morphed {
    font-size: 2.5rem;
    line-height: 1.2;
}


.scroll-down-indicator {
    position: absolute;
    bottom: var(--space-4);
    left: 50%;
    opacity: 1;
    transition: opacity 0.5s ease;
    animation: bounce 2s infinite cubic-bezier(0.5, 0.05, 0.55, 0.95);
}

.scroll-down-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

.scroll-down-indicator svg {
    width: 48px;
    height: 48px;
    stroke: var(--accent);
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translate(-50%, 0);
    }

    40% {
        transform: translate(-50%, -20px);
    }

    60% {
        transform: translate(-50%, -10px);
    }
}

/* Content Sections */
.content-section {
    width: 100%;
    max-width: 1200px;
    margin: var(--space-6) auto;
    padding: var(--space-4);
    background: var(--overlay-bg);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

#bio-text::after {
    content: '_';
    animation: blink 0.7s infinite;
    color: var(--accent);
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

#bio-text.typing-done::after {
    display: none;
}

/* Skills Accordion */
.skills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.skill-item {
    border: 1px solid var(--border);
    padding: var(--space-3);
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.skill-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.skill-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.skill-header svg {
    width: 48px;
    height: 48px;
    fill: var(--icon-color);
}

.skill-item.active .skill-header svg {
    fill: var(--icon-hover-color);
    filter: drop-shadow(0 0 8px var(--shadow-main));
}

.skill-header p {
    font-size: var(--step-1);
    font-weight: bold;
}

.skill-details {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.5s ease, margin-top 0.5s ease;
}

.skill-item.active .skill-details {
    max-height: 250px;
    opacity: 1;
    margin-top: var(--space-2);
}

.skill-details ul {
    list-style: none;
    padding-left: var(--space-2);
}

.skill-details li {
    position: relative;
    padding-left: 1.5em;
    margin-bottom: 0.5em;
    font-size: var(--step--1);
}

.skill-details li::before {
    content: '>';
    position: absolute;
    left: 0;
    color: var(--accent-alt);
}

/* Languages Section */
.languages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.language-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.language-item svg {
    width: 40px;
    height: auto;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.language-details {
    width: 100%;
}

.language-details p {
    margin: 0 0 0.25rem 0;
    font-weight: bold;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 5px;
}

.progress-bar {
    width: 0;
    height: 100%;
    background-color: var(--accent);
    border-radius: 5px;
    transition: width 1.5s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Projects Section */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.project-item {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    padding: var(--space-3);
    transition: all 0.3s ease;
}

.project-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    transform: translateY(-5px);
}

.project-item h4 {
    color: var(--accent-alt);
    font-size: var(--step-1);
    margin-bottom: var(--space-1);
}

.project-item p {
    font-size: var(--step--1);
    opacity: 0.8;
    flex-grow: 1;
}

.project-link {
    margin-top: var(--space-2);
    align-self: flex-end;
}

/* MODIFICATO */
.project-link svg {
    width: 24px;
    height: 24px;
    fill: var(--icon-color);
    transition: all 0.3s ease;
}

        .project-link:hover svg {
            fill: var(--accent-alt);
            transform: scale(1.1);
        }

        /* Experience Section */
        .experience-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: var(--space-3);
            margin-top: var(--space-4);
        }

        .experience-item {
            border: 1px solid var(--border);
            padding: var(--space-3);
            transition: all 0.3s ease;
        }

        .experience-item:hover {
            background-color: rgba(255, 255, 255, 0.05);
            transform: translateY(-5px);
        }

        .experience-item h4 {
            color: var(--accent-alt);
            font-size: var(--step-1);
            margin-bottom: var(--space-1);
        }

        .experience-item p {
            font-size: var(--step--1);
            opacity: 0.8;
        }

        .experience-date {
            font-size: var(--step--1);
            color: var(--accent);
            opacity: 0.7;
            float: right; /* To align dates to the right */
        }

        /* Contacts & Footer */.contact-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-4);
}

.social-links {
    display: flex;
    gap: var(--space-3);
}

.social-links a svg {
    width: 40px;
    height: 40px;
    fill: var(--icon-color);
    transition: all 0.3s ease;
}

.social-links a:hover svg {
    fill: var(--accent-alt);
    transform: scale(1.2);
    filter: drop-shadow(0 0 5px var(--shadow-accent));
}

footer {
    margin-top: var(--space-6);
    text-align: center;
    font-size: var(--step--1);
    opacity: 0.7;
}

footer a {
    color: var(--fg);
}

/* Utility Overlay & Theme Toggle */
.hidden {
    display: none !important;
}

.utility-overlay {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: 100;
    display: flex;
    gap: var(--space-2);
}

.utility-btn {
    background: var(--overlay-bg);
    border: 1px solid var(--border);
    padding: var(--space-2);
    cursor: pointer;
    color: var(--fg);
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.utility-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--accent);
}

[data-theme="dark"] #icon-sun {
    display: none;
}

[data-theme='light'] #icon-moon {
    display: none;
}

/* CV Download Button */
.cv-download-btn {
    display: inline-block;
    margin-top: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--accent);
    color: var(--accent);
    text-decoration: none;
    font-family: var(--font-display);
    transition: all 0.3s ease;
    box-shadow: 0 0 5px var(--shadow-main);
}

.cv-download-btn:hover {
    background-color: var(--accent);
    color: var(--bg);
    box-shadow: 0 0 15px var(--shadow-main), 0 0 25px var(--shadow-main);
    text-decoration: none;
}

@media (max-width: 480px) {
    .hero {
        padding-left: var(--space-2);
        padding-right: var(--space-2);
    }

    .stage {
        padding: 3vmin 0;
    }

    .skills-grid,
    .projects-grid,
    .experience-grid {
        grid-template-columns: 1fr; /* Stack everything in a single column */
    }

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

    h1 {
        font-size: var(--step-3); /* Reduce heading size on mobile */
    }

    .glitch {
        font-size: clamp(32px, 12vw, 100px); /* Reduce glitch title size */
    }
}