/* The sandpile pass: a festival pass alone on a black page, with the words above it and the pill at the foot. Its
   seal is a sandpile grown by script.js on the canvas, in the colours below. */
:root {
  --page: #000000;          /* the page */
  --ink: #f4f1ea;           /* the words */
  --muted: #8a877f;         /* the quiet words */
  --ticket: #121212;        /* the pass */
  --ticket-edge: #262525;   /* its edge and the perforation */
  --sand-1: #ff5b3a;        /* a cell holding one grain: the accent */
  --sand-2: #f4f1ea;        /* two grains */
  --sand-3: #2e2d31;        /* three grains */
  --spark: #fff3e6;         /* a cell the sand reaches for the first time */
  --cold: #3a3a3a;          /* the seal while the connection is lost */
  --error: #ff6a55;         /* the connection lost */
  --ok: #7fe0a6;            /* the pass is ready */
  --button: #f4f1ea;        /* the pill */
  --button-ink: #0b0b0b;    /* its words */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap, no zoom */
html {
  touch-action: manipulation;
}

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

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

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

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

/* ---------------------------------------------------------------- the words */
.sp {
  display: grid;
  width: min(380px, 100%);
}

.sp__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}

.sp__words {
  min-width: 0;
}

.sp__title,
.sp__meta {
  margin: 0;
  white-space: nowrap;
}

.sp__title {
  font-size: 20px;
  font-weight: 620;
  font-stretch: 88%;
  line-height: 25px;
  letter-spacing: -0.025em;
}

.sp__meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 430;
  line-height: 18px;
}

.sp__swap {
  display: inline-block;
}

.sp[data-mode='lost'] .sp__title {
  color: var(--error);
}

.sp[data-mode='done'] .sp__title,
.sp[data-mode='added'] .sp__title {
  color: var(--ok);
}

.sp__figure {
  position: relative;
  flex: none;
  display: grid;
  place-items: center end;
  min-width: 60px;
  height: 30px;
  margin: 0;
}

.sp__pct {
  grid-area: 1 / 1;
  font-size: 27px;
  font-weight: 460;
  font-stretch: 78%;
  line-height: 30px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.sp[data-mode='lost'] .sp__pct {
  color: var(--error);
}

.sp__tick {
  grid-area: 1 / 1;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--ok);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
}

/* ---------------------------------------------------------------- the pass */
/* a ticket: the seal on the left, the details on the right, a perforation between them with a notch at each end */
.pass {
  --seal: min(172px, 46vw);
  --cut: calc(var(--seal) + 28px);
  position: relative;
  display: grid;
  grid-template-columns: var(--seal) 1fr;
  gap: 28px;
  align-items: center;
  margin-top: 16px;
  padding: 14px;
  border-radius: 14px;
  background: var(--ticket);
  -webkit-mask-image:
    radial-gradient(circle 9px at var(--cut) 0, transparent 8.5px, #000 9px),
    radial-gradient(circle 9px at var(--cut) 100%, transparent 8.5px, #000 9px);
  -webkit-mask-composite: source-in;
  mask-image:
    radial-gradient(circle 9px at var(--cut) 0, transparent 8.5px, #000 9px),
    radial-gradient(circle 9px at var(--cut) 100%, transparent 8.5px, #000 9px);
  mask-composite: intersect;
}

/* the perforation: a row of tiny holes */
.pass::before {
  content: '';
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: calc(var(--cut) - 0.75px);
  width: 1.5px;
  background: repeating-linear-gradient(180deg, var(--ticket-edge) 0 3px, transparent 3px 7px);
}

.pass__seal {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--seal);
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
}

.pass__canvas {
  display: block;
  image-rendering: pixelated;
}

/* before anything is grown, a quiet word in the middle */
.pass__empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #4a4844;
  font-size: 12px;
  font-weight: 500;
  font-stretch: 85%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}

.pass__info {
  display: grid;
  gap: 11px;
  min-width: 0;
  margin: 0;
}

.pass__info div {
  min-width: 0;
}

.pass__info dt {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 520;
  font-stretch: 85%;
  line-height: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pass__info dd {
  margin: 2px 0 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 520;
  line-height: 18px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pass__code {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pass__code.is-set {
  color: var(--sand-1);
  letter-spacing: 0.04em;
}

.pass__code span {
  display: inline-block;
}

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

.sp__status {
  min-width: 0;
  overflow: hidden;
  padding: 3px 2px;
  margin: -3px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 430;
  line-height: 17px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sp[data-mode='lost'] .sp__status {
  color: var(--error);
}

/* the pill: its fill swells from the middle with a small give and the words widen on the width axis */
.pill {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  min-width: 128px;
  height: 46px;
  padding: 0 22px;
  overflow: hidden;
  border: 0;
  border-radius: 23px;
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(244, 241, 234, 0.42);
  font: inherit;
  font-size: 14.5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

.pill__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--button);
  transform: scale(1);
  transition: transform 0.55s cubic-bezier(0.3, 1.5, 0.5, 1), opacity 0.2s ease;
}

.pill__label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--button-ink);
  font-weight: 600;
  font-stretch: 86%;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: font-stretch 0.5s cubic-bezier(0.3, 1.5, 0.5, 1), color 0.25s ease;
}

.pill__label svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pill.is-quiet .pill__fill {
  transform: scale(0.86, 0.4);
  opacity: 0;
}

.pill.is-quiet .pill__label {
  color: var(--ink);
}

@media (hover: hover) {
  .pill:hover .pill__label {
    font-stretch: 100%;
  }

  .pill.is-quiet:hover .pill__fill {
    transform: scale(1);
    opacity: 1;
  }

  .pill.is-quiet:hover .pill__label {
    color: var(--button-ink);
  }
}

.pill:active .pill__label,
.pill.is-pressed .pill__label {
  font-stretch: 100%;
}

.pill.is-quiet:active .pill__fill,
.pill.is-quiet.is-pressed .pill__fill {
  transform: scale(1);
  opacity: 1;
}

.pill.is-quiet:active .pill__label,
.pill.is-quiet.is-pressed .pill__label {
  color: var(--button-ink);
}

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

@media (max-width: 380px) {
  .pass {
    gap: 22px;
    --cut: calc(var(--seal) + 25px);
  }

  .pill {
    min-width: 0;
    padding: 0 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pill__fill {
    transition: opacity 0.25s ease;
  }

  .pill.is-quiet .pill__fill {
    transform: none;
  }

  .pill__label {
    transition: color 0.25s ease;
  }
}
