/* The postcard turn: a picture postcard lying on a linen table. It lifts, turns over to show its back (the message
   being written, the stamp, the postmark), then turns again and shows a new place. The sizes come from the script,
   in --cw and --ch (the card) and --u (one hundredth of the card, for every measure inside it). */
:root {
  --table: #1d3b3c;         /* the linen of the table */
  --table-light: #2c5654;   /* the light on the table */
  --card: #fbf4e6;          /* the front of the card, the white border */
  --card-back: #f6eedc;     /* the back of the card */
  --edge: #d6c6a6;          /* the board inside, seen when the card is edge-on */
  --print: #6b5a46;         /* the printed words on the back */
  --rule: #b9a68a;          /* the printed lines on the back */
  --hand: #1f2f54;          /* the ink of the handwriting */
  --postmark: #2b2f45;      /* the ink of the postmark */
  --title: #fff5e2;         /* the big letters on the front */
  --ui: #fbf4e6;            /* the button */
  --ui-ink: #1d3b3c;        /* the words on the button */

  --cw: 900px;
  --ch: 600px;
  --u: 9px;
  --teeth: 12px;
  --thick: 2.4px;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--table);
  color: var(--ui);
  font-family: 'Fraunces Variable', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--table);
  perspective: 1800px;
  perspective-origin: 50% var(--py, 46%);
  -webkit-tap-highlight-color: transparent;
}

/* ---- the table ---- */
.desk {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, var(--table-light), transparent 75%),
    repeating-linear-gradient(0deg, rgb(255 255 255 / 0.025) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgb(0 0 0 / 0.05) 0 1px, transparent 1px 4px),
    var(--table);
}

.desk::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 120% 90% at 50% 45%, transparent 55%, rgb(0 0 0 / 0.45));
}

/* ---- where the card sits (the shadow and the card share the place) ---- */
.shadow,
.tilt {
  position: absolute;
  left: 50%;
  top: var(--cy, 46%);
  width: var(--cw);
  height: var(--ch);
  margin-left: calc(var(--cw) / -2);
  margin-top: calc(var(--ch) / -2);
}

.shadow__soft,
.shadow__tight {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--u) * 0.6);
}

.shadow__soft {
  background: rgb(4 18 18 / 0.5);
  filter: blur(calc(var(--u) * 2.6));
  opacity: 0;
}

.shadow__tight {
  inset: 1px;
  background: rgb(4 16 16 / 0.55);
  filter: blur(calc(var(--u) * 0.35));
}

.tilt,
.card {
  transform-style: preserve-3d;
}

.card {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

/* ---- the faces, the paper and the thickness ---- */
.face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.face--front {
  transform: translateZ(calc(var(--thick) / 2));
}

.face--back {
  transform: rotateY(180deg) translateZ(calc(var(--thick) / 2));
}

/* the deckle edge: a rectangle a tooth smaller than the card, and a row of round teeth all round it */
.paper,
.slice,
.stamp__paper {
  -webkit-mask:
    linear-gradient(#000 0 0) center / calc(100% - var(--teeth)) calc(100% - var(--teeth)) no-repeat,
    radial-gradient(closest-side, #000 calc(100% - 0.7px), #0000 100%) 0 0 / var(--teeth) var(--teeth) round;
  mask:
    linear-gradient(#000 0 0) center / calc(100% - var(--teeth)) calc(100% - var(--teeth)) no-repeat,
    radial-gradient(closest-side, #000 calc(100% - 0.7px), #0000 100%) 0 0 / var(--teeth) var(--teeth) round;
}

.paper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--card);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.36 0 0 0 0 0.22 0 0 0 0.16 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

.paper::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(125deg, rgb(255 255 255 / 0.18), transparent 40%, rgb(80 50 20 / 0.08));
}

.paper--back {
  background-color: var(--card-back);
}

.slice {
  position: absolute;
  inset: 0;
  background: var(--edge);
}

.slice--a { transform: translateZ(calc(var(--thick) * 0.3)); }
.slice--b { transform: translateZ(0); background: #cdbb98; }
.slice--c { transform: translateZ(calc(var(--thick) * -0.3)); }

/* ---- the front ---- */
.print {
  position: absolute;
  inset: var(--border, 22px);
  overflow: hidden;
  background: #e9d7b8;
  box-shadow: inset 0 0 0 1px rgb(60 40 20 / 0.18);
}

.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  visibility: hidden;
}

[data-place="0"] .scene[data-scene="0"],
[data-place="1"] .scene[data-scene="1"],
[data-place="2"] .scene[data-scene="2"] {
  visibility: visible;
}

.print::after {
  /* the old print: a warm wash and a little grain */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 80% at 50% 40%, transparent 60%, rgb(90 50 20 / 0.22)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.2 0 0 0 0 0.1 0 0 0 0.22 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23g)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.title {
  position: absolute;
  left: calc(var(--u) * 4);
  bottom: calc(var(--u) * 3.4);
  margin: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  color: var(--title);
  line-height: 1;
  font-weight: 400;
  pointer-events: none;
}

.title__hello {
  font-family: 'Caveat Variable', cursive;
  font-weight: 700;
  font-size: calc(var(--u) * 4.2);
  margin: 0 0 calc(var(--u) * -0.6) calc(var(--u) * 0.6);
  transform: rotate(-4deg);
  text-shadow: calc(var(--u) * 0.18) calc(var(--u) * 0.18) 0 var(--ext, #7a3b25);
}

.title__name {
  display: block;
  white-space: nowrap;
  font-size: var(--name, 64px);
  font-weight: 900;
  font-variation-settings: 'opsz' 144, 'SOFT' 100, 'WONK' 1;
  letter-spacing: -0.01em;
  text-shadow:
    calc(var(--u) * 0.12) calc(var(--u) * 0.12) 0 var(--ext, #7a3b25),
    calc(var(--u) * 0.24) calc(var(--u) * 0.24) 0 var(--ext, #7a3b25),
    calc(var(--u) * 0.36) calc(var(--u) * 0.36) 0 var(--ext, #7a3b25),
    calc(var(--u) * 0.48) calc(var(--u) * 0.48) 0 var(--ext, #7a3b25),
    calc(var(--u) * 0.6) calc(var(--u) * 0.6) 0 var(--ext, #7a3b25),
    calc(var(--u) * 0.8) calc(var(--u) * 1) calc(var(--u) * 1.2) rgb(30 15 5 / 0.35);
}

.title .ch {
  display: inline-block;
  white-space: pre;
}

.is-tall .title {
  left: 0;
  right: 0;
  align-items: center;
  bottom: calc(var(--u) * 5);
}

/* ---- the back ---- */
.back {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1.12fr auto 1fr;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    'head head head'
    'msg rule box'
    'msg rule addr'
    'cap rule print';
  column-gap: calc(var(--u) * 3.6);
  padding: calc(var(--u) * 3.6) calc(var(--u) * 5) calc(var(--u) * 3.4);
  color: var(--print);
}

.back p {
  margin: 0;
}

.back__head {
  grid-area: head;
  text-align: center;
  font-size: calc(var(--u) * 2.3);
  font-weight: 600;
  font-variation-settings: 'opsz' 72, 'SOFT' 50;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  padding-left: 0.42em;
  margin-bottom: calc(var(--u) * 2) !important;
}

.back__caption,
.back__print {
  font-size: calc(var(--u) * 1.15);
  font-style: italic;
  font-variation-settings: 'opsz' 9;
  letter-spacing: 0.02em;
  align-self: end;
}

.back__caption {
  grid-area: cap;
}

.back__print {
  grid-area: print;
  text-align: right;
}

.back__msg {
  grid-area: msg;
  align-self: start;
  padding-top: calc(var(--u) * 1.4);
}

.back__rule {
  grid-area: rule;
  width: 1px;
  position: relative;
}

.back__rule span {
  position: absolute;
  inset: 0;
  background: var(--rule);
  transform-origin: 50% 0;
}

.back__box {
  grid-area: box;
  justify-self: end;
  width: calc(var(--u) * 12.5);
  height: calc(var(--u) * 15);
  border: 1px dashed var(--rule);
  display: grid;
  place-items: center;
  text-align: center;
  font-size: calc(var(--u) * 1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.3;
  padding: calc(var(--u) * 1.4);
}

.back__addr {
  grid-area: addr;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: calc(var(--u) * 3);
}

.back__lines {
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 1.1);
}

.aline {
  position: relative;
  height: calc(var(--u) * 4.4);
}

.aline__rule {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--rule);
  transform-origin: 0 50%;
}

.hand {
  display: block;
  width: fit-content;
  padding: 0 0.18em;
  margin-left: -0.18em;
  font-family: 'Caveat Variable', cursive;
  font-weight: 500;
  color: var(--hand);
  white-space: nowrap;
  font-size: calc(var(--u) * 3.6);
  line-height: 1.3;
}

.aline .hand {
  position: absolute;
  left: calc(var(--u) * 1.2);
  bottom: calc(var(--u) * -0.3);
  font-size: calc(var(--u) * 2.9);
}

.aline:nth-child(2) .hand { left: calc(var(--u) * 3); }
.aline:nth-child(3) .hand { left: calc(var(--u) * 4.8); }

.hand--sign {
  margin-left: calc(var(--u) * 6);
  font-weight: 700;
}

.is-tall .back {
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto auto auto;
  grid-template-areas:
    'head box'
    'msg msg'
    'rule rule'
    'addr addr'
    'cap print';
  padding: calc(var(--u) * 4.4) calc(var(--u) * 4.4) calc(var(--u) * 3.6);
  column-gap: calc(var(--u) * 2);
}

.is-tall .back__head {
  text-align: left;
  align-self: center;
  letter-spacing: 0.3em;
  padding-left: 0;
  margin-bottom: 0 !important;
}

.is-tall .back__msg {
  padding-top: calc(var(--u) * 2.4);
}

.is-tall .back__rule {
  width: auto;
  height: 1px;
  margin: calc(var(--u) * 1.6) 0 calc(var(--u) * 1);
}

.is-tall .back__rule span {
  transform-origin: 0 50%;
}

.is-tall .back__addr {
  padding: 0 0 calc(var(--u) * 2.6) calc(var(--u) * 10);
}

.is-tall .back__print {
  text-align: right;
}

/* ---- the things that land on the back: stamp, postmark, rubber stamp, pen ---- */
.over {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stamp {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  filter: drop-shadow(0 calc(var(--u) * 0.15) calc(var(--u) * 0.25) rgb(40 25 10 / 0.35));
}

.stamp__lift {
  width: 100%;
  height: 100%;
}

.stamp__paper {
  --teeth: calc(var(--u) * 0.95);
  position: absolute;
  inset: 0;
  background: #fffaf0;
  padding: calc(var(--u) * 1.05);
}

.stamp__art {
  display: block;
  width: 100%;
  height: 100%;
}

.stamp__value,
.stamp__label {
  position: absolute;
  color: #fffaf0;
  font-weight: 800;
  font-variation-settings: 'opsz' 72, 'SOFT' 100;
  text-shadow: 0 0 calc(var(--u) * 0.3) rgb(30 15 5 / 0.6);
}

.stamp__value {
  left: calc(var(--u) * 1.6);
  top: calc(var(--u) * 1.3);
  font-size: calc(var(--u) * 2.2);
}

.stamp__label {
  left: 0;
  right: 0;
  bottom: calc(var(--u) * 1.5);
  text-align: center;
  font-size: calc(var(--u) * 0.95);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.postmark {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
}

.postmark svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.postmark__ink {
  stroke: var(--postmark);
  fill: var(--postmark);
}

.postmark__ink circle,
.postmark__ink path {
  fill: none;
}

.postmark__ink text {
  stroke: none;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-weight: 700;
}

.postmark__ring {
  font-size: 8.4px;
  letter-spacing: 1px;
}

.postmark__day {
  font-size: 10px;
  letter-spacing: 0.4px;
}

.postmark__year {
  font-size: 8px;
  letter-spacing: 1px;
}

.tool {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
}

.tool__shadow {
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: rgb(30 20 10 / 0.5);
  filter: blur(calc(var(--u) * 0.8));
}

.tool__body {
  position: absolute;
  inset: 0;
}

.tool__body svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pen {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--u) * 5);
  height: calc(var(--u) * 13.3);
  visibility: hidden;
  filter: drop-shadow(calc(var(--u) * 0.6) calc(var(--u) * 0.8) calc(var(--u) * 0.5) rgb(30 20 10 / 0.3));
}

.pen svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- the button ---- */
.act {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  bottom: max(16px, env(safe-area-inset-bottom), 3.2vh);
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  color: var(--ui-ink);
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.act__fill {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--ui);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.28);
  transition: transform 0.55s cubic-bezier(0.34, 1.8, 0.5, 1);
}

.act__label {
  position: relative;
  display: block;
  padding: 13px 26px 14px;
  font-size: 16px;
  font-weight: 650;
  font-variation-settings: 'opsz' 24, 'SOFT' 100;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: letter-spacing 0.5s cubic-bezier(0.34, 1.8, 0.5, 1), opacity 0.3s;
}

.act:active .act__fill {
  transform: scale(0.94);
  transition-duration: 0.12s;
}

.act:focus-visible {
  outline: 2px solid var(--ui);
  outline-offset: 4px;
  border-radius: 999px;
}

@media (hover: hover) {
  .act:hover .act__fill {
    transform: scale(1.08, 1.14);
  }

  .act:hover .act__label {
    letter-spacing: 0.06em;
  }

  .act:active .act__fill {
    transform: scale(0.96);
  }
}

.act[aria-busy='true'] {
  cursor: default;
}

.act[aria-busy='true'] .act__label {
  opacity: 0.6;
}

/* ---- reduced motion: the back fades over the front, nothing turns ---- */
.is-reduced .face--back {
  transform: translateZ(calc(var(--thick) / 2 + 0.5px));
  -webkit-backface-visibility: visible;
  backface-visibility: visible;
  opacity: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
