/* Lịch bloc xé — the pad, its binding, the stubs of torn pages and the cover.
   Three inks: newsprint paper, calendar red, black. No texture beyond the
   paper's own torn edge. Anton prints the numerals, Archivo everything else. */

@font-face {
  font-family: Anton;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/anton-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: Anton;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/anton-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: Anton;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/anton-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;
}
@font-face {
  font-family: Archivo;
  font-style: normal;
  font-weight: 400 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("../fonts/archivo-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: Archivo;
  font-style: normal;
  font-weight: 400 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("../fonts/archivo-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: Archivo;
  font-style: normal;
  font-weight: 400 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("../fonts/archivo-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;
}

:root {
  --wall: #151311;
  --paper: #f3efe6;
  --red: #cc2419;
  --ink: #151311;
  --display: Anton, "Archivo", sans-serif;
  --text: Archivo, "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* phone: the pad fills the screen, a sliver of wall around it */
  --side: 8px;
  --wall-h: 8px;
  --bind-h: 50px;
  --stub-h: 14px;
  --foot-h: 12px;
  --pad-w: calc(100% - 2 * var(--side));
  --top: calc(var(--wall-h) + var(--bind-h));
  --page-h: calc(100svh - var(--top) - var(--foot-h));

  color-scheme: light;
  accent-color: var(--red);
  scroll-snap-type: y mandatory;
  scroll-padding-top: var(--top);
  scroll-padding-bottom: var(--foot-h);
  scrollbar-color: var(--red) var(--wall);
  scrollbar-width: thin;
  overflow-x: clip;
}

@media (min-width: 900px) and (min-height: 600px) {
  :root {
    /* room above the pad for the cord and the nail it hangs from */
    --wall-h: 40px;
    --bind-h: 62px;
    --stub-h: 16px;
    --foot-h: 34px;
    --pad-w: min(1120px, 100% - 128px);
  }
}

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

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  overflow-x: clip;
  padding-top: var(--top);
  padding-bottom: var(--foot-h);
  background: var(--wall);
  color: var(--ink);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

html:has(body.locked) {
  overflow: hidden;
}

::selection {
  background: var(--red);
  color: var(--paper);
}

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

input,
textarea {
  caret-color: var(--red);
}

.defs {
  position: absolute;
}

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

[hidden] {
  display: none !important;
}

/* ---------- wall and binding (fixed: the pad hangs, pages move) ---------- */
.wall-top {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  height: var(--wall-h);
  background: var(--wall);
}

.hanger {
  display: none;
}

.binding {
  position: fixed;
  top: var(--wall-h);
  left: 50%;
  z-index: 30;
  display: flex;
  align-items: center;
  width: var(--pad-w);
  height: var(--bind-h);
  padding: 0 6px 0 16px;
  background: var(--red);
  color: var(--paper);
  translate: -50% 0;
}

.binding-date {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(17px, 5.6vw, 22px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.binding-dot {
  margin: 0 0.2em;
}

.music-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--paper);
  cursor: pointer;
}

.music-btn svg {
  width: 22px;
  height: 22px;
}

.music-btn[aria-pressed="false"] {
  opacity: 0.72;
}

.music-btn:focus-visible {
  outline-color: var(--paper);
  outline-offset: -4px;
}

/* torn stubs pile up under the binding, each with its own ragged edge */
.stubs {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: var(--stub-h);
  pointer-events: none;
}

.stub {
  position: absolute;
  inset: 0;
  background: var(--paper);
  mask:
    url("../img/tear-stub-edge.svg") var(--jag-x, 0) 0 / 480px 100% repeat-x;
  translate: 0 var(--drop, 0);
  visibility: hidden;
}

.stub::after {
  /* the perforation line the page tore along */
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
}

.stub--cover {
  background: var(--red);
}

.stub--cover::after {
  display: none;
}

.stub.is-on {
  visibility: visible;
}

/* ---------- the pad: sheets stacked by scrolling ----------
   Each later sheet sticks under the binding while the sheet above it is
   torn away, so a page is always waiting beneath the one being torn. */
.pad {
  width: var(--pad-w);
  margin: 0 auto;
  outline: none;
}

.slot {
  position: relative;
  height: var(--page-h);
}

.slot + .slot {
  height: calc(2 * var(--page-h));
  margin-top: calc(-1 * var(--page-h));
}

.page-anchor {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: var(--page-h);
  pointer-events: none;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.slot + .slot .page-anchor {
  top: var(--page-h);
}

/* The script measures each page and sets the slot, anchor and sheet heights
   so a page taller than the screen is read first, then torn. These defaults
   are the one-screen case. */
.sheet {
  position: sticky;
  top: var(--top);
  z-index: var(--z, 10);
  height: var(--page-h);
}

.page {
  position: relative;
  min-height: var(--page-h);
}

.page-probe {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: var(--page-h);
  visibility: hidden;
  pointer-events: none;
}

.sheet.is-tearing {
  z-index: 40;
  filter: drop-shadow(0 18px 24px rgb(0 0 0 / 0.4));
}

.sheet.is-gone {
  z-index: 25;
}

.leaf {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  transform-origin: 0 var(--cut, 0);
  will-change: transform;
}

/* a torn page keeps only what was below the binding, with a ragged top */
.is-tearing > .leaf,
.is-gone > .leaf {
  mask:
    url("../img/tear-leaf-edge.svg") var(--jag-x, 0) var(--cut, 0) / 480px
    var(--stub-h) repeat-x,
    linear-gradient(#000 0 0) 0 calc(var(--cut, 0px) + var(--stub-h)) / 100%
    100% no-repeat;
}

.perf {
  position: absolute;
  top: calc(var(--stub-h) - 3px);
  left: 0;
  width: 100%;
  height: 4px;
  background: url("../img/perforation.svg") 0 0 / 9px 4px repeat-x;
  opacity: 0.55;
}

.is-tearing .perf,
.is-gone .perf {
  visibility: hidden;
}

.pad-foot {
  position: fixed;
  top: calc(var(--top) + var(--page-h));
  bottom: 0;
  left: 50%;
  z-index: 35;
  width: var(--pad-w);
  background: var(--wall);
  translate: -50% 0;
}

.pad-foot span {
  display: block;
  height: 3px;
  margin: 0 auto;
  background: var(--paper);
}

.pad-foot span + span {
  margin-top: 1px;
}

.pad-foot span:nth-child(2) {
  width: calc(100% - 4px);
}

.pad-foot span:nth-child(3) {
  width: calc(100% - 8px);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: 0;
  font: 800 15px / 1.15 var(--text);
  font-stretch: 88%;
  letter-spacing: 0.04em;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background-color 160ms ease,
    color 160ms ease,
    translate 160ms var(--ease-out);
}

.btn svg {
  flex: none;
  width: 20px;
  height: 20px;
}

.btn:active {
  translate: 0 2px;
}

/* ---------- the cover: a red sheet over the first page ---------- */
.cover {
  position: fixed;
  top: var(--top);
  left: 50%;
  z-index: 50;
  width: var(--pad-w);
  height: var(--page-h);
  translate: -50% 0;
}

.cover.is-torn {
  filter: drop-shadow(0 18px 24px rgb(0 0 0 / 0.45));
}

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

.cover-leaf {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: var(--red);
  color: var(--paper);
  transform-origin: 0 0;
  touch-action: none;
  cursor: grab;
}

.cover-leaf.is-torn {
  mask:
    url("../img/tear-leaf-edge.svg") 0 0 / 480px var(--stub-h) repeat-x,
    linear-gradient(#000 0 0) 0 var(--stub-h) / 100% 100% no-repeat;
}

.perf--light {
  filter: invert(1);
  opacity: 0.4;
}

.cover-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: calc(var(--stub-h) + 22px) 22px 22px;
}

.cover-guest {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.cover-guest b {
  font-weight: 800;
}

.cover-names {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  min-height: 0;
  contain: size;
  overflow: hidden;
  padding-top: 0.12em;
  margin: 0;
  font-family: var(--display);
  font-size: clamp(60px, 24vw, 168px);
  font-weight: 400;
  line-height: 1.04;
  text-transform: uppercase;
}

.cover-amp {
  color: var(--ink);
  font-size: 0.62em;
  line-height: 1;
}

.cover-date {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 18px;
  padding-top: 12px;
  border-top: 2px solid var(--paper);
  font-family: var(--display);
  font-size: clamp(26px, 7vw, 44px);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}

.cover-invite {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
}

.btn--open {
  width: 100%;
  min-height: 56px;
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
}

.btn--open span {
  text-wrap: balance;
}

.btn--open:hover {
  background: var(--paper);
  color: var(--ink);
}

.btn--open:focus-visible {
  outline-color: var(--paper);
}

@media (min-width: 900px) and (min-height: 600px) {
  .binding {
    padding: 0 10px 0 28px;
  }

  .binding-date {
    font-size: 28px;
  }

  .hanger {
    position: absolute;
    bottom: 0;
    left: 50%;
    display: block;
    width: 300px;
    height: calc(var(--wall-h) - 4px);
    translate: -50% 0;
  }

  .cover-body {
    display: grid;
    grid-template:
      "guest guest" auto
      "names names" minmax(0, 1fr)
      "date invite" auto
      "date open" auto
      / minmax(0, 1fr) minmax(340px, 520px);
    column-gap: 56px;
    padding: calc(var(--stub-h) + 28px) 48px 44px;
  }

  .cover-guest {
    grid-area: guest;
    font-size: 18px;
  }

  /* the couple runs across the whole cover, as large as it will go */
  .cover-names {
    flex-flow: row wrap;
    align-content: flex-end;
    justify-content: flex-start;
    column-gap: 0.22em;
    grid-area: names;
    margin-bottom: 28px;
    padding-bottom: 22px;
    border-bottom: 3px solid var(--paper);
    font-size: 200px;
    line-height: 0.96;
  }

  .cover-amp {
    font-size: 1em;
  }

  .cover-date {
    flex-direction: column;
    align-self: end;
    gap: 0.3em;
    grid-area: date;
    margin: 0;
    padding: 0;
    border: 0;
    font-size: clamp(56px, 8vh, 84px);
    line-height: 1.12;
  }

  .cover-date [data-weekday] {
    color: var(--ink);
  }

  .cover-invite {
    grid-area: invite;
    margin-bottom: 12px;
    font-size: 19px;
  }

  .btn--open {
    grid-area: open;
    min-height: 68px;
    padding: 0 16px;
    font-size: 15px;
    letter-spacing: 0.02em;
  }
}

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