* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ===== 顶部栏 ===== */
#game-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 50px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}
#game-header h1 {
  font-size: 16px;
  color: #6b5744;
  white-space: nowrap;
}
#home-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #6b5744;
  padding: 4px 8px;
}
#score-display {
  font-weight: bold;
  color: #f59563;
  font-size: 15px;
}
#best-display {
  font-size: 12px;
  color: #9a8474;
}
#rank-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

/* ===== 游戏画布 ===== */
#game-canvas {
  display: block;
  margin: 0 auto;
  background: #faf3eb;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

#canvas-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: calc(100vh - 50px);
  margin-top: 50px;
  padding: 10px;
}

/* ===== 开始界面 ===== */
#start-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
#start-box {
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
#start-box h2 {
  font-size: 24px;
  color: #5a4a3a;
  margin-bottom: 12px;
}
#start-box p {
  font-size: 14px;
  color: #8a7a6a;
  line-height: 1.6;
  margin-bottom: 20px;
}
#start-btn {
  background: linear-gradient(135deg, #4CAF50, #66BB6A);
  color: #fff;
  border: none;
  padding: 12px 36px;
  border-radius: 25px;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 3px 10px rgba(76,175,80,0.3);
}
#start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(76,175,80,0.4);
}
.back-link {
  display: inline-block;
  margin-top: 16px;
  color: #9a8474;
  text-decoration: none;
  font-size: 13px;
}
.back-link:hover { text-decoration: underline; }

/* ===== 方向按钮（移动端） ===== */
#mobile-controls {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
}
@media (max-width: 600px) {
  #mobile-controls { display: block; }
}
@media (pointer: coarse) {
  #mobile-controls { display: block; }
}
.ctrl-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.ctrl-row + .ctrl-row { margin-top: 6px; }
.ctrl-btn {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: none;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(4px);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.1s;
  color: #5a4a3a;
}
.ctrl-btn:active {
  transform: scale(0.9);
  background: rgba(245,149,99,0.4);
}
.ctrl-spacer {
  width: 56px;
  height: 56px;
  visibility: hidden;
}

/* ===== 游戏结束弹窗 ===== */
#game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
#game-over-box {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
#game-over-box h2 {
  font-size: 22px;
  color: #e74c3c;
  margin-bottom: 8px;
}
#final-score {
  font-size: 16px;
  color: #5a4a3a;
  margin-bottom: 4px;
}
#new-record {
  color: #f59563;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
}
#submit-area {
  margin: 12px 0;
}
#player-name-input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e0d5c8;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 8px;
  outline: none;
  transition: border-color 0.2s;
}
#player-name-input:focus {
  border-color: #f59563;
}
#submit-area button {
  background: linear-gradient(135deg, #4CAF50, #66BB6A);
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(76,175,80,0.3);
}
#game-over-box > button {
  background: linear-gradient(135deg, #f59563, #edc17a);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 2px 8px rgba(245,149,99,0.3);
}

/* ===== 排行榜 ===== */
#leaderboard-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
#leaderboard-box {
  background: #fff;
  border-radius: 16px;
  padding: 24px 20px;
  max-width: 360px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
#leaderboard-box h3 {
  text-align: center;
  font-size: 20px;
  color: #5a4a3a;
  margin-bottom: 12px;
}
#leaderboard-list {
  list-style: none;
  padding: 0;
}
#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px;
  border-bottom: 1px solid #f0e8df;
  font-size: 14px;
  color: #5a4a3a;
}
#leaderboard-list li:nth-child(1) { background: #fff8e1; font-weight: bold; }
#leaderboard-list li:nth-child(2) { background: #f5f5f5; font-weight: bold; }
#leaderboard-list li:nth-child(3) { background: #fbe9e7; font-weight: bold; }
#leaderboard-box button {
  display: block;
  margin: 16px auto 0;
  background: linear-gradient(135deg, #f59563, #edc17a);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}
