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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0606;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

body.game-running {
  cursor: crosshair;
}

/* film grain */
body::before {
  content: '';
  position: fixed;
  inset: -50%;
  z-index: 999;
  pointer-events: none;
  width: 200%;
  height: 200%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23f)' opacity='0.06'/%3E%3C/svg%3E");
  opacity: 0.4;
  mix-blend-mode: multiply;
  animation: noiseAnim 0.1s steps(1) infinite;
}

@keyframes noiseAnim {
  0% {
    transform: translate(0, 0);
  }

  20% {
    transform: translate(-12px, 8px);
  }

  40% {
    transform: translate(9px, -14px);
  }

  60% {
    transform: translate(-6px, 11px);
  }

  80% {
    transform: translate(15px, -7px);
  }

  100% {
    transform: translate(-4px, 3px);
  }
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 998;
  pointer-events: none;
  background: repeating-linear-gradient(0deg,
      transparent 0px,
      transparent 3px,
      rgba(0, 0, 0, 0.06) 3px,
      rgba(0, 0, 0, 0.06) 4px);
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(ellipse at 15% 85%, rgba(30, 0, 0, .6) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 15%, rgba(8, 0, 18, .5) 0%, transparent 50%),
    #0a0606;
}

#vignette {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 28%, rgba(0, 0, 0, .82) 100%);
}

canvas#darkness {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.scene-crack {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  border-left: 1px solid rgba(70, 35, 25, .2);
  transform-origin: top left;
}

.scene-stain {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(55, 10, 5, .18), transparent 70%);
}

.scene-scratch {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(90, 45, 30, .18), transparent);
}

.dust {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: rgba(190, 160, 130, .13);
  animation: dustUp linear infinite;
}

@keyframes dustUp {
  0% {
    opacity: 0;
    transform: translateY(0);
  }

  15% {
    opacity: .3;
  }

  85% {
    opacity: .2;
  }

  100% {
    opacity: 0;
    transform: translateY(-110px) translateX(20px);
  }
}

#blood-strip {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 6;
  pointer-events: none;
  display: flex;
}

.drip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.drip-body {
  background: #7a0000;
  width: 100%;
}

.drip-tip {
  background: #7a0000;
  border-radius: 0 0 50% 50%;
  margin-top: -1px;
}

#hud {
  position: fixed;
  top: 22px;
  left: 18px;
  z-index: 90;
  pointer-events: none;
}

#scoreVal {
  font-family: 'VT323', monospace;
  font-size: 30px;
  color: #cc2222;
  letter-spacing: 2px;
  text-shadow: 0 0 14px rgba(220, 0, 0, .45);
}

.lives-label {
  font-family: 'Special Elite', serif;
  font-size: 9px;
  color: #4a2525;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-top: 9px;
}

.lives-container {
  font-size: 20px;
  margin-top: 4px;
  letter-spacing: 2px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #060303;
  color: #c0a898;
  padding: 24px;
}

#startScreen {
  background: #060303;
  align-items: flex-start;
  justify-content: flex-start;
  padding-left: clamp(30px, 8vw, 120px);
  padding-top: clamp(20px, 4vh, 50px);
  overflow-y: auto;
}

.title-block {
  margin-bottom: 28px;
  position: relative;
}

.warn-stamp {
  display: inline-block;
  font-family: 'Special Elite', serif;
  font-size: 10px;
  letter-spacing: 6px;
  color: #cc2020;
  border: 1px solid #6a1010;
  padding: 3px 10px 2px;
  transform: rotate(-2deg);
  margin-bottom: 10px;
  opacity: 0.8;
}

.main-title {
  display: block;
  font-family: 'Creepster', cursive;
  font-size: clamp(64px, 13vw, 130px);
  color: #c01010;
  line-height: 0.9;
  letter-spacing: 4px;
  text-shadow:
    4px 4px 0 #2d0000,
    0 0 40px rgba(200, 0, 0, .4),
    0 0 80px rgba(120, 0, 0, .2);
  transform: rotate(-1.8deg) skewX(-0.5deg);
}

@keyframes flicker {

  0%,
  89%,
  100% {
    opacity: 1;
    color: #c01010;
  }

  90% {
    opacity: .65;
    color: #e03030;
    text-shadow: -4px 0 rgba(0, 255, 200, .15), 4px 0 rgba(255, 0, 80, .2);
  }

  92% {
    opacity: 1;
  }

  95% {
    opacity: .8;
  }

  97% {
    opacity: 1;
  }
}

.main-title {
  animation: flicker 7s ease-in-out infinite;
}

.tagline {
  display: block;
  font-family: 'Special Elite', serif;
  font-size: 11px;
  color: #4a3030;
  letter-spacing: 5px;
  text-transform: uppercase;
  margin-top: 8px;
  padding-left: 6px;
}

.divider {
  width: 180px;
  height: 1px;
  background: linear-gradient(90deg, #5a1010, transparent);
  margin: 22px 0;
}

#level-grid {
  width: 100%;
  max-width: 520px;
  margin-top: 4px;
}

.night-hdr {
  font-family: 'Creepster', cursive;
  font-size: 22px;
  color: #882020;
  letter-spacing: 3px;
  margin-top: 16px;
  margin-bottom: 6px;
  text-shadow: 0 0 15px rgba(150, 0, 0, .3);
}

.night-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.lvl-tile {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: #aa5050;
  border: 1px solid rgba(140, 40, 40, .4);
  cursor: pointer;
  transition: background .12s, color .12s;
  position: relative;
}

.lvl-tile:hover:not(.locked) {
  background: rgba(120, 20, 20, .28);
  color: #ee5050;
}

.lvl-tile.locked {
  color: #201010;
  border-color: rgba(50, 15, 15, .25);
  cursor: not-allowed;
}

.lvl-tile.done::after {
  content: '\2713';
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 12px;
  color: #407840;
}

.actions {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  padding: 9px 28px;
  font-family: 'VT323', monospace;
  font-size: 24px;
  letter-spacing: 3px;
  background: transparent;
  color: #bb3030;
  border-top: 1px solid rgba(160, 50, 50, .5);
  border-left: 1px solid rgba(140, 40, 40, .4);
  border-right: 1px solid rgba(180, 60, 60, .35);
  border-bottom: 2px solid rgba(160, 50, 50, .55);
  cursor: pointer;
  text-transform: uppercase;
  transition: background .18s, color .18s;
}

.btn:hover {
  background: rgba(120, 20, 20, .22);
  color: #ee5050;
}

.btn.ok {
  color: #407840;
  border-color: rgba(60, 120, 60, .45);
}

.btn.ok:hover {
  color: #60bb60;
  background: rgba(20, 70, 20, .2);
}

#ghost-caught {
  position: fixed;
  inset: 0;
  z-index: 195;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .96);
}

@keyframes caughtPulse {

  0%,
  100% {
    box-shadow: inset 0 0 80px rgba(180, 0, 0, .3);
  }

  50% {
    box-shadow: inset 0 0 160px rgba(220, 0, 0, .55);
  }
}

#ghost-caught {
  animation: caughtPulse 0.8s ease-in-out infinite;
}

#caught-ghost-img {
  width: min(55vw, 420px);
  height: min(55vw, 420px);
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid #7a0000;
  box-shadow:
    0 0 60px rgba(200, 0, 0, .6),
    0 0 120px rgba(140, 0, 0, .3),
    inset 0 0 40px rgba(0, 0, 0, .8);
  filter: contrast(1.6) brightness(0.75) saturate(0.7);
  animation: caughtImgShake 0.15s linear infinite;
}

@keyframes caughtImgShake {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }

  25% {
    transform: translate(-6px, 5px) rotate(-1deg);
  }

  50% {
    transform: translate(5px, -6px) rotate(1deg);
  }

  75% {
    transform: translate(-4px, -3px) rotate(-0.5deg);
  }

  100% {
    transform: translate(6px, 4px) rotate(0.5deg);
  }
}

#caught-name {
  font-family: 'Creepster', cursive;
  font-size: clamp(42px, 9vw, 85px);
  color: #cc1010;
  letter-spacing: 5px;
  text-shadow: 0 0 40px rgba(220, 0, 0, .6), 3px 3px 0 #2a0000;
  margin-top: 24px;
  text-transform: uppercase;
}

#caught-msg {
  font-family: 'Special Elite', serif;
  font-size: 13px;
  color: #5a3030;
  letter-spacing: 5px;
  text-transform: uppercase;
  margin-top: 10px;
}

#caught-countdown {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: #3a2020;
  letter-spacing: 3px;
  margin-top: 18px;
}

#intermissionScreen {
  background: #030804;
}

#intermissionScreen h1 {
  font-family: 'Creepster', cursive;
  font-size: clamp(42px, 9vw, 80px);
  color: #60aa60;
  letter-spacing: 4px;
  text-shadow: 0 0 30px rgba(50, 190, 50, .3);
  margin-bottom: 14px;
}

#intermissionScreen p {
  font-family: 'Special Elite', serif;
  font-size: 14px;
  color: #507050;
  line-height: 1.8;
  margin-bottom: 28px;
  max-width: 360px;
  text-align: center;
}

#gameOver h1 {
  font-family: 'Creepster', cursive;
  font-size: clamp(52px, 11vw, 105px);
  color: #be0e0e;
  letter-spacing: 4px;
  text-shadow: 0 0 50px rgba(200, 0, 0, .5);
  margin-bottom: 12px;
  animation: flicker 3s ease-in-out infinite;
}

.final-score {
  font-family: 'VT323', monospace;
  font-size: 24px;
  color: #6a4040;
  letter-spacing: 2px;
  margin-bottom: 10px;
}

#gameOver p {
  font-family: 'Special Elite', serif;
  font-size: 13px;
  color: #4a3030;
  margin-bottom: 28px;
  letter-spacing: 2px;
}

#jumpscare {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000;
}

#jumpscare img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  animation: jShake 0.1s linear infinite;
}

@keyframes jShake {
  0% {
    transform: translate(0, 0) scale(1.05);
  }

  25% {
    transform: translate(-10px, 8px) scale(1.08);
  }

  50% {
    transform: translate(8px, -10px) scale(1.04);
  }

  75% {
    transform: translate(-5px, -6px) scale(1.1);
  }

  100% {
    transform: translate(10px, 5px) scale(1.05);
  }
}

.shake {
  animation: sShake .4s ease-out;
}

@keyframes sShake {
  0% {
    transform: translate(0, 0);
  }

  20% {
    transform: translate(-15px, 10px);
  }

  40% {
    transform: translate(12px, -8px);
  }

  60% {
    transform: translate(-8px, 12px);
  }

  80% {
    transform: translate(10px, -6px);
  }

  100% {
    transform: translate(0, 0);
  }
}

.made-tag {
  position: fixed;
  bottom: 10px;
  right: 12px;
  z-index: 97;
  font-family: 'Special Elite', serif;
  font-size: 9px;
  color: rgba(70, 40, 40, .45);
  letter-spacing: 2px;
  pointer-events: none;
  transform: rotate(-1.5deg);
  text-transform: uppercase;
}