/*
 * Ticket effects: makes the flat ticket read as a crisp piece of 7.5 pt thermal ticket stock.
 * With WebGL the ticket is drawn on the canvas (ticket-gl.js) and the DOM ticket below is hidden; without
 * it, the DOM ticket is shown flat, lit by gradient layers that ticket-effects.js updates per frame.
 *
 *   .tfx                     stage cell: perspective, takes the pointer
 *     .tfx-shadow            the DOM ticket's shadow: a sharp and a soft copy, crossfaded by height
 *     .tfx-card              print feed and tear (and, for the DOM ticket, tilt, lift and flip)
 *       .tfx-front           the ticket face (.tfx-face), and its .tfx-shade / .tfx-spec lighting
 *       .tfx-back            the back art, turned around
 *       canvas.tfx-gl        the WebGL ticket and its shadow
 *     .tfx-slot              printer mouth, shown while printing
 */

.tfx {
  --scale: 1;
  --w: calc(528px * var(--scale));
  --h: calc(188px * var(--scale));
  --glare: 0.3; --grain: 0.3; --gloss: 1;
  position: relative;
  width: var(--w);
  height: var(--h);
  perspective: 1100px;
  touch-action: pan-y; /* vertical swipes still scroll the page; horizontal drags tilt */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.tfx-card {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  will-change: transform;
}

.tfx-front, .tfx-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.tfx-back { transform: rotateY(180deg); }
/* the engine marks which side faces the viewer; the other side is switched off */
.tfx-card[data-face="b"] > .tfx-front, .tfx-card[data-face="f"] > .tfx-back { visibility: hidden; }

/* ---- WebGL: the canvas is larger than the ticket, centred on it, with room for the shadow ---- */
.tfx-gl { position: absolute; display: none; pointer-events: none; }
.tfx[data-gl="on"] .tfx-gl { display: block; }
/* asleep: a still picture of the ticket in the canvas's place, until the live one is drawn again */
.tfx-still { position: absolute; pointer-events: none; }
.tfx-still canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tfx[data-gl="on"] .tfx-still { display: none; }
/* the DOM ticket stays underneath, see-through, so its text is still there for screen readers */
.tfx[data-gl] .tfx-front { opacity: 0; }
.tfx[data-gl] .tfx-back, .tfx[data-gl] .tfx-shadow { visibility: hidden; }
/* Site (2026-11-17): session replays (PostHog) redraw the page without its scripts and can't redraw the WebGL canvas, so
   there the DOM ticket shows in its place, the side that's up. A visitor's page always runs scripts: this never matches. */
@media (scripting: none) {
  .tfx[data-gl] .tfx-card:not([data-face="b"]) > .tfx-front { opacity: 1; visibility: visible; }
  .tfx[data-gl] .tfx-card[data-face="b"] > .tfx-back { visibility: visible; }
  .tfx .tfx-gl, .tfx .tfx-still { display: none !important; }
}

.tfx-face {
  position: absolute;
  left: 0; top: 0;
  width: 528px;
  height: 188px;
  transform: scale(var(--scale));
  transform-origin: 0 0;
  overflow: hidden;
}

.tfx-content {
  position: absolute;
  inset: 0;
  /* don't inherit the page's text settings (the site's .ticket wrapper does the same) */
  text-align: left;
  color: #000;
  font-size: 16px;
  line-height: normal;
  letter-spacing: normal;
  text-transform: none;
}
/* the editor draws a 1 px gray outline and a 1 px margin around the ticket; a cut ticket has neither */
.tfx .tfx-content .sf .ticket { margin: 0; outline: none; }
.tfx-backart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.tfx-layer { position: absolute; inset: 0; pointer-events: none; }

/* ---- paper tooth ---- */
.tfx-grain {
  background-image: var(--tfx-noise);
  background-size: 128px 128px;
  mix-blend-mode: multiply;
  opacity: calc(0.55 * var(--grain));
}
.tfx:not([data-grain]) .tfx-grain { display: none; }

/* ---- thermal print: a very light, even texture in the ink and a hair of bleed ---- */
.tfx[data-ink] .sf-ink {
  -webkit-mask-image: var(--tfx-ink-mask);
  mask-image: var(--tfx-ink-mask);
  -webkit-mask-size: 96px 96px;
  mask-size: 96px 96px;
  text-shadow: 0 0 0.6px rgba(0, 0, 0, 0.5);
}

/* ---- glossy ink: a white copy of the printed text, masked to the light, screened over the black ---- */
.sf-gloss { display: none; }
.tfx[data-gloss] .sf-gloss {
  display: inline-block;
  pointer-events: none;
  color: #fff !important;
  -webkit-text-fill-color: #fff;
  -webkit-text-stroke-color: #fff;
  text-shadow: 0 0 0.6px rgba(255, 255, 255, 0.5);
  mix-blend-mode: screen;
  opacity: 0;
  /* a soft spot twice the ticket's size; the engine slides it to the pointer with mask-position */
  -webkit-mask-image: radial-gradient(circle 100px at center, #000 0%, rgba(0, 0, 0, 0.45) 40%, transparent 100%);
  mask-image: radial-gradient(circle 100px at center, #000 0%, rgba(0, 0, 0, 0.45) 40%, transparent 100%);
  -webkit-mask-size: 1056px 376px;
  mask-size: 1056px 376px;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}
.tfx .sf-gloss img { filter: invert(1); }

/* ---- perforations: dashed slits, a dark side and a lit side ---- */
.tfx-perf { display: none; }
.tfx[data-perf] .tfx-perf { display: block; }
.tfx-perf i {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  margin-left: -1px;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.34) 0 5px, transparent 5px 7.5px) 0 1px / 1px 100% no-repeat,
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.9) 0 5px, transparent 5px 7.5px) 1px 1px / 1px 100% no-repeat;
}

/* ---- glare (flat HTML ticket only): a fixed light's reflection, broad because paper scatters light. A
   gradient twice the ticket's size; the engine slides it with the tilt by transform, without redrawing. ---- */
.tfx-glare {
  inset: auto;
  left: -264px; top: -94px;
  width: 1056px; height: 376px;
  opacity: 0;
  background: radial-gradient(circle 300px at center, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.4) 20%, rgba(255, 255, 255, 0) 55%);
  mix-blend-mode: overlay;
}
.tfx:not([data-glare]) .tfx-glare { display: none; }

/* ---- light from the tilt (the engine writes each layer's colour) ---- */
.tfx-spec { mix-blend-mode: screen; }

/* ---- the cut edges: a hairline, lit on top ---- */
.tfx-edge {
  border: 0.5px solid rgba(0, 0, 0, 0.22);
  border-top-color: rgba(255, 255, 255, 0.7);
}

/* ---- the DOM ticket's shadow: one dark rectangle, a sharp and a soft copy ---- */
.tfx-shadow { position: absolute; inset: 4% 0; pointer-events: none; will-change: transform; }
.tfx:not([data-shadow]) .tfx-shadow { display: none; }
.tfx-shadow i { position: absolute; inset: 0; background: #000; }
.tfx-shadow .sharp { filter: blur(calc(2px * var(--scale) + 1px)); }
.tfx-shadow .soft { filter: blur(calc(16px * var(--scale) + 4px)); }

/* ---- printing: fed out of a slot on the left, right edge first, at a steady speed ---- */
.tfx-slot {
  position: absolute;
  top: -7%; bottom: -7%;
  left: -12px;
  width: 12px;
  border-radius: 3px 1px 1px 3px;
  background: linear-gradient(90deg, #555, #2a2a2a 45%, #050505);
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.25), 1px 0 0 rgba(255, 255, 255, 0.15), 6px 0 14px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
  z-index: 2;
}
.tfx[data-print] .tfx-slot { opacity: 1; }
.tfx[data-print="feed"], .tfx[data-print="attached"] { clip-path: inset(-80px -80px -120px -12px); /* the slot sits in that 12 px */ }
.tfx[data-print="feed"] .tfx-card,
.tfx[data-print="feed"] .tfx-shadow { animation: tfx-feed var(--feed-ms, 2400ms) cubic-bezier(0.3, 0, 0.25, 1) both; }
@keyframes tfx-feed {
  from { translate: -101% 0; }
  to { translate: 0 0; }
}
/* the tear: a short tug to the right as the stock gives, then it settles */
.tfx[data-print="tear"] .tfx-card { animation: tfx-tear 520ms cubic-bezier(0.2, 0.7, 0.3, 1) both; }
@keyframes tfx-tear {
  0% { translate: var(--pull) 0; rotate: 0deg; }
  35% { translate: calc(var(--pull) + 10px) -1px; rotate: -0.7deg; }
  100% { translate: 0 0; rotate: 0deg; }
}
.tfx[data-print="attached"] { cursor: grab; }

@media (prefers-reduced-motion: reduce) {
  .tfx[data-print] .tfx-card, .tfx[data-print] .tfx-shadow { animation: none !important; }
}

/* ---- click-to-edit ---- */
/* the field under the pointer: a dashed outline drawn on the sheet (positioned by the engine) */
.tfx-hover { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; display: none; z-index: 3; }
.tfx-hover path { fill: none; stroke: #d7262c; stroke-linejoin: round; stroke-linecap: round; }
.tfx-hover[data-style="dashed"] path { fill: rgba(215, 38, 44, 0.06); stroke-width: 1.25; stroke-dasharray: 4 3; }
/* a focus ring: thin solid line with a soft glow */
.tfx-hover[data-style="ring"] path { fill: rgba(215, 38, 44, 0.04); stroke-width: 1.5; filter: drop-shadow(0 0 3px rgba(215, 38, 44, 0.45)); }
/* the print's weight on the page's own ticket (what's typed while editing, the flat HTML ticket): the same
   medium + outline the drawn ticket uses, instead of each browser's own made-up bold (inkCss in ticket-gl.js) */
.tfx .sf .ticket { font-weight: 400; font-synthesis: none; -webkit-text-stroke-width: 0; }
/* site (2026-10-21): the weight from a ring of eight sharp shadows half the ink width out, as inkCss (the outline stroke
   drew faint light lines inside letters in some Chromes) */
.tfx .sf .ticket .sf-ink { --tfx-r: calc(var(--tfx-ink, .4px) / 2); --tfx-d: calc(var(--tfx-ink, .4px) * .35355);
  text-shadow: var(--tfx-r) 0 0 currentColor, calc(-1 * var(--tfx-r)) 0 0 currentColor, 0 var(--tfx-r) 0 currentColor, 0 calc(-1 * var(--tfx-r)) 0 currentColor,
    var(--tfx-d) var(--tfx-d) 0 currentColor, var(--tfx-d) calc(-1 * var(--tfx-d)) 0 currentColor, calc(-1 * var(--tfx-d)) var(--tfx-d) 0 currentColor, calc(-1 * var(--tfx-d)) calc(-1 * var(--tfx-d)) 0 currentColor; }
.tfx[data-ink] .sf .ticket .sf-ink { text-shadow: var(--tfx-r) 0 0 currentColor, calc(-1 * var(--tfx-r)) 0 0 currentColor, 0 var(--tfx-r) 0 currentColor, 0 calc(-1 * var(--tfx-r)) 0 currentColor,
    var(--tfx-d) var(--tfx-d) 0 currentColor, var(--tfx-d) calc(-1 * var(--tfx-d)) 0 currentColor, calc(-1 * var(--tfx-d)) var(--tfx-d) 0 currentColor, calc(-1 * var(--tfx-d)) calc(-1 * var(--tfx-d)) 0 currentColor,
    0 0 .6px rgba(0, 0, 0, .5); }

/* what just changed (highlight()): a blue outline that throbs a few times and fades */
.tfx-mark { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; display: none; z-index: 3; opacity: 0; }
.tfx-mark path { fill: rgba(40, 130, 255, 0.07); stroke: #2f86ff; stroke-width: 1.6; stroke-linejoin: round; filter: drop-shadow(0 0 3px rgba(47, 134, 255, 0.95)) drop-shadow(0 0 8px rgba(47, 134, 255, 0.55)); }
@keyframes tfx-mark { 0% { opacity: 0; } 9% { opacity: 1; } 22% { opacity: .3; } 35% { opacity: 1; } 48% { opacity: .3; } 61% { opacity: 1; } 78% { opacity: 1; } 100% { opacity: 0; } }
/* a highlighter wash, no line */
.tfx-hover[data-style="tint"] path { fill: rgba(215, 38, 44, 0.13); stroke: none; }
.tfx-hover[data-style="underline"] path { stroke-width: 2; }
/* corner marks, like a viewfinder */
.tfx-hover[data-style="brackets"] path { stroke-width: 1.75; }
/* While a field is edited the drawn ticket lies flat and leaves that field out; the page's own text shows it,
   with the input in it, exactly where it was drawn. */
.tfx[data-gl="on"][data-editing] .tfx-front { opacity: 1; visibility: hidden; z-index: 1; /* over the canvas */ }
.tfx[data-gl="on"][data-editing] .tfx-front .tfx-editing { visibility: visible; }
.tfx[data-gl="on"][data-editing] .tfx-front .tfx-editing * { visibility: visible; }
.tfx-input {
  font: inherit; color: inherit; letter-spacing: inherit; text-align: inherit; text-transform: none;
  position: absolute; left: 0; top: 0; /* over the field's ghost, placed by the engine */
  width: 4ch; height: auto; margin: 0; padding: 0; border: 0; border-radius: 1px;
  background: rgba(215, 38, 44, 0.12);
  outline: 1.5px solid #d7262c; outline-offset: 1px;
  caret-color: #d7262c;
  line-height: normal; text-align: left; white-space: pre;
  box-sizing: content-box;
  -webkit-user-select: text; user-select: text;
}
.tfx-input::selection { background: rgba(215, 38, 44, 0.3); color: inherit; }
/* until the text changes, the drawn ticket shows the field and the input only shows its caret and selection */
.tfx-input.tfx-pristine, .tfx-input.tfx-pristine::selection { color: transparent; -webkit-text-fill-color: transparent; }
.tfx .tfx-ghost { color: transparent !important; -webkit-text-fill-color: transparent; }
.tfx-editlabel {
  position: absolute; z-index: 6; transform: translate(-50%, -100%);
  /* above the ticket (below it for the lower lines), so it never covers the next line up */
  display: flex; gap: 8px; align-items: baseline; white-space: nowrap; pointer-events: none;
  padding: 5px 9px; border-radius: 7px; background: #141414; color: #fff;
  font: 600 12px/1.2 system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.tfx-editlabel[hidden] { display: none; }
.tfx-editlabel.below { transform: translate(-50%, 0); }
.tfx-editlabel b { text-transform: capitalize; }
.tfx-editlabel span { color: #9a9a9a; font-variant-numeric: tabular-nums; }
.tfx-editlabel span.full { color: #ff6b6b; }
.tfx-editlabel small { color: #8a8a8a; font-weight: 400; font-size: 11px; }
@media (hover: none) { .tfx-editlabel small { display: none; } }
/* the flat HTML ticket: its own text takes the hover */
.tfx:not([data-gl]) .tfx-front .sf-ink [data-slot] { cursor: pointer; }
.tfx:not([data-gl]) .tfx-front .sf-ink [data-slot]:hover { outline: 1px dashed #d7262c; outline-offset: 1px; }
