:root {
  --bg: #0f1220;
  --panel: rgba(27, 32, 51, 0.9);
  --text: #f2f4f8;
  --muted: #9aa3b8;
  --border: #323a55;
  --gold: #ffc94a;
  --green: #4fd18b;
  --red: #ef6b5b;
  --cell: 40px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; color: var(--text); overflow: hidden;
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { background: radial-gradient(120% 80% at 50% 0%, #1d2440 0%, var(--bg) 60%, #0b0d17 100%); }
body::before { content: ''; position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.4s;
  background: url(img/bg.webp) center / cover no-repeat; }
body.bg-ok::before { opacity: 0.22; }
#app { position: relative; z-index: 1; height: 100vh; height: 100dvh; max-width: 620px; margin: 0 auto;
  display: flex; flex-direction: column; padding: 10px 12px; gap: 6px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.logo { width: 34px; height: 34px; flex: none; }
.logo svg { width: 100%; height: 100%; display: block; }
.head { flex: 1; min-width: 0; }
.title { font-weight: 800; font-size: 18px; letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene:empty { display: none; }

.stats { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip { background: var(--panel); border: 1px solid var(--border); border-radius: 99px; padding: 4px 11px;
  font-size: 12.5px; color: #c9cfdc; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip b { color: #fff; }
.chip.best b { color: var(--gold); }
.msg { text-align: center; min-height: 20px; font-size: 14px; color: var(--muted); transition: color 0.2s; }
.msg.good { color: var(--green); font-weight: 700; }
.msg.bad { color: var(--red); font-weight: 600; }
.msg.info { color: #e8d48a; }

/* ---------- board ---------- */
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; }
.board { position: relative; }
.layer { position: absolute; inset: 0; }
#tiles { filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.55)); }
.tile { position: absolute; left: calc(var(--x) * var(--cell)); top: calc(var(--y) * var(--cell));
  width: var(--cell); height: var(--cell); }
.floor { background: #252c44; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.floor.alt { background: #29304a; }
.goal::after { content: ''; position: absolute; left: 50%; top: 50%; width: 34%; height: 34%; border-radius: 3px;
  transform: translate(-50%, -50%) rotate(45deg); border: max(2px, calc(var(--cell) * 0.06)) solid var(--gold);
  box-shadow: 0 0 10px rgba(255, 201, 74, 0.45), inset 0 0 6px rgba(255, 201, 74, 0.35); }
.wall { background: #505874 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' fill='%23505874'/%3E%3Cpath d='M0 1h40M0 21h40M1 0v20M21 0v20M11 20v20M31 20v20' stroke='%2333394f' stroke-width='2'/%3E%3Cpath d='M0 3.5h40M0 23.5h40' stroke='%23ffffff' stroke-opacity='.07' stroke-width='2'/%3E%3C/svg%3E") 0 0 / 100% 100%; }
.wall.cap { box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.13); }
.wall.base { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.28); }
.wall.cap.base { box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.13), inset 0 -4px 0 rgba(0, 0, 0, 0.28); }

/* ---------- pieces ---------- */
.piece { position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); will-change: transform;
  transform: translate(calc(var(--x) * var(--cell)), calc(var(--y) * var(--cell))); transition: transform 0.12s ease-out; }
.snap .piece { transition: none; }
.piece .in { width: 100%; height: 100%; }
.piece svg { width: 100%; height: 100%; display: block; overflow: visible; }

.crate, .logo { --fr: #a4602a; --pn: #d99549; --ln: #b8752f; --ed: #5a3212; }
.crate .in { padding: calc(var(--cell) * 0.04); }
.crate svg { filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)); transition: filter 0.2s; }
.crate svg * { transition: fill 0.2s, stroke 0.2s; }
.crate.on { --fr: #2b8a55; --pn: #5bcf8c; --ln: #43b575; --ed: #17492d; }
.crate.on svg { filter: drop-shadow(0 0 7px rgba(91, 207, 140, 0.6)); }
.crate.stuck { --fr: #94302e; --pn: #e4675a; --ln: #c84e43; --ed: #4f1513; }
.crate.stuck .in { animation: wobble 0.4s; }
.fr { fill: var(--fr); stroke: var(--ed); stroke-width: 4; }
.br { stroke-width: 3; }
.pn { fill: var(--pn); stroke: var(--ed); stroke-width: 3; }
.ln { stroke: var(--ln); stroke-width: 3; fill: none; }
.nl { fill: var(--ed); opacity: 0.7; }

.worker { z-index: 2; }
.worker .face { transition: transform 0.12s, opacity 0.12s; }
.worker.w-l .face { transform: translateX(-3px); }
.worker.w-r .face { transform: translateX(3px); }
.worker.w-u .face { opacity: 0; }
.worker.bump .in { animation: bump 0.16s ease-out; }

.won .crate .in { animation: pop 0.45s ease both; animation-delay: calc(var(--i) * 90ms); }
.won .worker .in { animation: hop 0.45s ease 2; }

/* ---------- footer ---------- */
.bar { display: flex; gap: 8px; }
.bar button { flex: 1; height: 40px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel);
  color: var(--text); font: 600 14px system-ui, sans-serif; cursor: pointer; touch-action: manipulation; }
.bar button:active:not(:disabled) { transform: translateY(1px); }
.bar button:disabled { opacity: 0.4; cursor: default; }
#reveal { background: rgba(58, 50, 32, 0.92); border-color: #6b5a2a; color: #ffe08a; }

@keyframes bump { 50% { transform: translate(calc(var(--bx) * 9%), calc(var(--by) * 9%)); } }
@keyframes wobble { 20%, 60% { transform: rotate(-6deg); } 40%, 80% { transform: rotate(6deg); } }
@keyframes pop { 40% { transform: scale(1.14); } }
@keyframes hop { 40% { transform: translateY(-14%); } }
