:root {
  --bg: #000000;
  --fg: #ffffff;
  --cyan: #66f0ff;
}

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

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Canvas WebGL: il livello più profondo */
#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  z-index: 0;
}

/* Vignette radiale impercettibile: concentra l'occhio al centro */
.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

/* Grana filmica anti-banding (zero carico GPU) */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 2;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
  animation: grain-shift 0.8s steps(5) infinite;
}

@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -2%); }
  80% { transform: translate(3%, 1%); }
  100% { transform: translate(0, 0); }
}

/* Logo centrato, sopra tutto, non intercetta il mouse (lo lascia alla scena) */
.stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
}

.logo {
  display: inline-flex;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1;
  font-size: clamp(1.5rem, 4.5vw, 3rem);
  color: rgba(255, 255, 255, 0.72);
  user-select: none;
}

/* Stato iniziale dei glifi: invisibili, "non ancora proiettati" dalla 4ª dimensione */
.logo span {
  display: inline-block;
  opacity: 0;
  filter: blur(8px);
  -webkit-clip-path: inset(0 0 100% 0);
  clip-path: inset(0 0 100% 0);
  /* aberrazione cromatica: l'ombra 2D della 4D ancora "fuori fuoco" */
  text-shadow: 6px 0 rgba(102, 240, 255, 0.6), -6px 0 rgba(255, 255, 255, 0.5);
}

/* Cristallizzazione: ogni glifo si de-proietta uno a uno, in stagger */
.logo.ready span {
  opacity: 1;
  filter: blur(0);
  -webkit-clip-path: inset(0 0 0% 0);
  clip-path: inset(0 0 0% 0);
  text-shadow: 0 0 24px rgba(255, 255, 255, 0.18);
  transition:
    opacity 0.7s,
    filter 0.9s,
    clip-path 0.9s,
    -webkit-clip-path 0.9s,
    text-shadow 0.9s;
  transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  transition-delay: calc(var(--i) * 55ms);
}

/* L'"8" (l'ottava cella) entra per ultima, con un alone ciano persistente */
.logo.ready span.eight {
  transition-delay: calc(var(--i) * 55ms + 80ms);
  text-shadow: 0 0 26px rgba(102, 240, 255, 0.22);
}

/* Respiro impercettibile a regime */
.logo.ready {
  animation: logo-breath 6s 4s ease-in-out infinite;
}

@keyframes logo-breath {
  0%, 100% { opacity: 0.92; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
  .logo.ready { animation: none; }
  .logo span,
  .logo.ready span {
    opacity: 1;
    filter: none;
    -webkit-clip-path: none;
    clip-path: none;
    text-shadow: 0 0 24px rgba(255, 255, 255, 0.18);
    transition: none;
  }
}
