:root {
  --white: oklch(1 0 0);
  --soft-yellow: oklch(0.96 0.09 101);
  --nailoong-yellow: oklch(0.88 0.18 94);
  --nailoong-orange: oklch(0.74 0.19 57);
  --signal-green: oklch(0.40 0.087 160);
  --alarm-red: oklch(0.63 0.23 28);
  --cyber-cyan: oklch(0.86 0.18 191);
  --cyber-magenta: oklch(0.67 0.27 342);
  --ink: oklch(0.12 0 0);
  --muted-ink: oklch(0.39 0 0);
  --night: oklch(0.085 0 0);
  --night-muted: oklch(0.76 0 0);
  --display-leading-desktop: 1.08;
  --display-leading-mobile: 1.12;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --scroll-progress: 0;
  --scroll-velocity: 0;
  --scroll-direction: 0;
  --flash-strength: 0;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
  background: var(--white);
}

body {
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  background: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.scroll-progress {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: color-mix(in oklch, var(--ink) 10%, transparent);
  pointer-events: none;
}

.scroll-progress span {
  display: block;
  width: calc(var(--scroll-progress) * 100%);
  height: 100%;
  background: var(--alarm-red);
  transform-origin: left center;
}

.hud {
  position: fixed;
  z-index: 90;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  color: var(--white);
  font-size: 12px;
  font-weight: 680;
  letter-spacing: 0.01em;
  mix-blend-mode: difference;
  pointer-events: none;
}

.hud-count b {
  font-variant-numeric: tabular-nums;
}

.glitch-flash {
  position: fixed;
  z-index: 80;
  inset: 0;
  overflow: hidden;
  background: var(--cyber-cyan);
  mix-blend-mode: screen;
  opacity: calc(var(--flash-strength) * 0.72);
  pointer-events: none;
  transition: opacity 70ms linear;
}

.glitch-flash::before,
.glitch-flash::after {
  content: "";
  position: absolute;
  inset: 0;
}

.glitch-flash::before {
  background: var(--cyber-magenta);
  clip-path: polygon(0 17%, 100% 10%, 100% 31%, 0 38%, 0 72%, 100% 62%, 100% 86%, 0 94%);
  transform: translateX(calc(var(--scroll-direction) * var(--scroll-velocity) * 4vw));
}

.glitch-flash::after {
  background: var(--white);
  clip-path: inset(46% 0 47% 0);
  opacity: calc(var(--scroll-velocity) * 0.82);
  transform: translateX(calc(var(--scroll-direction) * var(--scroll-velocity) * -7vw));
}

.story-screen {
  --section-progress: 0;
  --local-progress: 0;
  --chaos-level: 0;
  --visibility: 1;
  --copy-shift: 0px;
  position: relative;
  min-height: 100svh;
  overflow: clip;
  isolation: isolate;
}

.tone-white {
  color: var(--ink);
  background: var(--white);
}

.tone-soft {
  color: var(--ink);
  background: var(--soft-yellow);
}

.tone-yellow {
  color: var(--ink);
  background: var(--nailoong-yellow);
}

.tone-orange {
  color: var(--ink);
  background: var(--nailoong-orange);
}

.tone-dark {
  color: var(--white);
  background: var(--night);
}

.screen-inner {
  position: relative;
  width: 100%;
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: clamp(90px, 12svh, 148px) clamp(26px, 7vw, 112px) clamp(64px, 9svh, 112px);
}

.layout-right .screen-inner {
  justify-content: flex-end;
}

.layout-center .screen-inner {
  justify-content: center;
  text-align: center;
}

.story-copy {
  position: relative;
  z-index: 5;
  width: min(760px, 63vw);
  opacity: var(--visibility);
  transform: translate3d(0, var(--copy-shift), 0);
  will-change: transform, opacity;
}

.layout-center .story-copy {
  width: min(1040px, 88vw);
}

.copy-wide {
  width: min(980px, 78vw);
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  max-width: 13ch;
  font-size: clamp(3.4rem, 8vw, 6rem);
  font-weight: 790;
  line-height: var(--display-leading-desktop);
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.layout-center h1,
.layout-center h2,
.copy-wide h2 {
  max-width: 18ch;
}

.single-word {
  font-size: clamp(5rem, 14vw, 8rem);
  line-height: 1.1;
}

.story-copy > p {
  max-width: 34ch;
  margin-top: clamp(20px, 2.5vw, 34px);
  color: var(--muted-ink);
  font-size: clamp(1.05rem, 2vw, 1.5rem);
  font-weight: 500;
  line-height: 1.68;
  text-wrap: pretty;
}

.tone-dark .story-copy > p {
  color: var(--night-muted);
}

.scroll-cue {
  position: absolute;
  z-index: 6;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: clamp(26px, 7vw, 112px);
  color: var(--muted-ink);
  font-size: 12px;
  font-weight: 650;
}

.scroll-cue span {
  display: inline-block;
  margin-left: 8px;
  animation: cue-drift 1.8s var(--ease-smooth) infinite;
}

@keyframes cue-drift {
  50% { transform: translateY(6px); }
}

.parallax-layer {
  will-change: transform, opacity;
}

.scene-image {
  position: absolute;
  z-index: 2;
  width: min(47vw, 700px);
  height: min(78svh, 820px);
  margin: 0;
  pointer-events: none;
  transform: translate3d(
    calc(var(--section-progress) * var(--image-drift-x, 8vw)),
    calc(var(--section-progress) * var(--image-drift-y, -20svh)),
    0
  ) rotate(calc(var(--section-progress) * var(--image-rotate, 5deg))) scale(var(--image-scale, 1));
  transform-origin: 50% 70%;
}

.scene-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.tone-white .scene-image img {
  mix-blend-mode: multiply;
}

.tone-white .image-wave,
.tone-white .image-standing {
  opacity: 0.88;
}

.tone-white .image-wave img,
.tone-white .image-standing img {
  mix-blend-mode: normal;
}

.layout-left .scene-image {
  right: 2vw;
  bottom: -8svh;
}

.layout-right .scene-image {
  left: 1vw;
  bottom: -8svh;
}

.layout-center .scene-image {
  right: 50%;
  bottom: -30svh;
  transform: translate3d(
    calc(50% + var(--section-progress) * var(--image-drift-x, 5vw)),
    calc(var(--section-progress) * var(--image-drift-y, -16svh)),
    0
  ) rotate(calc(var(--section-progress) * var(--image-rotate, 4deg))) scale(var(--image-scale, 1));
  opacity: 0.34;
}

/* The warm-color chapters now use true transparent cutouts. Keep their
   characters present instead of fading them like full-bleed source photos. */
.tone-soft .scene-image,
.tone-yellow .scene-image,
.tone-orange .scene-image {
  opacity: 0.84;
}

.image-wave {
  --image-scale: 1.06;
  --image-rotate: -2deg;
}

.image-standing {
  --image-scale: 0.96;
  --image-drift-y: -22svh;
}

.image-crossed {
  --image-scale: 1.12;
  --image-rotate: 4deg;
}

.image-angel {
  --image-scale: 0.92;
  --image-drift-x: 14vw;
  bottom: -20svh;
}

.image-heart {
  --image-scale: 0.93;
  --image-rotate: -3deg;
}

.image-kick {
  --image-scale: 1.18;
  --image-rotate: 8deg;
  bottom: -22svh;
}

.image-blush {
  --image-scale: 1.28;
  clip-path: none;
}

.image-rabbit {
  --image-scale: 1.25;
  --image-drift-y: -32svh;
  --image-rotate: -7deg;
  clip-path: none;
}

.image-wallet {
  --image-scale: 0.92;
  clip-path: none;
}

.image-wallet img {
  mix-blend-mode: normal !important;
}

.image-heart-small {
  --image-scale: 1.08;
  --image-rotate: 5deg;
}

.image-official {
  --image-scale: 1.02;
  right: -8vw !important;
  bottom: -4svh !important;
  width: min(65vw, 980px);
}

.image-official img {
  mix-blend-mode: screen;
  opacity: 0.88;
}

.image-laugh-cutout {
  --image-scale: 1.12;
  --image-drift-y: -34svh;
  --image-rotate: -5deg;
  right: -2vw !important;
  bottom: -12svh !important;
  width: min(58vw, 820px);
  height: min(88svh, 920px);
}

.image-laugh-cutout img {
  mix-blend-mode: normal;
  filter: brightness(1.16) saturate(1.08) contrast(1.02);
}

.image-maid {
  --image-scale: 1.04;
  clip-path: none;
}

.image-maid img {
  mix-blend-mode: normal;
  opacity: 0.92;
  filter: brightness(1.18) saturate(1.08);
}

.image-laugh-crop {
  --image-scale: 1.18;
  --image-rotate: 4deg;
  bottom: -20svh !important;
  opacity: 0.28;
}

.image-laugh-crop img {
  mix-blend-mode: normal;
  filter: grayscale(0.45) contrast(1.12) brightness(0.82);
}

.echo-lines {
  display: flex;
  flex-wrap: wrap;
  justify-content: inherit;
  gap: 10px 22px;
  margin-top: clamp(24px, 3vw, 42px);
  font-size: clamp(1.6rem, 4vw, 3.7rem);
  font-weight: 750;
  line-height: 1.24;
  letter-spacing: -0.025em;
}

.echo-lines span:nth-child(2) {
  color: var(--alarm-red);
}

.echo-loud span:nth-child(1) { transform: rotate(-3deg); }
.echo-loud span:nth-child(2) { transform: rotate(2deg) scale(1.06); }
.echo-loud span:nth-child(3) { transform: rotate(-1deg) scale(1.12); }

.rule-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px 18px;
  max-width: 760px;
  margin-top: clamp(30px, 5vw, 68px);
  padding-top: 24px;
  border-top: 2px solid currentColor;
  font-size: clamp(1.5rem, 4vw, 3.5rem);
  line-height: 1.38;
}

.rule-line span {
  font-size: 0.55em;
  font-weight: 700;
}

.rule-line b {
  font-weight: 780;
}

.sticky-screen {
  min-height: 190svh;
}

.sticky-screen.climax {
  min-height: 235svh;
}

.sticky-frame {
  position: sticky;
  top: 0;
  height: 100svh;
  min-height: 100svh;
}

.sticky-screen .scene-image {
  transform: translate3d(
    calc((var(--sticky-progress) * 22vw) - 11vw),
    calc((var(--sticky-progress) * -46svh) + 23svh),
    0
  ) rotate(calc((var(--sticky-progress) * 2 - 1) * var(--image-rotate, 7deg))) scale(calc(var(--image-scale, 1) + var(--sticky-progress) * 0.14));
}

.corrupt-screen::after {
  content: "";
  position: absolute;
  z-index: 12;
  inset: -24px 0;
  background: linear-gradient(
    to bottom,
    transparent 0 3px,
    color-mix(in oklch, currentColor 22%, transparent) 3px 4px
  );
  background-size: 100% 4px;
  mix-blend-mode: soft-light;
  opacity: calc(0.025 + var(--chaos-level) * 0.085);
  pointer-events: none;
  transform: translateY(calc(var(--local-progress) * -24px));
}

.corrupt-heavy {
  background-color: var(--night);
}

.corrupt-heavy .screen-inner {
  transform: translate3d(
    calc(var(--scroll-direction) * var(--scroll-velocity) * var(--chaos-level) * -10px),
    0,
    0
  );
}

.corrupt-heavy .story-copy {
  text-shadow:
    calc(var(--scroll-velocity) * -7px) 0 0 color-mix(in oklch, var(--cyber-cyan) 56%, transparent),
    calc(var(--scroll-velocity) * 7px) 0 0 color-mix(in oklch, var(--cyber-magenta) 52%, transparent);
}

.corrupt-heavy .scene-image {
  filter:
    drop-shadow(calc(var(--scroll-velocity) * -10px) 0 0 color-mix(in oklch, var(--cyber-cyan) 52%, transparent))
    drop-shadow(calc(var(--scroll-velocity) * 10px) 0 0 color-mix(in oklch, var(--cyber-magenta) 48%, transparent));
}

.glitch-title {
  position: relative;
  isolation: isolate;
}

.glitch-title::before {
  content: attr(data-glitch);
  position: absolute;
  z-index: -1;
  inset: 0;
  color: var(--cyber-cyan);
  white-space: normal;
  opacity: calc(0.07 + var(--scroll-velocity) * 0.72);
  clip-path: polygon(0 0, 100% 0, 100% 35%, 0 44%, 0 72%, 100% 62%, 100% 100%, 0 100%);
  transform: translate3d(
    calc(-2px - var(--scroll-velocity) * 11px),
    calc(var(--section-progress) * -4px),
    0
  );
  pointer-events: none;
}

.glitch-title::after {
  content: attr(data-glitch);
  position: absolute;
  z-index: -1;
  inset: 0;
  color: var(--cyber-magenta);
  white-space: normal;
  opacity: calc(0.05 + var(--scroll-velocity) * 0.66);
  clip-path: polygon(0 13%, 100% 4%, 100% 54%, 0 63%, 0 86%, 100% 76%, 100% 100%, 0 100%);
  transform: translate3d(
    calc(2px + var(--scroll-velocity) * 13px),
    calc(var(--section-progress) * 3px),
    0
  );
  pointer-events: none;
}

.signal-shards {
  position: absolute;
  z-index: 9;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.signal-shards span {
  position: absolute;
  right: -14vw;
  left: -14vw;
  height: clamp(4px, 0.8vw, 11px);
  opacity: calc(0.05 + var(--scroll-velocity) * 0.64);
  transform: translate3d(
    calc(var(--scroll-direction) * var(--scroll-velocity) * 22vw),
    calc(var(--section-progress) * 12px),
    0
  );
}

.signal-shards span:nth-child(1) {
  top: 24%;
  background: var(--cyber-cyan);
  clip-path: inset(0 17% 0 4%);
}

.signal-shards span:nth-child(2) {
  top: 53%;
  height: clamp(2px, 0.42vw, 6px);
  background: var(--white);
  clip-path: inset(0 3% 0 36%);
  transform: translate3d(
    calc(var(--scroll-direction) * var(--scroll-velocity) * -27vw),
    calc(var(--section-progress) * -9px),
    0
  );
}

.signal-shards span:nth-child(3) {
  top: 76%;
  background: var(--cyber-magenta);
  clip-path: inset(0 27% 0 11%);
}

.corrupt-lite::after {
  opacity: calc(0.015 + var(--chaos-level) * 0.04);
}

.corrupt-coda::after {
  opacity: 0.035;
}

.corrupt-coda .glitch-title::before,
.corrupt-coda .glitch-title::after {
  opacity: calc(0.035 + var(--scroll-velocity) * 0.2);
}

.clone-field {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
}

.clone-field img {
  position: absolute;
  width: clamp(120px, 16vw, 260px);
  aspect-ratio: 1;
  object-fit: contain;
  mix-blend-mode: normal;
  opacity: calc(0.14 + var(--visibility) * 0.25);
  border-radius: 0;
}

.clone-field img:nth-child(1) {
  top: 8%;
  left: -3%;
  transform: translateY(calc(var(--section-progress) * -16svh)) rotate(-11deg);
}

.clone-field img:nth-child(2) {
  right: -4%;
  bottom: 3%;
  transform: translateY(calc(var(--section-progress) * 12svh)) rotate(9deg);
}

.clone-field img:nth-child(3) {
  right: 15%;
  top: -9%;
  transform: translateY(calc(var(--section-progress) * -20svh)) rotate(16deg);
}

.panic-ticker {
  position: absolute;
  z-index: 7;
  right: 0;
  bottom: 9svh;
  left: 0;
  overflow: hidden;
  padding: 12px 0;
  border-block: 1px solid color-mix(in oklch, var(--white) 26%, transparent);
  color: var(--nailoong-yellow);
  font-size: clamp(1.2rem, 4vw, 3.2rem);
  font-weight: 780;
  line-height: 1;
  white-space: nowrap;
  transform: rotate(-2deg);
}

.panic-ticker span {
  display: block;
  width: max-content;
  animation: ticker-move 12s linear infinite;
}

@keyframes ticker-move {
  to { transform: translateX(-50%); }
}

.finale .screen-inner {
  justify-content: center;
  text-align: center;
}

.finale .story-copy {
  width: min(920px, 88vw);
}

.finale h2 {
  max-width: 16ch;
  margin-inline: auto;
}

.finale .story-copy > p {
  margin-inline: auto;
}

#restart-button {
  position: relative;
  z-index: 8;
  margin-top: 34px;
  padding: 14px 20px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: var(--nailoong-yellow);
  font-size: 15px;
  font-weight: 760;
  cursor: pointer;
  transition: transform 180ms var(--ease-out), background-color 180ms ease;
}

#restart-button:hover {
  transform: translateY(-2px);
}

#restart-button:active {
  transform: translateY(0) scale(0.98);
}

#restart-button:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: 4px;
}

@media (max-width: 760px) {
  .hud {
    padding-inline: 16px;
  }

  .screen-inner {
    align-items: flex-start;
    padding: 14svh 22px 7svh;
  }

  .layout-right .screen-inner,
  .layout-center .screen-inner,
  .finale .screen-inner {
    justify-content: flex-start;
    text-align: left;
  }

  .story-copy,
  .layout-center .story-copy,
  .copy-wide,
  .finale .story-copy {
    width: 100%;
  }

  h1,
  h2 {
    max-width: 11ch;
    font-size: clamp(2.7rem, 13vw, 4.6rem);
    line-height: var(--display-leading-mobile);
    letter-spacing: -0.025em;
  }

  .layout-center h1,
  .layout-center h2,
  .copy-wide h2,
  .finale h2 {
    max-width: 13ch;
    margin-inline: 0;
  }

  .single-word {
    font-size: 5.7rem;
  }

  .story-copy > p {
    max-width: 29ch;
    margin-top: 18px;
    font-size: 1.05rem;
    line-height: 1.72;
  }

  .finale .story-copy > p {
    margin-inline: 0;
  }

  .scene-image,
  .layout-left .scene-image,
  .layout-right .scene-image,
  .layout-center .scene-image {
    right: -20vw;
    bottom: -7svh;
    left: auto;
    width: 92vw;
    height: 57svh;
    opacity: 0.34;
    transform: translate3d(
      calc(var(--section-progress) * 10vw),
      calc(var(--section-progress) * -18svh),
      0
    ) rotate(calc(var(--section-progress) * var(--image-rotate, 6deg))) scale(var(--image-scale, 1));
  }

  .tone-soft .scene-image,
  .tone-yellow .scene-image,
  .tone-orange .scene-image {
    opacity: 0.86;
  }

  .sticky-screen .scene-image {
    transform: translate3d(
      calc((var(--sticky-progress) * 30vw) - 15vw),
      calc((var(--sticky-progress) * -50svh) + 25svh),
      0
    ) rotate(calc((var(--sticky-progress) * 2 - 1) * var(--image-rotate, 8deg))) scale(calc(var(--image-scale, 1) + var(--sticky-progress) * 0.16));
  }

  .image-standing,
  .image-heart,
  .image-heart-small {
    right: -28vw;
  }

  .image-wallet {
    right: -24vw;
    opacity: 0.9;
  }

  .image-angel,
  .image-rabbit {
    bottom: -15svh;
  }

  .image-kick {
    right: -14vw;
    bottom: -13svh;
    width: 105vw;
  }

  .image-official {
    right: -36vw !important;
    bottom: -2svh !important;
    width: 130vw;
    height: 54svh;
    opacity: 0.42;
  }

  .image-laugh-cutout {
    right: -29vw !important;
    bottom: -9svh !important;
    width: 116vw;
    height: 70svh;
    opacity: 0.86;
  }

  .image-maid {
    right: -21vw;
    opacity: 0.88;
  }

  .image-laugh-crop {
    right: -24vw;
    opacity: 0.22;
  }

  .echo-lines {
    justify-content: flex-start;
    gap: 8px 14px;
    font-size: clamp(1.45rem, 8vw, 2.6rem);
    line-height: 1.3;
  }

  .rule-line {
    font-size: clamp(1.45rem, 8vw, 2.6rem);
  }

  .sticky-screen {
    min-height: 170svh;
  }

  .sticky-screen.climax {
    min-height: 220svh;
  }

  .clone-field img {
    width: 34vw;
    opacity: 0.3;
  }

  .panic-ticker {
    bottom: 8svh;
    font-size: 1.45rem;
  }

  #restart-button {
    padding: 14px 18px;
  }
}

@media (max-width: 380px) {
  h1,
  h2 {
    font-size: clamp(2.5rem, 12vw, 3.6rem);
  }

  .screen-inner {
    padding-inline: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .parallax-layer,
  .scene-image,
  .story-copy,
  .clone-field img,
  .corrupt-heavy .screen-inner {
    transform: none !important;
    opacity: 1;
  }

  .glitch-flash {
    opacity: 0 !important;
    transition: none;
  }

  .corrupt-screen::after {
    opacity: 0.02;
    transform: none !important;
  }

  .glitch-title::before,
  .glitch-title::after,
  .signal-shards {
    display: none;
  }

  .corrupt-heavy .story-copy {
    text-shadow: none;
  }

  .corrupt-heavy .scene-image {
    filter: none;
  }

  .scroll-cue span,
  .panic-ticker span {
    animation: none;
  }

  #restart-button {
    transition: none;
  }
}
