/* 《小白貓下班大作戰》— 像素風外框。只用硬邊、無圓角、無模糊、無漸層。 */
:root {
  --ink: #29313D;
  --navy: #3D4A5A;
  --slate: #657383;
  --dusk: #78809B;
  --lift: #D3AB6A;
  --lift-l: #E3C98E;
  --lift-d: #B28758;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* 用 dvh 避免手機網址列伸縮造成破版 */
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

.stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas,
.pixel-art {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: -moz-crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
}

#game {
  display: block;
  background: var(--ink);
  touch-action: none;
  cursor: pointer;
}

/* 高解析文字層：疊在遊戲畫布上，不接收點擊 */
#hdtext {
  position: fixed;
  pointer-events: none;
  z-index: 1;
}

/* ── 手機觸控按鈕 ───────────────────────────── */
.touch-pad {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: none;
  gap: 10px;
  z-index: 2;
  touch-action: none;
}
.touch-pad--left { left: max(12px, env(safe-area-inset-left)); }
.touch-pad--right { right: max(12px, env(safe-area-inset-right)); }
/* 只有在跑步中才顯示；選單、貓窩時收起來，避免擋住按鈕 */
body.touch.in-play .touch-pad { display: flex; }

.pixel-btn {
  width: 64px;
  height: 64px;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--ink);
  border-radius: 0;
  background: var(--navy);
  box-shadow: inset 4px 4px 0 0 var(--slate), inset -4px -4px 0 0 var(--ink);
  opacity: 0.88;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}
.pixel-btn--jump {
  width: 76px;
  height: 76px;
  background: var(--lift-d);
  box-shadow: inset 4px 4px 0 0 var(--lift), inset -4px -4px 0 0 var(--ink);
}
/* 衝刺：能量滿才亮；躲：靠近紙箱才出現 */
.pixel-btn--dash {
  align-self: flex-end;
  margin-bottom: 44px;
  background: var(--navy);
  opacity: 0.35;
}
body.can-dash .pixel-btn--dash {
  opacity: 0.95;
  background: var(--lift);
  box-shadow: inset 4px 4px 0 0 var(--lift-l), inset -4px -4px 0 0 var(--lift-d);
}
.pixel-btn--hide {
  display: none;
  align-self: flex-end;
  background: var(--lift-d);
}
body.near-box .pixel-btn--hide { display: flex; }
.pixel-btn.is-down {
  box-shadow: inset 4px 4px 0 0 var(--ink);
  opacity: 1;
}
.pixel-btn .ico { display: block; line-height: 0; pointer-events: none; }
.pixel-btn canvas { display: block; }

/* ── 手機直放：遊戲在上方，下半部是放大的按鈕 ── */
body.portrait .touch-pad { bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px)); }
body.portrait .touch-pad--left { left: max(16px, env(safe-area-inset-left)); gap: 14px; }
body.portrait .touch-pad--right {
  right: max(16px, env(safe-area-inset-right));
  flex-direction: column;       /* 由上到下：躲、衝、跳（跳在最下面，拇指最好按） */
  align-items: flex-end;
  gap: 14px;
}
body.portrait .pixel-btn { width: min(22vw, 88px); height: min(22vw, 88px); }
body.portrait .pixel-btn--jump { width: min(27vw, 108px); height: min(27vw, 108px); }
body.portrait .pixel-btn--dash,
body.portrait .pixel-btn--hide { align-self: flex-end; margin-bottom: 0; }
body.portrait .pixel-btn canvas { transform: scale(1.25); }
/* 平板橫放：按鈕稍微加大 */
@media (min-width: 900px) and (pointer: coarse) {
  body:not(.portrait) .pixel-btn { width: 80px; height: 80px; }
  body:not(.portrait) .pixel-btn--jump { width: 96px; height: 96px; }
}

noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--lift-l);
  font-size: 16px;
}

/* 便利店篇：店內顯示方向鍵＋「看」（沿用躲的那顆按鈕），衝刺鍵收起 */
.pixel-btn--hide .ico-store { display: none; }
body.in-store .pixel-btn--hide { display: flex; }
body.in-store .pixel-btn--hide .ico-run { display: none; }
body.in-store .pixel-btn--hide .ico-store { display: block; }
body.in-store .pixel-btn--dash { display: none; }
/* 第二篇的新場景：沒有紙箱，「躲」那顆按鈕一直在、變成「拍」 */
.pixel-btn--hide .ico-swat { display: none; }
body.seq-run .pixel-btn--hide { display: flex; background: var(--lift-d); }
body.seq-run .pixel-btn--hide .ico-run,
body.seq-run .pixel-btn--hide .ico-store { display: none; }
body.seq-run .pixel-btn--hide .ico-swat { display: block; }
/* 生活圈彈珠台：← → 控制貓掌、↑ 蓄力發球；躲／衝不顯示 */
body.in-pinball .pixel-btn--hide,
body.in-pinball .pixel-btn--dash { display: none; }
