:root {
  --bg-0: #030306;
  --bg-1: #080b14;
  --ink: #e6ebff;
  --accent-a: #7ec2ff;
  --accent-b: #7b69d8;
  --accent-c: #cf4b7b;
  --mx: 0.5;
  --my: 0.5;
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  --push-x: 0px;
  --push-y: 0px;
  --pulse: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  font-family: "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #030306;
  background:
    radial-gradient(
      1200px 900px at calc(12% + (var(--mx) - 0.5) * 14%)
        calc(42% + (var(--my) - 0.5) * 14%),
      rgba(28, 36, 75, 0.74) 0%,
      transparent 58%
    ),
    radial-gradient(860px 640px at 76% 18%, rgba(40, 22, 70, 0.54) 0%, transparent 66%),
    radial-gradient(
      circle at 18% 40%,
      #11172f 0%,
      var(--bg-1) 28%,
      var(--bg-0) 70%
    );
  color: var(--ink);
  overflow: hidden;
  perspective: 1400px;
  animation: worldHue 22s linear infinite;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: -10%;
  pointer-events: none;
  z-index: 0;
}

body::before {
  background:
    radial-gradient(
      700px 500px at 8% 50%,
      rgba(126, 194, 255, 0.08),
      transparent 58%
    ),
    radial-gradient(
      820px 560px at 84% 18%,
      rgba(123, 105, 216, 0.1),
      transparent 62%
    ),
    radial-gradient(
      760px 640px at 64% 88%,
      rgba(207, 75, 123, 0.1),
      transparent 64%
    );
  filter: blur(24px) saturate(88%);
  animation:
    glowShift 13s ease-in-out infinite alternate,
    auroraSpin 32s linear infinite;
}

body::after {
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: soft-light;
  opacity: 0.2;
  animation:
    scanlineMove 8s linear infinite,
    scanlineFlicker 0.8s steps(2, end) infinite;
}

.fx-wrap {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.fx-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, transparent 42%, rgba(0, 0, 0, 0.44) 100%),
    radial-gradient(circle at 20% 14%, rgba(255, 50, 95, 0.08), transparent 36%);
  mix-blend-mode: multiply;
}

.fx-ring {
  display: none;
}

.fx-ring-a {
  width: min(100vh, 760px);
  aspect-ratio: 1;
  left: clamp(-260px, -12vw, -120px);
  top: 50%;
  transform: translateY(-50%) rotateX(71deg) rotateZ(0deg);
  box-shadow:
    0 0 40px rgba(70, 215, 255, 0.22),
    inset 0 0 30px rgba(141, 107, 255, 0.22);
  animation: ringSpinA 12s linear infinite;
}

.fx-ring-b {
  width: min(74vh, 560px);
  aspect-ratio: 1;
  left: clamp(-180px, -7vw, -80px);
  top: 52%;
  transform: translateY(-50%) rotateX(74deg) rotateZ(0deg);
  border-color: rgba(255, 106, 159, 0.24);
  box-shadow:
    0 0 60px rgba(255, 106, 159, 0.24),
    inset 0 0 36px rgba(70, 215, 255, 0.16);
  animation: ringSpinB 7.5s linear infinite reverse;
}

.fx-beam {
  position: absolute;
  width: 120vmax;
  height: 24vmax;
  left: -10%;
  top: 40%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(126, 194, 255, 0.06) 28%,
    rgba(207, 75, 123, 0.09) 52%,
    transparent 78%
  );
  filter: blur(26px) saturate(108%);
  transform: translateY(-50%) rotate(-11deg);
  animation: beamSweep 9.2s ease-in-out infinite;
}

.fx-particles {
  position: absolute;
  inset: -20%;
  background-image:
    radial-gradient(circle, rgba(126, 194, 255, 0.38) 1px, transparent 1.6px),
    radial-gradient(circle, rgba(207, 75, 123, 0.28) 1px, transparent 1.8px),
    radial-gradient(circle, rgba(220, 220, 255, 0.2) 1px, transparent 1.5px);
  background-size:
    170px 170px,
    230px 230px,
    120px 120px;
  background-position:
    0 0,
    80px 120px,
    40px 40px;
  opacity: 0.11;
  filter: blur(0.2px);
  animation: particlesDrift 34s linear infinite;
}

.enter-gate {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  background:
    radial-gradient(
      700px 420px at 50% 45%,
      rgba(126, 194, 255, 0.08),
      transparent 64%
    ),
    radial-gradient(
      860px 420px at 50% 100%,
      rgba(207, 75, 123, 0.12),
      transparent 70%
    ),
    rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px) saturate(84%);
  transition:
    opacity 520ms ease,
    visibility 520ms ease,
    transform 520ms ease;
}

.enter-btn {
  appearance: none;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid rgba(195, 167, 255, 0.44);
  border-radius: 999px;
  background:
    linear-gradient(
      140deg,
      rgba(114, 129, 196, 0.26),
      rgba(70, 55, 110, 0.38) 45%,
      rgba(102, 32, 56, 0.3) 100%
    ),
    rgba(4, 6, 14, 0.92);
  color: rgba(236, 226, 255, 0.94);
  font: inherit;
  font-weight: 700;
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  letter-spacing: 0.04em;
  text-transform: none;
  padding: 0.95rem 1.6rem;
  min-width: 238px;
  cursor: pointer;
  box-shadow:
    0 16px 44px rgba(0, 0, 0, 0.64),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 20px rgba(123, 105, 216, 0.2);
  transition:
    transform 180ms ease,
    box-shadow 220ms ease,
    border-color 220ms ease,
    filter 220ms ease;
}

.enter-btn::before {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: -1;
  background: linear-gradient(
    115deg,
    transparent 20%,
    rgba(255, 255, 255, 0.08) 44%,
    transparent 58%
  );
  transform: translateX(-130%);
  opacity: 0.85;
  transition: transform 680ms cubic-bezier(0.19, 1, 0.22, 1);
}

.enter-btn:hover {
  transform: translateY(-1px) scale(1.02);
  border-color: rgba(221, 188, 255, 0.66);
  box-shadow:
    0 18px 44px rgba(0, 0, 0, 0.68),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 0 34px rgba(207, 75, 123, 0.28);
  filter: saturate(1.12) contrast(1.04);
}

.enter-btn:hover::before {
  transform: translateX(130%);
}

.enter-btn:active {
  transform: translateY(1px) scale(0.992);
}

.enter-btn:focus-visible {
  outline: none;
  border-color: rgba(224, 191, 255, 0.84);
  box-shadow:
    0 0 0 3px rgba(176, 116, 209, 0.28),
    0 14px 34px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(207, 75, 123, 0.22);
}

body.gate-closed .enter-gate {
  opacity: 0;
  visibility: hidden;
  transform: scale(1.03);
}

.intro-video-wrap {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.84);
  backdrop-filter: blur(6px) saturate(84%);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 720ms ease,
    transform 720ms ease,
    visibility 720ms ease;
}

body.gate-closed .intro-video-wrap {
  opacity: 1;
  visibility: visible;
}

.intro-video {
  display: block;
  width: auto;
  height: auto;
  max-width: 92vw;
  max-height: 92vh;
  border: 1px solid rgba(216, 176, 255, 0.18);
  border-radius: 14px;
  box-shadow:
    0 22px 90px rgba(0, 0, 0, 0.82),
    0 0 58px rgba(123, 105, 216, 0.22),
    0 0 18px rgba(207, 75, 123, 0.16);
}

body.intro-done .intro-video-wrap {
  opacity: 0;
  visibility: hidden;
  transform: scale(1.04);
}

.layout {
  position: relative;
  z-index: 3;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 38vw) 1fr;
  align-items: center;
  gap: clamp(12px, 3vw, 48px);
  padding: clamp(12px, 3vw, 36px);
  transform: translate3d(
    calc(var(--push-x) * 0.08),
    calc(var(--push-y) * 0.08),
    0
  );
  transition: transform 180ms ease-out;
}

body.prelude .layout {
  opacity: 0;
  transform: translate3d(0, 0, 0) scale(0.98);
}

body.intro-done .layout {
  animation: sceneReveal 900ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.figure-wrap {
  position: relative;
  height: clamp(520px, 90vh, 980px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transform: translateX(-40px) scale(0.96);
  opacity: 0;
  animation:
    figureEnter 1.1s 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards,
    figureHover 5s 1.4s ease-in-out infinite;
  transform-style: preserve-3d;
}

body.prelude .figure-wrap,
body.prelude .copy {
  animation-play-state: paused;
}

.figure-wrap::before {
  content: "";
  position: absolute;
  bottom: 7%;
  left: 50%;
  width: min(70%, 280px);
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(126, 194, 255, 0.14),
    rgba(123, 105, 216, 0.02) 68%,
    transparent 72%
  );
  filter: blur(18px);
  animation: haloPulse 4.6s ease-in-out infinite;
}

.figure-wrap::after {
  content: "";
  position: absolute;
  inset: 8% -6% 3%;
  border-radius: 44%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: conic-gradient(
    from 0deg,
    rgba(70, 215, 255, 0.2),
    rgba(141, 107, 255, 0.08),
    rgba(255, 106, 159, 0.2),
    rgba(70, 215, 255, 0.2)
  );
  mix-blend-mode: screen;
  filter: blur(11px);
  opacity: 0.3;
  transform: translateZ(-18px) scale(0.9);
  animation: auraSpin 16s linear infinite;
}

.figure {
  position: relative;
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 16px 28px rgba(0, 0, 0, 0.72))
    drop-shadow(0 0 calc(14px * var(--pulse)) rgba(126, 194, 255, 0.16));
  transform: translate3d(var(--push-x), calc(var(--push-y) * 0.5), 0)
    rotateX(var(--tilt-y)) rotateY(var(--tilt-x));
  animation:
    idleFloat 4.8s ease-in-out 1.4s infinite,
    chromaBreath 10s ease-in-out infinite;
  transition:
    transform 200ms ease-out,
    filter 220ms ease-out;
  user-select: none;
  -webkit-user-drag: none;
}

.copy {
  max-width: 900px;
  padding-right: clamp(12px, 5vw, 80px);
  transform: translateY(26px);
  opacity: 0;
  animation:
    copyEnter 1s 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards,
    copyFloat 8.2s 1.5s ease-in-out infinite;
  transform-style: preserve-3d;
}

.copy.dialogue-box {
  max-width: min(860px, 92vw);
  padding: 16px 20px;
  border: 1px solid rgba(255, 66, 96, 0.52);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(10, 0, 4, 0.84), rgba(0, 0, 0, 0.76)),
    rgba(0, 0, 0, 0.72);
  box-shadow:
    0 0 34px rgba(255, 42, 92, 0.26),
    inset 0 0 26px rgba(255, 38, 70, 0.14);
}

.line {
  margin: 0;
  font-size: clamp(1.2rem, 2.4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: 0.01em;
  text-wrap: balance;
  color: #e9ddff;
  text-shadow:
    0 0 10px rgba(126, 194, 255, 0.1),
    0 0 26px rgba(207, 75, 123, 0.12);
  animation: none;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.18));
  white-space: pre-line;
}

.line em {
  font-style: italic;
}

.line.mojibake {
  font-family: "MS Gothic", "Courier New", monospace;
  font-size: clamp(1rem, 2.15vw, 1.95rem);
  line-height: 1.3;
  letter-spacing: 0.04em;
  color: #ffb2c3;
  text-shadow:
    0 0 6px rgba(255, 0, 68, 0.62),
    0 0 16px rgba(255, 0, 68, 0.4),
    0 0 30px rgba(255, 0, 68, 0.3);
  animation: mojibakeFlicker 1.15s steps(2, end) infinite;
}

.line.dialogue {
  position: relative;
  min-height: 7.5em;
}

.line.dialogue::after {
  content: " _";
  color: rgba(255, 180, 198, 0.92);
  animation: cursorBlink 0.9s steps(1, end) infinite;
}

.line.done::after {
  content: "";
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .figure-wrap {
    width: min(56vw, 340px);
    height: min(74vh, 700px);
    transform: translateY(20px) scale(0.96);
  }

  .copy {
    padding: 0 12px 20px;
  }
}

@keyframes figureEnter {
  0% {
    opacity: 0;
    transform: translateX(-56px) scale(0.94) rotate(-1.4deg);
    filter: blur(4px);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1) rotate(0deg);
    filter: blur(0);
  }
}

@keyframes sceneReveal {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.98);
    filter: blur(4px);
  }
  100% {
    opacity: 1;
    transform: translate3d(
        calc(var(--push-x) * 0.08),
        calc(var(--push-y) * 0.08),
        0
      )
      scale(1);
    filter: blur(0);
  }
}

@keyframes copyEnter {
  0% {
    opacity: 0;
    transform: translateY(26px);
    filter: blur(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

@keyframes idleFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes figureHover {
  0%,
  100% {
    transform: translateX(0) rotate(-0.5deg);
  }
  50% {
    transform: translateX(2px) rotate(0.8deg);
  }
}

@keyframes haloPulse {
  0%,
  100% {
    transform: translateX(-50%) scale(0.95);
    opacity: 0.62;
  }
  50% {
    transform: translateX(-50%) scale(1.06);
    opacity: 0.95;
  }
}

@keyframes haloColorRoll {
  0% {
    filter: blur(18px) hue-rotate(0deg);
  }
  100% {
    filter: blur(18px) hue-rotate(360deg);
  }
}

@keyframes glowShift {
  0% {
    transform: translate3d(-2%, -1%, 0) scale(1);
  }
  100% {
    transform: translate3d(2%, 1.5%, 0) scale(1.05);
  }
}

@keyframes auroraSpin {
  0% {
    transform: rotate(0deg) scale(1.03);
  }
  100% {
    transform: rotate(360deg) scale(1.03);
  }
}

@keyframes scanlineMove {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(8px);
  }
}

@keyframes worldHue {
  0% {
    filter: hue-rotate(0deg) saturate(1);
  }
  50% {
    filter: hue-rotate(-3deg) saturate(1.03);
  }
  100% {
    filter: hue-rotate(0deg) saturate(1);
  }
}

@keyframes ringSpinA {
  0% {
    transform: translateY(-50%) rotateX(71deg) rotateZ(0deg);
  }
  100% {
    transform: translateY(-50%) rotateX(71deg) rotateZ(360deg);
  }
}

@keyframes ringSpinB {
  0% {
    transform: translateY(-50%) rotateX(74deg) rotateZ(0deg) scale(1);
  }
  50% {
    transform: translateY(-50%) rotateX(74deg) rotateZ(180deg) scale(1.03);
  }
  100% {
    transform: translateY(-50%) rotateX(74deg) rotateZ(360deg) scale(1);
  }
}

@keyframes beamSweep {
  0%,
  100% {
    transform: translate(-10%, -50%) rotate(-11deg);
    opacity: 0.1;
  }
  50% {
    transform: translate(8%, -50%) rotate(-9deg);
    opacity: 0.24;
  }
}

@keyframes particlesDrift {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(-2%, -1%, 0) scale(1.03);
  }
  100% {
    transform: translate3d(-4%, -2%, 0) scale(1.06);
  }
}

@keyframes auraSpin {
  0% {
    transform: translateZ(-18px) scale(0.9) rotate(0deg);
  }
  100% {
    transform: translateZ(-18px) scale(0.9) rotate(360deg);
  }
}

@keyframes chromaBreath {
  0%,
  100% {
    filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.62))
      drop-shadow(0 0 12px rgba(70, 215, 255, 0.16));
  }
  50% {
    filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.62))
      drop-shadow(0 0 20px rgba(255, 106, 159, 0.22));
  }
}

@keyframes copyFloat {
  0%,
  100% {
    transform: translateY(0) rotateX(0deg);
  }
  50% {
    transform: translateY(-6px) rotateX(2deg);
  }
}

@keyframes scanlineFlicker {
  0%,
  100% {
    opacity: 0.14;
  }
  50% {
    opacity: 0.22;
  }
}

@keyframes cursorBlink {
  0%,
  40% {
    opacity: 1;
  }
  41%,
  100% {
    opacity: 0;
  }
}

@keyframes mojibakeFlicker {
  0%,
  100% {
    opacity: 1;
    transform: translate(0, 0);
    filter: hue-rotate(0deg);
  }
  15% {
    opacity: 0.92;
    transform: translate(-0.5px, 0.2px);
  }
  28% {
    opacity: 0.84;
    transform: translate(0.8px, -0.3px);
    filter: hue-rotate(-10deg);
  }
  62% {
    opacity: 0.96;
    transform: translate(-0.2px, 0.4px);
  }
  74% {
    opacity: 0.76;
    transform: translate(1.1px, -0.6px);
    filter: hue-rotate(8deg);
  }
}
