:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --text: #111111;
  --muted: #71716d;
  --line: #111111;
  --panel: rgba(245, 245, 242, 0.86);
  --ghost: #a855f7;
  --warning: #ff3b3b;
  --terminal: #39ff88;
  --shadow: rgba(17, 17, 17, 0.12);
  --cursor-shape: url("data:image/svg+xml,%3Csvg width='28' height='32' viewBox='0 0 28 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.5 2.5 24.5 18.1 15.05 19.38 19.45 27.88 15.22 30.08 10.78 21.55 4.75 28.02 3.5 2.5Z' fill='black'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

html {
  cursor: none;
}

html.native-cursor {
  cursor: auto;
}

html.native-cursor *,
html.native-cursor button {
  cursor: auto;
}

html.native-cursor .custom-cursor {
  display: none;
}

body {
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  transition:
    background 900ms ease,
    color 900ms ease,
    filter 280ms ease;
}

body *,
button {
  cursor: none;
}

button {
  font: inherit;
}

.page {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  padding: clamp(18px, 3vw, 34px);
  transition:
    transform 120ms ease,
    filter 240ms ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 32px;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand {
  font-weight: 700;
}

.session-pill {
  max-width: min(54vw, 360px);
  overflow: hidden;
  color: var(--muted);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  display: grid;
  min-height: calc(100vh - 92px);
  place-items: center;
  padding: 64px 0;
}

.intro,
.final-scene,
.ending {
  width: min(700px, 92vw);
  text-align: center;
}

.kicker {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(30px, 6vw, 76px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 0.98;
}

.copy {
  min-height: 26px;
  margin: 22px auto 0;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 18px);
  line-height: 1.5;
}

.normal-line {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--text);
  font-size: 13px;
  opacity: 0.68;
}

.button-row,
.final-buttons,
.ending-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 34px;
}

.system-button {
  min-width: 112px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
  letter-spacing: 0;
  transition:
    background 140ms ease,
    color 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

.system-button:hover,
.system-button:focus-visible,
.system-button.is-pressed {
  outline: none;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.18);
}

.system-button.is-ghost-pressed {
  border-color: var(--ghost);
  background: rgba(168, 85, 247, 0.14);
  color: var(--ghost);
  box-shadow: 0 0 18px rgba(168, 85, 247, 0.45);
}

.log-panel {
  position: fixed;
  right: clamp(14px, 2.4vw, 28px);
  bottom: clamp(14px, 2.4vw, 28px);
  z-index: 5;
  width: min(330px, calc(100vw - 28px));
  max-height: 210px;
  border: 1px solid rgba(17, 17, 17, 0.14);
  background: var(--panel);
  color: var(--muted);
  opacity: 0.26;
  padding: 12px;
  font-size: 11px;
  line-height: 1.45;
  transform: translateY(8px);
  transition:
    opacity 480ms ease,
    transform 480ms ease,
    border-color 480ms ease,
    background 480ms ease,
    color 480ms ease;
}

.log-heading {
  margin-bottom: 8px;
  color: currentColor;
  font-size: 10px;
  opacity: 0.78;
}

.log-lines {
  display: grid;
  gap: 3px;
  max-height: 160px;
  overflow: hidden;
}

.log-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-line::before {
  content: "> ";
}

.center-message {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 12;
  width: min(680px, 88vw);
  color: var(--warning);
  font-size: clamp(24px, 5vw, 60px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow:
    2px 0 rgba(57, 255, 136, 0.22),
    -2px 0 rgba(168, 85, 247, 0.24);
  transform: translate(-50%, -50%) scale(0.98);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.center-message.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.system-modal {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  background: rgba(245, 245, 242, 0.96);
  color: var(--text);
  box-shadow: 12px 12px 0 rgba(17, 17, 17, 0.12);
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.system-modal.is-copy {
  opacity: 0.48;
  pointer-events: none;
}

.modal-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  padding: 0 8px 0 13px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(17, 17, 17, 0.04);
}

.modal-close {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  line-height: 1;
}

.modal-body {
  padding: 24px;
}

.modal-body p {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
  text-transform: lowercase;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.modal-actions .system-button {
  min-width: 92px;
  min-height: 38px;
  font-size: 12px;
}

.custom-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  width: 28px;
  height: 32px;
  pointer-events: none;
  transform: translate3d(-80px, -80px, 0);
  will-change: transform;
}

.custom-cursor::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: currentColor;
  -webkit-mask: var(--cursor-shape) center / contain no-repeat;
  mask: var(--cursor-shape) center / contain no-repeat;
}

.custom-cursor::after {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: 1;
  background: var(--cursor-outline, rgba(255, 255, 255, 0.85));
  -webkit-mask: var(--cursor-shape) center / contain no-repeat;
  mask: var(--cursor-shape) center / contain no-repeat;
  opacity: 0.95;
}

.current-cursor {
  color: #111111;
  --cursor-outline: rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.28));
  transition: opacity 240ms ease;
}

.ghost-cursor {
  z-index: 29;
  color: var(--ghost);
  --cursor-outline: rgba(255, 59, 59, 0.55);
  opacity: 0;
  filter: blur(0.45px) drop-shadow(0 0 12px rgba(168, 85, 247, 0.68));
  mix-blend-mode: multiply;
  transition:
    opacity 500ms ease,
    filter 140ms ease;
}

.ghost-cursor.is-visible {
  opacity: 0.72;
}

.ghost-cursor.is-conflicting {
  filter: blur(0.2px) drop-shadow(0 0 24px rgba(255, 59, 59, 0.85));
  animation: cursor-pulse 180ms steps(2, end) 3;
}

.trail-dot {
  position: fixed;
  z-index: 1;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(168, 85, 247, 0.25);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: trail-fade 1600ms ease forwards;
}

.ghost-trail {
  background: rgba(255, 59, 59, 0.22);
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.3);
}

.crt-scanlines,
.noise {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 600ms ease;
}

.crt-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.03) 0,
    rgba(255, 255, 255, 0.03) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: overlay;
}

.noise {
  background-image:
    radial-gradient(circle at 18% 24%, rgba(255, 255, 255, 0.14) 0 1px, transparent 1px),
    radial-gradient(circle at 72% 38%, rgba(255, 255, 255, 0.10) 0 1px, transparent 1px),
    radial-gradient(circle at 44% 82%, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px);
  background-size: 18px 18px, 23px 23px, 29px 29px;
  animation: noise-shift 360ms steps(2, end) infinite;
}

.final-scene,
.ending {
  display: none;
}

.ending-actions {
  display: none;
}

.ending-actions.is-visible {
  display: flex;
}

.final-scene.is-visible,
.ending.is-visible {
  display: block;
}

.intro.is-hidden {
  display: none;
}

body.mid {
  --panel: rgba(20, 20, 20, 0.82);
}

body.mid .log-panel {
  border-color: rgba(168, 85, 247, 0.36);
  color: #111111;
  opacity: 0.86;
  transform: translateY(0);
}

body.horror {
  --bg: #080808;
  --text: #e7e7e7;
  --muted: #a0a0a0;
  --line: #e7e7e7;
  --panel: rgba(8, 8, 8, 0.86);
  --shadow: rgba(255, 59, 59, 0.16);
  color-scheme: dark;
}

body.horror .current-cursor {
  color: #e7e7e7;
  --cursor-outline: rgba(0, 0, 0, 0.9);
}

body.horror .current-cursor::before {
  filter:
    drop-shadow(0 1px 0 rgba(0, 0, 0, 0.86))
    drop-shadow(0 0 9px rgba(255, 255, 255, 0.18));
}

body.horror .ghost-cursor {
  mix-blend-mode: screen;
}

body.horror .log-panel {
  border-color: rgba(57, 255, 136, 0.34);
  color: var(--terminal);
  text-shadow: 0 0 8px rgba(57, 255, 136, 0.22);
}

body.horror .system-modal {
  background: rgba(8, 8, 8, 0.96);
  color: var(--text);
  border-color: var(--warning);
  box-shadow: 10px 10px 0 rgba(255, 59, 59, 0.18);
}

body.horror .modal-titlebar {
  background: rgba(255, 59, 59, 0.13);
}

body.horror .crt-scanlines {
  opacity: 0.42;
}

body.horror .noise {
  opacity: 0.18;
}

body.deep-horror .crt-scanlines {
  opacity: 0.68;
}

body.deep-horror .noise {
  opacity: 0.34;
}

body.deep-horror .page {
  text-shadow:
    1px 0 rgba(255, 59, 59, 0.26),
    -1px 0 rgba(57, 255, 136, 0.18);
}

body.shake .page {
  animation: screen-shake 170ms steps(2, end);
}

body.glitch #mainTitle,
body.glitch #normalLine,
body.glitch #finalQuestion,
body.glitch #endingTitle {
  animation: text-glitch 260ms steps(2, end);
}

body.ending-me {
  --bg: #f5f5f2;
  --text: #111111;
  --muted: #71716d;
  --line: #111111;
  --panel: rgba(245, 245, 242, 0.88);
}

body.ending-me .ghost-cursor,
body.ending-none .ghost-cursor,
body.ending-none .current-cursor {
  opacity: 0 !important;
}

body.ending-ghost .current-cursor {
  opacity: 0;
}

body.ending-ghost .ghost-cursor {
  opacity: 0.92;
}

body.ending-none .system-button,
body.ending-none .system-modal {
  animation: autonomous-drift 2400ms ease-in-out infinite alternate;
}

@keyframes trail-fade {
  from {
    opacity: 0.72;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.24);
  }
}

@keyframes cursor-pulse {
  50% {
    opacity: 1;
    transform: translate3d(var(--cursor-x, -80px), var(--cursor-y, -80px), 0) scale(1.6);
  }
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-5px, 2px);
  }
  50% {
    transform: translate(4px, -2px);
  }
  75% {
    transform: translate(-2px, -3px);
  }
}

@keyframes text-glitch {
  0%,
  100% {
    transform: translate(0, 0);
  }
  33% {
    transform: translate(3px, -1px);
  }
  66% {
    transform: translate(-2px, 1px);
  }
}

@keyframes noise-shift {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-3px, 2px);
  }
}

@keyframes autonomous-drift {
  from {
    transform: translate(-3px, 2px);
  }
  to {
    transform: translate(4px, -2px);
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-pill {
    max-width: 100%;
    text-align: left;
  }

  .log-panel {
    left: 14px;
    right: 14px;
    width: auto;
  }

  .stage {
    align-items: start;
    padding-top: 18vh;
  }

  .system-button {
    min-width: 96px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
