:root {
  --chili: #d62d20;
  --chili-dark: #a81d13;
  --cream: #fff4df;
  --cream-2: #ffe9c2;
  --ink: #3b1511;
  --gold: #ffc231;
  --green: #1f9d55;
  --card: #fffaf0;
  --shadow: 0 4px 0 rgba(59, 21, 17, 0.18);
  --r: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: 'Mitr', 'Kanit', system-ui, sans-serif;
  background: var(--cream);
  background-image: radial-gradient(circle at 20px 20px, rgba(214, 45, 32, 0.07) 3px, transparent 4px);
  background-size: 40px 40px;
  color: var(--ink);
  line-height: 1.4;
  min-height: 100vh;
}
.wrap { max-width: 480px; margin: 0 auto; padding: 12px 12px 90px; }
.wrap.wide { max-width: 860px; }
.top { text-align: center; padding: 8px 0 4px; }
.brand { display: inline-flex; gap: 6px; align-items: center; background: var(--chili); color: #fff; padding: 6px 16px; border-radius: 99px; font-size: 1.05rem; box-shadow: var(--shadow); }
h1, h2, h3 { margin: 0; font-weight: 500; }
.card { background: var(--card); border: 3px solid var(--ink); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); margin: 12px 0; }
.btn {
  font: inherit; font-size: 1.1rem; color: #fff; background: var(--chili); border: 3px solid var(--ink);
  border-radius: 14px; padding: 12px 18px; box-shadow: 0 5px 0 var(--ink); cursor: pointer; min-height: 48px;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: var(--cream-2); color: var(--ink); }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.block { display: block; width: 100%; }
input, select { font: inherit; font-size: 1rem; padding: 10px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); width: 100%; min-height: 44px; }
label { display: block; font-size: 0.9rem; margin: 10px 0 4px; }
.muted { opacity: 0.7; font-size: 0.85rem; }
.err { color: var(--chili-dark); font-size: 0.95rem; min-height: 1.4em; }
.hidden { display: none !important; }

/* ---------- play: scene layout ---------- */
html.playing, html.playing body { overflow: hidden; overscroll-behavior: none; height: 100%; }
#game { position: fixed; inset: 0; display: flex; flex-direction: column; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; background: #f4f1ea; z-index: 5; }
.hud { flex: 0 0 auto; height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; padding-top: env(safe-area-inset-top); font-size: 0.95rem; background: var(--cream); border-bottom: 2px solid var(--ink); box-sizing: content-box; }
.hud b { color: var(--chili); font-size: 1.05rem; font-variant-numeric: tabular-nums; }
#scene { flex: 1 1 0; min-height: 0; position: relative; display: flex; flex-direction: column; overflow: hidden; }
.cabinet { flex: 0 0 62%; display: flex; flex-direction: column; min-height: 0; background: #e9ecee; border-bottom: 4px solid #aeb7bd; }
.shelf { flex: 1; min-height: 0; display: flex; flex-direction: column; background: linear-gradient(#f7f9fa, #e3e8eb); }
.tier { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 6px; padding: 0 8px; border-bottom: 3px solid #b9c2c8; box-shadow: 0 2px 4px rgba(0,0,0,.08); }
.basket { position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-width: 0; cursor: grab; padding-bottom: 4px; }
.basket:active { cursor: grabbing; }
.pile { position: relative; flex: 1; min-height: 0; pointer-events: none; }
.pile .food { display: block; width: 30px; height: 30px; filter: drop-shadow(0 2px 1px rgba(0,0,0,.2)); }
.bin { position: relative; height: 30px; border-radius: 3px 3px 9px 9px; background: linear-gradient(#e6ebee, #aab4bb); border: 2px solid #8b969d; box-shadow: 0 3px 4px rgba(0,0,0,.18); pointer-events: none; }
.bin .tag { position: absolute; left: 5%; right: 5%; top: 4px; bottom: 3px; background: #fff; border-radius: 3px; text-align: center; font-size: 0.62rem; line-height: 1.1; display: flex; flex-direction: column; justify-content: center; overflow: hidden; white-space: nowrap; }
.bin .tag small { opacity: .65; font-size: 0.58rem; }
.counter-top { flex: 1; min-height: 0; position: relative; padding: 0 10px 8px; background: linear-gradient(#fff, #f0ede6); }
.cz { position: absolute; left: 10px; right: 10px; bottom: 8px; display: grid; grid-template-columns: 55fr 36fr; column-gap: 10px; align-items: end; transition: transform .5s ease; }
.cz.zoom { transform: scale(1.25); transform-origin: 82% 100%; }
.hint { position: absolute; left: 12px; top: 8px; font-size: 0.78rem; background: var(--gold); border: 2px solid var(--ink); border-radius: 99px; padding: 1px 10px; animation: nudge 1.2s ease-in-out infinite; pointer-events: none; z-index: 7; }
@keyframes nudge { 50% { transform: translateX(5px); } }
/* art: bowl (wide translucent mixing bowl; swap the look here) */
.bowl { position: relative; min-width: 0; width: 100%; aspect-ratio: 1.5; max-height: 100%; z-index: 6; will-change: transform; }
.rim { position: absolute; left: 0; right: 0; top: 0; height: 18px; border-radius: 50%; background: linear-gradient(rgba(255,255,255,.95), rgba(255,175,190,.8)); border: 2px solid rgba(190,50,70,.6); cursor: grab; z-index: 3; box-shadow: 0 2px 3px rgba(190,50,70,.2); }
.rim .h { display: none; }
.bbody { position: absolute; left: 2%; right: 2%; top: 9px; bottom: 0; border: 2px solid rgba(190,50,70,.55); border-top: 0; border-radius: 0 0 50% 50% / 0 0 78% 78%; background: linear-gradient(105deg, rgba(255,255,255,.4), rgba(255,120,150,.26) 40%, rgba(255,90,120,.36)); overflow: hidden; box-shadow: inset 0 -12px 16px rgba(190,50,70,.2), inset 8px 0 10px rgba(255,255,255,.35); }
.bowl.over-bowl .bbody { box-shadow: 0 0 0 4px var(--gold), inset 0 -12px 16px rgba(190,50,70,.2); }
.bowl.bump .bbody { animation: bump .25s; }
@keyframes bump { 40% { transform: scale(1.04, .95); } }
.bpieces { position: absolute; inset: 0; }
.bpieces .piece { position: absolute; width: 28px; height: 28px; padding: 0; cursor: grab; transform: translate(-50%, -50%) rotate(var(--rot)); }
.bpieces .piece .food { width: 100%; height: 100%; display: block; pointer-events: none; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.bpieces .piece::after { content: ''; position: absolute; inset: -6px; }
.bbody .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 0.8rem; opacity: .5; pointer-events: none; }
/* art: scale */
.scale-unit { position: relative; min-width: 0; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; z-index: 4; }
.lcd { width: 86%; margin: 0 auto; text-align: center; font-size: 1.15rem; font-variant-numeric: tabular-nums; background: #1f3a22; color: #8cff96; border: 3px solid #cfd6da; border-radius: 8px; padding: 2px 4px; text-shadow: 0 0 6px rgba(140,255,150,.6); white-space: nowrap; }
.plate { width: 100%; height: 22px; margin-top: 4px; border-radius: 50%; background: linear-gradient(#f4f6f7, #b8c1c7); border: 2px solid #8b969d; }
.sbase { width: 100%; height: 38px; display: flex; align-items: center; margin-top: -6px; border-radius: 8px 8px 12px 12px; background: linear-gradient(#fff, #d5dbdf); border: 2px solid #aab4bb; box-shadow: 0 4px 6px rgba(0,0,0,.15); }
.sglow { position: absolute; inset: -6px -6px -4px; border-radius: 16px; display: flex; align-items: flex-start; justify-content: center; font-size: 0.75rem; color: #1f6b34; padding-top: 2px; opacity: 0; box-shadow: 0 0 0 4px var(--green), 0 0 18px 6px rgba(31,157,85,.6); background: rgba(31,157,85,.12); pointer-events: none; transition: opacity .12s; }
.scale-unit.over .sglow { opacity: 1; }
.scale-unit.reading .lcd { box-shadow: 0 0 14px 3px rgba(140,255,150,.55); }
.sign { flex: 0 0 auto; height: 28px; background: var(--chili); color: #fff; text-align: center; line-height: 28px; font-size: 0.95rem; border-bottom: 3px solid var(--chili-dark); letter-spacing: .5px; }
.toast { position: absolute; left: 50%; top: 46%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 99px; font-size: 0.95rem; z-index: 40; pointer-events: none; white-space: nowrap; }
.intro { position: absolute; left: 12px; right: 12px; top: calc(62% + 6px); z-index: 30; background: var(--card); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 40px 8px 12px; font-size: 0.85rem; box-shadow: var(--shadow); }
.intro.hidden { display: none; }
.intro button { position: absolute; top: 2px; right: 2px; width: 40px; height: 40px; border: 0; background: none; font-size: 1.1rem; color: var(--ink); cursor: pointer; }
.tongs { position: fixed; left: 0; top: 0; width: 60px; height: 130px; transform-origin: 30px 13px; pointer-events: none; z-index: 50; will-change: transform; }
.tin { position: relative; width: 60px; height: 130px; }
.tin.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px) rotate(-6deg); } 40%, 80% { transform: translateX(8px) rotate(6deg); } }
.arm { transform-origin: 30px 13px; transform: rotate(var(--a, 0deg)); transition: transform .1s; }
.armL { --a: 11deg; } .armR { --a: -11deg; }
.tongs.closed .armL { --a: 1.5deg; } .tongs.closed .armR { --a: -1.5deg; }
.held { position: absolute; left: 30px; top: 112px; width: 34px; height: 34px; transform: translate(-50%, -50%); transform-origin: 50% 0; display: none; }
.held .food { width: 100%; height: 100%; display: block; }
.tongs.hasheld .held { display: block; }
.flyer { position: fixed; left: 0; top: 0; width: 30px; height: 30px; z-index: 45; pointer-events: none; will-change: transform; }
.flyer .food { width: 100%; height: 100%; display: block; }

/* reveal */
.result { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; background: var(--cream); border-top: 3px solid var(--ink); border-radius: 22px 22px 0 0; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); z-index: 60; transform: translateY(105%); transition: transform .55s cubic-bezier(.2,.9,.3,1); box-shadow: 0 -6px 18px rgba(59,21,17,.25); }
.result.open { transform: none; }
.result .grab { width: 44px; height: 5px; border-radius: 3px; background: rgba(59,21,17,.25); margin: 0 auto 8px; }
.stagger { opacity: 0; transform: translateY(14px); transition: opacity 0.4s, transform 0.4s; }
.stagger.show { opacity: 1; transform: none; }
.confetti { position: fixed; top: -30px; z-index: 70; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
.errbox { text-align: center; padding: 30px 10px; }
.errbox .em { font-size: 4rem; }

/* ---------- shop / admin ---------- */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.receipt { width: 58mm; max-width: 100%; margin: 12px auto; background: #fff; border: 1px dashed #555; padding: 4mm 3mm; text-align: center; font-size: 12px; color: #000; font-family: 'Mitr', sans-serif; }
.receipt svg { width: 100%; height: auto; display: block; }
.receipt .t1 { font-size: 15px; font-weight: 600; }
.receipt .kv { display: flex; justify-content: space-between; margin: 2px 0; }
table.t { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.t th { text-align: left; font-weight: 500; padding: 2px 3px; font-size: 0.75rem; }
table.t td { padding: 2px 2px; }
table.t input { padding: 6px 6px; min-height: 36px; font-size: 0.9rem; }
.scroll { overflow-x: auto; }
pre.sim { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 10px; overflow-x: auto; font-size: 0.8rem; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 1.4rem; }
.ok { color: var(--green); }

@media print {
  body { background: #fff !important; }
  body.printing .wrap > :not(#receiptArea), body.printing .top { display: none !important; }
  body.printing #receiptArea { margin: 0; }
  body.printing #receiptArea > :not(.receipt) { display: none !important; }
  body.printing .receipt { border: 0; margin: 0; width: 58mm; }
  @page { margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}

.shelf[data-cols="4"] { --cols: 4; } .shelf[data-cols="5"] { --cols: 5; }
.shelf[data-cols="4"] .tier, .shelf[data-cols="5"] .tier { gap: 4px; padding: 0 5px; }
.shelf[data-cols="4"] .pile .food, .shelf[data-cols="5"] .pile .food { width: 24px; height: 24px; }
.shelf[data-cols="4"] .bin .tag, .shelf[data-cols="5"] .bin .tag { font-size: 0.5rem; } .shelf[data-cols="4"] .bin .tag small, .shelf[data-cols="5"] .bin .tag small { font-size: 0.48rem; }

.chip { font: inherit; font-size: 0.8rem; background: var(--gold); color: var(--ink); border: 2px solid var(--ink); border-radius: 99px; padding: 1px 12px; min-height: 28px; cursor: pointer; }
.prizes { position: absolute; left: 10px; right: 10px; top: calc(40px + env(safe-area-inset-top)); z-index: 80; background: #fffaf0; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px 10px; box-shadow: var(--shadow); font-size: 0.82rem; }
.prizes .ph { display: flex; justify-content: space-between; align-items: center; font-size: 0.95rem; }
.prizes .ph button { border: 0; background: none; font-size: 1.1rem; width: 40px; height: 36px; margin: -6px -10px -6px 0; color: var(--ink); cursor: pointer; }
.prizes ul { list-style: none; margin: 4px 0 6px; padding: 0; }
.prizes li { padding: 4px 0; border-bottom: 1px dotted rgba(59,21,17,.3); line-height: 1.3; }
.prizes li.out { opacity: .55; text-decoration: line-through; }
.prizes li.out em { text-decoration: none; display: inline-block; }
.prizes li em { font-style: normal; color: var(--chili-dark); }

/* ---------- timer chip ---------- */
.timer { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-weight: 700; font-size: 0.95rem; font-variant-numeric: tabular-nums; background: #fff; border: 2px solid var(--ink); border-radius: 99px; padding: 0 10px; line-height: 24px; min-width: 76px; text-align: center; }
.timer.run { background: var(--gold); }
.timer.low { background: var(--chili); color: #fff; animation: tpulse .8s ease-in-out infinite; }
@keyframes tpulse { 50% { transform: scale(1.12); } }

/* ---------- result = thermal receipt slip ---------- */
.result { --paper: #fbf9f1; background: #e7dfd0; }
.slip { position: relative; background: var(--paper); color: #2b2622; padding: 14px 14px 18px; margin: 4px 2px 22px; box-shadow: 0 3px 8px rgba(59,21,17,.22); font-size: 0.9rem; line-height: 1.35; }
.slip::after { content: ''; position: absolute; left: 0; right: 0; bottom: -9px; height: 9px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpolygon points='0,0 14,0 7,9' fill='%23fbf9f1'/%3E%3C/svg%3E") repeat-x; filter: drop-shadow(0 2px 1px rgba(59,21,17,.12)); }
.slip.pop { animation: slipin .55s cubic-bezier(.3,1.3,.5,1); }
@keyframes slipin { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.slip .sh { text-align: center; }
.slip .s1 { font-size: 1.1rem; font-weight: 500; letter-spacing: .5px; }
.slip .s2 { font-size: 1rem; }
.slip .s3, .slip .items .ct, .slip .kv b, .slip .code, .slip .wts, .slip .sm { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'Courier New', monospace; font-variant-numeric: tabular-nums; }
.slip .s3 { font-size: .78rem; opacity: .75; margin-top: 2px; }
.slip .dv { border-top: 2px dashed #9b9384; margin: 10px 0; }
.slip .ln { width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: baseline; padding: 6px 2px; margin: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; min-height: 34px; border-bottom: 1px dotted rgba(43,38,34,.25); }
.slip .ln .nm { min-width: 0; overflow-wrap: anywhere; }
.slip .ln .ct { opacity: .75; }
.slip .ln .sm { min-width: 64px; text-align: right; font-weight: 700; }
.slip .ln::before { content: none; }
.slip .itm.open .ln .nm::before { content: '▾ '; }
.slip .itm:not(.open) .ln .nm::before { content: '▸ '; opacity: .6; }
.slip .wts { display: flex; flex-wrap: wrap; gap: 4px 6px; padding: 6px 4px 8px 16px; font-size: .78rem; background: rgba(43,38,34,.04); }
.slip .wts[hidden] { display: none; }
.slip .wts span { border: 1px solid rgba(43,38,34,.25); padding: 0 5px; border-radius: 3px; }
.slip .hintline { text-align: center; font-size: .72rem; opacity: .55; margin-top: 4px; }
.slip .kv { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; padding: 1px 0; }
.slip .kv.big { font-size: 1.05rem; }
.slip .kv.big b { font-size: 1.7rem; color: var(--chili-dark); }
.slip .kv.bad, .slip .kv.bad b { color: var(--chili); }
.slip .stars { text-align: center; font-size: 2rem; letter-spacing: 6px; line-height: 1.1; }
.slip .stars i { font-style: normal; color: #c9c3b5; }
.slip .stars i.on { color: #f0a30a; text-shadow: 0 1px 0 rgba(59,21,17,.25); }
.slip .note { margin: 8px 0; padding: 6px 8px; border: 1px dashed var(--chili-dark); font-size: .84rem; }
.slip .note.out { text-align: center; color: var(--chili); }
.slip .prize { text-align: center; padding: 6px 0 2px; }
.slip .prize .pb { font-size: 1.7rem; line-height: 1.15; margin: 2px 0 8px; }
.slip .prize.tlast .pb { font-size: 1.4rem; }
.slip.t0 .prize .pb { color: #b86a00; }
.slip .cqr { width: min(190px, 60%); margin: 0 auto 6px; }
.slip .cqr svg { display: block; width: 100%; height: auto; }
.slip .code { font-size: 1.45rem; letter-spacing: 1px; font-weight: 700; word-break: break-all; }
.slip .cap { text-align: center; font-size: .85rem; margin-top: 6px; }
.slip .fun { background: #fff4c9; border: 1px solid #e3c868; padding: 8px 10px; text-align: center; border-radius: 4px; }
.slip .fun .fh { font-size: .75rem; opacity: .7; }
.slip .btn { margin-top: 12px; }
.hud { gap: 6px; }
.hud .billtxt { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.82rem; }
.hud .billtxt b { font-size: 0.92rem; }
.hud .timer, .hud .chip { flex: none; white-space: nowrap; }
