/* The split-flap transition: a page folds down along a thin crease like a flap on a departures board, and the
   next page is printed on its back and under it. */
:root {
  --paper: #f2eee6;
  --ink: #171614;
  --muted: #8b857b;
  --night: #16191c;
  --night-ink: #ece7dd;
  --night-muted: #8a8f94;
  --accent: #d9542b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: 'Newsreader Variable', 'Newsreader', Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  /* the script writes --cut, where the crease runs, and --hs, the size of the headline */
  --pad: clamp(20px, 4vw, 60px);
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
  perspective: 1500px;
  perspective-origin: 50% var(--cut, 50%);
}

/* ------------------------------------------------------------------ the pages */
.page {
  position: absolute;
  inset: 0;
  visibility: hidden;
}

.page.is-on {
  visibility: visible;
}

.page--a {
  background: var(--paper);
  color: var(--ink);
  --muted-c: var(--muted);
}

.page--b {
  background: var(--night);
  color: var(--night-ink);
  --muted-c: var(--night-muted);
}

.bar,
.foot {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
}

.bar {
  top: calc(var(--pad) * 0.75);
}

.foot {
  bottom: calc(var(--pad) * 0.75);
  font-size: 14px;
  font-style: italic;
  color: var(--muted-c);
}

.brand {
  font-size: 19px;
  font-weight: 560;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  gap: clamp(16px, 2.4vw, 30px);
  font-size: 15px;
}

.nav a {
  color: var(--muted-c);
  text-decoration: none;
  transition: color 0.25s ease;
}

.nav a[aria-current] {
  color: inherit;
}

@media (hover: hover) {
  .nav a:not([aria-current]):hover {
    color: var(--accent);
  }
}

a:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 6px;
  border-radius: 2px;
}

/* the headline stands on the crease line; the rest hangs under it */
.hero {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  top: var(--cut, 50%);
  height: 0;
}

.headline {
  position: absolute;
  left: 50%;
  top: 0;
  margin: 0;
  font-size: var(--hs, 200px);
  line-height: 1;
  font-weight: 340;
  font-optical-sizing: auto;
  letter-spacing: -0.035em;
  white-space: nowrap;
  transform: translateX(-50%);
}

.below {
  position: absolute;
  left: 50%;
  width: min(100%, 34ch);
  top: calc(var(--hs, 200px) * 0.36);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  transform: translateX(-50%);
}

.lede {
  margin: 0;
  font-size: clamp(16px, 1.3vw, 19px);
  line-height: 1.45;
  color: var(--muted-c);
}

.go {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
}

.go__arrow {
  width: 22px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (hover: hover) {
  .go--next:hover .go__arrow {
    transform: translateX(5px);
  }

  .go--back:hover .go__arrow {
    transform: translateX(-5px);
  }
}

/* ------------------------------------------------------------------ the fold */
.fold {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  transform-style: preserve-3d;
}

/* every piece is a whole copy of a page, clipped to the half it shows */
.piece {
  position: absolute;
  inset: 0;
}

.piece > .page {
  visibility: visible;
}

.piece--top {
  clip-path: inset(0 0 calc(100% - var(--cut, 50%)) 0);
}

.piece--bottom {
  clip-path: inset(var(--cut, 50%) 0 0 0);
}

.flap {
  position: absolute;
  inset: 0;
  transform-origin: 50% var(--cut, 50%);
  transform-style: preserve-3d;
  will-change: transform;
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* the back of the flap is turned over once already, so a half turn of the flap shows it the right way up */
.face--back {
  transform-origin: 50% var(--cut, 50%);
  transform: rotateX(180deg);
}

/* the light on the folding pieces: a black layer whose opacity the script sets */
.shade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
}

.crease {
  position: absolute;
  left: 0;
  top: var(--cut, 50%);
  width: 100%;
  height: 1px;
  margin-top: -0.5px;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 4;
  pointer-events: none;
}

.headline .ch {
  display: inline-block;
}

@media (max-width: 600px) {
  .foot {
    font-size: 13px;
  }

  .brand {
    font-size: 17px;
  }
}
