/* ============ 基础 ============ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0e18;
  color: #f2f5fb;
  font-family: system-ui, -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ============ HUD（每个玩家一份，分屏时各占一个视口） ============ */
#hudLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* 外层只负责「摆到哪个视口 + 缩放」，内层是完整一整屏的 HUD 版面 */
.hudView {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: top left;
  will-change: transform;
}
.hudView.split { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.hudView:not(.primary) .tags,
.hudView:not(.primary) #musicTag { display: none; }

.hudInner {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.corner { position: absolute; display: flex; gap: 10px; }
.tl { top: 20px; left: 22px; flex-direction: column; align-items: flex-start; }
.tc { top: 18px; left: 50%; transform: translateX(-50%); }
.tr { top: 20px; right: 22px; flex-direction: column; align-items: flex-end; }
.bl { bottom: 22px; left: 22px; }
.br { bottom: 22px; right: 22px; flex-direction: column; align-items: flex-end; gap: 8px; }

.card {
  background: linear-gradient(180deg, rgba(12,17,28,0.82), rgba(12,17,28,0.62));
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 16px;
  padding: 10px 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  text-align: center;
}

.card .label {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  font-weight: 700;
}

.card .value {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.card .value .sub { font-size: 20px; opacity: 0.5; font-weight: 700; }

.lapCard .value.final { color: #ffd24a; text-shadow: 0 0 22px rgba(255,210,74,0.55); animation: pulseFinal 1s infinite; }
@keyframes pulseFinal { 50% { opacity: 0.55; } }

.timeCard { padding: 6px 16px; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; opacity: 0.92; }

.placeCard .value { display: flex; align-items: baseline; gap: 2px; justify-content: center; }
.placeCard .value .suffix { font-size: 19px; font-weight: 800; opacity: 0.75; }
.placeCard .value.p1 { color: #ffd24a; }
.placeCard .value.p2 { color: #d9e2f0; }
.placeCard .value.p3 { color: #f0a86a; }

.mapWrap {
  background: rgba(10,14,24,0.5);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 18px;
  padding: 6px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#minimap { width: 196px; height: 196px; display: block; }

.tags { display: flex; gap: 6px; }
.tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(12,17,28,0.7);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
}
.tag.ok { color: #7ef29a; border-color: rgba(126,242,154,0.35); }
.tag.bad { color: #ff8a80; border-color: rgba(255,138,128,0.35); }

/* 速度表 */
.speedo { position: relative; width: 260px; height: 150px; }
.speedo svg { width: 100%; height: 100%; display: block; }
.gaugeTrack { fill: none; stroke: rgba(8,12,20,0.6); stroke-width: 17; stroke-linecap: round; }
.gaugeFill {
  fill: none;
  stroke: #8fd8ff;
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke 0.2s;
  filter: drop-shadow(0 0 8px currentColor);
}
.speedo .num {
  position: absolute;
  left: 0; right: 0; bottom: 6px;
  text-align: center;
  font-size: 42px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 14px rgba(0,0,0,0.6);
}
.speedo .unit { font-size: 13px; font-weight: 700; opacity: 0.6; margin-left: 5px; }

/* 道具槽 */
.itemSlot {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 168px;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, rgba(12,17,28,0.82), rgba(12,17,28,0.6));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.itemSlot.empty { opacity: 0.45; }
.itemSlot .icon { font-size: 40px; line-height: 1; min-width: 44px; text-align: center; }
.itemSlot .hint { font-size: 12px; font-weight: 700; color: rgba(255,255,255,0.75); max-width: 110px; }
.itemSlot.filled { border-color: rgba(255,210,74,0.5); box-shadow: 0 0 26px rgba(255,180,58,0.25); }
.itemSlot.rolling .icon { animation: roulette 0.14s infinite; }
@keyframes roulette {
  0% { transform: translateY(-6px) scale(0.7); opacity: 0.4; }
  50% { transform: translateY(0) scale(1.1); opacity: 1; }
  100% { transform: translateY(6px) scale(0.7); opacity: 0.4; }
}

/* 中央大字 */
#centerMsg {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(0.7);
  font-size: 130px;
  font-weight: 900;
  letter-spacing: -0.03em;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  text-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 60px rgba(255,255,255,0.25);
  -webkit-text-stroke: 3px rgba(10,14,24,0.55);
  text-align: center;
  white-space: nowrap;
}
#centerMsg.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#centerMsg.count { color: #ffd24a; animation: pop 0.5s; }
#centerMsg.go { color: #7ef29a; animation: pop 0.5s; }
#centerMsg.ready { font-size: 64px; color: #cfe4ff; }
#centerMsg.final { color: #ffd24a; }
#centerMsg.finish { color: #ffd24a; }
#centerMsg.lap { font-size: 90px; color: #ffffff; }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(1.9); opacity: 0.2; }
  60% { transform: translate(-50%, -50%) scale(0.95); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* 特效层 */
.vignette {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.22s;
  background: radial-gradient(ellipse at center, rgba(255,160,40,0) 42%, rgba(255,132,20,0.42) 100%);
}
.hudInner.boosting .vignette { opacity: 1; animation: boostPulse 0.34s infinite; }
@keyframes boostPulse { 50% { opacity: 0.65; } }

.flashLayer { position: absolute; inset: 0; opacity: 0; transition: opacity 0.25s; }
.hudInner.fx-hit .flashLayer { opacity: 1; background: radial-gradient(ellipse at center, rgba(255,0,0,0) 30%, rgba(255,30,30,0.5) 100%); }
.hudInner.fx-turbo .flashLayer { opacity: 1; background: radial-gradient(ellipse at center, rgba(120,220,255,0) 35%, rgba(120,220,255,0.4) 100%); }

/* 逆向行驶警告 */
#wrongWay {
  position: absolute;
  left: 50%;
  top: 27%;
  transform: translateX(-50%);
  padding: 8px 22px;
  border-radius: 999px;
  background: rgba(180, 20, 20, 0.82);
  border: 2px solid rgba(255, 120, 110, 0.9);
  color: #fff;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
#wrongWay.on { opacity: 1; animation: wrongBlink 0.6s infinite; }
@keyframes wrongBlink { 50% { opacity: 0.35; } }

/* ============ 大厅 / 结算面板 ============ */
#lobby, #results {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 35%, rgba(8,12,22,0.35), rgba(6,9,16,0.82));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.panel {
  width: min(920px, 93vw);
  max-height: 92vh;
  overflow: auto;
  padding: 26px 30px 24px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(16,22,36,0.94), rgba(11,15,26,0.96));
  border: 1px solid rgba(255,255,255,0.13);
  box-shadow: 0 30px 90px rgba(0,0,0,0.6);
}
.panel.narrow { width: min(640px, 92vw); }

.brand {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}
.brand span {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  margin-left: 8px;
}

.cols { display: flex; gap: 34px; }
.col { flex: 1; min-width: 0; }

.colTitle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #8fd8ff;
  margin-bottom: 12px;
}

/* 踢走残留手柄 */
.miniKick {
  margin-left: auto;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 800;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 138, 128, 0.45);
  background: rgba(255, 90, 74, 0.12);
  color: #ff9b90;
  cursor: pointer;
}
.miniKick:hover { background: rgba(255, 90, 74, 0.26); color: #fff; }
.miniKick.ghost {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.75);
}
.miniKick.ghost:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }

/* ---- 地图选择 ---- */
.trackPicker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.trackCard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.045);
  color: rgba(255, 255, 255, 0.85);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.08s;
}
.trackCard:hover { background: rgba(255, 255, 255, 0.09); }
.trackCard:active { transform: scale(0.98); }
.trackCard.on {
  border-color: rgba(255, 210, 74, 0.75);
  background: rgba(255, 210, 74, 0.12);
  box-shadow: 0 0 26px rgba(255, 180, 58, 0.18);
}
.trackThumb {
  width: 84px;
  height: 84px;
  border-radius: 10px;
  display: block;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.trackThumb svg { width: 100%; height: 100%; display: block; }
.trackCard .tName { font-size: 13.5px; font-weight: 800; }
.trackCard .tDesc { font-size: 11px; font-weight: 600; color: rgba(255, 255, 255, 0.45); }
.trackCard.on .tName { color: #ffd24a; }

@media (max-width: 720px), (max-height: 620px) {
  .trackPicker { grid-template-columns: repeat(2, 1fr); }
  .trackThumb { width: 64px; height: 64px; }
}

/* ---- 人机数量 ---- */
.aiBtns {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.aiBtn {
  width: 34px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.75);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.aiBtn:hover { background: rgba(255, 255, 255, 0.13); }
.aiBtn.on {
  border-color: rgba(255, 210, 74, 0.8);
  background: rgba(255, 210, 74, 0.18);
  color: #ffd24a;
}
.aiHint {
  margin-left: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.42);
  letter-spacing: 0;
}

.kickBtn {
  flex: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
}
.kickBtn:hover {
  background: rgba(255, 90, 74, 0.32);
  border-color: rgba(255, 90, 74, 0.65);
  color: #fff;
}

.playerRow.stale {
  border-color: rgba(255, 201, 60, 0.42);
  background: rgba(255, 201, 60, 0.07);
}
.staleTag {
  flex: none;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 201, 60, 0.18);
  color: #ffc93c;
}

.qrBox {
  background: #fff;
  border-radius: 16px;
  padding: 10px;
  width: 210px;
  height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qrBox img { width: 100%; height: 100%; display: block; }

.roomRow {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.02em;
}
.roomRow b {
  margin-left: 6px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 20px;
  letter-spacing: 0.16em;
  color: #ffd24a;
}

.urlList { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; }
.urlRow {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 14px;
  font-weight: 700;
  color: rgba(255,255,255,0.72);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 7px 12px;
  border-radius: 10px;
}
.urlRow.primary { color: #ffd24a; border-color: rgba(255,210,74,0.35); background: rgba(255,210,74,0.08); }

.note { margin-top: 10px; font-size: 12.5px; color: rgba(255,255,255,0.42); }

.playerList { display: flex; flex-direction: column; gap: 8px; min-height: 62px; }
.playerRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.055);
  border: 1px solid rgba(255,255,255,0.08);
  font-weight: 700;
}
.playerRow .name { flex: 1; }
.playerRow .seat { font-size: 12px; color: rgba(255,255,255,0.42); font-weight: 600; }
.playerList .empty {
  padding: 14px;
  border-radius: 12px;
  border: 1px dashed rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.45);
  font-size: 13.5px;
  text-align: center;
}

.dot { width: 13px; height: 13px; border-radius: 50%; display: inline-block; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,0.15); }

.divider { height: 1px; background: rgba(255,255,255,0.1); margin: 20px 0; }

.lobbyHint { font-size: 14px; line-height: 1.6; color: rgba(255,255,255,0.75); }
.lobbyHint b { color: #ffd24a; }

.keys { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.keys span {
  font-size: 11.5px;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.55);
}
.keys b { color: rgba(255,255,255,0.88); }

/* 结算表 */
.resultTable { width: 100%; border-collapse: collapse; }
.resultTable td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.075);
  font-size: 16px;
  font-weight: 700;
}
.resultTable tr:last-child td { border-bottom: none; }
.resultTable td.p { font-size: 20px; font-weight: 900; width: 44px; color: rgba(255,255,255,0.85); }
.resultTable td.medal { width: 34px; font-size: 20px; }
.resultTable td.who { display: flex; align-items: center; gap: 10px; }
.resultTable td.t, .resultTable td.gap {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 14.5px;
  color: rgba(255,255,255,0.7);
}
.resultTable td.gap { width: 84px; color: rgba(255,255,255,0.45); }
.resultTable tr.me { background: rgba(255,210,74,0.09); }
.resultTable tr.me td.p { color: #ffd24a; }
.resultTable .ai {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(143,216,255,0.15);
  color: #8fd8ff;
}

#fatal {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  background: #0a0e18;
  color: #ff8a80;
  font-size: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
}

@media (max-width: 900px), (max-height: 620px) {
  .cols { flex-direction: column; gap: 22px; }
  .card .value { font-size: 32px; }
  #minimap { width: 132px; height: 132px; }
  .speedo { width: 190px; height: 112px; }
  .speedo .num { font-size: 30px; }
  #centerMsg { font-size: 76px; }
  .itemSlot { min-width: 120px; padding: 7px 12px; }
  .itemSlot .icon { font-size: 28px; }
}
