/* Liam Salerno — page shell and postcard */

:root {
  --page: #ece2cd;
  --paper: #faf4e7;
  --paper-edge: #f0e5cf;
  --ink: #1b2436;
  --ink-soft: #3a4357;
  --link: #1d4c94;
  --link-line: rgba(29, 76, 148, .45);
  --rule: rgba(27, 36, 54, .28);
  --maple: #b4441c;
  --chip: #f6eedd;
  --shadow:
    0 1px 1px rgba(40, 28, 10, .10),
    0 3px 6px rgba(40, 28, 10, .10),
    0 14px 28px -6px rgba(40, 28, 10, .22),
    0 40px 70px -20px rgba(30, 20, 5, .35);
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .16 0 0 0 .38 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --noise-card: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .16 0 0 0 .2 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fibres: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .05' numOctaves='2' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .36 0 0 0 0 .22 0 0 0 .22 -.04'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --ease-settle: cubic-bezier(.2, .8, .25, 1);
  color-scheme: light;
}

.night {
  --page: #111a2a;
  --paper: #222e42;
  --paper-edge: #1b2637;
  --ink: #f0e7d3;
  --ink-soft: #cfc6b3;
  --link: #a9cdf7;
  --link-line: rgba(169, 205, 247, .5);
  --rule: rgba(240, 231, 211, .26);
  --maple: #e4865a;
  --chip: #26324a;
  --shadow:
    0 1px 1px rgba(0, 0, 0, .3),
    0 3px 6px rgba(0, 0, 0, .25),
    0 14px 28px -6px rgba(0, 0, 0, .45),
    0 40px 70px -20px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--page);
  transition: background-color 1.2s ease;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-optical-sizing: auto;
  color: var(--ink);
  background: var(--page);
  transition: background-color 1.2s ease, color 1.2s ease;
}

/* ---------- painting layers ---------- */

#scene, #sprites, .grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100lvh;
  display: block;
}
#scene { z-index: 0; cursor: pointer; }
#sprites { z-index: 1; pointer-events: none; }
.grain {
  z-index: 2;
  pointer-events: none;
  background-image: var(--noise);
  background-size: 220px;
  opacity: .3;
  mix-blend-mode: multiply;
}
.night .grain { opacity: .3; mix-blend-mode: soft-light; }

/* ---------- layout ---------- */

main {
  position: relative;
  z-index: 3;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 56px 24px 84px;
  pointer-events: none;
}

/* ---------- the postcard ---------- */

.card {
  --tilt: -1.5deg;
  position: relative;
  width: min(880px, 100%);
  padding: 46px 56px 50px;
  pointer-events: auto;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(120% 90% at 50% 40%, transparent 55%, var(--paper-edge) 100%),
    var(--fibres),
    var(--noise-card);
  background-size: 100% 100%, 600px, 220px;
  border-radius: 3px;
  box-shadow: var(--shadow);
  transform: rotate(var(--tilt));
  transition:
    transform .8s var(--ease-settle),
    opacity .55s ease,
    visibility 0s linear 0s,
    background-color 1.2s ease,
    color 1.2s ease,
    box-shadow 1.2s ease;
  outline: none;
}
.night .card {
  background-image:
    radial-gradient(120% 90% at 50% 40%, transparent 55%, var(--paper-edge) 100%),
    var(--noise-card);
  background-size: 100% 100%, 220px;
  background-blend-mode: normal, soft-light;
}

.js:not(.still) .card { animation: settle 1.05s var(--ease-settle) .1s backwards; }

@keyframes settle {
  from { opacity: 0; transform: translate(4vw, 9vh) rotate(5deg) scale(.96); }
  60% { opacity: 1; }
  to { transform: rotate(var(--tilt)); }
}

/* put away */
.card-away .card {
  opacity: 0;
  visibility: hidden;
  transform: translate(-46vw, 46vh) rotate(-16deg) scale(.12);
  transition:
    transform .75s cubic-bezier(.55, 0, .7, .4),
    opacity .45s ease .3s,
    visibility 0s linear .75s,
    background-color 1.2s ease,
    color 1.2s ease;
}
.still .card, .still.card-away .card { transition: background-color 1.2s ease, color 1.2s ease, box-shadow 1.2s ease; }

/* ---------- header ---------- */

.card-head {
  padding-right: 200px;
  min-height: 132px;
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 2rem + 2.6vw, 3.85rem);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -.012em;
}

.tagline {
  margin: .4em 0 0;
  font-style: italic;
  font-size: clamp(1.2rem, 1.05rem + .5vw, 1.45rem);
  line-height: 1.3;
  color: var(--ink-soft);
  text-wrap: balance;
  transition: color 1.2s ease;
}

/* ---------- stamp ---------- */

.stamp {
  position: absolute;
  top: 30px;
  right: 40px;
  width: 124px;
  transform: rotate(3.2deg);
  filter: drop-shadow(0 1px 1px rgba(40, 28, 10, .25)) drop-shadow(0 3px 5px rgba(40, 28, 10, .14));
}
.night .stamp { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .5)) drop-shadow(0 3px 5px rgba(0, 0, 0, .35)); }

.stamp-paper {
  --r: 4px;
  --s: 11.6px;
  padding: 9px;
  background: #fbf7ec;
  -webkit-mask:
    radial-gradient(circle, transparent var(--r), #000 calc(var(--r) + .5px)) calc(var(--s) / -2) calc(var(--s) / -2) / var(--s) var(--s) round,
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--r)) calc(100% - 2 * var(--r)) no-repeat;
  mask:
    radial-gradient(circle, transparent var(--r), #000 calc(var(--r) + .5px)) calc(var(--s) / -2) calc(var(--s) / -2) / var(--s) var(--s) round,
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--r)) calc(100% - 2 * var(--r)) no-repeat;
}

.stamp-face {
  aspect-ratio: 5 / 6;
  overflow: hidden;
  border: 1.5px solid #b4441c;
  background: #d9cdb4;
}
.stamp-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 28%;
  filter: sepia(.3) saturate(.85) contrast(1.03);
}
.stamp-caption {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 1px 0;
  color: #b4441c;
  line-height: 1;
  font-size: .64rem;
  font-style: italic;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.stamp-value { font-size: 1.05rem; font-style: normal; font-weight: 600; letter-spacing: 0; }
.stamp-value::after { content: "¢"; font-size: .62em; vertical-align: .45em; margin-left: 1px; }

.postmark {
  position: absolute;
  left: -146px;
  top: 74px;
  width: 200px;
  height: auto;
  overflow: visible;
  transform: rotate(-6deg);
  fill: none;
  stroke: var(--maple);
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: .72;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.night .postmark { mix-blend-mode: normal; opacity: .55; }
.postmark text {
  fill: var(--maple);
  stroke: none;
  font: 600 8.3px/1 "Newsreader", Georgia, serif;
  letter-spacing: .9px;
}
.postmark .pm-wave { stroke-width: 1.7; }
.postmark .pm-cross { stroke-width: 1.4; }

/* ---------- body: message | address ---------- */

.card-body {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 1fr);
  margin-top: 22px;
}

.message {
  padding-right: 40px;
  font-size: 1.22rem;
  line-height: 1.55;
}
.message p { margin: 0; text-wrap: pretty; hyphens: manual; }
.message p + p { margin-top: .85em; }

.address {
  list-style: none;
  margin: 0;
  padding: 0 0 0 40px;
  border-left: 1px solid var(--rule);
  font-size: 1.16rem;
  line-height: 1.35;
  transition: border-color 1.2s ease;
}
.address li {
  padding: .78em 2px .16em;
  border-bottom: 1px solid var(--rule);
  transition: border-color 1.2s ease;
}
.address li:first-child { padding-top: .2em; }

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1px;
  text-underline-offset: .18em;
  transition: color 1.2s ease, text-decoration-color .25s ease;
}
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------- close (put away) ---------- */

.card-close {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  opacity: .55;
  cursor: pointer;
  transition: opacity .2s ease, background-color .2s ease, color 1.2s ease;
}
.card-close:hover, .card-close:focus-visible { opacity: 1; background: var(--rule); }
.card-close svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ---------- writing-in ---------- */

/* Before postcard.js wraps the words, keep them hidden; reveal anyway if it never runs. */
.js:not(.still) .card:not(.writing):not(.written) [data-write] {
  opacity: 0;
  animation: failsafe 0s linear 3.5s forwards;
}
@keyframes failsafe { to { opacity: 1; } }

.card.writing .w {
  position: relative;
  opacity: 0;
  animation: ink .6s cubic-bezier(.25, .7, .3, 1) forwards;
}
@keyframes ink {
  from { opacity: 0; top: .28em; filter: blur(1.5px); }
  to { opacity: 1; top: 0; filter: blur(0); }
}

/* ---------- picture controls ---------- */

.controls {
  position: fixed;
  z-index: 4;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.controls button {
  min-height: 32px;
  padding: 4px 11px 5px;
  border: 0;
  border-radius: 2px;
  font: italic 400 .98rem/1.2 "Newsreader", Georgia, serif;
  color: var(--ink);
  background: var(--chip) var(--noise);
  background-size: auto, 220px;
  box-shadow: 0 1px 1px rgba(40, 28, 10, .18), 0 3px 8px -2px rgba(40, 28, 10, .28);
  cursor: pointer;
  transform: rotate(-1.4deg);
  transition: transform .2s ease, background-color 1.2s ease, color 1.2s ease;
}
.controls button:nth-child(even) { transform: rotate(1.1deg); }
.controls button:nth-child(3n) { transform: rotate(-.4deg) translateY(1px); }
.controls button:hover { transform: rotate(0) translateY(-1px); }
.night .controls button, .night .chip { background-image: none; }
.night .controls button { box-shadow: 0 1px 1px rgba(0, 0, 0, .4), 0 3px 8px -2px rgba(0, 0, 0, .5); }

/* ---------- mini-card chip ---------- */

.chip {
  position: fixed;
  z-index: 4;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 13px 5px 5px;
  border: 0;
  border-radius: 2px;
  font: 500 1.02rem/1 "Newsreader", Georgia, serif;
  color: var(--ink);
  background: var(--paper) var(--noise);
  background-size: auto, 220px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transform: rotate(-2.5deg);
  animation: chip-in .55s var(--ease-settle) .35s backwards;
  transition: transform .2s ease;
}
.chip:hover { transform: rotate(-1deg) translateY(-2px); }
.chip img {
  width: 34px;
  height: 40px;
  object-fit: cover;
  object-position: 50% 30%;
  border: 1.5px solid var(--maple);
  filter: sepia(.25);
}
@keyframes chip-in {
  from { opacity: 0; transform: translateY(24px) rotate(-8deg); }
}

/* ---------- motion off ---------- */

.still .chip { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .card, .chip, .controls button { animation: none !important; transition-duration: .01s !important; }
}

/* ---------- tablet ---------- */

@media (max-width: 860px) {
  .card { padding: 42px 40px 44px; }
  .card-head { padding-right: 168px; }
  .stamp { right: 30px; width: 112px; }
  .stamp-caption { letter-spacing: .08em; }
  .message { padding-right: 28px; font-size: 1.16rem; }
  .address { padding-left: 28px; font-size: 1.12rem; }
}

/* ---------- phone ---------- */

@media (max-width: 640px) {
  main {
    display: block;
    min-height: 0;
    padding: max(18px, env(safe-area-inset-top)) 14px 18px;
  }
  .card {
    --tilt: -.6deg;
    width: 100%;
    padding: 40px 22px 30px;
  }
  .card-head { padding-right: 92px; min-height: 0; }
  h1 { font-size: 2.35rem; }
  .tagline { font-size: 1.14rem; }

  .stamp { top: 22px; right: 16px; width: 76px; }
  .stamp-paper { --r: 3px; --s: 8.4px; padding: 6px; }
  .stamp-caption { justify-content: flex-end; padding-top: 3px; }
  .stamp-caption span:first-child { display: none; }
  .stamp-value { font-size: .78rem; }
  .postmark { width: 150px; left: -118px; top: 58px; }
  .postmark .pm-wave { display: none; }

  .card-body { display: block; margin-top: 26px; }
  .message { padding: 0; font-size: 1.13rem; }
  .address {
    margin-top: 22px;
    padding: 6px 0 0;
    border-left: 0;
    border-top: 1px solid var(--rule);
    font-size: 1.1rem;
  }
  .address li:first-child { padding-top: .78em; }

  .card-close { top: 4px; left: 4px; }

  /* Controls sit beneath the card instead of floating over its text. */
  .controls {
    position: relative;
    z-index: 3;
    right: auto;
    bottom: auto;
    padding: 4px 14px max(20px, env(safe-area-inset-bottom));
    justify-content: center;
  }
  .controls button { min-height: 40px; padding: 8px 13px 9px; }
  .card-away .controls { position: fixed; right: 0; left: 0; bottom: 0; justify-content: flex-end; }
  .card-away main { height: 100dvh; overflow: hidden; }
  .chip { bottom: max(70px, env(safe-area-inset-bottom)); }
}
