:root {
  color-scheme: light;
  --ink: #161823;
  --muted: #6e7180;
  --accent: #ff6b35;
  --accent-soft: #fff0e9;
  --paper: #fffefa;
  --duration: 4200ms;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(rgba(28, 31, 46, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 31, 46, .035) 1px, transparent 1px),
    #f4f5f9;
  background-size: 32px 32px;
}

button { font: inherit; }

.stage {
  width: min(92vw, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(38px, 7vh, 72px) 20px 48px;
  text-align: center;
}

.intro { transition: opacity .4s ease, transform .4s ease; }
.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
}

h1 { margin: 0; font-size: clamp(32px, 5vw, 52px); letter-spacing: -.045em; }
.intro p { margin: 12px auto 0; color: var(--muted); font-size: 15px; }

.printer-scene {
  position: relative;
  width: min(100%, 430px);
  height: 560px;
  margin: 42px auto 10px;
  perspective: 900px;
}

.printer {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 50%;
  width: 390px;
  max-width: 94%;
  height: 56px;
  transform: translateX(-50%);
  border: 1px solid rgba(43, 47, 66, .08);
  border-radius: 17px 17px 12px 12px;
  background: linear-gradient(180deg, #fff 0%, #f1f2f6 70%, #e4e6ed 100%);
  box-shadow: 0 18px 30px rgba(38, 41, 60, .18), inset 0 1px 0 #fff;
}

.printer::before {
  content: "";
  position: absolute;
  inset: 8px 14px auto;
  height: 9px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,.85), rgba(255,255,255,0));
}

.printer-slot {
  position: absolute;
  left: 50%;
  bottom: 7px;
  width: 78%;
  height: 10px;
  transform: translateX(-50%);
  overflow: hidden;
  border-radius: 999px;
  background: #222631;
  box-shadow: inset 0 2px 4px #090b10;
}

.printer-slot span {
  position: absolute;
  inset: 1px auto 1px -35%;
  width: 34%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.5), transparent);
}

.printer-light {
  position: absolute;
  z-index: 2;
  right: 22px;
  top: 17px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aeb2bd;
}

.paper-viewport {
  position: absolute;
  top: 43px;
  left: 50%;
  width: 350px;
  max-width: 78vw;
  height: 0;
  transform: translateX(-50%);
  overflow: hidden;
  filter: drop-shadow(0 20px 18px rgba(27, 29, 42, .18));
}

.receipt {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 495px;
  padding: 31px 30px 32px;
  color: #24252b;
  text-align: left;
  font-family: "Courier New", monospace;
  background:
    linear-gradient(90deg, rgba(0,0,0,.018), transparent 12%, rgba(255,255,255,.3) 45%, transparent 76%),
    var(--paper);
  transform: translateY(-92%);
}

.receipt::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -8px;
  left: 0;
  height: 10px;
  background: linear-gradient(135deg, transparent 6px, var(--paper) 0) 0 0/12px 12px repeat-x;
}

.receipt-header { display: flex; align-items: center; gap: 13px; }
.receipt-header strong { display: block; font-size: 18px; letter-spacing: .05em; }
.receipt-header small { display: block; margin-top: 3px; color: #777; font-size: 10px; }
.receipt-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  color: white;
  font-family: Inter, sans-serif;
  font-size: 13px;
  font-weight: 900;
  background: linear-gradient(135deg, #ff655b, #d92d20);
}

.rule { height: 1px; margin: 19px 0; background: #d7d5ce; }
.rule.dashed { background: repeating-linear-gradient(90deg, #aaa 0 5px, transparent 5px 10px); }
.meta { margin: 0; font-size: 11px; }
.meta div, .items div, .totals div { display: flex; justify-content: space-between; gap: 18px; margin: 8px 0; }
.meta dt { color: #777; }
.meta dd { margin: 0; font-weight: 700; }
.paid { color: #268c5a; }
.document-copy h2 { margin: 0 0 8px; font-family: Inter, sans-serif; font-size: 15px; }
.document-copy p { margin: 0; color: #5f626d; font-family: Inter, sans-serif; font-size: 10px; line-height: 1.6; }
.report-table { font-size: 10px; }
.report-table div { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 8px 5px; border-bottom: 1px solid #e3e1da; }
.report-table .table-head { color: #777; font-size: 9px; font-weight: 700; background: #f3f2ee; }
.report-table b { color: #268c5a; }
.signature { margin: 22px 0 20px auto; width: 135px; text-align: center; }
.signature span { display: block; height: 26px; border-bottom: 1px solid #777; transform: skew(-22deg); }
.signature small { display: block; margin-top: 6px; color: #888; font-size: 7px; }
.thanks { margin: 0; color: #777; text-align: center; font-size: 10px; }
.print-line { opacity: 0; transform: translateY(-5px); }

.progress {
  width: min(100%, 400px);
  height: 5px;
  margin: 0 auto 18px;
  overflow: hidden;
  border-radius: 99px;
  background: #e3e5eb;
}
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ff986c, var(--accent)); }

.actions { display: flex; justify-content: center; gap: 10px; }
.actions button {
  min-height: 48px;
  padding: 0 21px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
}
.actions button:hover { transform: translateY(-2px); }
.actions button:active { transform: translateY(0) scale(.98); }
.primary { border: 0; color: #fff; background: var(--ink); box-shadow: 0 10px 24px rgba(22, 24, 35, .2); }
.download { border: 1px solid #ffd1bf; color: #d94a18; background: var(--accent-soft); }
.download:disabled { color: #a7a8af; border-color: #dedfe5; background: #eeeff3; cursor: not-allowed; opacity: .68; }
.download-arrow { display: inline-grid; width: 20px; height: 20px; margin-right: 5px; place-items: center; border-radius: 50%; background: rgba(255,107,53,.12); }
.secondary { border: 1px solid #d8dae2; color: #4e5260; background: rgba(255,255,255,.7); }
.button-icon { margin-right: 7px; }

.download-target {
  position: fixed;
  z-index: 11;
  right: 28px;
  bottom: 28px;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-size: 26px;
  font-weight: 900;
  background: var(--accent);
  box-shadow: 0 14px 34px rgba(255,107,53,.32);
  opacity: 0;
  transform: translateY(18px) scale(.75);
  transition: opacity .25s ease, transform .4s cubic-bezier(.22,1,.36,1);
}
.stage.downloading .download-target { opacity: 1; transform: translateY(0) scale(1); animation: targetPulse .7s ease-in-out infinite alternate; }

.collected {
  position: fixed;
  z-index: 10;
  top: 50%;
  left: 50%;
  display: flex;
  width: min(88vw, 390px);
  align-items: center;
  gap: 15px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 22px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 30px 90px rgba(23,25,37,.28);
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -45%) scale(.92);
  backdrop-filter: blur(14px);
  transition: opacity .45s ease, transform .55s cubic-bezier(.22,1,.36,1);
}
.collected.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.collected strong, .collected small { display: block; }
.collected small { margin-top: 4px; color: var(--muted); }
.success-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 50%; color: white; font-weight: 900; background: #2da66d; }
.close-card { position: absolute; top: 10px; right: 12px; border: 0; color: #999; font-size: 23px; background: transparent; cursor: pointer; }

.stage.printing .printer { animation: printerVibration .13s linear infinite; }
.stage.printing .printer-slot span { animation: slotScan .7s linear infinite; }
.stage.printing .printer-light { background: #ff783e; box-shadow: 0 0 12px #ff7b43; animation: blink .75s ease-in-out infinite alternate; }
.stage.printing .paper-viewport { animation: revealPaper var(--duration) cubic-bezier(.2,.72,.18,1) forwards; }
.stage.printing .receipt { transform: translateY(0); }
.stage.printing .progress span { animation: load var(--duration) linear forwards; }
.stage.printing .print-line { opacity: 1; transform: translateY(0); }
.stage.printing .primary {
  --progress: 0%;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  color: #9a3c18;
  border: 1px solid #ffc7ae;
  background: #fff0e9;
  box-shadow: 0 8px 20px rgba(255,107,53,.18);
  animation: statusVibration .16s linear infinite;
}
.stage.printing .primary::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 auto 0 0;
  width: var(--progress);
  background: linear-gradient(90deg, #ffd7c5, #ffb58f);
  transition: width .08s linear;
}
.stage.printing .receipt::before {
  content: "";
  position: absolute;
  z-index: 4;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  opacity: .75;
  background: linear-gradient(90deg, transparent, rgba(255,107,53,.7), transparent);
  box-shadow: 0 2px 8px rgba(255,107,53,.22);
  animation: printHeadGlow .45s ease-in-out infinite alternate;
}

.stage.done .intro { opacity: .55; transform: translateY(-4px); }
.stage.done .paper-viewport { height: 510px; }
.stage.done .receipt { transform: translateY(0); }
.stage.done .print-line { opacity: 1; transform: translateY(0); }
.stage.done .progress span { width: 100%; }
.stage.done .receipt { cursor: grab; }
.stage.done .receipt:hover { transform: translateY(0) rotateX(1deg) scale(1.012); transition: transform .3s ease; }
.stage.downloading .receipt {
  transform-origin: 50% 0;
  animation: detachPdf 1.05s cubic-bezier(.55,.02,.18,1) forwards;
}
.stage.downloading .paper-viewport { overflow: visible; }
.stage.downloading .printer { animation: tearJolt .32s ease 2; }
.stage.downloading .collected { opacity: 0; pointer-events: none; transform: translate(-50%, -55%) scale(.94); }

@keyframes revealPaper { 0% { height: 0; } 15% { height: 82px; } 100% { height: 510px; } }
@keyframes load { to { width: 100%; } }
@keyframes inkIn { to { opacity: 1; transform: translateY(0); } }
@keyframes slotScan { to { left: 105%; } }
@keyframes printerPulse { 50% { transform: translateX(-50%) translateY(1px); } }
@keyframes blink { to { opacity: .4; } }
@keyframes printerVibration {
  0% { transform: translateX(-50%) translate(0, 0) rotate(0); }
  25% { transform: translateX(-50%) translate(-.7px, .45px) rotate(-.035deg); }
  50% { transform: translateX(-50%) translate(.6px, -.35px) rotate(.03deg); }
  75% { transform: translateX(-50%) translate(-.35px, -.2px) rotate(-.02deg); }
  100% { transform: translateX(-50%) translate(.5px, .4px) rotate(.025deg); }
}
@keyframes statusVibration {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-.45px, .25px); }
  50% { transform: translate(.35px, -.25px); }
  75% { transform: translate(-.2px, -.15px); }
}
@keyframes printHeadGlow { to { opacity: .28; transform: scaleX(.82); } }
@keyframes detachPdf {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  12% { transform: translateY(7px) rotate(-1deg); }
  28% { transform: translateY(13px) rotate(1.4deg); }
  42% { transform: translateY(18px) rotate(-.6deg); }
  68% { transform: translate(65px, 120px) rotate(5deg) scale(.78); opacity: .92; }
  100% { transform: translate(calc(50vw - 205px), calc(50vh - 180px)) rotate(11deg) scale(.12); opacity: 0; }
}
@keyframes tearJolt {
  35% { transform: translateX(-50%) translateY(-2px); }
  70% { transform: translateX(-50%) translateY(1px); }
}
@keyframes targetPulse { to { box-shadow: 0 18px 42px rgba(255,107,53,.55); transform: translateY(0) scale(1.08); } }

@media (max-width: 560px) {
  .stage { padding-top: 28px; }
  .intro p { max-width: 310px; }
  .printer-scene { height: 535px; margin-top: 32px; }
  .receipt { padding-right: 22px; padding-left: 22px; }
  .receipt-header strong { font-size: 15px; }
  .actions { flex-wrap: wrap; }
  .actions button { padding: 0 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
