:root {
  --page: #ece8df;
  --panel: #fbfaf7;
  --ink: #1b1a17;
  --muted: #6b675e;
  --line: #d8d2c4;
  --paper: #fffdf6;
  --paper-ink: #1b1a17;
  --accent: #1b1a17;
  --ok: #1f7a4d;
  --bad: #b3261e;
  --warn: #8a5a00;
  --add-bg: #fde7c4;
  --del-bg: #f7d4d1;
  --radius: 14px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #161513;
    --panel: #201f1c;
    --ink: #eeeae1;
    --muted: #a39e93;
    --line: #36342f;
    --accent: #eeeae1;
    --add-bg: #5a3d0c;
    --del-bg: #5c1f1b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
h1 { font-size: 1.5rem; line-height: 1.2; margin: 0 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .3rem; }
h3 { font-size: .95rem; margin: 0 0 .3rem; }
.lede { color: var(--muted); margin: 0 0 1.1rem; }
.fine { color: var(--muted); font-size: .85rem; margin: .8rem 0 0; }
.mono { font-family: var(--mono); font-size: .85rem; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: .55rem; text-decoration: none; }
.brand-mark {
  width: 18px; height: 22px; align-self: center; border: 2px solid var(--ink); border-radius: 2px;
  background: repeating-linear-gradient(var(--ink) 0 2px, transparent 2px 6px) 3px 5px / 8px 12px no-repeat;
}
.brand-name { font-weight: 750; font-size: 1.25rem; letter-spacing: -.02em; }
.brand-tag { color: var(--muted); font-size: .9rem; }
.tabs { display: flex; gap: .25rem; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tabs a { text-decoration: none; padding: .35rem .9rem; border-radius: 999px; font-weight: 550; font-size: .95rem; color: var(--muted); }
.tabs a[aria-selected="true"] { background: var(--ink); color: var(--page); }
.count:empty { display: none; }
.count { font-size: .75rem; opacity: .8; }

.banner { margin: 12px clamp(16px, 4vw, 40px) 0; padding: .7rem 1rem; border-radius: 10px; background: #fff3d6; color: #5c3c00; border: 1px solid #f0d58f; }

main { flex: 1; padding: clamp(16px, 3vw, 32px) clamp(16px, 4vw, 40px); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 460px); gap: clamp(16px, 3vw, 40px); align-items: start; max-width: 1180px; margin: 0 auto; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(18px, 3vw, 28px); }
.panel.wide { max-width: 900px; margin: 0 auto; }

/* form */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .9rem; }
.req, .opt { font-weight: 400; color: var(--muted); font-size: .78rem; margin-left: .3rem; }
textarea, input[type="text"] {
  display: block; width: 100%; margin-top: .35rem; padding: .65rem .75rem;
  font: inherit; font-weight: 400; color: var(--ink); background: var(--page);
  border: 1px solid var(--line); border-radius: 10px; resize: vertical;
}
textarea:focus, input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
button, .filebtn {
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  padding: .6rem 1.1rem; border-radius: 10px; border: 1px solid var(--ink); background: transparent; color: var(--ink);
  margin: 0;
}
button.primary { background: var(--ink); color: var(--page); }
button:hover, .filebtn:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: progress; }
.filebtn input { display: none; }
.form-error { color: var(--bad); font-weight: 600; margin: 0 0 .8rem; }

/* result column */
.result { position: sticky; top: 16px; }
.placeholder { text-align: center; color: var(--muted); padding-top: 1rem; }
.ghost-receipt {
  height: 260px; max-width: 360px; margin: 0 auto 1rem; border: 2px dashed var(--line); border-radius: 6px;
}

/* the receipt */
.receipt {
  --zig: 10px;
  position: relative; max-width: 420px; margin: 0 auto;
  background: var(--paper); color: var(--paper-ink);
  font: 13.5px/1.45 var(--mono);
  padding: 28px 24px 30px;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,.14));
  -webkit-mask:
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / var(--zig) 51% repeat-x,
    conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) top / var(--zig) 51% repeat-x;
          mask:
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / var(--zig) 51% repeat-x,
    conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) top / var(--zig) 51% repeat-x;
  animation: print .5s ease-out;
}
@keyframes print { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.receipt .r-head { text-align: center; }
.receipt .r-title { font-weight: 800; font-size: 1.15rem; letter-spacing: .25em; }
.receipt .r-sub { font-size: .78rem; color: #6b675e; letter-spacing: .08em; }
.receipt hr { border: 0; border-top: 1.5px dashed #b9b2a2; margin: 12px 0; }
.receipt .kv { display: flex; justify-content: space-between; gap: 1rem; }
.receipt .kv span:first-child { color: #6b675e; white-space: nowrap; }
.receipt .kv span:last-child { text-align: right; overflow-wrap: anywhere; }
.receipt .lbl { color: #6b675e; font-size: .78rem; letter-spacing: .12em; margin-top: 6px; }
.receipt .txt { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: auto; }
.receipt .txt.short { max-height: 90px; }
.receipt .hash { font-size: .72rem; overflow-wrap: anywhere; color: #3d3a34; }
.receipt .num { font-size: 1.5rem; font-weight: 800; letter-spacing: .12em; text-align: center; margin: 4px 0; }
.receipt .barcode {
  height: 38px; margin: 10px 4px 4px;
  background: var(--bars) center / 100% 100% no-repeat;
}
.receipt .r-foot { text-align: center; font-size: .72rem; color: #6b675e; }
.receipt-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; margin: 18px auto 0; max-width: 420px; }
.receipt-actions button { font-size: .88rem; padding: .5rem .85rem; }

/* stamp */
.verdict { position: relative; max-width: 420px; margin: 0 auto; }
.stamp {
  position: absolute; z-index: 2; top: 128px; left: 50%;
  transform: translate(-50%, -50%) rotate(-8deg);
  font: 800 1.9rem/1 var(--sans); letter-spacing: .12em;
  padding: .45rem .9rem; border: 4px solid currentColor; border-radius: 8px;
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  animation: thump .35s cubic-bezier(.2,1.6,.4,1);
  pointer-events: none; white-space: nowrap;
}
.stamp.ok { color: var(--ok); }
.stamp.bad { color: var(--bad); }
.stamp.unk { color: var(--warn); font-size: 1.5rem; }
@keyframes thump { from { transform: translate(-50%, -50%) rotate(-8deg) scale(1.8); opacity: 0; } to { transform: translate(-50%, -50%) rotate(-8deg) scale(1); opacity: 1; } }
.reasons { max-width: 420px; margin: 16px auto 0; padding: .8rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.reasons.ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.reasons.bad { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.reasons strong { display: block; margin-bottom: .2rem; }
.reasons ul { margin: .2rem 0 0; padding-left: 1.1rem; }
.reasons .who { font-family: var(--mono); font-size: .85rem; }

/* quote diff */
.quote { margin-top: 1.6rem; padding-top: 1.3rem; border-top: 1px dashed var(--line); }
.diff { margin-top: .8rem; padding: .8rem 1rem; border-radius: 10px; background: var(--page); border: 1px solid var(--line); line-height: 1.9; overflow-wrap: anywhere; }
.diff del { background: var(--del-bg); text-decoration: line-through; text-decoration-thickness: 2px; border-radius: 4px; padding: 1px 3px; }
.diff ins { background: var(--add-bg); text-decoration: none; border-radius: 4px; padding: 1px 3px; font-weight: 650; }
.diff-verdict { font-weight: 700; margin-top: .7rem; }
.diff-verdict.ok { color: var(--ok); }
.diff-verdict.bad { color: var(--bad); }
.legend { color: var(--muted); font-size: .8rem; margin-top: .3rem; }

/* my receipts */
.mine { list-style: none; padding: 0; margin: 0; }
.mine li { display: grid; grid-template-columns: auto 1fr auto; gap: .3rem 1rem; align-items: center; padding: .8rem 0; border-top: 1px dashed var(--line); }
.mine .n { font: 700 1rem var(--mono); letter-spacing: .08em; }
.mine .q { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mine .meta { grid-column: 2; color: var(--muted); font-size: .82rem; }
.mine .btns { grid-row: 1 / span 2; grid-column: 3; display: flex; gap: .4rem; }
.mine .btns button { font-size: .82rem; padding: .35rem .7rem; }
.mine .empty { display: block; color: var(--muted); border: 0; }

/* footer */
.limits { padding: 18px clamp(16px, 4vw, 40px) 28px; border-top: 1px solid var(--line); }
.limits details { max-width: 1180px; margin: 0 auto; }
.limits summary { cursor: pointer; font-weight: 650; }
.limits .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: .8rem; }
@media (max-width: 700px) { .limits .cols { grid-template-columns: 1fr; } }
.limits ul { margin: 0; padding-left: 1.1rem; color: var(--muted); }
.limits .fine { max-width: 1180px; margin: .9rem auto 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: .6rem 1rem; border-radius: 999px; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.2); }

@media print {
  body { background: #fff; }
  .top, .banner, .panel, .limits, .receipt-actions, .reasons, .placeholder, .toast { display: none !important; }
  .split { display: block; }
  .result { position: static; }
  .receipt { filter: none; -webkit-mask: none; mask: none; border: 1px dashed #999; animation: none; }
  .view[hidden] { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { .receipt, .stamp { animation: none; } }
