:root {
  --blue: #1f5fd0;
  --yellow: #fff200;
  --pink: #ff00ff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: Calibri, Carlito, "Segoe UI", sans-serif;
}
body.gated #stage,
body.gated #core,
body.gated .mq,
body.gated #peek,
body.gated #strobe,
body.gated #calm-toggle,
body.gated #mute-toggle { visibility: hidden; }

/* ---------------- gate (deliberately still) ---------------- */
#gate {
  position: fixed; inset: 0; z-index: 1000;
  background: #000; color: #fff;
  display: grid; place-items: center;
  padding: 16px; overflow: auto;
}
.gate-card {
  max-width: 620px;
  border: 6px solid #ffd400;
  background: #111;
  padding: clamp(18px, 4vw, 36px);
  text-align: center;
  font: 18px/1.5 Arial, Helvetica, sans-serif;
}
.gate-tri { font-size: 72px; line-height: 1; color: #ffd400; }
.gate-card h2 { margin: 8px 0 14px; font-size: clamp(22px, 5vw, 32px); color: #ffd400; letter-spacing: .02em; }
.gate-card p { margin: 0 0 12px; }
.gate-small { color: #bbb; font-size: 15px; }
.gate-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin: 20px 0 14px; }
.gate-buttons button {
  font: 700 17px Arial, Helvetica, sans-serif;
  padding: 14px 20px; cursor: pointer;
  border: 3px solid #fff; background: #000; color: #fff;
}
#enter-full { background: #ffd400; color: #000; border-color: #ffd400; }
.gate-buttons button:hover, .gate-buttons button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.gate-leave { color: #999; font-size: 14px; }

/* ---------------- stage ---------------- */
#stage { position: fixed; inset: 0; overflow: hidden; background: #fff; }
body.calm #stage { transition: background-color 3.5s linear; }
#mol {
  position: absolute; inset: -10%;
  background: url(assets/cutouts/molecule.png) 0 0 / 260px auto repeat;
  opacity: .25;
  animation: molmove 9s linear infinite;
}
@keyframes molmove { to { background-position: 520px 462px; } }
body.calm #mol { animation-duration: 40s; transition: opacity 3s; }
#scribble { position: absolute; inset: 0; width: 100%; height: 100%; }
#spam, #floaters { position: absolute; inset: 0; overflow: hidden; }

/* keyboard spam */
.spam {
  position: absolute;
  white-space: pre;
  line-height: 1.05;
  pointer-events: none;
  will-change: transform, opacity;
}
.spam.blink { animation: blink var(--bl, .18s) steps(1) infinite; }
@keyframes blink { 50% { visibility: hidden; } }
.spam.drift { animation: drift var(--dur) linear forwards; }
@keyframes drift { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); } }
.spam.shake { animation: shake .09s steps(2) infinite; }
@keyframes shake {
  0% { transform: translate(-3px, 2px) rotate(-1deg); }
  100% { transform: translate(3px, -2px) rotate(1deg); }
}
.spam.pop { animation: pop var(--dur) ease-out forwards; }
@keyframes pop {
  0% { transform: scale(.1); }
  15% { transform: scale(1.35) rotate(var(--rot)); }
  100% { transform: scale(1) rotate(var(--rot)); opacity: 0; }
}
body.calm .spam.blink { animation: fade 2.6s ease-in-out infinite; }
body.calm .spam.shake { animation: none; }
@keyframes fade { 50% { opacity: .15; } }

.trail {
  position: fixed; z-index: 30; pointer-events: none;
  font: 700 16px Calibri, Carlito, sans-serif;
  animation: trail .8s linear forwards;
}
@keyframes trail { to { transform: translate(var(--dx), 40px) rotate(var(--rot)); opacity: 0; } }

/* cutouts */
.floater {
  position: absolute; left: 0; top: 0;
  pointer-events: none; user-select: none;
  will-change: transform;
}
.floater img { display: block; width: 100%; height: auto; -webkit-user-drag: none; }
.floater.triple { display: flex; }
.floater.triple img { width: 42%; margin-right: -12%; flex: none; }
#floaters-top { position: fixed; inset: 0; z-index: 11; overflow: hidden; pointer-events: none; }
body.gated #floaters-top { visibility: hidden; }
.floater.over { pointer-events: auto; cursor: default; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.floater.secret { pointer-events: auto; cursor: default; -webkit-tap-highlight-color: transparent; }

/* the hat man */
.hatman svg { display: block; width: 100%; height: auto; overflow: visible; }
.hatman .eyes { filter: drop-shadow(0 0 3px #fff); }
#watcher {
  position: absolute; left: 50%; bottom: -3vh;
  width: min(44vh, 62vw);
  transform: translateX(-50%) scale(var(--s, 1));
  transform-origin: 50% 100%;
  opacity: var(--o, .22);
  transition: transform .9s linear, opacity .9s linear;
}
#watcher.close { z-index: 5; }
#peek {
  position: fixed; z-index: 12; pointer-events: none;
  width: clamp(110px, 17vw, 210px);
  transition: transform 2.8s ease-in-out;
}
#peek:not(.left):not(.right):not(.bottom) { visibility: hidden; }
#peek.fast { transition-duration: .22s; }
#peek.left { left: 0; top: 30%; transform: translateX(-105%) rotate(14deg); }
#peek.left.out { transform: translateX(-42%) rotate(14deg); }
#peek.right { right: 0; top: 22%; transform: translateX(105%) rotate(-14deg); }
#peek.right.out { transform: translateX(42%) rotate(-14deg); }
#peek.bottom { left: 12%; bottom: 0; transform: translateY(105%); }
#peek.bottom.out { transform: translateY(58%); }

/* film grain: a thin layer everywhere, plus thick patches that wander (main.js moves the mask) */
#grain { position: fixed; inset: 0; z-index: 150; pointer-events: none; overflow: hidden; }
body.gated #grain { visibility: hidden; }
#grain i {
  position: absolute; inset: 0;
  background-image: var(--grain);
  image-rendering: pixelated;
  animation: grainshift .45s steps(1) infinite;
}
#grain .g-base { opacity: .16; background-size: 256px 256px; }
#grain .g-hot { opacity: .85; background-size: 512px 512px; animation-duration: .3s; }
@keyframes grainshift {
  0% { background-position: 0 0; }
  12% { background-position: -83px 41px; }
  25% { background-position: 57px -119px; }
  37% { background-position: -161px -67px; }
  50% { background-position: 109px 93px; }
  62% { background-position: -37px 151px; }
  75% { background-position: 141px -29px; }
  87% { background-position: -101px -137px; }
}
body.calm #grain i { animation-duration: 2.4s; }

/* tunnel vision: the edges go dark and throb, in episodes (main.js keeps it on ~30% of the time) */
#tunnel {
  position: fixed; inset: -25%; z-index: 140;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.4s ease-in-out;
}
body.gated #tunnel { visibility: hidden; }
#tunnel.on { opacity: 1; }
#tunnel::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 20%, rgba(0, 0, 0, .3) 34%, rgba(0, 0, 0, .72) 50%, rgba(0, 0, 0, .94) 68%);
  animation: tunnel var(--tp, 1.1s) ease-in-out infinite alternate;
}
@keyframes tunnel {
  0% { transform: scale(1.3); opacity: .5; }
  100% { transform: scale(.9); opacity: 1; }
}

#strobe {
  position: fixed; inset: 0; z-index: 8;
  pointer-events: none;
  mix-blend-mode: difference;
  background: transparent;
}

/* marquees */
.mq {
  position: fixed; left: 0; right: 0; z-index: 9;
  height: 1.9rem; overflow: hidden; pointer-events: none;
  background: #000; color: #0f0;
  font: 700 1.2rem/1.9rem Calibri, Carlito, sans-serif;
  white-space: nowrap;
}
.mq-top { top: 0; }
.mq-bot { bottom: 0; color: var(--pink); background: #fff; }
.mq span { display: inline-block; padding-left: 100%; animation: mq 22s linear infinite; }
.mq-bot span { animation-direction: reverse; animation-duration: 31s; }
@keyframes mq { to { transform: translateX(-100%); } }
body.calm .mq span { animation-duration: 80s; }

/* ---------------- the real content ---------------- */
#core {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: 2.4rem 10px;
  pointer-events: none;
}
.win {
  pointer-events: auto;
  width: min(660px, 95vw);
  border: 2px solid #000;
  background: #d4d0c8;
  box-shadow: 9px 9px 0 #000, 18px 18px 0 var(--pink);
  animation: jit .14s steps(2) infinite;
}
@keyframes jit {
  0% { transform: translate(-1px, 1px) rotate(-.4deg); }
  100% { transform: translate(1px, -1px) rotate(.4deg); }
}
body.calm .win { animation: none; }
.win-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(#0a3fb5, #3b7be8); color: #fff;
  font: 13px "Segoe UI", Tahoma, sans-serif;
  padding: 4px 6px;
}
.win-btns i {
  display: inline-block; width: 18px; height: 16px; margin-left: 3px;
  background: #d4d0c8; color: #000; text-align: center;
  font: 700 11px/15px Arial, sans-serif; border: 1px solid #fff;
  border-right-color: #404040; border-bottom-color: #404040;
}
.win-body {
  /* paint.net's "transparent" checkerboard */
  background: repeating-conic-gradient(#fff 0 25%, #cfcfcf 0 50%) 0 0 / 20px 20px;
  padding: clamp(10px, 2.6vw, 22px);
  text-align: center;
}

h1 {
  display: inline-block; margin: 0;
  font: 900 clamp(60px, min(21vw, 22vh), 170px)/.9 Impact, Haettenschweiler, "Arial Narrow Bold", "Arial Black", sans-serif;
  letter-spacing: .02em;
  color: var(--yellow);
  background: var(--blue);
  padding: .1em .2em .14em;
  transform: rotate(-2deg);
  /* cut out with the lasso, badly */
  clip-path: polygon(1% 7%, 12% 2%, 30% 6%, 48% 1%, 66% 5%, 83% 0%, 99% 6%, 97% 30%, 100% 62%, 98% 96%, 80% 93%, 62% 100%, 41% 94%, 22% 99%, 3% 93%, 0% 60%, 2% 33%);
  text-shadow: 4px 4px 0 #000, -4px 4px 0 #000, 4px -4px 0 #000, -4px -4px 0 #000,
    0 5px 0 #000, 5px 0 0 #000, -5px 0 0 #000, 0 -5px 0 #000, 9px 9px 0 #000;
}
h1 span { display: inline-block; animation: hop .5s steps(3) infinite alternate, hue .37s steps(1) infinite; }
h1 span:nth-child(2) { animation-delay: -.12s, -.1s; }
h1 span:nth-child(3) { animation-delay: -.27s, -.2s; }
h1 span:nth-child(4) { animation-delay: -.4s, -.3s; }
@keyframes hop {
  0% { transform: translateY(6%) rotate(-5deg) scale(.96); }
  100% { transform: translateY(-7%) rotate(6deg) scale(1.07); }
}
@keyframes hue {
  0% { color: var(--yellow); }
  25% { color: #fff; }
  50% { color: #00ff00; }
  75% { color: var(--pink); }
}
body.calm h1 span { animation: hop 2.4s ease-in-out infinite alternate; }

.ca {
  margin: clamp(8px, 2vw, 16px) auto 0;
  background: #fff;
  border: 3px dashed var(--pink);
  padding: 10px;
  cursor: pointer;
}
.ca code {
  display: block;
  font: 700 clamp(12px, 2.9vw, 20px)/1.25 "Courier New", Courier, monospace;
  color: #000;
  word-break: break-all;
}
.copy {
  margin-top: 10px;
  font: 700 clamp(15px, 3vw, 20px) "Comic Sans MS", "Comic Sans", Calibri, sans-serif;
  background: #00ff00; color: #000;
  border: 3px solid #000;
  padding: 8px 20px;
  cursor: pointer;
  box-shadow: 4px 4px 0 #000;
  animation: wob 1.3s ease-in-out infinite alternate;
}
.copy:active { transform: translate(4px, 4px); box-shadow: none; }
.copy.done { background: var(--yellow); }

.links { display: flex; gap: 18px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: clamp(10px, 2.2vw, 18px); }
.btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: #000; color: #fff; text-decoration: none;
  border: 3px solid #fff; outline: 3px solid #000;
  padding: 10px 16px;
  font: 700 clamp(15px, 3vw, 20px) Arial, Helvetica, sans-serif;
  letter-spacing: .04em;
  box-shadow: 6px 6px 0 var(--pink);
  animation: wob 1.1s ease-in-out infinite alternate;
}
.btn-dex { animation-delay: -.6s; box-shadow: 6px 6px 0 #00ff00; }
.btn svg { width: 40px; height: 40px; }
.btn img { width: 40px; height: 40px; image-rendering: pixelated; }
.btn:hover, .btn:focus-visible { background: var(--pink); color: #000; }
.btn-dex:hover img, .btn-dex:focus-visible img { filter: invert(1); }
@keyframes wob {
  0% { transform: rotate(-3deg) scale(.98); }
  100% { transform: rotate(3deg) scale(1.05); }
}
body.calm .btn, body.calm .copy { animation-duration: 4s; }

#mute-toggle { bottom: calc(2.2rem + 30px); }
#calm-toggle { bottom: 2.2rem; }
#calm-toggle, #mute-toggle {
  position: fixed; left: 6px; z-index: 20;
  font: 700 12px Arial, Helvetica, sans-serif;
  background: #000; color: #fff; border: 2px solid #fff;
  padding: 5px 8px; cursor: pointer; opacity: .85;
}

/* ---------------- the secret ---------------- */
#scare {
  position: fixed; inset: 0; z-index: 100;
  display: none; overflow: hidden;
  background: #000;
}
#scare.on { display: block; }
.scare-man {
  position: absolute; left: 50%; top: 50%;
  width: min(70vh, 90vw);
  transform: translate(-50%, -40%) scale(.12);
  transform-origin: 50% 31%;
}
#scare.on .scare-man { animation: rush 3.4s cubic-bezier(.55, 0, 1, .35) forwards; }
@keyframes rush { to { transform: translate(-50%, -40%) scale(9); } }
.scare-face {
  position: absolute; left: 50%; top: 50%;
  width: min(95vh, 120vw);
  transform: translate(-50%, -50%);
  filter: contrast(2.2) brightness(1.1);
  visibility: hidden;
}
.scare-text {
  position: absolute; left: 0; right: 0; bottom: 8%;
  text-align: center; color: #f00;
  font: 900 clamp(40px, 13vw, 150px)/1 Impact, "Arial Black", sans-serif;
  text-shadow: 0 0 18px #f00;
}
body.quake #scare { animation: quake .05s steps(2) infinite; }
@keyframes quake {
  0% { transform: translate(-14px, 9px) rotate(-1.2deg); }
  100% { transform: translate(14px, -9px) rotate(1.2deg); }
}

@media (max-height: 560px) {
  .win-bar { display: none; }
  .links { margin-top: 8px; }
}
