/* Il sito passa lentamente tra 5 palette (verde → blu → viola → rosso → arancio)
   e tutti i colori cambiano insieme. Ogni palette resta ferma per metà del suo
   tempo e sfuma nella successiva nell'altra metà.
   Il punto di partenza casuale lo imposta lo script in header.php. */
@property --bg           { syntax: '<color>'; inherits: true; initial-value: #0b0d12; }
@property --surface      { syntax: '<color>'; inherits: true; initial-value: #12161f; }
@property --surface-2    { syntax: '<color>'; inherits: true; initial-value: #181d29; }
@property --border       { syntax: '<color>'; inherits: true; initial-value: #232a3a; }
@property --text         { syntax: '<color>'; inherits: true; initial-value: #e6e9f0; }
@property --muted        { syntax: '<color>'; inherits: true; initial-value: #8d95a8; }
@property --accent       { syntax: '<color>'; inherits: true; initial-value: #4ade80; }
@property --accent-2     { syntax: '<color>'; inherits: true; initial-value: #22d3ee; }
@property --accent-hover { syntax: '<color>'; inherits: true; initial-value: #6ee7a0; }
@property --on-accent    { syntax: '<color>'; inherits: true; initial-value: #06210f; }
@property --syntax       { syntax: '<color>'; inherits: true; initial-value: #c084fc; }

@keyframes palette-cycle {
    0%, 10%, 100% { /* verde */
        --bg: #0b0d12; --surface: #12161f; --surface-2: #181d29; --border: #232a3a;
        --text: #e6e9f0; --muted: #8d95a8;
        --accent: #4ade80; --accent-2: #22d3ee; --accent-hover: #6ee7a0; --on-accent: #06210f; --syntax: #c084fc;
    }
    20%, 30% { /* blu */
        --bg: #0a0e17; --surface: #111827; --surface-2: #172033; --border: #233047;
        --text: #e6edf7; --muted: #8b9ab3;
        --accent: #60a5fa; --accent-2: #2dd4bf; --accent-hover: #93c5fd; --on-accent: #0a1a33; --syntax: #c084fc;
    }
    40%, 50% { /* viola */
        --bg: #0c0a14; --surface: #15121f; --surface-2: #1c1829; --border: #2a2440;
        --text: #ece9f5; --muted: #9a93ae;
        --accent: #a78bfa; --accent-2: #f472b6; --accent-hover: #c4b5fd; --on-accent: #1a0f3a; --syntax: #f9a8d4;
    }
    60%, 70% { /* rosso */
        --bg: #0c0a0b; --surface: #161214; --surface-2: #1e181b; --border: #2d2428;
        --text: #f0e9eb; --muted: #a3959c;
        --accent: #f43f5e; --accent-2: #fb923c; --accent-hover: #fb7185; --on-accent: #1f0509; --syntax: #fbbf24;
    }
    80%, 90% { /* arancio */
        --bg: #0d0b0a; --surface: #171311; --surface-2: #1f1a17; --border: #2e2620;
        --text: #f2ece6; --muted: #a39a90;
        --accent: #fb923c; --accent-2: #facc15; --accent-hover: #fdba74; --on-accent: #2a1203; --syntax: #f87171;
    }
}

:root {
    --theme-cycle: 80s; /* durata di un giro completo delle 5 palette */
    /* steps(): pochi aggiornamenti al secondo, la sfumatura resta fluida ma il browser lavora meno */
    animation: palette-cycle var(--theme-cycle) steps(40) infinite;
    animation-delay: var(--theme-delay, 0s);

    --bg: #0b0d12;
    --surface: #12161f;
    --surface-2: #181d29;
    --border: #232a3a;
    --text: #e6e9f0;
    --muted: #8d95a8;
    --accent: #4ade80;
    --accent-2: #22d3ee;
    --accent-hover: #6ee7a0;
    --on-accent: #06210f;
    --syntax: #c084fc;
    --danger: #f87171;
    --radius: 12px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    --container: 1100px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

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

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -0.02em; }

.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 20px;
}

.accent { color: var(--accent); }
.prompt { color: var(--accent); font-family: var(--mono); }

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

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

.logo {
    font-family: var(--mono);
    font-weight: 500;
    color: var(--text);
    font-size: 1.05rem;
}
.logo:hover { text-decoration: none; }
.logo-prompt { color: var(--muted); }
.logo-accent { color: var(--accent); }

.site-nav { display: flex; gap: 28px; }
.site-nav a {
    color: var(--muted);
    font-size: .95rem;
    font-weight: 500;
    position: relative;
}
.site-nav a:hover, .site-nav a.active { color: var(--text); text-decoration: none; }
.site-nav a.active::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -6px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

.nav-toggle {
    display: none;
    background: none;
    border: 0;
    padding: 8px;
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    margin: 5px 0;
    background: var(--text);
    transition: transform .2s, opacity .2s;
}
.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Hero */
.hero {
    padding: 120px 0 100px;
    background:
        radial-gradient(600px 300px at 15% 10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%),
        radial-gradient(500px 300px at 85% 40%, color-mix(in srgb, var(--accent-2) 8%, transparent), transparent 70%);
}
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); font-weight: 700; }
.hero-role {
    font-family: var(--mono);
    color: var(--accent-2);
    margin: 0 0 1rem;
    min-height: 1.7em; /* niente salti mentre le frasi si scrivono e cancellano */
}

.caret {
    display: inline-block;
    width: .55em;
    height: 1.15em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--accent);
    animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.hero-tagline { color: var(--muted); max-width: 620px; font-size: 1.15rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 2rem; }

.eyebrow {
    font-family: var(--mono);
    color: var(--muted);
    font-size: .95rem;
    margin: 0 0 1rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 12px 22px;
    border-radius: 8px;
    font-weight: 600;
    font-size: .95rem;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: transform .15s, background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); }

/* Sections */
.section { padding: 70px 0; }
.section-title { font-size: 1.6rem; margin-bottom: 1.5rem; }
.section-title .prompt { font-size: 1.1rem; margin-right: 6px; }

.page-header { padding: 90px 0 30px; }
.page-header h1 { font-size: clamp(2.2rem, 5vw, 3.2rem); }
.lead { color: var(--muted); font-size: 1.15rem; max-width: 620px; }

.about {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 48px;
    align-items: center;
}
.about p { color: var(--muted); }

/* Terminal */
.terminal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.terminal-bar {
    position: relative;
    display: flex;
    gap: 7px;
    padding: 12px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.terminal-bar span { width: 11px; height: 11px; border-radius: 50%; }
.terminal-bar span:nth-child(1) { background: var(--accent); }
.terminal-bar span:nth-child(2) { background: var(--accent-2); }
.terminal-bar span:nth-child(3) { background: var(--muted); }
.terminal-title {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: .78rem;
    color: var(--muted);
    pointer-events: none;
}
.terminal-body {
    height: 320px;
    overflow-y: auto;
    padding: 18px 20px;
    font-family: var(--mono);
    font-size: .88rem;
    line-height: 1.7;
    color: var(--text);
    cursor: text;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.terminal pre {
    margin: 0 0 .6em;
    font: inherit;
    overflow-x: auto;
}
.terminal-output p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.terminal-output a { color: var(--accent-2); }
.terminal-line { display: flex; align-items: center; gap: .6em; }
.terminal-line input {
    flex: 1;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: 0;
    outline: none;
    color: var(--text);
    font: inherit;
    caret-color: var(--accent);
}
.t-key { color: var(--syntax); }
.t-str { color: var(--accent); }
.t-cmd { color: var(--accent); }
.t-muted { color: var(--muted); }

/* Elementi che servono solo con JavaScript attivo */
html:not(.js) .js-only { display: none; }

/* Skills */
.skills {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.skills li {
    font-family: var(--mono);
    font-size: .9rem;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
}

/* Cards */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}
/* In home i progetti in evidenza stanno 2 per riga: con 4 progetti niente card isolata */
.grid-featured { grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); }
.card {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
    display: flex;
    flex-direction: column;
    transition: border-color .2s, transform .2s;
}
.card:hover { border-color: var(--accent); transform: translateY(-3px); }
/* Riflettore: la posizione (--mx, --my) la aggiorna main.js */
.card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(320px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%);
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
}
.card:hover::before { opacity: 1; }
.card > * { position: relative; }
.card h3 { font-size: 1.25rem; }
.card p { color: var(--muted); flex: 1; }
.tags {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tags li {
    font-family: var(--mono);
    font-size: .78rem;
    color: var(--accent-2);
    background: color-mix(in srgb, var(--accent-2) 8%, transparent);
    padding: 3px 10px;
    border-radius: 6px;
}
.card-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.card-link { font-weight: 600; font-size: .95rem; }
.card-link-secondary { color: var(--muted); font-weight: 500; }
.card-link-secondary:hover { color: var(--accent); }
.more { margin-top: 1.5rem; font-weight: 600; }

/* CTA */
.cta { text-align: center; }
.cta .container {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 8%, transparent), color-mix(in srgb, var(--accent-2) 6%, transparent));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 56px 20px;
    max-width: calc(var(--container) - 40px);
}
.cta p { color: var(--muted); margin-bottom: 1.5rem; }

/* Contatti */
.contact-form form,
.contact-form .alert { max-width: 720px; }
.page-header .socials { margin-top: 1rem; }

.contact-form form { display: flex; flex-direction: column; }
.contact-form label { font-size: .9rem; font-weight: 500; margin-bottom: 6px; }
.contact-form input,
.contact-form textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    padding: 12px 14px;
    margin-bottom: 18px;
    transition: border-color .15s;
}
.contact-form input:focus,
.contact-form textarea:focus { outline: none; border-color: var(--accent); }
.contact-form textarea { resize: vertical; }
.contact-form .btn { align-self: flex-start; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.alert {
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid;
}
.alert ul { margin: 0; padding-left: 18px; }
.alert-success { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.alert-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }

.socials { list-style: none; padding: 0; margin: 0; display: flex; gap: 18px; }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 28px 0;
    color: var(--muted);
    font-size: .9rem;
}
.footer-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: space-between;
    align-items: center;
}
.footer-inner p { margin: 0; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

.not-found { padding-bottom: 90px; }
.not-found h1 { font-size: 6rem; color: var(--accent); font-family: var(--mono); }

/* Mobile */
/* Sfondo animato (lo crea main.js) */
.bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

/* Transizioni tra le pagine (Chrome, Edge, Safari 18+; gli altri browser cambiano pagina normalmente) */
@view-transition { navigation: auto; }
.site-header { view-transition-name: header; }
main { view-transition-name: page; }
::view-transition-old(page) { animation: page-out .2s ease-in both; }
::view-transition-new(page) { animation: page-in .35s ease-out both; }
@keyframes page-out { to { opacity: 0; transform: translateY(-10px); } }
@keyframes page-in { from { opacity: 0; transform: translateY(14px); } }

@media (max-width: 760px) {
    body { font-size: 16px; }
    .terminal-body { height: 300px; }
    .terminal-line input { font-size: 16px; } /* sotto i 16px iOS fa lo zoom sul campo */

    .nav-toggle { display: block; }
    .site-nav {
        position: absolute;
        top: 64px; left: 0; right: 0;
        flex-direction: column;
        gap: 0;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        display: none;
    }
    .nav-open .site-nav { display: flex; }
    .site-nav a { padding: 14px 20px; border-top: 1px solid var(--border); }
    .site-nav a.active::after { display: none; }
    .site-nav a.active { color: var(--accent); }

    .hero { padding: 80px 0 60px; }
    .section { padding: 50px 0; }
    .page-header { padding: 60px 0 10px; }
    .about { grid-template-columns: 1fr; gap: 32px; }
    .terminal pre { white-space: pre-wrap; overflow-wrap: anywhere; }
    .grid { grid-template-columns: 1fr; }
    .cta .container { margin: 0 16px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
    :root { animation-play-state: paused; }
    * { transition: none !important; scroll-behavior: auto !important; }
    .caret { animation: none; }
    @view-transition { navigation: none; }
}
