@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&family=IBM+Plex+Mono:wght@400;500&display=swap");

:root {
  /* Dream Workshop — liminal archive tokens */
  --bg: #080808;
  --bg-1: #101010;
  --bg-2: #101010;
  --bg-3: #141414;
  --panel: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.05);
  --text: #eaeaea;
  --text-dim: #8c8c8c;
  --text-faint: #5e5e5e;
  --accent: #7a8471;
  --accent-2: #a8a18f;
  --danger: #6e4f4f;
  --danger-text: #9a7575;
  --hover: rgba(255, 255, 255, 0.08);
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: 0.22s ease;

  /* Legacy aliases used across existing WAKING_? rules */
  --ink: var(--text);
  --dim: var(--text-dim);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 300;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

body:active {
  cursor: grabbing;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- Flash / glitch layer (driven from JS during the wake-in) ---- */
#flash {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(120, 0, 10, 0.0) 30%, rgba(90, 0, 8, 0.9) 100%);
  mix-blend-mode: screen;
}

/* full white blast for per-frame "white flash" effects */
#whiteflash {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  background: #ffffff;
}

/* signal interference: crawling TV static + scanlines, flickered in just before
   the frame blacks out */
#interference {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  /* multiply = DARKENS the scene: a failing/broken light, not white snow */
  mix-blend-mode: multiply;
  background-color: #000;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.85) 0, rgba(0, 0, 0, 0.85) 1px, rgba(0, 0, 0, 0.1) 1px, rgba(0, 0, 0, 0.1) 3px);
  background-size: 140px 140px, 100% 3px;
  animation: interf-roll 0.1s steps(2) infinite;
}
@keyframes interf-roll {
  0% {
    background-position: 0 0, 0 0;
  }
  50% {
    background-position: 18px -22px, 0 -2px;
  }
  100% {
    background-position: -14px 30px, 0 1px;
  }
}

/* faint crawling scanlines for an analog-horror unease */
#scanlines {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.06;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.08) 0px,
    rgba(255, 255, 255, 0.08) 1px,
    transparent 2px,
    transparent 3px
  );
  animation: scan 8s linear infinite;
}

@keyframes scan {
  to {
    background-position: 0 120px;
  }
}

/* DreamDistortion — brief dream-signal glitches (non-blocking) */
#dream-distortion {
  position: fixed;
  inset: 0;
  z-index: 305;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s linear;
}
#dream-distortion.active {
  opacity: 1;
}
#dream-distortion.hidden {
  display: none;
}
#dream-distortion-noise {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  image-rendering: pixelated;
  mix-blend-mode: soft-light;
  object-fit: cover;
}
#dream-distortion.fx-vhs #dream-distortion-noise {
  opacity: 0.28;
}
#dream-distortion-chroma {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  --dd-chroma: 3px;
}
#dream-distortion.fx-chroma #dream-distortion-chroma {
  opacity: 1;
}
#dream-distortion-chroma::before,
#dream-distortion-chroma::after {
  content: "";
  position: absolute;
  inset: 0;
}
#dream-distortion-chroma::before {
  box-shadow: inset var(--dd-chroma) 0 0 rgba(255, 52, 68, 0.2);
  mix-blend-mode: screen;
  transform: translateX(calc(var(--dd-chroma) * -0.4));
}
#dream-distortion-chroma::after {
  box-shadow: inset calc(var(--dd-chroma) * -1) 0 0 rgba(48, 200, 255, 0.18);
  mix-blend-mode: screen;
  transform: translateX(calc(var(--dd-chroma) * 0.4));
}
body.dream-distortion-active #scanlines {
  animation-duration: 1.6s;
}
body.blackout-active #dream-distortion {
  visibility: hidden !important;
  pointer-events: none !important;
}

/* ---- Reticle + gaze ring ---- */
#reticle {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.35;
  transition: opacity 0.6s ease;
}

#reticle.active {
  opacity: 1;
}

#reticle svg {
  position: absolute;
  inset: 0;
}

#reticle .ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 2;
}

#gaze-ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 0 164;
  filter: drop-shadow(0 0 6px var(--accent));
  transition: stroke-dasharray 0.08s linear;
}

#reticle .dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

/* ---- Whisper (cold, liminal, flickering — never italic) ---- */
#whisper {
  position: fixed;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(760px, 88vw);
  text-align: center;
  font-family: var(--mono);
  font-weight: 400;
  font-style: normal;
  text-transform: lowercase;
  font-size: clamp(1rem, 2.6vw, 1.4rem);
  line-height: 1.6;
  letter-spacing: 1.5px;
  color: var(--text);
  text-shadow:
    0 0 22px rgba(0, 0, 0, 0.95),
    0 0 10px rgba(234, 234, 234, 0.12),
    0 1px 2px rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
}

#whisper.show {
  animation: whisper 7s steps(60) forwards, whisperGlitch 0.9s steps(2) infinite;
}

@keyframes whisper {
  0% {
    opacity: 0;
    filter: blur(3px);
  }
  6% {
    opacity: 0.32;
  }
  9% {
    opacity: 0.95;
    filter: blur(0);
  }
  11% {
    opacity: 0.48;
  }
  14% {
    opacity: 1;
  }
  82% {
    opacity: 1;
  }
  88% {
    opacity: 0.2;
  }
  92% {
    opacity: 0.7;
  }
  100% {
    opacity: 0;
    filter: blur(2px);
  }
}

/* L5 finale — urgent flashing escape captions */
#l5-flash-caption {
  position: fixed;
  inset: 0;
  z-index: 48;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: 2rem;
}

#l5-flash-caption.hidden {
  display: none;
}

#l5-flash-caption-text {
  margin: 0;
  max-width: min(920px, 92vw);
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.1rem, 3.2vw, 2rem);
  line-height: 1.35;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #ff2a2a;
  text-shadow:
    0 0 12px rgba(255, 40, 40, 0.95),
    0 0 28px rgba(255, 0, 0, 0.55),
    0 0 48px rgba(0, 0, 0, 0.9);
  opacity: 0;
}

#l5-flash-caption.flash-on #l5-flash-caption-text {
  animation: l5FlashCaption 2.2s steps(2, end) infinite;
}

@keyframes l5FlashCaption {
  0%,
  45% {
    opacity: 1;
    filter: blur(0);
  }
  50%,
  100% {
    opacity: 0.08;
    filter: blur(1px);
  }
}

/* faint chromatic stutter, like a failing signal */
@keyframes whisperGlitch {
  0%,
  96%,
  100% {
    text-shadow:
      0 0 22px rgba(0, 0, 0, 0.95),
      0 0 10px rgba(234, 234, 234, 0.12),
      0 1px 2px rgba(0, 0, 0, 0.85);
    transform: translateX(-50%);
  }
  97% {
    text-shadow: -2px 0 rgba(255, 60, 90, 0.55), 2px 0 rgba(60, 200, 255, 0.5),
      0 0 22px rgba(0, 0, 0, 0.95), 0 0 10px rgba(234, 234, 234, 0.12);
    transform: translateX(calc(-50% + 1px));
  }
  98% {
    text-shadow: 2px 0 rgba(255, 60, 90, 0.55), -2px 0 rgba(60, 200, 255, 0.5),
      0 0 22px rgba(0, 0, 0, 0.95), 0 0 10px rgba(234, 234, 234, 0.12);
    transform: translateX(calc(-50% - 1px));
  }
}

/* ---- Threshold prompt ---- */
#threshold-prompt {
  position: fixed;
  top: 62%;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  font-size: clamp(0.8rem, 2.5vw, 0.9rem);
  font-weight: 500;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
  text-shadow:
    0 0 24px rgba(0, 0, 0, 0.94),
    0 0 14px rgba(234, 234, 234, 0.12),
    0 2px 4px rgba(0, 0, 0, 0.85);
}

#threshold-prompt.show {
  opacity: 0.98;
  transform: translateX(-50%) translateY(0);
}

/* ---- HUD ---- */
#hud {
  position: fixed;
  top: 22px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 26px;
  pointer-events: none;
  mix-blend-mode: screen;
}
#hud.hidden {
  display: none;
}

#progress {
  font-size: 0.68rem;
  letter-spacing: 4px;
  color: var(--dim);
}

#lucidity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lucidity-label {
  font-size: 0.6rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--dim);
}

.lucidity-bar {
  width: 120px;
  height: 3px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}

#lucidity-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 10px var(--accent);
  transition: width 2.5s ease;
}

/* ---- Objective ---- */
#objective {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: clamp(0.78rem, 2.4vw, 0.88rem);
  font-weight: 500;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  text-shadow:
    0 0 24px rgba(0, 0, 0, 0.96),
    0 0 14px rgba(234, 234, 234, 0.12),
    0 2px 4px rgba(0, 0, 0, 0.88);
  transition: opacity 0.6s ease, color 0.4s ease;
  text-align: center;
  white-space: nowrap;
}

#objective.show {
  opacity: 1;
}

#objective.open {
  color: var(--accent-2);
  text-shadow:
    0 0 22px rgba(0, 0, 0, 0.92),
    0 0 12px rgba(168, 161, 143, 0.22),
    0 1px 3px rgba(0, 0, 0, 0.8);
}

/* ---- Hint button + panel ---- */
#hint-btn {
  position: fixed;
  top: max(52px, calc(12px + env(safe-area-inset-top)));
  right: max(22px, calc(12px + env(safe-area-inset-right)));
  z-index: 12;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.62rem;
  line-height: 1;
  cursor: pointer;
  transition: opacity var(--ease), border-color var(--ease), color var(--ease), background var(--ease);
}
#hint-btn:hover {
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text);
  background: var(--hover);
}
#hint-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--panel);
}
#hint-btn.hidden {
  display: none;
}

#hint-panel {
  position: fixed;
  top: max(52px, calc(12px + env(safe-area-inset-top)));
  right: max(58px, calc(48px + env(safe-area-inset-right)));
  z-index: 13;
  width: min(280px, calc(100vw - 80px));
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 0.58rem;
  line-height: 1.6;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#hint-panel.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}
#hint-panel.hidden {
  display: none;
}
#hint-text {
  margin: 0;
  white-space: pre-line;
}
#hint-panel.open #hint-text {
  color: var(--accent-2);
  text-shadow: none;
}

/* ---- Shared game UI (inputs, buttons, bottom bars) ---- */
.game-ui-bar {
  position: fixed;
  bottom: max(18px, calc(10px + env(safe-area-inset-bottom)));
  right: max(18px, calc(10px + env(safe-area-inset-right)));
  left: auto;
  top: auto;
  transform: none;
  z-index: 12;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 0;
  background: transparent;
  border: none;
  backdrop-filter: none;
  box-shadow: none;
  pointer-events: all;
}
.game-ui-bar.hidden {
  display: none;
}

.game-ui-countdown {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
  min-width: 3.2em;
}
.game-ui-countdown.urgent {
  color: var(--danger-text);
  animation: countdown-pulse 0.8s ease infinite;
}

.game-ui-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.game-ui-input {
  width: 108px;
  padding: 5px 8px;
  font-family: var(--font);
  font-size: 0.58rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
}
.game-ui-input::placeholder {
  color: var(--text-faint);
  opacity: 0.65;
  letter-spacing: 0.06em;
}
.game-ui-input:focus {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.45);
}

.game-ui-btn {
  padding: 5px 10px;
  font-family: var(--font);
  font-size: 0.54rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease), opacity var(--ease);
  appearance: none;
  -webkit-appearance: none;
}
.game-ui-btn:hover {
  border-color: rgba(255, 255, 255, 0.14);
  background: var(--hover);
  color: var(--text);
}

/* ---- Eyelid close / open (gradual dark, not instant cut) ---- */
#eye-close {
  position: fixed;
  inset: 0;
  z-index: 22;
  pointer-events: none;
  overflow: hidden;
}
#eye-close.hidden {
  display: none;
}
.eye-close-lid {
  position: absolute;
  left: 0;
  width: 100%;
  height: 51%;
  background: #000;
  transition: transform 0.95s cubic-bezier(0.42, 0, 0.58, 1);
  will-change: transform;
}
.eye-close-lid.top {
  top: 0;
  transform: translateY(-100%);
  border-radius: 0 0 48% 48% / 0 0 10vh 10vh;
}
.eye-close-lid.bottom {
  bottom: 0;
  transform: translateY(100%);
  border-radius: 48% 48% 0 0 / 10vh 10vh 0 0;
}
#eye-close.active .eye-close-lid.top,
#eye-close.active .eye-close-lid.bottom {
  transform: translateY(0);
}
#eye-close.opening .eye-close-lid.top {
  transform: translateY(-100%);
}
#eye-close.opening .eye-close-lid.bottom {
  transform: translateY(100%);
}

/* ---- Level 1 quest overlays ---- */
#l1-blackout {
  position: fixed;
  inset: 0;
  z-index: 330;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(6vh, 24px) max(5vw, 20px);
  background: #000;
  pointer-events: all;
}
#l1-blackout .l1-blackout-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(38em, 92vw);
  text-align: center;
}
#l1-blackout.hidden {
  display: none;
}
#l1-blackout-text {
  font-family: var(--mono);
  font-size: clamp(0.72rem, 2.2vw, 0.95rem);
  line-height: 1.8;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-align: center;
  white-space: pre-line;
  margin: 0;
  width: 100%;
  opacity: 0;
  transition: opacity 1s ease 0.2s;
}
#l1-blackout-text.show {
  opacity: 1;
}
#l1-blackout-continue {
  position: relative;
  bottom: auto;
  right: auto;
  z-index: 281;
  margin: 2rem 0 0;
  opacity: 0;
  transition: opacity 0.7s ease 0.5s;
}
#l1-blackout-continue.show {
  opacity: 1;
}
#l1-blackout-continue.hidden {
  display: none;
}

/* Narrative interstitials between chapters (typewriter + subtle glitch) */
#l1-blackout-chapter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1.75rem;
  width: 100%;
}
#l1-blackout-chapter.hidden {
  display: none;
}
#l1-blackout-chapter-label {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(0.62rem, 1.8vw, 0.74rem);
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--text-faint);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.1s ease, transform 1.1s ease;
}
#l1-blackout-chapter-label.show {
  opacity: 1;
  transform: none;
}
#l1-blackout-chapter-title {
  margin: 0;
  font-family: "Special Elite", "Courier New", var(--mono);
  font-size: clamp(1.35rem, 4.8vw, 2.15rem);
  line-height: 1.15;
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow:
    0 0 28px rgba(234, 234, 234, 0.12),
    0 0 2px rgba(255, 255, 255, 0.35);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1.2s ease 0.1s, transform 1.2s ease 0.1s;
}
#l1-blackout-chapter-title.show {
  opacity: 1;
  transform: none;
}
#l1-blackout.narrative-interstitial #l1-blackout-text {
  font-family: "Special Elite", "Courier New", var(--mono);
  font-size: clamp(0.78rem, 2.4vw, 1.02rem);
  line-height: 1.85;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-shadow:
    0 0 18px rgba(140, 140, 140, 0.1),
    1px 0 0 rgba(255, 255, 255, 0.03),
    -1px 0 0 rgba(122, 132, 113, 0.08);
  animation: narrative-text-in 1.4s ease both;
}
#l1-blackout.narrative-interstitial #l1-blackout-text.show {
  animation: narrative-text-in 1.4s ease both, narrative-glitch 4.5s ease-in-out 1.6s infinite;
}
#l1-blackout.narrative-interstitial #l1-blackout-continue {
  font-family: var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
}
@keyframes narrative-text-in {
  0% {
    opacity: 0;
    filter: blur(2px);
    transform: translateY(6px);
  }
  35% {
    opacity: 0.7;
    filter: blur(0.5px);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: none;
  }
}
@keyframes narrative-glitch {
  0%,
  92%,
  100% {
    text-shadow:
      0 0 18px rgba(140, 140, 140, 0.1),
      1px 0 0 rgba(255, 255, 255, 0.04),
      -1px 0 0 rgba(122, 132, 113, 0.08);
    transform: none;
  }
  93% {
    text-shadow:
      -2px 0 rgba(168, 161, 143, 0.35),
      2px 0 rgba(122, 132, 113, 0.2);
    transform: translateX(-1px);
  }
  94% {
    text-shadow:
      2px 0 rgba(168, 161, 143, 0.28),
      -1px 0 rgba(122, 132, 113, 0.22);
    transform: translateX(1px);
  }
  95% {
    transform: none;
  }
}

/* Brief non-blocking horror text flashes (see js/disturb-flash.js) */
#disturb-flash {
  position: fixed;
  inset: 0;
  z-index: 318;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.04s linear;
}
#disturb-flash.show {
  opacity: 1;
}
#disturb-flash.hidden {
  display: none;
}
#disturb-flash-text {
  margin: 0;
  max-width: min(92vw, 34rem);
  font-family: var(--mono);
  font-size: clamp(0.72rem, 2.4vw, 0.95rem);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.32em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  text-shadow:
    0 0 22px rgba(0, 0, 0, 0.1),
    0 0 2px rgba(255, 255, 255, 0.15);
}
#disturb-flash.show #disturb-flash-text {
  animation: disturb-glitch 0.55s steps(2, end) infinite;
}

/* FlashFrameManager — subliminal fullscreen frames (non-blocking) */
#flash-frame {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  pointer-events: none;
  opacity: 1;
}
#flash-frame.hidden {
  display: none;
}
#flash-frame.show {
  display: flex;
}
#flash-frame-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
}

@keyframes disturb-glitch {
  0%,
  88%,
  100% {
    opacity: 1;
    transform: none;
    text-shadow:
      0 0 18px rgba(210, 214, 224, 0.1),
      1px 0 rgba(255, 255, 255, 0.05);
  }
  90% {
    opacity: 0.92;
    transform: translateX(-1px);
    text-shadow:
      -2px 0 rgba(168, 161, 143, 0.35),
      2px 0 rgba(122, 132, 113, 0.2);
  }
  92% {
    opacity: 0.96;
    transform: translateX(1px);
    text-shadow:
      2px 0 rgba(168, 161, 143, 0.28),
      -1px 0 rgba(122, 132, 113, 0.22);
  }
}

/* DreamMessageManager — floating psychological text (non-blocking) */
#dream-message {
  position: fixed;
  inset: 0;
  z-index: 316;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.08s linear;
}
#dream-message.show {
  opacity: 1;
}
#dream-message.hidden {
  display: none;
}
#dream-message-text {
  margin: 0;
  max-width: min(92vw, 36rem);
  font-family: var(--mono);
  font-size: clamp(0.74rem, 2.6vw, 0.98rem);
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: 0.28em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  text-shadow:
    0 0 24px rgba(0, 0, 0, 0.92),
    0 0 12px rgba(234, 234, 234, 0.12),
    0 2px 4px rgba(0, 0, 0, 0.85);
}
#dream-message.show #dream-message-text {
  animation: dream-msg-glitch 0.62s steps(2, end) infinite;
}
@keyframes dream-msg-glitch {
  0%,
  90%,
  100% {
    opacity: 1;
    transform: none;
  }
  92% {
    opacity: 0.9;
    transform: translateX(-1px);
    text-shadow:
      -2px 0 rgba(168, 161, 143, 0.35),
      2px 0 rgba(122, 132, 113, 0.22),
      0 0 20px rgba(0, 0, 0, 0.9);
  }
  94% {
    opacity: 0.94;
    transform: translateX(1px);
  }
}

#dream-system-msg {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 315;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
#dream-system-msg.show {
  opacity: 0.92;
}
#dream-system-msg.hidden {
  display: none;
}
#dream-system-msg-text {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(0.62rem, 2vw, 0.72rem);
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-shadow:
    0 0 16px rgba(0, 0, 0, 0.95),
    0 0 6px rgba(140, 140, 140, 0.1);
}

/* Dream Box — liminal entity chat */
#dream-chat.dream-box {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  left: auto;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%) translateX(24px);
  z-index: 318;
  width: clamp(16rem, 32vw, 24rem);
  height: auto;
  max-height: min(52vh, 22rem);
  opacity: 0;
  transition:
    opacity 0.9s ease,
    transform 0.9s ease;
  pointer-events: none;
}
#dream-chat.dream-box.show {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
  pointer-events: auto;
}
#dream-chat.dream-box.leaving {
  opacity: 0;
  transform: translateY(-50%) translateX(12px);
  filter: none;
  animation: none;
}
#dream-chat.dream-box.hidden {
  display: none;
}
.dream-box-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  max-height: min(52vh, 22rem);
  padding: 1rem 1.05rem 1.1rem;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: dream-box-fade-in 0.95s ease forwards;
}
@keyframes dream-box-fade-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@media (max-width: 720px) {
  /* On phones the box is anchored bottom-centred and near full-width so it
     never covers the central reticle/important view. */
  #dream-chat.dream-box {
    right: auto;
    left: 50%;
    top: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: min(94vw, 32rem);
    max-height: min(46vh, 20rem);
    transform: translateX(-50%) translateY(16px);
  }
  #dream-chat.dream-box.show {
    transform: translateX(-50%) translateY(0);
  }
  #dream-chat.dream-box.leaving {
    transform: translateX(-50%) translateY(10px);
  }
  /* Bigger, easier tap target for the submit control on touch. */
  .dream-box-submit,
  #dream-chat-submit {
    padding: 0.55rem 0.2rem;
    font-size: 0.72rem;
  }
}
.dream-box-title {
  margin: 0 0 0.2rem;
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 300;
  letter-spacing: 0.22em;
  text-transform: lowercase;
  color: var(--text-dim);
}
.dream-box-close {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: color 0.2s ease;
}
.dream-box-close:hover {
  color: var(--text);
}
.dream-box-presence {
  margin: 0 0 0.75rem;
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  color: var(--text-faint);
}
.dream-box-question,
#dream-chat-question {
  margin: 0 0 0.75rem;
  flex: 0 0 auto;
  font-family: var(--font);
  font-size: clamp(0.88rem, 2.2vw, 0.98rem);
  font-weight: 300;
  line-height: 1.5;
  color: var(--text);
}
.dream-box-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.dream-box-input,
#dream-chat-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.42rem 0;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.84rem;
  font-weight: 300;
  outline: none;
}
.dream-box-input::placeholder,
#dream-chat-input::placeholder {
  color: var(--text-faint);
  opacity: 0.65;
  font-style: italic;
}
.dream-box-input:focus,
#dream-chat-input:focus {
  border-bottom-color: var(--accent);
}
.dream-box-submit,
#dream-chat-submit {
  align-self: flex-end;
  padding: 0.12rem 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--ease);
}
.dream-box-submit:hover:not(:disabled),
#dream-chat-submit:hover:not(:disabled) {
  color: var(--text);
}
.dream-box-submit:disabled,
#dream-chat-submit:disabled {
  opacity: 0.3;
  cursor: default;
}
.dream-box-status {
  margin: 0.4rem 0 0;
  font-family: var(--font);
  font-size: 0.6rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  font-style: italic;
  color: var(--text-faint);
}
.dream-box-status.hidden {
  display: none;
}
.dream-box-reply,
#dream-chat-reply {
  margin: 0.7rem 0 0;
  flex: 0 1 auto;
  overflow-y: auto;
  font-family: var(--font);
  font-size: clamp(0.82rem, 2.1vw, 0.92rem);
  font-weight: 300;
  line-height: 1.48;
  color: var(--text-dim);
  opacity: 0;
  animation: dream-box-reply-in 0.85s ease forwards;
}
.dream-box-reply.hidden,
#dream-chat-reply.hidden {
  display: none;
}
@keyframes dream-box-reply-in {
  0% {
    opacity: 0;
    transform: translateY(3px);
  }
  100% {
    opacity: 0.9;
    transform: translateY(0);
  }
}

/* L3 flat cinema — fullscreen still + green-screen video */
#l3-cinema-overlay {
  position: fixed;
  inset: 0;
  z-index: 338;
  background: #000;
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
}
#l3-cinema-overlay.show {
  opacity: 1;
}
#l3-cinema-overlay.hidden {
  display: none;
}
#l3-cinema-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#level-jump-bar {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 300;
  color: var(--text-dim);
  pointer-events: none;
}
#level-jump-bar.hidden {
  display: none;
}
#level-jump-bar label {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  pointer-events: none;
  flex: none;
}
#level-jump-select {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 300;
  color: var(--text);
  background-color: rgba(0, 0, 0, 0.35);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 12px) center, calc(100% - 8px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 28px 7px 10px;
  min-width: 9.5rem;
  max-width: min(240px, 58vw);
  cursor: pointer;
  pointer-events: all;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  transition: border-color var(--ease), background-color var(--ease);
}
#level-jump-select:focus {
  border-color: var(--accent);
  background-color: rgba(0, 0, 0, 0.45);
  color: var(--text);
}
#level-jump-select option {
  color: var(--text);
  background: var(--bg);
}

#clue-key {
  position: fixed;
  top: 78px;
  left: 22px;
  z-index: 12;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: opacity var(--ease), transform var(--ease), border-color var(--ease), color var(--ease), background var(--ease);
  pointer-events: all;
}
#clue-key:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--hover);
  transform: scale(1.06);
}
#clue-key.hidden {
  display: none;
}

#riddle-key {
  position: fixed;
  top: 78px;
  left: 22px;
  z-index: 12;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color var(--ease), color var(--ease), background var(--ease);
}
#riddle-key:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--hover);
}
#riddle-key.hidden {
  display: none;
}
#riddle-panel {
  position: fixed;
  top: 78px;
  left: 68px;
  z-index: 13;
  max-width: min(28em, 86vw);
  padding: 14px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#riddle-panel.show {
  opacity: 1;
  pointer-events: all;
}
#riddle-panel.hidden {
  display: none;
}
#riddle-panel #riddle-text {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(0.68rem, 2vw, 0.82rem);
  line-height: 1.75;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  white-space: pre-line;
}
#riddle-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
}

/* Centered answer panels (riddle box + L1 code box) with a large countdown —
   kept transparent and neutral to match the rest of the UI (no purple). */
#l3-red-puzzle:not(.hidden),
#l1-puzzle:not(.hidden) {
  flex-direction: column;
  align-items: stretch;
  gap: 11px;
  padding: 16px 18px 15px;
  left: 50%;
  right: auto;
  bottom: max(40px, calc(28px + env(safe-area-inset-bottom)));
  transform: translateX(-50%);
  width: min(460px, 90vw);
  max-width: min(460px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Instruction line inside the answer panels */
#l3-red-puzzle:not(.hidden) .game-ui-hint,
#l1-puzzle:not(.hidden) .game-ui-hint {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-align: center;
  color: rgba(196, 204, 218, 0.82);
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  text-transform: uppercase;
}

#l3-red-puzzle:not(.hidden) .game-ui-countdown,
#l1-puzzle:not(.hidden) .game-ui-countdown {
  font-size: clamp(1.4rem, 5.6vw, 1.9rem);
  letter-spacing: 0.26em;
  text-align: center;
  color: rgba(210, 216, 228, 0.95);
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.7);
  min-width: 0;
}

#l3-red-puzzle:not(.hidden) .game-ui-form,
#l1-puzzle:not(.hidden) .game-ui-form {
  width: 100%;
  gap: 10px;
}

#l3-red-input.game-ui-input,
#l1-code-input.game-ui-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  font-size: clamp(1rem, 4vw, 1.3rem);
  padding: 12px 14px;
  text-align: center;
  letter-spacing: 0.16em;
  color: var(--text);
  border-color: var(--line);
  background: rgba(0, 0, 0, 0.32);
}
#l3-red-input.game-ui-input::placeholder,
#l1-code-input.game-ui-input::placeholder {
  color: var(--text-faint);
}
#l3-red-input.game-ui-input:focus,
#l1-code-input.game-ui-input:focus {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.46);
}

#l3-red-puzzle:not(.hidden) .game-ui-btn,
#l1-puzzle:not(.hidden) .game-ui-btn {
  font-size: 0.8rem;
  padding: 12px 18px;
  color: var(--text-dim);
  border-color: var(--line);
  background: rgba(0, 0, 0, 0.32);
}

#clue-panel {
  position: fixed;
  top: 78px;
  left: 68px;
  z-index: 13;
  width: min(340px, calc(100vw - 90px));
  padding: 14px 16px 12px;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.7;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  pointer-events: all;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#clue-panel.show {
  opacity: 1;
  transform: translateY(0);
}
#clue-panel.hidden {
  display: none;
}
#clue-close {
  float: right;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 14px;
  cursor: pointer;
  padding: 0 0 6px 8px;
}
#clue-close:hover {
  color: var(--text);
}

#l1-puzzle.hidden {
  display: none;
}

@keyframes countdown-pulse {
  50% {
    opacity: 0.55;
  }
}

#l3-red-puzzle.hidden {
  display: none;
}
#l3-red-riddle {
  display: none;
}

/* nausea / disorientation after the second eye — kept subtle */
body.l1-nausea #scene {
  filter: blur(0.8px) saturate(1.08) contrast(1.04);
  animation: nausea-wobble 0.35s ease-in-out infinite;
}
body.l1-nausea #scanlines {
  opacity: 0.1;
}
body.l1-nausea #interference {
  opacity: 0.14;
}
@keyframes nausea-wobble {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-0.6px, 0.3px);
  }
  50% {
    transform: translate(0.6px, -0.3px);
  }
  75% {
    transform: translate(-1px, -2px);
  }
  100% {
    transform: translate(1px, 2px);
  }
}

/* ---- Look hint ---- */
#skip-level {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 45;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  pointer-events: all;
}
#skip-level:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.14);
  background: var(--hover);
}
#skip-level.hidden {
  display: none;
}

#skip-video {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(52px, calc(env(safe-area-inset-bottom) + 38px));
  /* Above quest-fullscreen-video (250) and quest-video-vignette (260). */
  z-index: 350;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  pointer-events: all;
}
#skip-video:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.14);
  background: var(--hover);
}
#skip-video.hidden {
  display: none;
}

body.jumpscare-active #skip-video:not(.hidden),
body.quest-video-webgl #skip-video:not(.hidden),
body.video-playing #skip-video:not(.hidden) {
  visibility: visible !important;
  pointer-events: all !important;
}

#look-hint {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--dim);
  pointer-events: none;
  animation: hintfade 6s ease forwards;
  animation-delay: 4s;
}

@keyframes hintfade {
  to {
    opacity: 0;
  }
}

/* ---- Intro / ending ---- */
#intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    radial-gradient(ellipse 120% 80% at 50% 100%, rgba(255, 255, 255, 0.018), transparent 55%);
  background-size: 64px 64px, 64px 64px, 100% 100%;
  transition: opacity 1.4s ease;
}

#intro.hidden {
  opacity: 0;
  pointer-events: none;
}

#intro.start-only {
  background: transparent;
  pointer-events: none;
}

#intro.start-only .intro-inner {
  max-width: none;
  padding: 0;
}

#intro.start-only #intro-btn {
  pointer-events: auto;
}

#intro.start-only #intro-title,
#intro.start-only #intro-lines {
  display: none !important;
}

/* Main menu — simple pre-game screen */
#intro.main-menu {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    radial-gradient(ellipse 120% 80% at 50% 100%, rgba(255, 255, 255, 0.018), transparent 55%);
  background-size: 64px 64px, 64px 64px, 100% 100%;
  pointer-events: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#intro.main-menu .intro-inner {
  max-width: min(520px, 90vw);
  padding: max(28px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

#intro.main-menu .menu-credit-studio {
  margin: 0 0 1.1rem;
  font-family: var(--mono);
  font-size: clamp(0.58rem, 1.6vw, 0.72rem);
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0;
  animation: bootCreditIn 1s ease forwards;
}

#intro.main-menu #intro-title {
  margin-bottom: 1.4rem;
  font-size: clamp(1.9rem, 7vw, 3rem);
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  opacity: 0;
  animation: bootCreditIn 1.1s ease forwards;
  animation-delay: 0.15s;
}

#intro.main-menu #intro-title::before,
#intro.main-menu #intro-title::after {
  display: none;
}

#intro.main-menu #intro-lines p {
  margin: 0 0 0.55rem;
  font-family: var(--font);
  font-size: clamp(0.82rem, 2.1vw, 0.98rem);
  line-height: 1.62;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  opacity: 0;
  animation: bootCreditIn 0.9s ease forwards;
}

#intro.main-menu #intro-lines p.menu-spacer {
  margin: 0 0 0.35rem;
  line-height: 0.4;
}

#intro.main-menu #intro-btn {
  pointer-events: auto;
  margin-top: 1.6rem;
  opacity: 0;
  animation: bootCreditIn 0.9s ease forwards;
}

/* Ending credits */
#intro.ending-credits .intro-inner {
  max-width: min(480px, 88vw);
}

#intro.ending-credits #intro-title {
  font-size: clamp(1.8rem, 6.5vw, 2.8rem);
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  margin-bottom: 1.6rem;
  animation: bootCreditIn 1.4s ease forwards;
}

#intro.ending-credits #intro-title::before,
#intro.ending-credits #intro-title::after {
  display: none;
}

#intro.ending-credits #intro-lines p {
  font-family: var(--font);
  font-size: clamp(0.84rem, 2.2vw, 1rem);
  line-height: 1.7;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

#intro.ending-credits #intro-lines p.ending-spacer {
  margin: 0 0 0.4rem;
  line-height: 0.35;
}

#intro.boot-intro {
  background: #000;
  pointer-events: auto;
  z-index: 300;
  overflow: hidden;
}

#intro.boot-intro.boot-intro--webgl {
  background: transparent;
}

#intro.boot-intro.boot-intro--webgl::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.2) 35%,
    rgba(0, 0, 0, 0.35) 70%,
    rgba(0, 0, 0, 0.72) 100%
  );
  pointer-events: none;
}

#intro.boot-intro.boot-intro--webgl #boot-intro-video-wrap {
  display: none;
}

#intro.boot-intro.boot-intro--webgl #boot-intro-video {
  animation: none;
}

#boot-intro-video-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #000;
}

#boot-intro-video-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.2) 35%,
    rgba(0, 0, 0, 0.35) 70%,
    rgba(0, 0, 0, 0.72) 100%
  );
  pointer-events: none;
}

#boot-intro-video {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  will-change: transform;
}

#intro.boot-intro.boot-intro--video #boot-intro-video {
  animation: bootIntroVideoZoom var(--boot-intro-dur, 12s) linear forwards;
}

@keyframes bootIntroVideoZoom {
  from {
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    transform: translate(-50%, -50%) scale(1.55);
  }
}

#intro.boot-intro .intro-inner {
  position: relative;
  z-index: 2;
  max-width: min(560px, 90vw);
  padding: 28px 20px;
}

#intro.boot-intro #intro-title {
  display: block;
  margin-bottom: 0.35em;
  font-size: clamp(1.8rem, 7vw, 3.4rem);
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  animation: bootCreditIn 1.4s ease forwards;
  animation-delay: 0.9s;
  opacity: 0;
}

#intro.boot-intro .boot-credit-studio {
  font-family: var(--mono);
  font-size: clamp(0.62rem, 1.8vw, 0.78rem);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 1.4em;
  opacity: 0;
  animation: bootCreditIn 1.2s ease forwards;
  animation-delay: 0.25s;
}

#intro.boot-intro .boot-credit-tagline {
  font-family: var(--font);
  font-size: clamp(0.82rem, 2.2vw, 1rem);
  letter-spacing: 0.28em;
  text-transform: lowercase;
  color: var(--accent-2);
  margin: 0.6em 0 2rem;
  opacity: 0;
  animation: bootCreditIn 1.2s ease forwards;
  animation-delay: 1.55s;
}

#intro.boot-intro #intro-lines p {
  color: var(--text);
  font-size: clamp(0.92rem, 2.4vw, 1.12rem);
  line-height: 1.75;
  letter-spacing: 0.02em;
  margin: 0 0 1.1em;
  opacity: 0;
  animation: bootCreditIn 1.1s ease forwards;
}

#intro.boot-intro #intro-lines p:last-child {
  margin-bottom: 0;
}

@keyframes bootCreditIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#intro.boot-intro #intro-btn {
  margin-top: 2.2rem;
  pointer-events: auto;
  opacity: 1;
  animation: none;
  transform: none;
  filter: none;
}

#intro.boot-intro #intro-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* ---- Headphones notice (once per device, before main menu) ---- */
#headphones-notice {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: all;
  transition: opacity 0.55s ease;
}
#headphones-notice.show {
  opacity: 1;
}
#headphones-notice.hidden {
  display: none;
}
.headphones-notice-panel {
  width: min(420px, 92vw);
  max-height: none;
  text-align: center;
  align-items: center;
}
.headphones-notice-title {
  margin: 0 0 1rem;
  font-family: var(--font);
  font-size: clamp(0.72rem, 2.4vw, 0.82rem);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
}
.headphones-notice-text {
  margin: 0 0 1.4rem;
  font-family: var(--font);
  font-size: clamp(0.88rem, 2.2vw, 0.98rem);
  font-weight: 300;
  line-height: 1.55;
  color: var(--text-dim);
}
#headphones-notice-btn {
  margin-top: 0;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  animation: bootCreditIn 0.9s ease forwards;
  animation-delay: 0.35s;
  transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease);
}
#headphones-notice-btn:hover {
  background: var(--hover);
  border-color: var(--accent-2);
  color: var(--text);
  transform: translateY(-1px);
}

.intro-inner {
  text-align: center;
  max-width: min(640px, 88vw);
  padding: 20px;
}

#intro-title {
  position: relative;
  font-family: var(--font);
  font-weight: 400;
  font-size: clamp(2.2rem, 8vw, 4.2rem);
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  margin-bottom: 40px;
  color: var(--text);
  text-shadow: none;
  opacity: 0;
  animation: titleArrive 2.6s steps(8) forwards, titleGlitch 3.4s steps(3) 2.6s infinite;
}

/* chromatic split copies of the title */
#intro-title::before,
#intro-title::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  text-indent: 14px;
  opacity: 0.55;
  pointer-events: none;
}

#intro-title::before {
  color: var(--danger-text);
  animation: titleShiftA 3.4s steps(3) 2.6s infinite;
}

#intro-title::after {
  color: var(--accent-2);
  animation: titleShiftB 3.4s steps(3) 2.6s infinite;
}

@keyframes titleArrive {
  0% {
    opacity: 0;
    filter: blur(10px);
    letter-spacing: 40px;
  }
  40% {
    opacity: 0.2;
  }
  55% {
    opacity: 0.9;
    filter: blur(0);
  }
  60% {
    opacity: 0.1;
  }
  100% {
    opacity: 1;
    filter: blur(0);
    letter-spacing: 14px;
  }
}

@keyframes titleGlitch {
  0%,
  90%,
  100% {
    clip-path: none;
    transform: translate(0, 0);
  }
  92% {
    transform: translate(-2px, 1px);
  }
  94% {
    clip-path: inset(20% 0 55% 0);
    transform: translate(3px, -1px);
  }
  96% {
    clip-path: inset(60% 0 10% 0);
    transform: translate(-3px, 0);
  }
}

@keyframes titleShiftA {
  0%,
  90%,
  100% {
    transform: translate(0, 0);
    opacity: 0;
  }
  92%,
  96% {
    transform: translate(-3px, 0);
    opacity: 0.5;
  }
}

@keyframes titleShiftB {
  0%,
  90%,
  100% {
    transform: translate(0, 0);
    opacity: 0;
  }
  92%,
  96% {
    transform: translate(3px, 0);
    opacity: 0.5;
  }
}

#intro-lines p {
  font-family: var(--font);
  font-style: normal;
  font-weight: 300;
  font-size: clamp(0.95rem, 2.6vw, 1.25rem);
  line-height: 1.9;
  letter-spacing: 1px;
  color: var(--dim);
  opacity: 0;
  animation: rise 1.4s ease forwards;
}

#intro-btn {
  margin-top: 40px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  animation: rise 1.4s ease forwards;
  transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease);
}

#intro-btn:hover {
  background: var(--hover);
  border-color: var(--accent-2);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
    filter: blur(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

/* ---- Mobile: portrait vertical play ---- */
@media (max-width: 600px) {
  #hud {
    top: max(10px, env(safe-area-inset-top));
    padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  }
  #progress {
    font-size: 0.58rem;
    letter-spacing: 2px;
  }
  #lucidity {
    gap: 6px;
  }
  .lucidity-label {
    font-size: 0.55rem;
    letter-spacing: 2px;
  }
  .lucidity-bar {
    width: 72px;
    height: 4px;
  }
  #objective {
    top: max(38px, calc(10px + env(safe-area-inset-top)));
    font-size: clamp(0.78rem, 4.2vw, 0.92rem);
    letter-spacing: 2px;
    max-width: 92vw;
    white-space: normal;
    line-height: 1.45;
    text-shadow:
      0 0 26px rgba(0, 0, 0, 0.98),
      0 0 16px rgba(242, 239, 247, 0.28),
      0 2px 5px rgba(0, 0, 0, 0.9);
  }
  #reticle {
    width: 48px;
    height: 48px;
  }
  #reticle svg {
    width: 48px;
    height: 48px;
  }
  #look-hint {
    bottom: max(12px, env(safe-area-inset-bottom));
    font-size: 0.54rem;
    letter-spacing: 2px;
  }
  #threshold-prompt {
    font-size: clamp(0.76rem, 3.8vw, 0.88rem);
    text-shadow:
      0 0 26px rgba(0, 0, 0, 0.96),
      0 0 16px rgba(236, 228, 255, 0.26),
      0 2px 5px rgba(0, 0, 0, 0.88);
  }
  #threshold-prompt span {
    letter-spacing: 2px;
  }
  #whisper {
    font-size: clamp(0.86rem, 3.6vw, 1.02rem);
    max-width: 88vw;
  }
  #dream-message-text {
    font-size: clamp(0.72rem, 3.8vw, 0.9rem);
    letter-spacing: 0.22em;
  }
  #dream-system-msg-text {
    font-size: clamp(0.64rem, 2.8vw, 0.74rem);
  }
  #clue-key {
    top: max(52px, calc(12px + env(safe-area-inset-top)));
    left: max(12px, env(safe-area-inset-left));
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  #clue-panel {
    top: max(52px, calc(12px + env(safe-area-inset-top)));
    left: max(58px, calc(12px + env(safe-area-inset-left)));
    width: min(300px, calc(100vw - 80px));
    font-size: 0.66rem;
  }
  #hint-btn {
    top: max(38px, calc(10px + env(safe-area-inset-top)));
    right: max(12px, env(safe-area-inset-right));
    width: 38px;
    height: 38px;
    font-size: 0.62rem;
  }
  #hint-panel {
    top: max(38px, calc(10px + env(safe-area-inset-top)));
    right: max(44px, calc(36px + env(safe-area-inset-right)));
    width: min(240px, calc(100vw - 56px));
    font-size: 0.54rem;
  }
  .game-ui-bar {
    bottom: max(14px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
    gap: 8px;
    max-width: calc(100vw - 24px);
  }
  .game-ui-input {
    width: 92px;
    font-size: 0.54rem;
    background: rgba(0, 0, 0, 0.35);
    border-color: var(--line-soft);
  }
  .game-ui-countdown {
    font-size: 0.56rem;
  }

  /* Answer panels — smaller and more transparent on phones */
  #l3-red-puzzle:not(.hidden),
  #l1-puzzle:not(.hidden) {
    width: min(260px, 76vw);
    max-width: min(260px, 76vw);
    padding: 9px 11px 8px;
    gap: 6px;
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    box-shadow: none;
  }
  #l3-red-puzzle:not(.hidden) .game-ui-hint,
  #l1-puzzle:not(.hidden) .game-ui-hint {
    font-size: 0.56rem;
    letter-spacing: 0.07em;
    color: var(--text-faint);
  }
  #l3-red-puzzle:not(.hidden) .game-ui-countdown,
  #l1-puzzle:not(.hidden) .game-ui-countdown {
    font-size: clamp(0.95rem, 4.2vw, 1.15rem);
    letter-spacing: 0.16em;
    color: var(--text-dim);
  }
  #l3-red-puzzle:not(.hidden) .game-ui-form,
  #l1-puzzle:not(.hidden) .game-ui-form {
    gap: 6px;
  }
  #l3-red-input.game-ui-input,
  #l1-code-input.game-ui-input {
    font-size: clamp(0.72rem, 3.4vw, 0.86rem);
    padding: 5px 7px;
    background: rgba(0, 0, 0, 0.35);
    border-color: var(--line-soft);
  }
  #l3-red-input.game-ui-input:focus,
  #l1-code-input.game-ui-input:focus {
    background: rgba(0, 0, 0, 0.45);
    border-color: var(--accent);
  }
  #l3-red-puzzle:not(.hidden) .game-ui-btn,
  #l1-puzzle:not(.hidden) .game-ui-btn {
    font-size: 0.56rem;
    padding: 5px 9px;
    background: transparent;
    border-color: var(--line-soft);
  }
  #l1-blackout-continue {
    bottom: max(14px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
  }
  #intro-title {
    font-size: clamp(1.6rem, 10vw, 2.6rem);
    letter-spacing: 8px;
    text-indent: 8px;
    margin-bottom: 22px;
  }
  #intro-title::before,
  #intro-title::after {
    text-indent: 8px;
  }
  .intro-inner {
    max-width: min(92vw, 560px);
    padding: 12px;
  }
  #intro-lines p {
    font-size: 0.82rem;
    line-height: 1.55;
  }
  #intro-btn {
    margin-top: 22px;
    padding: 12px 28px;
    font-size: 0.72rem;
  }
  #editor-toggle {
    display: none;
  }
  #editor {
    width: min(240px, 88vw);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
  }
}

/* ---- Jump scare ---- */
#jumpscare {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}
#jumpscare.show {
  display: flex;
}
#jumpscare.show.image-scare {
  background: radial-gradient(circle at 50% 42%, rgba(120, 0, 0, 0.65), #000 78%);
  animation: js-bg 0.09s steps(2, end) 0s 3;
}
#jumpscare.image-scare-priority {
  z-index: 420;
}
#jumpscare img {
  display: none;
  height: 104vh;
  max-width: none;
  object-fit: contain;
  filter: contrast(1.25) saturate(0.85) brightness(0.92) drop-shadow(0 0 40px rgba(0, 0, 0, 0.9));
  transform-origin: 50% 45%;
  will-change: transform;
}
#jumpscare.show.image-scare img {
  display: block;
  animation: js-zoom 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both, js-shake 0.07s steps(2, end) infinite;
}
#jumpscare-video {
  display: none;
  width: 100vw;
  height: 100vh;
  max-width: none;
  object-fit: cover;
  background: #000;
}
#jumpscare.show.video-scare #jumpscare-video {
  display: none; /* mp4 plays on #jumpscare-buffer */
}
#jumpscare-buffer {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  object-fit: cover;
  background: #000;
  pointer-events: none;
  z-index: 200;
  transform: translateZ(0);
  will-change: transform;
}
/* 4 dark corners over the fullscreen level video (no colour grade) */
#quest-video-vignette {
  position: fixed;
  inset: 0;
  z-index: 260;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  background:
    radial-gradient(50% 50% at 0% 0%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0) 100%),
    radial-gradient(50% 50% at 100% 0%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0) 100%),
    radial-gradient(50% 50% at 0% 100%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0) 100%),
    radial-gradient(50% 50% at 100% 100%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0) 100%);
}
#quest-video-vignette.show {
  opacity: 1;
}

video.quest-fullscreen-video {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  object-fit: cover;
  background: #000;
  z-index: 250;
  pointer-events: none;
  transform: translateZ(0);
}
video.quest-fullscreen-video.mirror-x {
  transform: scaleX(-1) translateZ(0);
}
#jumpscare.show.video-scare #jumpscare-buffer {
  display: block;
}
#jumpscare.show.youtube-scare #jumpscare-buffer,
#jumpscare.show.youtube-scare #jumpscare-video {
  display: none !important;
}
/* YouTube quest — chromeless fullscreen (controls hidden via API + CSS crop) */
#yt-quest-pool {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.yt-quest-host {
  position: relative;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  background: #000;
}
.yt-quest-host.yt-quest-visible {
  position: fixed;
  inset: 0;
  z-index: 250;
  width: 100vw;
  height: 100vh;
  opacity: 1;
  visibility: visible;
  pointer-events: none;
  overflow: hidden;
  background: #000;
}
.yt-quest-host.yt-quest-waiting .yt-quest-mount,
.yt-quest-host.yt-quest-waiting .yt-quest-mount iframe {
  opacity: 0;
}
.yt-quest-host.yt-quest-playing .yt-quest-mount,
.yt-quest-host.yt-quest-playing .yt-quest-mount iframe {
  opacity: 1;
  transition: opacity 0.35s ease;
}
.yt-quest-cover {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: #000;
  pointer-events: none;
}
.yt-quest-host.yt-quest-playing .yt-quest-cover {
  opacity: 0;
  transition: opacity 0.4s ease;
}
#jumpscare.show.youtube-scare {
  display: flex !important;
  z-index: 240;
  background: transparent;
}
/* crop YouTube logo + title bar */
.yt-quest-host.yt-quest-visible::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14vmin;
  background: #000;
  z-index: 4;
  pointer-events: none;
}
.yt-quest-host.yt-quest-visible::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  width: 22vmin;
  height: 12vmin;
  background: #000;
  z-index: 4;
  pointer-events: none;
}
.yt-quest-mount {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.yt-quest-mount iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(104vw, 185vh);
  height: max(104vh, 58vw);
  transform: translate(-50%, -50%);
  border: 0;
  pointer-events: none;
  background: #000;
}
/* WebGL quest fullscreen — hide HUD only; canvas keeps rendering */
body.quest-video-webgl #hud,
body.quest-video-webgl #reticle,
body.quest-video-webgl #look-hint,
body.quest-video-webgl #objective,
body.quest-video-webgl #hint-btn,
body.quest-video-webgl #hint-panel,
body.quest-video-webgl #whisper {
  visibility: hidden;
}
/* Any video (incl. in-scene projections) hides the center reticle dot */
body.video-playing #reticle {
  visibility: hidden;
}
/* freeze WebGL while mobile HTML overlay plays — stops GPU fight with the decoder */
body.jumpscare-active #scene {
  visibility: hidden;
  pointer-events: none;
}
body.jumpscare-active #hud,
body.jumpscare-active #reticle,
body.jumpscare-active #look-hint,
body.jumpscare-active #objective,
body.jumpscare-active #hint-btn,
body.jumpscare-active #hint-panel,
body.jumpscare-active #whisper {
  visibility: hidden;
}
/* Narrative blackout — keep gameplay HUD / ambient text below the story layer */
body.blackout-active #objective,
body.blackout-active #whisper,
body.blackout-active #threshold-prompt,
body.blackout-active #look-hint,
body.blackout-active #reticle,
body.blackout-active #hud,
body.blackout-active #hint-btn,
body.blackout-active #hint-panel,
body.blackout-active #riddle-key,
body.blackout-active #riddle-panel,
body.blackout-active #l1-puzzle,
body.blackout-active #l3-red-puzzle,
body.blackout-active #clue-key,
body.blackout-active #clue-panel,
body.blackout-active #dream-message,
body.blackout-active #dream-chat,
body.blackout-active #dream-system-msg,
body.blackout-active #disturb-flash,
body.blackout-active #l5-flash-caption,
body.blackout-active #level-jump-bar {
  visibility: hidden !important;
  pointer-events: none !important;
}
@keyframes js-zoom {
  0% {
    transform: scale(1.9) translateY(6%);
    opacity: 0.2;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}
@keyframes js-shake {
  0% {
    margin-left: -10px;
    margin-top: -6px;
  }
  25% {
    margin-left: 12px;
    margin-top: 5px;
  }
  50% {
    margin-left: -8px;
    margin-top: 8px;
  }
  75% {
    margin-left: 9px;
    margin-top: -7px;
  }
  100% {
    margin-left: -10px;
    margin-top: -6px;
  }
}
@keyframes js-bg {
  0% {
    background-color: #4a0000;
  }
  100% {
    background-color: #000;
  }
}

/* ---- Monster placement editor ---- */
#editor-toggle {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 40;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}
#editor-toggle:hover {
  background: rgba(20, 26, 40, 0.8);
  border-color: rgba(255, 255, 255, 0.14);
}

#editor {
  position: fixed;
  left: 14px;
  bottom: 56px;
  z-index: 41;
  width: 290px;
  padding: 14px 14px 12px;
  font-family: var(--mono);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s, transform 0.2s;
}
#editor.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}
.ed-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 120px;
}
#ed-prop-controls.hidden {
  display: none;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}
#editor-close {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
}
#editor-close:hover {
  color: #fff;
}
.ed-mon-preview-bar {
  margin: -2px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.ed-mon-preview-bar .ed-buttons {
  margin-top: 4px;
}
.ed-mon-preview-bar .ed-tip {
  margin-top: 6px;
  font-size: 8.5px;
}
.ed-mon-preview-bar .ed-buttons button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ed-row {
  display: block;
  margin: 9px 0 3px;
}
.ed-name {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 5px;
  text-transform: lowercase;
}
.ed-name i {
  font-style: normal;
  color: var(--text);
}
#editor input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: var(--line);
  outline: none;
  cursor: pointer;
}
#editor input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 1px solid rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
#editor input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 1px solid rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.ed-mini {
  width: 100%;
  margin: 2px 0 4px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  cursor: pointer;
  text-transform: lowercase;
}
.ed-mini:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.14);
}

.ed-section {
  margin: 8px 0 4px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 4px 8px 8px;
  background: rgba(255, 255, 255, 0.02);
}
.ed-section > summary {
  cursor: pointer;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 6px 2px;
  list-style: none;
  user-select: none;
}
.ed-section > summary::-webkit-details-marker {
  display: none;
}
.ed-sub {
  margin: 0.35rem 0 0.5rem;
  padding: 0.35rem 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.ed-sub > summary {
  cursor: pointer;
  font-size: 0.78rem;
  opacity: 0.85;
  margin-bottom: 0.35rem;
  list-style: none;
}
.ed-sub > summary::-webkit-details-marker {
  display: none;
}
.ed-section[open] > summary {
  color: var(--text);
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
}
.ed-btn-group {
  margin-top: 8px;
}
.ed-group-label {
  display: block;
  font-size: 8.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.ed-buttons-single button {
  width: 100%;
}
.ed-eye-card {
  margin: 8px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
}
.ed-eye-card.sel {
  border-color: rgba(122, 132, 113, 0.5);
  box-shadow: 0 0 0 1px var(--line);
}
.ed-eye-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.ed-eye-head button {
  font-size: 9px;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  cursor: pointer;
}
.ed-eye-video,
.ed-eye-blacktext {
  width: 100%;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 9px;
  padding: 5px 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  resize: vertical;
}
.ed-row-stack {
  flex-direction: column;
  align-items: stretch;
}
#ed-filter-preset,
#ed-bg-filter-preset,
#ed-fx-type {
  width: 100%;
}
.ed-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.ed-buttons button {
  flex: 1;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 4px;
  cursor: pointer;
}
.ed-buttons button:hover {
  background: var(--hover);
  border-color: rgba(255, 255, 255, 0.14);
}
.ed-buttons button.active {
  background: #b6485a;
  border-color: #d96b7c;
  color: #fff;
}
#ed-eye-add-red {
  border-color: rgba(180, 60, 50, 0.5);
  color: #ffb0a8;
}
#ed-eye-add-red:hover {
  background: rgba(80, 20, 18, 0.85);
  border-color: rgba(220, 80, 70, 0.65);
}
.ed-row-check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ed-row-check .ed-name {
  margin-bottom: 0;
}
.ed-red-eye-card .ed-eye-head span {
  color: #ffb0a8;
}
.ed-purple-eye-card .ed-eye-head span {
  color: #e0b0ff;
}
.ed-purple-eye-card {
  border-color: rgba(180, 80, 255, 0.35);
}
.ed-purple-img-preview {
  display: block;
  width: 100%;
  max-height: 90px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin: 2px 0 4px;
  border: 1px solid rgba(180, 80, 255, 0.5);
}
#ed-audio-panel .ed-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0;
}
.ed-eye-video-upload {
  margin: 8px 0 4px;
  padding: 8px 0 2px;
  border-top: 1px solid var(--line-soft);
}
.ed-row-file input[type="file"] {
  font-size: 9px;
  max-width: 100%;
}
.ed-tip {
  margin-top: 9px;
  font-size: 9px;
  line-height: 1.45;
  letter-spacing: 0.03em;
  color: var(--text-faint);
}
.ed-tip-warn {
  color: #c9a86a;
  border-left: 2px solid #8a6d3b;
  padding-left: 8px;
}
.ed-row-tv select {
  width: 100%;
  margin-top: 4px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 11px;
}

#editor {
  max-height: 82vh;
  overflow-y: auto;
}
.ed-divider {
  margin: 14px 0 4px;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-top: 1px solid var(--line-soft);
  padding-top: 9px;
}

/* sprite-sheet cutter + per-frame effects */
.ed-grid2 {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.ed-grid2 .ed-row {
  flex: 1;
  margin-top: 0;
}
.ed-num input[type="number"],
#ed-fx-type {
  width: 100%;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 6px;
  margin-top: 4px;
}
#ed-sheet-file,
#ed-prop-file,
#ed-bg-file {
  width: 100%;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
}
#ed-sheet-file::file-selector-button,
#ed-prop-file::file-selector-button,
#ed-bg-file::file-selector-button {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  margin-right: 8px;
  cursor: pointer;
}
#ed-mon-list {
  margin-top: 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}
#ed-mon-list .ed-fx-row.sel {
  border-color: rgba(122, 132, 113, 0.5);
  background: var(--hover);
}

#ed-fx-list {
  margin-top: 9px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.ed-fx-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
}
.ed-fx-row.sel {
  border-color: var(--accent-2);
  background: var(--hover);
}
#ed-prop-list {
  margin-top: 9px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.ed-fx-del {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  color: #d99;
  background: rgba(182, 72, 90, 0.18);
  border: 1px solid rgba(217, 107, 124, 0.4);
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  cursor: pointer;
}
.ed-fx-del:hover {
  background: rgba(182, 72, 90, 0.4);
}

.ed-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ed-color-row .ed-name {
  display: inline;
}
.ed-color-row input[type="color"] {
  width: 46px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

/* live selection box while drawing an occluder */
#draw-rect {
  position: fixed;
  z-index: 39;
  border: 1.5px dashed #d96b7c;
  background: rgba(217, 107, 124, 0.14);
  pointer-events: none;
  display: none;
}
body.drawing #scene {
  cursor: crosshair;
}

@media (max-width: 600px) {
  #editor {
    width: 210px;
  }
}

/* Red-eye jumpscare flash (L2) — fills the screen briefly (<1s) */
#redeye-jumpscare {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 320;
  opacity: 0;
  pointer-events: none;
  display: none;
  background: transparent;
}

#redeye-jumpscare.show {
  display: block;
}

.ed-red-jump-preview {
  display: block;
  width: 100%;
  max-height: 90px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin: 2px 0 4px;
  border: 1px solid rgba(255, 70, 70, 0.5);
}

/* ---- Boot loader (initial asset progress) ---- */
.boot-loader {
  position: fixed;
  inset: 0;
  z-index: 340;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(122, 132, 113, 0.08), transparent 70%),
    var(--bg);
  opacity: 1;
  transition: opacity 0.45s ease;
  pointer-events: all;
}

.boot-loader.hidden {
  display: none;
}

.boot-loader.boot-loader--hide {
  opacity: 0;
  pointer-events: none;
}

.boot-loader-inner {
  width: min(420px, 88vw);
  text-align: center;
}

.boot-loader-brand {
  margin: 0 0 1.25rem;
  font-family: var(--mono);
  font-size: clamp(0.85rem, 2.8vw, 1rem);
  font-weight: 500;
  letter-spacing: 0.28em;
  color: var(--text);
}

.boot-loader-label {
  margin: 0 0 1rem;
  font-family: var(--font);
  font-size: clamp(0.82rem, 2.2vw, 0.92rem);
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  min-height: 1.4em;
}

.boot-loader-track {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-soft);
  overflow: hidden;
}

.boot-loader-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(122, 132, 113, 0.85), rgba(168, 161, 143, 0.95));
  box-shadow: 0 0 12px rgba(122, 132, 113, 0.35);
  transition: width 0.28s ease-out;
}

.boot-loader-pct {
  margin: 0.65rem 0 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--text-faint);
}
