/* A receipt on a counter. One paper colour, one ink colour, one typeface. Nothing here is styled
   for fun: the deadpan is the joke, so the page has to look like a till printed it. */

:root {
  --counter: #2b2724;
  --counter-lip: #211e1b;
  --paper: #f7f3ea;
  --ink: #23201c;
  --ink-soft: #5d574e;
  --ink-faint: #b3a99a;
  --teeth: 8px;
  --pad: 18px;
  --fs: clamp(11.5px, 3.4vw, 13px);
}

* { box-sizing: border-box; }

html { background: var(--counter); }

body {
  margin: 0;
  /* clip, not hidden: a torn bill tilts a little past the edge, and hidden would take the sticky
     foot's scrollport away with it. */
  overflow-x: clip;
  padding: 26px 14px 64px;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(255, 245, 225, 0.07), rgba(0, 0, 0, 0) 60%),
    var(--counter);
  color: var(--paper);
  font: var(--fs) / 1.55 ui-monospace, SFMono-Regular, Menlo, "DejaVu Sans Mono", monospace;
  -webkit-text-size-adjust: 100%;
}

#stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
}

.bill {
  width: min(380px, 100%);
}

/* The paper's background stops short of the bottom edge so the serrated strip can show its teeth
   against the counter. Both the sheet and the (sticky) tail are painted the same way. */
.paper,
.tail {
  background-color: transparent;
  background-image:
    repeating-linear-gradient(90deg, rgba(90, 60, 20, 0.022) 0 1px, rgba(0, 0, 0, 0) 1px 4px),
    linear-gradient(var(--paper), var(--paper));
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 100% calc(100% - var(--teeth));
}

.paper {
  position: relative;
  color: var(--ink);
  padding: 22px var(--pad) 0;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* The foot travels with the paper's bottom edge, and stays in view when the visitor scrolls up to
   read: the total is the point of the thing. */
.bill.live .tail {
  position: sticky;
  bottom: 0;
}

/* Full bleed, so the teeth reach both edges of the paper; the foot keeps the margin instead. */
.tail { margin: 0 calc(var(--pad) * -1); }

.serrate {
  height: var(--teeth);
  /* A 16px tile with an 8px rise makes the 90-degree cone exactly fill it: real teeth, no clipping. */
  background: conic-gradient(from -45deg at bottom, rgba(0, 0, 0, 0), var(--paper) 1deg 89deg, rgba(0, 0, 0, 0) 90deg) 50% / 16px var(--teeth) repeat-x;
}

/* ---- printed lines ---- */

/* The foot's lines come from the template rather than the printer, so the reset has to cover the
   elements, not just the printed rows. */
.paper p,
.paper h2 { margin: 0; }

.row {
  margin: 0;
  opacity: var(--ink-alpha, 1);
  animation: land 120ms ease-out;
}

@keyframes land {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: var(--ink-alpha, 1); transform: none; }
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 6px;
}

.brand b:first-child { letter-spacing: 0.22em; font-weight: 700; }
.brand b { font-weight: 400; }
.brand b:nth-child(2) { color: var(--ink-soft); }
.brand b:nth-child(3) { color: var(--ink-soft); }

.plain { white-space: pre-wrap; }
.shout { letter-spacing: 0.06em; }

.fine,
.note {
  color: var(--ink-soft);
  font-size: 0.92em;
}

.note { margin: 1px 0 3px; }
.studio { color: var(--ink-soft); font-size: 0.92em; margin-top: 4px; }
.studio a { color: inherit; }
.studio a:hover { color: var(--ink); }

.rule {
  border-top: 1px dashed var(--ink-faint);
  margin: 8px 0;
}

.rule.double {
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 5px; /* border-box, so the two rules sit 3px apart and read as the receipt's "=" row */
  margin: 8px 0;
}

.head {
  font: inherit;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  margin: 12px 0 6px;
  padding: 5px 0;
  border-top: 1px dashed var(--ink-faint);
  border-bottom: 1px dashed var(--ink-faint);
}

/* The header closes on a dashed rule and the first section opens on one; one line is enough. */
.rule + .head {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.line {
  display: flex;
  align-items: baseline;
  gap: 0.45em;
}

.line .label { flex: 0 1 auto; min-width: 0; }
.line .val { flex: 0 0 auto; text-align: right; }
.line.meta { justify-content: space-between; }
.line.strong { font-weight: 700; }

/* A zero-height rule that sits on the text baseline: the leader dots of any receipt. */
.line .lead {
  flex: 1 1 1.5em;
  min-width: 0.9em;
  height: 0;
  border-bottom: 1px dotted var(--ink-faint);
  transform: translateY(-0.3em);
}

/* ---- the foot ---- */

.foot { padding: 0 var(--pad) 12px; }
.foot .rule { margin-top: 12px; }
.foot .shout { margin-top: 8px; }

.actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.actions button {
  font: inherit;
  color: var(--ink);
  background: none;
  border: 1px dashed var(--ink-faint);
  border-radius: 0;
  padding: 5px 10px;
  cursor: pointer;
  letter-spacing: 0.04em;
}

.actions button:hover { border-color: var(--ink); }
.actions button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.actions [data-tear] { flex: 1 1 auto; font-weight: 700; }

/* ---- the closing block ---- */

.barcode {
  display: flex;
  align-items: stretch;
  height: 38px;
  margin: 10px 0 4px;
}

.barcode i { background: var(--ink); }
.barcode i.gap { background: none; }

/* The torn piece comes away and settles crooked. The angle has to stay small: a bill can be
   thousands of pixels tall, and a degree at that height throws the bottom of the paper across the
   counter. Rotating about the middle halves what is left of that, and the page clips the rest. */
.bill.torn .paper {
  animation: tear 460ms cubic-bezier(0.22, 1.1, 0.36, 1) both;
  transform-origin: 50% 50%;
}

@keyframes tear {
  0% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(7px) rotate(-0.35deg); }
  100% { transform: translateY(0) rotate(0.4deg); }
}

.after {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.after button {
  font: inherit;
  color: var(--paper);
  background: none;
  border: 1px dashed rgba(247, 243, 234, 0.4);
  border-radius: 0;
  padding: 7px 14px;
  cursor: pointer;
}

.after button:hover { border-color: var(--paper); }
.after button:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }
.after button[disabled] { opacity: 0.5; cursor: default; }

/* On a 320px phone the longest label and its value need every character of the width, so the paper
   keeps a narrower margin rather than letting "Against the background glow" break in two. */
@media (max-width: 400px) {
  :root { --pad: 12px; }
  body { padding-left: 9px; padding-right: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .row,
  .bill.torn .paper {
    animation: none;
  }
}
