/* Animazioni. Quelle automatiche partono solo con html.anim
   (non messa se il sistema chiede di ridurre il movimento). */

main, footer { overflow-x: clip; }

/* barra in alto: avanzamento e ombra */
.nav { transition: box-shadow .3s; }
.nav.scrolled { box-shadow: 0 10px 30px -12px #2b2f7a40; }
.nav-inner { transition: height .25s; }
.progress { position: absolute; left: 0; bottom: -2px; width: 100%; height: 3px; transform-origin: 0 50%; transform: scaleX(var(--scroll, 0)); background: var(--rainbow); }
.nav nav a { transition: color .2s, translate .2s, border-color .2s; }
.nav nav a:hover { translate: 0 -2px; }
.logo::after { content: "_"; color: var(--violet); animation: blink 1s steps(1) infinite; }

/* sfondo dell'apertura: aurora, codice, torcia che segue il mouse */
.hero::before { content: ""; position: absolute; inset: -20%; z-index: -2; pointer-events: none; background: radial-gradient(circle at 26% 30%, #2f6bff40, transparent 30%), radial-gradient(circle at 74% 34%, #ff3d8b38, transparent 28%), radial-gradient(circle at 56% 74%, #ff9f1c33, transparent 28%), radial-gradient(circle at 20% 72%, #00c2b233, transparent 26%); }
.anim .hero::before { animation: aurora 11s ease-in-out infinite alternate; }
.bg-code { position: absolute; inset: 0; z-index: -1; overflow: hidden; padding: 28px max(20px, (100vw - 1080px) / 2); font: 13px/22px var(--mono); color: #14153817; pointer-events: none; user-select: none; -webkit-mask-image: radial-gradient(ellipse 90% 80% at 50% 10%, #000 20%, transparent 80%); mask-image: radial-gradient(ellipse 90% 80% at 50% 10%, #000 20%, transparent 80%); }
.bg-code .k { color: #8228f038; }
.bg-code .s { color: #00857a38; }
.bg-code.hot { color: #14153880; -webkit-mask-image: radial-gradient(circle 190px at var(--hx, -999px) var(--hy, -999px), #000, transparent 75%); mask-image: radial-gradient(circle 190px at var(--hx, -999px) var(--hy, -999px), #000, transparent 75%); }
.bg-code.hot .k { color: var(--violet); }
.bg-code.hot .s { color: var(--teal); }
.anim .bg-code .typing::after { content: "▍"; color: var(--pink); animation: blink 1s steps(1) infinite; }

/* rombi che galleggiano */
.shard { position: absolute; left: var(--x); top: var(--y); width: var(--s); height: calc(var(--s) * 1.9); z-index: -1; clip-path: polygon(50% 0, 100% 34%, 50% 100%, 0 34%); background: linear-gradient(135deg, #fff, var(--c) 55%, color-mix(in srgb, var(--c) 70%, #4b1fa8)); opacity: .85; pointer-events: none; animation: float var(--t) ease-in-out var(--delay) infinite; }
#particles { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; opacity: calc(1 - var(--fade, 0) * .55); }

/* entrata dell'apertura e dissolvenza scorrendo */
.anim .hero-inner { opacity: calc(1 - var(--p, 0) * .85); translate: 0 calc(var(--p, 0) * 70px); }
.anim .hero-text > *, .anim .hero-side > * { animation: rise .8s cubic-bezier(.2, .8, .2, 1) both; }
.anim .hero-text > :nth-child(2) { animation: pop 1s cubic-bezier(.2, .9, .25, 1.25) .15s both, rainbow 6s linear infinite; }
.anim .hero-text > :nth-child(3) { animation-delay: .35s; }
.anim .hero-text > :nth-child(4) { animation-delay: .5s; }
.anim .hero-text > :nth-child(5) { animation-delay: .65s; }
.anim .hero-side > :nth-child(1) { animation-delay: .4s; }
.anim .hero-side > :nth-child(2) { animation-delay: .75s; }
.anim h1 .dot { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.anim .contact .big { animation: rainbow 6s linear infinite; }
.anim .badge i { animation: pulse 1.8s ease-out infinite; }
.scroll-hint { position: absolute; left: 50%; bottom: 18px; width: 16px; height: 16px; margin-left: -8px; border: solid var(--violet); border-width: 0 3px 3px 0; rotate: 45deg; opacity: calc(1 - var(--p, 0) * 3); animation: hint 1.6s ease-in-out infinite; }

/* finché c'è il benvenuto l'entrata aspetta */
.anim.waiting .hero-text > *, .anim.waiting .hero-side > * { animation-play-state: paused; }
.anim .welcome[open] { animation: pop .6s cubic-bezier(.2, .9, .25, 1.25) both; }

/* terminale in 3D con linea di scansione */
.terminal { position: relative; box-shadow: 0 30px 70px -30px #3b2fb066, 0 0 50px -18px #ff3d8b66; transform: perspective(1200px) rotateX(var(--rx, 2deg)) rotateY(var(--ry, -5deg)); transition: transform .25s ease-out; }
.anim .terminal::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: linear-gradient(90deg, transparent, #8b3dff, #ff3d8b, transparent) no-repeat; background-size: 40% 100%; animation: scan 3.6s linear infinite; }
.terminal-body .cmd.typing::after { content: "▍"; color: var(--pink); }

/* striscia tecnologie */
.marquee:hover .track { animation-play-state: paused; }

/* pulsanti con riflesso */
.btn { position: relative; overflow: hidden; }
.btn::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; background: linear-gradient(100deg, transparent, #ffffff80, transparent); transform: skewX(-20deg); transition: left .55s ease; pointer-events: none; }
.btn:hover::after { left: 125%; }
.anim .btn-main { animation: glow 2.4s ease-in-out infinite; }

/* comparsa allo scorrimento, in entrata e in uscita */
.anim [data-reveal] { opacity: 0; translate: 0 48px; scale: .97; transition: opacity .6s ease, translate .7s cubic-bezier(.2, .8, .2, 1), scale .7s cubic-bezier(.2, .8, .2, 1), transform .15s ease-out, border-color .3s, box-shadow .3s; transition-delay: var(--d, 0s), var(--d, 0s), var(--d, 0s), 0s, 0s, 0s; }
.anim [data-reveal].above { translate: 0 -48px; }
.anim [data-reveal="left"] { translate: -80px 0; }
.anim [data-reveal="right"] { translate: 80px 0; }
.anim [data-reveal="zoom"] { translate: 0 24px; scale: .82; }
.anim [data-reveal="zoom"].above { translate: 0 -24px; }
.anim [data-reveal].in { opacity: 1; translate: 0 0; scale: 1; }
.anim h2[data-reveal]::after { transform-origin: left; scale: 0 1; transition: scale .9s ease .3s; }
.anim h2[data-reveal].in::after { scale: 1 1; }

/* righe ed etichette una dopo l'altra */
.anim .project li, .anim .card .tags span, .anim .profile li { opacity: 0; translate: -20px 0; transition: opacity .45s ease, translate .45s ease; transition-delay: calc(var(--i, 0) * .09s + .35s); }
.anim .card .tags span { translate: 0 14px; }
.anim [data-reveal].in li, .anim [data-reveal].in .tags span { opacity: 1; translate: 0 0; }

/* schede che si inclinano e si illuminano */
.tilt { position: relative; }
/* la trasformazione 3D solo al passaggio del mouse: da ferma sfocherebbe il testo */
.tilt:hover { transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); }
.tilt::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%); opacity: 0; transition: opacity .25s; pointer-events: none; }
.tilt:hover::before { opacity: 1; }
.tilt:hover { border-color: var(--accent); box-shadow: 0 18px 40px -14px color-mix(in srgb, var(--accent) 55%, transparent); }

.anim .avatar { animation: bob 4.5s ease-in-out infinite, halo 4s ease-in-out infinite; }

@keyframes aurora { to { transform: translate(6%, 4%) scale(1.12); } }
@keyframes rainbow { to { background-position: 200% 0; } }
@keyframes float { 50% { translate: 0 -26px; rotate: 14deg; } }
@keyframes rise { from { opacity: 0; translate: 0 28px; } }
@keyframes pop { from { opacity: 0; scale: .7; translate: 0 30px; } }
@keyframes bob { 50% { translate: 0 -8px; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #12b76a99; } 100% { box-shadow: 0 0 0 10px #12b76a00; } }
@keyframes hint { 50% { translate: 0 8px; } }
@keyframes scan { from { background-position: -60% 0; } to { background-position: 160% 0; } }
@keyframes glow { 50% { box-shadow: 0 6px 30px #8b3dff99; } }
@keyframes halo { 50% { box-shadow: 0 0 22px #8b3dff77; } }

/* sul telefono il testo copre tutto lo sfondo: il codice resta appena accennato */
@media (max-width: 820px) {
  .bg-code { opacity: .45; }
}

@media (prefers-reduced-motion: reduce) {
  .shard, .scroll-hint, .logo::after { animation: none; }
}
