:root {
  --bg: #e7e1d3;
  --bg-glow: #f6efdc;
  --text: #2a2723;
  --muted: #6d675c;
  --ink: #2a2723;
  --paper: #fbf8f1;
  --paper-edge: #e9e2d2;
  --accent: #b3261e;
  --key: #c8372d;
  --key-shadow: #8a2018;
  --device: #2f2c28;
  --device-hi: #45413b;
  --slot: #0e0d0c;
  --panel: #f7f2e6;
  --panel-line: #cfc6b3;
  --field: #fffdf8;
  --field-ink: #2a2723;
  --field-line: #bdb39e;
  --sign-bg: #fbf6ea;
  --sign-ink: #b3261e;
  --sign-glow: transparent;
  --tape-paper: rgb(251 248 241 / 0.6);
  --tape-ink: rgb(42 39 35 / 0.5);
  --tape-edge: rgb(42 39 35 / 0.08);
  --font: "Courier Prime", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sign-font: "Monoton", "Courier Prime", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --bg-glow: #2a1c1f;
    --text: #ece6d8;
    --muted: #a39d90;
    --device: #262320;
    --device-hi: #3a3631;
    --panel: #1d1b19;
    --panel-line: #3b3731;
    --field: #262320;
    --field-ink: #ece6d8;
    --field-line: #4d4840;
    --sign-bg: #171514;
    --sign-ink: #ff5a7a;
    --sign-glow: #ff2d63;
    --tape-paper: rgb(251 248 241 / 0.04);
    --tape-ink: rgb(236 230 216 / 0.32);
    --tape-edge: rgb(236 230 216 / 0.07);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(60% 40% at 50% 0%, var(--bg-glow), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

main {
  width: 100%;
  max-width: 460px;
  padding: 36px 16px 24px;
}

/* ---- shop sign ------------------------------------------------------------------------- */

.sign {
  position: relative;
  margin: 0 auto 18px;
  padding: 14px 18px 12px;
  border: 3px solid var(--sign-ink);
  border-radius: 10px;
  background: var(--sign-bg);
  text-align: center;
  box-shadow:
    0 0 0 4px var(--sign-bg),
    0 0 22px var(--sign-glow);
}

.sign h1 {
  margin: 0;
  font-family: var(--sign-font);
  font-weight: 400;
  font-size: clamp(30px, 9vw, 44px);
  letter-spacing: 0.06em;
  color: var(--sign-ink);
  text-shadow:
    0 0 4px var(--sign-glow),
    0 0 14px var(--sign-glow);
  animation: flicker 2.4s linear 0.2s 1 both;
}

@keyframes flicker {
  0%, 6%, 9%, 14% { opacity: 0.25; }
  5%, 8%, 12%, 100% { opacity: 1; }
}

.open {
  position: absolute;
  top: -11px;
  right: 14px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--key);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  animation: open 1.6s ease-in-out infinite alternate;
}

@keyframes open {
  from { box-shadow: 0 0 0 0 rgb(200 55 45 / 0.5); }
  to { box-shadow: 0 0 0 5px rgb(200 55 45 / 0); }
}

.tagline {
  margin: 0 0 16px;
  text-align: center;
  color: var(--muted);
}

/* ---- register panel (input) ------------------------------------------------------------- */

.register {
  padding: 14px;
  border: 2px solid var(--panel-line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 2px 0 var(--panel-line);
}

#form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#form input {
  grid-column: 1 / -1;
}

#form input,
#form select {
  font: inherit;
  font-size: 16px;
  padding: 11px 12px;
  border: 2px solid var(--field-line);
  border-radius: 8px;
  background: var(--field);
  color: var(--field-ink);
  min-width: 0;
}

#form input:focus-visible,
#form select:focus-visible {
  outline: 2px solid var(--key);
  outline-offset: 1px;
}

.key {
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--key);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--key-shadow);
  transition:
    transform 0.06s,
    box-shadow 0.06s;
}

.key:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--key-shadow);
}

.key:disabled {
  opacity: 0.6;
  cursor: progress;
}

.examples {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.examples button {
  font: inherit;
  padding: 3px 9px;
  border: 1px dashed var(--field-line);
  border-radius: 999px;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.examples button:hover {
  border-style: solid;
}

/* ---- printer device --------------------------------------------------------------------- */

.printer {
  margin-top: 26px;
  position: relative;
}

.device {
  position: relative;
  z-index: 2;
  margin: 0 -14px;
  padding: 10px 16px 14px;
  border-radius: 14px 14px 8px 8px;
  background: linear-gradient(var(--device-hi), var(--device));
  box-shadow:
    0 8px 18px rgb(0 0 0 / 0.25),
    inset 0 1px 0 rgb(255 255 255 / 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #9a948a;
  font-size: 11px;
  letter-spacing: 0.14em;
}

.slot {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 4px;
  height: 5px;
  border-radius: 3px;
  background: var(--slot);
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4a4740;
}

.printer.busy .led {
  background: #5ee07a;
  box-shadow: 0 0 8px #5ee07a;
  animation: blink 0.5s steps(2, jump-none) infinite;
}

@keyframes blink {
  to { opacity: 0.25; }
}

#out {
  margin-top: -6px;
  padding: 0 4px;
  /* on the parent, so the shadow follows the torn edge the mask cuts */
  filter: drop-shadow(0 6px 8px rgb(0 0 0 / 0.25));
}

#out.feeding {
  overflow: hidden;
}

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

.receipt {
  --tear: 10px;
  position: relative;
  padding: 24px 20px calc(18px + var(--tear));
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  /* faint thermal-ink bleed */
  text-shadow: 0 0 0.4px rgb(42 39 35 / 0.6);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.36 0 0 0 0 0.3 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(90deg, var(--paper-edge), var(--paper) 4%, var(--paper) 96%, var(--paper-edge)),
    var(--paper);
  /* torn bottom edge */
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--tear)) 100%;
}

/* html-to-image drops the layered paper background, so captures use flat paper */
.receipt.capturing {
  background: #fbf8f1;
}

.receipt.capturing .stamp {
  mix-blend-mode: normal;
}

/* ---- tear-off pieces -------------------------------------------------------------------- */

.flyer {
  position: fixed;
  z-index: 50;
  transform-origin: 50% 0;
  filter: drop-shadow(0 14px 18px rgb(0 0 0 / 0.35));
  pointer-events: none;
}

.stub {
  --tear: 7px;
  height: 22px;
  background: var(--paper);
  /* the ragged edge the rip leaves behind */
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--tear)) 100%;
}

.scrap {
  position: fixed;
  z-index: 51;
  background: var(--paper);
  border-radius: 1px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  pointer-events: none;
}

/* after printing, the paper hangs from the slot and sways a little */
.receipt.hanging {
  transform-origin: 50% 0;
  animation: sway 5s ease-in-out infinite alternate;
}

@keyframes sway {
  from { transform: rotate(-0.4deg); }
  to { transform: rotate(0.4deg); }
}

.total.rung {
  animation: rung 0.9s ease-out;
}

@keyframes rung {
  0%, 30% {
    background: var(--ink);
    color: var(--paper);
  }
  100% { background: transparent; }
}

.center {
  text-align: center;
}

.store {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.15em;
}

.small {
  font-size: 12px;
}

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

.rule.double {
  border-top: 3px double var(--ink);
}

.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  margin: 0;
}

.meta dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.meta dt {
  text-transform: uppercase;
}

.aisle {
  margin: 10px 0 2px;
  font-weight: 700;
}

.line {
  display: grid;
  grid-template-columns: 1fr 3.5em 5em;
  gap: 6px;
}

.line .qty,
.line .price {
  text-align: right;
}

.line.mystery {
  font-style: italic;
}

.total {
  display: grid;
  grid-template-columns: 1fr auto;
  font-weight: 700;
}

.total.big {
  font-size: 18px;
}

.gifts {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gifts li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.gifts span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note {
  margin: 4px 0 0;
  padding: 8px 10px;
  border: 1px dashed var(--ink);
  font-style: italic;
  text-align: center;
}

.stamp {
  width: fit-content;
  margin: 14px auto 6px;
  transform: rotate(-6deg);
  border: 3px solid var(--accent);
  color: var(--accent);
  padding: 4px 8px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-align: center;
  opacity: 0;
  mix-blend-mode: multiply;
  text-shadow: none;
  pointer-events: none;
}

.stamp.down {
  opacity: 0.85;
}

.barcode {
  display: block;
  width: 100%;
  height: 48px;
  margin: 12px 0 4px;
}

.error {
  background: var(--paper);
  color: var(--ink);
  padding: 18px 20px;
  text-align: center;
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
  overflow-wrap: anywhere;
}

/* ---- after-print actions ----------------------------------------------------------------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 0;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition:
    opacity 0.3s,
    transform 0.3s;
}

.actions.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.actions button {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border: 2px solid var(--field-line);
  border-radius: 8px;
  background: var(--field);
  color: var(--field-ink);
  cursor: pointer;
}

.actions button:active {
  transform: translateY(2px);
}

.actions .key {
  border: none;
  color: #fff;
  background: var(--key);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  transform: translate(-50%, 20px);
  opacity: 0;
  transition:
    opacity 0.25s,
    transform 0.25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.sound {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  border: 2px solid var(--field-line);
  background: var(--field);
  color: var(--field-ink);
  cursor: pointer;
}

.credit {
  max-width: 460px;
  padding: 0 16px 32px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.credit a {
  color: inherit;
}

/* ---- journal tape (wide screens only) ---------------------------------------------------- */

.tape {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 0;
  width: 190px;
  overflow: hidden;
  pointer-events: none;
  background: var(--tape-paper);
  color: var(--tape-ink);
  box-shadow:
    inset 1px 0 0 var(--tape-edge),
    inset -1px 0 0 var(--tape-edge);
  /* lines fade in at the bottom and out at the top */
  mask: linear-gradient(transparent, #000 16%, #000 84%, transparent);
}

.tape.left {
  left: max(16px, calc(50% - 480px));
}

.tape.right {
  right: max(16px, calc(50% - 480px));
}

main,
.credit {
  position: relative;
  z-index: 1;
}

@media (min-width: 1040px) {
  .tape {
    display: block;
  }
}

.track {
  padding: 0 14px;
  font-size: 11px;
  line-height: 1.75;
  animation: tape var(--tape-time, 90s) linear infinite;
  transition: opacity 0.6s;
}

.track.swapping {
  opacity: 0;
}

.track p {
  margin: 0;
  overflow-wrap: anywhere;
}

.track .when {
  display: block;
  margin-top: 10px;
  opacity: 0.6;
  letter-spacing: 0.08em;
}

.track .cut {
  margin: 14px 0 4px;
  text-align: center;
  letter-spacing: 0.12em;
  opacity: 0.7;
}

/* the track holds the lines twice, so moving it up by half loops seamlessly */
@keyframes tape {
  to {
    transform: translateY(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tape .track {
    animation: none;
  }
  .receipt.hanging,
  .total.rung,
  .dots::after,
  .printer.busy .led,
  .sign h1,
  .open {
    animation: none;
  }
  .actions,
  .toast,
  .key {
    transition: none;
  }
}
