@import url("../pages/introduction.css");
@import url("../themes/illustrated-postcard.css");
@import url("../pages/image.css");
@import url("../pages/how-it-works.css");

@property --motion-stamp-peel-progress {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

:root {
  scrollbar-gutter: stable;
}

/* Keep dragged physical objects inside the table without owning document scroll. */
.postcard-table {
  overflow: clip;
}

.postcard {
  container-type: inline-size;
  --postcard-gutter: min(4vw, 44px);
  --motion-page-width: 854px;
  --motion-card-aspect: 1.62;
  --motion-camera-padding: 18px;
  --motion-scene-width: calc(var(--motion-page-width) + 2 * var(--motion-camera-padding));
  --motion-stage-inset: clamp(12px, calc(var(--motion-scene-width) * .06), 64px);
  --motion-canvas: #f3f3f1;
  --motion-paper: #fff;
  --motion-ink: #272727;
  --motion-rule: #a6a6a3;
  --motion-muted: #666663;
  --motion-stamp-width: calc(60px * var(--motion-stamp-size-ratio));
  --motion-stamp-height: calc(74px * var(--motion-stamp-size-ratio));
  --motion-strip-padding: 0px;
  --motion-strip-width: calc(var(--motion-stamp-width) * var(--motion-stamp-count, 0) + 2 * var(--motion-strip-padding));
  --motion-strip-height: calc(var(--motion-stamp-height) + 2 * var(--motion-strip-padding));
  --motion-stage-width: max(var(--motion-scene-width), var(--motion-strip-width) + var(--motion-stage-inset));
  --motion-stage-gap: 28px;
  color-scheme: light;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding-inline: var(--postcard-gutter);
  background: var(--motion-canvas);
  color: var(--motion-ink);
  font: 16px / 1.5 ui-sans-serif, system-ui, sans-serif;
}

@supports (color: light-dark(#000, #fff)) {
  .postcard {
    color-scheme: light dark;
    --motion-canvas: light-dark(#f3f3f1, #191919);
    --motion-paper: light-dark(#fff, #242424);
    --motion-ink: light-dark(#272727, #e7e7e3);
    --motion-rule: light-dark(#a6a6a3, #747472);
    --motion-muted: light-dark(#666663, #aaa9a5);
  }
}

.postcard,
.postcard * {
  box-sizing: border-box;
}

.postcard [hidden] {
  display: none !important;
}

.postcard.postcard-table {
  padding-inline: 0;
  --motion-page-height: calc(var(--motion-page-width) / var(--motion-card-aspect));
  --motion-card-sine: sin(min(90deg, var(--motion-card-roll)));
  --motion-strip-sine: sin(min(90deg, var(--motion-strip-roll)));
  --motion-stage-side: calc(var(--motion-strip-travel-x) + var(--motion-strip-height) * var(--motion-strip-sine) / 2 + 4px);
  --motion-stage-top: max(0px, calc(var(--motion-card-travel-y) + var(--motion-page-width) * var(--motion-card-sine) / 2 - var(--motion-camera-padding)));
  --motion-stage-bottom: calc(var(--motion-strip-travel-y) + var(--motion-strip-width) * var(--motion-strip-sine) / 2 + 4px);
  --motion-stage-gap: max(28px, var(--motion-stage-top) + var(--motion-stage-bottom));
  --motion-resting-width: calc(2 * var(--motion-stage-side) + max(
    var(--motion-stage-width),
    var(--motion-page-width) + var(--motion-page-height) * var(--motion-card-sine) + 2 * var(--motion-card-travel-x)
  ));
  --motion-resting-height: calc(
    var(--motion-stage-top) + var(--motion-page-height) + 2 * var(--motion-camera-padding)
    + var(--motion-stage-gap) + var(--motion-strip-height) + var(--motion-stage-bottom)
  );
}

.postcard .motion-table-scroll {
  container-type: size;
  --motion-width-scale: min(
    1,
    calc((100cqw - 2 * var(--postcard-gutter)) / var(--motion-resting-width))
  );
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: clip;
}

/* One camera projects the wood, postcard and loose stamps. */
.postcard .motion-table-camera {
  --motion-scene-scale: min(
    var(--motion-width-scale),
    calc(100cqh / var(--motion-resting-height))
  );
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
  /* Transparent coplanar containers must not intercept object hit tests. */
  pointer-events: none;
  --motion-view-height: 100cqh;
  perspective: calc(
    (var(--motion-page-width) * var(--motion-camera-lift-factor) + var(--motion-camera-lift-extra))
    * var(--motion-camera-perspective-factor) * var(--motion-scene-scale)
  );
  perspective-origin: 50% calc(var(--motion-view-height) / 2);
}

.postcard .motion-table-plane {
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
  min-inline-size: calc(var(--motion-resting-width) * var(--motion-scene-scale) + 2 * var(--postcard-gutter));
  min-block-size: calc(var(--motion-resting-height) * var(--motion-scene-scale));
  background-color: var(--motion-canvas);
  transform: rotateX(var(--motion-table-rotation));
  transform-origin: 50% calc(var(--motion-view-height) / 2);
  transform-style: preserve-3d;
}

.postcard .motion-table-plane::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--motion-table-overscan-y, 0px)) calc(-1 * var(--motion-table-overscan-x, 0px));
  background: inherit;
  pointer-events: none;
  z-index: -1;
}

.postcard .motion-table-plane .motion-stage {
  width: var(--motion-resting-width);
  padding: var(--motion-stage-top) var(--motion-stage-side) var(--motion-stage-bottom);
  zoom: var(--motion-scene-scale);
}

.postcard .motion-stage {
  position: relative;
  transform-style: preserve-3d;
  flex: 1;
  /* The focused page preview fits the card by width. */
  width: var(--motion-stage-width);
  zoom: min(1, calc(100cqw / var(--motion-stage-width)));
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--motion-stage-gap);
}

.postcard .motion-sections {
  pointer-events: auto;
  display: flex;
  align-self: flex-end;
  margin-right: var(--motion-stage-inset);
  padding: var(--motion-strip-padding);
  position: relative;
  z-index: 0;
}

.postcard .motion-drag-frame,
.postcard .motion-sections {
  touch-action: pinch-zoom;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.postcard .motion-sections button {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: var(--motion-stamp-width);
  height: var(--motion-stamp-height);
  place-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: var(--motion-paper);
  color: var(--motion-ink);
  font: inherit;
  font-size: 15px;
}

.postcard .motion-sections button[data-opening-slot]:not(:has(> .motion-stamp)) {
  background: transparent;
}

.postcard .motion-sections button[data-opening-slot]:not(:has(> .motion-stamp))::after {
  content: "";
  position: absolute;
  inset: 6% 8%;
  background: currentColor;
  opacity: .08;
  pointer-events: none;
}

.postcard .motion-stamp {
  --motion-stamp-peel-progress: 0;
  --motion-stamp-press-progress: var(--motion-stamp-press-progress-setting);
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  font: calc(15px * var(--motion-stamp-size-ratio)) / 1.5 ui-sans-serif, system-ui, sans-serif;
}

.postcard .motion-sections .motion-stamp {
  transition: --motion-stamp-peel-progress var(--motion-stamp-press-return-duration)
    var(--motion-stamp-press-return-easing);
}

.postcard .motion-sections button[data-stamp-pressed] > .motion-stamp {
  transition-timing-function: var(--motion-stamp-pressed-easing);
  --motion-stamp-peel-progress: var(--motion-stamp-press-progress);
}

.postcard[data-reduced-motion="true"] .motion-sections .motion-stamp {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .postcard .motion-sections .motion-stamp {
    transition: none;
  }
}

.postcard .motion-sections button:focus-visible {
  z-index: 1;
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.postcard .motion-drag-frame {
  position: relative;
  width: var(--motion-scene-width);
  z-index: 1;
  transform-style: preserve-3d;
  /* Hit-test the tilted card through the frame's plane. */
  pointer-events: none;
}

.postcard .motion-canvas {
  width: 100%;
  min-width: 0;
  padding: var(--motion-camera-padding);
  position: relative;
  z-index: 1;
  pointer-events: none;
  transform: rotate(var(--motion-camera-rotation));
  transform-origin: center;
  transform-style: preserve-3d;
}

.postcard .motion-flight-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.postcard .motion-stamp-flight {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--motion-stamp-width);
  height: var(--motion-stamp-height);
  transform-origin: 0 0;
  pointer-events: none;
}

.postcard .motion-shadow {
  position: absolute;
  inset: 0;
  background: var(--motion-ink);
  opacity: var(--motion-shadow-opacity);
  pointer-events: none;
  transform-origin: center;
}

.postcard .motion-pose {
  position: relative;
  transform-style: preserve-3d;
}

.postcard .motion-card {
  position: relative;
  pointer-events: auto;
  width: 100%;
  aspect-ratio: var(--motion-card-aspect);
  background: var(--motion-paper);
  transform-origin: center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.postcard .motion-panel {
  position: absolute;
  inset: 0;
  padding: 42px;
  font-size: 18px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

/* Keep authored text out of the arriving paper until its pens are prepared. */
.postcard[data-arriving] .motion-panel > * {
  visibility: hidden;
}

.postcard svg.handwritten-text {
  display: block;
  height: auto;
}

/* The font supplies paths; the postcard's light/dark palette owns ink. */
.postcard .motion-panel svg.handwritten-text path {
  stroke: var(--motion-ink);
}

.postcard .motion-postage {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--motion-stamp-width);
  height: var(--motion-stamp-height);
}

.postcard .motion-postage-probe {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
}

.postcard .motion-plane-probe {
  position: absolute;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
}

.postcard .motion-postage-probe[data-stamp-corner="top-right"],
.postcard .motion-postage-probe[data-stamp-corner="bottom-right"] {
  left: 100%;
}

.postcard .motion-postage-probe[data-stamp-corner="bottom-left"],
.postcard .motion-postage-probe[data-stamp-corner="bottom-right"] {
  top: 100%;
}

.postcard .motion-postage-flat {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 1px solid var(--motion-ink);
  background: var(--motion-paper);
}

.postcard .motion-postage-flat img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.postcard .motion-postmark,
.postcard .motion-press {
  position: absolute;
  top: var(--motion-postmark-top);
  right: var(--motion-postmark-right);
  width: calc(var(--motion-postmark-width) * var(--motion-postmark-size-ratio));
  height: calc(var(--motion-postmark-height) * var(--motion-postmark-size-ratio));
  pointer-events: none;
}

.postcard .motion-postmark {
  z-index: 2;
  opacity: 0;
  transform: rotate(var(--motion-postmark-rotation));
}

.postcard .motion-postmark-ring {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--motion-ink);
  border-radius: 50%;
}

.postcard .motion-postmark-lines {
  position: absolute;
  inset: 22% 0 22% 40%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.postcard .motion-postmark-lines span {
  display: block;
  border-top: 1px solid var(--motion-ink);
}

.postcard .motion-press {
  z-index: 3;
  border: 0;
  border-radius: 0;
  background: transparent;
  opacity: 0;
  transform: perspective(var(--motion-postmark-perspective))
    translateZ(var(--motion-postmark-drop-height)) rotate(var(--motion-postmark-rotation));
  transform-origin: center;
}
