/* v2 Mascotte+Mood Fase 3 — mood background come LAYER SOPRA IL TEMA.

   Decisione owner: NON sostituire il background del tema
   (theme-deep/aurora/focus) né l'ambient-mesh. Il mood è un tint
   contestuale a bassa opacità, dietro al contenuto e all'ambient-mesh
   resta la SUA unica vignette (.ambient-mesh-vignette, non duplicata).

   Stack z-index (dal fondo): ambient-mesh (-10) → mood tint (-9) →
   noise (-8) → contenuto (auto, sopra). Niente regola globale
   `body > * { z-index:1 }` (romperebbe modali/sticky).
*/

/* Mood corrente → variabile, default = fallback */
body { --mood-current: var(--mood-default); }
body[data-mood="default"]     { --mood-current: var(--mood-default); }
body[data-mood="felice"]      { --mood-current: var(--mood-felice); }
body[data-mood="festeggia"]   { --mood-current: var(--mood-festeggia); }
body[data-mood="triste"]      { --mood-current: var(--mood-triste); }
body[data-mood="pensieroso"]  { --mood-current: var(--mood-pensieroso); }
body[data-mood="determinato"] { --mood-current: var(--mood-determinato); }
body[data-mood="coach"]       { --mood-current: var(--mood-coach); }
body[data-mood="dorme"]       { --mood-current: var(--mood-dorme); }
body[data-mood="fiero"]       { --mood-current: var(--mood-fiero); }
body[data-mood="sorpreso"]    { --mood-current: var(--mood-sorpreso); }
body[data-mood="preoccupato"] { --mood-current: var(--mood-preoccupato); }

/* Tint contestuale: dietro al contenuto, sopra l'ambient-mesh.
   opacity bassa = il tema resta percepibile sotto. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -9;
  pointer-events: none;
  background: var(--mood-current);
  opacity: 0.50;
  transition: opacity 600ms var(--ease-apple, ease),
              background 600ms var(--ease-apple, ease);
}

/* Grain sottile (ambient.css prometteva "grain" ma non lo implementava).
   Un solo layer, opt-out via data-atmosphere. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -8;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/></svg>");
  opacity: 0.035;
  mix-blend-mode: overlay;
}

/* Mood scuri: alza il contrasto del testo secondario (AA) */
body[data-mood="triste"],
body[data-mood="dorme"],
body[data-mood="coach"] {
  --text-3: var(--text-3-on-dark);
}

/* Opt-out atmosfera: spegne tint + grain (la mesh resta, è preesistente) */
body[data-atmosphere="off"]::before,
body[data-atmosphere="off"]::after {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  body::before { transition: none; }
}
