/* ============================================================
   Codegenesis – cinematic preloader
   All styles scoped under .cg-preloader
   All @keyframes prefixed cg-
   ============================================================ */

.cg-preloader {
  --cg-amber: #FFB800;
  --cg-cyan: #00F0FF;
  --cg-violet: #7B61FF;
  --cg-white: #E8E8EC;
  --cg-bg: #05060A;

  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cg-bg);
  color: var(--cg-white);
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  -webkit-font-smoothing: antialiased;
  will-change: clip-path, opacity;
  /* start fully covering; JS drives the clip reveal on exit */
  clip-path: circle(150% at 50% 50%);
}

/* Fall back to CSS custom props from the host site if defined */
.cg-preloader {
  background: var(--bg, var(--cg-bg));
}

/* ---------- Film grain overlay (steady, subtle – not strobing) ---------- */
.cg-preloader::after {
  content: "";
  position: absolute;
  inset: -50%;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
  /* gentle drift – steady grain, no harsh strobe */
  animation: cg-grain 1.4s steps(3) infinite;
  z-index: 3;
}

@keyframes cg-grain {
  0%   { transform: translate(0, 0); }
  33%  { transform: translate(-3px, 2px); }
  66%  { transform: translate(2px, -2px); }
  100% { transform: translate(-2px, 1px); }
}

/* ---------- Scanlines ---------- */
.cg-preloader::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.5;
}

/* ---------- CRT power-on ---------- */
/* thin bright line that expands vertically to fill the frame */
.cg-crt {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  transform-origin: center center;
  background:
    radial-gradient(120% 60% at 50% 50%,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(210, 255, 245, 0.75) 22%,
      rgba(120, 200, 190, 0.25) 45%,
      transparent 70%);
}

/* brightness bloom that flares then settles */
.cg-bloom {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(70% 70% at 50% 50%,
    rgba(255, 255, 255, 0.6),
    rgba(255, 255, 255, 0) 65%);
  mix-blend-mode: screen;
}

/* faint green/white phosphor tint that fades to the normal palette */
.cg-phosphor {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(180deg,
    rgba(120, 255, 205, 0.10),
    rgba(180, 255, 235, 0.05));
  mix-blend-mode: screen;
}

/* ---------- White flash layer ---------- */
.cg-flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: #ffffff;
  opacity: 0;
  mix-blend-mode: screen;
}

/* ---------- Signal-lock RGB split blip (single) ---------- */
.cg-rgb {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  background:
    linear-gradient(90deg, rgba(255, 0, 60, 0.22), transparent 12%),
    linear-gradient(-90deg, rgba(0, 240, 255, 0.22), transparent 12%);
}

/* ---------- VHS tracking band ---------- */
/* horizontal distortion / brighter scanline band that drifts down */
.cg-track {
  position: absolute;
  left: -4%;
  top: 0;
  width: 108%;
  height: 5.5%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0.14) 40%,
      rgba(255, 255, 255, 0.22) 50%,
      rgba(255, 255, 255, 0.14) 60%,
      rgba(255, 255, 255, 0) 100%);
  mix-blend-mode: screen;
  /* ~2px chromatic offset within the band */
  box-shadow:
    2px 0 0 rgba(255, 0, 60, 0.16),
    -2px 0 0 rgba(0, 240, 255, 0.16);
  filter: blur(0.4px);
}

/* ---------- Vignette ---------- */
.cg-vignette {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(120% 120% at 50% 50%,
    transparent 55%,
    rgba(0, 0, 0, 0.35) 90%,
    rgba(0, 0, 0, 0.6) 100%);
}

/* ---------- Terminal block ---------- */
.cg-terminal {
  position: absolute;
  /* centred both axes (loading bar removed) */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: left;
  z-index: 4;
  line-height: 1.6;
  font-size: clamp(15px, 2.4vw, 26px);
  letter-spacing: 0.02em;
  white-space: pre;
  will-change: transform, filter, opacity;
  perspective: 600px;
}

@media (max-width: 720px) {
  .cg-terminal {
    transform: translate(-50%, -50%);
    top: 50%;
    font-size: clamp(13px, 4.6vw, 20px);
    text-align: left;
  }
}

.cg-line {
  display: block;
  white-space: pre;
  min-height: 1.6em;
}

/* per-character span */
.cg-ch {
  display: inline-block;
  will-change: transform, opacity, filter;
  transform: translateZ(0);
}

/* Token colors */
.cg-prompt   { color: var(--cg-cyan); }
.cg-fn       { color: var(--cg-amber); }
.cg-arg      {
  color: var(--cg-cyan);
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.55);
}
.cg-punct    { color: rgba(0, 240, 255, 0.8); }

/* build() slightly bolder w/ back shadow */
.cg-fn.cg-bold {
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(255, 184, 0, 0.18), 0 0 10px rgba(255, 184, 0, 0.3);
}

/* render() – white, heavy */
.cg-fn.cg-render {
  color: var(--cg-white);
  font-weight: 900;
  text-shadow: 0 0 14px rgba(232, 232, 236, 0.75);
}

/* subtle chromatic aberration applied to typed characters */
.cg-ch.cg-aberr {
  text-shadow:
    1px 0 rgba(255, 0, 0, 0.30),
    -1px 0 rgba(0, 255, 255, 0.30);
}

/* combine aberration with arg glow when both present */
.cg-arg.cg-aberr {
  text-shadow:
    1px 0 rgba(255, 0, 0, 0.30),
    -1px 0 rgba(0, 255, 255, 0.30),
    0 0 6px rgba(0, 240, 255, 0.55);
}

/* ---------- Cursor ---------- */
.cg-cursor {
  display: inline-block;
  color: var(--cg-white);
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.7), 0 0 2px rgba(0, 240, 255, 0.9);
  will-change: opacity;
}

/* ---------- Retro boot readout (bottom-left) ---------- */
.cg-boot {
  position: absolute;
  /* centred, sitting slightly ABOVE centre; the code lines type in just below it */
  left: 50%;
  top: calc(50% - clamp(88px, 15vh, 148px));
  transform: translateX(-50%);
  z-index: 5;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(11px, 1.5vw, 15px);
  letter-spacing: 0.06em;
  color: var(--cg-amber);
  white-space: pre;
  text-align: center;
  text-shadow: 0 0 8px rgba(255, 184, 0, 0.35);
  user-select: none;
}
.cg-boot .cg-boot-label { color: var(--cg-cyan); }
.cg-boot .cg-boot-track { color: rgba(0, 240, 255, 0.75); }
.cg-boot .cg-boot-fill  { color: var(--cg-amber); }
.cg-boot .cg-boot-pct   { color: var(--cg-white); }

/* ---------- Quiet build string (top-right) ---------- */
.cg-buildstr {
  position: absolute;
  right: clamp(14px, 4vw, 42px);
  top: clamp(14px, 4vh, 36px);
  z-index: 5;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(9px, 1.2vw, 12px);
  letter-spacing: 0.14em;
  color: rgba(0, 240, 255, 0.65);
  user-select: none;
}
.cg-buildstr .cg-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cg-amber);
  box-shadow: 0 0 8px rgba(255, 184, 0, 0.7);
  vertical-align: middle;
  margin-right: 5px;
  animation: cg-dotblink 1.4s steps(1) infinite;
}

@keyframes cg-dotblink {
  0%, 60%  { opacity: 1; }
  61%, 100% { opacity: 0.25; }
}

/* ---------- Reduced-motion wordmark + static bar ---------- */
.cg-wordmark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: clamp(20px, 4vw, 38px);
  color: var(--cg-white);
  text-align: center;
}
.cg-wordmark .cg-mark-amber { color: var(--cg-amber); }

.cg-bootbar {
  position: absolute;
  left: 50%;
  top: calc(50% + clamp(34px, 7vh, 60px));
  transform: translateX(-50%);
  z-index: 4;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(10px, 1.4vw, 14px);
  letter-spacing: 0.06em;
  white-space: pre;
  color: var(--cg-amber);
}
.cg-bootbar .cg-boot-label { color: var(--cg-cyan); }
.cg-bootbar .cg-boot-track { color: rgba(0, 240, 255, 0.75); }
.cg-bootbar .cg-boot-fill  { color: var(--cg-amber); }
.cg-bootbar .cg-boot-pct   { color: var(--cg-white); }

/* Honour OS-level reduced motion: stop grain/scanline shimmer + dot blink */
@media (prefers-reduced-motion: reduce) {
  .cg-preloader::after { animation: none; }
  .cg-preloader::before { opacity: 0.25; }
  .cg-buildstr .cg-dot { animation: none; }
}
