@property --down {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

@property --side {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

:root {
  --ink: #26382c;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='164' height='164'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath d='M0 0h164v164H0z' filter='url(%23g)' opacity='.16'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: system-ui, sans-serif;
  background: #182c23;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--grain), radial-gradient(ellipse at 50% 34%, #2d4938, #14261e 77%);
}

.desk {
  display: flex;
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(.65rem, 3vw, 2.5rem);
  overflow: clip;
  container-type: inline-size;
}

.stage {
  --leaf: min(26rem, 50cqi);
  --sheet-width: calc(2 * var(--leaf));
  --visible-width: calc(var(--leaf) * (1 + max(0, cos(var(--side)))));
  --visible-height: calc(var(--sheet-height) * (1 + max(0, cos(var(--down)))) / 2);
  width: var(--sheet-width);
  margin: auto;
  border-radius: 2px;
  box-shadow: 0 2px 4px #0a160e35, 0 16px 36px #07160e66;
}

.tilt {
  height: 100%;
  transform-style: preserve-3d;
}

.card {
  display: grid;
  grid-template: "front blank" 1fr "note blank" 1fr / minmax(0, 1fr) minmax(0, 1fr);
  width: var(--sheet-width);
  transform-style: preserve-3d;
  font-family: Georgia, "Times New Roman", serif;
}

.paper {
  background-color: #f7ecd5;
  background-image: url("./paper-grain.svg"), linear-gradient(90deg, #f8eed8, #f5e9d0);
  border-radius: 1px;
}

.intro .note, .intro .blank .paper {
  background-color: rgb(65 41 22 / var(--wash));
  background-blend-mode: normal, multiply;
}

.front, .note {
  display: flex;
  min-height: clamp(11.25rem, 23vw, 14rem);
  padding: clamp(.8rem, 3.2vw, 2rem);
}

.front {
  --portrait-size: clamp(1.85rem, 8.5vw, 5.25rem);
  --portrait-gap: clamp(.45rem, 1.9vw, 1.375rem);
  grid-area: front;
  flex-direction: column;
  justify-content: center;
  gap: clamp(.25rem, 1vw, .75rem);
  transform: translateZ(.3px);
}

.identity {
  display: flex;
  gap: var(--portrait-gap);
  align-items: center;
}

.identity > :last-child {
  flex: 1;
  min-width: 0;
  container-type: inline-size;
}

.portrait {
  flex: 0 0 var(--portrait-size);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #74694f url("./portrait.jpg") center / cover;
  box-shadow: 0 0 0 1px #8671518c, 0 0 0 3px #fffaefad;
}

h1 {
  margin: 0;
  font-size: min(2.6rem, 10cqi);
  font-weight: normal;
  letter-spacing: -.045em;
  line-height: 1.02;
  white-space: nowrap;
}

.role {
  margin: .55em 0 0;
  color: #4a5947;
  font: 500 clamp(.75rem, 1.8vw, .9rem)/1.35 system-ui, sans-serif;
}

.contact:not([hidden]) {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  min-height: 44px;
  margin-inline-start: calc(var(--portrait-size) + var(--portrait-gap));
  color: #61452a;
  font-size: clamp(.875rem, 1.8vw, 1rem);
  text-decoration-color: #785638b3;
  text-underline-offset: .23em;
}

.contact:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

.note {
  --wash: calc(.13 * abs(sin(var(--down))));
  grid-area: note;
  position: relative;
  align-items: center;
  transform-origin: top;
  transform: rotateX(var(--down));
  transform-style: preserve-3d;
}

.note p {
  margin: 0;
  font-size: clamp(1rem, 2.65vw, 1.4rem);
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-wrap: pretty;
  backface-visibility: hidden;
}

.blank {
  grid-area: blank;
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  transform-origin: left;
  transform: translateZ(-.5px) rotateY(var(--side));
  transform-style: preserve-3d;
  pointer-events: none;
}

.blank .paper {
  --wash: calc(.13 * abs(sin(var(--side))));
  position: relative;
}

.blank .paper:first-child { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

.blank .paper:last-child {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  transform-origin: top;
  transform: rotateX(calc(-1 * var(--down)));
}

.note::before, .blank .paper::before, .blank .paper::after {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: .35;
}

.note::before, .blank .paper::before {
  inset: 0 0 auto;
  height: 9px;
  background: url("./paper-crease.svg#horizontal") top left / 128px 9px repeat-x;
}

.blank .paper:first-child::before { display: none; }

.blank .paper::after {
  inset: 0 auto 0 0;
  width: 9px;
  background: url("./paper-crease.svg#vertical") top left / 9px 128px repeat-y;
}


@media (max-height: 37rem) {
  .desk { padding: .625rem; }
  .front, .note { min-height: min(11.25rem, 43svh); padding: .625rem; }
  .note p { font-size: clamp(.9375rem, 3vw, 1rem); line-height: 1.25; }
}

@media (max-width: 40rem), (pointer: coarse) and (orientation: landscape) and (max-height: 30rem) {
  .stage {
    --leaf: min(34rem, 100cqi);
    --sheet-width: var(--leaf);
    --visible-width: var(--leaf);
    --visible-height: calc(var(--sheet-height) * (1 + max(0, cos(var(--down))) + 2 * max(0, cos(var(--side)))) / 4);
  }

  .card {
    grid-template: "front" 1fr "note" 1fr "blank" 2fr / minmax(0, 1fr);
  }

  .front, .note {
    min-height: min(9rem, 22svh);
    padding: clamp(.625rem, 2.8vw, 1rem);
  }

  .front {
    --portrait-size: clamp(2.4rem, 10vw, 4rem);
    --portrait-gap: clamp(.625rem, 2.5vw, 1rem);
  }

  .role { font-size: clamp(.8125rem, 2.5vw, .9rem); }
  .note p { font-size: clamp(.9375rem, 3.6vw, 1rem); line-height: 1.28; }

  .blank {
    /* Follow the bottom of the offer while the two blank halves tuck behind it and the cover. */
    transform-origin: top;
    transform:
      translateY(calc((cos(var(--down)) - 1) * 50%))
      translateZ(calc(var(--sheet-height, 0px) * sin(var(--down)) / 4 - .5px))
      rotateX(calc(var(--down) - var(--side)));
  }

  .blank .paper::after { display: none; }
  .blank .paper:first-child::before { display: block; }

  @media (orientation: landscape) and (min-width: 30rem) and (max-height: 30rem) {
    .front, .note { padding-block: .5rem; }

    .front {
      --portrait-size: 3.25rem;
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: center;
      gap: .75rem;
    }

    h1 { font-size: min(1.65rem, 10cqi); }
    .contact:not([hidden]) { align-self: center; margin-inline-start: 0; }
  }
}

@media (prefers-reduced-motion: no-preference) {
  .contact:hover { color: var(--ink); }

  .tilt {
    --tilt: rotateX(var(--pitch, 0deg)) rotateY(var(--yaw, 0deg));
    transform: perspective(105rem) var(--tilt);
    transition: transform 180ms ease-out;
  }

  .intro .tilt { transform: var(--tilt); }

  .intro .stage {
    /* Center the projected paper, not the folded leaves behind it. */
    width: var(--visible-width);
    height: var(--visible-height);
    transition: --down 1.4s cubic-bezier(.36, 0, .24, 1), --side 1.55s cubic-bezier(.36, 0, .24, 1);
  }

  .intro:not(.tall) .stage { --down: -180deg; }
  .intro:not(.wide) .stage { --side: 180deg; }
}
