/*
 * The fidgets and the hero background on the NeuroX front page.
 *
 * A copy of the platform's src/sites/neurox-nj/fidgets.css (PR #138). Only
 * this token mapping differs: everything below the "shared" line is the same
 * as the platform's, so change both together.
 */

.ps-fx {
  --ps-fx-tint-teal: var(--tint-teal);
  --ps-fx-tint-ind: var(--tint-ind);
  --ps-fx-tint-mag: var(--tint-mag);
  --ps-fx-s1: var(--s1);
  --ps-fx-s2: var(--s2);
  --ps-fx-s3: var(--s3);
  --ps-fx-mag-text: var(--magenta-text);
  --ps-fx-label: var(--font-mono);
}

/* ── shared: the static site's copy is identical from here down ─────────── */

.ps-fx {
  --ps-fx-focus: var(--focus-ring);
  --ps-fx-pond: var(--ps-fx-tint-teal);
  --ps-fx-dot: rgba(48, 48, 144, 0.16);
  --ps-fx-floor: rgba(20, 20, 63, 0.3);
  --ps-fx-tray-hi: #ffffff;
  --ps-fx-tray: #ececfb;
  --ps-fx-tray-lo: #dadaf3;
  --ps-fx-tray-edge: #c3c3e9;
  --ps-fx-tray-shine: rgba(255, 255, 255, 0.95);
  --ps-fx-tray-line: rgba(48, 48, 144, 0.1);
  --ps-fx-board-hi: #ffffff;
  --ps-fx-board: #f0f0fb;
  --ps-fx-cell: #dedff1;
  --ps-fx-cell-edge: #b7badb;
  --ps-fx-track-off: #cdd0e6;
  --ps-fx-rod: #7c869a;
  --ps-fx-ripple: #0a7a72;
  --ps-fx-next-bg: #303090;
  --ps-fx-next-ink: #ffffff;
  --ps-fx-gi0: #7a7adb;
  --ps-fx-gi1: #303090;
  --ps-fx-gi2: #1e1e64;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="bone"]) .ps-fx {
    --ps-fx-dot: rgba(180, 180, 255, 0.14);
    --ps-fx-floor: rgba(0, 0, 0, 0.55);
    --ps-fx-tray-hi: #3a3a86;
    --ps-fx-tray: #28286a;
    --ps-fx-tray-lo: #1e1e52;
    --ps-fx-tray-edge: #13133a;
    --ps-fx-tray-shine: rgba(255, 255, 255, 0.14);
    --ps-fx-tray-line: rgba(180, 180, 255, 0.18);
    --ps-fx-board-hi: #26265e;
    --ps-fx-board: #1c1c48;
    --ps-fx-cell: #2e2e68;
    --ps-fx-cell-edge: #4a4a92;
    --ps-fx-track-off: #38386f;
    --ps-fx-rod: #8c8cc8;
    --ps-fx-ripple: #5fe0d5;
    --ps-fx-next-bg: #b4b4ff;
    --ps-fx-next-ink: #14143f;
    --ps-fx-gi0: #b4b4ff;
    --ps-fx-gi1: #6a6ae0;
    --ps-fx-gi2: #4646b4;
  }
}
:root[data-theme="midnight"] .ps-fx {
  --ps-fx-dot: rgba(180, 180, 255, 0.14);
  --ps-fx-floor: rgba(0, 0, 0, 0.55);
  --ps-fx-tray-hi: #3a3a86;
  --ps-fx-tray: #28286a;
  --ps-fx-tray-lo: #1e1e52;
  --ps-fx-tray-edge: #13133a;
  --ps-fx-tray-shine: rgba(255, 255, 255, 0.14);
  --ps-fx-tray-line: rgba(180, 180, 255, 0.18);
  --ps-fx-board-hi: #26265e;
  --ps-fx-board: #1c1c48;
  --ps-fx-cell: #2e2e68;
  --ps-fx-cell-edge: #4a4a92;
  --ps-fx-track-off: #38386f;
  --ps-fx-rod: #8c8cc8;
  --ps-fx-ripple: #5fe0d5;
  --ps-fx-next-bg: #b4b4ff;
  --ps-fx-next-ink: #14143f;
  --ps-fx-gi0: #b4b4ff;
  --ps-fx-gi1: #6a6ae0;
  --ps-fx-gi2: #4646b4;
}

/* ── The box ──────────────────────────────────────────────────────────── */

.ps-fx {
  position: relative;
  isolation: isolate;
  justify-self: end;
  width: 100%;
  max-width: 520px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
}

/*
 * The hero background: colour pools, a dot grid and four outline shapes.
 *
 * It sits behind the tray only, in a band no taller than the tray, so its box
 * never covers a word: not the heading, not the header, and not the controls
 * below the tray. The contrast scan treats any box over text as hiding it,
 * even one painted behind, so this is about boxes, not just paint. For the
 * same reason the pools are gradients on one element rather than large
 * blurred shapes, and every shape stays inside the band while it moves.
 */
.ps-fx-stage {
  position: relative;
  isolation: isolate;
}
.ps-fx-bg {
  position: absolute;
  z-index: -1;
  top: -40px;
  bottom: -14px;
  left: -40px;
  right: -120px;
  pointer-events: none;
  overflow: hidden;
}
.ps-fx-pools {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(closest-side, var(--ps-fx-tint-teal), transparent) 85% 0% / 60% 70% no-repeat,
    radial-gradient(closest-side, var(--ps-fx-tint-mag), transparent) 20% 100% / 55% 60% no-repeat,
    radial-gradient(closest-side, var(--ps-fx-tint-ind), transparent) 0% 40% / 50% 60% no-repeat;
}
.ps-fx-dotgrid {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--ps-fx-dot) 1.4px, transparent 1.9px);
  background-size: 22px 22px;
  -webkit-mask-image: radial-gradient(50% 60% at 45% 50%, #000 0%, transparent 78%);
  mask-image: radial-gradient(50% 60% at 45% 50%, #000 0%, transparent 78%);
}
.ps-fx-fl {
  position: absolute;
  opacity: 0.5;
  border: 5px solid var(--ps-fx-s1);
  border-radius: 50%;
}
.ps-fx-f1 {
  width: 46px;
  height: 46px;
  top: 24px;
  left: 20px;
}
.ps-fx-f2 {
  width: 34px;
  height: 34px;
  bottom: 30px;
  left: 18px;
  border-color: var(--ps-fx-s3);
  border-radius: 9px;
}
.ps-fx-f3 {
  width: 64px;
  height: 64px;
  top: 20px;
  right: 60px;
  border-color: var(--ps-fx-s2);
  border-radius: 0 100% 0 0;
  border-left: 0;
  border-bottom: 0;
}
.ps-fx-f4 {
  width: 26px;
  height: 26px;
  bottom: 40px;
  right: 80px;
  border: 0;
  background: var(--ps-fx-s3);
  opacity: 0.35;
}

/* ── The tray ─────────────────────────────────────────────────────────── */

.ps-fx-float {
  position: relative;
}
/* The tray's shadow on the floor: a real element, not a pseudo-element. */
.ps-fx-floor {
  position: absolute;
  z-index: -1;
  left: 14%;
  right: 14%;
  bottom: -30px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--ps-fx-floor), transparent);
}
.ps-fx-tray {
  position: relative;
  border-radius: 46px;
  padding: 18px 18px 30px;
  background: linear-gradient(165deg, var(--ps-fx-tray-hi) 0%, var(--ps-fx-tray) 50%, var(--ps-fx-tray-lo) 100%);
  box-shadow:
    inset 0 2px 0 var(--ps-fx-tray-shine),
    inset 0 -12px 0 var(--ps-fx-tray-edge),
    inset 0 0 0 1px var(--ps-fx-tray-line),
    0 2px 3px rgba(20, 20, 63, 0.1),
    0 24px 44px -16px rgba(48, 48, 144, 0.42),
    0 54px 80px -40px rgba(228, 12, 144, 0.34);
  transform: perspective(1000px) rotateX(var(--ps-fx-rx, 0deg)) rotateY(var(--ps-fx-ry, 0deg));
}
/* Square before the board is drawn and after, so nothing moves when it is. */
.ps-fx-board {
  aspect-ratio: 1 / 1;
  border-radius: 32px;
}
.ps-fx-toy {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 32px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ps-fx-toy .ps-fx-pc {
  cursor: pointer;
  outline: none;
}
.ps-fx-toy .ps-fx-t {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.45s cubic-bezier(0.5, 0, 0.2, 1);
}
.ps-fx-toy .ps-fx-mv {
  transition: transform 0.36s cubic-bezier(0.4, 0, 0.2, 1);
}
.ps-fx-toy .ps-fx-fast {
  transition: transform 0.09s ease-out;
}
.ps-fx-toy .ps-fx-flip {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.12s ease-in;
}
.ps-fx-toy .ps-fx-lt {
  transition: fill 0.22s;
}
.ps-fx-toy .ps-fx-ctr {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.ps-fx-toy .ps-fx-wig {
  animation: ps-fx-wig 0.32s ease-in-out;
}
.ps-fx-toy .ps-fx-rip {
  transform-box: fill-box;
  transform-origin: center;
  animation: ps-fx-rip 1.7s cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
}
@keyframes ps-fx-wig {
  25% {
    transform: translateX(-7px);
  }
  75% {
    transform: translateX(7px);
  }
}
@keyframes ps-fx-rip {
  from {
    transform: scale(0.12);
    opacity: 0.95;
  }
  to {
    transform: scale(1);
    opacity: 0;
  }
}

/* ── The controls, on a solid card so their words are measured on one colour ── */

.ps-fx-ui {
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
  padding: 16px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ps-fx-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  justify-content: center;
  align-items: baseline;
}
.ps-fx-count {
  font-family: var(--ps-fx-label);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.ps-fx-meta b {
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.ps-fx-hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.98rem;
  max-width: 30em;
}
.ps-fx-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  max-width: 100%;
}
.ps-fx-tbtn {
  font: inherit;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
.ps-fx-tbtn svg {
  width: 18px;
  height: 18px;
  flex: none;
}
.ps-fx-tbtn:hover {
  background: var(--ps-fx-tint-ind);
}
.ps-fx-tbtn-next,
.ps-fx-tbtn-next:hover {
  background: var(--ps-fx-next-bg);
  border-color: var(--ps-fx-next-bg);
  color: var(--ps-fx-next-ink);
}
.ps-fx-tbtn-next:hover {
  box-shadow: 0 0 0 4px var(--ps-fx-tint-mag);
}
.ps-fx-tbtn.ps-fx-nudge {
  animation: ps-fx-nudge 1.1s ease-in-out 3;
}
@keyframes ps-fx-nudge {
  50% {
    box-shadow: 0 0 0 9px var(--ps-fx-tint-mag);
  }
}
.ps-fx-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 2px;
  max-width: 244px;
  margin: 0;
  padding: 0;
}
.ps-fx-dot {
  width: 28px;
  height: 28px;
  border: 0;
  background: none;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 50%;
  color: inherit;
}
.ps-fx-dot span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink-muted);
  transition: transform 0.2s;
}
.ps-fx-dot:hover span {
  border-color: var(--ink);
  transform: scale(1.2);
}
.ps-fx-dot[aria-current="true"] span {
  background: var(--ps-fx-mag-text);
  border-color: var(--ps-fx-mag-text);
  transform: scale(1.35);
}

/* ── Motion: only for readers who have not asked for less, either way ──── */

@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion="reduced"]) .ps-fx-pools {
    animation: ps-fx-drift 30s ease-in-out infinite alternate;
  }
  :root:not([data-motion="reduced"]) .ps-fx-dotgrid {
    animation: ps-fx-dots 18s linear infinite;
  }
  :root:not([data-motion="reduced"]) .ps-fx-f1 {
    animation: ps-fx-bob-a 11s ease-in-out infinite alternate;
  }
  :root:not([data-motion="reduced"]) .ps-fx-f2 {
    animation: ps-fx-bob-b 13s ease-in-out infinite alternate;
  }
  :root:not([data-motion="reduced"]) .ps-fx-f3 {
    animation: ps-fx-bob-a 15s ease-in-out infinite alternate-reverse;
  }
  :root:not([data-motion="reduced"]) .ps-fx-f4 {
    animation: ps-fx-bob-b 9s ease-in-out infinite alternate;
  }
  :root:not([data-motion="reduced"]) .ps-fx-float {
    animation: ps-fx-float 7s ease-in-out infinite;
  }
  :root:not([data-motion="reduced"]) .ps-fx-floor {
    animation: ps-fx-shadow 7s ease-in-out infinite;
  }
  :root:not([data-motion="reduced"]) .ps-fx-tray {
    transition: transform 0.35s ease-out;
  }
}
@keyframes ps-fx-drift {
  to {
    background-position: 70% 15%, 35% 85%, 10% 60%;
  }
}
@keyframes ps-fx-dots {
  to {
    background-position: 22px 22px;
  }
}
/* Small enough that a shape never leaves the band. */
@keyframes ps-fx-bob-a {
  to {
    transform: translate(8px, 12px) rotate(30deg);
  }
}
@keyframes ps-fx-bob-b {
  to {
    transform: translate(10px, -10px) rotate(-25deg);
  }
}
@keyframes ps-fx-float {
  50% {
    transform: translateY(-9px);
  }
}
@keyframes ps-fx-shadow {
  50% {
    transform: scaleX(0.88);
    opacity: 0.7;
  }
}

/*
 * Reduced motion: the fidgets still respond, at once; the background, the
 * float and the tilt all stop. The script also stops the tilt and the
 * staggered moves, so this is the belt to its braces.
 */
@media (prefers-reduced-motion: reduce) {
  .ps-fx-toy *,
  .ps-fx-dot span {
    transition: none !important;
    animation: none !important;
  }
  .ps-fx-tray {
    transform: none;
  }
  .ps-fx-tbtn.ps-fx-nudge {
    animation: none;
  }
}
[data-motion="reduced"] .ps-fx-toy *,
[data-motion="reduced"] .ps-fx-dot span {
  transition: none !important;
  animation: none !important;
}
[data-motion="reduced"] .ps-fx-tray {
  transform: none;
}
[data-motion="reduced"] .ps-fx-tbtn.ps-fx-nudge {
  animation: none;
}

/* ── Narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .ps-fx {
    justify-self: center;
    max-width: 420px;
  }
  .ps-fx-bg {
    top: -28px;
    left: -24px;
    right: -24px;
  }
  .ps-fx-fl {
    display: none;
  }
}
@media (max-width: 480px) {
  .ps-fx-ui {
    padding: 12px 8px;
  }
  .ps-fx-tray {
    border-radius: 34px;
    padding: 12px 12px 22px;
  }
  .ps-fx-board,
  .ps-fx-toy {
    border-radius: 24px;
  }
}
