/* A stack of travel postcards to flick away: the postcards of Casa Lumen, a made-up guest house in Amalfi, on a warm
   table with a soft light from above and a fine grain. Every card is two layers: .card is moved by the script
   (spring, drag, flight, tilt), .card__flip is turned over by the script, their children are styled here.
   The sizes come from the stage in vw and vh: the script reads them back. */
:root {
  --page: #efe9df;          /* the table */
  --light: #faf6ee;         /* the light falling on it */
  --ink: #1e1c19;           /* the words on the page */
  --muted: #8d8578;         /* the small words on the page */
  --paper: #fbf8f2;         /* the card's paper */
  --paper-edge: #e9e2d5;    /* the paper's edge in shadow */
  --blue: #2c4f93;          /* the ink of the pen and of the postmark */
  --lemon: #e7bf3a;         /* the sun of the mark */
  --shadow: 46, 36, 22;     /* the colour of the shadows, r g b */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* ------------------------------------------------------------------ the table */
.stage {
  position: relative;
  height: 100svh;
  min-height: 320px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  background:
    radial-gradient(60% 55% at 50% 42%, var(--light), transparent 72%),
    radial-gradient(120% 90% at 50% 120%, rgba(var(--shadow), 0.07), transparent 60%),
    var(--page);
}

/* the grain of the table, painted once by the script */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--grana, none);
  background-size: 160px 160px;
  opacity: calc(var(--grana-forza, 0.07) * 2.4);
}

/* ------------------------------------------------------------------ the head */
.head {
  position: absolute;
  top: clamp(12px, 4.2vh, 34px);
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 clamp(14px, 4vw, 40px);
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0;
  font-size: clamp(12px, 1.5vw + 0.4vh, 15px);
  font-weight: 620;
  font-stretch: 112%;
  letter-spacing: -0.01em;
}

.brand__mark {
  width: 1.5em;
  height: 1.5em;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.brand__sun {
  fill: var(--lemon);
  stroke: none;
}

.brand__place {
  color: var(--muted);
  font-weight: 450;
  font-stretch: 100%;
}

.head__note {
  margin: 0;
  color: var(--muted);
  font-size: clamp(11px, 1.2vw + 0.3vh, 13px);
  font-stretch: 105%;
}

/* ------------------------------------------------------------------ the stack */
.table {
  position: absolute;
  inset: 0;
  perspective: 1400px;
}

.card {
  /* the size of a card: on its side, 3 by 2, measured on the width and the height */
  --w: min(540px, 84vw, 66vh);
  --lift: 0;
  --sx: 0;
  --sy: 1;
  --lx: 30%;
  --ly: 20%;
  --sh: 0.3;
  position: absolute;
  left: 50%;
  top: 47%;
  width: var(--w);
  aspect-ratio: 3 / 2;
  margin-left: calc(var(--w) / -2);
  margin-top: calc(var(--w) / -3);
  font-size: calc(var(--w) / 30);
  transform-style: preserve-3d;
  will-change: transform;
  cursor: grab;
}

.card.is-held {
  cursor: grabbing;
}

/* the shadow lives apart from the faces: it does not turn over with the card and falls always downwards.
   Its box is empty, so the shadow is only drawn around it */
.card__shade {
  position: absolute;
  inset: 0;
  border-radius: 0.38em;
  box-shadow:
    calc(var(--sx) * (0.5px + var(--lift) * 2px)) calc(var(--sy) * (0.5px + var(--lift) * 2px)) calc(1px + var(--lift) * 3px) rgba(var(--shadow), calc(0.2 - var(--lift) * 0.08)),
    calc(var(--sx) * (3px + var(--lift) * 16px)) calc(var(--sy) * (3px + var(--lift) * 16px)) calc(8px + var(--lift) * 30px) rgba(var(--shadow), calc(0.11 + var(--lift) * 0.05)),
    calc(var(--sx) * (8px + var(--lift) * 44px)) calc(var(--sy) * (8px + var(--lift) * 44px)) calc(22px + var(--lift) * 70px) rgba(var(--shadow), calc(0.06 + var(--lift) * 0.08));
}

.card__flip {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.card__front,
.card__back {
  position: absolute;
  inset: 0;
  border-radius: 0.38em;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.7), transparent 40%),
    radial-gradient(120% 120% at 100% 100%, var(--paper-edge), transparent 55%),
    var(--paper);
  box-shadow:
    inset 0 0 0 1px rgba(var(--shadow), 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

/* the grain of the paper, on both faces */
.card__front::after,
.card__back::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--grana, none);
  background-size: 160px 160px;
  opacity: calc(var(--grana-forza, 0.07) * 2);
}

.card__back {
  transform: rotateY(180deg);
}

/* the front: a photo with a white border of paper */
.card__photo {
  position: absolute;
  inset: 4.4% 3.1% 4.4% 3.1%;
  overflow: hidden;
  border-radius: 0.14em;
  background: #c9c2b4;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.card__photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.92) contrast(1.03);
  pointer-events: none;
}

/* the print's own grain, a touch stronger than the paper's */
.card__photo::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: var(--grana, none);
  background-size: 160px 160px;
  opacity: calc(var(--grana-forza, 0.07) * 3);
}

/* the gloss of the print: a soft light that moves with the tilt */
.card__sheen {
  position: absolute;
  inset: -20%;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(38% 30% at var(--lx) var(--ly), rgba(255, 250, 240, 0.32), rgba(255, 250, 240, 0.07) 45%, transparent 70%);
  opacity: var(--sh);
}

.card__label {
  position: absolute;
  left: 6.6%;
  bottom: 9.5%;
  z-index: 3;
  color: #fffdf8;
  font-size: 0.86em;
  font-weight: 620;
  font-stretch: 118%;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

/* the back: printed words, the note in blue ink, the stamp, the postmark, the address */
.card__back {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 9% 6% 7%;
}

.card__back::before {
  /* the printed line down the middle */
  content: '';
  position: absolute;
  left: 50%;
  top: 22%;
  bottom: 12%;
  width: 1px;
  background: rgba(var(--shadow), 0.22);
}

.back__printed {
  position: absolute;
  top: 6.5%;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  color: rgba(var(--shadow), 0.55);
  font-size: 0.66em;
  font-weight: 560;
  font-stretch: 125%;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

.back__left {
  display: flex;
  align-items: center;
  padding-right: 8%;
}

.back__note {
  display: grid;
  gap: 0.12em;
  margin: 0;
  color: var(--blue);
  font-family: 'Caveat Variable', 'Caveat', cursive;
  font-size: 1.42em;
  font-weight: 520;
  line-height: 1.05;
  transform: rotate(-2.5deg);
}

.back__note span {
  display: block;
  white-space: nowrap;
  /* the pen writes every line from the left: the script opens this window */
  clip-path: inset(-20% calc(100% - var(--pen, 100%)) -20% -4%);
}

.back__sign {
  margin-top: 0.2em;
  margin-left: 40%;
  font-weight: 640;
}

.back__right {
  position: relative;
}

.stamp {
  /* the perforated edge: paper-coloured holes on the stamp's white border */
  position: absolute;
  top: 0;
  right: 0;
  width: 3.6em;
  height: 4.4em;
  padding: 0.32em;
  background:
    radial-gradient(circle, var(--paper) 1.7px, transparent 2px) -3px -3px / 6px 6px,
    #fffefb;
  filter: drop-shadow(0 1px 1px rgba(var(--shadow), 0.18));
  transform: rotate(2deg);
}

.stamp img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.8) sepia(0.12);
}

.stamp b {
  position: absolute;
  left: 0.55em;
  top: 0.45em;
  color: #fff;
  font-size: 0.62em;
  font-weight: 700;
  font-stretch: 110%;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.postmark {
  position: absolute;
  top: 0.9em;
  right: 1.4em;
  width: 8.4em;
  height: 4.2em;
  overflow: visible;
  fill: none;
  stroke: var(--blue);
  stroke-width: 1.3;
  opacity: 0.72;
  transform: rotate(-9deg);
  transform-origin: 25% 50%;
}

.postmark text {
  fill: var(--blue);
  stroke: none;
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  font-size: 7px;
  font-weight: 680;
  font-stretch: 112%;
  letter-spacing: 0.08em;
  text-anchor: middle;
}

.address {
  position: absolute;
  left: 8%;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 0.35em;
  margin: 0;
  color: var(--blue);
  font-family: 'Caveat Variable', 'Caveat', cursive;
  font-size: 1.14em;
  font-weight: 480;
  line-height: 1;
}

.address span {
  padding: 0 0 0.12em 0.2em;
  border-bottom: 1px solid rgba(var(--shadow), 0.22);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ the caption and the hint */
.foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(10px, 4.5vh, 36px);
  z-index: 0;
  display: grid;
  justify-items: center;
  gap: clamp(4px, 1vh, 8px);
  pointer-events: none;
}

.caption {
  position: relative;
  height: 1.3em;
  width: 100%;
  margin: 0;
  overflow: hidden;
  font-size: clamp(14px, 1.6vw + 0.8vh, 20px);
  font-weight: 560;
  font-stretch: 108%;
  letter-spacing: -0.015em;
  text-align: center;
}

.caption__name {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  white-space: nowrap;
}

.hint {
  display: flex;
  align-items: center;
  gap: 0.8em;
  margin: 0;
  color: var(--muted);
  font-size: clamp(10.5px, 1vw + 0.4vh, 12.5px);
  font-stretch: 106%;
}

.hint__rule {
  width: 1px;
  height: 0.9em;
  background: currentColor;
  opacity: 0.5;
}

/* ------------------------------------------------------------------ the drawn pointer of the walk on its own */
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 60;
  width: 22px;
  height: 22px;
  pointer-events: none;
  opacity: 0;
  fill: #ffffff;
  stroke: var(--ink);
  stroke-width: 1.3;
  stroke-linejoin: round;
  filter: drop-shadow(0 3px 5px rgba(var(--shadow), 0.35));
}

@media (max-width: 520px) {
  .head__note {
    display: none;
  }
}
