.thesis-page { --thesis-stage-top: 112px; }

.thesis-page .case-study {
  padding-inline: 60px;
  overflow: clip;
}

.thesis-layout {
  display: grid;
  grid-template-columns: minmax(0, 606px) minmax(0, 613px);
  align-items: stretch;
  gap: 49px;
  width: min(100%, 1273px);
  margin: 0 auto 127px;
}

.thesis-copy {
  position: relative;
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.thesis-copy__stage-rail {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.thesis-copy__stage,
.thesis-pages {
  position: sticky;
  top: var(--thesis-stage-top);
  width: 100%;
  height: calc(100vh - var(--thesis-stage-top) - 40px);
}

.thesis-copy__block {
  position: relative;
  width: 100%;
  min-height: var(--anchor-height, 100vh);
}

.thesis-copy__content {
  --copy-opacity: 0;
  --copy-translate-y: 100px;
  position: absolute;
  top: 50%;
  left: 0;
  display: flex;
  width: 100%;
  flex-direction: column;
  justify-content: center;
  opacity: var(--copy-opacity);
  transform: translate3d(
    0,
    calc(-50% + var(--copy-translate-y)),
    0
  );
  will-change: transform, opacity;
}

.thesis-copy__content:nth-child(-n + 2) { max-width: 520px; }

h2 {
  margin-bottom: 25px;
}

.thesis-pages {
  align-self: start;
  margin: 0;
  padding: 0;
  list-style: none;
  perspective: 1200px;
}

.thesis-pages__status {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max-content;
  max-width: 80%;
  transform: translate(-50%, -50%);
  color: rgb(0 0 0 / 48%);
  font-size: 14px;
  font-weight: 200;
  text-align: center;
}

.thesis-sheet {
  --sheet-x: 0px;
  --sheet-y: 0px;
  --sheet-rotation: 0deg;
  --sheet-opacity: 1;
  --sheet-flight-x: 0px;
  --sheet-flight-rotation: 0deg;
  --sheet-travel: 0vh;
  --sheet-scale: 1;
  --sheet-shadow-primary: 0;
  --sheet-shadow-secondary: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: var(--sheet-index, 1);
  width: min(68%, 405px);
  aspect-ratio: 595 / 842;
  margin: 0;
  box-shadow:
    -1px -1px 4px rgb(0 0 0 / 7%),
    0 3px 8px -2px rgb(0 0 0 / 10%),
    0 24px 38px -5px rgb(0 0 0 / var(--sheet-shadow-primary)),
    -3px 0 12px rgb(0 0 0 / var(--sheet-shadow-secondary));
  background: #fff;
  opacity: var(--sheet-opacity);
  transform: translate3d(
      calc(-50% + var(--sheet-x) + var(--sheet-flight-x)),
      calc(-50% + var(--sheet-y) + var(--sheet-travel)),
      0
    )
    rotate(calc(var(--sheet-rotation) + var(--sheet-flight-rotation)))
    scale(var(--sheet-scale));
  will-change: transform, opacity;
}

.thesis-sheet img {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  object-fit: contain;
  opacity: 0;
}

.thesis-sheet.is-rendered img {
  opacity: 1;
}

@media (max-width: 960px) {
  .thesis-page {
    --thesis-gutter: clamp(16px, 5vw, 40px);
  }

  .thesis-page .case-study {
    padding-inline: 0;
  }

  .thesis-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    margin-bottom: 48px;
  }

  .thesis-copy__stage {
    display: grid;
    grid-template: "pages" minmax(0, 1fr) "copy" auto / minmax(0, 1fr);
    height: calc(100svh - var(--thesis-stage-top));
  }

  .thesis-copy__content,
  .thesis-copy__content:nth-child(n) {
    position: relative;
    grid-area: copy;
    top: auto;
    left: auto;
    z-index: 1;
    justify-content: start;
    width: min(100%, 580px);
    max-width: none;
    justify-self: center;
    padding: 4px var(--thesis-gutter) clamp(16px, 4svh, 32px);
    transform: translateY(calc(var(--copy-translate-y) / 5));
  }

  .thesis-page .case-study .thesis-copy h2 {
    margin-bottom: 12px;
    font-size: clamp(1.125rem, 5.4vw, 1.625rem);
    line-height: 1.12;
    overflow-wrap: anywhere;
  }

  .thesis-page .case-study .thesis-copy p {
    margin-bottom: 8px;
    font-size: clamp(0.875rem, 3.7vw, 1.0625rem);
    line-height: 1.4;
  }

  .thesis-page .case-study .thesis-copy p:last-child { margin-bottom: 0; }

  .thesis-pages {
    position: relative;
    top: auto;
    grid-area: pages;
    align-self: stretch;
    height: auto;
    container-type: size;
  }

  .thesis-sheet {
    width: min(75cqw, 350px, max(0px, (100cqh - 40px) * 595 / 842));
    transform: translate3d(
        calc(-50% + (var(--sheet-x) + var(--sheet-flight-x)) * 0.55),
        calc(-50% + var(--sheet-y) * 0.45 + var(--sheet-travel)),
        0
      )
      rotate(calc(var(--sheet-rotation) + var(--sheet-flight-rotation)))
      scale(var(--sheet-scale));
  }
}

@media (max-width: 760px) {
  .thesis-page {
    --thesis-stage-top: 0px;
  }

  .thesis-page .case-back__link {
    white-space: normal;
    text-align: center;
  }
}

@supports (animation-timeline: view()) and (animation-range: contain) {
  @media (max-width: 760px) {
    .thesis-copy__stage-rail {
      view-timeline: --thesis-rail block;
    }

    .thesis-copy__stage {
      position: relative;
      animation: thesis-stage-follow linear both;
      animation-timeline: --thesis-rail;
      animation-range: contain;
    }

    @keyframes thesis-stage-follow {
      from { transform: translateY(0); }
      to { transform: translateY(var(--stage-travel, 0px)); }
    }
  }
}

@media (max-width: 960px) and (max-height: 540px) and (min-width: 540px) {
  .thesis-copy__stage {
    grid-template: "copy pages" minmax(0, 1fr) / minmax(0, 1fr) minmax(0, 1fr);
  }

  .thesis-copy__content:nth-child(n) {
    align-self: center;
    padding: 8px 16px;
  }

  .thesis-page .case-study .thesis-copy h2 { font-size: 1.25rem; }
  .thesis-page .case-study .thesis-copy p { font-size: 0.875rem; }
}

@media (prefers-reduced-motion: reduce) {
  .thesis-sheet,
  .thesis-copy__content { will-change: auto; }
}
