:root {
  --bg: #050505;
  --fg: #d8d8d8;
  --dim: #6b6b6b;
  --red: #b3001b;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--fg);
  font-family: "Courier New", ui-monospace, monospace;
}
::selection { background: #3a0008; color: #fff; }

#noise {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; image-rendering: pixelated;
  z-index: 50; mix-blend-mode: screen; opacity: .05;
}

.screen { position: fixed; inset: 0; display: none; }
.screen.on { display: flex; }

.box { max-width: 580px; border: 1px solid #2a2a2a; background: #0a0a0a; padding: 32px; }
.box h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: .3em; color: #eee; font-weight: normal; }
.sub { margin: 0 0 20px; color: var(--dim); }
.back { color: var(--red); min-height: 0; }
.back:empty { display: none; }
.warn { color: var(--dim); font-size: 14px; line-height: 1.6; }
.warn b { color: var(--fg); }
.credit { margin: 28px 0 0; font-size: 12px; }
.credit a { color: var(--dim); text-decoration: none; }
.credit a:hover { color: var(--fg); }

button {
  font: inherit; background: #111; color: var(--fg);
  border: 1px solid #444; padding: 10px 18px; cursor: pointer; margin: 8px 8px 0 0;
}
button:hover { border-color: var(--red); color: #fff; }

#gate, #end { align-items: center; justify-content: center; padding: 24px; }

#term { padding: 32px; }
#termtext { margin: 0; font-size: 15px; line-height: 1.55; white-space: pre-wrap; color: #9a9a9a; }
#termtext::after { content: "\2588"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

#chat { flex-direction: column; max-width: 760px; margin: 0 auto; padding: 40px 24px 28px; }
#log { flex: 1; overflow-y: auto; padding-right: 8px; scrollbar-width: thin; scrollbar-color: #222 transparent; }
#log p { margin: 0 0 14px; line-height: 1.55; font-size: 17px; }
#log p.them { color: #e6e6e6; }
#log p.me { color: var(--dim); }
#log p.me::before { content: "> "; }
.choices { margin: 0 0 14px; }
#say { display: flex; gap: 10px; border-top: 1px solid #1c1c1c; padding-top: 14px; }
.prompt { color: var(--red); font-size: 17px; }
#in {
  flex: 1; background: transparent; border: 0; outline: none;
  color: #fff; font: inherit; font-size: 17px; caret-color: var(--red);
}
.hush {
  position: fixed; left: 0; right: 0; bottom: 4px; margin: 0;
  text-align: center; font-size: 13px; color: var(--bg);
}
.hush::selection { color: var(--red); background: #000; }

#face {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; background: #000;
}
#face.on { display: flex; }
#face .fl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#face .fl svg, #face .fl img { height: 94vh; max-width: 100vw; object-fit: contain; }
#face .red  { mix-blend-mode: screen; opacity: .5; filter: sepia(1) saturate(12) hue-rotate(-50deg) brightness(.8); }
#face .cyan { mix-blend-mode: screen; opacity: .45; filter: sepia(1) saturate(12) hue-rotate(150deg) brightness(.7); }
#face.on { animation: fflick .18s steps(1) infinite; }
#face.on .base  { animation: fbase .1s steps(1) infinite; }
#face.on .red   { animation: fred .09s steps(1) infinite; }
#face.on .cyan  { animation: fcyan .11s steps(1) infinite; }
#face.on .slice { animation: fslice .14s steps(1) infinite; }
@keyframes fflick { 0% { filter: none; } 30% { filter: invert(1); } 45% { filter: contrast(3) brightness(1.4); } 60% { filter: none; } }
@keyframes fbase  { 0% { transform: none; } 50% { transform: translate(6px, -4px) scale(1.03); } }
@keyframes fred   { 0% { transform: translate(-14px, 3px); } 50% { transform: translate(-6px, -5px) skewX(4deg); } }
@keyframes fcyan  { 0% { transform: translate(12px, -3px); } 50% { transform: translate(18px, 4px); } }
@keyframes fslice {
  0%  { clip-path: inset(18% 0 70% 0); transform: translateX(-40px); }
  25% { clip-path: inset(52% 0 34% 0); transform: translateX(36px); }
  50% { clip-path: inset(70% 0 12% 0); transform: translateX(-22px) scaleY(1.2); }
  75% { clip-path: inset(34% 0 50% 0); transform: translateX(50px); }
}
#flash { position: fixed; inset: 0; z-index: 70; background: #fff; opacity: 0; pointer-events: none; }
#flash.on { animation: flash .25s; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

body.glitch .screen.on, body.glitch #face { animation: jit .3s steps(3); }
body.glitch #log p { text-shadow: 2px 0 var(--red), -2px 0 #0aa; }
@keyframes jit {
  0%   { transform: translate(4px, -2px) skewX(3deg); }
  33%  { transform: translate(-5px, 3px) scaleY(1.04); }
  66%  { transform: translate(2px, 1px) skewX(-6deg); }
  100% { transform: none; }
}

#stop {
  position: fixed; top: 8px; right: 8px; z-index: 90; margin: 0;
  padding: 4px 8px; font-size: 11px; color: #444; background: transparent; border-color: #1a1a1a;
}
#pause {
  position: fixed; inset: 0; z-index: 95; display: none;
  align-items: center; justify-content: center; background: rgba(0, 0, 0, .96);
}
#pause.on { display: flex; }

@media (prefers-reduced-motion: reduce) {
  #flash.on, body.glitch .screen.on, body.glitch #face, #termtext::after,
  #face.on, #face.on .fl { animation: none; }
  #face .red, #face .cyan, #face .slice { display: none; }
}

@media print {
  body > * { display: none !important; }
  body::after { content: "you can't take me with you on paper."; display: block; color: #000; font: 24px monospace; padding: 40px; }
  body.lv9::after { content: "the fifth thing is PULSE. you can put me down now."; }
}

/* the "404" page with hop! on it */
#run {
  flex-direction: column; align-items: center; justify-content: center; padding: 24px;
  background: #fafafa; color: #555; font-family: system-ui, "Segoe UI", Arial, sans-serif;
}
.e404 { margin: 0; font-size: 72px; font-weight: 300; color: #333; letter-spacing: .05em; }
.e404-sub { margin: 0 0 12px; font-size: 20px; color: #777; }
#run .small { margin: 10px 0; font-size: 14px; color: #888; text-align: center; }
#run .fine { font-size: 11px; color: #aaa; margin-top: 18px; }
#run .fine a { color: #aaa; }
#hop {
  width: min(94vw, 900px); aspect-ratio: 640 / 200; image-rendering: pixelated;
  border: 1px solid #e2e2e2; cursor: pointer; touch-action: manipulation;
}

/* the five levels */
#whisper {
  position: fixed; left: 0; right: 0; bottom: 18%; z-index: 55; text-align: center;
  color: var(--red); font-size: 22px; letter-spacing: .2em; pointer-events: none;
  opacity: 0; transition: opacity 1.2s;
}
#whisper.on { opacity: 1; }
#gmenu {
  position: fixed; z-index: 85; display: none; min-width: 220px; padding: 4px 0;
  background: #0d0d0d; border: 1px solid #3a0008; font-size: 14px;
}
#gmenu.on { display: block; }
#gmenu div { padding: 7px 16px; color: #bbb; cursor: default; }
#gmenu div:hover { background: #3a0008; color: #fff; }

/* phone puzzles */
#whisper.flip { transform: rotate(180deg); }
#whisper.big { bottom: 40%; font-size: 44px; color: #fff; transition: none; }
#beat {
  position: fixed; left: 50%; top: 22%; z-index: 55; display: none;
  width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; background: var(--red); pointer-events: none;
}
#beat.on { display: block; }
#beat.thump { animation: thump .5s ease-out; }
@keyframes thump { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }
html.phone #chat, html.phone #log { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
@media (max-width: 600px) {
  #whisper { font-size: 16px; letter-spacing: .1em; padding: 0 12px; }
  #chat { padding: 28px 14px 16px; }
  #log p, #in { font-size: 16px; }
}

/* commands */
body.dim .screen.on { filter: brightness(.3); transition: filter 1.5s; }
body.hate .screen.on { filter: sepia(1) saturate(6) hue-rotate(-40deg) brightness(.8); }
body.hidden #log, body.hidden #say { visibility: hidden; }

.stars button { color: var(--red); letter-spacing: .1em; }
