html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#stage {
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 캔버스는 512x384 그대로 그리고, JS가 창 크기에 맞춰 정수배로 확대 (픽셀이 안 뭉개지게) */
#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  display: block;
}

/* ===== 모바일 조작 버튼 ===== */
#touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-sizing: border-box;
  pointer-events: none;
  z-index: 10;
}
#touch .tpad {
  display: flex;
  gap: 14px;
  pointer-events: auto;
}
#touch .tbtn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 127, 208, 0.28);
  color: #fff;
  font-size: 15px;
  font-weight: bold;
  font-family: "Segoe UI", "맑은 고딕", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#touch .tbtn:active {
  background: rgba(255, 127, 208, 0.6);
}
#touch .tbtn[data-act="jump"],
#touch .tbtn[data-act="bubble"] {
  width: 72px;
  height: 72px;
}

/* ===== 전체 순위 (그룹 게임 컬렉션) ===== */
#layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
#stage { position: relative; }
.bb-board {
  display: none;
  width: 260px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px 18px;
  box-sizing: border-box;
  border: 2px solid #ff7fd0;
  border-radius: 12px;
  background: #140b1c;
  color: #fff;
  font-family: "Segoe UI", "맑은 고딕", sans-serif;
}
/* 넓은 화면에서만 게임 옆에 순위표 */
@media (min-width: 900px) {
  .bb-board { display: block; }
  .bb-overlay .bb-rank-list-mini { display: none; }
}
.bb-back { color: #ff9fdc; font-size: 13px; text-decoration: none; }
.bb-back:hover { text-decoration: underline; }
.bb-board-head { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.bb-board-head h2 { margin: 0; font-size: 18px; color: #ffe14d; }
.bb-board-note { margin: 6px 0 0; font-size: 12px; color: #b9a8c8; }
.bb-text-btn { background: none; border: 0; color: #7dff7d; font: inherit; font-size: 13px; cursor: pointer; }

.bb-rank-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.bb-rank-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px; background: #241634;
  font-size: 14px; font-variant-numeric: tabular-nums;
}
.bb-rank-list li.bb-rank-1 { background: linear-gradient(135deg, #4a3510, #241634); color: #ffe14d; }
.bb-rank-list li.bb-rank-2 { color: #dfe3f0; }
.bb-rank-list li.bb-rank-3 { color: #e8b48c; }
.bb-rank-badge { font-weight: bold; min-width: 34px; flex-shrink: 0; color: #b9a8c8; }
.bb-rank-1 .bb-rank-badge { color: #ffe14d; }
.bb-rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-rank-empty { justify-content: center !important; background: transparent !important; color: #b9a8c8; }
.bb-my-best { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid #3a2750; color: #7dff7d; font-size: 13px; font-weight: bold; }
.bb-my-best:empty { display: none; }

/* 게임오버·엔딩 순위 등록 창 */
.bb-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.72);
  font-family: "Segoe UI", "맑은 고딕", sans-serif;
  color: #fff;
}
.bb-overlay[hidden] { display: none; }
@media (max-width: 899px) {
  .bb-overlay { position: fixed; }
}
.bb-overlay-card {
  width: min(360px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 20px;
  box-sizing: border-box;
  border: 2px solid #ff7fd0;
  border-radius: 12px;
  background: #140b1c;
  text-align: center;
}
.bb-overlay-card h2 { margin: 0 0 6px; font-size: 26px; color: #ff5a5a; }
.bb-final { margin: 0 0 14px; font-size: 16px; }
.bb-final strong { color: #7dff7d; }
.bb-name-label { display: block; margin-bottom: 6px; font-size: 13px; color: #b9a8c8; text-align: left; }
.bb-name-row { display: flex; gap: 8px; }
.bb-name-input {
  flex: 1; min-width: 0; min-height: 40px; padding: 0 12px;
  border: 1px solid #5a3f78; border-radius: 8px; background: #241634; color: #fff;
  font: inherit; font-size: 15px;
  -webkit-user-select: text; user-select: text;
}
.bb-name-input:focus { outline: 2px solid #ff7fd0; }
.bb-primary-btn, .bb-secondary-btn {
  min-height: 40px; padding: 0 14px; border-radius: 8px; font: inherit; font-weight: bold; cursor: pointer;
}
.bb-primary-btn { border: 0; background: #ff7fd0; color: #140b1c; white-space: nowrap; }
.bb-primary-btn:disabled { opacity: 0.5; cursor: default; }
.bb-secondary-btn { margin-top: 12px; width: 100%; border: 1px solid #ff7fd0; background: transparent; color: #ff9fdc; }
.bb-rank-result { min-height: 1.2em; margin: 10px 0 0; color: #ffe14d; font-weight: bold; font-size: 14px; }
.bb-rank-list-mini li { font-size: 13px; padding: 5px 8px; }
