/* ==========================================================
   Somnia — the part that goes wrong.
   <html> gets cumulative stage classes from js/core.js:
     .s1 (≥.12)  .s2 (≥.28)  .s3 (≥.45, lights out)  .s4 (≥.62)
     .s5 (≥.80)  .s6 (≥.95)  .after (point of no return)  .scared
   ========================================================== */

/* ---------- fixed atmosphere layers ---------- */
.layer { position: fixed; inset: 0; pointer-events: none; }
#grain {
  z-index: 60; background-size: 160px 160px; image-rendering: pixelated;
  opacity: clamp(0, calc((var(--ew) - .22) * .55), .32);
}
#vignette {
  z-index: 61;
  background: radial-gradient(ellipse at 50% 50%, transparent 38%, rgba(0,0,0,.65) 78%, rgba(0,0,0,.96) 100%);
  opacity: calc(clamp(0, (var(--ew) - .3) * 1.7, 1) * (.82 + var(--beat, 0) * .18));
}
.s5 #vignette { background: radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(25,0,2,.75) 72%, rgba(45,0,4,.98) 100%); }
#scanlines {
  z-index: 62; opacity: 0; transition: opacity 2s;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.28) 0 1px, transparent 1px 3px);
}
.s4 #scanlines { opacity: .4; }
#hands { z-index: 63; overflow: hidden; }
#subliminal { z-index: 97; display: none; place-items: center; background: #000; }
#subliminal.on { display: grid; }
#subliminal span { font: 900 clamp(80px, 22vw, 320px)/1 var(--font); color: #d1001c; letter-spacing: .05em; transform: scaleY(1.4); }
#subliminal canvas { width: 100vw; height: 100vh; }
#flicker { z-index: 95; background: #000; opacity: 0; }
#ghost-cursor {
  position: fixed; left: 0; top: 0; width: 22px; height: 22px; z-index: 96; pointer-events: none; opacity: 0;
  transition: opacity 1.5s; will-change: transform;
}
#ghost-cursor svg { width: 100%; height: 100%; fill: #000; stroke: #fff; stroke-width: 1.4; stroke-linejoin: round; }
#ghost-cursor.on { opacity: .75; }
#scare { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 10000; display: none; background: #000; }
#scare.on { display: block; }
html.locked, html.locked body { overflow: hidden; }

/* ---------- "nothing is quite level" ---------- */
.feat, .rev, .price, .step, .stat, .float-card, .phone, .faq details, .log-list li {
  rotate: calc(var(--rot, 0) * var(--ew) * 1deg);
}
.hid { color: transparent; font-size: .85em; }
.hid::selection { color: #ff2040; background: #000; }

/* ---------- s1: tiny wrongness ---------- */
.s1 .step.ghost { opacity: .08; }
.s1 .hypno-mark { opacity: .9; }
.s1 .rev.odd blockquote { letter-spacing: .01em; }

/* ---------- s2: unease ---------- */
.s2 .step.ghost { opacity: .45; }
.s2 .anomaly { animation: anomaly 2.4s ease-in-out infinite; }
.s2 .rev.wrong .stars { color: #b8860b; }
.s2 .i-z { animation-duration: 9s; }
.s2 .float-card { animation-duration: 14s; }
@keyframes anomaly { 50% { background: rgba(255,60,80,.12); } }

/* ---------- s3: the lights went out ---------- */
.s3 .topbar { background: #120003; color: #b8a3a6; }
.s3 .topbar b { color: #ff2a3d; }
.s3 .step.ghost { opacity: .85; background: rgba(192,0,26,.08); }
.s3 .step.ghost i { background: #8a0013; }
.s3 .rev.wrong .stars, .s3 .log .bad time, .s3 .log-list.live time { color: #e0001f; }
.s3 .rev.wrong blockquote { color: #e6c9c9; }
.s3 .hypno-line { stroke: #c0001a; }
.s3 .i-moon { fill: #9f8f86; }
.s3 .i-skin { fill: #b8a39a; }
.s3 .i-z { opacity: 0; }
.s3 .btn-primary { box-shadow: 0 10px 30px -10px #c0001a; }
.s3 .log .dup { font-style: italic; opacity: .8; }
.s3 .wake { color: #d1001c; font-weight: 800; word-break: break-all; letter-spacing: .1em; }
.s3 .glitchable { position: relative; }
.s3 .glitchable::before, .s3 .glitchable::after {
  content: attr(data-text); position: absolute; left: 0; top: 0; width: 100%; pointer-events: none;
}
.s3 .glitchable::before { color: #ff0033; animation: gl1 2.7s steps(1) infinite; opacity: .8; }
.s3 .glitchable::after { color: #00d8ff; animation: gl2 3.3s steps(1) infinite; opacity: .55; }
@keyframes gl1 {
  0%, 86%, 100% { clip-path: inset(100% 0 0 0); transform: none; }
  87% { clip-path: inset(10% 0 60% 0); transform: translate(-6px, 0); }
  90% { clip-path: inset(50% 0 20% 0); transform: translate(5px, 1px); }
  93% { clip-path: inset(30% 0 45% 0); transform: translate(-3px, -1px); }
}
@keyframes gl2 {
  0%, 80%, 100% { clip-path: inset(100% 0 0 0); transform: none; }
  81% { clip-path: inset(65% 0 5% 0); transform: translate(6px, 0); }
  84% { clip-path: inset(5% 0 70% 0); transform: translate(-5px, 0); }
  88% { clip-path: inset(40% 0 35% 0); transform: translate(3px, 2px); }
}

/* ---------- s4: wrong ---------- */
.s4 h2 {
  font-family: Georgia, "Songti SC", "STSong", "SimSun", serif;
  text-shadow: 2px 0 rgba(255,0,40,.45), -2px 0 rgba(0,190,255,.22);
}
.s4 .i-orb { fill: #c0001a; }
.s4 .i-orb-pupil { fill: #000; opacity: 1; }
.s4 .rev.wrong, .s4 .price.forever, .jit { animation: jitter .35s steps(2) infinite; }
.s4 .price.forever { box-shadow: 0 0 60px -10px #c0001a; border-color: #c0001a; }
.s4 .badge { background: #8a0013; }
.s4 .faq summary { letter-spacing: .02em; }
.s4 .eyebrow { color: #e0001f; background: rgba(192,0,26,.12); }
@keyframes jitter {
  0% { translate: 0 0; } 25% { translate: -1px 1px; } 50% { translate: 1px 0; } 75% { translate: 0 -1px; }
}

/* ---------- s5: horror ---------- */
.s5 h2 { animation: breathe 6s ease-in-out infinite; }
.s5 p, .s5 summary { text-shadow: 0 0 8px rgba(190,0,20,.25); }
.s5 .stars { color: #8a0013; }
@keyframes breathe { 50% { filter: blur(1.3px); letter-spacing: .03em; } }

/* ---------- hands on the glass ---------- */
.hand { position: absolute; width: 150px; opacity: 0; transition: opacity 4s ease-out; mix-blend-mode: screen; filter: blur(1.4px); }
.hand.on { opacity: .2; }
.hand svg { width: 100%; height: auto; }
.hand path, .hand ellipse { fill: #e8dede; }

/* ---------- point of no return (scrolled back up after the end) ---------- */
.after .i-figure { opacity: 1; }
.after .i-skin { fill: #9a8a85; }
.after .i-lid { stroke: #000; }
.after .avatar .ew, .after .avatar .pu { fill: #000 !important; }
.after .avatar .mouth { stroke: #000 !important; }
.after .stats-grid { box-shadow: 0 0 0 1px #2a0006; }

/* ---------- demo + finale ---------- */
.chat, .toast { transition: opacity .6s, transform .5s; }
.in-demo .chat, .in-demo .toast { opacity: 0 !important; pointer-events: none; }
.in-demo #grain { opacity: .07; }
.in-demo #scanlines { opacity: 0; }
.in-demo #vignette { opacity: .5; }
.in-demo .hand.on { opacity: .07; }
.demo-caption.alarm { color: #ff2a3d; }
.scared .demo-head h2 { color: #5a4a4a; }
.s6 #grain { opacity: .2; }
.finale .fin-line.in.shake { animation: jitter .2s steps(2) 6; }

/* reduce motion: keep the story, drop the shaking */
@media (prefers-reduced-motion: reduce) {
  .jit, .s4 .rev.wrong, .s4 .price.forever, .s5 h2 { animation: none !important; }
}
