/* ======================================================================
   METAL MODE — easter egg 🤘 (attivato dal pulsante nella firma)
   Questo file va incluso DOPO hacker-theme.css / hacker-red-theme.css,
   sempre attivo (mai disabled): tutte le regole sono scoped su
   "html.metal-mode ..." quindi finché quella classe non è presente
   sul tag <html> non ha alcun effetto su dark/light.
   ====================================================================== */
html.metal-mode{
  --bg:            #000000;
  --bg-2:          #060606;
  --bg-3:          #0a0a0a;
  --line:          #2a2a2a;
  --line-soft:     #1a1a1a;

  --fg:            #f5f5f5;
  --fg-muted:      #d8d8d8;
  --dim:           #9a9a9a;

  --orange:        #ff2e2e;      /* diventa il "colore principale" del tema */
  --orange-2:      #ff8a00;
  --orange-dim:    #b3001f;
  --orange-glow:   rgba(255,46,46,0.65);
  --orange-soft:   rgba(255,46,46,0.10);

  --danger: #ff2e2e;
  --warn:   #ffe600;
  --ok:     #39ff14;

  /* palette multicolore, invariata */
  --metal-red:     #ff1a1a;
  --metal-orange:  #ff8800;
  --metal-green:   #39ff14;
  --metal-purple:  #b026ff;
  --metal-magenta: #ff00ea;
}

/* ---------- sfondo pece: flicker da ampli rotto ---------- */
html.metal-mode body{
  background: var(--bg);
  animation: metal-flicker 6s infinite;
}
@keyframes metal-flicker{
  0%, 96%, 100% { filter: none; }
  97% { filter: brightness(1.15); }
  98% { filter: brightness(0.9); }
}
/* tremore: NON sul body (romperebbe il position:fixed degli overlay GIF,
   che diventerebbero relativi al body invece che alla finestra), ma sui
   blocchi di contenuto visibile */
html.metal-mode header,
html.metal-mode main,
html.metal-mode footer,
html.metal-mode .navbar{
  animation: metal-tremor 0.4s infinite;
}
@keyframes metal-tremor{
  0%, 100%{ transform: translate(0,0); }
  20%{ transform: translate(-1px, 2px); }
  40%{ transform: translate(3px, -1px); }
  60%{ transform: translate(-1px, -1px); }
  80%{ transform: translate(1px, 1px); }
}

/* ---------- overlay GIF: sfondo a piastrelle ciclico + fuoco fullscreen ----------
   Due <div> vuoti nell'HTML (vedi istruzioni sotto), popolati via JS con le GIF.
   Nascosti finché .metal-mode non è sull'<html>. */
#metal-bg-overlay,
#metal-fire-overlay{
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
}
html.metal-mode #metal-bg-overlay{
  display: block;
  background-repeat: repeat;
  background-size: 220px 220px;
  background-position: center;
  opacity: .14;
  mix-blend-mode: screen;
  z-index: 1;
}
html.metal-mode #metal-fire-overlay{
  display: block;
  background-size: cover;
  background-position: center bottom;
  opacity: .2;
  mix-blend-mode: screen;
  z-index: 2;
}

/* titoli ed elementi in risalto: testo che scorre tra i colori fluo,
   rallentato molto (era 5s, ora 18s) */
html.metal-mode h1,
html.metal-mode h2,
html.metal-mode h3,
html.metal-mode strong,
html.metal-mode b,
html.metal-mode .brand,
html.metal-mode .kicker,
html.metal-mode blockquote{
  background: linear-gradient(90deg,
    var(--metal-red), var(--metal-orange), var(--metal-green),
    var(--metal-purple), var(--metal-magenta), var(--metal-red));
  background-size: 400% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent !important;
  animation: metal-shift 18s linear infinite;
  text-shadow: none;
}
@keyframes metal-shift{
  0%{ background-position: 0% 50%; }
  100%{ background-position: 400% 50%; }
}

/* link */
html.metal-mode a{
  color: var(--metal-orange);
  border-color: rgba(255,136,0,0.4);
}
html.metal-mode a:hover{
  color: var(--metal-magenta);
  border-color: var(--metal-magenta);
  text-shadow: 0 0 10px var(--metal-magenta);
}

/* icone (font-awesome, social-icon, widicons, oss-platforms...) diventano fluo */
html.metal-mode i,
html.metal-mode svg,
html.metal-mode .social-icon,
html.metal-mode .widicons{
  filter: drop-shadow(0 0 6px var(--metal-purple)) saturate(2) hue-rotate(10deg);
}

/* scrollbar e selezione testo coerenti */
html.metal-mode ::-webkit-scrollbar-thumb{ background: var(--metal-purple); }
html.metal-mode ::-webkit-scrollbar-thumb:hover{ background: var(--metal-magenta); }
html.metal-mode ::selection{ background: var(--metal-magenta); color: #000; }

/* ---------- cursore: GIF scelta a caso dallo script (vedi JS), con fallback
   sull'icona bianca disegnata se non hai ancora configurato nessuna GIF ---------- */
html.metal-mode,
html.metal-mode *{
  cursor: var(--metal-cursor,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40' width='32' height='32'%3E%3Crect x='23' y='3' width='7' height='19' rx='3.5' transform='rotate(8 26.5 12.5)' fill='white'/%3E%3Crect x='8' y='5' width='7' height='18' rx='3.5' transform='rotate(-8 11.5 14)' fill='white'/%3E%3Crect x='9' y='17' width='22' height='16' rx='8' fill='white'/%3E%3Ccircle cx='7' cy='28' r='6' fill='white'/%3E%3C/svg%3E") 6 30, auto) !important;
}

/* ---------- pulsante toggle nella firma/footer ---------- */
/* icona bianca disegnata al posto dell'emoji: il <button> ora va vuoto,
   niente testo dentro (vedi HTML aggiornato) */
.metal-toggle{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 34px;
  height: 34px;
  margin-left: var(--sp-2);
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all .25s ease;
}
.metal-toggle::before{
  content: "";
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect x='23' y='3' width='7' height='19' rx='3.5' transform='rotate(8 26.5 12.5)' fill='white'/%3E%3Crect x='8' y='5' width='7' height='18' rx='3.5' transform='rotate(-8 11.5 14)' fill='white'/%3E%3Crect x='9' y='17' width='22' height='16' rx='8' fill='white'/%3E%3Ccircle cx='7' cy='28' r='6' fill='white'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  filter: drop-shadow(0 0 3px rgba(255,255,255,.5));
}
.metal-toggle:hover{
  border-color: var(--orange);
  box-shadow: var(--glow-sm);
  transform: translateY(-2px) rotate(-8deg);
}
html.metal-mode .metal-toggle{
  background: #000;
  border-color: var(--metal-purple);
  box-shadow: 0 0 14px var(--metal-purple);
  animation: metal-pulse 1.4s ease-in-out infinite, metal-melt 3.5s ease-in-out infinite;
}
@keyframes metal-pulse{
  0%, 100%{ box-shadow: 0 0 10px var(--metal-purple); }
  50%{ box-shadow: 0 0 20px var(--metal-magenta); }
}

/* ======================================================================
   PULSANTI CHE PRENDONO FUOCO (in alto — navbar)
   ====================================================================== */
html.metal-mode .navbar .navbar-nav .nav-link,
html.metal-mode #toggle-tema{
  animation: metal-fire 1.3s ease-in-out infinite;
}
@keyframes metal-fire{
  0%, 100%{
    color: var(--metal-red) !important;
    text-shadow: 0 -1px 6px var(--metal-orange), 0 -3px 12px var(--metal-red);
    transform: translateY(0) skewX(0deg);
  }
  25%{
    color: var(--metal-orange) !important;
    text-shadow: 0 -2px 8px #ffe600, 0 -4px 14px var(--metal-orange);
    transform: translateY(-1px) skewX(1deg);
  }
  50%{
    color: #ffe600 !important;
    text-shadow: 0 -1px 10px var(--metal-orange), 0 -3px 16px var(--metal-red);
    transform: translateY(0) skewX(-1deg);
  }
  75%{
    color: var(--metal-orange) !important;
    text-shadow: 0 -2px 8px var(--metal-red), 0 -4px 12px var(--metal-orange);
    transform: translateY(-1px) skewX(1deg);
  }
}
/* sfalsamento: ogni voce di menu "brucia" con un timing leggermente diverso */
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(1) .nav-link{ animation-delay: 0s; }
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(2) .nav-link{ animation-delay: .12s; }
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(3) .nav-link{ animation-delay: .24s; }
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(4) .nav-link{ animation-delay: .36s; }
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(5) .nav-link{ animation-delay: .48s; }
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(6) .nav-link{ animation-delay: .60s; }
html.metal-mode .navbar .navbar-nav .nav-item:nth-child(7) .nav-link{ animation-delay: .72s; }

/* ======================================================================
   PULSANTI CHE SI SCIOLGONO (in basso — footer)
   ====================================================================== */
html.metal-mode .footer-moderno .social-icon,
html.metal-mode .footer-moderno .btn-sostieni{
  position: relative;
  overflow: visible;
  animation: metal-melt 3.5s ease-in-out infinite;
}
@keyframes metal-melt{
  0%, 100%{ border-radius: 50%; transform: translateY(0) scale(1); }
  50%{ border-radius: 20% 80% 65% 35% / 70% 75% 25% 30%; transform: translateY(8px) scale(1.05, 0.9); }
}
html.metal-mode .footer-moderno .btn-sostieni{
  animation-name: metal-melt-pill;
}
@keyframes metal-melt-pill {
  0%, 100% { 
    /* Stato iniziale e finale: pillola compatta */
    border-radius: 30px; 
    transform: translateY(0) scale(1); 
  }
  25% {
    /* Inizia a cadere e cedere verso destra */
    border-radius: 20px 40px 15px 45px / 45px 15px 40px 20px;
    transform: translateY(6px) scale(1.05, 0.90);
  }
  50% { 
    /* Punto massimo di schiacciamento a terra (pozzanghera) */
    border-radius: 8px 50px 15px 40px / 12px 45px 10px 50px; 
    transform: translateY(14px) scale(1.20, 0.70); 
  }
  75% {
    /* Torna su riprendendo forma, ma oscillando verso sinistra */
    border-radius: 40px 15px 45px 20px / 15px 45px 20px 40px;
    transform: translateY(4px) scale(0.95, 1.05);
  }
}

/* 
  Assicurati di richiamare l'animazione in questo modo nella classe:
  L'uso di 'ease-in-out' è fondamentale per rendere morbidi i cambi di direzione,
  mentre 'infinite' garantisce il ciclo continuo (in un senso e nell'altro).
*/
.metal-pill {
  animation: metal-melt-pill 4s ease-in-out infinite;
  will-change: transform, border-radius;
}
/* Effetto goccia metallica (accelerazione hardware e riflessi volumetrici) */
html.metal-mode .footer-moderno .social-icon::after,
html.metal-mode .metal-toggle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 12px;  /* Dimensione base leggermente aumentata */
  height: 10px;
  background: var(--metal-red);
  border-radius: 50px;
  
  /* Ancoraggio in alto per simulare l'adesione al pulsante */
  transform-origin: top center;
  transform: translateX(-50%) scale(0);
  
  /* Inset shadow per il riflesso del metallo liquido + outer glow più intenso */
  box-shadow: 
    0 0 10px var(--metal-red), 
    inset 0 -2px 4px rgba(255, 255, 255, 0.45);
    
  animation: metal-drip-advanced 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  pointer-events: none;
  will-change: transform, opacity;
  z-index: -1;
}

@keyframes metal-drip-advanced {
  0%, 15% {
    /* Stato iniziale invisibile */
    transform: translate(-50%, 0) scale(0);
    opacity: 0;
  }
  30% {
    /* Accumulo: la goccia si gonfia alla base del pulsante */
    transform: translate(-50%, 10) scaleX(1.2) scaleY(2);
    opacity: 1;
  }
  45% {
    /* Tensione superficiale: si allunga verso il basso prima del distacco */
    transform: translate(-50%, 12px) scaleX(0.6) scaleY(2.5);
    opacity: 1;
  }
  60% {
    /* Distacco e caduta libera */
    transform: translate(-50%, 28px) scaleX(0.9) scaleY(3.2);
    opacity: 0.8;
  }
  80%, 100% {
    /* Dissolvenza nel vuoto */
    transform: translate(-50%, 55px) scaleX(0.4) scaleY(0.4);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce){
  html.metal-mode body,
  html.metal-mode header, html.metal-mode main, html.metal-mode footer, html.metal-mode .navbar,
  html.metal-mode h1, html.metal-mode h2, html.metal-mode h3,
  html.metal-mode strong, html.metal-mode b, html.metal-mode .brand,
  html.metal-mode .metal-toggle,
  html.metal-mode .navbar .navbar-nav .nav-link,
  html.metal-mode #toggle-tema,
  html.metal-mode .footer-moderno .social-icon,
  html.metal-mode .footer-moderno .btn-sostieni,
  html.metal-mode .footer-moderno .social-icon::after,
  html.metal-mode .metal-toggle::after{
    animation: none !important;
  }
}