* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #263450, #16202f 70%);
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  color: #eef2f8;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 14px;
  width: min(92vw, calc((100vh - 110px) * 13 / 11));
  background: #223047;
  border: 2px solid #3a4d6e;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 14px;
}
.hud-item b { color: #ffd75e; font-variant-numeric: tabular-nums; }

#hud-battle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
  width: min(92vw, calc((100vh - 110px) * 13 / 11));
  background: #223047;
  border: 2px solid #3a4d6e;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
}
#hudb-players { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #1b2740;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 3px 8px;
  white-space: nowrap;
}
.chip.dead { opacity: 0.45; }
.chip .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }

/* ---------- Stage & canvas ---------- */
#stage {
  position: relative;
  width: min(92vw, calc((100vh - 110px) * 13 / 11));
  aspect-ratio: 13 / 11;
}
#game {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 12px;
  border: 3px solid #3a4d6e;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  background: #0e1520;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 18, 28, 0.82);
  border-radius: 12px;
  z-index: 10;
}
.hidden { display: none !important; }

.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  background: #2a3a55;
  border: 2px solid #46608c;
  border-radius: 18px;
  padding: 28px 36px;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.card h1 { font-size: 30px; color: #ffd75e; text-shadow: 0 3px 0 #7a5410; }
.card h2 { font-size: 26px; color: #ffd75e; }
.subtitle { color: #9fb4d8; letter-spacing: 2px; }
.rules { font-size: 14px; line-height: 1.7; color: #cdd9ee; }
.controls { font-size: 13px; color: #9fb4d8; line-height: 1.9; }
.stats { font-size: 16px; line-height: 2; }
.stats b { color: #ffd75e; }
kbd {
  background: #16202f;
  border: 1px solid #46608c;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  margin: 0 1px;
}

.row {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: center;
  border: none;
  font-size: 14px;
}
fieldset.row {
  border: 1px solid #46608c;
  border-radius: 10px;
  padding: 8px 16px;
}
fieldset.row legend { padding: 0 8px; color: #9fb4d8; font-size: 13px; }
.row label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
input[type="range"] { width: 90px; accent-color: #ffd75e; }
input[type="radio"], input[type="checkbox"] { accent-color: #ffd75e; }

.cfg-row { margin-top: 8px; font-size: 13px; }
.best { color: #9fb4d8; font-size: 13px; }
.stars { font-size: 24px; color: #ffd75e; letter-spacing: 3px; }
select {
  font-family: inherit;
  font-size: 13px;
  color: #eef2f8;
  background: #16202f;
  border: 1px solid #46608c;
  border-radius: 6px;
  padding: 3px 6px;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #3a2b00;
  background: linear-gradient(#ffe28a, #ffcf3f);
  border: 2px solid #d9a812;
  border-radius: 12px;
  padding: 10px 26px;
  min-width: 200px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.08s ease;
}
.btn:hover { transform: scale(1.04); filter: brightness(1.06); }
.btn:active { transform: scale(0.97); }
.btn-big { font-size: 19px; padding: 13px 34px; }
.btn-small { font-size: 13px; padding: 4px 12px; min-width: 0; }
.btn-ghost {
  background: transparent;
  color: #cdd9ee;
  border-color: #46608c;
}
.btn-ghost:hover { background: #34486b; }

.manual-link {
  color: #9fb4d8;
  font-size: 14px;
  text-decoration: none;
  border-bottom: 1px dashed #46608c;
  padding-bottom: 1px;
}
.manual-link:hover { color: #ffd75e; border-color: #ffd75e; }

/* ---------- Touch controls（TouchControls.js 偵測到觸控裝置才顯示） ---------- */
#touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 5vw calc(14px + env(safe-area-inset-bottom));
  z-index: 20;
  pointer-events: none; /* 只有 pad 與炸彈鈕本體收事件，不擋畫面點擊 */
}
#tc-pad {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(34, 48, 71, 0.55);
  border: 2px solid rgba(70, 96, 140, 0.65);
  pointer-events: auto;
  touch-action: none;
}
.tc-arrow {
  position: absolute;
  font-size: 24px;
  color: #9fb4d8;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.tc-arrow.active { color: #ffd75e; }
.tc-up { left: 50%; top: 20%; }
.tc-down { left: 50%; top: 80%; }
.tc-left { left: 20%; top: 50%; }
.tc-right { left: 80%; top: 50%; }
#tc-bomb {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  font-size: 42px;
  background: rgba(34, 48, 71, 0.55);
  border: 3px solid rgba(217, 168, 18, 0.75);
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}
#tc-bomb:active { transform: scale(0.9); background: rgba(255, 215, 94, 0.35); }

/* ---------- 觸控裝置版面（body.touch 由 TouchControls.js 掛上） ---------- */
body.touch kbd, body.touch .controls { display: none; }
body.touch .btn-small { padding: 6px 14px; }
/* 選單/結算卡片可能比 canvas 高：改全螢幕 overlay，卡片置中、放不下時可捲動 */
body.touch .overlay {
  position: fixed;
  border-radius: 0;
  overflow-y: auto;
  padding: 16px 8px;
  z-index: 30;
}
body.touch .overlay .card { margin: auto; }

@media (orientation: portrait) {
  /* 底部保留虛擬按鍵高度，canvas 不被蓋住 */
  body.touch #app { padding-bottom: 190px; }
  body.touch #stage,
  body.touch #hud,
  body.touch #hud-battle {
    width: min(96vw, calc((100vh - 320px) * 13 / 11));
  }
}
@media (orientation: landscape) {
  /* 橫式：canvas 讓出左右下角給虛擬按鍵（半透明可重疊） */
  body.touch #stage,
  body.touch #hud,
  body.touch #hud-battle {
    width: min(70vw, calc((100vh - 90px) * 13 / 11));
  }
}

@media (max-width: 520px) {
  #hud, #hud-battle { font-size: 11px; gap: 4px 8px; padding: 6px 8px; }
  .card { padding: 16px 14px; gap: 10px; }
  .card h1 { font-size: 24px; }
  .row { gap: 10px; flex-wrap: wrap; }
  .overlay { overflow-y: auto; }
  .btn { min-width: 160px; }
}
