:root {
  --bg: #f6efe6; --ink: #2b1b12; --muted: #7a6656; --brown: #3b2418; --card: #fffaf3;
  --floor: #efe2d0; --wall: #6b4a35; --wall2: #573a29; --accent: #d9822b; --ok: #2f8f4e; --warn: #c77a12; --bad: #b3372b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body.game { overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
#app { height: 100%; max-width: 560px; margin: 0 auto; }
.screen { height: 100%; display: flex; flex-direction: column; padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); }
.screen[hidden] { display: none; }
.center { align-items: center; justify-content: center; text-align: center; gap: 8px; }
h1 { font-size: 26px; margin: 8px 0 4px; }
.big-ico { font-size: 64px; }
.small { color: var(--muted); font-size: 14px; }
.spinner { width: 40px; height: 40px; border: 4px solid #d8c7b3; border-top-color: var(--brown); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* гра */
#play, #loading { touch-action: none; }
.bar { display: flex; align-items: center; justify-content: space-between; }
.title { font-weight: 800; font-size: 20px; color: var(--brown); }
.dots { display: flex; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #dccbb6; }
.dot.cur { background: var(--accent); }
.dot.ok { background: var(--ok); }
.hint { margin: 6px 0; color: var(--muted); font-size: 14px; min-height: 40px; }
.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.board { position: relative; background: var(--floor); border-radius: 12px; box-shadow: 0 0 0 4px var(--wall2), 0 8px 24px rgba(59,36,24,.25); }
.cell { position: absolute; left: 0; top: 0; width: var(--c); height: var(--c); }
.cell.wall { background: var(--wall); border-radius: 6px; box-shadow: inset 0 -4px 0 var(--wall2); }
.cup, .sugar { position: absolute; left: 0; top: 0; width: var(--c); height: var(--c); }
.cup::before { content: ''; position: absolute; inset: 22% 18% 14% 14%; background: #fff; border: 3px solid var(--brown); border-radius: 4px 4px 40% 40%; }
.cup::after { content: ''; position: absolute; right: 6%; top: 34%; width: 18%; height: 28%; border: 3px solid var(--brown); border-left: 0; border-radius: 0 50% 50% 0; }
.cup.hit::before { background: #c58a55; transition: background .4s; }
/* попадання: чашка підстрибує й світиться, кубик тоне, поле блимає */
.cup.hit { z-index: 3; border-radius: 30%; animation: cupPop .7s ease-out; box-shadow: 0 0 0 3px var(--accent), 0 0 22px 8px rgba(217,130,43,.75); }
@keyframes cupPop { 0% { scale: 1; } 35% { scale: 1.35; } 65% { scale: .95; } 100% { scale: 1; } }
.sugar.sink::before { animation: sink .55s ease-in forwards; }
@keyframes sink { 30% { transform: translateY(-18%) scale(1.1); } 100% { transform: translateY(25%) scale(.15); opacity: 0; } }
.board.solved { animation: solved .9s ease-out; }
@keyframes solved { 30% { box-shadow: 0 0 0 4px var(--ok), 0 0 30px 6px rgba(47,143,78,.5); } }
.sugar { transition-property: transform; transition-timing-function: cubic-bezier(.3,.1,.3,1); z-index: 2; }
.sugar::before { content: ''; position: absolute; inset: 20%; background: #fff; border-radius: 6px; box-shadow: 0 3px 0 #d9cbb8, inset 0 0 0 2px #eee4d6; }
.bump-U::before { animation: bU .18s; } .bump-D::before { animation: bD .18s; } .bump-L::before { animation: bL .18s; } .bump-R::before { animation: bR .18s; }
@keyframes bU { 50% { transform: translateY(-4px); } } @keyframes bD { 50% { transform: translateY(4px); } }
@keyframes bL { 50% { transform: translateX(-4px); } } @keyframes bR { 50% { transform: translateX(4px); } }
.stats { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin: 10px 2px; }
.actions { display: flex; gap: 10px; }
.btn { flex: 1; min-height: 52px; border: 0; border-radius: 14px; font: inherit; font-weight: 700; font-size: 17px; background: var(--brown); color: #fff; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--brown); box-shadow: inset 0 0 0 2px #d8c7b3; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; }

/* виграш */
#win h1 { margin-top: 0; }
.gift { font-size: 18px; font-weight: 600; margin: 0; }
.code { font: 800 46px/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 6px; padding: 10px 18px; margin: 6px 0;
  background: var(--card); border-radius: 16px; box-shadow: 0 0 0 3px var(--accent); animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px var(--accent), 0 0 24px 4px rgba(217,130,43,.55); } }
.clock { font-variant-numeric: tabular-nums; font-size: 18px; color: var(--brown); }
.qr { flex: 0 0 auto; width: 150px; height: 150px; background: #fff; border-radius: 8px; }
.stale .code { box-shadow: 0 0 0 3px var(--bad); animation: none; text-decoration: line-through; }
.cup-anim { position: relative; width: 90px; height: 90px; }
.mug { position: absolute; bottom: 0; left: 15px; width: 56px; height: 46px; background: #fff; border: 4px solid var(--brown); border-radius: 6px 6px 22px 22px; }
.mug::after { content: ''; position: absolute; right: -18px; top: 8px; width: 14px; height: 20px; border: 4px solid var(--brown); border-left: 0; border-radius: 0 12px 12px 0; }
.steam { position: absolute; bottom: 50px; width: 8px; height: 26px; border-radius: 8px; background: #cdb9a3; opacity: 0; animation: steam 2.2s ease-in infinite; }
.s1 { left: 28px; } .s2 { left: 42px; animation-delay: .7s; } .s3 { left: 56px; animation-delay: 1.4s; }
@keyframes steam { 0% { transform: translateY(8px) scaleY(.6); opacity: 0; } 40% { opacity: .9; } 100% { transform: translateY(-22px) scaleY(1.2); opacity: 0; } }

/* офіціант */
body.staff { overflow-y: auto; }
.staff .screen { height: auto; min-height: 100%; gap: 12px; }
.panel { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: 0 2px 8px rgba(59,36,24,.08); }
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 16px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brown); }
.pin-dots span.on { background: var(--brown); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 320px; margin: 0 auto; }
.keypad button { min-height: 64px; font-size: 26px; font-weight: 700; border: 0; border-radius: 16px; background: var(--card); color: var(--ink); box-shadow: 0 2px 6px rgba(59,36,24,.12); }
.keypad button:active { background: #eadcc9; }
.err { color: var(--bad); min-height: 22px; font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat-grid b { display: block; font-size: 22px; }
.stat-grid span { font-size: 12px; color: var(--muted); }
.ticket-qr { width: min(80vw, 320px); height: min(80vw, 320px); margin: 0 auto; display: block; background: #fff; border-radius: 12px; }
.code-input { width: 100%; font: 800 32px ui-monospace, Menlo, monospace; letter-spacing: 6px; text-align: center; text-transform: uppercase;
  padding: 10px; border: 2px solid #d8c7b3; border-radius: 14px; background: #fff; color: var(--ink); }
.result { border-radius: 14px; padding: 14px; font-size: 20px; font-weight: 700; text-align: center; color: #fff; }
.result.ok { background: var(--ok); } .result.already { background: var(--warn); } .result.expired, .result.unknown { background: var(--bad); }
.journal { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.journal li { padding: 6px 0; border-bottom: 1px solid #eadcc9; display: flex; gap: 8px; }
.journal time { color: var(--muted); font-variant-numeric: tabular-nums; }
a.link { color: var(--brown); font-weight: 600; }
.landing p { max-width: 380px; }
.form3 { gap: 8px; }
.form3 label { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.form3 input { font: 600 20px/1 inherit; padding: 10px; border: 2px solid #d8c7b3; border-radius: 12px; width: 100%; background: #fff; color: var(--ink); }
.btn.mini { flex: 0 0 auto; min-height: 36px; font-size: 14px; padding: 0 12px; margin-left: auto; }
.tbl { font-size: 22px; font-weight: 800; }
.demo-badge { display: none; font-size: 12px; font-weight: 800; color: #fff; background: var(--bad); border-radius: 6px; padding: 2px 6px; vertical-align: middle; }
.demo .demo-badge { display: inline-block; }
.demo-badge.big { font-size: 18px; padding: 4px 12px; letter-spacing: 2px; }
.demo .code { box-shadow: 0 0 0 3px var(--bad); }
#again { flex: 0 0 auto; padding: 0 24px; margin-top: 8px; }
.choose { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; margin-top: 12px; }

/* горизонталь на телефоні: поле зліва на всю висоту, усе інше — колонкою справа */
@media (orientation: landscape) and (max-height: 540px) {
  body.game #app { max-width: none; }
  #play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(200px, 36%); column-gap: 16px; align-items: center;
    grid-template-rows: minmax(0, 1fr) repeat(5, auto) minmax(0, 1fr); padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  #play > .board-wrap { grid-column: 1; grid-row: 1 / -1; height: 100%; overflow: hidden; }
  #play > .bar { grid-column: 2; grid-row: 2; }
  #play > .row { grid-column: 2; grid-row: 3; flex-wrap: wrap; gap: 2px 10px; }
  #play > .hint { grid-column: 2; grid-row: 4; min-height: 0; }
  #play > .stats { grid-column: 2; grid-row: 5; flex-wrap: wrap; gap: 4px 10px; }
  #play > .actions { grid-column: 2; grid-row: 6; }
  .title { font-size: 18px; }
  #win { overflow-y: auto; justify-content: flex-start; }
}
/* екран коду не вміщається (низький екран) — прокрутка замість обрізання */
#win { overflow-y: auto; }

/* темна тема телефона — лише гра */
@media (prefers-color-scheme: dark) {
  body.game { --bg: #1b130e; --ink: #f2e6d8; --muted: #b8a391; --card: #2a1d15; }
  body.game .title, body.game .clock { color: #e9b98a; }
  body.game .btn.ghost { color: var(--ink); box-shadow: inset 0 0 0 2px #5b4637; }
  body.game .dot { background: #4a382c; }
  body.game .spinner { border-color: #4a382c; border-top-color: #e9b98a; }
  body.game .board { box-shadow: 0 0 0 4px var(--wall2), 0 8px 24px rgba(0,0,0,.5); }
  body.game .mug, body.game .mug::after { border-color: #e9b98a; }
}
