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

:root {
  --bg: #0f1220;
  --panel: #1a1f35;
  --panel2: #232a48;
  --line: #2e375c;
  --text: #e8ecff;
  --muted: #8b94b8;
  --accent: #5b8cff;
  --accent2: #34d399;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;   /* 防双击缩放 */
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
}

/* ---------- 顶部 ---------- */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.brand { font-size: 18px; font-weight: 700; }
#hud { display: flex; gap: 6px; }
.hud-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
}
.fs-btn {
  cursor: pointer;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

/* ---------- 画布区 ---------- */
#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 840 / 600;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #11152a;
  touch-action: none;
}

/* ---------- 覆盖层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 28, .85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.hidden { display: none; }

/* 菜单打开时铺满整屏：窄屏下画布比例区放不下整个菜单，会把「进入游戏」裁掉 */
#menu.overlay { position: fixed; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 20px;
  width: min(360px, 92%);
  max-height: 92%;
  overflow-y: auto;
  text-align: center;
}
.panel h1 { font-size: 22px; margin-bottom: 12px; }
.panel h2 { font-size: 20px; margin-bottom: 8px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  outline: none;
  margin-bottom: 10px;
}
input:focus { border-color: var(--accent); }
#serverInput { font-size: 13px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }

.speed-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.speed-btn {
  flex: 1;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
}
.speed-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#joinBtn, #respawnBtn {
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c5bff);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
#joinBtn:active, #respawnBtn:active { transform: scale(.97); }

.tips {
  margin-top: 14px;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.9;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.tips b { color: var(--text); }
.error { color: #ff7b7b; font-size: 13px; margin-top: 8px; min-height: 18px; }

#toast {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 70, 70, .95);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 20;
  white-space: nowrap;
}
#toast.hidden { display: none; }

/* ---------- 虚拟方向键 ---------- */
#vpad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(2, 68px);
  gap: 10px;
  justify-content: center;
  margin: 14px 0 6px;
}
.vbtn {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  border-radius: 16px;
  font-size: 24px;
  touch-action: none;
}
.vbtn:active { background: var(--accent); }
.vbtn.up    { grid-area: 1 / 2; }
.vbtn.left  { grid-area: 2 / 1; }
.vbtn.down  { grid-area: 2 / 2; }
.vbtn.right { grid-area: 2 / 3; }

/* ---------- 排行榜 ---------- */
#sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
#sidebar h3 { font-size: 14px; margin-bottom: 8px; }
#rankList { list-style: none; max-height: 150px; overflow-y: auto; }
#rankList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  font-size: 13px;
  border-radius: 6px;
}
#rankList li.me { background: var(--panel2); }
#rankList .rk { width: 20px; color: var(--muted); font-weight: 700; text-align: center; }
#rankList li.top1 .rk { color: #ffd34d; }
#rankList li.top2 .rk { color: #cfd8e3; }
#rankList li.top3 .rk { color: #e0915b; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.dot.dead { opacity: .25; }
#rankList .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rankList .nm.dead { color: var(--muted); text-decoration: line-through; }
#rankList .sc { font-weight: 700; color: var(--accent2); }
.muted { margin-top: 8px; font-size: 11px; word-break: break-all; color: var(--muted); }

/* ---------- 横屏矮屏：方向键浮到右下，排行榜让位 ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  #app { max-width: none; padding: 8px; }
  #stage {
    width: min(calc((100vh - 76px) * 1.4), 100%);
    margin: 0 auto;
  }
  #vpad {
    position: fixed;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    margin: 0;
    z-index: 30;
    opacity: .85;
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
  }
  #sidebar { display: none; }
}
