/*
 * Nightmare Mode: lightweight, opt-in, CSS-animated visual apparitions.
 * Works independently of the music player. No visual effect intercepts clicks.
 */
.nm-toggle {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid rgba(166, 76, 60, .68);
  border-radius: 50px;
  background: linear-gradient(140deg, rgba(38, 7, 11, .94), rgba(7, 5, 7, .96));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .45);
  color: #f2d8ca;
  font: 700 .73rem Georgia, "Times New Roman", serif;
  letter-spacing: .055em;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
}
.nm-toggle:hover,
.nm-toggle:focus-visible {
  border-color: #d9a17d;
  background: #2e0c11;
}
.nm-toggle:focus-visible {
  outline: 2px solid #eed4a4;
  outline-offset: 3px;
}
.nm-toggle.is-active {
  border-color: rgba(232, 75, 61, .95);
  box-shadow: inset 0 0 12px rgba(155, 24, 23, .25), 0 0 13px rgba(130, 17, 22, .28);
}
.nm-toggle:disabled {
  opacity: .54;
  cursor: not-allowed;
  box-shadow: none;
}
.nm-toggle__symbol {
  color: #d06958;
  font-size: 1rem;
  line-height: 1;
}
.nm-toggle.is-active .nm-toggle__symbol {
  color: #ff897b;
  text-shadow: 0 0 8px rgba(255, 60, 42, .55);
}
.nm-toggle__state {
  color: #c6a7a0;
  font-size: .67rem;
  text-transform: uppercase;
}
.nm-toggle.is-active .nm-toggle__state { color: #ff9381; }
.nm-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}


/* Realistic, optimized photo atlas: eight portraits packed into one 22 KB WebP. */
.nightmare-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow: hidden;
  isolation: isolate;
  pointer-events: none !important;
  user-select: none;
}
.nightmare-layer * { box-sizing: border-box; pointer-events: none !important; }
.nm-photo {
  position: absolute;
  aspect-ratio: 272 / 352;
  background-image: url("nightmare-photo-atlas.webp");
  background-size: 400% 200%;
  background-repeat: no-repeat;
  will-change: transform, opacity;
  pointer-events: none;
}
.nm-photo--watcher { background-position: 0% 0%; }
.nm-photo--hand { background-position: 33.3333% 0%; }
.nm-photo--face { background-position: 66.6667% 0%; }
.nm-photo--clown { background-position: 100% 0%; }
.nm-photo--glass { background-position: 0% 100%; }
.nm-photo--lurker { background-position: 33.3333% 100%; }
.nm-photo--ward { background-position: 66.6667% 100%; }
.nm-photo--faceless { background-position: 100% 100%; }

.nm-watcher-real {
  width: clamp(175px, 25vw, 325px);
  mix-blend-mode: screen;
  opacity: 0;
  filter: brightness(.78) contrast(1.2) drop-shadow(0 0 20px #050101);
  -webkit-mask-image: radial-gradient(ellipse 92% 90% at 74% 49%, #000 50%, transparent 100%);
  mask-image: radial-gradient(ellipse 92% 90% at 74% 49%, #000 50%, transparent 100%);
}
.nm-watcher-right { right: -2%; }
.nm-watcher-left { left: -2%; }

.nm-hand-real {
  top: 0;
  width: clamp(175px, 24vw, 320px);
  mix-blend-mode: screen;
  opacity: 0;
  filter: brightness(.89) contrast(1.15);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 10%, #000 78%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 10%, #000 78%, transparent);
}
.nm-pressure-lens,
.nm-face-membrane {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 42% 35%, rgba(235,232,220,.13), transparent 39%),
    radial-gradient(ellipse at center, rgba(9,7,10,.28) 0%, rgba(28,18,20,.29) 48%, rgba(242,226,204,.13) 55%, transparent 71%);
  border: 1px solid rgba(230,217,206,.17);
  box-shadow: inset 11px 12px 28px rgba(0,0,0,.5), inset -12px -6px 19px rgba(223,201,177,.12), 0 0 18px rgba(0,0,0,.33);
  -webkit-backdrop-filter: blur(1.7px) contrast(1.18);
  backdrop-filter: blur(1.7px) contrast(1.18);
}
.nm-pressure-claw { width: min(18vw, 155px); height: min(23vw, 200px); opacity: 0; }
.nm-pressure-lens::before, .nm-face-membrane::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px solid rgba(214,187,179,.12);
  box-shadow: 0 0 17px rgba(223,213,201,.16);
}
.nm-face-real {
  width: clamp(215px, 40vw, 480px);
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 2;
  -webkit-mask-image: radial-gradient(ellipse 74% 83% at 50% 44%, #000 52%, transparent 100%);
  mask-image: radial-gradient(ellipse 74% 83% at 50% 44%, #000 52%, transparent 100%);
}
.nm-face-membrane {
  width: clamp(210px, 42vw, 485px);
  aspect-ratio: 272/352;
  z-index: 3;
  opacity: 0;
  mix-blend-mode: screen;
}

.nm-phantom-cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 26px;
  height: 36px;
  z-index: 9;
  opacity: 0;
  filter: drop-shadow(0 2px 2px #000) drop-shadow(0 0 5px rgba(195,28,22,.5));
  will-change: transform, opacity;
}
.nm-phantom-cursor svg { display: block; }

.nm-cursed-file {
  position: absolute;
  z-index: 10;
  opacity: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 116px;
  padding: 9px 5px;
  gap: 6px;
  color: #ddc4ad;
  background: rgba(15,8,10,.92);
  border: 1px solid #7a3933;
  border-radius: 7px;
  box-shadow: 0 0 18px rgba(0,0,0,.93);
  font: 700 .68rem Georgia, "Times New Roman", serif;
  letter-spacing: .04em;
  text-align: center;
  overflow-wrap: anywhere;
  transform: scale(.84);
  transition: opacity .3s ease, transform .3s ease;
}
.nm-cursed-file-symbol {
  font: 2rem/1 Georgia, serif;
  color: #bd5b4e;
  text-shadow: 0 0 6px #530a0b;
}
.nm-cursed-file.nm-file-visible { opacity: 1; transform: scale(1); }
.nm-cursed-file.nm-file-clicked { opacity: .1; transform: scale(1.15); }

.nm-archive-overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  opacity: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 14px;
  background: rgba(1,1,2,.87);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  transition: opacity .23s ease;
}
.nm-archive-open { opacity: 1; }
.nm-archive-window {
  width: min(420px, 86vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  gap: 9px;
  background: linear-gradient(145deg, #1e0d0e, #080607);
  border: 1px solid rgba(198,80,64,.67);
  box-shadow: 0 0 75px #0b0102, 0 0 45px rgba(156,32,29,.21), inset 0 0 13px #240a09;
  transform: scale(.82);
  animation: nm-window-arrival 2.8s ease-out both;
}
@keyframes nm-window-arrival {
  0% { transform: scale(.82); opacity: 0; }
  12% { transform: scale(1.04); opacity: 1; }
  30%,82% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.95); opacity: .1; }
}
.nm-archive-title,
.nm-archive-footer {
  width: 100%;
  color: #e5c6a7;
  font: 700 clamp(.63rem, 1.7vw, .78rem) Georgia, "Times New Roman", serif;
  letter-spacing: .12em;
  padding: 3px 8px;
  text-align: left;
  overflow-wrap: anywhere;
}
.nm-archive-footer {
  color: #ac4d44;
  text-align: center;
  letter-spacing: .24em;
}
.nm-popup-photo {
  position: relative;
  width: min(100%, 330px);
  max-height: min(65vh, 440px);
  flex: 0 1 auto;
  border: 1px solid rgba(105,48,49,.43);
  box-shadow: inset 0 0 18px #000, 0 0 24px #050101;
}

@media (max-width: 620px) {
  .nm-toggle { min-height: 34px; padding: 5px 9px; gap: 5px; font-size: .7rem; }
  .nm-toggle__state { font-size: .6rem; }
  .nm-watcher-real { width: clamp(165px, 46vw, 260px); }
  .nm-hand-real { width: clamp(175px, 42vw, 250px); }
  .nm-face-real { width: clamp(220px, 84vw, 400px); }
  .nm-face-membrane { width: clamp(220px, 85vw, 410px); }
  .nm-archive-window { width: min(88vw, 370px); padding: 8px; }
  .nm-popup-photo { width: min(100%, 260px); }
  .nm-archive-title { letter-spacing: .035em; }
}
@media (prefers-reduced-motion: reduce) {
  .nm-toggle { transition: none; }
  .nightmare-layer { display: none !important; }
}
@media (prefers-contrast: more) {
  .nm-toggle { border-color: currentColor; }
}


/* Haunted signal: randomized typewriter message in place of the claw event. */
.nm-glitch-screen {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: clamp(16px, 5vw, 50px);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom,
      rgba(207, 210, 210, .018) 0 1px, transparent 1px 5px),
    radial-gradient(ellipse at center,
      rgba(64, 8, 11, .66) 0%, rgba(6, 6, 8, .86) 56%, rgba(0, 0, 0, .80) 100%);
}
.nm-glitch-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .28;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg,
      transparent 0 75px, rgba(104, 16, 21, .19) 76px 78px,
      transparent 79px 150px);
}
.nm-glitch-box {
  position: relative;
  z-index: 2;
  width: min(690px, 92vw);
  padding: clamp(22px, 4vw, 44px);
  border: 1px solid rgba(183, 67, 59, .72);
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(32, 10, 14, .96), rgba(4, 5, 7, .97));
  box-shadow:
    0 0 60px 15px rgba(0, 0, 0, .84),
    0 0 30px rgba(129, 22, 19, .33),
    inset 0 0 22px rgba(118, 20, 18, .18);
  transform-origin: center;
}
.nm-glitch-label {
  margin-bottom: 18px;
  color: #bf756e;
  font: 700 .76rem/1.2 Georgia, "Times New Roman", serif;
  letter-spacing: .27em;
  text-transform: uppercase;
}
.nm-glitch-text {
  display: block;
  min-height: 3.6em;
  color: #f7e6d7;
  font: 700 clamp(1.3rem, 3.2vw, 2.4rem)/1.5 Georgia, "Times New Roman", serif;
  letter-spacing: .028em;
  text-shadow: 0 0 9px rgba(255, 235, 216, .14),
               2px 2px 2px rgba(64, 0, 0, .9);
  overflow-wrap: break-word;
}
.nm-glitch-text::after {
  content: "_";
  margin-left: 2px;
  color: #e18478;
  font-weight: 400;
  opacity: .8;
}
.nm-glitch-scan {
  position: absolute;
  z-index: 1;
  top: -14vh;
  left: 0;
  right: 0;
  height: 13vh;
  pointer-events: none;
  background: linear-gradient(to bottom,
    transparent, rgba(211, 168, 156, .07),
    rgba(170, 42, 31, .095), transparent);
  mix-blend-mode: screen;
  opacity: 0;
}
@media (max-width: 520px) {
  .nm-glitch-box { padding: 24px 19px; }
  .nm-glitch-label { font-size: .61rem; letter-spacing: .13em; }
  .nm-glitch-text { min-height: 5em; font-size: clamp(1.22rem, 5vw, 1.75rem); }
}


/* Four additional photorealistic pressing faces in one optimized WebP sheet. */
.nm-new-face {
  aspect-ratio: 272 / 352;
  background-image: url("nightmare-pressing-faces-atlas.webp");
  background-repeat: no-repeat;
  background-size: 200% 200%;
}
.nm-new-face--spider { background-position: 0% 0%; }
.nm-new-face--grinning { background-position: 100% 0%; }
.nm-new-face--stretched { background-position: 0% 100%; }
.nm-new-face--porcelain { background-position: 100% 100%; }
.nm-toggle__label { display: inline; text-transform: none; }


/* Fix mobile pressing-face apparitions: the four new artwork variants need
   absolute positioning and a centered, high-visibility viewport reveal. */
.nm-new-face {
  position: absolute;
  display: block;
  height: auto;
  aspect-ratio: 272 / 352;
  will-change: opacity, transform;
}
@media (max-width: 640px), (max-height: 500px) {
  .nm-face-real {
    position: absolute;
    width: min(88vw, 58dvh, 420px);
    aspect-ratio: 272 / 352;
    mix-blend-mode: normal;
    background-color: #080507;
    -webkit-mask-image: radial-gradient(ellipse 68% 80% at 50% 49%,
      #000 38%, rgba(0, 0, 0, .92) 54%, transparent 89%);
    mask-image: radial-gradient(ellipse 68% 80% at 50% 49%,
      #000 38%, rgba(0, 0, 0, .92) 54%, transparent 89%);
  }
  .nm-face-membrane {
    width: min(90vw, 60dvh, 430px);
    aspect-ratio: 272 / 352;
    mix-blend-mode: screen;
    -webkit-backdrop-filter: blur(.4px);
    backdrop-filter: blur(.4px);
    border-color: rgba(235, 221, 208, .25);
  }
}


/* The haunted doll: transparent cutout, walking in from the left to grab
   a simulated cursor and open a fictional file. Never blocks real input. */
.nm-doll-walker {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  transform-origin: 50% 90%;
  will-change: transform, opacity;
  filter: drop-shadow(2px 7px 12px rgba(0, 0, 0, .9))
          drop-shadow(0 0 15px rgba(84, 20, 25, .25));
}
.nm-doll-body {
  width: 100%;
  height: 100%;
  background: url("nightmare-doll.webp") center / contain no-repeat;
  transform-origin: 54% 85%;
  will-change: transform;
  pointer-events: none;
}
.nm-doll-file {
  transform: translate(-50%, -50%) scale(.9);
  opacity: 0;
  width: clamp(108px, 19vw, 144px);
  padding: 12px 7px;
  border-color: rgba(208, 112, 99, .89);
  box-shadow: 0 0 26px #080101, 0 0 20px rgba(123, 35, 38, .42);
  z-index: 6;
}
.nm-doll-file.nm-file-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.nm-doll-file.nm-file-clicked {
  transform: translate(-50%, -50%) scale(1.12);
  opacity: .1;
}
.nm-doll-cursor {
  z-index: 11;
  filter: drop-shadow(0 1px 2px #050505) drop-shadow(0 0 9px rgba(231, 143, 107, .52));
}
.nm-doll-click-ring {
  position: absolute;
  z-index: 11;
  width: 36px;
  height: 36px;
  border: 2px solid rgba(219, 133, 107, .85);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 12px rgba(164, 51, 44, .45);
  animation: nm-doll-click-ring .55s ease-out both;
}
@keyframes nm-doll-click-ring {
  from { opacity: .95; scale: .35; }
  to   { opacity: 0; scale: 2.3; }
}
@media (max-width: 640px) {
  .nm-doll-walker { filter: drop-shadow(1px 6px 9px #020101); }
  .nm-doll-file { width: 111px; padding: 9px 4px; font-size: .61rem; }
}
@media (prefers-reduced-motion: reduce) {
  .nm-doll-walker, .nm-doll-cursor, .nm-doll-click-ring {
    display: none !important;
    animation: none !important;
  }
}


/* Rare full-viewport 'Something Behind the Glass' scare. Video remains
   fully inside the webpage, silent, cancellable and accessible. */
.nm-glass-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: radial-gradient(ellipse at center, #10131a 0%, #050608 68%, #000 100%);
  overflow: hidden;
  pointer-events: none !important;
  animation: nm-glass-enter .8s ease-out both;
}
.nm-glass-video {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 1;
  pointer-events: none !important;
  background: #070a0e;
}
.nm-glass-skip {
  position: absolute;
  z-index: 2;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  pointer-events: auto !important;
  border: 1px solid rgba(216,184,161,.75);
  border-radius: 99px;
  background: rgba(11,10,12,.88);
  color: #fff4eb;
  padding: 9px 15px;
  font: 700 .8rem/1.25 system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 18px rgba(0,0,0,.8);
}
.nm-glass-skip:hover, .nm-glass-skip:focus-visible {
  background: #382327;
  outline: 2px solid #efd7ba;
  outline-offset: 2px;
}
@keyframes nm-glass-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (orientation: portrait) {
  /* Letterbox the wide original on phones instead of cropping away both hands. */
  .nm-glass-video {
    object-fit: contain;
  }
}
@media (prefers-reduced-motion: reduce) {
  .nm-glass-overlay { display: none !important; animation: none !important; }
}


/* Spider hallway video: vertical horror-film pop-up with a dimmed webpage behind it.
   Keep the entire 9:16 image (including the author website text) visible. */
.nm-hallway-overlay {
  background: rgba(0, 0, 0, .94);
  animation: nm-glass-enter .65s ease-out both;
}
.nm-hallway-video {
  inset: auto;
  top: 50%;
  left: 50%;
  width: min(430px, 92vw);
  height: min(92%, 800px);
  transform: translate(-50%, -50%);
  object-fit: contain;
  object-position: center;
  border: 1px solid rgba(178, 122, 99, .48);
  border-radius: 5px;
  box-shadow: 0 0 62px rgba(0, 0, 0, .90), 0 0 36px rgba(117, 49, 38, .22);
}
@media (max-width: 700px) {
  .nm-hallway-video {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .nm-hallway-overlay { display: none !important; animation: none !important; }
}
