/*
 * 赛道与仪表盘。
 *
 * HUD 的排布照着那几代《暴力摩托》的规矩来：**底下一整块仪表盘**，
 * 左表（我）/ 中间（名次与差距）/ 右表（前面的那台车）排在同一条水平线上。
 *
 * 对齐是硬要求，所以三块用同一套骨架：`grid-template-columns: 118px minmax() 118px`，
 * 两边各自是"表 → 速度 → 血条"的等宽列、`align-items:end` 让它们的底边齐平。
 * 想加东西就往中间那列加，**不要往左右两块里塞**——塞进去两边就不对称了。
 */

#arena { position: fixed; inset: 0; height: 100dvh; overflow: hidden; background: #06080e; touch-action: none; }
#game { display: block; width: 100%; height: 100%; outline: 0; touch-action: none; }

.hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.hud button { pointer-events: auto; }

/* ------------------------------------------------------------ 顶部横条 */
.hud-top {
  position: absolute; top: 16px; left: 20px; right: 20px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px;
}
.hud-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 900; letter-spacing: 1px; text-shadow: 0 2px 10px #000a;
}
.hud-brand .brand-mark { width: 34px; height: 33px; font-size: 21px; border-radius: 9px 3px 9px 3px; }
.hud-timer {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 20px; border: 1px solid var(--line); border-radius: 12px;
  background: #080e18cc; backdrop-filter: blur(10px);
}
.hud-timer b { font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.hud-timer span { font-size: 8px; letter-spacing: 1.6px; color: var(--muted); }
.hud-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.hud-rank {
  display: flex; align-items: baseline; gap: 3px; margin-right: 4px;
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: #080e18cc; font-size: 12px; font-weight: 800; color: var(--muted);
  backdrop-filter: blur(10px);
}
.hud-rank b { font-size: 22px; font-style: italic; color: var(--amber); font-variant-numeric: tabular-nums; }

/*
 * 常驻键位提示：小字、居中、贴在顶栏下沿。
 *
 * 为什么不用弹窗：赛车游戏里"忘了怎么打"的代价是一整局的体验，而开一次帮助
 * 弹窗要么挡视线要么得暂停。所以把键位**一直摆在那里**，小到不抢画面，
 * 但一眼能扫到。窄屏与触屏上关掉它——那时候屏幕上有真的按钮。
 */
.hud-keys {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  margin: 0; padding: 3px 13px; max-width: min(720px, 76vw);
  border: 1px solid var(--line); border-radius: 999px;
  background: #070c14a8; backdrop-filter: blur(6px);
  font-size: 10px; line-height: 1.7; letter-spacing: .4px;
  color: var(--muted); text-align: center; white-space: nowrap;
}
.hud-keys kbd {
  min-width: 18px; padding: 1px 4px; margin: 0 2px;
  font-size: 10px; background: #0b1220cc;
}

/* ------------------------------------------------------------ 名次与播报 */
.rank-list {
  position: absolute; left: 20px; top: 96px;
  display: flex; flex-direction: column; gap: 3px; width: 186px;
}
.rank-row {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) 34px; gap: 7px; align-items: center;
  padding: 5px 9px; border-radius: 8px;
  background: #070c14b8; font-size: 11px; backdrop-filter: blur(6px);
}
.rank-row b { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row i { font-style: normal; font-size: 10px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rank-row.me { background: #ffb03a2e; box-shadow: inset 2px 0 var(--amber); }
.rank-row.me b { color: var(--amber); }

.feed-list {
  position: absolute; right: 20px; top: 96px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; max-width: 300px;
}
.feed-row {
  padding: 5px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: #070c14c4; font-size: 11px; backdrop-filter: blur(6px);
  animation: bt-feed .22s ease-out;
}
@keyframes bt-feed { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ 底部仪表盘 */
.hud-dash {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: grid; grid-template-columns: 118px minmax(196px, 280px) 118px;
  align-items: end; gap: 16px; padding: 12px 18px;
  border: 1px solid var(--line2); border-radius: 18px;
  background: linear-gradient(160deg, #131c2ae8, #0a111cf2);
  box-shadow: 0 18px 40px #00000088; backdrop-filter: blur(12px);
}
.dash-block { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 118px; }
.dash-block canvas { display: block; width: 96px; height: 96px; }
.dash-speed { font-size: 9px; letter-spacing: 1.4px; color: var(--muted); }
.dash-speed b {
  margin-right: 3px; font-size: 21px; font-style: italic; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.dash-center {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding-bottom: 4px; text-align: center;
}
.dash-center > strong { font-size: 17px; font-style: italic; letter-spacing: .5px; }
.dash-gap,
.dash-rival { font-size: 9px; letter-spacing: .8px; color: var(--muted); }
.dash-gap b,
.dash-rival b { color: var(--text); font-size: 11px; }

.sta-row { display: flex; align-items: center; gap: 6px; width: 100%; font-size: 8px; color: var(--muted); }
.sta-row > span { width: 34px; flex: 0 0 auto; }
.sta-row > em { font-style: normal; font-variant-numeric: tabular-nums; color: #cfe0ee; }
.sta-track { flex: 1; height: 6px; border-radius: 4px; background: #ffffff14; overflow: hidden; }
.sta-track > b {
  display: block; height: 100%; width: 100%; border-radius: 4px;
  background: linear-gradient(90deg, #ff6a7a, #ffd23f, #7cf7a0);
  transition: width .12s linear;
}
.sta-row.nos { margin-top: 1px; }
.sta-row.nos .sta-track { height: 4px; }
.sta-row.nos .sta-track > b { background: linear-gradient(90deg, #3ad2ff, #c691ff); }

.progress-rail {
  position: absolute; left: 50%; bottom: 178px; transform: translateX(-50%);
  width: min(560px, 66vw); height: 4px; border-radius: 3px;
  background: #ffffff1c; overflow: visible;
}
.progress-rail > i {
  position: absolute; top: -4px; left: 0; width: 14px; height: 12px;
  border-radius: 3px; background: var(--amber); box-shadow: 0 0 12px var(--amber);
}
.progress-rail::after {
  content: ""; position: absolute; right: 0; top: -6px;
  width: 2px; height: 16px; background: #ffffffaa;
}

.respawn {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 34px; border: 1px solid #ff8da955; border-radius: 14px;
  background: #170d12d9; text-align: center; backdrop-filter: blur(8px);
}
.respawn strong { font-size: 30px; font-style: italic; color: var(--danger); }
.respawn span { font-size: 11px; color: var(--muted); }
.respawn b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ 触屏控件 */
.touch-controls { display: none; }
html.touch-device .touch-controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}
html.touch-device .steer-pad {
  position: relative; width: 168px; height: 54px; border-radius: 999px;
  border: 1px solid var(--line2); background: #070c1499;
  touch-action: none; pointer-events: auto;
}
html.touch-device .steer-pad > i {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: linear-gradient(150deg, #ffd899, var(--amber));
  box-shadow: 0 6px 16px #00000066;
}
html.touch-device .touch-buttons { display: flex; align-items: flex-end; gap: 10px; }
html.touch-device .touch-button {
  width: 62px; height: 62px; border-radius: 50%; pointer-events: auto;
  border: 1px solid var(--line2); background: #0d1623cc; color: var(--text);
  font-size: 12px; font-weight: 800;
}
html.touch-device .touch-button.big { width: 82px; height: 82px; font-size: 14px; background: #ffb03a2e; }
html.touch-device .touch-button.on { background: var(--amber); color: #201203; }
/* 攻击是两个方向、两个按钮：竖着叠成一列，横向就不再跟氮气/刹车/油门抢地方。 */
html.touch-device .punch-pair { display: flex; flex-direction: column; align-items: center; gap: 8px; }
html.touch-device .touch-button.small { width: 52px; height: 52px; font-size: 11px; }
/* 触屏上屏幕里就有真的按钮，那行小字纯属占地方。 */
html.touch-device .hud-keys { display: none; }

/* 触屏设备上仪表盘会跟控件抢地方：把它挪到上面一档并缩小。 */
html.touch-device .hud-dash { bottom: calc(96px + env(safe-area-inset-bottom)); padding: 9px 12px; gap: 10px; }
html.touch-device .dash-block { width: 92px; }
html.touch-device .dash-block canvas { width: 74px; height: 74px; }
html.touch-device .progress-rail { bottom: calc(232px + env(safe-area-inset-bottom)); }

@media (max-width: 760px) {
  .hud-top { left: 12px; right: 12px; top: 12px; }
  /* 窄屏上名次表会往上顶一格，键位那行小字就没地方站了——直接让位。 */
  .hud-keys { display: none; }
  .rank-list { left: 12px; top: 84px; width: 148px; }
  .feed-list { right: 12px; top: 84px; max-width: 210px; }
  .hud-dash { grid-template-columns: 84px minmax(140px, 1fr) 84px; gap: 10px; padding: 9px 11px; }
  .dash-block { width: 84px; }
  .dash-block canvas { width: 68px; height: 68px; }
  .dash-speed { display: none; }
  .dash-center > strong { font-size: 14px; }
  .progress-rail { bottom: 152px; width: 76vw; }
}

@media (max-height: 620px) {
  .rank-row:nth-child(n + 4) { display: none; }
  .hud-dash { bottom: 12px; }
}
