:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #1b2421; --muted: #5f6b67; --line: #d9e0dd;
  --brand: #1d4f43; --brand-ink: #ffffff; --accent: #2f9e6f; --warn-bg: #fff6e0; --warn: #8a5a00; --err: #b3261e;
  --chip: #eef3f1; --handle: #21c07a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111715; --card: #1a2220; --ink: #e7eeeb; --muted: #9aa8a3; --line: #2c3834;
          --brand: #2f7d69; --chip: #22302c; --warn-bg: #2d2615; --warn: #f1c46b; --err: #ff8a80; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; min-height: 100vh;
       padding-bottom: env(safe-area-inset-bottom); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
       padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--brand); color: var(--brand-ink); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 19px; }
.brand img { border-radius: 6px; }
.who { font-size: 14px; opacity: .9; }
main { max-width: 560px; margin: 0 auto; padding: 16px; }
h1 { font-size: 24px; margin: 8px 0 12px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
p { margin: 8px 0; }
.hint { color: var(--muted); font-size: 15px; }
.muted { color: var(--muted); }
.err { color: var(--err); font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 14px;
       border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font: inherit; font-weight: 600;
       cursor: pointer; flex: 1; touch-action: manipulation; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.big { width: 100%; min-height: 56px; margin-top: 14px; font-size: 18px; }
.btn.huge { width: 100%; min-height: 120px; flex-direction: column; font-size: 22px; border-radius: 18px; }
.btn.huge .ico { font-size: 40px; line-height: 1; }
.btn.link { width: 100%; background: none; border: none; color: var(--accent); margin-top: 6px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; margin-top: 10px; }
.two { display: flex; gap: 10px; }
.two .field { flex: 1; min-width: 0; }

.field { display: block; margin-top: 12px; font-size: 15px; color: var(--muted); }
.field input, .field textarea { display: block; width: 100%; margin-top: 6px; padding: 12px; font: inherit; color: var(--ink);
       background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
#joinCode { font-size: 24px; letter-spacing: 3px; text-align: center; direction: ltr; text-transform: uppercase; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 14px; }
.card.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.card.read { margin-top: 0; }
.card.read.ok { border-color: var(--accent); }
.card.read .big { font-size: 18px; font-weight: 700; }
.card.read input { display: block; width: 100%; margin-top: 8px; padding: 10px 12px; font: inherit; color: var(--ink);
                   background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.list .l1 { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); }
.list .l2 { margin-top: 4px; font-weight: 600; }
.list .l3 { font-size: 14px; color: var(--muted); margin-top: 2px; }
.list .ok { color: var(--accent); }

.steps { padding-inline-start: 22px; }
.steps li { margin: 8px 0; }
.code-box { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
            padding: 10px 12px; margin-top: 10px; }
.code-box span { flex: 3; font-size: 26px; letter-spacing: 3px; direction: ltr; text-align: center; font-weight: 700; }

.stage { position: relative; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; margin-top: 6px;
         background: #000; border-radius: 10px; overflow: hidden; }
.stage canvas { display: block; width: 100%; height: auto; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage .quad { fill: rgba(33, 192, 122, .16); stroke: var(--handle); stroke-width: 2.5; }
.stage .hdl { fill: rgba(255, 255, 255, .25); stroke: var(--handle); stroke-width: 3; }
.stage .hdl.on { fill: rgba(33, 192, 122, .55); }

.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 42px; border: 0; border-radius: 9px; background: none; color: var(--ink); font: inherit; font-weight: 600; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.preview { margin-top: 10px; background: var(--chip); border-radius: 10px; padding: 8px; text-align: center; }
.preview canvas { max-width: 100%; max-height: 55vh; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; }
.thumbs button { flex: 0 0 auto; position: relative; padding: 0; border: 2px solid transparent; border-radius: 8px; background: none; }
.thumbs button.on { border-color: var(--accent); }
.thumbs canvas { display: block; height: 76px; width: auto; border-radius: 6px; }
.thumbs .n { position: absolute; bottom: 2px; inset-inline-start: 4px; font-size: 12px; background: rgba(0, 0, 0, .6); color: #fff;
             border-radius: 6px; padding: 0 5px; }

.pay-main { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.pay-main button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 92px;
                   padding: 8px 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink);
                   font: inherit; font-size: 15px; font-weight: 600; line-height: 1.25; }
.pay-main button .ico { font-size: 28px; line-height: 1; }
.pay-main button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chips button.more { border-style: dashed; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 22px; background: var(--card);
                color: var(--ink); font: inherit; font-size: 16px; }
.chips button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chips.small { margin-top: 6px; }
.chips.small button { min-height: 40px; font-size: 15px; }
.pay-more { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px 10px; margin-top: 12px; }
#cardOther { margin-top: 8px; direction: ltr; text-align: center; }
#amount, #cheque { direction: ltr; text-align: right; }

.done-ico { width: 88px; height: 88px; margin: 24px auto 4px; border-radius: 50%; background: var(--accent); color: #fff;
            font-size: 52px; display: flex; align-items: center; justify-content: center; }
.done-ico.later { background: #c98a00; }
#vDone { text-align: center; }

.busy { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: flex; flex-direction: column; align-items: center;
        justify-content: center; gap: 14px; color: #fff; font-weight: 600; }
.spin { width: 46px; height: 46px; border: 5px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%;
        animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 30; left: 16px; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); max-width: 528px;
         margin: 0 auto; padding: 12px 14px; border-radius: 12px; background: #263330; color: #fff; text-align: center;
         opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
