/* Tờ tem cưới — the souvenir sheet, its perforations, the cover and the reader.
   Two inks on white gummed paper: cobalt and candy pink. The ground under the
   sheet is the cobalt ink, so every perforation hole shows it. One grotesk,
   Bricolage Grotesque, condensed for the printed caps. */

@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-vietnamese.woff2") format("woff2");
  unicode-range:
    U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
    U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329,
    U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-latin-ext.woff2") format("woff2");
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-latin.woff2") format("woff2");
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* The perforation pitch: every stamp is a whole number of pitches on a side,
   so the holes of neighbouring stamps always land on one another. */
@property --p {
  syntax: "<length>";
  inherits: true;
  initial-value: 12px;
}

:root {
  --blue: #1a2fb8;
  --pink: #ff8cc0;
  --paper: #fbfaf7;
  --face: "Bricolage Grotesque", "Arial Narrow", sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: drop-shadow(0 14px 18px rgb(6 14 70 / 0.42));

  color-scheme: light;
  accent-color: var(--blue);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--pink) var(--blue);
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--blue);
  color: var(--blue);
  font-family: var(--face);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.45;
  caret-color: var(--blue);
  overflow-x: clip;
}

body.locked,
html:has(.reader:not([hidden])) {
  overflow: hidden;
}

::selection {
  background: var(--pink);
  color: var(--blue);
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.cover :focus-visible,
.reader :focus-visible {
  outline-color: var(--paper);
}

h1,
h2,
p,
ol,
figure {
  margin: 0;
  padding: 0;
}

ol {
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
}

.defs {
  position: absolute;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

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

[hidden] {
  display: none !important;
}

.dot {
  display: inline-block;
  width: 0.32em;
  height: 0.32em;
  margin-inline: 0.3em;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 0.2em;
}

/* ---------- the sheet ---------- */

.page {
  container-type: inline-size;
}

.sheet {
  /* phone: 28 pitches across, 56 down */
  --cols: 28;
  --rows: 56;
  --edge: 8px;
  --side: 12px;
  --top: 42px;
  --bottom: 64px;
  --p: max(
    9px,
    round(
      down,
      min(
        (100cqw - 2 * var(--edge) - 2 * var(--side)) /
        var(--cols),
        (100svh - 2 * var(--edge) - var(--top) - var(--bottom)) /
        var(--rows)
      ),
      1px
    )
  );
  --tall: calc(var(--rows) * var(--p) + var(--top) + var(--bottom));
  --stack: 28px;

  position: relative;
  width: calc(var(--cols) * var(--p) + 2 * var(--side));
  margin: 0 auto var(--stack);
  padding: 0 var(--side);
  background: var(--paper);
  filter: var(--shadow);
}

@media (min-width: 900px) and (orientation: landscape) {
  .sheet {
    /* desktop: 68 pitches across, 46 down */
    --cols: 68;
    --rows: 46;
    --edge: 24px;
    --side: 40px;
    --top: 52px;
    --bottom: 64px;
    --stack: 48px;
  }
}

/* the first sheet fills the first screen */
.sheet--hero {
  margin-top: max(var(--edge), (100svh - var(--tall)) / 2);
  margin-bottom: max(var(--stack), (100svh - var(--tall)) / 2);
}

.sheet--flow .block {
  grid-template-rows: none;
}

.selvage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selvage--top {
  height: var(--top);
}

.selvage--bottom {
  height: var(--bottom);
}

.issue {
  font-size: 0.75rem;
  font-weight: 700;
  font-stretch: 75%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
  text-wrap: balance;
}

.music-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-inline-end: -10px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--blue);
  cursor: pointer;
}

.music-btn[aria-pressed="true"] {
  background: var(--pink);
}

.plate {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  font-stretch: 75%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
}

.marks {
  display: flex;
  align-items: center;
  gap: 5px;
}

.register {
  width: 18px;
  height: 18px;
  color: var(--blue);
}

.ink {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.ink--blue {
  background: var(--blue);
}

.ink--pink {
  background: var(--pink);
}

.plate-text {
  display: grid;
}

.plate-number {
  font-variant-numeric: tabular-nums;
}

/* ---------- the postmark: the reply cancels the sheet ---------- */

.postmark {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin-inline-end: -6px;
  padding: 2px 6px;
  color: var(--blue);
  text-decoration: none;
  touch-action: manipulation;
}

.postmark-mark {
  width: 84px;
  height: 45px;
  flex: none;
  transition: transform 0.4s var(--ease-out);
}

.postmark:hover .postmark-mark {
  transform: rotate(-8deg);
}

.postmark-waves,
.postmark-ring {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
}

.postmark-ring--in {
  stroke-width: 1.4;
}

.postmark-day,
.postmark-year {
  fill: currentColor;
  font-family: var(--face);
  font-weight: 800;
  font-stretch: 75%;
  font-variant-numeric: tabular-nums;
}

.postmark-day {
  font-size: 14px;
}

.postmark-year {
  font-size: 10px;
  letter-spacing: 0.06em;
}

.postmark-label {
  max-width: 7.5em;
  font-size: 1rem;
  font-weight: 800;
  font-stretch: 75%;
  line-height: 1.02;
  text-transform: uppercase;
  text-wrap: balance;
}

/* ---------- the stamp block and its perforations ---------- */

.block {
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--p));
  grid-template-rows: repeat(var(--rows), var(--p));
}

.countdown,
.row {
  display: contents;
}

.cell {
  position: relative;
}

/* Every cell punches its own four edges; shared edges land hole on hole. */
.cell::after {
  content: "";
  position: absolute;
  inset: calc(var(--p) / -2);
  z-index: 2;
  pointer-events: none;
  background:
    url("../img/perf-hole.svg") 0 0 / var(--p) var(--p) round no-repeat,
    url("../img/perf-hole.svg") 0 100% / var(--p) var(--p) round no-repeat,
    url("../img/perf-hole.svg") 0 0 / var(--p) var(--p) no-repeat round,
    url("../img/perf-hole.svg") 100% 0 / var(--p) var(--p) no-repeat round;
}

.lift {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.cell.is-lifting,
.cell.is-torn,
.cell.is-peeled {
  background: var(--blue);
}

/* the cue: one corner of the couple stamp already off its gum */
.cell.is-peeled .lift {
  z-index: 5;
  filter: var(--shadow);
  transform: rotate(-2.4deg);
  transform-origin: 0 0;
}

.cell.is-lifting .lift {
  z-index: 5;
  transition: none;
  filter: var(--shadow);
}

.cell.is-torn .lift {
  visibility: hidden;
}

.tear {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.tear:focus-visible {
  outline-offset: calc(var(--p) * -0.5 + 3px);
}

.cell.is-lifting .tear {
  z-index: 6;
  cursor: grabbing;
}

@media (hover: hover) {
  .cell[data-tear]:not(.is-torn) .lift {
    transition: transform 0.35s var(--ease-out);
  }

  .cell[data-tear]:hover:not(.is-lifting) .lift {
    transform: translateY(-2px) rotate(-0.6deg);
  }
}

/* A loose stamp: the same pitch tile bites a half hole at every pitch. */
.loose,
.cell.is-lifting .stamp,
.cell.is-peeled .stamp,
.reader-lift .stamp {
  mask:
    url("../img/perf-edge.svg") 0 0 / var(--p) var(--p) round,
    linear-gradient(#000 0 0) center / calc(100% - var(--p))
    calc(100% - var(--p)) no-repeat;
}

/* ---------- the cover: one loose stamp and its tear-off tab ---------- */

.cover {
  --p: max(
    10px,
    round(down, min((100vw - 40px) / 26, (100svh - 56px) / 37, 22px), 1px)
  );

  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: var(--blue);
}

body:not(.locked) .cover {
  display: none;
}

/* reduced motion skips the cover from the very first paint, before any script */
@media (prefers-reduced-motion: reduce) {
  .cover {
    display: none;
  }

  body.locked {
    overflow-x: clip;
    overflow-y: visible;
  }
}

.cover-pair {
  display: grid;
  width: calc(26 * var(--p));
  filter: var(--shadow);
}

.cover-card {
  height: calc(30 * var(--p));
  padding: calc(var(--p) * 0.75);
  background: var(--paper);
  container-type: inline-size;
}

.cover-print {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 7cqi 7cqi 6cqi;
  background: var(--blue);
  color: var(--paper);
}

.cover-title {
  font-size: 13cqi;
  font-weight: 800;
  font-stretch: 75%;
  line-height: 0.98;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  text-wrap: balance;
}

.cover-guest {
  margin-top: 4cqi;
  color: var(--pink);
  font-size: max(12px, 4.6cqi);
  font-weight: 700;
  line-height: 1.2;
}

.cover-guest b {
  display: block;
  color: var(--paper);
  font-size: 7.5cqi;
  font-weight: 800;
  font-stretch: 75%;
  text-transform: uppercase;
}

.cover-value {
  margin-top: auto;
  color: var(--pink);
  font-size: 36cqi;
  font-weight: 800;
  font-stretch: 75%;
  line-height: 0.84;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.cover-names {
  margin-top: 4cqi;
  padding-top: 3.4cqi;
  border-top: max(2px, 0.6cqi) solid var(--pink);
  font-size: 7cqi;
  font-weight: 800;
  font-stretch: 85%;
  line-height: 1.1;
}

.cover-date {
  margin-top: 1cqi;
  color: var(--pink);
  font-size: max(12px, 4.6cqi);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cover-tab {
  display: block;
  height: calc(6 * var(--p));
  padding: calc(var(--p) * 0.75);
  border: 0;
  background: var(--paper);
  cursor: pointer;
  text-align: start;
  touch-action: manipulation;
  transform-origin: 0 0;
}

.cover-tab-print {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 100%;
  padding-inline: 16px 14px;
  background: var(--pink);
  color: var(--blue);
  font-size: max(1rem, var(--p) * 1.05);
  font-weight: 800;
  font-stretch: 85%;
  line-height: 1.15;
}

.cover-tab-print .icon {
  width: 24px;
  height: 24px;
  transition: transform 0.4s var(--ease-out);
}

.cover-tab:hover .icon {
  transform: translateY(3px);
}

.cover.is-opening .cover-tab {
  animation: tab-off 0.6s cubic-bezier(0.5, 0, 0.75, 0) forwards;
}

.cover.is-opening .cover-card {
  animation: card-off 0.75s 0.32s cubic-bezier(0.7, 0, 0.84, 0) forwards;
}

.cover.is-opening {
  animation: ground-off 0.45s 0.85s ease-out forwards;
}

@keyframes tab-off {
  30% {
    transform: rotate(5deg) translateY(4px);
  }
  100% {
    transform: rotate(22deg) translateY(70vh);
  }
}

@keyframes card-off {
  100% {
    transform: translateY(-110vh) rotate(-5deg);
  }
}

@keyframes ground-off {
  100% {
    background-color: rgb(26 47 184 / 0);
  }
}

/* ---------- the reader: a torn stamp, large ---------- */

.reader {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(26 47 184 / 0.94);
}

.reader-lift {
  position: fixed;
  filter: var(--shadow);
  transform-origin: 50% 50%;
}

.reader-lift .stamp {
  position: absolute;
  inset: 0;
}

.reader-back {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 2px solid var(--paper);
  border-radius: 999px;
  background: var(--blue);
  color: var(--paper);
  font-weight: 800;
  font-stretch: 85%;
  cursor: pointer;
  transform: translateX(-50%);
}

.reader-back:hover {
  background: var(--paper);
  color: var(--blue);
}

/* ---------- shells for the next printing ---------- */

.shell:empty {
  height: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  .issue,
  .plate {
    font-size: 0.8125rem;
  }

  .postmark-mark {
    width: 112px;
    height: 60px;
  }

  .postmark-label {
    font-size: 1.25rem;
  }
}

/* the narrowest phones keep the registration marks and the postmark only */
@media (max-width: 359px) {
  .plate-text {
    display: none;
  }
}
