/* Moving grid background — grey with white highlights.
   Layers: fine drifting grid, slower major grid, a white pointer spotlight that
   lights up the lines, a soft light sweep, and a 3D floor grid at the bottom.
   Drop-in: load after your main stylesheet. */

:root {
  --bgg-top: #eceef0;
  --bgg-bottom: #d8dce0;
  --bgg-line: rgb(88 96 106 / .15);     /* fine grey lines */
  --bgg-major: rgb(88 96 106 / .26);    /* major grey lines */
  --bgg-white: #fff;
  --bgg-cell: 40px;
}

/* The grid replaces the page background, so the page itself must be see-through */
html, body {
  background: transparent !important;
}

.bg-grid {
  position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background: linear-gradient(180deg, var(--bgg-top), var(--bgg-bottom));
  --mx: 50%; --my: 28%;
}

/* Grid sheets are oversized so they can drift without showing an edge */
.bg-grid .g { position: absolute; inset: -240px; will-change: transform; }
.bg-grid .fine {
  background-image:
    linear-gradient(var(--bgg-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--bgg-line) 1px, transparent 1px);
  background-size: var(--bgg-cell) var(--bgg-cell);
  animation: bgg-fine 10s linear infinite;
}
.bg-grid .major {
  background-image:
    linear-gradient(var(--bgg-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--bgg-major) 1px, transparent 1px);
  background-size: calc(var(--bgg-cell) * 5) calc(var(--bgg-cell) * 5);
  animation: bgg-major 100s linear infinite;
}
@keyframes bgg-fine  { to { transform: translate(var(--bgg-cell), var(--bgg-cell)); } }
@keyframes bgg-major { to { transform: translate(calc(var(--bgg-cell) * -5), calc(var(--bgg-cell) * 5)); } }

/* White glow + brightened lines that follow the pointer */
.bg-grid::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(360px circle at var(--mx) var(--my), rgb(255 255 255 / .55), transparent 70%);
}
.bg-grid .spot {
  position: absolute; inset: 0;
  -webkit-mask-image: radial-gradient(circle 260px at var(--mx) var(--my), #000 0, transparent 100%);
          mask-image: radial-gradient(circle 260px at var(--mx) var(--my), #000 0, transparent 100%);
}
.bg-grid .lit {
  background-image:
    linear-gradient(var(--bgg-white) 2px, transparent 2px),
    linear-gradient(90deg, var(--bgg-white) 2px, transparent 2px);
  background-size: var(--bgg-cell) var(--bgg-cell);
  animation: bgg-fine 10s linear infinite;   /* same motion as .fine so lines stay aligned */
}

/* Slow white light sweep across the whole page */
.bg-grid .beam {
  position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 38%, rgb(255 255 255 / .5) 50%, transparent 62%);
  background-size: 260% 100%;
  animation: bgg-beam 11s ease-in-out infinite;
}
@keyframes bgg-beam { from { background-position: 130% 0; } to { background-position: -130% 0; } }

/* 3D floor grid rolling toward the viewer */
.bg-grid .floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 58%;
  perspective: 620px; perspective-origin: 50% 0;
}
.bg-grid .plane {
  position: absolute; left: -60%; right: -60%; bottom: 0; height: 150%;
  transform-origin: 50% 100%; transform: rotateX(68deg);
  background-image:
    linear-gradient(rgb(255 255 255 / .95) 2px, transparent 2px),
    linear-gradient(90deg, rgb(255 255 255 / .95) 2px, transparent 2px);
  background-size: 64px 64px;
  animation: bgg-floor 5s linear infinite;
  -webkit-mask-image: linear-gradient(to top, #000 15%, transparent 85%);
          mask-image: linear-gradient(to top, #000 15%, transparent 85%);
}
@keyframes bgg-floor { to { background-position: 0 64px; } }

/* Soft vignette keeps text areas calm */
.bg-grid::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 35%, transparent 45%, rgb(120 128 138 / .18));
}

/* Phones and tablets have no pointer: hide the spotlight */
@media (hover: none), (pointer: coarse) { .bg-grid .spot, .bg-grid::before { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .bg-grid .g, .bg-grid .beam, .bg-grid .plane { animation: none; }
}
@media print { .bg-grid { display: none; } }

