/*
  REDDY – Safe, Go! · modulo interattivo aggiuntivo
  "Caccia al rischio" + "Piano, non correre!".
  Caricato sopra la build principale, non ne modifica il codice.
*/

:root {
  --rx-bg: #04161f;
  --rx-panel: #0a2733;
  --rx-yellow: #fcaf02;
  --rx-cyan: #36d2ff;
  --rx-red: #d0112b;
  --rx-green: #3ddc84;
  --rx-text: #f4f1e8;
  --rx-muted: #9fb8c2;
  --rx-pixel: "Silkscreen", "Courier New", ui-monospace, monospace;
  --rx-head: "Pixelify Sans", "Silkscreen", system-ui, sans-serif;
  --rx-body: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------------------------------------------------------------
   Rischi nascosti
   --------------------------------------------------------------- */
.rx-hazard {
  position: absolute;
  z-index: 5;
  width: var(--rx-w, 64px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform: rotate(var(--rx-rot, 0deg));
  transition: transform 0.18s steps(3), filter 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.rx-hazard img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  pointer-events: none;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.35));
}
.rx-hazard:hover,
.rx-hazard:focus-visible {
  transform: rotate(var(--rx-rot, 0deg)) scale(1.1);
}
.rx-hazard:focus-visible {
  outline: 3px dashed var(--rx-yellow);
  outline-offset: 6px;
}

/* Piccolo segnale di "qualcosa non va": un tremolio ogni tanto */
.rx-hazard:not(.is-found) {
  animation: rx-wobble 5s steps(1) infinite;
  animation-delay: var(--rx-delay, 0s);
}
@keyframes rx-wobble {
  0%, 88%, 100% { transform: rotate(var(--rx-rot, 0deg)); }
  90% { transform: rotate(calc(var(--rx-rot, 0deg) - 5deg)); }
  92% { transform: rotate(calc(var(--rx-rot, 0deg) + 5deg)); }
  94% { transform: rotate(calc(var(--rx-rot, 0deg) - 3deg)); }
  96% { transform: rotate(calc(var(--rx-rot, 0deg) + 2deg)); }
}

.rx-hazard.is-found {
  cursor: default;
  filter: grayscale(0.85) brightness(0.8);
  opacity: 0.75;
}
.rx-hazard__check {
  position: absolute;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: var(--rx-green);
  color: var(--rx-bg);
  font: 700 14px/1 var(--rx-pixel);
  box-shadow: 0 0 0 3px var(--rx-bg);
  transform: scale(0);
  transition: transform 0.25s steps(4);
}
.rx-hazard.is-found .rx-hazard__check {
  transform: scale(1);
}

/* Scoppio di pixel al ritrovamento */
.rx-burst {
  position: fixed;
  z-index: 60;
  width: 8px;
  height: 8px;
  pointer-events: none;
  background: var(--c, var(--rx-yellow));
  animation: rx-burst 0.6s steps(6) forwards;
}
@keyframes rx-burst {
  from { transform: translate(0, 0); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)); opacity: 0; }
}

/* Posizioni: ogni rischio sta dentro un elemento della sezione (vedi
   "anchor" in reddy-extra.js), non ai bordi della pagina.
   Quasi tutti stanno nel flusso del layout, con uno spazio tutto loro:
   così non finiscono mai sopra un testo, a qualunque larghezza. */
.rx-hazard--perche,
.rx-hazard--progetto,
.rx-hazard--come,
.rx-hazard--ambienti,
.rx-hazard--lucca { position: relative; flex-shrink: 0; }

/* in fondo alla card "La prevenzione nasce dall'esperienza" */
.rx-hazard--perche   { --rx-w: 30px; --rx-rot: -8deg; justify-self: end; margin-top: .25rem; }
/* nella cella libera accanto ai contatori */
.rx-hazard--progetto { --rx-w: 60px; --rx-rot: 4deg;  justify-self: start; align-self: center; }
/* in fondo alla card 03 */
.rx-hazard--come     { --rx-w: 48px; --rx-rot: -4deg; justify-self: end; }
/* accanto a "Scegli un ambiente" */
.rx-hazard--ambienti { --rx-w: 36px; --rx-rot: 6deg;  display: inline-block; vertical-align: middle; margin-left: 1.25rem; }
/* accanto al testo del calendario */
.rx-hazard--lucca    { --rx-w: 60px; --rx-rot: -3deg; margin-left: auto; align-self: center; }
/* sul palco di Reddy, lontano dalla scritta di sfondo */
.why__point, .intro__stats, .step, .reddy__stage { position: relative; }
.rx-hazard--reddy    { --rx-w: 34px; --rx-rot: 10deg; right: 12%; bottom: 1.5rem; }

@media (max-width: 760px) {
  .rx-hazard--perche   { --rx-w: 26px; }
  .rx-hazard--progetto { --rx-w: 50px; }
  .rx-hazard--come     { --rx-w: 40px; }
  .rx-hazard--ambienti { --rx-w: 30px; }
  .rx-hazard--lucca    { --rx-w: 46px; }
  .rx-hazard--reddy    { --rx-w: 28px; right: 8%; }
}

/* ---------------------------------------------------------------
   Contatore
   --------------------------------------------------------------- */
.rx-counter {
  position: fixed;
  z-index: 40;
  top: 96px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 0;
  background: var(--rx-bg);
  color: var(--rx-text);
  font: 400 11px/1 var(--rx-pixel);
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow:
    0 0 0 2px var(--rx-yellow),
    4px 4px 0 2px rgba(0, 0, 0, 0.45);
  transform: translateY(-12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s steps(3);
}
.rx-counter.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.rx-counter:focus-visible {
  outline: 3px dashed var(--rx-cyan);
  outline-offset: 4px;
}
.rx-counter__label strong {
  color: var(--rx-yellow);
  font-weight: 700;
}
.rx-counter__pips {
  display: flex;
  gap: 3px;
}
.rx-counter__pip {
  width: 8px;
  height: 8px;
  background: rgba(255, 255, 255, 0.18);
}
.rx-counter__pip.is-on {
  background: var(--rx-green);
}
.rx-counter.is-bump {
  animation: rx-bump 0.4s steps(4);
}
@keyframes rx-bump {
  50% { transform: scale(1.12); }
}

/* ---------------------------------------------------------------
   Fumetto di Reddy (toast)
   --------------------------------------------------------------- */
.rx-toast {
  position: fixed;
  z-index: 50;
  left: 16px;
  bottom: 104px;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: end;
  width: min(380px, calc(100vw - 32px));
  padding: 14px 16px 14px 12px;
  background: var(--rx-panel);
  color: var(--rx-text);
  box-shadow:
    0 0 0 3px var(--rx-bg),
    0 0 0 5px var(--c, var(--rx-yellow)),
    6px 6px 0 5px rgba(0, 0, 0, 0.45);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s steps(3);
}
.rx-toast.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.rx-toast__sprite {
  position: relative;
  width: 56px;
  height: 84px;
}
.rx-toast__sprite img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  opacity: 0;
}
.rx-toast__sprite img.is-active {
  opacity: 1;
}
.rx-toast__kicker {
  margin: 0 0 6px;
  color: var(--c, var(--rx-yellow));
  font: 700 11px/1.2 var(--rx-pixel);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.rx-toast__text {
  margin: 0;
  font: 400 14px/1.45 var(--rx-body);
}
.rx-toast__close {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 28px;
  height: 28px;
  border: 0;
  background: none;
  color: var(--rx-muted);
  font: 700 14px/1 var(--rx-pixel);
  cursor: pointer;
}
.rx-toast__close:hover,
.rx-toast__close:focus-visible {
  color: var(--rx-text);
}

/* ---------------------------------------------------------------
   "Piano, non correre!" — Reddy stordito sopra il corridore
   --------------------------------------------------------------- */
body.rx-stunned .parkour__runner .sprite {
  visibility: hidden;
}
.rx-stun {
  position: fixed;
  z-index: 45;
  pointer-events: none;
  display: none;
}
.rx-stun.is-visible {
  display: block;
}
.rx-stun__sprite {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  animation: rx-shake 0.3s steps(2) 2;
}
@keyframes rx-shake {
  50% { transform: translateX(-3px); }
}
.rx-stun__stars {
  position: absolute;
  left: 50%;
  bottom: 38%;
  width: 44px;
  height: 14px;
  margin-left: -22px;
  animation: rx-orbit 0.8s steps(8) infinite;
}
.rx-stun__stars i {
  position: absolute;
  top: 3px;
  width: 8px;
  height: 8px;
  background: var(--rx-yellow);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
.rx-stun__stars i:nth-child(1) { left: 0; }
.rx-stun__stars i:nth-child(2) { left: 18px; background: var(--rx-cyan); }
.rx-stun__stars i:nth-child(3) { left: 36px; }
@keyframes rx-orbit {
  0%   { transform: scaleX(1); }
  50%  { transform: scaleX(-1); }
  100% { transform: scaleX(1); }
}
.rx-stun__bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  width: max-content;
  max-width: 220px;
  padding: 8px 10px;
  background: var(--rx-text);
  color: var(--rx-bg);
  font: 700 10px/1.4 var(--rx-pixel);
  letter-spacing: 0.04em;
  text-align: center;
  transform: translateX(-30%);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
}
.rx-stun__bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 30%;
  border: 6px solid transparent;
  border-top-color: var(--rx-text);
}

/* ---------------------------------------------------------------
   Schermata di completamento
   --------------------------------------------------------------- */
.rx-complete {
  width: min(460px, calc(100vw - 32px));
  padding: 32px 28px 28px;
  border: 0;
  background: var(--rx-panel);
  color: var(--rx-text);
  text-align: center;
  box-shadow:
    0 0 0 4px var(--rx-bg),
    0 0 0 7px var(--rx-green),
    10px 10px 0 7px rgba(0, 0, 0, 0.5);
}
.rx-complete::backdrop {
  background: rgba(2, 10, 14, 0.78);
}
.rx-complete__sprite {
  position: relative;
  width: 96px;
  height: 144px;
  margin: 0 auto 16px;
}
.rx-complete__sprite img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  opacity: 0;
}
.rx-complete__sprite img.is-active {
  opacity: 1;
}
.rx-complete__kicker {
  margin: 0 0 8px;
  color: var(--rx-green);
  font: 700 12px/1.2 var(--rx-pixel);
  letter-spacing: 0.1em;
}
.rx-complete__title {
  margin: 0 0 12px;
  font: 700 28px/1.1 var(--rx-head);
}
.rx-complete__text {
  margin: 0 0 24px;
  color: var(--rx-muted);
  font: 400 15px/1.5 var(--rx-body);
}
.rx-complete__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.rx-btn {
  display: inline-block;
  padding: 14px 20px;
  border: 0;
  font: 700 12px/1 var(--rx-pixel);
  letter-spacing: 0.08em;
  text-decoration: none;
  cursor: pointer;
}
.rx-btn--primary {
  background: var(--rx-yellow);
  color: var(--rx-bg);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
}
.rx-btn--ghost {
  background: none;
  color: var(--rx-text);
  box-shadow: inset 0 0 0 2px var(--rx-cyan);
}
.rx-btn:focus-visible {
  outline: 3px dashed var(--rx-text);
  outline-offset: 4px;
}

/* Chi ha chiesto meno movimento: niente tremolii, stelle ferme */
@media (prefers-reduced-motion: reduce) {
  .rx-hazard:not(.is-found),
  .rx-stun__sprite,
  .rx-stun__stars,
  .rx-counter.is-bump {
    animation: none;
  }
  .rx-burst {
    display: none;
  }
}

@media print {
  .rx-hazard, .rx-counter, .rx-toast, .rx-stun { display: none !important; }
}
