/* Tiny Game: a till receipt that plays. All art is painted in code. */

:root {
  --font-display: 'Special Elite', 'Courier New', monospace;
  --font-mono: 'Cutive Mono', 'Courier New', monospace;
  --font-num: 'VT323', 'Courier New', monospace;
  --grain-paper: none;
  --grain-dark: none;
  --counter-tex: none;
  --tear-shape: polygon(0 0, 100% 0, 100% calc(100% - 9px), 100% 100%, 100.00% 100%, 98.33% calc(100% - 9px), 96.67% 100%, 95.00% calc(100% - 9px), 93.33% 100%, 91.67% calc(100% - 9px), 90.00% 100%, 88.33% calc(100% - 9px), 86.67% 100%, 85.00% calc(100% - 9px), 83.33% 100%, 81.67% calc(100% - 9px), 80.00% 100%, 78.33% calc(100% - 9px), 76.67% 100%, 75.00% calc(100% - 9px), 73.33% 100%, 71.67% calc(100% - 9px), 70.00% 100%, 68.33% calc(100% - 9px), 66.67% 100%, 65.00% calc(100% - 9px), 63.33% 100%, 61.67% calc(100% - 9px), 60.00% 100%, 58.33% calc(100% - 9px), 56.67% 100%, 55.00% calc(100% - 9px), 53.33% 100%, 51.67% calc(100% - 9px), 50.00% 100%, 48.33% calc(100% - 9px), 46.67% 100%, 45.00% calc(100% - 9px), 43.33% 100%, 41.67% calc(100% - 9px), 40.00% 100%, 38.33% calc(100% - 9px), 36.67% 100%, 35.00% calc(100% - 9px), 33.33% 100%, 31.67% calc(100% - 9px), 30.00% 100%, 28.33% calc(100% - 9px), 26.67% 100%, 25.00% calc(100% - 9px), 23.33% 100%, 21.67% calc(100% - 9px), 20.00% 100%, 18.33% calc(100% - 9px), 16.67% 100%, 15.00% calc(100% - 9px), 13.33% 100%, 11.67% calc(100% - 9px), 10.00% 100%, 8.33% calc(100% - 9px), 6.67% 100%, 5.00% calc(100% - 9px), 3.33% 100%, 1.67% calc(100% - 9px), 0 calc(100% - 9px));
}

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

html, body { margin: 0; height: 100%; }

body {
  overflow: hidden;
  background: #141311;
  color: #ded7c8;
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* ---------- the counter ---------- */

.counter {
  position: fixed;
  inset: 0;
  background-color: #171614;
  background-image: var(--grain-dark), var(--counter-tex);
  background-size: 220px 220px, cover;
  background-position: 0 0, center;
  overflow: hidden;
}

.mat {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 21%;
  z-index: 1;
  background-color: #383d36;
  background-image:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .20) 0 1px, rgba(255, 255, 255, .018) 1px 2px, transparent 2px 5px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .07) 0 1px, transparent 1px 4px),
    var(--grain-dark);
  background-size: auto, auto, 180px 180px;
  border-top: 1px solid #0d0e0c;
}

.machine {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 500px);
  height: 19px;
  z-index: 5;
  background: #0a0a09;
  border-bottom: 1px solid #302f2b;
}
.machine__slot {
  position: absolute;
  inset: 4px 7px 3px;
  background: #050504;
  box-shadow: inset 0 3px 0 #000, inset 0 -1px 0 rgba(226, 218, 200, .10);
}

/* ---------- the paper ---------- */

.stage {
  position: absolute;
  top: 15px;
  bottom: calc(56px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(88vw, 480px);
  z-index: 3;
}

.paper-shadow {
  position: absolute;
  inset: 8px -9px -11px 5px;
  z-index: 0;
  background-image: radial-gradient(circle, rgba(0, 0, 0, .62) .7px, rgba(0, 0, 0, 0) 1px);
  background-size: 3px 3px;
  opacity: .5;
  -webkit-mask-image: radial-gradient(120% 105% at 52% 46%, #000 52%, transparent 80%);
  mask-image: radial-gradient(120% 105% at 52% 46%, #000 52%, transparent 80%);
}

.receipt {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 13px 26px 0;
  color: var(--ink);
  background-color: transparent;
  container-type: inline-size;
  overflow: hidden;
}

.receipt .paper {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--paper);
  -webkit-clip-path: var(--tear-shape);
  clip-path: var(--tear-shape);
}

.receipt::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 7px;
  z-index: 8;
  background: repeating-linear-gradient(90deg, rgba(0, 0, 0, .055) 0 1px, transparent 1px 3px);
  opacity: .6;
  pointer-events: none;
}
.receipt::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 6px;
  z-index: 8;
  background: repeating-linear-gradient(90deg, transparent 0 2px, rgba(0, 0, 0, .05) 2px 3px);
  opacity: .7;
  pointer-events: none;
}

.receipt .grain {
  position: absolute;
  inset: 0;
  z-index: 9;
  background-image: var(--grain-paper);
  background-size: 150px 150px;
  opacity: var(--grain-opacity, .62);
  pointer-events: none;
  -webkit-clip-path: var(--tear-shape);
  clip-path: var(--tear-shape);
}

.receipt[data-stock="thermal"] {
  --paper: #f4efe2;
  --paper-hi: #faf6ec;
  --ink: #1e1b18;
  --ink-2: #514a42;
  --ink-3: #7d766b;
  --rule: #bdb5a6;
  --red: #c2402d;
  --yellow: #f2c200;
  --blue: #2e4c6d;
  --cream: #f8f3e6;
  --carton: #d8d2c5;
  --tin: #f2c200;
  --bread: #eddfc3;
  --banana: #f2c200;
  --cereal: #2e4c6d;
  --milk-label: #2e4c6d;
  --stamp: 194, 64, 45;
}
.receipt[data-stock="carbon"] {
  --paper: #f2d7d2;
  --paper-hi: #f9e7e2;
  --ink: #3b2523;
  --ink-2: #6b4b47;
  --ink-3: #99726d;
  --rule: #cfa09a;
  --red: #a82f2b;
  --yellow: #d3a445;
  --blue: #3a4f68;
  --cream: #fae9e4;
  --carton: #d8bcb8;
  --tin: #d3a445;
  --bread: #e9cec2;
  --banana: #d3a445;
  --cereal: #3a4f68;
  --milk-label: #6b4b47;
  --stamp: 168, 47, 43;
}
.receipt[data-stock="legal"] {
  --paper: #f0e6b8;
  --paper-hi: #f7efcb;
  --ink: #2c2a1c;
  --ink-2: #5c583e;
  --ink-3: #8b8663;
  --rule: #c2b88b;
  --red: #b8462f;
  --yellow: #d9a400;
  --blue: #33536f;
  --cream: #f7efcb;
  --carton: #d4c9a4;
  --tin: #d9a400;
  --bread: #e8d7a8;
  --banana: #d9a400;
  --cereal: #33536f;
  --milk-label: #33536f;
  --stamp: 184, 70, 47;
}
.receipt[data-stock="blueprint"] {
  --paper: #203c5c;
  --paper-hi: #2b4a6c;
  --ink: #dce9f3;
  --ink-2: #aac3d7;
  --ink-3: #7c9ab3;
  --rule: #5a7994;
  --red: #e8836a;
  --yellow: #e6d193;
  --blue: #9ec7e8;
  --cream: #2c4a68;
  --carton: #3c5b79;
  --tin: #6a6239;
  --bread: #3b5570;
  --banana: #6a6239;
  --cereal: #33587c;
  --milk-label: #9ec7e8;
  --stamp: 220, 234, 245;
}

/* ---------- printed header ---------- */

.head { flex: none; text-align: center; }
.head__store {
  margin: 0;
  font-size: 9.5px;
  letter-spacing: .3em;
  text-transform: uppercase;
  opacity: .82;
}
.head__name {
  margin: 3px 0 5px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(28px, 8.2cqw, 39px);
  line-height: 1;
  letter-spacing: .005em;
}
.head__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  font-size: clamp(7.4px, 1.95cqw, 9px);
  letter-spacing: .13em;
  text-transform: uppercase;
  opacity: .8;
}
.head__row--sub { margin-bottom: 2px; opacity: .7; }
.rule { height: 1px; margin-top: 8px; background: var(--rule); }

/* ---------- play area ---------- */

.play {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 8px -8px 0;
  touch-action: none;
  cursor: ew-resize;
}

.code {
  position: absolute;
  inset: 11px 18px auto 18px;
  margin: 0;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: clamp(6.8px, 2.3cqw, 10.4px);
  line-height: 1.62;
  letter-spacing: .01em;
  color: var(--ink);
  opacity: .155;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}
.code--ghost {
  z-index: 0;
  transform: translate(1px, .8px);
  opacity: .06;
}

#canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  outline: none;
}

.plate {
  position: absolute;
  z-index: 4;
  left: 6%;
  right: 6%;
  top: 11%;
  padding: 12px 10px 11px;
  border: 1px dashed var(--rule);
  background: var(--paper);
  text-align: center;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.plate__kicker {
  margin: 0 0 8px;
  font-size: clamp(7.4px, 2cqw, 9px);
  letter-spacing: .18em;
  text-transform: uppercase;
  opacity: .7;
}
.plate__go {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(18px, 4.6cqw, 24px);
  line-height: 1.08;
  text-transform: uppercase;
  letter-spacing: .015em;
}
.plate__or {
  display: block;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: clamp(8.6px, 2.25cqw, 10.5px);
  line-height: 1.2;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .72;
}
.plate__sub {
  max-width: 33ch;
  margin: 8px auto 0;
  font-size: clamp(7.8px, 2.05cqw, 9.5px);
  line-height: 1.42;
  opacity: .72;
}
.plate.is-off { opacity: 0; transform: translateY(-5px); pointer-events: none; }

.miss {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 1px;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: .4em;
  text-indent: .4em;
  color: var(--red);
  opacity: 0;
  pointer-events: none;
}
.miss.is-on { animation: miss-flash .55s steps(2, end) 1; }
@keyframes miss-flash {
  0%, 55% { opacity: 1; }
  100% { opacity: 0; }
}

.stamp {
  position: absolute;
  z-index: 5;
  top: 48%;
  left: 50%;
  width: 88%;
  height: auto;
  transform: translate(-50%, -50%) rotate(-7deg);
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.receipt[data-stock="blueprint"] .stamp { mix-blend-mode: normal; opacity: 0; }
.stamp.is-on {
  opacity: 1;
  animation: stamp-down .3s cubic-bezier(.2, .85, .3, 1.15) both;
}
.receipt[data-stock="blueprint"] .stamp.is-on { opacity: .94; }
@keyframes stamp-down {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-13deg) scale(1.35); }
  55% { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-7deg) scale(1); }
}

.hint {
  flex: none;
  margin: 0;
  padding: 4px 0 5px;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-size: clamp(7px, 1.9cqw, 8.6px);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: .6;
}
.hint.is-over { color: var(--red); opacity: .9; }

/* ---------- printed list and total ---------- */

.slip { flex: none; }
.slip__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: clamp(7px, 1.85cqw, 8.6px);
  letter-spacing: .14em;
  text-transform: uppercase;
}
.slip__row--head { margin-top: 3px; opacity: .78; }

.lines {
  list-style: none;
  margin: 3px 0 0;
  padding: 0;
  height: calc(3 * clamp(13px, 3.55cqw, 15px));
  overflow: hidden;
  scrollbar-width: none;
}
.lines::-webkit-scrollbar { display: none; }
.lines li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: baseline;
  height: clamp(13px, 3.55cqw, 15px);
  font-size: clamp(9.5px, 2.6cqw, 12px);
  letter-spacing: .015em;
  text-transform: uppercase;
  animation: print-line .16s ease-out both;
}
.lines li .nm { white-space: nowrap; }
.lines li .lead { border-bottom: 1px dotted var(--rule); transform: translateY(-3px); }
.lines li .pr { font-variant-numeric: tabular-nums; }
.lines li.is-void { color: var(--red); opacity: .8; }
@keyframes print-line {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.total {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  margin-top: 4px;
  padding-top: 1px;
  border-top: 1px solid var(--rule);
}
.total__label {
  padding-bottom: 10px;
  font-size: clamp(7.4px, 1.95cqw, 9px);
  letter-spacing: .28em;
  text-transform: uppercase;
  opacity: .86;
}
.total__value {
  font-family: var(--font-num);
  font-size: clamp(46px, 13cqw, 68px);
  line-height: .78;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
}

.slip__row--foot { margin-top: 3px; align-items: center; }
.drops { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.drop {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  opacity: .45;
  transition: background-color .12s ease;
}
.drop.is-full { background: var(--red); border-color: var(--red); opacity: 1; }
.best a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--ink-3);
}
.best {
  max-width: 55%;
  overflow: hidden;
  text-align: right;
  white-space: nowrap;
  text-overflow: ellipsis;
  letter-spacing: .07em;
}

.barcode {
  flex: none;
  height: clamp(26px, 5.6cqw, 38px);
  margin: 4px -4px 0;
  padding-top: 4px;
  border-top: 1px solid var(--rule);
}
.barcode canvas { display: block; width: 100%; height: 100%; }

.tear {
  flex: none;
  height: 9px;
  margin: 0 -26px;
  background: transparent;
}

/* ---------- paper stock tabs ---------- */

.stocks {
  position: absolute;
  z-index: 7;
  left: clamp(10px, 2.2vw, 30px);
  bottom: calc(10px + env(safe-area-inset-bottom));
}
.stocks__label {
  margin: 0 0 7px 3px;
  font-size: 8px;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: #a9a395;
}
.stocks__row { display: flex; align-items: flex-end; gap: 9px; }

.tab {
  --tilt: -5deg;
  --dy: 2px;
  position: relative;
  width: clamp(32px, 3.2vw, 40px);
  height: clamp(27px, 3vw, 34px);
  padding: 0;
  border: 0;
  background: var(--tab-paper);
  color: var(--tab-ink);
  cursor: pointer;
  clip-path: polygon(0 14%, 8% 2%, 16% 12%, 24% 3%, 32% 13%, 40% 2%, 48% 12%, 56% 3%, 64% 13%, 72% 2%, 80% 12%, 88% 3%, 95% 12%, 100% 4%, 100% 100%, 0 100%);
  transform: rotate(var(--tilt)) translateY(var(--dy));
  transition: transform .18s ease, filter .18s ease;
}
.tab:nth-child(2) { --tilt: 4deg; --dy: 1px; }
.tab:nth-child(3) { --tilt: -2deg; --dy: 3px; }
.tab:nth-child(4) { --tilt: 6deg; --dy: 2px; }
.tab[aria-pressed="true"] { --tilt: 0deg; --dy: -6px; }
.tab:hover { filter: brightness(1.06); }
.tab:focus-visible { outline: none; }
.tab:focus-visible::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed var(--tab-ink);
  opacity: .7;
  pointer-events: none;
}
.tab__dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 3px;
  height: 3px;
  background: var(--tab-dot);
}

/* ---------- feed in and tear off ---------- */

.receipt.is-printing { animation: feed-in .34s ease-out both; }
.receipt.is-printing .plate { animation: plate-in .24s .16s ease-out both; }
.receipt.is-tearing { animation: tear-off .3s ease-in both; }
.receipt.is-tearing .stamp { opacity: 0; animation: none; }

/* These used to clip the whole receipt away, so a theme tap or a new round
   left the header and the paper stock strip over an empty dark counter for
   half a second. The paper now feeds with a short rise and fade, and the game
   stays on screen the whole way through. */
@keyframes feed-in {
  from { opacity: .55; transform: translateY(-7px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes plate-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes tear-off {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(9px) rotate(.2deg); opacity: .9; }
}


/* On a tall phone, keep the start card just above the cart so the opening
   frame reads as a game rather than a menu over an empty sheet. */
@media (max-width: 700px) and (min-height: 700px) {
  .plate { top: auto; bottom: 150px; }
}

/* ---------- smaller screens ---------- */

@media (max-height: 640px) {
  .stage { top: 12px; bottom: calc(48px + env(safe-area-inset-bottom)); }
  .head__store { font-size: 8px; }
  .head__name { margin: 1px 0 3px; font-size: clamp(22px, 7cqw, 30px); }
  .head__row { font-size: 7.2px; }
  .rule { margin-top: 5px; }
  .play { margin-top: 5px; }
  .plate { top: 5%; padding: 8px 8px 7px; }
  .plate__kicker { margin-bottom: 5px; }
  .plate__go { font-size: clamp(15px, 4.2cqw, 19px); }
  .plate__sub { display: none; }
  .lines { height: calc(3 * 12px); }
  .lines li { height: 12px; font-size: 9.5px; }
  .total__value { font-size: 42px; }
  .hint { font-size: 7px; padding: 3px 0; }
  .barcode { height: 24px; }
  .stocks__label { margin-bottom: 4px; font-size: 7px; }
}

@media (max-height: 480px) {
  .head__store { display: none; }
  .head__row--sub { display: none; }
  .head__name { font-size: 20px; margin: 0 0 2px; }
  .head__row { font-size: 6.8px; }
  .play { margin-top: 3px; }
  .lines { height: calc(2 * 11px); }
  .lines li { height: 11px; font-size: 8.6px; }
  .total__value { font-size: 34px; }
  .barcode { display: none; }
  .slip__row--foot { font-size: 6.4px; }
  .code { font-size: 6.4px; line-height: 1.34; }
  .plate { top: 0; left: 14%; right: 14%; padding: 5px 8px 4px; }
  .plate__kicker { display: none; }
  .plate__or { display: none; }
  .plate__go { font-size: 12px; }
  .stocks { bottom: 5px; }
  .stocks__label { display: block; font-size: 6.8px; margin-bottom: 3px; }
  .tab { width: 30px; height: 24px; }
  .stamp { width: 74%; }
}

@media (max-width: 360px) {
  .receipt { padding-left: 18px; padding-right: 18px; }
  .tear { margin: 0 -18px; }
  .stocks__row { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .receipt.is-printing,
  .receipt.is-printing .plate,
  .receipt.is-tearing,
  .stamp.is-on,
  .miss.is-on,
  .lines li {
    animation: none !important;
  }
}
