:root {
  --bg: #030305;
  --phosphor: #9dffb8;
  --phosphor-dim: rgba(157, 255, 184, 0.46);
  --phosphor-faint: rgba(157, 255, 184, 0.16);
  --warn: #ff3b3b;
  --violet: #7a6cff;
  --gutter: clamp(16px, 3vw, 36px);
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --crt: "VT323", ui-monospace, Menlo, monospace;
}

*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--phosphor);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) and (pointer: fine) {
  body { cursor: none; }
}

#void {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- CRT layers ---------- */

.crt,
.crt > div {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.crt { z-index: 3; }

.grain {
  inset: -50% !important;
  opacity: 0.075;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.4 -0.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 0.9s steps(6) infinite;
}

@keyframes grain {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-7%, 4%); }
  40%  { transform: translate(5%, -6%); }
  60%  { transform: translate(-3%, 8%); }
  80%  { transform: translate(8%, 2%); }
  100% { transform: translate(-5%, -4%); }
}

.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.32) 0,
    rgba(0, 0, 0, 0.32) 1px,
    transparent 1px,
    transparent 3px
  );
}

.roll {
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(157, 255, 184, 0.035) 48%,
    rgba(157, 255, 184, 0.06) 50%,
    transparent 58%
  );
  background-size: 100% 300%;
  animation: roll 9s linear infinite;
}

@keyframes roll {
  from { background-position: 0 100%; }
  to   { background-position: 0 0%; }
}

.vignette {
  background:
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 45%, rgba(0, 0, 0, 0.88) 100%);
}

/* ---------- Reticle ---------- */

#reticle {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
  will-change: transform;
}

#reticle.on { opacity: 1; }

#reticle .ring {
  position: absolute;
  left: -34px;
  top: -34px;
  width: 68px;
  height: 68px;
  border: 1px dashed var(--phosphor-dim);
  border-radius: 50%;
  animation: spin 14s linear infinite;
}

#reticle .ring.inner {
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border: 1px solid var(--phosphor);
  animation: pulse 2.4s ease-in-out infinite;
}

#reticle .tag {
  position: absolute;
  left: 44px;
  top: -8px;
  font: 13px/1 var(--crt);
  letter-spacing: 0.12em;
  color: var(--phosphor-dim);
  white-space: nowrap;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50%      { transform: scale(0.5); opacity: 0.4; }
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  padding: max(var(--gutter), env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
           max(var(--gutter), env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  font: 17px/1.35 var(--crt);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-shadow: 0 0 6px rgba(157, 255, 184, 0.45);
  animation: flicker 7s infinite;
}

.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tl, .tr { top: max(var(--gutter), env(safe-area-inset-top)); }
.bl, .br { bottom: max(var(--gutter), env(safe-area-inset-bottom)); }
.tl, .bl { left: max(var(--gutter), env(safe-area-inset-left)); }
.tr, .br { right: max(var(--gutter), env(safe-area-inset-right)); text-align: right; align-items: flex-end; }

.dim { color: var(--phosphor-dim); }
.warn { color: var(--warn); text-shadow: 0 0 6px rgba(255, 59, 59, 0.6); }

.rec {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--warn);
  text-shadow: 0 0 6px rgba(255, 59, 59, 0.6);
}

.rec .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 8px var(--warn);
  animation: blink 1.2s steps(1) infinite;
}

.rec.lost .dot { animation-duration: 0.35s; }

@keyframes blink { 50% { opacity: 0; } }

#audio {
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-shadow: inherit;
  color: var(--phosphor);
  background: transparent;
  border: 0;
  padding: 6px 0;
}

#audio:hover,
#audio:focus-visible {
  color: var(--bg);
  background: var(--phosphor);
  text-shadow: none;
  outline: none;
}

#audio[aria-pressed="true"] { color: var(--warn); }
#audio[aria-pressed="true"]:hover { color: var(--bg); background: var(--warn); }

/* ---------- Center ---------- */

.center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92vw, 900px);
  transform: translate(-50%, -50%);
  text-align: center;
}

.glitch {
  position: relative;
  margin: 0;
  font: 400 clamp(72px, 17vw, 230px)/0.9 var(--crt);
  letter-spacing: 0.18em;
  padding-left: 0.18em; /* balance trailing letter-spacing */
  color: rgba(214, 255, 225, 0.82);
  text-shadow:
    -2px 0 rgba(255, 42, 74, 0.55),
     2px 0 rgba(42, 240, 255, 0.45),
     0 0 24px rgba(157, 255, 184, 0.35),
     0 0 80px rgba(122, 108, 255, 0.35);
  mix-blend-mode: screen;
  user-select: none;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  padding-left: 0.18em;
  clip-path: inset(0 0 100% 0);
}

.glitch::before {
  color: #ff2a4a;
  animation: slice-a 4.3s infinite steps(1);
}

.glitch::after {
  color: #2af0ff;
  animation: slice-b 5.1s infinite steps(1);
}

@keyframes slice-a {
  0%, 88%  { clip-path: inset(0 0 100% 0); transform: none; }
  89%      { clip-path: inset(12% 0 70% 0); transform: translate(-9px, 0); }
  91%      { clip-path: inset(58% 0 22% 0); transform: translate(7px, 0); }
  93%      { clip-path: inset(34% 0 50% 0); transform: translate(-4px, 0); }
  95%      { clip-path: inset(80% 0 4% 0);  transform: translate(11px, 0); }
  97%      { clip-path: inset(0 0 100% 0); }
}

@keyframes slice-b {
  0%, 90%  { clip-path: inset(0 0 100% 0); transform: none; }
  91%      { clip-path: inset(66% 0 18% 0); transform: translate(8px, 0); }
  93%      { clip-path: inset(6% 0 82% 0);  transform: translate(-10px, 0); }
  96%      { clip-path: inset(44% 0 40% 0); transform: translate(5px, 0); }
  98%      { clip-path: inset(0 0 100% 0); }
}

body.glitching .glitch {
  transform: skewX(-8deg) translateX(6px);
  filter: blur(0.6px);
}

body.glitching .hud { transform: translateX(-4px); filter: brightness(1.5); }

.log {
  margin: clamp(18px, 3vh, 34px) auto 0;
  min-height: 2.8em;
  max-width: 44ch;
  font: 300 clamp(12px, 1.6vw, 15px)/1.5 var(--mono);
  letter-spacing: 0.08em;
  color: var(--phosphor-dim);
  text-shadow: 0 0 6px rgba(157, 255, 184, 0.3);
}

.caret { animation: blink 1s steps(1) infinite; color: var(--phosphor); }

.back { margin: 18px 0 0; }

.back a {
  pointer-events: auto;
  color: var(--phosphor);
  text-decoration: none;
  font: 18px var(--crt);
  letter-spacing: 0.16em;
  padding: 4px 8px;
}

.back a:hover,
.back a:focus-visible {
  color: var(--bg);
  background: var(--phosphor);
  outline: none;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  41%      { opacity: 1; }
  42%      { opacity: 0.72; }
  43%      { opacity: 1; }
  77%      { opacity: 1; }
  77.5%    { opacity: 0.6; }
  78%      { opacity: 0.95; }
  78.6%    { opacity: 0.7; }
  79%      { opacity: 1; }
}

.noscript {
  position: fixed;
  inset: auto 0 45% 0;
  text-align: center;
  font: 20px var(--crt);
  letter-spacing: 0.14em;
  z-index: 5;
}

@media (max-width: 560px) {
  .hud { font-size: 15px; }
  .hide-sm { display: none; }
  .glitch { letter-spacing: 0.1em; padding-left: 0.1em; }
  .glitch::before, .glitch::after { padding-left: 0.1em; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .roll, .hud, .glitch::before, .glitch::after, #reticle .ring { animation: none; }
}
