/* The punch card: the loyalty card of a small coffee roaster, on cream paper, on a white page. Ink almost black,
   one roasted-orange accent for the bean that is next and for the stamp. */
:root {
  --page: #ffffff;          /* the page */
  --paper: #f3ecdf;         /* the card */
  --paper-back: #e3d7c2;    /* the back of the card, seen on a falling bean */
  --paper-shade: #d9cdb8;   /* the card in its own shadow, seen through a hole */
  --ink: #1d1813;           /* the words and the printed beans */
  --muted: #8b8174;         /* the small print */
  --accent: #cf4a1f;        /* the next bean and the stamp */
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Bricolage Grotesque Variable', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px 32px;
}

.loyalty {
  position: relative;
  width: min(320px, 100%);
  perspective: 900px;
}

/* the beans that fall out of the back of the card: under the card, over the page */
.chads {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.chad {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  overflow: visible;
  will-change: transform;
}

.chad__face {
  fill: var(--paper);
  stroke: rgba(29, 24, 19, 0.28);
  stroke-width: 0.8;
}

.chad__crease {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.1;
  stroke-linecap: round;
  opacity: 0.55;
}

.chad.is-under .chad__face {
  fill: var(--paper-shade);
}

.chad.is-back .chad__face {
  fill: var(--paper-back);
}

.chad.is-back .chad__crease {
  opacity: 0;
}

/* ---------------------------------------------------------------- the card: the script tilts it under the press */
.deal {
  position: relative;
  z-index: 1;
  transform-style: preserve-3d;
}

.tilt {
  position: relative;
  z-index: 1;
  transform-style: preserve-3d;
  will-change: transform;
}

.card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 320 / 420;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  container-type: inline-size;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.card:focus-visible {
  outline: none;
}

.card:focus-visible::after {
  content: '';
  position: absolute;
  inset: -5px;
  border: 1.5px solid var(--ink);
  border-radius: 20px;
  pointer-events: none;
}

/* the paper: its shadow is a drop-shadow of the cut paper, so it falls into every hole by itself */
.paper {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 1.4px 1.1px rgba(52, 36, 18, 0.26)) drop-shadow(0 4px 6px rgba(52, 36, 18, 0.13));
}

.paper__sheet {
  fill: var(--paper);
}

.paper__frame {
  fill: none;
  stroke: rgba(29, 24, 19, 0.14);
  stroke-width: 1;
}

.paper__rule {
  fill: none;
  stroke: rgba(29, 24, 19, 0.18);
  stroke-width: 1;
}

/* a printed bean: the outline where the punch cuts, the crease in the middle */
.bean__in {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.5s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.bean__edge {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 2.2 2.6;
  opacity: 0.42;
  transition: stroke 0.25s ease, opacity 0.25s ease;
}

.bean__crease {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  stroke-linecap: round;
  opacity: 0.5;
  transition: stroke 0.25s ease, opacity 0.25s ease;
}

.bean.is-gift .bean__edge,
.bean.is-gift .bean__crease {
  stroke: var(--accent);
  opacity: 0.8;
}

/* the bean the next punch will take: in the accent, a touch bigger, when the pointer or the focus is on the card */
.card.is-aiming .bean.is-next .bean__in {
  transform: scale(1.1);
}

.card.is-aiming .bean.is-next .bean__edge {
  stroke: var(--accent);
  stroke-dasharray: none;
  opacity: 1;
}

.card.is-aiming .bean.is-next .bean__crease {
  stroke: var(--accent);
  opacity: 1;
}

/* the stamp of the redeemed card, in the accent ink */
.stamp {
  opacity: 0;
}

.stamp__box {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
}

.stamp__box--in {
  stroke-width: 1;
}

.stamp__word,
.stamp__date {
  fill: var(--accent);
  text-anchor: middle;
  font-family: 'Bricolage Grotesque Variable', 'Helvetica Neue', Arial, sans-serif;
}

.stamp__word {
  font-size: 19px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-variation-settings: 'wght' 780, 'wdth' 78;
}

.stamp__date {
  font-size: 8.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-variation-settings: 'wght' 560, 'wdth' 90;
}

/* ---------------------------------------------------------------- the words printed on the card */
.card__words {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
}

.card__brand {
  position: absolute;
  top: 7.2cqi;
  left: 7.5cqi;
  font-size: 10.6cqi;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variation-settings: 'wght' 760, 'wdth' 76;
}

.card__kind {
  position: absolute;
  top: 19.4cqi;
  left: 7.5cqi;
  color: var(--muted);
  font-size: 3.6cqi;
  letter-spacing: 0.02em;
  font-variation-settings: 'wght' 480, 'wdth' 92;
}

.card__headline {
  position: absolute;
  top: 31.5cqi;
  left: 7.5cqi;
  right: 9cqi;
  font-size: 8.9cqi;
  line-height: 1.02;
  letter-spacing: -0.015em;
  font-variation-settings: 'wght' 420, 'wdth' 88;
  text-wrap: balance;
}

.card__status {
  position: absolute;
  top: 63.4cqi;
  left: 7.5cqi;
  right: 7.5cqi;
  font-size: 4.7cqi;
  line-height: 1.2;
  white-space: nowrap;
  font-variation-settings: 'wght' 520, 'wdth' 92;
}

.card__num {
  display: inline-block;
  color: var(--accent);
  font-variation-settings: 'wght' 640, 'wdth' 92;
  will-change: transform;
}

.card__small {
  position: absolute;
  left: 7.5cqi;
  right: 7.5cqi;
  bottom: 7.4cqi;
  color: var(--muted);
  font-size: 3.3cqi;
  letter-spacing: 0.03em;
  font-variation-settings: 'wght' 460, 'wdth' 94;
}

/* ---------------------------------------------------------------- undo: printed on nothing, it sits on the card */
.undo {
  position: absolute;
  top: 5.2%;
  right: 4.5%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 8px 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(29, 24, 19, 0);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  line-height: 1;
  font-variation-settings: 'wght' 560, 'wdth' 90;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.2s ease;
}

.undo[hidden] {
  display: none;
}

.undo svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) and (pointer: fine) {
  .undo:hover {
    background: rgba(29, 24, 19, 0.07);
  }
}

.undo:active {
  background: rgba(29, 24, 19, 0.12);
}

.undo:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 1px;
}

.hint {
  position: relative;
  z-index: 2;
  margin: 26px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  letter-spacing: 0.01em;
  font-variation-settings: 'wght' 480, 'wdth' 94;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
