/* Arcade motion layer for the homepage.
   Everything here is scoped to body.arcade-motion, which arcade-motion.js adds only
   when the visitor has not asked for reduced motion. Remove the two tags and the
   page goes back to static. No libraries, no canvas, no WebGL. */

/* Pre-paint guard: the inline snippet in <head> adds .mo-js so the typed line and
   the hero counter don't flash their final text before the script runs.
   If the script never runs, the fallback animation shows them after 1.5s. */
.mo-js:not(.mo-ready) body.arcade-home .arcade-hero .lede,
.mo-js:not(.mo-ready) body.arcade-home .arcade-proof strong { visibility: hidden; animation: mo-failsafe 0s 1.5s forwards; }
@keyframes mo-failsafe { to { visibility: visible; } }

/* ---------- hero world ---------- */
body.arcade-motion .arcade-world .mo-layer { position: absolute; pointer-events: none; background-repeat: no-repeat; image-rendering: pixelated; }
body.arcade-motion .arcade-world .mo-pu { animation: mo-bob 1.1s steps(1, end) infinite; }
body.arcade-motion .arcade-world .mo-pu-chip { animation-delay: -.55s; }
@keyframes mo-bob { 0% { transform: translateY(0); } 50% { transform: translateY(-6%); } }

body.arcade-motion .arcade-world .mo-flag { transform-origin: 0 50%; animation: mo-flag .9s steps(1, end) infinite; }
@keyframes mo-flag { 0% { transform: skewY(0) scaleX(1); } 33% { transform: skewY(-4deg) scaleX(.96); } 66% { transform: skewY(3deg) scaleX(.98); } }

body.arcade-motion .arcade-world .mo-eye { background: #6c1bcf; opacity: 0; animation: mo-blink 4.2s steps(1, end) infinite 1.4s; }
body.arcade-motion .arcade-world .mo-eye::after { content: ""; position: absolute; left: 0; right: 0; top: 46%; height: 16%; background: #fefefc; }
@keyframes mo-blink { 0%, 93% { opacity: 0; } 94%, 97% { opacity: 1; } 98% { opacity: 0; } }

body.arcade-motion .arcade-world .mo-door { mix-blend-mode: screen; background: radial-gradient(closest-side, rgba(255,246,170,.9), rgba(255,214,0,.35) 60%, rgba(255,214,0,0)); animation: mo-door 1.8s steps(3, jump-none) infinite alternate; }
@keyframes mo-door { from { opacity: .15; transform: scale(.9); } to { opacity: .85; transform: scale(1.25); } }

body.arcade-motion .arcade-world .mo-spark { width: 2.2%; aspect-ratio: 1; background: #ffd600; clip-path: polygon(40% 0,60% 0,60% 40%,100% 40%,100% 60%,60% 60%,60% 100%,40% 100%,40% 60%,0 60%,0 40%,40% 40%); opacity: 0; animation: mo-spark 2.4s steps(1, end) infinite; }
body.arcade-motion .arcade-world .mo-spark.w { background: #fff; }
@keyframes mo-spark { 0%, 60% { opacity: 0; transform: scale(.5); } 64% { opacity: 1; transform: scale(.6); } 72% { opacity: 1; transform: scale(1); } 80% { opacity: 1; transform: scale(.5); } 84% { opacity: 0; } }

/* ---------- hero copy ---------- */
body.arcade-motion .arcade-hero .lede .mo-ch { visibility: hidden; }
body.arcade-motion .arcade-hero .lede .mo-ch.on { visibility: visible; }
body.arcade-motion .mo-caret { display: inline-block; width: .55em; height: .9em; margin-left: .08em; vertical-align: -.08em; background: var(--pink, #ff2e88); animation: mo-caret .9s steps(1, end) infinite; }
@keyframes mo-caret { 50% { opacity: 0; } }

body.arcade-motion .mo-num { font-variant-numeric: tabular-nums; }

body.arcade-motion .arcade-start .arcade-play { animation: mo-caret 1s steps(1, end) infinite; }
body.arcade-motion .arcade-start .mo-shine { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
body.arcade-motion .arcade-start .mo-shine::before { content: ""; position: absolute; top: 0; bottom: 0; left: -30%; width: 18%; background: rgba(255,255,255,.55); transform: skewX(-20deg); animation: mo-shine 4.5s steps(10, end) infinite 2s; }
@keyframes mo-shine { 0% { left: -30%; } 22%, 100% { left: 125%; } }

body.arcade-motion .site-head .brand:hover svg { animation: mo-hop .4s steps(4, end); }
@keyframes mo-hop { 50% { transform: translateY(-6px); } }

/* ---------- missions ---------- */
body.arcade-motion .arcade-mission:hover .arcade-mission-art,
body.arcade-motion .arcade-mission:focus-visible .arcade-mission-art { animation: mo-art .5s steps(1, end) infinite; }
@keyframes mo-art { 50% { background-position-y: 46%; } }
body.arcade-motion .arcade-mission:hover .arcade-mission-cursor,
body.arcade-motion .arcade-mission:focus-visible .arcade-mission-cursor { animation: mo-cursor .5s steps(1, end) infinite; }
@keyframes mo-cursor { 50% { transform: translateX(5px); } }

body.arcade-motion .mo-pop { position: absolute; right: 10px; top: 8px; z-index: 3; pointer-events: none; font-family: "Press Start 2P", monospace; font-size: 14px; color: var(--yellow, #ffd600); -webkit-text-stroke: 1px var(--ink, #111); text-shadow: 2px 2px 0 var(--ink, #111); animation: mo-pop .8s steps(6, end) forwards; }
@keyframes mo-pop { from { transform: translateY(0); opacity: 1; } 70% { opacity: 1; } to { transform: translateY(-46px); opacity: 0; } }

/* ---------- reveals (only applied to things below the fold at load) ---------- */
body.arcade-motion .mo-wait { clip-path: inset(0 100% 0 0); }
body.arcade-motion .mo-wait.mo-in { animation: mo-wipe .55s steps(8, end) forwards; }
@keyframes mo-wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

body.arcade-motion .mo-drop { opacity: 0; transform: translateY(28px); }
body.arcade-motion .mo-drop.mo-in { animation: mo-drop .45s steps(5, end) forwards; }
@keyframes mo-drop { to { opacity: 1; transform: translateY(0); } }

/* ---------- CRT on the dark band ---------- */
body.arcade-motion .dark { position: relative; overflow: hidden; }
body.arcade-motion .dark > .wrap { position: relative; z-index: 1; }
body.arcade-motion .dark::after { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.045) 0 1px, transparent 1px 4px); }
body.arcade-motion .dark::before { content: ""; position: absolute; left: 0; right: 0; height: 90px; top: -90px; z-index: 2; pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(255,255,255,.05), transparent); animation: mo-roll 7s linear infinite; }
@keyframes mo-roll { to { top: 100%; } }

/* ---------- power-ups ---------- */
body.arcade-motion .powerups li { position: relative; }
body.arcade-motion .powerups li::before { content: ""; position: absolute; left: -20px; top: .35em; width: 12px; height: 12px; background: var(--pink, #ff2e88); clip-path: polygon(40% 0,60% 0,60% 40%,100% 40%,100% 60%,60% 60%,60% 100%,40% 100%,40% 60%,0 60%,0 40%,40% 40%); opacity: 0; }
body.arcade-motion .powerups li:hover::before,
body.arcade-motion .powerups li:focus-within::before { animation: mo-caret .5s steps(1, end) infinite; opacity: 1; }

/* ---------- sound toggle ---------- */
.mo-sfx { display: inline-flex; margin-top: 14px; align-items: center; gap: 8px; padding: 8px 10px; border: 3px solid var(--ink, #111); background: var(--paper, #fff8e7); box-shadow: 3px 3px 0 var(--ink, #111); font: 10px/1 "Press Start 2P", monospace; color: var(--ink, #111); cursor: pointer; }
.mo-sfx:hover, .mo-sfx:focus-visible { transform: translate(1px,1px); box-shadow: 2px 2px 0 var(--ink, #111); }
.mo-sfx[aria-pressed="true"] { background: var(--yellow, #ffd600); }

@media (max-width: 560px) {
  body.arcade-motion .mo-pop { font-size: 11px; }
  .mo-sfx { padding: 7px 8px; font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  body.arcade-motion *, body.arcade-motion *::before, body.arcade-motion *::after { animation: none !important; }
  body.arcade-motion .mo-wait, body.arcade-motion .mo-drop { clip-path: none; opacity: 1; transform: none; }
}
