* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: #faf6ef; color: #4a3f35;
  min-height: 100vh; min-height: 100dvh;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.app { max-width: 440px; margin: 0 auto; padding: 10px 12px 18px; display: flex; flex-direction: column; gap: 10px; min-height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar h1 { font-size: 17px; margin: 0; }
.icon-btn { border: none; background: #efe5d6; color: #4a3f35; border-radius: 10px; padding: 8px 11px; font-size: 15px; cursor: pointer; }
.icon-btn:active { transform: scale(0.95); }
.btn { border: none; border-radius: 12px; padding: 12px 14px; font-size: 16px; font-weight: 700; cursor: pointer; background: #efe5d6; color: #4a3f35; }
.btn.primary { background: #ee7150; color: #fff; }
.btn.accent { background: #4b8bd0; color: #fff; }
.btn.small { padding: 8px 10px; font-size: 14px; }
.btn.on { background: #4a3f35; color: #fff; }
.btn:disabled { opacity: 0.45; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.stats { display: flex; gap: 6px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 70px; background: #efe5d6; border-radius: 10px; padding: 6px 8px; text-align: center; }
.stat b { display: block; font-size: 18px; }
.stat small { font-size: 11px; color: #85766a; }
.stat.warn { background: #ffd9cc; }

.orders { display: flex; gap: 6px; }
.order { flex: 1; border: 2px dashed #d9c9b3; border-radius: 12px; padding: 6px 4px; text-align: center; background: #fff; }
.order .ov { font-size: 22px; font-weight: 800; }
.order small { display: block; font-size: 11px; color: #85766a; }
.order.filled { border-style: solid; border-color: #8cc676; background: #eef8e8; }
.order.expiring small { color: #e14b3b; font-weight: 700; }

.banner { background: #4a3f35; color: #fff; border-radius: 12px; padding: 9px 12px; font-size: 14px; text-align: center; min-height: 38px; }
.banner.ship { background: #4b8bd0; }
.banner.danger { background: #e14b3b; }
.banner.discard { background: #8a5a44; }

.board { display: grid; gap: 6px; background: #d8c8b2; padding: 6px; border-radius: 14px; }
.cell { position: relative; aspect-ratio: 1 / 1; background: #eadcc8; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 800; cursor: pointer; font-size: 15px; }
.tile { position: absolute; inset: 0; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.tile.pop { animation: pop 0.22s ease-out; }
.tile.glow { box-shadow: 0 0 0 3px #fff, 0 0 12px 4px #4b8bd0; animation: glow 0.9s ease-in-out infinite alternate; }
.tile.dim { opacity: 0.35; }
.cell.vanish::after { content: ''; position: absolute; inset: 20%; border-radius: 50%; background: rgba(255,255,255,0.8); animation: vanish 0.25s ease-out forwards; }
.floating { position: absolute; left: 50%; top: 0; transform: translateX(-50%); font-size: 14px; font-weight: 800; color: #2e7d32; pointer-events: none; animation: floatup 0.8s ease-out forwards; white-space: nowrap; z-index: 5; }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes glow { from { transform: scale(1); } to { transform: scale(0.93); } }
@keyframes vanish { from { opacity: 1; transform: scale(0.5); } to { opacity: 0; transform: scale(1.4); } }
@keyframes floatup { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -30px; } }

.queue { display: flex; align-items: center; gap: 10px; justify-content: center; }
.queue .label { font-size: 12px; color: #85766a; }
.qtile { width: 56px; height: 56px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; }
.qtile.small { width: 40px; height: 40px; font-size: 15px; opacity: 0.8; }
.qtile.hidden { background: #e2d6c4; color: #a8998a; }

.overlay { position: fixed; inset: 0; background: rgba(40, 32, 26, 0.55); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.overlay.show { display: flex; }
.sheet { background: #fffaf2; border-radius: 16px; padding: 16px; width: 100%; max-width: 420px; max-height: 92dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0; font-size: 20px; }
.sheet h3 { margin: 10px 0 0; font-size: 14px; color: #85766a; }
.sheet .reason { font-size: 18px; font-weight: 800; color: #e14b3b; }
.sheet table { border-collapse: collapse; width: 100%; font-size: 15px; }
.sheet td { padding: 4px 0; }
.sheet td:last-child { text-align: right; font-weight: 700; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #efe5d6; }
.set-name { font-size: 14px; }
.set-name small { display: block; font-size: 11px; color: #9a8b7d; }
.set-row input[type=number], .set-row input[type=text], .set-row select { width: 110px; font-size: 16px; padding: 6px 8px; border: 1px solid #d9c9b3; border-radius: 8px; background: #fff; }
.set-row input[type=checkbox] { width: 24px; height: 24px; }
.note { font-size: 12px; color: #85766a; line-height: 1.5; }

/* B */
.bstage { position: relative; }
.bboard { display: grid; gap: 5px; background: #d8c8b2; padding: 6px; border-radius: 14px; position: relative; }
.bcol { display: flex; flex-direction: column-reverse; gap: 5px; border-radius: 9px; cursor: pointer; }
.bcol .cell { cursor: pointer; }
.bcol.hover .cell { background: #e2d2bb; }
.bcol .cell.top { box-shadow: inset 0 3px 0 #e14b3b55; }
.bcol .cell.wall { background: repeating-linear-gradient(45deg, #9c8a76 0 5px, #8b7864 5px 10px); cursor: default; }
.bcol.hover .cell.wall { background: repeating-linear-gradient(45deg, #9c8a76 0 5px, #8b7864 5px 10px); }
.shape-name { font-size: 12px; color: #7a6a5a; text-align: center; min-height: 16px; margin-bottom: 4px; }
.dropper { display: grid; gap: 5px; padding: 0 6px; }
.dropper .slot { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; }
.timerbar { height: 8px; border-radius: 4px; background: #e2d6c4; overflow: hidden; }
.timerbar > div { height: 100%; background: #ee7150; width: 100%; }
.toast { position: fixed; left: 50%; top: 32%; transform: translateX(-50%); background: #4a3f35; color: #fff; padding: 14px 20px; border-radius: 14px; font-size: 20px; font-weight: 800; z-index: 40; pointer-events: none; opacity: 0; transition: opacity 0.2s; text-align: center; }
.toast.show { opacity: 0.95; }

/* 시작 화면 */
.hero { text-align: center; padding: 18px 0 4px; }
.hero h1 { font-size: 24px; margin: 0 0 6px; }
.hero p { margin: 0; color: #85766a; font-size: 14px; }
.card { display: block; text-decoration: none; color: inherit; background: #fff; border-radius: 16px; padding: 16px; box-shadow: 0 2px 0 #e7dccb; }
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card p { margin: 0; font-size: 14px; color: #6b5d50; line-height: 1.5; }
.card .go { display: inline-block; margin-top: 10px; background: #ee7150; color: #fff; padding: 8px 14px; border-radius: 10px; font-weight: 700; }
.card.b .go { background: #4b8bd0; }
.records { font-size: 13px; }
.records .rec { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid #efe5d6; }
.records .rec span:last-child { color: #85766a; text-align: right; }

/* B v2: 주문 목록 + 컨베이어 */
.orders-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.orders-title small { font-weight: 400; color: #85766a; font-size: 11px; }
.order.fresh { animation: pop 0.35s ease-out; border-style: solid; border-color: #4b8bd0; }
.order.hit { border-style: solid; border-color: #8cc676; background: #eef8e8; }
.tile.can-ship { box-shadow: 0 0 0 3px #4b8bd0, 0 0 10px 2px #4b8bd088; animation: glow 1.6s ease-in-out infinite; cursor: pointer; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px #4b8bd0, 0 0 3px 0 #4b8bd044; } }
.dropper .slot { cursor: pointer; }
.pbar { height: 6px; margin: 4px 6px 0; border-radius: 3px; background: #efe5d6; overflow: hidden; }
.pfill { height: 100%; background: #8cc676; border-radius: 3px; transition: width 0.4s ease, background 0.4s; }
.pfill.mid { background: #e8c35a; }
.pfill.low { background: #ee9a6a; }
.tile.shipping { animation: shipout 0.3s ease-in forwards; }
@keyframes shipout { to { transform: translateY(60%) scale(0.6); opacity: 0; } }
.belt { margin-top: 4px; height: 26px; border-radius: 8px; overflow: hidden; position: relative;
  background: repeating-linear-gradient(90deg, #6b5d50 0 14px, #857566 14px 28px); background-size: 28px 100%;
  animation: belt 0.8s linear infinite; display: flex; align-items: center; justify-content: center; }
.belt span { background: rgba(255,255,255,0.9); border-radius: 6px; padding: 1px 8px; font-size: 12px; font-weight: 700; color: #4a3f35; }
.belt.flash span { background: #8cc676; color: #fff; }
@keyframes belt { from { background-position: 0 0; } to { background-position: 28px 0; } }
.order.big { border-style: solid; border-color: #ee7150; background: #fff1ea; }

/* B v6: 떨어질 자리 세로선 + 돌 상자 */
#board, #dropper { touch-action: none; -webkit-user-select: none; user-select: none; }
.aim-line { position: absolute; width: 0; border-left: 3px dashed rgba(75, 139, 208, 0.75); transform: translateX(-1.5px); pointer-events: none; z-index: 5; }
.aim-line::after { content: ''; position: absolute; bottom: -3px; left: -7.5px; width: 12px; height: 3px; border-radius: 2px; background: rgba(75, 139, 208, 0.9); }
.aim-line.full { border-left-color: rgba(225, 75, 59, 0.7); }
.aim-line.full::after { background: rgba(225, 75, 59, 0.9); }
/* v8: 저절로 내려오는 상자, 월세, 일시정지 */
.tile.falling { position: absolute; inset: auto; left: 0; top: 0; z-index: 6; pointer-events: none; transform-origin: 50% 100%; will-change: transform; box-shadow: 0 3px 6px rgba(90, 70, 50, 0.22); }
.tile.land { transform-origin: 50% 100%; animation: land 0.2s ease-out; }
@keyframes land { 0% { transform: scale(1.1, 0.84); } 55% { transform: scale(0.97, 1.04); } 100% { transform: scale(1, 1); } }
.order .oc { font-weight: 700; color: #a07a2a; }
.shape-name .minor { color: #a8998a; }
.belt.bad span { background: #ee9a6a; color: #fff; }
.stat small span { font-weight: 700; }
.paused { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 4px; background: rgba(250, 244, 236, 0.82); border-radius: 14px; z-index: 8; cursor: pointer; }
.paused.show { display: flex; }
.paused b { font-size: 22px; }
.paused small { color: #85766a; }

/* v9: 폰 한 화면에 벨트까지 들어오게 (B 전용) */
body.bpage { overscroll-behavior-y: none; }
.bpage .app { gap: 6px; padding-top: 6px; padding-bottom: 10px; }
.bpage .topbar h1 { font-size: 15px; }
.bpage .topbar .icon-btn { padding: 6px 9px; font-size: 14px; }
.bpage .stat { padding: 4px 6px; }
.bpage .stat b { font-size: 16px; }
.bpage .stat small { font-size: 10px; }
.bpage .orders-title { margin-bottom: 3px; font-size: 12px; }
.bpage .order { padding: 4px 3px; display: grid; grid-template-columns: 1fr 1fr; align-items: center; }
.bpage .order .ov { grid-column: 1 / -1; font-size: 20px; line-height: 1.15; }
.bpage .order .pbar { grid-column: 1 / -1; margin: 2px 5px 2px; }
.bpage .order small { font-size: 10px; }
.bpage .bstage { width: 100%; margin: 0 auto; }
.bpage .shape-name { margin-bottom: 2px; }
.bpage .belt { height: 24px; }
@media (max-height: 700px) {
  .bpage .orders-title small { display: none; }
  .bpage .stat small { font-size: 9px; }
}
.bpage .stat { min-width: 0; }
.bpage .stat small { white-space: nowrap; }
.bpage .order .pbar { grid-row: 2; }
.bpage .order .oc { grid-row: 3; grid-column: 1; }
.bpage .order small:last-child { grid-row: 3; grid-column: 2; }
.bpage .order .oc:last-child { grid-column: 1 / -1; }
.bpage .shape-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
