:root {
  --cyan: #37e6ff;
  --blue: #1f7bff;
  --orange: #ffa63d;
  --pink: #ff3d8f;
  --ink: #061019;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #05090f;
  color: #eaf6ff;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

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

.hidden { display: none !important; }

/* ================= HUD ================= */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-variant-numeric: tabular-nums;
}

.hud-tl {
  position: absolute;
  top: 18px;
  left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 168px;
}

.panel {
  position: relative;
  background: linear-gradient(100deg, rgba(5, 22, 34, 0.82), rgba(5, 22, 34, 0.42));
  border-left: 3px solid var(--cyan);
  padding: 6px 12px 7px;
  transform: skewX(-9deg);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35), inset 0 0 24px rgba(55, 230, 255, 0.06);
  backdrop-filter: blur(6px);
}
.panel > * { display: block; transform: skewX(9deg); }
.panel .label {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: #7fd7ea;
  opacity: 0.85;
  text-transform: uppercase;
}
.panel b {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #f2fbff;
  text-shadow: 0 0 14px rgba(55, 230, 255, 0.5);
}
.panel b em { font-style: normal; font-size: 12px; color: #7fd7ea; }
.panel-lap b { font-size: 24px; color: var(--cyan); }

.hud-tr {
  position: absolute;
  top: 18px;
  right: 20px;
  text-align: right;
  width: 190px;
}
.pos-wrap { display: flex; align-items: baseline; justify-content: flex-end; gap: 8px; }
.pos-wrap .label {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #7fd7ea;
}
.pos {
  font-size: 52px;
  font-weight: 900;
  line-height: 1;
  font-style: italic;
  color: #fff;
  text-shadow: 0 0 24px rgba(55, 230, 255, 0.85), 0 0 4px rgba(255, 255, 255, 0.9);
}
.pos i { font-style: normal; font-size: 16px; color: #8ec9dd; }
.ranklist {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  background: rgba(6, 20, 32, 0.42);
  backdrop-filter: blur(6px);
  border-radius: 10px;
  padding: 6px 4px;
  border: 1px solid rgba(120, 210, 240, 0.18);
}
.rankrow {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 9px;
  line-height: 1.5;
  opacity: 0.8;
  padding: 2px 6px;
  border-right: 2px solid rgba(55, 230, 255, 0.3);
  transform: skewX(-9deg);
}
.rankrow.me {
  opacity: 1;
  border-right-color: var(--cyan);
  background: linear-gradient(90deg, transparent, rgba(55, 230, 255, 0.18));
}
.rankrow .dot { width: 8px; height: 8px; border-radius: 50%; align-self: center; }
.rankrow .nm { min-width: 58px; text-align: right; font-weight: 600; }
.rankrow .gp { min-width: 46px; text-align: right; color: #8ec9dd; }

.hud-minimap {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 200px;
  height: 200px;
  border-radius: 14px;
  background: radial-gradient(circle at 50% 45%, rgba(6, 26, 42, 0.86), rgba(3, 10, 18, 0.72));
  border: 1px solid rgba(55, 230, 255, 0.35);
  box-shadow: 0 0 26px rgba(0, 0, 0, 0.5), inset 0 0 30px rgba(55, 230, 255, 0.08);
  overflow: hidden;
}
.hud-minimap canvas { display: block; width: 200px; height: 200px; }
.mm-title {
  position: absolute;
  left: 10px;
  bottom: 6px;
  font-size: 10px;
  letter-spacing: 0.22em;
  color: #7fd7ea;
  opacity: 0.8;
}

.hud-br {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
}
.speedo-wrap { position: relative; width: 240px; height: 240px; }
#speedo { width: 240px; height: 240px; display: block; filter: drop-shadow(0 0 18px rgba(0, 0, 0, 0.55)); }
.nos {
  position: absolute;
  left: 50%;
  top: 192px;
  transform: translateX(-50%);
  width: 156px;
  text-align: center;
}
.nos-head {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.24em;
  color: #8fd8ea;
  margin-bottom: 3px;
}
.nos-head b { color: var(--cyan); font-size: 11px; }
.nos-bar {
  height: 10px;
  border-radius: 5px;
  background: rgba(6, 22, 34, 0.95);
  border: 1px solid rgba(55, 230, 255, 0.55);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.8);
  overflow: hidden;
  position: relative;
}
.nos-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1f7bff, #37e6ff 60%, #b8fbff);
  box-shadow: 0 0 14px rgba(55, 230, 255, 0.9);
  transition: width 0.08s linear;
}
.nos.full .nos-bar {
  border-color: #b8fbff;
  animation: nosPulse 0.7s ease-in-out infinite alternate;
}
.nos.full .nos-bar i { background: linear-gradient(90deg, #ffd24a, #ff9c2b, #fff1b8); box-shadow: 0 0 20px rgba(255, 190, 60, 0.95); }
.nos-tip {
  margin-top: 3px;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: #8ee2f2;
  height: 12px;
}
.nos.full .nos-tip { color: var(--orange); text-shadow: 0 0 12px rgba(255, 166, 61, 0.9); }

@keyframes nosPulse {
  from { box-shadow: 0 0 6px rgba(255, 190, 60, 0.3); }
  to { box-shadow: 0 0 22px rgba(255, 190, 60, 0.8); }
}

.drift-wrap {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) skewX(-9deg);
  width: 300px;
  opacity: 0.55;
  transition: opacity 0.15s;
  background: linear-gradient(100deg, rgba(5, 22, 34, 0.7), rgba(5, 22, 34, 0.3));
  border: 1px solid rgba(55, 230, 255, 0.25);
  border-radius: 8px;
  padding: 7px 12px 8px;
}
.drift-wrap.active { opacity: 1; border-color: rgba(55, 230, 255, 0.7); box-shadow: 0 0 22px rgba(55, 230, 255, 0.2); }
.drift-head {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: #7fd7ea;
  transform: skewX(9deg);
}
.drift-head b { color: var(--cyan); }
.drift-bar {
  position: relative;
  height: 12px;
  margin-top: 4px;
  border-radius: 6px;
  background: rgba(6, 20, 32, 0.9);
  border: 1px solid rgba(55, 230, 255, 0.3);
  overflow: hidden;
}
.drift-bar i {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, #1f7bff, #37e6ff 55%, #ffffff);
  box-shadow: 0 0 16px rgba(55, 230, 255, 0.85);
  transition: width 0.06s linear;
}
.drift-bar u {
  position: absolute;
  left: 64%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 166, 61, 0.9);
  box-shadow: 0 0 10px rgba(255, 166, 61, 0.9);
}
.drift-wrap.perfect .drift-bar i { background: linear-gradient(90deg, #ff9c2b, #ffd24a, #fff); box-shadow: 0 0 20px rgba(255, 190, 60, 0.9); }
.drift-hint {
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #8ec9dd;
  transform: skewX(9deg);
  height: 12px;
}

.toasts {
  position: absolute;
  left: 50%;
  top: 21%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 640px;
}
.toast {
  font-size: 26px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  text-shadow: 0 0 24px rgba(55, 230, 255, 0.85), 0 3px 0 rgba(0, 30, 50, 0.5);
  animation: toastIn 0.22s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  white-space: nowrap;
}
.toast.small { font-size: 17px; font-weight: 700; }
.toast.perfect { color: #ffd24a; text-shadow: 0 0 28px rgba(255, 190, 60, 0.95); }
.toast.double { color: #ff6bd0; text-shadow: 0 0 30px rgba(255, 80, 200, 0.95); font-size: 34px; }
.toast.nitro { color: #7fe6ff; text-shadow: 0 0 30px rgba(80, 220, 255, 1); font-size: 34px; }
.toast.pad { color: #9dff9d; text-shadow: 0 0 24px rgba(120, 255, 150, 0.9); }
.toast.bad { color: #ff7a6b; text-shadow: 0 0 20px rgba(255, 90, 80, 0.8); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(0.86); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.toast.out { animation: toastOut 0.4s ease-in forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-22px) scale(1.06); }
}

.countdown {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 150px;
  font-weight: 900;
  font-style: italic;
  color: #fff;
  text-shadow: 0 0 50px rgba(55, 230, 255, 0.95), 0 0 12px rgba(255, 255, 255, 0.9);
  opacity: 0;
}
.countdown.show { animation: cdPop 0.9s ease-out both; }
.countdown.go { color: var(--orange); text-shadow: 0 0 60px rgba(255, 166, 61, 0.95); }
@keyframes cdPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.86); }
}

/* 氮气/极速屏幕效果：只做边缘柔光，避免盖住画面 */
.boost-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  background: radial-gradient(ellipse 78% 78% at 50% 50%, transparent 55%, rgba(70, 200, 255, 0.10) 82%, rgba(20, 110, 220, 0.26) 100%);
}
.boost-fx.on { opacity: 1; }
.boost-fx.nitro {
  background: radial-gradient(ellipse 72% 72% at 50% 50%, transparent 48%, rgba(90, 215, 255, 0.14) 78%, rgba(20, 120, 240, 0.34) 100%);
}

.hintbar.dim { opacity: 0.18; transition: opacity 1.2s; }
.hintbar {
  position: absolute;
  right: 20px;
  bottom: 258px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  width: 400px;
  font-size: 11.5px;
  color: #e2f6ff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  opacity: 0.85;
}
.hintbar span { display: flex; align-items: center; gap: 4px; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(12, 34, 52, 0.9);
  border: 1px solid rgba(55, 230, 255, 0.4);
  border-bottom-width: 2px;
  font-size: 11px;
  font-family: inherit;
  color: #d9f6ff;
  text-align: center;
  line-height: 1.2;
}

/* ================= 覆盖层 ================= */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 42%, rgba(6, 26, 44, 0.58), rgba(2, 8, 16, 0.82));
  backdrop-filter: blur(3px);
  pointer-events: auto;
  animation: fadeIn 0.35s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.ov-bg {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, rgba(55, 230, 255, 0.05) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(0deg, rgba(55, 230, 255, 0.04) 0 1px, transparent 1px 46px);
  mask-image: radial-gradient(ellipse at 50% 50%, black 10%, transparent 72%);
  pointer-events: none;
}

.start-card {
  position: relative;
  width: min(760px, 92vw);
  max-height: 92vh;
  overflow: auto;
  padding: 30px 34px 24px;
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(8, 30, 48, 0.95), rgba(4, 12, 22, 0.97));
  border: 1px solid rgba(55, 230, 255, 0.35);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7), inset 0 0 70px rgba(55, 230, 255, 0.06);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%);
}
.start-card.small { width: min(560px, 92vw); text-align: center; }
.start-card h1 {
  margin: 6px 0 4px;
  font-size: 46px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.02em;
  background: linear-gradient(100deg, #ffffff, #8fe9ff 45%, #1f7bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(55, 230, 255, 0.45));
}
.start-card h2 { font-size: 30px; margin: 4px 0 16px; font-style: italic; color: #d8f4ff; }
.start-tag {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--cyan);
  opacity: 0.85;
}
.start-card .sub { color: #8ec9dd; font-size: 13px; letter-spacing: 0.06em; margin-bottom: 18px; }

.keys-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  margin: 14px 0 18px;
  text-align: left;
}
.krow { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: #cfe9f5; }
.krow span { color: #9dc6d6; }

.tips { text-align: left; font-size: 12.5px; line-height: 1.65; color: #b9d8e4; margin: 0 0 20px; }
.tips p { margin: 3px 0; }
.tips b { color: var(--cyan); }
.tips kbd { padding: 1px 5px; font-size: 10.5px; }

.btn {
  pointer-events: auto;
  cursor: pointer;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #04121c;
  padding: 13px 46px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(100deg, #37e6ff, #1f7bff);
  box-shadow: 0 10px 30px rgba(31, 123, 255, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.12s, box-shadow 0.12s;
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(55, 230, 255, 0.55); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent;
  color: #a9d8e8;
  border: 1px solid rgba(55, 230, 255, 0.45);
  box-shadow: none;
}
.row-btns { display: flex; gap: 12px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.foot { margin-top: 14px; font-size: 11px; color: #6f9cae; letter-spacing: 0.08em; }

.result-table { margin: 12px 0 6px; }
.btn.ghost {
  background: transparent;
  border: 1px solid rgba(120, 210, 240, 0.45);
  color: #bfe6f4;
  box-shadow: none;
}
.btn.ghost:hover { border-color: var(--cyan); color: #eafcff; }
.rrow {
  display: grid;
  grid-template-columns: 34px 1fr 92px 92px;
  gap: 8px;
  padding: 9px 12px;
  font-size: 14px;
  align-items: center;
  border-radius: 8px;
  text-align: left;
}
.rrow.head { font-size: 10.5px; letter-spacing: 0.2em; color: #7fd7ea; opacity: 0.75; padding-bottom: 2px; }
.rrow.me { background: linear-gradient(90deg, rgba(55, 230, 255, 0.18), transparent); border-left: 3px solid var(--cyan); }
.rrow .rk { font-weight: 900; font-style: italic; color: var(--cyan); font-size: 17px; }
.rrow .tm { color: #d8f4ff; text-align: right; font-variant-numeric: tabular-nums; }
.rrow .bl { color: #b9d7e4; text-align: right; font-variant-numeric: tabular-nums; }
.rrow .bl.best { color: #ffd24a; font-weight: 700; text-shadow: 0 0 12px rgba(255, 200, 70, 0.55); }
.rrow.head span:nth-child(3), .rrow.head span:nth-child(4) { text-align: right; }
.result-stats {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0 4px;
  font-size: 12px;
  color: #9dc6d6;
}
.result-stats b { color: #eaf6ff; font-size: 16px; display: block; }

@media (max-width: 900px) {
  .hud-tl { width: 140px; }
  .panel b { font-size: 16px; }
  .drift-wrap { width: 220px; bottom: 18px; }
  .hintbar { display: none; }
  .hud-minimap { width: 130px; height: 130px; }
  .hud-minimap canvas { width: 130px; height: 130px; }
  .speedo-wrap { width: 170px; height: 170px; }
  #speedo { width: 170px; height: 170px; }
  .nos { top: 64px; width: 110px; }
  .toasts { width: 92vw; }
  .start-card h1 { font-size: 34px; }
  .keys-grid { grid-template-columns: 1fr; }
}