/* VARIABILI GLOBALI */
:root {
    --bg: #ffffff;
    --bg-alt: #f5f5f5;
    --surface: #ffffff;
    --text: #111111;
    --muted: #5c5c5c;
    --border: #e4e4e4;
    --accent: #111111;
    --accent-text: #ffffff;
    --contact-bg: #111111;
    --contact-text: #ffffff;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.14);
    --radius: 8px;
    --dur: 200ms;
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f0f10;
        --bg-alt: #161618;
        --surface: #1c1c1f;
        --text: #f2f2f2;
        --muted: #a3a3a8;
        --border: #2c2c30;
        --accent: #f2f2f2;
        --accent-text: #0f0f10;
        --contact-bg: #1c1c1f;
        --contact-text: #f2f2f2;
        --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
        --shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.5);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0f0f10;
    --bg-alt: #161618;
    --surface: #1c1c1f;
    --text: #f2f2f2;
    --muted: #a3a3a8;
    --border: #2c2c30;
    --accent: #f2f2f2;
    --accent-text: #0f0f10;
    --contact-bg: #1c1c1f;
    --contact-text: #f2f2f2;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
    --shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 72px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

a { color: inherit; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    left: 16px;
    top: -48px;
    background: var(--accent);
    color: var(--accent-text);
    padding: 8px 16px;
    border-radius: 4px;
    z-index: 200;
}

.skip-link:focus { top: 8px; }

/* CONTAINER */
.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 16px;
}

.container.narrow { max-width: 680px; }

/* NAVBAR */
.navbar {
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 64px;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    text-decoration: none;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 32px;
}

.nav-links a {
    text-decoration: none;
    color: var(--muted);
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
    border-bottom-color: var(--text);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: background var(--dur) var(--ease);
}

.icon-btn:hover { background: var(--bg-alt); }

.icon-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-sun { display: none; }
    :root:not([data-theme="light"]) .icon-moon { display: block; }
}

.menu-toggle {
    display: none;
    gap: 4px;
    align-content: center;
}

.menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: currentColor;
    transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* HERO */
.hero {
    padding: 112px 0 96px;
    text-align: center;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-alt) 100%);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 16px;
}

.hero h1 {
    font-size: clamp(2.25rem, 6vw, 3.5rem);
    line-height: 1.15;
    margin-bottom: 16px;
}

.hero-sub {
    font-size: clamp(1.05rem, 2.4vw, 1.3rem);
    color: var(--muted);
    margin-bottom: 32px;
    min-height: 1.6em;
}

.caret {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: currentColor;
    margin-left: 2px;
    vertical-align: -0.15em;
    animation: blink 1s steps(1) infinite;
}

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

.hero-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

/* BOTTONI */
.cta-btn,
.ghost-btn,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 24px;
    border-radius: 4px;
    font: inherit;
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}

.cta-btn {
    background: var(--accent);
    color: var(--accent-text);
    border: 1px solid var(--accent);
}

.cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.cta-btn.light {
    background: var(--contact-text);
    color: var(--contact-bg);
    border-color: var(--contact-text);
}

.ghost-btn {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.ghost-btn:hover { background: var(--bg-alt); }

.btn {
    min-height: 40px;
    padding: 0 16px;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    font-size: 0.95rem;
}

.btn:hover { opacity: 0.85; }

/* SEZIONI */
.section { padding: 80px 0; }
.section.alt { background: var(--bg-alt); }

.section h2 {
    text-align: center;
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    margin-bottom: 32px;
}

.lead {
    font-size: 1.1rem;
    color: var(--muted);
    text-align: center;
}

/* ABOUT */
.facts {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 40px;
}

.facts li {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.facts strong {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
}

/* PROGETTI */
.search-wrap {
    max-width: 360px;
    margin: 0 auto 40px;
}

.search-wrap label,
.field label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
}

input,
textarea {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    min-height: 44px;
}

textarea { resize: vertical; }

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
    gap: 24px;
}

.project-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.project-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.project-num {
    font-size: 0.8rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    margin-bottom: 8px;
}

.project-card h3 { margin-bottom: 8px; }

.project-card p {
    color: var(--muted);
    margin-bottom: 24px;
    flex: 1;
}

.empty {
    text-align: center;
    color: var(--muted);
    display: grid;
    gap: 16px;
    justify-items: center;
}

.empty[hidden] { display: none; }

/* DIALOG */
.project-dialog {
    margin: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    width: min(520px, calc(100% - 32px));
    box-shadow: var(--shadow-hover);
}

.project-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.project-dialog[open] { animation: pop var(--dur) var(--ease); }

@keyframes pop {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.dialog-inner {
    position: relative;
    padding: 32px;
}

.dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 1.4rem;
    line-height: 1;
}

.dialog-inner h3 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    padding-right: 40px;
}

.dialog-inner p {
    color: var(--muted);
    margin-bottom: 24px;
}

.dialog-links {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.dialog-note {
    font-size: 0.9rem;
    color: var(--muted);
}

/* COMPETENZE */
.skills {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.skill {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.95rem;
}

/* CONTATTI */
.contact {
    background: var(--contact-bg);
    color: var(--contact-text);
}

.contact .lead { color: inherit; opacity: 0.8; margin-bottom: 32px; }

.contact-form {
    display: grid;
    gap: 16px;
    text-align: left;
}

.contact-form input,
.contact-form textarea {
    background: rgba(255, 255, 255, 0.06);
    color: var(--contact-text);
    border-color: rgba(255, 255, 255, 0.2);
}

.contact-form [aria-invalid="true"] { border-color: #ff8a8a; }

.contact-form .cta-btn { justify-self: start; }

.error {
    color: #ff9d9d;
    font-size: 0.9rem;
    margin-top: 6px;
}

.alt-contact {
    margin-top: 16px;
    opacity: 0.85;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.copy-btn {
    font: inherit;
    font-size: 0.85rem;
    background: transparent;
    color: inherit;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 4px 10px;
    min-height: 32px;
    cursor: pointer;
}

/* FOOTER */
footer {
    background: #0a0a0a;
    color: #e6e6e6;
    text-align: center;
    padding: 32px 16px;
    font-size: 0.9rem;
}

/* TOAST */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 16px);
    background: var(--accent);
    color: var(--accent-text);
    padding: 10px 16px;
    border-radius: var(--radius);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
    z-index: 300;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* REVEAL ALLO SCROLL */
.js .reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 500ms var(--ease), transform 500ms var(--ease);
}

.js .reveal.visible {
    opacity: 1;
    transform: none;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .menu-toggle { display: inline-grid; }

    .nav-menu {
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        display: none;
    }

    .nav-menu.open { display: block; }

    .nav-links {
        flex-direction: column;
        gap: 0;
        padding: 8px 16px 16px;
    }

    .nav-links a {
        display: block;
        padding: 12px 0;
        border-bottom: 1px solid var(--border);
    }

    .nav-links a.active { border-bottom-color: var(--border); font-weight: 600; }

    .hero { padding: 72px 0 64px; }
    .section { padding: 56px 0; }
    .project-card { padding: 24px; }
    .facts { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .js .reveal { opacity: 1; transform: none; }
}
