:root {
  --bg: #04050c;
  --ink: #e9f0fc;
  --muted: #8494b3;
  --cyan: #5ff0ff;
  --magenta: #ff4fd8;
  --violet: #9d7bff;
  --line: rgba(120, 170, 230, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: none;
}

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

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 38%, rgba(2, 3, 8, 0.62) 100%);
}

.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: #a3b9dd;
  text-transform: uppercase;
}

.brand-dot {
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  background: var(--cyan);
  box-shadow: 0 0 12px rgba(95, 240, 255, 0.9), 0 0 24px rgba(95, 240, 255, 0.5);
}

.brand-name { font-weight: 700; }

.brand-cn {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: rgba(150, 180, 220, 0.45);
  margin-left: 4px;
}

#scorebar {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 9px;
  border-radius: 999px;
  background: rgba(9, 15, 30, 0.55);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
}

.chip i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
  flex: none;
}

.chip .nm {
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #b8c8e6;
}

.chip .sc {
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 9px;
  text-align: right;
}

.chip.bot .nm { color: #8593b0; }

.chip.me {
  border-color: rgba(95, 240, 255, 0.55);
  background: rgba(16, 40, 60, 0.6);
  box-shadow: 0 0 18px rgba(95, 240, 255, 0.14);
}

.chip.me .nm { color: #ecfeff; }

.chip.dead { opacity: 0.32; }

.topright {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: #7c8dad;
  font-variant-numeric: tabular-nums;
}

#ping.bad { color: #ff8a8a; }

#soundBtn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(9, 15, 30, 0.5);
  color: #cfe6ff;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  pointer-events: auto;
  transition: color 0.2s ease, border-color 0.2s ease;
}

#soundBtn:hover { border-color: rgba(95, 240, 255, 0.4); }
#soundBtn.muted { color: #5a6a88; }

/* ---------- 中央横幅 ---------- */
#banner {
  position: fixed;
  top: 24%;
  left: 50%;
  width: 100%;
  padding: 0 24px;
  text-align: center;
  transform: translate(-50%, -50%) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#banner-kicker {
  font-size: 10px;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 10px;
  opacity: 0.9;
  text-shadow: 0 0 18px rgba(95, 240, 255, 0.55);
}

#banner-title {
  font-size: clamp(56px, 11vw, 128px);
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: #f3f9ff;
  text-shadow: 0 0 40px rgba(95, 240, 255, 0.35), 0 0 90px rgba(120, 80, 255, 0.25);
}

#banner-sub {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.34em;
  color: #93a8cc;
}

#banner.tone-count #banner-title { font-size: clamp(88px, 16vw, 178px); }

#banner.tone-kill #banner-title {
  color: #ffd9f6;
  text-shadow: 0 0 40px rgba(255, 79, 216, 0.5), 0 0 100px rgba(255, 79, 216, 0.25);
}

#banner.tone-kill #banner-kicker { color: var(--magenta); text-shadow: 0 0 18px rgba(255, 79, 216, 0.6); }

#banner.tone-win #banner-title {
  background: linear-gradient(100deg, #ffffff 10%, #8df6ff 45%, #ff8be8 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 40px rgba(120, 200, 255, 0.4));
}

/* ---------- 冲刺条 ---------- */
#dashmeter {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(260px, 48vw);
  z-index: 11;
}

.dash-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
  font-size: 9px;
  letter-spacing: 0.26em;
  color: #687b9c;
}

.dash-label { transition: color 0.2s ease, text-shadow 0.2s ease; }
#dashmeter.ready .dash-label {
  color: #7df3ff;
  text-shadow: 0 0 12px rgba(95, 240, 255, 0.65);
}

.dash-key { letter-spacing: 0.12em; font-size: 9px; color: #4d5d7c; }

.dash-track {
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

#dashfill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--magenta), var(--cyan));
  box-shadow: 0 0 14px rgba(95, 240, 255, 0.8);
  transition: width 0.08s linear, background 0.3s ease, box-shadow 0.3s ease;
}

#dashmeter:not(.ready) #dashfill {
  background: linear-gradient(90deg, #5a2a6a, #2e6a80);
  box-shadow: none;
}

#helpline {
  position: fixed;
  bottom: 14px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: rgba(120, 135, 165, 0.5);
  pointer-events: none;
}

/* ---------- 移动端 ---------- */
#mobile { display: none; }

body.touch #mobile {
  display: flex;
  position: fixed;
  left: 22px;
  right: 22px;
  bottom: 24px;
  align-items: flex-end;
  justify-content: space-between;
  z-index: 12;
  pointer-events: none;
}

#stick {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 1px solid rgba(120, 200, 255, 0.18);
  background: rgba(10, 20, 40, 0.35);
  backdrop-filter: blur(6px);
  position: relative;
  pointer-events: auto;
  touch-action: none;
}

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b7f9ff, #3cc8e8 60%, #1a5f8a);
  box-shadow: 0 0 22px rgba(95, 240, 255, 0.45), inset 0 0 10px rgba(0, 0, 0, 0.25);
  will-change: transform;
}

#dashBtn {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(140deg, #6ff3ff, #9d7bff 60%, #ff4fd8);
  color: #051018;
  font-size: 19px;
  font-weight: 900;
  font-family: inherit;
  letter-spacing: 0.05em;
  pointer-events: auto;
  box-shadow: 0 0 30px rgba(120, 160, 255, 0.35);
  touch-action: none;
}

body.touch #dashmeter { bottom: 132px; }
body.touch #helpline { display: none; }
body.touch .topright { gap: 8px; }

/* ---------- 开始界面 ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 56px 24px;
  overflow: auto;
  background:
    radial-gradient(58% 58% at 24% 28%, rgba(30, 70, 145, 0.3), transparent 70%),
    radial-gradient(52% 52% at 82% 72%, rgba(120, 30, 120, 0.2), transparent 70%),
    rgba(3, 4, 10, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 180, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 180, 255, 0.05) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000, transparent 76%);
  mask-image: radial-gradient(ellipse at center, #000, transparent 76%);
  pointer-events: none;
}

.overlay-inner {
  position: relative;
  width: min(760px, 100%);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 9px;
  letter-spacing: 0.38em;
  color: #6fd9ee;
}

.eyebrow .line {
  width: 28px;
  height: 1px;
  background: linear-gradient(90deg, var(--cyan), transparent);
}

#overlay h1 {
  margin: 20px 0 0;
  font-size: clamp(64px, 12vw, 132px);
  line-height: 0.95;
  font-weight: 900;
  letter-spacing: -0.045em;
  color: #f0f5ff;
}

#overlay h1 span {
  background: linear-gradient(100deg, #5ff0ff 8%, #9d7bff 52%, #ff56d8 96%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 28px rgba(120, 120, 255, 0.35));
}

.tagline {
  margin: 24px 0 30px;
  max-width: 44ch;
  font-size: 14px;
  line-height: 1.75;
  color: #93a4c4;
}

.join-row {
  display: flex;
  gap: 10px;
  max-width: 470px;
}

#nameInput {
  flex: 1;
  min-width: 0;
  height: 50px;
  padding: 0 16px;
  background: rgba(8, 14, 28, 0.7);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.04em;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#nameInput::placeholder { color: #55658a; }

#nameInput:focus {
  border-color: rgba(95, 240, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(95, 240, 255, 0.08), 0 0 24px rgba(95, 240, 255, 0.12);
}

#joinBtn {
  height: 50px;
  padding: 0 22px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(120deg, #63f2ff, #9d7bff);
  color: #040a12;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease, opacity 0.2s ease;
}

#joinBtn:hover { filter: brightness(1.08); }
#joinBtn:active { transform: scale(0.98); }
#joinBtn:disabled { opacity: 0.55; cursor: wait; }

.join-meta {
  margin-top: 12px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #61718f;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 42px;
  margin-top: 42px;
  padding-top: 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }
body.touch .dash-key { display: none; }

.controls b {
  display: block;
  margin-bottom: 6px;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #cfe0ff;
}

.controls span {
  font-size: 10px;
  letter-spacing: 0.05em;
  color: #6b7c9c;
}

.hint {
  margin-top: 24px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: #526180;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translate(-50%, -8px);
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(120, 170, 230, 0.2);
  background: rgba(8, 14, 28, 0.9);
  backdrop-filter: blur(8px);
  color: #dbe9ff;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 60;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  #topbar { padding: 12px 14px; gap: 8px; }
  .brand-cn { display: none; }
  .brand { letter-spacing: 0.18em; }
  #scorebar { gap: 4px; }
  .chip { padding: 4px 8px 4px 7px; font-size: 9px; }
  .chip .nm { max-width: 62px; }
  .chip .sc { font-size: 10px; }
  #overlay { padding: 40px 20px; }
  .tagline { font-size: 13px; }
  .controls { gap: 24px; margin-top: 32px; }
  #helpline { display: none; }
  #dashmeter { bottom: 26px; }
}

@media (max-width: 560px) {
  #topbar { flex-wrap: wrap; }
  #scorebar { flex-basis: 100%; order: 3; margin-top: 2px; }
  .brand { font-size: 9px; }
  .topright { margin-left: auto; }
  #overlay h1 { font-size: clamp(58px, 19vw, 92px); }
  .join-row { flex-direction: column; }
  #joinBtn { width: 100%; }
  .controls { gap: 18px 26px; }
  .controls > div { min-width: 108px; }
  #banner { top: 27%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
