/* Return Stonk Policy - two inks and one machine. */

@font-face {
  font-family: "Satoshi";
  src: url("fonts/Satoshi-Black.woff2") format("woff2");
  font-weight: 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Satoshi";
  src: url("fonts/Satoshi-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Satoshi";
  src: url("fonts/Satoshi-Medium.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Sligoil";
  src: url("fonts/Sligoil-Micro.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Sligoil";
  src: url("fonts/Sligoil-MicroBold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --acid: #d3fb0e;
  --ink: #000;
  --ink-2: rgba(0, 0, 0, 0.62);
  --print-2: rgba(211, 251, 14, 0.58);
  --pad: clamp(18px, 2.2vw, 38px);
  --gap: clamp(16px, 1.8vw, 30px);
  --tooth: 15px;
  --rip: 8px;
  /* one length for the machine column: a percentage here would resolve against the
     parent's height wherever --ps is used in a vertical property */
  --col-w: clamp(300px, 36vw, 500px);
  --sans: "Satoshi", "Helvetica Neue", Arial, sans-serif;
  --mono: "Sligoil", ui-monospace, "SFMono-Regular", Menlo, monospace;
  /* keep the paper edge as one recipe: a solid body plus a repeating tooth strip */
  --rip-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='15' height='8' preserveAspectRatio='none'><path d='M0 0 L7.5 8 L15 0 Z' fill='%23000'/></svg>");
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--acid);
  color: var(--ink);
  font-family: var(--sans);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }

h1, h2, p, dl, dd, dt, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }

:where(a, button, [role="switch"]):focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

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

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 40;
  background: var(--ink); color: var(--acid);
  font: 700 14px/1 var(--sans); padding: 12px 16px; border-radius: 4px;
  text-decoration: none; transition: top .15s;
}
.skip:focus { top: 12px; }

/* ---------------------------------------------------------------- stage */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--col-w);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "mast machine"
    "subs machine";
  column-gap: clamp(24px, 3vw, 60px);
  row-gap: var(--gap);
  height: 100dvh;
  padding: var(--pad);
}

.mast { grid-area: mast; min-width: 0; }
.subs { grid-area: subs; }
.col-right { grid-area: machine; }

.col { min-width: 0; min-height: 0; }

.col-right {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
  /* every part of the machine is measured off one printer width */
  /* the printer's viewBox is cropped to the drawing itself, so the machine's outer edges
     line up with the panel below it; 339 x 259 is that crop */
  --pw: min(var(--col-w), calc(46dvh * 339 / 259));
  --ps: calc(var(--pw) / 339);
  --tape-w: calc(184 * var(--ps) - 6px);
  --tape-pad: 10px;
  --tape-h: clamp(220px, 42dvh, 400px);
}

/* ------------------------------------------------------------- masthead */

.lockup {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: clamp(16px, 2vw, 34px);
}

.mark {
  width: clamp(58px, 8.6vw, 124px);
  height: auto;
  color: var(--ink);
  flex: none;
}

.wordmark {
  font-weight: 900;
  font-size: clamp(38px, 5.1vw, 78px);
  line-height: 0.86;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.strap {
  margin-top: clamp(12px, 1.4vw, 22px);
  max-width: 46ch;
  font-weight: 500;
  font-size: clamp(15px, 1.25vw, 20px);
  line-height: 1.32;
  color: var(--ink-2);
}

.ident {
  margin-top: clamp(14px, 1.6vw, 24px);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
}

.ticker {
  font: 900 clamp(17px, 1.5vw, 23px)/1 var(--sans);
  letter-spacing: -0.02em;
  background: var(--ink); color: var(--acid);
  padding: 9px 13px 10px; border-radius: 4px;
}

.links { display: flex; flex-wrap: wrap; gap: 10px; }

.link {
  display: inline-flex; align-items: center; gap: 9px;
  min-height: 44px; padding: 0 16px;
  border: 2px solid var(--ink); border-radius: 4px;
  background: transparent; color: var(--ink);
  font: 700 14px/1 var(--sans); letter-spacing: 0.01em;
  text-decoration: none; cursor: pointer;
}
/* the marks keep their own approved colours, so the pill never inverts under them */
.link:hover { box-shadow: 4px 4px 0 var(--ink); transform: translate(-2px, -2px); }
.link:active { box-shadow: none; transform: none; }
.link svg { width: 16px; height: 16px; fill: var(--ink); }
.link img {
  width: 24px; height: 24px; object-fit: contain;
  background: var(--ink); padding: 3px; border-radius: 3px;
}
.link[aria-disabled="true"] {
  border-style: dashed; color: var(--ink-2); cursor: not-allowed;
}
.link[aria-disabled="true"]:hover { box-shadow: none; transform: none; }
.link[aria-disabled="true"] svg { fill: var(--ink-2); }
.link[aria-disabled="true"] img { opacity: .5; }

/* contract block: the only place on the page where the address lives */
.contract {
  margin-top: 14px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  background: var(--ink); color: var(--acid);
  border-radius: 5px; padding: 12px 14px;
}
.contract-lab {
  font: 700 11px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--print-2);
}
.contract-val {
  font: 400 clamp(11px, 0.95vw, 14px)/1.4 var(--mono);
  overflow-wrap: anywhere; word-break: break-all; flex: 1 1 16ch; min-width: 0;
  -webkit-user-select: all; user-select: all;
}
.contract-val[data-empty="true"] { color: var(--print-2); user-select: auto; }
.contract-copy {
  flex: none; min-height: 36px; padding: 0 14px;
  background: var(--acid); color: var(--ink); border: 0; border-radius: 3px;
  font: 900 12px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer;
}
.contract-copy:disabled { background: transparent; color: var(--print-2); box-shadow: inset 0 0 0 2px currentColor; cursor: not-allowed; }
.contract-copy:not(:disabled):active { transform: translateY(1px); }
.contract-copy:focus-visible { outline-color: var(--acid); }

/* ------------------------------------------------------- subscriptions */

.subs { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; min-height: 0; }

.subs-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; }
.subs-h {
  font: 900 clamp(15px, 1.25vw, 19px)/1 var(--sans);
  letter-spacing: 0.02em; text-transform: uppercase;
}
.subs-note { font: 400 12px/1.35 var(--mono); color: var(--ink-2); max-width: 62ch; }

.subs-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
  gap: clamp(12px, 1.2vw, 20px);
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 4px 26px 2px;
  /* paper running off the edge of the desk: the cue that the stack continues */
  -webkit-mask-image: linear-gradient(#000 calc(100% - 52px), transparent);
  mask-image: linear-gradient(#000 calc(100% - 52px), transparent);
  scrollbar-width: thin;
  scrollbar-color: var(--ink) transparent;
}
.subs-list::-webkit-scrollbar { width: 8px; }
.subs-list::-webkit-scrollbar-thumb { background: var(--ink); border-radius: 8px; }

.sub { min-width: 0; display: flex; }

.paper {
  background: var(--ink);
  color: var(--acid);
  padding: 15px 15px calc(13px + var(--rip));
  -webkit-mask-image: linear-gradient(#000, #000), var(--rip-mask);
  mask-image: linear-gradient(#000, #000), var(--rip-mask);
  -webkit-mask-size: 100% calc(100% - var(--rip)), var(--tooth) var(--rip);
  mask-size: 100% calc(100% - var(--rip)), var(--tooth) var(--rip);
  -webkit-mask-position: top left, bottom left;
  mask-position: top left, bottom left;
  -webkit-mask-repeat: no-repeat, repeat-x;
  mask-repeat: no-repeat, repeat-x;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.sub-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sub-name {
  font: 900 15px/1.15 var(--sans); letter-spacing: -0.01em;
  text-transform: uppercase;
}
.sub-plan {
  flex: none;
  font: 400 11px/1 var(--mono); letter-spacing: 0.1em;
  color: var(--print-2);
}

.sub-rule { height: 2px; background: var(--print-2); margin: 10px 0 9px; opacity: .5; }

.sub-rows { font: 400 12px/1.62 var(--mono); }
.sub-rows > div { display: flex; justify-content: space-between; gap: 12px; }
.sub-rows dt { color: var(--print-2); letter-spacing: 0.06em; text-transform: uppercase; }
.sub-rows dd { font-variant-numeric: tabular-nums; }

.sub-big { margin-top: 11px; }
.sub-big-lab {
  display: block;
  font: 400 10px/1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--print-2); margin-bottom: 4px;
}
.money { font: 400 clamp(23px, 1.85vw, 29px)/1 var(--mono); letter-spacing: -0.02em; display: block; }
.money .tail { font-size: 0.52em; opacity: 0.62; letter-spacing: 0.01em; }

.sub-act {
  margin-top: auto;
  padding-top: 13px;
  min-height: 46px;              /* the result lands in the button's own slot */
  display: grid;
}
.sub-act > * { grid-area: 1 / 1; align-self: center; }

.btn-refund {
  width: 100%; min-height: 46px;
  background: var(--acid); color: var(--ink);
  border: 0; border-radius: 4px;
  font: 900 15px/1 var(--sans); letter-spacing: 0.04em; text-transform: uppercase;
  cursor: pointer;
}
.btn-refund:hover { background: #fff; }
.btn-refund:active { transform: translateY(2px); }
.btn-refund:disabled { background: transparent; color: var(--print-2); box-shadow: inset 0 0 0 2px currentColor; cursor: progress; }
.btn-refund:focus-visible { outline-color: var(--acid); }

.sub-done {
  font: 400 12px/1.4 var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
  text-align: center;
}
.sub-done b { display: block; font: 700 17px/1.3 var(--mono); color: var(--acid); letter-spacing: 0; }

/* a spent receipt keeps its ink but loses its emphasis; opacity here would drop the
   result line below a readable contrast */
.sub.is-closed .paper { color: var(--print-2); }
.sub.is-closed .sub-done { color: var(--acid); }
.sub.is-closed .money { text-decoration: line-through; text-decoration-thickness: 2px; }

.subs-empty {
  font: 700 15px/1.5 var(--sans);
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 6px 2px 18px;
}
.subs-empty[hidden] { display: none; }
.btn-ghost {
  min-height: 44px; padding: 0 18px;
  background: var(--ink); color: var(--acid); border: 0; border-radius: 4px;
  font: 900 14px/1 var(--sans); letter-spacing: 0.04em; text-transform: uppercase;
  cursor: pointer;
}
.btn-ghost:active { transform: translateY(2px); }

/* ------------------------------------------------------------- machine */

.machine-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.machine-id {
  font: 900 12px/1 var(--sans); letter-spacing: 0.16em;
  background: var(--ink); color: var(--acid);
  padding: 11px 11px 12px; border-radius: 4px;
}
.sw {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 38px; padding: 0 12px;
  border: 2px solid var(--ink); border-radius: 4px;
  background: transparent; color: var(--ink);
  font: 700 12px/1 var(--sans); letter-spacing: 0.04em;
  cursor: pointer;
}
.sw-state {
  font: 400 10px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase;
  border-left: 2px solid currentColor; padding-left: 8px; opacity: .75;
}
.sw[aria-checked="true"] { background: var(--ink); color: var(--acid); }
.sw[aria-checked="true"]:focus-visible { outline-color: var(--ink); }

/* --ps turns one printer width into every part fixed to the drawing */
.well {
  position: relative;
  min-height: 0;
  /* the printer's viewBox is cropped to the drawing itself, so the machine's outer edges
     line up with the panel below it; 339 x 259 is that crop */
  --pw: min(var(--col-w), calc(46dvh * 339 / 259));
  --ps: calc(var(--pw) / 339);
  --tape-w: calc(184 * var(--ps) - 6px);
  /* the paper's run is reserved whether or not anything has printed, so nothing below
     the machine moves when a receipt arrives */
  --tape-h: clamp(230px, 44dvh, 430px);
  --tape-pad: 10px;
  height: calc(157 * var(--ps) + var(--tape-h));
}

.printer { width: var(--pw); height: auto; display: block; margin-left: auto; }
.printer-slot { transform-box: fill-box; transform-origin: center; }
.well.is-printing .printer-slot { animation: feed .16s steps(2, jump-none) infinite; }
@keyframes feed { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(1.5px); } }

.tape {
  position: absolute;
  top: calc(157 * var(--ps));
  right: calc(129 * var(--ps) + 3px);
  width: var(--tape-w);
  background: var(--ink);
  color: var(--acid);
  border-left: 2px solid var(--acid);
  border-right: 2px solid var(--acid);
  padding: calc(10 * var(--ps)) var(--tape-pad) calc(10px + var(--rip));
  /* 24 columns of a 0.6em advance have to sit inside the slot, whatever the slot measures */
  font-size: clamp(8px, calc((var(--tape-w) - 2 * var(--tape-pad)) / 24 / 0.6), 15px);
  -webkit-mask-image: linear-gradient(#000, #000), var(--rip-mask);
  mask-image: linear-gradient(#000, #000), var(--rip-mask);
  -webkit-mask-size: 100% calc(100% - var(--rip)), var(--tooth) var(--rip);
  mask-size: 100% calc(100% - var(--rip)), var(--tooth) var(--rip);
  -webkit-mask-position: top left, bottom left;
  mask-position: top left, bottom left;
  -webkit-mask-repeat: no-repeat, repeat-x;
  mask-repeat: no-repeat, repeat-x;
  transform-origin: top center;
}

.tape-text {
  margin: 0;
  font-family: var(--mono);
  font-size: inherit;
  line-height: 1.42;
  white-space: pre;
  letter-spacing: 0;
}
.tape-text b { font-weight: 700; }
.tape-code { margin-top: 6px; height: 2.4em; }
.tape-code svg { display: block; width: 100%; height: 100%; }
.tape-foot {
  margin-top: 6px;
  font: 400 0.84em/1.45 var(--mono);
  color: var(--acid);
  letter-spacing: 0.04em;
  white-space: pre-line;
}

.tape.is-torn { animation: drop .5s cubic-bezier(.4, .1, .8, 1) forwards; }
@keyframes drop {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(90px) rotate(-7deg); opacity: 0; }
}

/* the counter the torn slips land on, filling from the panel upwards */
/* the slips stack inside the paper's own column, directly under what produced them */
.pile {
  display: flex; flex-wrap: wrap; gap: 6px;
  align-content: start; justify-content: flex-start;
  width: var(--tape-w);
  margin-left: auto;
  margin-right: calc(129 * var(--ps) + 3px);
  min-height: 30px; overflow: hidden;
  position: relative; z-index: 2;
}

/* one panel closes the column: what the machine is doing, and what you are up */
.panel {
  position: relative; z-index: 2;
  display: grid;
  grid-template-columns: 146px 1fr;   /* fixed, so swapping READY for the button moves nothing */
  align-items: center; gap: 10px 16px;
  background: var(--ink); color: var(--acid);
  border-radius: 5px; padding: 11px 13px;
}

.panel-state { display: grid; }
.panel-state > * { grid-area: 1 / 1; }

.state-idle {
  font: 400 11px/1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--print-2); align-self: center; padding: 0 4px;
}

.tear {
  width: 100%; min-height: 44px; padding: 0 12px;
  background: var(--acid); color: var(--ink);
  border: 0; border-radius: 3px;
  font: 900 13px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer;
}
.tear:hover { background: #fff; }
.tear:active { transform: translateY(2px); }
.tear:focus-visible { outline-color: var(--acid); }

.panel-tally {
  display: flex; align-items: baseline; justify-content: flex-end;
  gap: 4px 14px; flex-wrap: wrap; min-width: 0;
}


/* ---------------------------------------------------------------- tally */

.tally-lab {
  font: 900 11px/1.3 var(--sans); letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--print-2);
}
.tally-val {
  font: 400 clamp(24px, 2.2vw, 34px)/0.95 var(--mono);
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.tally-cur { font-size: 0.42em; letter-spacing: 0.06em; }

.slip {
  background: var(--ink); color: var(--acid);
  font: 400 11px/1 var(--mono); letter-spacing: 0.02em;
  padding: 7px 9px calc(5px + 6px);
  -webkit-mask-image: linear-gradient(#000, #000), var(--rip-mask);
  mask-image: linear-gradient(#000, #000), var(--rip-mask);
  -webkit-mask-size: 100% calc(100% - 6px), 10px 6px;
  mask-size: 100% calc(100% - 6px), 10px 6px;
  -webkit-mask-position: top left, bottom left;
  mask-position: top left, bottom left;
  -webkit-mask-repeat: no-repeat, repeat-x;
  mask-repeat: no-repeat, repeat-x;
  animation: land .32s cubic-bezier(.2, .9, .3, 1) both;
}
@keyframes land {
  from { transform: translateY(-26px) rotate(6deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ----------------------------------------------------------- narrow/short */

/* a shorter desktop gets a shorter paper run rather than a scrollbar on the body */
@media (min-width: 901px) and (max-height: 860px) {
  .well { --tape-h: clamp(200px, 40dvh, 340px); }
  .tally-val { font-size: 30px; }
}

@media (max-width: 900px), (max-height: 700px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "mast" "machine" "subs";
    height: auto;
    min-height: 100dvh;
    row-gap: clamp(26px, 4.5vw, 42px);
  }
  .col-right { grid-template-rows: none; }
  .subs { display: block; }
  .subs-list {
    overflow: visible; padding-bottom: 0;
    -webkit-mask-image: none; mask-image: none;
  }
  .col-right {
    display: block;
    --col-w: min(calc(100vw - 2 * var(--pad)), 430px);
    --pw: var(--col-w);
    --tape-h: clamp(280px, 78vw, 420px);
    --tape-pad: 6px;
  }
  .machine-bar { margin-bottom: 12px; }
  .well { margin-inline: auto; }
  .pile { margin-top: 12px; margin-bottom: 0; min-height: 0; }
  .panel { margin-top: 12px; }
  .lockup { flex-wrap: wrap-reverse; justify-content: flex-start; }
  .mark { width: clamp(52px, 15vw, 74px); }
}

@media (prefers-reduced-motion: reduce) {
  .well.is-printing .printer-slot { animation: none; }
  .tape.is-torn { animation-duration: .01ms; }
  .slip { animation: none; }
  .btn-refund:active, .tear:active, .btn-ghost:active { transform: none; }
}
