:root {
  --cyan: #00ffe1;
  --magenta: #ff2fd6;
  --yellow: #ffe95c;
  --bg: #05010f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Rajdhani', 'Microsoft YaHei', sans-serif;
  color: #d8e6ff;
  user-select: none;
}

#game-container { position: fixed; inset: 0; }
#game-container canvas { display: block; }

.hidden { display: none !important; }

/* ---- CRT 扫描线氛围 ---- */
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: repeating-linear-gradient(
    to bottom, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 3px, rgba(0,0,0,.14) 4px);
  mix-blend-mode: multiply;
  box-shadow: inset 0 0 220px rgba(2, 0, 20, .85);
}

/* ================= 开始 / 结束界面 ================= */
#start-screen, #end-screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px;
  background: radial-gradient(ellipse at 50% 120%, rgba(255,47,214,.16), transparent 60%),
              radial-gradient(ellipse at 50% -20%, rgba(0,255,225,.12), transparent 55%),
              rgba(4, 1, 14, .82);
  backdrop-filter: blur(3px);
  text-align: center;
}

.title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(52px, 9vw, 108px);
  letter-spacing: .12em;
  color: #fff;
  text-shadow: 0 0 8px var(--cyan), 0 0 28px var(--cyan), 0 0 60px rgba(0,255,225,.6);
  animation: flicker 4s infinite;
}
.title span {
  color: var(--magenta);
  text-shadow: 0 0 8px var(--magenta), 0 0 28px var(--magenta), 0 0 60px rgba(255,47,214,.6);
  margin-left: .18em;
}
.title.small { font-size: clamp(26px, 4vw, 44px); }

@keyframes flicker {
  0%, 91%, 94%, 100% { opacity: 1; }
  92% { opacity: .55; }
  93% { opacity: .85; }
}

.subtitle {
  font-size: clamp(16px, 2.2vw, 24px);
  letter-spacing: .55em; text-indent: .55em;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0,255,225,.8);
}

.rules { font-size: 17px; color: #9fb0d8; letter-spacing: .12em; }

/* ---- 开始界面设置面板：赛道 / 圈数 / AI 数量 ---- */
.settings {
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 26px;
  border: 1px solid rgba(255, 47, 214, .3);
  border-radius: 6px;
  background: rgba(20, 4, 30, .35);
  box-shadow: 0 0 24px rgba(255, 47, 214, .08), inset 0 0 24px rgba(255, 47, 214, .04);
}
.set-row { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.set-label {
  font-family: 'Orbitron', sans-serif; font-size: 12px;
  letter-spacing: .3em; color: var(--magenta);
  text-shadow: 0 0 8px rgba(255, 47, 214, .7);
  width: 86px; text-align: right; flex-shrink: 0;
}
.set-group { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.set-btn {
  font-family: 'Rajdhani', 'Microsoft YaHei', sans-serif;
  font-weight: 600; font-size: 15px; letter-spacing: .08em;
  padding: 7px 18px;
  clip-path: none; border-radius: 3px;
  background: rgba(8, 12, 32, .6);
  color: #9fb0d8;
  border: 1px solid rgba(0, 255, 225, .22);
  box-shadow: none;
  transition: background .12s, color .12s, box-shadow .12s, border-color .12s;
}
.set-btn:hover {
  transform: none; filter: none;
  box-shadow: 0 0 10px rgba(0, 255, 225, .3);
  color: #d8e6ff;
}
.set-btn.selected {
  background: rgba(0, 255, 225, .16);
  color: #fff;
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(0, 255, 225, .45);
  text-shadow: 0 0 8px rgba(0, 255, 225, .8);
}

.controls-grid {
  display: grid; grid-template-columns: repeat(3, auto);
  gap: 10px 34px;
  padding: 18px 30px;
  border: 1px solid rgba(0,255,225,.35);
  border-radius: 6px;
  background: rgba(0, 20, 30, .35);
  box-shadow: 0 0 24px rgba(0,255,225,.12), inset 0 0 24px rgba(0,255,225,.05);
  font-size: 16px; color: #b9c8ea;
}
.controls-grid b {
  font-family: 'Orbitron', sans-serif; font-size: 13px;
  color: var(--yellow); margin-right: 8px;
  text-shadow: 0 0 8px rgba(255,233,92,.7);
}

button {
  font-family: 'Orbitron', sans-serif;
  font-size: 20px; font-weight: 700; letter-spacing: .2em;
  padding: 16px 54px;
  color: #041018;
  background: linear-gradient(90deg, var(--cyan), #43ffd9);
  border: none; border-radius: 4px;
  cursor: pointer;
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
  box-shadow: 0 0 24px rgba(0,255,225,.55);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s;
}
button:hover { transform: scale(1.05); box-shadow: 0 0 44px rgba(0,255,225,.9); filter: brightness(1.1); }
button:active { transform: scale(.97); }

#end-rank {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(40px, 7vw, 84px); font-weight: 900; letter-spacing: .1em;
  color: var(--yellow);
  text-shadow: 0 0 12px var(--yellow), 0 0 42px rgba(255,233,92,.65);
}
#end-stats {
  font-family: 'Orbitron', sans-serif;
  font-size: 16px; line-height: 2.1; letter-spacing: .14em;
  color: #cfe0ff;
}
#end-stats .k { color: #7f8fb8; margin-right: 14px; }
#end-stats .v { color: var(--cyan); text-shadow: 0 0 10px rgba(0,255,225,.7); }

/* ================= HUD ================= */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 30; }

.hud-top {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: stretch;
}
.hud-box {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 96px;
  padding: 8px 18px;
  background: rgba(5, 8, 26, .55);
  border: 1px solid rgba(0,255,225,.4);
  border-radius: 4px;
  box-shadow: 0 0 16px rgba(0,255,225,.12);
}
.label {
  font-family: 'Orbitron', sans-serif; font-size: 10px;
  letter-spacing: .3em; color: var(--magenta);
  text-shadow: 0 0 8px rgba(255,47,214,.8);
}
.big {
  font-family: 'Orbitron', sans-serif; font-size: 26px; font-weight: 700;
  color: #fff; text-shadow: 0 0 10px rgba(0,255,225,.9);
}
.time-box { min-width: 220px; }
.sub-times { display: flex; gap: 16px; font-size: 13px; color: #8fa3cf; font-family: 'Orbitron', sans-serif; }
#hud-best { color: var(--yellow); }

.hud-bottom {
  position: absolute; bottom: 24px; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 36px;
}

#nitro-box { width: 300px; }
#nitro-box .label { margin-bottom: 6px; text-align: left; }
#nitro-bar {
  height: 14px;
  border: 1px solid rgba(0,255,225,.55);
  border-radius: 3px;
  background: rgba(0, 20, 30, .5);
  overflow: hidden;
  transform: skewX(-18deg);
}
#nitro-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #0066ff, var(--cyan));
  box-shadow: 0 0 14px var(--cyan);
  transition: width .08s linear;
}
#nitro-fill.burning { background: linear-gradient(90deg, #7b2fff, var(--magenta)); box-shadow: 0 0 18px var(--magenta); }

#speed-box { display: flex; align-items: baseline; gap: 10px; }
#hud-speed {
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: 64px; color: #fff;
  text-shadow: 0 0 12px var(--cyan), 0 0 40px rgba(0,255,225,.5);
}
.unit { font-family: 'Orbitron', sans-serif; font-size: 14px; color: var(--magenta); letter-spacing: .2em; }

#toast {
  position: absolute; top: 34%; left: 50%; transform: translateX(-50%);
  font-family: 'Orbitron', sans-serif; font-size: 44px; font-weight: 900;
  letter-spacing: .25em; color: var(--yellow);
  text-shadow: 0 0 14px var(--yellow), 0 0 50px rgba(255,233,92,.7);
  opacity: 0; transition: opacity .25s;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

#mute-ind {
  position: absolute; top: 18px; right: 22px;
  font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: .2em;
  color: #ff6a6a; text-shadow: 0 0 8px rgba(255,80,80,.8);
}

/* ================= 倒计时 ================= */
#countdown {
  position: fixed; inset: 0; z-index: 35;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: clamp(90px, 18vw, 220px);
  color: var(--cyan);
  text-shadow: 0 0 20px var(--cyan), 0 0 90px rgba(0,255,225,.8);
}
#countdown.go { color: var(--yellow); text-shadow: 0 0 20px var(--yellow), 0 0 90px rgba(255,233,92,.9); }
#countdown.pop { animation: pop .9s ease-out; }
@keyframes pop {
  0% { transform: scale(1.7); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: .2; }
}

/* ================= 移动端适配 ================= */
html, body { overscroll-behavior: none; }
body {
  touch-action: none;               /* 禁止滚动/双击缩放等默认手势 */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* 移动端静音按钮（触屏设备无 M 键） */
#mute-btn {
  display: none;
  position: fixed; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  z-index: 33; width: 44px; height: 44px; padding: 0;
  font-size: 20px; letter-spacing: 0; clip-path: none; border-radius: 50%;
  background: rgba(5, 10, 30, .6); color: var(--cyan);
  border: 1px solid rgba(0, 255, 225, .5);
  box-shadow: 0 0 12px rgba(0, 255, 225, .25);
}
body.touch-device #mute-btn { display: block; }

/* ---- 触控按键 ---- */
#touch-controls { position: fixed; inset: 0; z-index: 32; pointer-events: none; }
.tc-left, .tc-right {
  position: absolute;
  bottom: calc(26px + env(safe-area-inset-bottom));
}
.tc-left { left: calc(18px + env(safe-area-inset-left)); display: flex; gap: 16px; }
.tc-right {
  right: calc(18px + env(safe-area-inset-right));
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  grid-template-areas: "nitro gas" "brake gas";
}
#tc-nitro { grid-area: nitro; }
#tc-brake { grid-area: brake; }
#tc-gas { grid-area: gas; }

.tc-btn {
  pointer-events: auto;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  width: 72px; height: 72px; padding: 0;
  border-radius: 50%; clip-path: none;
  font-family: 'Orbitron', sans-serif; font-size: 24px; letter-spacing: 0;
  color: #aefcff;
  background: rgba(6, 12, 34, .5);
  border: 2px solid rgba(0, 255, 225, .55);
  box-shadow: 0 0 14px rgba(0, 255, 225, .2);
  backdrop-filter: blur(3px);
  transition: none;
}
.tc-btn:hover { transform: none; filter: none; }
.tc-btn:active, .tc-btn.active {
  background: rgba(0, 255, 225, .35); color: #fff;
  box-shadow: 0 0 22px rgba(0, 255, 225, .8);
  transform: none;
}
#tc-gas { width: 96px; height: 96px; font-size: 32px; }
#tc-nitro {
  font-size: 16px; color: #ffb8ef;
  border-color: rgba(255, 47, 214, .6);
  box-shadow: 0 0 14px rgba(255, 47, 214, .25);
}
#tc-nitro:active, #tc-nitro.active {
  background: rgba(255, 47, 214, .35);
  box-shadow: 0 0 22px rgba(255, 47, 214, .85);
}
#tc-brake { color: #ffd0d0; border-color: rgba(255, 90, 90, .55); }

/* ---- 竖屏提示 ---- */
#rotate-hint {
  position: fixed; inset: 0; z-index: 45;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center; cursor: pointer;
  background: rgba(4, 1, 14, .92);
}
.rotate-phone { font-size: 64px; animation: rotatePhone 1.6s ease-in-out infinite; }
@keyframes rotatePhone {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(90deg); }
}
.rotate-text {
  font-family: 'Orbitron', sans-serif; font-size: 22px;
  color: var(--cyan); letter-spacing: .2em;
  text-shadow: 0 0 12px rgba(0, 255, 225, .7);
}
.rotate-sub { color: #8fa3cf; font-size: 15px; }

/* ---- 小屏 HUD 缩放 ---- */
@media (max-width: 900px) {
  .title { font-size: clamp(38px, 11vw, 72px); }
  .subtitle { letter-spacing: .3em; text-indent: .3em; }
  .rules { font-size: 14px; padding: 0 16px; }
  .settings { gap: 10px; padding: 12px 14px; }
  .set-label { width: auto; flex-basis: 100%; text-align: center; }
  .set-btn { font-size: 13px; padding: 6px 13px; }
  .controls-grid {
    grid-template-columns: repeat(2, auto);
    gap: 8px 22px; font-size: 13px; padding: 14px 18px;
  }
  button { font-size: 16px; padding: 14px 36px; }
  .hud-top { gap: 6px; top: calc(10px + env(safe-area-inset-top)); }
  .hud-box { min-width: 62px; padding: 5px 10px; }
  .big { font-size: 18px; }
  .time-box { min-width: 130px; }
  .sub-times { font-size: 9px; gap: 8px; flex-wrap: wrap; justify-content: center; }
  #toast { font-size: 26px; top: 26%; }
  #hud-speed { font-size: 40px; }
  .unit { font-size: 11px; }
  #nitro-box { width: 170px; }
}

/* ---- 触屏设备：HUD 上移，底部空间留给虚拟按键 ---- */
body.touch-device .hud-bottom { padding: 0; }
body.touch-device #speed-box {
  position: fixed;
  top: calc(78px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
}
body.touch-device #nitro-box {
  position: fixed;
  top: calc(78px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  width: 150px;
}

/* ================= 联机：账号栏 / 弹窗 / 排行榜 ================= */
#net-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 10px 0 4px;
  flex-wrap: wrap;
}
.net-btn {
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1px;
  color: #bfeaff;
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.45);
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
  transition: all .15s;
}
.net-btn:hover { background: rgba(0, 229, 255, 0.22); box-shadow: 0 0 14px rgba(0, 229, 255, .45); }
.net-btn.accent { color: #051018; background: linear-gradient(90deg, #00e5ff, #37ffc8); border: none; }
.net-btn.accent:hover { box-shadow: 0 0 20px rgba(0, 229, 255, .7); }
.net-btn.wechat { color: #0a2; background: rgba(60, 220, 120, 0.12); border-color: rgba(60, 220, 120, .6); color: #7dffa8; }
.net-btn.ghost { color: #8fa3b8; background: transparent; border-color: rgba(143, 163, 184, .35); }
.net-btn.small { padding: 3px 10px; font-size: 13px; }
.net-btn.full { display: block; width: 100%; margin-top: 10px; }
#net-userbox { display: inline-flex; align-items: center; gap: 8px; color: #37ffc8; font-weight: 700; }
#announcement {
  max-width: 560px; margin: 2px auto 8px; color: #ffd27d; font-size: 14px;
  text-shadow: 0 0 8px rgba(255, 180, 60, .5);
}

/* 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 5, 14, 0.78); backdrop-filter: blur(4px);
}
.modal-box {
  position: relative;
  width: min(400px, 92vw);
  max-height: 86vh; overflow-y: auto;
  background: linear-gradient(160deg, rgba(13, 17, 38, .97), rgba(20, 10, 40, .97));
  border: 1px solid rgba(0, 229, 255, .5);
  box-shadow: 0 0 40px rgba(0, 229, 255, .25), inset 0 0 30px rgba(0, 229, 255, .05);
  border-radius: 10px;
  padding: 26px 24px 22px;
}
.modal-box.wide { width: min(560px, 94vw); }
.modal-title {
  font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 19px;
  color: #00e5ff; text-align: center; letter-spacing: 3px; margin-bottom: 16px;
  text-shadow: 0 0 16px rgba(0, 229, 255, .7);
}
.modal-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: #8fa3b8; font-size: 18px; cursor: pointer;
}
.modal-close:hover { color: #ff2fd6; }

/* 登录弹窗 */
.auth-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.auth-tab {
  flex: 1; padding: 8px 0; font-weight: 700; font-size: 15px; letter-spacing: 2px;
  background: transparent; color: #8fa3b8; border: 1px solid rgba(143, 163, 184, .3);
  border-radius: 6px; cursor: pointer;
}
.auth-tab.selected { color: #051018; background: linear-gradient(90deg, #00e5ff, #37ffc8); border-color: transparent; }
.auth-input {
  display: block; width: 100%; box-sizing: border-box; margin-top: 10px;
  padding: 11px 12px; font-size: 15px; color: #eafcff;
  background: rgba(0, 20, 35, .7); border: 1px solid rgba(0, 229, 255, .35); border-radius: 6px;
  outline: none;
}
.auth-input:focus { border-color: #00e5ff; box-shadow: 0 0 10px rgba(0, 229, 255, .35); }
.auth-msg { min-height: 20px; margin-top: 8px; font-size: 13px; color: #ff6b8a; text-align: center; }

/* 排行榜 */
.lb-filters { display: flex; gap: 8px; margin-bottom: 12px; }
.lb-filters select {
  flex: 1; padding: 8px; font-size: 14px; color: #eafcff;
  background: rgba(0, 20, 35, .85); border: 1px solid rgba(0, 229, 255, .35); border-radius: 6px;
}
.lb-list { max-height: 46vh; overflow-y: auto; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; margin-bottom: 6px;
  background: rgba(0, 229, 255, .05); border-left: 3px solid rgba(0, 229, 255, .4);
  border-radius: 4px; font-size: 15px;
}
.lb-row.top0 { border-left-color: #ffd700; background: rgba(255, 215, 0, .1); }
.lb-row.top1 { border-left-color: #c0c0c0; background: rgba(192, 192, 192, .08); }
.lb-row.top2 { border-left-color: #cd7f32; background: rgba(205, 127, 50, .08); }
.lb-rank { width: 28px; text-align: center; font-family: 'Orbitron', sans-serif; font-weight: 700; color: #00e5ff; }
.lb-row.top0 .lb-rank { color: #ffd700; }
.lb-name { flex: 1; color: #eafcff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-time { font-family: 'Orbitron', sans-serif; color: #37ffc8; font-size: 14px; }
.lb-empty { padding: 26px 0; text-align: center; color: #8fa3b8; }

/* 结算界面联机状态 */
#end-net { margin: 8px 0; font-size: 15px; color: #bfeaff; min-height: 24px; }
#end-net .hi { color: #ffd700; font-family: 'Orbitron', sans-serif; }
#end-net .net-btn { margin-top: 4px; }

@media (max-width: 640px) {
  .net-btn { font-size: 13px; padding: 7px 12px; }
  .modal-box { padding: 20px 16px 18px; }
}
