/* Retro Room — phase 8e: the backdrop.
 *
 * Layers of early-3D-console motif over the colour wash in theme.css. Read as
 * a stack, back to front:
 *
 *   0  colour blobs        (theme.css, body::before)
 *   1  starfield           slow, far away
 *   2  perspective grid    the horizon, scrolling toward the viewer
 *   3  wireframe solids    the actual "look at our polygons" era signature
 *   4  scan streaks        fast horizontal passes
 *   5  scanlines           (theme.css, body::after)
 *
 * Everything is drawn here rather than fetched. Two reasons, and the first is
 * the one that decides it: the console's own logos, boot sequence and typefaces
 * are Sony's, and this project's own rules say to keep that branding out. The
 * era's *visual language* — wireframes, gouraud gradients, grid horizons — is
 * not owned by anyone. The second is practical: the page is COEP-isolated, so
 * every external image would need the right CORP header, and an inline shape
 * cannot 404 in six months.
 *
 * All of it is inert while a game is on screen, and under prefers-reduced-motion.
 */

#backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  /* Keeps the motifs from competing with menu text. Raised from the blobs
     alone, but still a backdrop and not a picture. */
  opacity: 0.85;
}

body.playing #backdrop { display: none; }

/* ---- 1. Starfield ---------------------------------------------------- */

.bd-stars {
  position: absolute;
  inset: -10%;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 18%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(1.2px 1.2px at 78% 12%, rgba(180, 220, 255, 0.5), transparent 60%),
    radial-gradient(1.6px 1.6px at 34% 62%, rgba(255, 255, 255, 0.4), transparent 60%),
    radial-gradient(1.2px 1.2px at 88% 54%, rgba(255, 220, 180, 0.45), transparent 60%),
    radial-gradient(1.3px 1.3px at 58% 30%, rgba(255, 255, 255, 0.35), transparent 60%),
    radial-gradient(1.1px 1.1px at 22% 84%, rgba(200, 200, 255, 0.4), transparent 60%),
    radial-gradient(1.5px 1.5px at 68% 78%, rgba(255, 255, 255, 0.3), transparent 60%),
    radial-gradient(1.2px 1.2px at 46% 8%, rgba(255, 255, 255, 0.35), transparent 60%);
  animation: bd-stars-drift 120s linear infinite;
}

@keyframes bd-stars-drift {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-6%, 3%, 0); }
}

/* ---- 2. Perspective grid --------------------------------------------- */
/* The floor of every 1995 demo. Skewed in 3D so the lines really converge
   rather than being a flat grid pretending to. */

.bd-grid {
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 120%;
  background-image:
    linear-gradient(to right, rgba(120, 190, 255, 0.24) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(120, 190, 255, 0.2) 1px, transparent 1px);
  background-size: 68px 68px;
  /* Origin at the bottom edge, so the plane recedes upward to a vanishing
     point. These three numbers are coupled: too little perspective or too
     steep an angle and the whole floor collapses into a sliver below the
     viewport, which is exactly what the first attempt did. */
  transform: perspective(460px) rotateX(70deg);
  transform-origin: 50% 100%;
  mask-image: linear-gradient(to bottom, transparent, #000 38%, #000 82%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 38%, #000 82%, transparent);
  animation: bd-grid-run 4.2s linear infinite;
}

/* Scrolling by exactly one cell means the loop is seamless — any other value
   and the grid visibly jumps every repeat. */
@keyframes bd-grid-run {
  from { background-position: 0 0; }
  to   { background-position: 0 68px; }
}

/* ---- 3. Wireframe solids --------------------------------------------- */

.bd-solid {
  position: absolute;
  color: rgba(150, 200, 255, 0.5);
}
.bd-solid svg { width: 100%; height: 100%; overflow: visible; }

/* Spread by hand rather than randomly: they sit in the margins and corners,
   away from the centre column where the menu text lives. */
.bd-solid.s1 { width: 120px; height: 120px; left: 6%;  top: 14%; color: rgba(232, 96, 116, 0.42); animation: bd-tumble-a 34s linear infinite; }
.bd-solid.s2 { width: 92px;  height: 92px;  right: 8%; top: 20%; color: rgba(120, 190, 255, 0.45); animation: bd-tumble-b 27s linear infinite; }
.bd-solid.s3 { width: 140px; height: 140px; left: 12%; bottom: 16%; color: rgba(108, 210, 140, 0.34); animation: bd-tumble-a 41s linear infinite reverse; }
.bd-solid.s4 { width: 104px; height: 104px; right: 11%; bottom: 20%; color: rgba(245, 190, 90, 0.36); animation: bd-tumble-b 31s linear infinite reverse; }
.bd-solid.s5 { width: 74px;  height: 74px;  left: 44%; top: 6%;  color: rgba(200, 170, 255, 0.3); animation: bd-tumble-b 38s linear infinite; }
.bd-solid.s6 { width: 86px;  height: 86px;  right: 30%; bottom: 8%; color: rgba(150, 220, 255, 0.28); animation: bd-tumble-a 45s linear infinite; }

/* `perspective()` first, or rotateX/rotateY just squash the shape flat
   instead of turning it — the first cut tumbled them into slivers. */
@keyframes bd-tumble-a {
  from { transform: perspective(520px) rotate(0deg) rotateX(0deg) rotateY(0deg); }
  to   { transform: perspective(520px) rotate(360deg) rotateX(360deg) rotateY(180deg); }
}
@keyframes bd-tumble-b {
  from { transform: perspective(520px) rotate(0deg) rotateY(0deg) rotateX(0deg); }
  to   { transform: perspective(520px) rotate(-360deg) rotateY(360deg) rotateX(-180deg); }
}

/* ---- 4. Scan streaks -------------------------------------------------- */
/* Fast bright passes left to right. Sparse on purpose: a streak every few
   seconds reads as a CRT artefact, a constant stream reads as a loading bar. */

.bd-streak {
  position: absolute;
  left: -30%;
  width: 26%;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(180, 225, 255, 0.85), transparent);
  filter: blur(0.4px);
  opacity: 0;
}
.bd-streak.k1 { top: 22%; animation: bd-sweep 7.5s linear infinite; }
.bd-streak.k2 { top: 54%; animation: bd-sweep 11s linear infinite 2.6s; }
.bd-streak.k3 { top: 76%; animation: bd-sweep 9.2s linear infinite 5.1s; height: 2px; }
.bd-streak.k4 { top: 38%; animation: bd-sweep 13.5s linear infinite 8.3s; }

@keyframes bd-sweep {
  0%        { transform: translate3d(0, 0, 0); opacity: 0; }
  4%        { opacity: 0.9; }
  /* The visible pass is a short window of a long cycle — that is what keeps
     them occasional rather than a procession. */
  22%       { opacity: 0.9; }
  26%, 100% { transform: translate3d(520%, 0, 0); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #backdrop * { animation: none !important; }
}

/* Narrow screens: fewer solids, and a shallower grid. At phone width the
   motifs otherwise crowd the only column the text has. */
@media (max-width: 620px) {
  .bd-solid.s5, .bd-solid.s6 { display: none; }
  .bd-solid.s1, .bd-solid.s3 { width: 92px; height: 92px; }
  .bd-solid.s2, .bd-solid.s4 { width: 74px; height: 74px; }
  .bd-grid { height: 48%; }
  #backdrop { opacity: 0.7; }
}
