/* One scene, not a form: a stone on a dark bench under a lamp. Everything the player needs
   sits in that scene as an object (the seller's paper tag, which also keeps the bill,
   chalk marks for what the tools found, a red stamp for the verdict). Text only labels objects. */
:root {
  --bg: #121411; --fg: #ece7da; --muted: #8f8e83; --line: #2e312a;
  --paper: #efe7d4; --ink: #221e18; --ink-soft: #6a6255; --pen: #b8321f;
  --jade: #7cc39c; --jade-deep: #1f6b4c; --red: #e0705c;
  --f-display: "Noto Serif SC", "Songti SC", serif;
  --f-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --f-didone: "Bodoni Moda", "Didot", Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; overscroll-behavior: none; }
body { font: 15px/1.5 var(--f-body); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; }

.app { height: 100vh; height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }

button, .btn { font: 600 15px var(--f-body); color: var(--fg); background: transparent; border: 0; border-radius: 999px; padding: 10px 14px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  -webkit-user-select: none; user-select: none; transition: transform .08s ease, background .15s, color .15s, opacity .15s; }
button:active:not(:disabled), .btn:active { transform: scale(.94); }
button:disabled { opacity: .3; cursor: default; }
button:focus-visible, .btn:focus-visible, input:focus-visible { outline: 2px solid var(--jade); outline-offset: 2px; }
.link { color: var(--muted); padding-inline: 10px; }
.link:hover { color: var(--fg); }
.go, .primary { background: var(--jade); color: #0d1a13; padding-inline: 22px; font-weight: 700; }
.ghost { color: var(--muted); }

/* header: a quiet line, not a bar */
.top { flex: none; display: flex; align-items: baseline; gap: 8px; padding: 8px 16px 4px; }
.top h1 { font-size: 19px; font-weight: 900; letter-spacing: .14em; white-space: nowrap; }
.meta { font: 11px var(--f-mono); color: var(--muted); white-space: nowrap; margin-right: auto; }
.top .link { min-height: 36px; padding: 4px 6px; font-size: 13px; font-weight: 500; }

/* the scene */
.stage { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  background: radial-gradient(110% 80% at 50% 38%, #47595a 0%, #2c3739 50%, #161917 100%); transition: background-color .3s; }
.stage.dark { background: radial-gradient(90% 70% at 50% 45%, #1b2020 0%, #0a0b0c 100%); }
.stage::after { content: ""; position: absolute; inset: auto 0 0; height: 70px; background: linear-gradient(transparent, var(--bg)); pointer-events: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.stage canvas.fx { pointer-events: none; }
.stage > :not(canvas) { pointer-events: none; z-index: 1; }

/* the seller's tag, hung in the corner on a string */
.tag { position: absolute; bottom: 10px; right: 16px; display: grid; justify-items: start; gap: 1px; padding: 10px 14px 10px 22px; min-width: 104px;
  background: var(--paper); color: var(--ink); transform: rotate(-3deg); transform-origin: 50% 0;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 calc(50% + 8px), 0 calc(50% - 8px));
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); transition: transform .3s; }
.tag::before { content: ""; position: absolute; left: 7px; top: calc(50% - 4px); width: 8px; height: 8px; border-radius: 50%; background: #1d2321; }
.tag-fees { font: 600 12px var(--f-display); color: var(--pen); }
.tag-claim { font: 700 15px var(--f-display); letter-spacing: .06em; }
.tag-claim s { text-decoration: none; }
.tag-claim s.struck { text-decoration: line-through 2px var(--pen); color: var(--ink-soft); }
.tag-claim em { font-style: normal; color: var(--pen); margin-left: 6px; font-family: var(--f-display); }
.tag-w { font: 11px var(--f-mono); color: var(--ink-soft); }
.tag-ask { font: 700 26px/1.1 var(--f-didone); font-variant-numeric: tabular-nums; margin-top: 2px; }
.tag-ask.struck { font-size: 16px; color: var(--ink-soft); text-decoration: line-through 2px var(--pen); }
.tag-pen { font: 700 26px/1.1 var(--f-didone); color: var(--pen); transform: rotate(-2deg); font-variant-numeric: tabular-nums; }
.tag-worth { font: 600 13px var(--f-display); color: var(--ink); border-top: 1px dashed var(--ink-soft); padding-top: 3px; margin-top: 2px; }
.tag.billed .tag-ask, .tag.billed .tag-pen { font-size: 15px; margin: 0; transform: none; }
.tag.billed .tag-worth { display: grid; font: 700 30px/1.05 var(--f-didone); font-variant-numeric: tabular-nums; padding-top: 5px; margin-top: 4px; justify-self: stretch; }
.tag-worth small { font: 600 11px var(--f-display); color: var(--ink-soft); letter-spacing: .1em; }
.tag-worth.up { color: #1f6b4c; } .tag-worth.down { color: var(--pen); }
.tag.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: rotate(-6deg) translateY(2px); } }

/* the seller talks from behind the tag */
.say { position: absolute; bottom: 40px; right: calc(16px + var(--tagw, 130px)); margin: 0; width: max-content; max-width: calc(100% - 32px - var(--tagw, 130px));
  font: 700 16px/1.35 var(--f-display); color: var(--ink); background: #f7f2e6; padding: 8px 12px; border-radius: 14px 14px 4px 14px;
  box-shadow: 0 6px 14px rgba(0,0,0,.3); animation: say .3s cubic-bezier(.2,1.6,.4,1); }
@keyframes say { from { transform: scale(.6) translateX(20px); opacity: 0; } }


/* what the tools found: chalk on the bench */
.chalk { position: absolute; left: 16px; right: 16px; top: 14px; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; justify-items: start; }
.chalk li { font: 700 15px/1.35 var(--f-display); color: #f4efe2; text-shadow: 0 1px 2px rgba(0,0,0,.8), 0 0 12px rgba(0,0,0,.5); opacity: .55; transition: opacity .3s; }
.chalk li:last-child { opacity: 1; }
.chalk li b { font: 500 11px var(--f-body); color: var(--jade); margin-right: 6px; letter-spacing: .1em; }
body[data-phase=cut] .chalk, body[data-phase=result] .chalk { opacity: 0; transition: opacity .3s; }

.taphint { position: absolute; left: 50%; bottom: 18%; transform: translateX(-50%); font: 700 15px var(--f-display); letter-spacing: .3em; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.8); animation: breathe 1.4s ease-in-out infinite; white-space: nowrap; }
@keyframes breathe { 50% { opacity: .45; } }

/* the verdict is stamped onto the scene */
.verdict { position: absolute; left: 0; right: 0; top: 44%; display: grid; justify-items: center; gap: 6px; }
.stamp { font: 900 30px/1 var(--f-display); letter-spacing: .1em; padding: 10px 14px 11px; border: 3px solid currentColor; outline: 1px solid currentColor; outline-offset: 3px;
  transform: rotate(-7deg); background: rgba(12,14,12,.35); animation: stamp .35s cubic-bezier(.2,1.8,.4,1); white-space: nowrap; mix-blend-mode: normal; }
.stamp.good { color: var(--jade); }
.stamp.bad { color: var(--red); }
@keyframes stamp { from { transform: rotate(-7deg) scale(2.4); opacity: 0; } }
.res-pct { font: 700 54px/1 var(--f-didone); -webkit-text-stroke: 5px rgba(10,12,10,.85); paint-order: stroke fill; text-shadow: 0 3px 16px rgba(0,0,0,.7); animation: rise .5s .25s backwards; }
.res-up { color: var(--jade); } .res-down { color: var(--red); }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.reveal { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); font: 900 clamp(17px, 4.6vw, 24px)/1 var(--f-display); letter-spacing: .1em;
  color: #f7f1e3; text-shadow: 0 1px 3px rgba(0,0,0,.9); white-space: nowrap; animation: rise .5s; }

/* the bench under the stone: controls, no boxes */
.tray { flex: none; padding: 6px 16px calc(12px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 4px; }
.tray > .row, .tray .deal > .row, .result .row { justify-content: space-between; }
.tool { flex-direction: column; gap: 1px; min-width: 58px; padding: 6px 8px; border-radius: 14px; color: var(--fg); }
.tool svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tool b { font: 700 13px var(--f-display); }
.tool i { font: 500 10px var(--f-mono); font-style: normal; color: var(--muted); line-height: 1.1; }
.tool[aria-pressed="true"] { background: rgba(124,195,156,.16); color: var(--jade); }
.tool[aria-pressed="true"] svg { filter: drop-shadow(0 0 6px rgba(124,195,156,.7)); }
#toolRow .go { margin-left: auto; }
.deal { display: grid; gap: 4px; }
.deal .row { gap: 0; }
.deal .go { margin-left: auto; }
#backBtn { font-size: 26px; font-weight: 400; padding-inline: 8px 12px; }
#counterRow .go { padding-inline: 30px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 40px; background: transparent; margin: 0; touch-action: pan-x; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: linear-gradient(90deg, var(--pen), var(--line)); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; border-radius: 50%; background: var(--paper); border: 0; margin-top: -13px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input[type=range]::-moz-range-track { height: 4px; background: var(--line); border-radius: 2px; }
input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: var(--paper); border: 0; }

.result { display: grid; gap: 6px; animation: rise .5s .4s backwards; }
.quip { margin: 0; font: 700 17px/1.4 var(--f-display); text-align: center; text-wrap: balance; }
.res-tag { margin: 0; text-align: center; font: 700 13px var(--f-display); color: var(--jade); letter-spacing: .1em; }
.res-crowd { margin: 0; text-align: center; font: 500 12px var(--f-body); color: var(--muted); letter-spacing: .02em; }
#retryRow .go { margin-inline: auto; }
.bind { display: flex; gap: 8px; }
.bind input { flex: 1; min-width: 0; min-height: 40px; padding: 0 10px; background: transparent; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 16px; }
.bind .go { padding-inline: 16px; }
.bind + .tip { margin-top: 6px; }
.login { display: grid; gap: 12px; }
.login p { margin: 0; }
.login .lead { font: 700 17px var(--f-display); overflow-wrap: anywhere; }
.ways { display: grid; gap: 8px; }
.ways button { background: #262a24; }
#outBtn { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); color: var(--muted); }

body[data-phase=cut] .tray { visibility: hidden; }
body[data-phase=deal] .tag { transform: rotate(-1deg); }
body[data-phase=cut] .tag, body[data-phase=result] .tag { transform: rotate(-2deg) scale(.86); }
#shareBtn { box-shadow: inset 0 0 0 1.5px var(--line); color: var(--fg); padding-inline: 22px; }

/* dialogs */
dialog { border: 0; padding: 0; background: transparent; color: var(--fg); max-width: min(520px, 100vw); width: 100%; margin: auto auto 0; }
dialog::backdrop { background: rgba(5,6,5,.72); }
.dlg { background: #1b1e1a; border-radius: 16px 16px 0 0; padding: 16px 18px calc(18px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 14px; max-height: 88dvh; overflow: auto; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head button { min-height: 36px; padding: 6px 10px; color: var(--muted); }
.dealbtns { display: flex; flex-wrap: wrap; gap: 8px; }
.dealbtns > * { flex: 1 1 auto; }
.dlg .dealbtns button:not(.primary), .dlg .dealbtns .btn:not(.primary) { background: #262a24; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #262a24; border-radius: 999px; padding: 4px; }
.seg button { min-height: 36px; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--fg); color: var(--bg); }
.cardwrap { display: grid; place-items: center; }
.cardwrap img { width: 100%; max-width: 340px; height: auto; display: block; box-shadow: 0 8px 20px rgba(0,0,0,.4); }
.tip { margin: 0; font-size: 12px; color: var(--muted); }
.help { display: grid; gap: 14px; font-size: 14px; }
.help p, .help ol { margin: 0; }
.help .lead { font: 700 17px var(--f-display); }
.howto { list-style: none; padding: 0; display: grid; gap: 10px; }
.howto li { display: grid; grid-template-columns: 2.2em 1fr; align-items: baseline; }
.howto b { font: 900 20px var(--f-display); color: var(--jade); }
.howto small { color: var(--muted); }
.rules { font-size: 13px; color: var(--muted); }
.stats { display: grid; gap: 14px; }
.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.statgrid b { display: block; font: 700 26px var(--f-display); }
.statgrid span { font-size: 12px; color: var(--muted); }
.hist { display: grid; gap: 4px; font-size: 13px; }
.hist div { display: grid; grid-template-columns: 3.2em 1fr; gap: 8px; align-items: center; }
.hist i { display: block; height: 12px; background: var(--jade-deep); min-width: 2px; border-radius: 2px; }

@media (prefers-reduced-motion: reduce) { .stamp, .res-pct, .reveal, .result, .say, .taphint, .tag.bump { animation: none; } }

/* 往期 list */
.days { display: grid; max-height: 46dvh; overflow-y: auto; border-top: 1px solid var(--line); }
.day { justify-content: space-between; border-radius: 0; border-bottom: 1px solid var(--line); padding: 10px 2px; min-height: 52px; font-weight: 500; }
.day span:first-child { font: 600 15px var(--f-mono); display: grid; text-align: left; line-height: 1.3; }
.day small { font: 400 12px var(--f-body); color: var(--muted); }
.day span:last-child { font: 700 15px var(--f-display); }
.day b { font: 700 16px var(--f-didone); margin-left: 4px; }
.day b.up { color: var(--jade); } .day b.down { color: var(--red); }
.day i { font: 400 13px var(--f-body); font-style: normal; color: var(--muted); }
