:root {
    --bg: #060a14;
    --accent: #3a5cff;
    --accent-glow: rgba(58, 92, 255, 0.35);
    --white: #f5f5f7;
    --muted: #8993b0;
    --font-display: "Space Grotesk", sans-serif;
    --font-mono: "JetBrains Mono", monospace;
}

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

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--white);
    font-family: var(--font-display);
    line-height: 1.6;
    overflow-x: clip;
    position: relative;
}

/* ============================================================
   SFONDO CONTINUO — un singolo layer fixed che copre l'intera
   pagina. Nessuna sezione ha il proprio sfondo: il glow respira
   lentamente sotto tutto il contenuto, senza giunture visibili.
   ============================================================ */

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    /* tre radial-gradient sovrapposti che si spostano lentamente */
    background:
        radial-gradient(ellipse 80% 60% at 20% 20%,  rgba(58, 92, 255, 0.28) 0%, transparent 65%),
        radial-gradient(ellipse 70% 50% at 80% 75%,  rgba(30, 55, 210, 0.22) 0%, transparent 60%),
        radial-gradient(ellipse 55% 45% at 60% 10%,  rgba(100, 130, 255, 0.14) 0%, transparent 55%),
        var(--bg);
    animation: bg-breathe 24s ease-in-out infinite alternate;
    will-change: transform;
}

/* ============================================================
   COSTELLAZIONE — canvas fisso dietro il contenuto. Parte
   invisibile e sfuma dentro solo quando js/constellation.js
   conferma il primo frame disegnato (html.bgfx-on + .is-ready).
   Sotto resta sempre il fallback CSS (body::before + .orb).
   ============================================================ */

#bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.2s ease-out;
}

html.bgfx-on #bg-canvas.is-ready { opacity: 1; }

/* mentre l'effetto gira, il fallback CSS si spegne (cross-fade) */
html.bgfx-on body::before { animation-play-state: paused; }
html.bgfx-on .orb { opacity: 0; visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
    #bg-canvas { display: none; }
}

@keyframes bg-breathe {
    0%   { transform: scale(1)    translate(0%,   0%);   }
    25%  { transform: scale(1.06) translate(2%,  -2%);   }
    50%  { transform: scale(1.10) translate(-2%,  2.5%); }
    75%  { transform: scale(1.07) translate(1.5%, 1%);   }
    100% { transform: scale(1.04) translate(-1%, -1.5%); }
}

/* ============================================================
   ORB — pallini grandi e sfocati che fluttuano su tutta la
   pagina, NON dentro le singole sezioni (niente clip).
   Sono fixed così non interrompono lo scorrimento.
   ============================================================ */

.orb {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    will-change: transform;
    animation: orb-float linear infinite;
    transition: opacity 1.2s ease-out, visibility 1.2s;
}

/* Orb 1 — grande, top-left */
.orb-1 {
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(58,92,255,0.22) 0%, transparent 70%);
    filter: blur(60px);
    top: -120px; left: -140px;
    animation-duration: 18s;
    animation-delay: 0s;
}

/* Orb 2 — medio, bottom-right */
.orb-2 {
    width: 380px; height: 380px;
    background: radial-gradient(circle, rgba(80,120,255,0.18) 0%, transparent 70%);
    filter: blur(50px);
    bottom: -80px; right: -100px;
    animation-duration: 23s;
    animation-delay: -8s;
}

/* Orb 3 — piccolo, center-right, va verso la sezione contact */
.orb-3 {
    width: 280px; height: 280px;
    background: radial-gradient(circle, rgba(40, 70, 220, 0.20) 0%, transparent 70%);
    filter: blur(40px);
    top: 55vh; right: 8%;
    animation-duration: 28s;
    animation-delay: -14s;
}

/* Orb 4 — sottile accent, top-right */
.orb-4 {
    width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(120, 150, 255, 0.16) 0%, transparent 70%);
    filter: blur(35px);
    top: 12%; right: 15%;
    animation-duration: 15s;
    animation-delay: -5s;
}

@keyframes orb-float {
    0%   { transform: translate(0px,    0px);   }
    25%  { transform: translate(30px,  -20px);  }
    50%  { transform: translate(15px,   35px);  }
    75%  { transform: translate(-25px,  15px);  }
    100% { transform: translate(0px,    0px);   }
}

@media (prefers-reduced-motion: reduce) {
    body::before, .orb { animation: none; }
}

/* ============================================================
   PALLINI piccoli (decorativi, posizionati assoluti nelle
   sezioni — non clippatii perché la sezione non ha overflow)
   ============================================================ */

.page-section { overflow: visible; } /* override importante */

.dot {
    --dy: 0px; /* aggiornato via JS per il parallasse */
    position: absolute;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px 3px var(--accent-glow);
    pointer-events: none;
    z-index: 1;
    animation: dot-bob ease-in-out infinite;
    will-change: transform;
}

.dot-s { width: 5px;  height: 5px;  opacity: 0.7; }
.dot-m { width: 8px;  height: 8px;  opacity: 0.55; }

/* Posizioni sparse sulle due sezioni */
.d-1  { top: 14%; left: 9%;   animation-duration: 6.1s; animation-delay:  0s;   }
.d-2  { top: 68%; left: 78%;  animation-duration: 5.7s; animation-delay: -2.2s; }
.d-3  { top: 32%; left: 91%;  animation-duration: 7.2s; animation-delay: -4.1s; }
.d-4  { top: 55%; left: 5%;   animation-duration: 6.5s; animation-delay: -1.5s; }
.d-5  { top: 85%; left: 42%;  animation-duration: 5.3s; animation-delay: -3.4s; }
.d-6  { top: 20%; left: 62%;  animation-duration: 6.8s; animation-delay: -5.1s; }
.d-7  { top: 76%; left: 22%;  animation-duration: 7.4s; animation-delay: -0.8s; }
.d-8  { top: 44%; left: 55%;  animation-duration: 6.0s; animation-delay: -2.9s; }

@keyframes dot-bob {
    0%, 100% { transform: translateY(var(--dy));              }
    50%       { transform: translateY(calc(var(--dy) - 20px)); }
}

@media (prefers-reduced-motion: reduce) {
    .dot { animation: none; }
}

/* ============================================================
   SCROLL REVEAL — cinematico
   Ogni elemento parte da basso+trasparente+sfocato, sale con
   una curva spring e si mette a fuoco. Il delay è iniettato
   via JS per il cascade.
   ============================================================ */

[data-reveal] {
    opacity: 0;
    transform: translateY(40px);
    filter: blur(6px);
    transition:
        opacity  0.9s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.9s cubic-bezier(0.16, 1, 0.3, 1),
        filter   0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-reveal].is-visible {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0px);
}

/* Il titolo grande ha anche uno scale leggero */
.about-title[data-reveal] {
    transform: translateY(50px) scale(0.96);
}
.about-title[data-reveal].is-visible {
    transform: translateY(0) scale(1);
}

@media (prefers-reduced-motion: reduce) {
    [data-reveal] {
        opacity: 1; transform: none; filter: none;
        transition: none;
    }
}

/* ============================================================
   STRUTTURA PAGINA
   ============================================================ */

.page-section {
    position: relative;
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem clamp(1.2rem, 6vw, 4rem);
    /* z-index per stare sopra gli orb fixed */
    z-index: 1;
}

.section-hidden { display: none; }

/* ============================================================
   NAVIGAZIONE LATERALE
   ============================================================ */

.side-nav {
    position: fixed;
    top: 50%;
    right: clamp(1.2rem, 4vw, 2.5rem);
    transform: translateY(-50%);
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.side-nav-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid var(--muted);
    background: transparent;
    transition: background 0.25s, border-color 0.25s, transform 0.25s, box-shadow 0.25s;
}
.side-nav-dot:hover { transform: scale(1.35); }
.side-nav-dot.active {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 12px 2px var(--accent-glow);
    transform: scale(1.2);
}

@media (max-width: 560px) {
    .side-nav { right: 0.9rem; gap: 0.9rem; }
    .side-nav-dot { width: 8px; height: 8px; }
}

/* ============================================================
   SEZIONE ABOUT
   ============================================================ */

.about-inner {
    position: relative;
    z-index: 2;
    max-width: 640px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.about-logo {
    width: 72px;
    height: auto;
    margin-bottom: 1.8rem;
    filter: drop-shadow(0 0 22px var(--accent-glow))
            drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}

.about-kicker {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.4em;
    color: var(--accent);
    margin-bottom: 1rem;
}

.about-title {
    font-weight: 700;
    font-size: clamp(3.2rem, 10vw, 7rem);
    letter-spacing: -0.03em;
    line-height: 1;
}

.about-dot { color: var(--accent); }

.about-lead {
    margin-top: 1.6rem;
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: var(--muted);
    max-width: 44ch;
    line-height: 1.7;
}

/* ============================================================
   SEZIONE CONTACT
   ============================================================ */

.contact-inner {
    position: relative;
    z-index: 2;
    max-width: 640px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.contact-title {
    font-weight: 700;
    font-size: clamp(2.4rem, 6vw, 4rem);
    letter-spacing: -0.02em;
}

.contact-lead {
    margin-top: 1.1rem;
    color: var(--muted);
    max-width: 38ch;
    line-height: 1.7;
}

.contact-link {
    margin-top: 2.2rem;
    font-family: var(--font-mono);
    font-size: clamp(1rem, 2.4vw, 1.4rem);
    color: var(--accent);
    border-bottom: 1px solid rgba(58, 92, 255, 0.45);
    padding-bottom: 0.3rem;
    transition: opacity 0.2s, border-color 0.2s;
    letter-spacing: 0.02em;
}
.contact-link:hover {
    opacity: 0.75;
    border-color: var(--accent);
}

a { color: inherit; text-decoration: none; }
::selection { background: var(--accent); color: #0a0a0f; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ============================================================
   SEZIONE GAME (nascosta per ora)
   ============================================================ */

.game-inner {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.tetris-stage {
    position: relative;
    width: min(90vw, 360px);
    aspect-ratio: 1 / 2;
    margin-top: 1.2rem;
    border: 1px solid rgba(155, 140, 255, 0.25);
    background: #050507;
    box-shadow: 0 0 40px rgba(155, 140, 255, 0.12);
}

#tetris-canvas { display: block; width: 100%; height: 100%; }

.tetris-hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    color: var(--white);
    text-shadow: 0 1px 4px #000;
    pointer-events: none;
}

.tetris-overlay {
    position: absolute; inset: 0;
    display: none;
    flex-direction: column;
    align-items: center; justify-content: center;
    gap: 1rem;
    background: rgba(5,5,7,0.85);
    backdrop-filter: blur(3px);
    z-index: 2;
}
.tetris-overlay.show { display: flex; }
.tetris-overlay-title { font-weight: 700; font-size: 1.6rem; }
.tetris-restart {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    color: var(--bg);
    background: var(--accent);
    border: none;
    padding: 0.7rem 1.4rem;
    cursor: pointer;
}
.tetris-restart:hover { opacity: 0.85; }

/* ============================================================
   SCROLL HINT — freccia pulsante in basso nella prima sezione
   ============================================================ */

.scroll-hint {
    position: absolute;
    bottom: 2.2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    color: var(--muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, opacity 0.4s;
    animation: hint-pulse 2.4s ease-in-out infinite;
    text-decoration: none;
}

.scroll-hint:hover {
    color: var(--accent);
}

/* Scompare una volta che si è scrollato */
.scroll-hint.hidden {
    opacity: 0;
    pointer-events: none;
}

.scroll-hint svg {
    width: 100%;
    height: 100%;
}

@keyframes hint-pulse {
    0%   { transform: translateX(-50%) translateY(0px);   opacity: 0.45; }
    50%  { transform: translateX(-50%) translateY(7px);   opacity: 1;    }
    100% { transform: translateX(-50%) translateY(0px);   opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
    .scroll-hint { animation: none; opacity: 0.6; }
}

/* ============================================================
   SCROLL-OUT — animazione in uscita quando l'elemento esce
   dal viewport verso l'alto
   ============================================================ */

[data-reveal].is-out {
    opacity: 0;
    transform: translateY(-28px);
    filter: blur(4px);
    transition:
        opacity  0.55s cubic-bezier(0.4, 0, 1, 1),
        transform 0.55s cubic-bezier(0.4, 0, 1, 1),
        filter   0.4s cubic-bezier(0.4, 0, 1, 1);
}

/* Il titolo grande si restringe leggermente in uscita */
.about-title[data-reveal].is-out {
    transform: translateY(-20px) scale(0.97);
}

@media (prefers-reduced-motion: reduce) {
    [data-reveal].is-out { opacity: 1; transform: none; filter: none; }
}
