:root {
  --graphite: #1b1c1f;
  --yellow: #F5C518;
  --font: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: #e9e7e2; }
body { font-family: var(--font); color: var(--graphite); }

.story { position: relative; height: 980vh; height: 980svh; }
.stage { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; }

.world {
  position: absolute; inset: 0;
  transform-origin: 50% 62%;
  will-change: transform;
}
.state { position: absolute; inset: 0; }
.layers { position: absolute; inset: 0; }
.layers picture { display: contents; }
.state img.base {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 60%;
  max-width: none;
}
.stage.sized .state img.base { object-fit: fill; inset: auto; }
.state:not(:first-child) img.base { opacity: 0; }
.state:first-child img.base { opacity: 1; }
.state img.failed { visibility: hidden; }
.state.failed .piece { display: none; }

/* Masked copies of the same frame (same URL, no extra download). */
.piece { position: absolute; overflow: hidden; pointer-events: none; visibility: hidden; mask-composite: intersect; -webkit-mask-composite: source-in; }
.rv, .edge { position: absolute; inset: 0; overflow: hidden; }
.lit { position: absolute; overflow: hidden; }
/* Linear wipes: mv carries a static soft mask and slides, inv slides back by the same amount (transforms only). */
.mv, .inv, .emv, .einv { position: absolute; will-change: transform; }
.inv, .einv { overflow: hidden; }
.edge { filter: brightness(2.1); opacity: 0; }
.pimg { position: absolute; max-width: none; display: block; user-select: none; }

/* Idle life: tiny clipped windows onto the same frames. */
.idle { position: absolute; overflow: hidden; pointer-events: none; z-index: 1; opacity: 0; }
.idle .pimg { opacity: 0; }

.head {
  position: absolute; z-index: 2;
  top: 14%; left: 0; right: 0;
  width: max-content; max-width: none;
  margin: 0 auto; padding: 0;
  text-align: center; white-space: nowrap;
  font-family: var(--font); font-weight: 600; line-height: 1.1;
  font-size: clamp(26px, 4.2vw, 64px);
  letter-spacing: -0.01em;
  color: var(--graphite);
  will-change: opacity, transform;
}
.head .w { display: inline-block; will-change: opacity, transform; }
.state:not(:first-child) .head { opacity: 0; }

.panel {
  position: absolute; z-index: 3;
  bottom: 8%; left: 0; right: 0;
  width: fit-content; max-width: calc(100% - 32px);
  margin: 0 auto;
  display: flex; align-items: center; gap: 22px;
  padding: 16px 18px 16px 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  backdrop-filter: blur(16px) saturate(1.15);
  box-shadow: 0 10px 40px rgba(27, 28, 31, 0.18);
  opacity: 0; pointer-events: none;
  will-change: opacity, transform;
}
.panel-line { margin: 0; font-size: 18px; font-weight: 600; color: var(--graphite); white-space: nowrap; }
.pill {
  display: inline-block; white-space: nowrap;
  padding: 12px 26px; border-radius: 999px;
  background: var(--yellow); color: var(--graphite);
  font-weight: 600; font-size: 16px; text-decoration: none;
}
.pill:focus-visible { outline: 2px solid var(--graphite); outline-offset: 3px; }

@media (max-width: 767px) {
  .panel { flex-direction: column; gap: 12px; border-radius: 24px; padding: 20px 24px; bottom: 7%; }
  .panel-line { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .story { height: auto; }
  .stage { position: static; height: auto; overflow: visible; }
  .state { position: relative; height: 100vh; height: 100svh; overflow: hidden; }
  .world { transform: none !important; will-change: auto; }
  .piece, .idle { display: none !important; }
  .state img.base, .state:not(:first-child) img.base { opacity: 1; }
  .head .w { opacity: 1 !important; transform: none !important; }
  .head, .state:not(:first-child) .head { opacity: 1 !important; transform: none !important; }
  .panel {
    position: relative; bottom: auto; margin: 8vh auto;
    opacity: 1 !important; transform: none !important; pointer-events: auto;
    background: rgba(255, 255, 255, 0.9);
  }
}
