/* GTG — CRT signal loop */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

#tv {
  position: fixed;
  inset: 0;
  height: 100dvh;
  background: #000;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- picture (jitters as one unit) ---- */

#stage {
  position: absolute;
  inset: 0;
  will-change: transform;
}

#noise {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  opacity: 0;
  transition: opacity 0.35s ease-out;
}

body.booted #noise { opacity: 1; }

/* ---- logo ---- */

#logo-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#logo {
  width: clamp(160px, 34vw, 420px);
  opacity: 0;
}

body.locked #logo {
  opacity: 1;
  transition: opacity 0.12s ease-out; /* fade in only; drop is instant */
}

#logo svg {
  display: block;
  width: 100%;
  height: auto;
  fill: #e8e8e8;
  /* phosphor glow + 1px chromatic fringing */
  filter:
    drop-shadow(1px 0 0 rgba(255, 70, 70, 0.20))
    drop-shadow(-1px 0 0 rgba(70, 240, 255, 0.20))
    drop-shadow(0 0 6px rgba(232, 232, 232, 0.50))
    drop-shadow(0 0 24px rgba(232, 232, 232, 0.22));
}

/* ---- CRT chrome overlays ---- */

#scanlines,
#refresh,
#vignette,
#flicker {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.20) 2px,
    rgba(0, 0, 0, 0.20) 3px
  );
}

/* slow refresh band drifting down the screen */
#refresh {
  overflow: hidden;
}

#refresh::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 22dvh;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.045) 45%,
    rgba(255, 255, 255, 0.065) 55%,
    rgba(255, 255, 255, 0) 100%
  );
  mix-blend-mode: screen;
  animation: refresh-sweep 6.5s linear infinite;
  will-change: transform;
}

@keyframes refresh-sweep {
  0%   { transform: translateY(-30dvh); }
  100% { transform: translateY(110dvh); }
}

/* curvature illusion: rounded dark corners + inset vignette */
#vignette {
  border-radius: 2.5% / 4%;
  box-shadow:
    0 0 0 120px #000,               /* fills the square corners outside the curve */
    inset 0 0 14vmin rgba(0, 0, 0, 0.55),
    inset 0 0 4vmin rgba(0, 0, 0, 0.35);
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 58%,
    rgba(0, 0, 0, 0.18) 82%,
    rgba(0, 0, 0, 0.42) 100%
  );
}

/* global brightness flicker — felt, not seen */
#flicker {
  background: #fff;
  opacity: 0.014;
  animation: flick 2.3s steps(1, end) infinite;
}

@keyframes flick {
  0%   { opacity: 0.012; }
  6%   { opacity: 0.026; }
  8%   { opacity: 0.008; }
  21%  { opacity: 0.018; }
  34%  { opacity: 0.010; }
  47%  { opacity: 0.024; }
  53%  { opacity: 0.014; }
  68%  { opacity: 0.022; }
  74%  { opacity: 0.009; }
  89%  { opacity: 0.020; }
  100% { opacity: 0.012; }
}

/* ---- reduced motion: clean locked picture, no animation ---- */

@media (prefers-reduced-motion: reduce) {
  #noise { display: none; }
  #flicker { display: none; }
  #refresh::before { animation: none; display: none; }
  #logo { opacity: 1 !important; transition: none !important; }
}
