* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}
body {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  /* 邊緣安全帶/letterbox 一律純黑:融入手機螢幕邊框,比模擬天空草地的漸層更不搶戲。 */
  background: #000;
  color: #0f172a;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  /* iPhone Safari(非全螢幕)工具列會佔畫面:height:100% 含工具列下方 →
     盤面底部被 Safari 底列遮住(太太回報「版面卡住」)。改 dvh 只吃可視高度,
     工具列收合/展開時 visualViewport resize 會觸發 layout() 重算。 */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}

/* ---- Install bar (PWA 安裝提示,只在瀏覽器分頁出現;裝了或按 ✕ 就消失) ---- */
#install-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: rgba(15,23,42,.78);
  color: #fff;
  font-size: 15px;
  line-height: 1.35;
}
#install-bar[hidden] { display: none; }
#install-msg { flex: 1 1 auto; min-width: 0; }
#install-go {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 18px;
  border: none; cursor: pointer;
  border-radius: 10px;
  font-size: 16px; font-weight: 700;
  color: #0f172a;
  background: #fbbf24;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
}
#install-go:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
#install-go[hidden] { display: none; }
#install-close {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  border-radius: 50%;
  font-size: 18px;
  color: #fff;
  background: rgba(255,255,255,.14);
}

/* ---- Board (fills the app; menu / HUD / game-over are all drawn in-canvas) ---- */
.board-wrap {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 邊緣安全帶:底部/左右留一小圈(+瀏海 safe-area)—— 全螢幕時盤面貼死螢幕邊,
     手指掃底排很容易誤觸系統邊緣手勢把整個 app 滑掉。邊帶由 body 天空→草地漸層填色。 */
  padding: env(safe-area-inset-top)
           calc(8px + env(safe-area-inset-right))
           calc(14px + env(safe-area-inset-bottom))
           calc(8px + env(safe-area-inset-left));
  min-height: 0;
}
/* 不加 border-radius / box-shadow:Safari 對持續重繪的 canvas layer 做圓角裁切+陰影
   合成是每幀成本(iPhone 有感);遊戲畫面本來就滿版美術,不需要框飾。 */
#board {
  display: block;
  touch-action: none;
}

/* ---- Overlaid corner buttons (translucent, over the canvas) ----
   back = top-left (aligns with in-canvas pause art); share = bottom-right
   (menu only; audio toggles moved into the in-canvas settings popup). */
.corner-btn {
  position: absolute;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  line-height: 1;
  color: #fff;
  background: rgba(15,23,42,.32);
  border-radius: 50%;
  box-shadow: 0 3px 0 rgba(0,0,0,.18);
  z-index: 5;
}
.corner-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.corner-btn[hidden] { display: none; }
.back-btn { top: calc(10px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left)); font-size: 30px; font-weight: 900; }
.share-btn { bottom: calc(14px + env(safe-area-inset-bottom)); right: calc(14px + env(safe-area-inset-right)); font-size: 22px; }

/* ---- Nickname modal (Part 4 訪客身分:canvas 遊戲沒有原生輸入框 → HTML 疊層問名字) ---- */
#nick-modal {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(15,23,42,.55);
}
#nick-modal[hidden] { display: none; }
.nick-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 14px;
  padding: 22px 20px;
  border-radius: 20px;
  background: #fff7ea;
  box-shadow: 0 14px 40px rgba(20,40,60,.45);
}
.nick-title { font-size: 20px; font-weight: 800; color: #5a3b1c; text-align: center; }
.nick-input {
  width: 100%; min-height: 52px;
  padding: 0 16px;
  border: 3px solid #e0cfa8; border-radius: 14px;
  font-size: 20px; color: #3d2410; background: #fffdf8;
  text-align: center; outline: none;
}
.nick-input:focus { border-color: #f5b642; }
.nick-err { min-height: 18px; font-size: 14px; color: #d1533c; text-align: center; }
.nick-actions { display: flex; gap: 12px; }
.nick-actions button {
  flex: 1 1 0; min-height: 50px;
  border: none; cursor: pointer;
  border-radius: 14px;
  font-size: 17px; font-weight: 800;
}
.nick-skip { color: #6b5a44; background: #ece0c9; }
.nick-ok { color: #fff; background: #6fb93c; box-shadow: 0 3px 0 rgba(0,0,0,.2); }
.nick-ok:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.2); }
