:root {
  --bg:           #030817;
  --bg-2:         #061632;
  --ink:          #c9d4d6;
  --ink-dim:      #6e8389;
  --ink-faint:    #2a3d44;
  --green:        #2bff8e;
  --green-soft:   #4fdc92;
  --magenta:      #ff2d8e;
  --magenta-soft: #ff6db0;
  --violet:       #b9a8ff;
  --yellow:       #faff00;
  --line:         rgba(195, 215, 220, .12);
  --mono:         "VT323", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --mono-2:       "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --hand:         "Caveat", "Segoe Script", cursive;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: var(--bg); }
body {
  margin: 0;
  position: relative;
  font-family: var(--mono);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  isolation: isolate;
  letter-spacing: .02em;
  /* keep the pixel grid crisp — no smoothing */
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: optimizeSpeed;
}

/* ─── Background layers ─────────────────────────────────────────────── */

.bg-base {
  position: fixed; inset: 0; z-index: 0;
  background:
    linear-gradient(90deg, rgba(0, 255, 170, .025), transparent 16%, rgba(255, 45, 142, .018) 55%, transparent 82%),
    radial-gradient(120% 80% at 30% 20%, rgba(18, 72, 160, .28), transparent 58%),
    radial-gradient(100% 70% at 80% 90%, rgba(4, 34, 95, .34), transparent 62%),
    var(--bg);
  filter: contrast(1.14) saturate(1.2);
}

/* large pixel noise — drawn by JS into this canvas */
.bg-pixels {
  position: fixed; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  opacity: .96;
  mix-blend-mode: screen;
  filter: contrast(1.55) saturate(1.35);
  animation: crtPixelJitter 2.7s steps(2, end) infinite;
}

/* dark solid cover over pixels: keeps CRT texture but returns the old solid-dark feel */
.bg-dark-cover {
  position: fixed; inset: 0; z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 45% 42%, rgba(5, 18, 48, .70), rgba(2, 8, 26, .88) 72%, rgba(0, 2, 10, .96) 100%),
    rgba(2, 8, 28, .76);
}

/* moving TV snow over the low-res pixel field */
.bg-crt-static {
  position: fixed; inset: 0; z-index: 3;
  pointer-events: none;
  opacity: .16;
  mix-blend-mode: screen;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='96' height='96'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.15' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.65  0 0 0 0 1  0 0 0 0 0.86  0 0 0 .8 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
  animation: crtStatic 320ms steps(2, end) infinite;
}

/* CRT phosphor mask: tiny RGB cells that make the background less smooth */
.bg-crt-mask {
  position: fixed; inset: 0; z-index: 4;
  pointer-events: none;
  opacity: .23;
  mix-blend-mode: overlay;
  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(255, 45, 90, .22) 0 1px,
      rgba(43, 255, 142, .16) 1px 2px,
      rgba(90, 150, 255, .18) 2px 3px,
      transparent 3px 6px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, .045) 0 1px,
      transparent 1px 4px
    );
  background-size: 6px 100%, 100% 5px;
  animation: crtMaskPulse 1.8s steps(3, end) infinite;
}

/* TV scanlines */
.bg-scanlines {
  position: fixed; inset: 0; z-index: 5;
  pointer-events: none;
  background-image:
    linear-gradient(180deg, transparent 0%, rgba(255,255,255,.08) 50%, transparent 100%),
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, .075) 0 1px,
      rgba(0, 0, 0, .26) 1px 3px,
      transparent 3px 6px
    );
  background-size: 100% 140px, 100% 6px;
  mix-blend-mode: overlay;
  opacity: .82;
  animation: crtScan 5.5s linear infinite, crtFlicker 2.2s steps(5, end) infinite;
}

/* dark vignette around the edges */
.bg-vignette {
  position: fixed; inset: 0; z-index: 30;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 48%, rgba(0, 0, 0, .34) 76%, rgba(0, 0, 0, .72) 100%),
    linear-gradient(90deg, rgba(255, 45, 142, .025), transparent 35%, rgba(43, 255, 142, .02));
  mix-blend-mode: multiply;
}

@keyframes crtPixelJitter {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-2px, 1px); }
  21% { transform: translate(2px, -1px); }
  60% { transform: translate(0, 1px); }
}

@keyframes crtStatic {
  0%   { transform: translate(0, 0); background-position: 0 0; }
  25%  { transform: translate(-1px, 1px); background-position: 43px 17px; }
  50%  { transform: translate(1px, -1px); background-position: 91px 53px; }
  75%  { transform: translate(-2px, 0); background-position: 21px 88px; }
  100% { transform: translate(0, 0); background-position: 120px 120px; }
}

@keyframes crtMaskPulse {
  0%, 100% { opacity: .20; }
  45% { opacity: .27; }
  48% { opacity: .18; }
  52% { opacity: .30; }
}

@keyframes crtScan {
  from { background-position: 0 -160px, 0 0; }
  to   { background-position: 0 100vh, 0 6px; }
}

@keyframes crtFlicker {
  0%, 100% { opacity: .80; }
  12% { opacity: .68; }
  13% { opacity: .88; }
  63% { opacity: .76; }
  64% { opacity: .91; }
}

/* ─── Code rain (left + right edges) ────────────────────────────────── */

.code-rain {
  position: fixed; top: 0; bottom: 0;
  width: 130px;
  z-index: 6;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 32px;
  line-height: 28px;
  color: rgba(170, 200, 200, .22);
  overflow: hidden;
  white-space: pre;
}
.code-rain--left  { left: 0;  padding: 8px 6px 8px 4px; }
.code-rain--right { right: 0; padding: 8px 4px 8px 6px; text-align: right; }

.code-rain__col {
  position: absolute;
  top: -50%;
  width: 100%;
  animation: rainFall linear infinite;
}
@keyframes rainFall {
  from { transform: translateY(0); }
  to   { transform: translateY(50%); }
}

/* static code fragments in the empty zones */
.code-fragment {
  position: fixed;
  z-index: 7;
  margin: 0;
  font-family: var(--mono);
  font-size: 30px;
  line-height: .86;
  letter-spacing: .03em;
  color: rgba(97, 255, 166, .34);
  text-shadow:
    0 0 6px rgba(43, 255, 142, .14),
    2px 0 0 rgba(255, 45, 142, .08);
  pointer-events: none;
  user-select: none;
  white-space: pre;
  mix-blend-mode: screen;
  opacity: .72;
}
.code-fragment::after {
  content: "";
  position: absolute;
  inset: -8px;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 6px,
    rgba(255, 255, 255, .035) 6px 7px
  );
  pointer-events: none;
}
.code-fragment--left {
  left: 38px;
  top: 270px;
}
.code-fragment--right {
  right: 76px;
  top: 96px;
  text-align: left;
}

/* ─── Corner tag ────────────────────────────────────────────────────── */

.corner-tag {
  position: fixed;
  z-index: 25;
  font-size: 32px;
  color: rgba(170, 200, 200, .35);
  letter-spacing: .05em;
}
.corner-tag--tr { top: 8px; right: 18px; }

/* ─── Stage / nodes ─────────────────────────────────────────────────── */

.stage {
  position: relative;
  z-index: 20;
  width: 100vw;
  height: 100vh;
}

/* base interactive node */
.node {
  position: absolute;
  left: var(--x, 0);
  top:  var(--y, 0);
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 88px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: .01em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    color       .18s ease,
    text-shadow .18s ease,
    background  .18s ease,
    transform   .12s ease;
  outline: none;
}

.node__label { display: inline-block; }

.node__lock {
  width: 44px;
  height: 56px;
  color: var(--green);
  filter: drop-shadow(0 0 6px rgba(43, 255, 142, .35));
  flex: 0 0 auto;
}
.node__lock--sm { width: 36px; height: 44px; opacity: .9; }

/* ── variants ── */

/* .Echo — framed, top-left */
.node--framed {
  position: fixed;
  left: 100px;
  top: 60px;
  transform: none;
  padding: 24px 38px;
  font-size: 104px;
  border: 1.5px solid transparent;
  border-radius: 6px;
  box-shadow: none;
  background: transparent;
}
.node--framed .node__lock { width: 52px; height: 64px; }

/* Melanism — magenta tint */
.node--magenta { color: var(--violet); }
.node--magenta .node__lock { color: var(--magenta); filter: drop-shadow(0 0 6px rgba(255, 45, 142, .35)); }

/* Antisolar / Demercurization — magenta underline */
.node--underlined .node__label {
  position: relative;
  padding-bottom: 4px;
}
.node--underlined .node__label::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 2px;
  background: var(--magenta);
  box-shadow: 0 0 10px rgba(255, 45, 142, .6);
  transition: background .18s ease, box-shadow .18s ease;
}

/* .Print — pinned to the very bottom-left, always below .Demercurization */
.node--print {
  position: fixed;
  left: 32px;
  top: auto;
  bottom: 42px;
  transform: none;
  font-size: 88px;
  line-height: 1;
  padding: 6px 6px 8px;
  z-index: 5;
}

/* ── interaction states (apply to every node, locked or not) ── */

.node:hover,
.node:focus-visible {
  color: var(--yellow);
  text-shadow:
    0 0 6px rgba(250, 255, 0, .65),
    0 0 18px rgba(250, 255, 0, .34);
}
.node:hover .node__lock,
.node:focus-visible .node__lock { color: var(--yellow); }
.node--underlined:hover .node__label::after,
.node--underlined:focus-visible .node__label::after {
  background: var(--yellow);
  box-shadow: 0 0 10px rgba(250, 255, 0, .70);
}

.node:active,
.node.is-active {
  color: var(--magenta);
  text-shadow:
    0 0 8px rgba(255, 45, 142, .65),
    0 0 22px rgba(255, 45, 142, .35);
  outline: 1.5px solid var(--magenta);
  outline-offset: 6px;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 45, 142, .16) inset,
    0 0 22px rgba(255, 45, 142, .35),
    0 0 60px rgba(255, 45, 142, .14);
  background: rgba(28, 8, 22, .18);
  transform: translate(-50%, -50%) scale(.985);
}
.node--framed:active,
.node--framed.is-active,
.node--print:active,
.node--print.is-active { transform: scale(.985); }
.node:active .node__lock,
.node.is-active .node__lock { color: var(--magenta); }

/* locked nodes still react, but hint they're not navigable */
.node--locked { cursor: not-allowed; }

/* ─── Footer ───────────────────────────────────────────────────────── */

.foot {
  position: fixed;
  z-index: 25;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  text-align: center;
  font-size: 36px;
  line-height: 1.4;
  color: var(--ink-dim);
  letter-spacing: .03em;
  pointer-events: auto;
}
.foot__contact {
  color: var(--green-soft);
  font-size: 40px;
  text-shadow: 0 0 6px rgba(43, 255, 142, .25);
}
.foot__contact a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed rgba(43, 255, 142, .35);
}
.foot__contact a:hover { color: var(--magenta-soft); border-bottom-color: var(--magenta); }
.foot__copy   { color: var(--ink-dim); }
.foot__build  { color: var(--ink-faint); font-size: 32px; }

/* ─── Logo box (bottom-right) with TV glitch ───────────────────────── */

.logo-box {
  position: fixed;
  z-index: 25;
  right: 28px;
  bottom: 28px;
  width: 280px;
  height: 260px;
  border: 8px solid rgba(3, 9, 12, .92);
  border-radius: 22px / 18px;
  background:
    radial-gradient(ellipse at center, rgba(20, 50, 56, .42) 0%, rgba(5, 15, 20, .78) 64%, rgba(0, 0, 0, .92) 100%),
    rgba(8, 22, 28, .72);
  box-shadow:
    0 0 0 1px rgba(195, 215, 220, .22),
    0 0 0 4px rgba(20, 35, 38, .62),
    0 18px 40px rgba(0, 0, 0, .62),
    inset 0 0 12px rgba(180, 220, 225, .12),
    inset 0 0 46px rgba(0, 0, 0, .88);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 32px;
  color: var(--ink-dim);
}

.logo-box::before {
  content: "";
  position: absolute;
  inset: 7px;
  z-index: 3;
  border-radius: 16px / 13px;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 38%, transparent 0 48%, rgba(0, 0, 0, .38) 78%, rgba(0, 0, 0, .78) 100%),
    linear-gradient(135deg, rgba(255, 255, 255, .16) 0 8%, transparent 24% 100%),
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, .055) 0 1px,
      transparent 1px 4px
    );
  box-shadow:
    inset 0 0 0 1px rgba(180, 215, 220, .16),
    inset 0 0 34px rgba(0, 0, 0, .72);
  mix-blend-mode: screen;
  opacity: .72;
}

.logo-box__art {
  position: relative;
  z-index: 2;
  flex: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.logo-box__art img {
  max-width: 98%;
  max-height: 98%;
  object-fit: contain;
  mix-blend-mode: screen;
  filter:
    contrast(1.25)
    brightness(1.08)
    drop-shadow(0 0 4px rgba(210, 235, 240, .18))
    drop-shadow(0 0 10px rgba(0, 0, 0, .9));
}
.logo-box__image {
  display: block;
  transform: rotate(-2deg);
}

.logo-placeholder {
  font-family: var(--hand);
  font-weight: 700;
  font-size: 96px;
  line-height: .95;
  color: #d8e3e6;
  text-align: center;
  letter-spacing: .02em;
  text-shadow:
    0 0 1px rgba(0, 0, 0, .9),
    0 0 6px rgba(0, 0, 0, .8);
  transform: rotate(-3deg);
  user-select: none;
}

/* glitch overlays — toggled by .is-glitching on .logo-box */
.glitch {
  position: absolute; inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
}
.glitch--r { background: rgba(255,  60, 100, .55); transform: translateX(0); }
.glitch--g { background: rgba(60, 255, 160, .35); transform: translateX(0); }
.glitch--b { background: rgba(80, 140, 255, .35); transform: translateX(0); }

.glitch--bars {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 3px,
    rgba(255, 255, 255, .08) 3px 4px,
    transparent 4px 9px,
    rgba(0, 0, 0, .35) 9px 11px
  );
  mix-blend-mode: overlay;
}

.glitch--noise {
  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'/>\
<feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.7 0'/></filter>\
<rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 120px 120px;
  mix-blend-mode: screen;
}

.logo-box.is-glitching .glitch--r     { opacity: .45; transform: translateX(-4px); }
.logo-box.is-glitching .glitch--g     { opacity: .35; transform: translateX( 3px); }
.logo-box.is-glitching .glitch--b     { opacity: .35; transform: translateX(-1px) translateY(1px); }
.logo-box.is-glitching .glitch--bars  { opacity: .85; }
.logo-box.is-glitching .glitch--noise { opacity: .55; }

.logo-box.is-glitching .logo-box__art img,
.logo-box.is-glitching .logo-placeholder {
  animation: jitter .12s steps(2) 3;
  filter:
    contrast(1.45)
    brightness(1.18)
    saturate(1.1)
    drop-shadow(0 0 7px rgba(210, 235, 240, .25))
    drop-shadow(0 0 12px rgba(0, 0, 0, .9));
}
@keyframes jitter {
  0%   { transform: translate(0,0) rotate(-3deg); }
  25%  { transform: translate(-3px,1px) rotate(-3deg) skewX(-2deg); }
  50%  { transform: translate(2px,-1px) rotate(-3deg) skewX(1deg);  }
  75%  { transform: translate(-1px,2px) rotate(-3deg) skewX(-1deg); }
  100% { transform: translate(0,0) rotate(-3deg); }
}

/* horizontal "tear" line that sweeps the box during a glitch */
.logo-box.is-glitching::after {
  content: "";
  position: absolute;
  z-index: 6;
  left: 0; right: 0;
  top: var(--tearY, 40%);
  height: 6px;
  background: linear-gradient(
    to right,
    transparent,
    rgba(255, 255, 255, .35),
    transparent
  );
  mix-blend-mode: screen;
  pointer-events: none;
  animation: tear .25s linear;
}
@keyframes tear {
  0%   { transform: translateY(-30px); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translateY(30px); opacity: 0; }
}

/* ─── Responsive guardrails ────────────────────────────────────────── */

@media (max-width: 900px) {
  .node { font-size: 60px; }
  .node--framed { left: 24px; top: 24px; padding: 16px 22px; font-size: 64px; }
  .node--print  { left: 16px; top: auto; bottom: 34px; font-size: 60px; }
  .logo-box { width: 260px; height: 250px; right: 12px; bottom: 12px; font-size: 26px; }
  .logo-placeholder { font-size: 72px; }
  .foot { font-size: 28px; }
  .foot__contact { font-size: 32px; }
  .foot__build   { font-size: 24px; }
}

@media (max-width: 600px) and (orientation: portrait) {
  body {
    min-height: 100svh;
  }

  .bg-pixels {
    opacity: .78;
  }
  .bg-crt-static {
    opacity: .09;
  }
  .bg-crt-mask {
    opacity: .14;
  }
  .bg-scanlines {
    opacity: .64;
  }

  .code-rain {
    width: 70px;
    font-size: 18px;
    line-height: 16px;
    color: rgba(170, 200, 200, .11);
  }

  .code-fragment {
    z-index: 7;
    max-width: 92vw;
    font-size: 22px;
    line-height: .82;
    opacity: .18;
    color: rgba(97, 255, 166, .22);
    overflow: hidden;
  }
  .code-fragment--left {
    left: 8px;
    top: 220px;
  }
  .code-fragment--right {
    right: 8px;
    top: 420px;
  }

  .corner-tag {
    top: 6px;
    right: 8px;
    max-width: 52vw;
    font-size: 16px;
    opacity: .38;
    overflow: hidden;
    white-space: nowrap;
  }

  .stage {
    position: relative;
    z-index: 20;
    min-height: 100svh;
  }

  .node {
    font-size: clamp(38px, 12vw, 54px);
    gap: 8px;
    padding: 3px 6px;
    z-index: 4;
  }
  .node__lock {
    width: 26px;
    height: 34px;
  }
  .node__lock--sm {
    width: 20px;
    height: 26px;
  }

  .node--framed {
    left: 20px;
    top: 62px;
    padding: 10px 14px;
    font-size: clamp(44px, 13vw, 58px);
    border-radius: 4px;
  }
  .node--framed .node__lock {
    width: 28px;
    height: 36px;
  }

  .node[data-key="may"] {
    --x: 50% !important;
    --y: 20% !important;
  }
  .node[data-key="melanism"] {
    --x: 54% !important;
    --y: 28% !important;
  }
  .node[data-key="lei"] {
    --x: 50% !important;
    --y: 43% !important;
  }
  .node[data-key="knowledge"] {
    --x: 57% !important;
    --y: 54% !important;
    font-size: clamp(34px, 10.5vw, 46px);
  }
  .node[data-key="antisolar"] {
    --x: 39% !important;
    --y: 65% !important;
  }
  .node[data-key="demercurization"] {
    --x: 43% !important;
    --y: 72% !important;
    font-size: clamp(32px, 10vw, 44px);
  }

  .node--print {
    left: 16px;
    top: auto;
    bottom: calc(24px + env(safe-area-inset-bottom));
    font-size: clamp(42px, 13vw, 58px);
  }

  .foot {
    left: 50%;
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: 90vw;
    font-size: 18px;
    line-height: 1.2;
  }
  .foot__contact {
    font-size: 22px;
  }
  .foot__build {
    font-size: 15px;
  }

  .logo-box {
    right: 10px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    width: 146px;
    height: 164px;
    font-size: 15px;
    z-index: 4;
  }
  .logo-box__head,
  .logo-box__foot {
    padding: 2px 5px;
  }
  .logo-placeholder {
    font-size: 44px;
  }
}
