/* The form that folds into an envelope: a sheet of laid letter paper on a white page, written on in blue black
   ink and corrected in pencil; the lined envelope it goes into, with its air mail border, its stamp and the ink of
   the postmark. */
:root {
  --page: #ffffff;          /* the page */
  --paper: #f8f3e7;         /* the letter paper, warm white */
  --laid: #8a7550;          /* the laid and chain lines pressed into the paper */
  --print: #2b2620;         /* the printed words of the letterhead */
  --soft: #7a6d58;          /* the quieter printed words */
  --emboss: #cdbf9f;        /* the blind embossed letterhead */
  --ink: #22305e;           /* the blue black ink of the writing */
  --rule: #b8b2a6;          /* the printed lines to write on */
  --graphite: #4f4b46;      /* the pencil of the corrections */
  --navy: #1f3a7a;          /* the button, the air mail blue */
  --navy-deep: #142757;
  --cream: #fbf6ea;         /* the words on the button */
  --envelope: #efe4cc;      /* the envelope */
  --liner: #1d4a3c;         /* the lining of the envelope */
  --liner-gold: #c9a54e;    /* the pattern of the lining */
  --air-red: #c43a3a;       /* the red of the air mail border */
  --postmark: #2c2541;      /* the ink of the postmark */
  --stamp-paper: #fbf6ea;   /* the stamp */
  --stamp-dusk: #e7674a;
  --stamp-gold: #f3b64c;
  --stamp-sun: #fde7a6;
  --stamp-sea: #1d6a73;
  --stamp-red: #c23a33;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--print);
  font-family: 'Bodoni Moda Variable', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100svh;
  display: grid;
  /* la colonna non si allarga col testo scritto: il foglio resta largo quanto lo schermo */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 40px 16px;
}

.post {
  width: min(420px, 100%);
}

.desk {
  position: relative;
}

/* ---------------------------------------------------------------- the sheet */
.sheet {
  position: relative;
  z-index: 2;
  margin: 0;
}

.paper {
  position: relative;
  padding: 30px 30px 26px;
  border-radius: 3px;
  background-color: var(--paper);
  background-image:
    radial-gradient(130% 70% at 12% 0%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 60%),
    var(--grain, none),
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--laid) 7%, transparent) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--laid) 5%, transparent) 0 1px, transparent 1px 26px);
  background-size: auto, 160px 160px, auto, auto;
  box-shadow:
    inset 0 0 0 1px rgba(120, 96, 60, 0.07),
    0 1px 1px rgba(60, 45, 25, 0.1),
    0 6px 14px -4px rgba(60, 45, 25, 0.16),
    0 24px 40px -20px rgba(60, 45, 25, 0.24);
}

/* the letterhead, pressed into the paper without ink */
.head__from {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--emboss);
  font-size: 11px;
  font-weight: 700;
  font-variation-settings: 'opsz' 11;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95), 0 -1px 0 rgba(90, 70, 40, 0.28);
}

.head__mark {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--emboss);
  stroke-width: 1.6;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.95)) drop-shadow(0 -1px 0 rgba(90, 70, 40, 0.28));
}

.head__title,
.head__sub {
  display: grid;
  margin: 0;
}

.head__line {
  grid-area: 1 / 1;
}

.head__line--sent {
  visibility: hidden;
}

.head__title {
  font-size: 32px;
  font-style: italic;
  font-weight: 500;
  font-variation-settings: 'opsz' 40;
  line-height: 1.08;
  letter-spacing: -0.01em;
  color: var(--print);
  outline: none;
}

.head__sub {
  margin-top: 8px;
  color: var(--soft);
  font-size: 14px;
  font-variation-settings: 'opsz' 11;
  line-height: 1.45;
}

/* ---------------------------------------------------------------- the fields */
.field {
  position: relative;
  margin-top: 14px;
}

.field__label {
  display: block;
  color: var(--soft);
  font-size: 10.5px;
  font-weight: 600;
  font-variation-settings: 'opsz' 9;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.field__rule {
  position: relative;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.field__rule::before {
  content: '';
  position: absolute;
  inset: -2px -10px -1px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--navy) 5%, transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.field__rule--lines {
  border-bottom: 0;
}

.field.is-on .field__rule:not(.field__rule--lines) {
  border-color: var(--ink);
  box-shadow: 0 1px 0 var(--ink);
}

.field__rule:has(:focus-visible)::before {
  opacity: 1;
}

@media (hover: hover) {
  .field:not(.is-on) .field__rule:not(.field__rule--lines):hover {
    border-color: color-mix(in srgb, var(--ink) 55%, var(--rule));
  }
}

.ink {
  position: relative;
  display: block;
  width: 100%;
  height: 40px;
  margin: 0;
  padding: 4px 0 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  font-family: 'Caveat Variable', 'Bradley Hand', cursive;
  font-size: 27px;
  font-weight: 500;
  line-height: 36px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.ink::placeholder {
  color: color-mix(in srgb, var(--ink) 26%, transparent);
}

/* the letter, on three printed lines */
.ink--letter {
  height: 108px;
  padding: 0;
  resize: none;
  overflow-y: auto;
  line-height: 36px;
  background-image: repeating-linear-gradient(to bottom, transparent 0 35px, var(--rule) 35px 36px);
  background-attachment: local;
  scrollbar-width: none;
}

.ink--letter::-webkit-scrollbar {
  display: none;
}

.field--letter.is-on .ink--letter {
  background-image: repeating-linear-gradient(to bottom, transparent 0 34px, var(--ink) 34px 36px);
}

/* the pretend hand's caret, for the library's preview */
.caret {
  position: absolute;
  left: 0;
  bottom: 8px;
  width: 1.5px;
  height: 25px;
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
}

.caret.is-on {
  animation: blink 1.05s steps(1) infinite;
}

@keyframes blink {
  0%,
  55% {
    opacity: 1;
  }
  56%,
  100% {
    opacity: 0;
  }
}

/* the pencil's word under a field */
.note {
  min-height: 21px;
  margin: 7px 0 0;
  color: var(--graphite);
  font-family: 'Shantell Sans Variable', 'Comic Sans MS', cursive;
  font-size: 14px;
  font-weight: 500;
  font-variation-settings: 'INFM' 100;
  line-height: 19px;
  letter-spacing: 0.01em;
  transform: rotate(-0.8deg);
  transform-origin: 0 50%;
}

/* the pencil marks, drawn over the sheet */
.pencil {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.pencil path {
  fill: none;
  stroke: var(--graphite);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pencil .smudge {
  stroke-width: 7;
  opacity: 0.1;
}

/* ---------------------------------------------------------------- the foot: the signature and the button */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
}

.foot__sign {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  margin: 0;
  color: var(--soft);
  font-size: 15px;
  font-style: italic;
  font-variation-settings: 'opsz' 14;
}

.foot__name {
  overflow: hidden;
  color: var(--ink);
  font-family: 'Caveat Variable', 'Bradley Hand', cursive;
  font-size: 24px;
  font-style: normal;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.send {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding: 0 20px 0 24px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--cream);
  font-family: 'Bodoni Moda Variable', Georgia, serif;
  font-size: 17px;
  font-style: italic;
  font-weight: 500;
  font-variation-settings: 'opsz' 14;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  transition: font-variation-settings 0.45s cubic-bezier(0.3, 1.5, 0.5, 1), font-weight 0.3s ease;
}

.send__bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 52%),
    linear-gradient(180deg, var(--navy), var(--navy-deep));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 1px 1px rgba(20, 30, 70, 0.3),
    0 8px 16px -8px rgba(20, 30, 70, 0.55);
  transition: transform 0.55s cubic-bezier(0.3, 1.9, 0.45, 1);
}

.send__label {
  white-space: nowrap;
}

.send__icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: transform 0.5s cubic-bezier(0.3, 1.9, 0.45, 1);
}

.send__icon path:last-child {
  transform-origin: 50% 27%;
  transition: transform 0.45s cubic-bezier(0.3, 1.7, 0.45, 1);
}

@media (hover: hover) {
  .send:hover {
    font-weight: 600;
    font-variation-settings: 'opsz' 96;
  }
  .send:hover .send__bg {
    transform: scale(1.04, 1.1);
  }
  .send:hover .send__icon {
    transform: translateX(2px) rotate(-6deg);
  }
  .send:hover .send__icon path:last-child {
    transform: scaleY(-1);
  }
}

.send:active .send__bg,
.send.is-pressed .send__bg {
  transform: scale(0.96);
  transition-duration: 0.12s;
}

.send:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 4px;
}

/* ---------------------------------------------------------------- what the sheet becomes */
.ground {
  position: absolute;
  z-index: 0;
  left: 0;
  top: 0;
  border-radius: 3px;
  visibility: hidden;
  pointer-events: none;
}

.env {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: var(--env-w, 380px);
  height: var(--env-h, 190px);
  margin-left: calc(var(--env-w, 380px) / -2);
  margin-top: calc(var(--env-h, 190px) / -2);
  visibility: hidden;
  pointer-events: none;
}

.env__turn,
.env__back,
.env__front {
  position: absolute;
  inset: 0;
}

.env__turn {
  transform-style: preserve-3d;
}

.env__back,
.env__front {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.env__front {
  overflow: hidden;
  border-radius: 4px;
  transform: rotateY(180deg);
  background-color: var(--envelope);
  background-image:
    radial-gradient(120% 90% at 20% 0%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 60%),
    var(--grain, none);
  background-size: auto, 160px 160px;
  box-shadow: inset 0 0 0 1px rgba(120, 96, 60, 0.12);
}

/* the inside of the envelope, lined */
.env__wall {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 4px;
  background-color: var(--liner);
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0) 40%), var(--liner-art, none);
  background-size: auto, 22px 22px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.flap {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  width: 100%;
  height: 60%;
  transform-origin: 50% 0;
}

.flap__in,
.flap__out {
  position: absolute;
  inset: 0;
}

.flap__out {
  clip-path: polygon(0 0, 100% 0, 54% 95%, 50% 100%, 46% 95%);
  background-color: var(--envelope);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 70%),
    var(--grain, none);
  background-size: auto, 160px 160px;
}

.flap__in {
  visibility: hidden;
  clip-path: polygon(0 0, 100% 0, 54% 95%, 50% 100%, 46% 95%);
  background-color: var(--liner);
  background-image: linear-gradient(0deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.18)), var(--liner-art, none);
  background-size: auto, 22px 22px;
}

/* the sender's name, written on the closed flap */
.flap__from {
  position: absolute;
  left: 0;
  right: 0;
  top: 16%;
  display: grid;
  justify-items: center;
  color: var(--ink);
  font-family: 'Caveat Variable', 'Bradley Hand', cursive;
  line-height: 1;
  clip-path: inset(-6px 100% -6px 0);
}

.flap__who {
  font-size: 23px;
  font-weight: 600;
}

.flap__mail {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 500;
  opacity: 0.85;
}

.fold {
  position: absolute;
  z-index: 3;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.pocket {
  position: absolute;
  z-index: 4;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.env__shade {
  position: absolute;
  z-index: 5;
  inset: 0;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(50, 36, 20, 0.5), rgba(50, 36, 20, 0) 62%);
  opacity: 0;
}

/* the three thirds of the sheet, each with its front and its back */
.ply {
  position: absolute;
  left: 0;
  width: 100%;
  transform-style: preserve-3d;
}

.ply--mid {
  top: 33.3333%;
  height: 33.3333%;
}

.ply--low {
  top: 100%;
  height: 100%;
  transform-origin: 50% 0;
}

.ply--high {
  bottom: 100%;
  height: 100%;
  transform-origin: 50% 100%;
}

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

.face--back {
  transform: rotateX(180deg);
  background-color: var(--paper);
  background-image:
    var(--grain, none),
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--laid) 7%, transparent) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--laid) 5%, transparent) 0 1px, transparent 1px 26px);
  background-size: 160px 160px, auto, auto;
}

.face--back.is-edge-top {
  border-radius: 3px 3px 0 0;
}

.face--back.is-edge-bottom {
  border-radius: 0 0 3px 3px;
}

.face__copy {
  position: absolute;
  left: 0;
}

.face__copy .paper {
  box-shadow: none;
}

/* the writing seen through the back of the paper, faintly and mirrored */
.face__through {
  position: absolute;
  inset: 0;
  transform: scaleY(-1);
  opacity: 0.05;
  filter: blur(0.5px);
}

.face__through .paper {
  background: none;
  box-shadow: none;
}

.face__light,
.face__ao,
.face__crease {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.face__light {
  top: 0;
  bottom: 0;
}

.face__ao {
  height: 60%;
  opacity: 0;
}

.face__ao--bottom {
  bottom: 0;
  background: linear-gradient(0deg, rgba(50, 36, 20, 0.55), rgba(50, 36, 20, 0));
}

.face__ao--top {
  top: 0;
  background: linear-gradient(180deg, rgba(50, 36, 20, 0.55), rgba(50, 36, 20, 0));
}

/* a fold's edge: rounded, it catches the light along its top and darkens under */
.face__crease {
  height: 7px;
  opacity: 0;
}

.face__crease--top {
  top: 0;
  background: linear-gradient(180deg, rgba(110, 86, 50, 0.28), rgba(255, 255, 255, 0.85) 1.5px, rgba(255, 255, 255, 0) 7px);
}

.face__crease--bottom {
  bottom: 0;
  background: linear-gradient(0deg, rgba(110, 86, 50, 0.3), rgba(255, 255, 255, 0.5) 1.5px, rgba(255, 255, 255, 0) 7px);
}

/* the bone folder pressing a crease: a gloss that runs along it */
.face__gloss {
  position: absolute;
  top: -6px;
  left: 0;
  width: 90px;
  height: 14px;
  background: radial-gradient(50% 50% at 50% 50%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0));
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the front of the envelope */
.env__border {
  position: absolute;
  inset: 0;
  padding: 7px;
  border-radius: 4px;
  background: repeating-linear-gradient(-45deg, var(--air-red) 0 9px, transparent 9px 13px, var(--navy) 13px 22px, transparent 22px 26px);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0.92;
}

.airmail {
  position: absolute;
  left: 22px;
  top: 21px;
  padding: 3px 8px 2px;
  border: 1px solid var(--navy);
  color: var(--navy);
  font-size: 9.5px;
  font-weight: 700;
  font-variation-settings: 'opsz' 9;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.env__to {
  position: absolute;
  left: 40%;
  top: 47%;
  display: grid;
  gap: 1px;
  color: var(--print);
  font-size: 12.5px;
  font-variation-settings: 'opsz' 12;
  line-height: 1.3;
}

.env__to-desk {
  font-size: 16px;
  font-style: italic;
  font-weight: 500;
  font-variation-settings: 'opsz' 24;
}

.stamp {
  position: absolute;
  right: 19px;
  top: 16px;
  width: 52px;
  height: 62px;
  opacity: 0;
  filter: drop-shadow(0 1px 1px rgba(60, 40, 20, 0.28));
}

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

.st-paper {
  fill: var(--stamp-paper);
}

.st-sun {
  fill: var(--stamp-sun);
}

.st-sea {
  fill: var(--stamp-sea);
}

.st-wave {
  fill: none;
  stroke: var(--stamp-paper);
  stroke-width: 0.9;
  stroke-linecap: round;
  opacity: 0.55;
}

.st-tower {
  fill: var(--stamp-paper);
}

.st-band {
  fill: var(--stamp-red);
}

.st-dark {
  fill: var(--print);
}

.st-beam {
  fill: var(--stamp-sun);
  opacity: 0.55;
}

.st-text {
  fill: var(--stamp-paper);
  font-family: 'Bodoni Moda Variable', Georgia, serif;
  font-weight: 700;
}

.st-caption {
  fill: var(--navy);
  font-family: 'Bodoni Moda Variable', Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.cancel {
  position: absolute;
  right: 4px;
  top: 12px;
  width: 172px;
  height: 72px;
  overflow: visible;
}

.cancel .ink-line {
  fill: none;
  stroke: var(--postmark);
  stroke-width: 1.7;
  stroke-linecap: round;
}

.cancel .ink-type {
  fill: var(--postmark);
  font-family: 'Bodoni Moda Variable', Georgia, serif;
  font-weight: 700;
  font-variation-settings: 'opsz' 9;
}

/* in cima alla pagina: in fondo al modulo, col suo margine, la allungherebbe */
.sr {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the phone */
@media (max-width: 460px) {
  /* meno vuoto sopra e sotto: il foglio intero sta nella casella dell'anteprima (rimpicciolita dal visore) */
  .stage {
    padding: 20px 16px;
  }
  .paper {
    padding: 26px 22px 22px;
  }
  .head__title {
    font-size: 28px;
  }
  .head__sub {
    font-size: 13.5px;
  }
  .send {
    padding: 0 16px 0 20px;
    font-size: 16px;
  }
  .env__to {
    left: 36%;
  }
}

/* telefono stretto: il pulsante un poco più piccolo lascia posto alla firma */
@media (max-width: 380px) {
  .foot {
    gap: 10px;
  }
  .send {
    gap: 8px;
    padding: 0 14px 0 16px;
    font-size: 15px;
  }
  .send__icon {
    width: 18px;
    height: 18px;
  }
}
