/* From your phone to Stellar: a receipt printer on a counter.
   The whole page is one till receipt, 32 columns wide like the 58 mm rolls, that feeds upwards out
   of a printer docked at the bottom of the screen. One typeface, Departure Mono, on the paper and
   on the printer's display; the stamp's word is drawn (outlines of Anton). */

@font-face {
  font-family: "Departure Mono";
  src: url("fonts/DepartureMono-Regular.woff2") format("woff2");
  font-display: block;
}

:root {
  --counter: #2a2d74; /* carbon-paper indigo: the counter the printer sits on */
  --machine: #14163a; /* the printer's body */
  --machine-lip: #3b3f95;
  --paper: #f5f6f4; /* thermal paper */
  --ink: #1d2142; /* thermal print, blue-black */
  --ink-soft: #5b6088;
  --ink-fresh: #9499bb; /* a line the moment it is printed, before it darkens */
  --go: #ffd43d; /* the one key that does something */
  --go-edge: #b58e0c;
  --seal: #0b8a69; /* stamp ink when the contract accepts */
  --void: #c8312f; /* stamp ink when it refuses */
  --glow: #7cf5d6; /* the display's lit dots */
  --glass: #04110e;

  --cols: 32;
  --advance: 0.64; /* a Departure Mono character is 7/11 em wide, rounded up */
  --pad: 16px; /* paper margin, each side */
  --gutter: 14px; /* counter left visible beside the paper, each side */
  --size: clamp(12px, calc((100vw - 2 * var(--pad) - 2 * var(--gutter)) / (var(--cols) * var(--advance))), 19px);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--counter);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--counter);
  color: var(--ink);
  font-family: "Departure Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--size);
  line-height: 1.4;
  /* Fractional character widths everywhere, so 32 columns measure the same on every engine. */
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

h1,
p {
  margin: 0;
  font-weight: normal;
  font-size: inherit;
}

a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

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

.defs {
  position: absolute;
}

/* ---- The counter and the paper -------------------------------------------------------------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  /* Room for the printer, which stays put at the bottom of the screen (app.js measures it); the
     paper ends a little inside it. */
  padding: 30px 0 calc(var(--printer, 190px) - 10px);
  /* The paper comes up from the slot: what is still inside the printer is not seen. */
  overflow: hidden;
}

.receipt {
  position: relative;
  width: calc(var(--cols) * 1ch + 2 * var(--pad));
  max-width: 100%;
  padding: 20px var(--pad) 34px;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(8, 9, 40, 0.08), 0 14px 34px rgba(8, 9, 40, 0.38);
  transition: transform 0.7s steps(14, end);
}

/* The torn edge at the top of the roll. */
.receipt::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 6px;
  background:
    linear-gradient(-45deg, var(--paper) 4.3px, transparent 0) 0 100% / 12px 12px repeat-x,
    linear-gradient(45deg, var(--paper) 4.3px, transparent 0) 0 100% / 12px 12px repeat-x;
}

/* On arrival the top of the receipt feeds out of the printer. */
.booting .receipt {
  transform: translateY(calc(100% - 56px));
  transition: none;
}

.big {
  font-size: 2em;
  line-height: 1.12;
  margin-bottom: 0.12em;
}

.rule {
  overflow: hidden;
  white-space: nowrap;
  color: var(--ink-soft);
}
.rule::before {
  content: "--------------------------------";
}
.rule.double::before {
  content: "================================";
}

.band {
  margin: 0.75em -0.5ch 0.4em;
  padding: 0.1em 0.5ch;
  background: var(--ink);
  color: var(--paper);
}

.soft {
  color: var(--ink-soft);
}

.gap {
  height: 0.7em;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 1ch;
}
.row .v {
  text-align: right;
  white-space: nowrap;
}
/* Double height, the way a till prints its totals. */
.row.tall {
  height: 2.8em;
}
.row.tall > * {
  transform: scaleY(2);
  transform-origin: 50% 0;
}
/* The short rule above a total. */
.subrule {
  text-align: right;
  color: var(--ink-soft);
}
.subrule::before {
  content: "----------";
}

.center {
  text-align: center;
}

/* A line being printed: the head burns it in from the top, and it darkens as it cools. */
.print {
  animation:
    print 0.15s steps(5, end) both,
    develop 0.6s ease-out both;
}
@keyframes print {
  from {
    clip-path: inset(0 0 100% 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}
@keyframes develop {
  from {
    color: var(--ink-fresh);
  }
}
.band.print {
  animation: print 0.15s steps(5, end) both;
}

/* A value the printer is still waiting for. */
.wait {
  display: inline-block;
  width: 3ch;
  text-align: left;
}
.wait::after {
  content: "...";
  display: inline-block;
  animation: dots 0.9s steps(4, jump-none) infinite;
}
@keyframes dots {
  from {
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

/* The proof's fingerprint, as a strip of bars. */
.bars {
  display: block;
  width: 100%;
  height: 2.6em;
  margin: 0.5em 0 0.15em;
  color: var(--ink);
}

/* ---- The stamp ------------------------------------------------------------------------------ */

.stamped {
  position: relative;
}
/* Blank paper kept for the stamp. */
.stamp-space {
  height: 7.3em;
}
.stamp {
  position: absolute;
  right: 9px;
  bottom: 0.5em;
  width: 66%;
  color: var(--seal);
  mix-blend-mode: multiply;
  transform: rotate(-7deg);
  pointer-events: none;
}
.stamp-void {
  color: var(--void);
  width: 73%;
}
.stamp-small {
  font-family: "Departure Mono", monospace;
  font-size: 15px;
  letter-spacing: 1.5px;
}
.stamp.slam {
  animation: slam 0.36s cubic-bezier(0.2, 1.5, 0.45, 1) both;
}
@keyframes slam {
  0% {
    opacity: 0;
    transform: rotate(-13deg) scale(2.3);
  }
  60% {
    opacity: 1;
    transform: rotate(-6deg) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: rotate(-7deg) scale(1);
  }
}
.receipt.thump {
  animation: thump 0.26s ease-out;
}
@keyframes thump {
  35% {
    transform: translateY(3px);
  }
}

/* ---- What is this? -------------------------------------------------------------------------- */

.about {
  color: var(--ink-soft);
}
.about summary {
  cursor: pointer;
  color: var(--ink);
  list-style: none;
  padding: 0.75em 0 0.6em;
}
.about summary::-webkit-details-marker {
  display: none;
}
.about summary::before {
  content: "[+] ";
}
.about[open] summary::before {
  content: "[-] ";
}
.about summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.about p {
  margin: 0 0 0.75em;
}
.about b {
  font-weight: normal;
  color: var(--ink);
}

/* ---- The printer ---------------------------------------------------------------------------- */

.printer {
  /* Fixed, not sticky: the paper moves and the printer never does, not even for a frame. */
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  transform: translateX(-50%);
  width: calc(var(--cols) * 1ch + 2 * var(--pad) + 40px);
  max-width: 100%;
  padding: 0 14px max(14px, env(safe-area-inset-bottom));
  background: var(--machine);
  border-radius: 16px 16px 0 0;
  box-shadow: inset 0 1px 0 var(--machine-lip), 0 -8px 22px rgba(7, 8, 32, 0.42);
}

.slot {
  height: 11px;
  margin: 0 6px;
  border-radius: 0 0 6px 6px;
  background: #05061a;
  box-shadow: inset 0 5px 6px #000;
}

.vfd {
  margin: 11px 0 12px;
  padding: 0.5em 0.8em 0.45em;
  border-radius: 7px;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px #000, inset 0 3px 10px rgba(0, 0, 0, 0.9);
  color: var(--glow);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-shadow: 0 0 8px rgba(124, 245, 214, 0.55);
}
.vfd p {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1ch;
  white-space: nowrap;
  overflow: hidden;
}
.vfd-top {
  font-size: 0.82em;
  opacity: 0.72;
}
.vfd-main {
  font-size: 1.5em;
  line-height: 1.25;
}

.led {
  flex: none;
  width: 0.42em;
  height: 0.42em;
  border-radius: 50%;
  background: #1c3f37;
}
.led.on {
  background: var(--glow);
  box-shadow: 0 0 8px var(--glow);
}
.led.busy {
  background: var(--go);
  box-shadow: 0 0 8px var(--go);
  animation: blink 0.5s steps(2, jump-none) infinite;
}
.led.fault {
  background: #ff6a5e;
  box-shadow: 0 0 8px #ff6a5e;
}
@keyframes blink {
  to {
    opacity: 0.25;
  }
}

.keys {
  display: flex;
  gap: 10px;
}
.key {
  flex: 1;
  min-height: 52px;
  padding: 0.75em 0.6em;
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-size: 1.08em;
  color: var(--ink);
  background: var(--go);
  box-shadow: 0 4px 0 var(--go-edge);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s, box-shadow 0.06s;
}
.key:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--go-edge);
}
.key:disabled {
  cursor: default;
  color: rgba(29, 33, 66, 0.72);
  background: #c9ab45;
  box-shadow: 0 4px 0 #8d7216;
}
.key:focus-visible {
  outline: 3px solid var(--paper);
  outline-offset: 3px;
}
.key-plain {
  flex: 0 1 34%;
  color: var(--paper);
  background: transparent;
  box-shadow: inset 0 0 0 1.5px rgba(245, 246, 244, 0.55);
}
.key-plain:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 1.5px rgba(245, 246, 244, 0.9);
}
.key[hidden] {
  display: none;
}

.noscript {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  margin: 0;
  padding: 1em;
  background: var(--go);
  color: var(--ink);
  text-align: center;
}

/* A phone on its side: the printer keeps to one line of display and a lower key. */
@media (max-height: 520px) {
  .vfd {
    margin: 7px 0 8px;
  }
  .vfd-top {
    display: none;
  }
  .vfd-main {
    font-size: 1.2em;
  }
  .key {
    min-height: 44px;
    padding: 0.5em 0.6em;
  }
  main {
    padding-top: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .receipt {
    transition: none;
  }
  .print,
  .band.print,
  .stamp.slam,
  .receipt.thump,
  .led.busy {
    animation: none;
  }
  .wait::after {
    animation: none;
  }
}
