/* ============================================================
 * NEON DRIFT GP — 设计令牌与布局（design-plan.md 落地）
 * 竖屏 390×844 为主，横屏 1280×800 自适应；触控目标 ≥44px
 * ============================================================ */
:root {
  /* 场景色 */
  --bg: #070B14;
  --grass: #0C1812;
  --road: #171C2C;
  --curb: #E8E8F0;
  /* 霓虹 */
  --neon-cyan: #00E5FF;
  --neon-pink: #FF2D95;
  --neon-amber: #FFB300;
  --neon-lime: #B6FF00;
  --neon-violet: #9B6BFF;
  --neon-red: #FF3B3B;
  --neon-orange: #FF8A3D;
  --neon-green: #39D98A;
  /* HUD */
  --hud-text: #F2F6FF;
  --hud-dim: #BCC6E0;
  --glass: rgba(10, 16, 30, .72);
  --radius-btn: 12px;
  --radius-panel: 16px;
  /* 字体（零依赖系统栈） */
  --font: "SF Pro Display", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}

#boot-fallback { position: fixed; inset: 0; z-index: 99999; background: var(--bg); color: var(--hud-text);
  font-size: 16px; line-height: 1.7; text-align: center; padding: 24px;
  display: flex; align-items: center; justify-content: center; }
#boot-fallback p { max-width: 320px; }
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg);
  font-family: var(--font); color: var(--hud-text); touch-action: none; user-select: none; -webkit-user-select: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

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

.hidden { display: none !important; }

/* ============ 通用玻璃面板 ============ */
.glass { background: var(--glass); border: 1px solid rgba(0, 229, 255, .18);
  border-radius: var(--radius-panel); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

/* ============ HUD（竞速中；全部 pointer-events:none 仅显示）============ */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud-top-left { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 12px;
  padding: 8px 14px; width: auto; max-width: 200px; }
#hud-lap { font-size: 16px; font-weight: 700; letter-spacing: .06em; color: var(--hud-text); }
#hud-timer { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em;
  color: var(--hud-text); text-shadow: 0 0 10px rgba(0,229,255,.35); }
#hud-rank { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px;
  font-size: 40px; font-weight: 800; color: var(--neon-cyan);
  text-shadow: 0 0 14px rgba(0,229,255,.55); }
#hud-speed { position: absolute; right: 14px; bottom: calc(16px + env(safe-area-inset-bottom));
  text-align: right; }
#speed-val { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--hud-text);
  text-shadow: 0 0 12px rgba(0,229,255,.3); }
#hud-speed .unit { font-size: 14px; color: var(--hud-dim); margin-left: 4px; }
#minimap { position: absolute; left: 12px; bottom: calc(16px + env(safe-area-inset-bottom));
  width: 104px; height: 140px; border-radius: var(--radius-panel); background: var(--glass); }
#corner-arrow { position: absolute; left: 50%; bottom: calc(168px + env(safe-area-inset-bottom));
  transform: translateX(-50%); width: 44px; height: 44px; font-size: 34px; color: var(--neon-cyan);
  text-shadow: 0 0 12px rgba(0,229,255,.7); display: flex; align-items: center; justify-content: center; }

#btn-pause { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 11; width: 48px; height: 48px; border-radius: 50%; background: var(--glass);
  font-size: 18px; color: var(--hud-text); border: 1px solid rgba(0,229,255,.25); }

/* ============ 触控区 ============ */
#touch { position: fixed; inset: 0; z-index: 5; }
#touch-left, #touch-right { position: absolute; top: 0; bottom: 0; width: 50%; }
#touch-left { left: 0; } #touch-right { right: 0; }
#btn-brake { position: absolute; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%; background: var(--glass);
  border: 1px solid rgba(255,59,59,.5); color: var(--hud-text); font-size: 14px; font-weight: 700;
  z-index: 6; touch-action: none; }
#btn-brake:active { background: rgba(255,59,59,.3); }

/* ============ 菜单 ============ */
#menu { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #101A33 0%, var(--bg) 62%); }
#menu-title { font-size: 37px; font-weight: 800; letter-spacing: .09em; white-space: nowrap;
  color: var(--neon-cyan);
  text-shadow: 0 0 18px rgba(0,229,255,.65), 0 0 46px rgba(0,229,255,.3);
  animation: titlePulse 2.6s ease-in-out infinite; }
@keyframes titlePulse { 0%,100% { text-shadow: 0 0 18px rgba(0,229,255,.65), 0 0 46px rgba(0,229,255,.3); }
  50% { text-shadow: 0 0 26px rgba(0,229,255,.95), 0 0 66px rgba(0,229,255,.5); } }
#menu-sub { font-size: 14px; letter-spacing: .22em; color: var(--hud-dim); margin-top: -8px; }

#track-cards { display: flex; gap: 12px; width: 100%; max-width: 560px; justify-content: center; }
.track-card { flex: 1; max-width: 176px; padding: 10px 8px 12px; text-align: center;
  border-radius: var(--radius-panel); background: var(--glass);
  border: 1px solid rgba(255,255,255,.08); transition: transform .15s, border-color .15s, box-shadow .15s; }
.track-card .tc-thumb { width: 100%; height: 84px; border-radius: 8px; margin-bottom: 8px;
  background: var(--road); position: relative; overflow: hidden; }
.track-card .tc-name { font-size: 14px; font-weight: 700; letter-spacing: .08em; }
.track-card .tc-desc { font-size: 11px; color: var(--hud-dim); margin-top: 3px; }
.track-card.selected { border-color: var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0,229,255,.35); transform: translateY(-2px); }
.track-card .tc-accent { position: absolute; inset: 0; opacity: .5; }

#menu-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.seg { display: flex; background: var(--glass); border-radius: var(--radius-btn);
  border: 1px solid rgba(255,255,255,.08); overflow: hidden; }
.seg-btn { min-width: 56px; height: 44px; padding: 0 12px; font-size: 14px; color: var(--hud-dim);
  transition: background .15s, color .15s; }
.seg-btn.active { background: rgba(0,229,255,.16); color: var(--neon-cyan); font-weight: 700; }

#btn-start { min-width: 200px; height: 56px; border-radius: 28px; font-size: 18px; font-weight: 800;
  letter-spacing: .12em; color: #04121A; background: linear-gradient(135deg, var(--neon-cyan), #7DF9FF);
  box-shadow: 0 0 22px rgba(0,229,255,.5); transition: transform .12s, box-shadow .12s; }
#btn-start:active { transform: scale(.96); box-shadow: 0 0 10px rgba(0,229,255,.4); }
#menu-hint { font-size: 12px; color: var(--hud-dim); text-align: center; line-height: 1.7; }

/* ============ 倒计时 ============ */
#countdown { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: rgba(7,11,20,.55); gap: 10px; }
#cd-num { font-size: 150px; font-weight: 800; color: var(--neon-cyan);
  text-shadow: 0 0 40px rgba(0,229,255,.8); }
#cd-num.go { color: var(--neon-lime); text-shadow: 0 0 40px rgba(182,255,0,.8); }
#cd-track { font-size: 15px; letter-spacing: .2em; color: var(--hud-dim); }

/* ============ 结算 ============ */
#results { position: fixed; inset: 0; z-index: 25; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #101A33 0%, var(--bg) 62%); }
#res-title { font-size: 30px; font-weight: 800; letter-spacing: .1em; color: var(--neon-cyan);
  text-shadow: 0 0 16px rgba(0,229,255,.5); }
#res-rank { font-size: 18px; line-height: 1.9; color: var(--hud-text); text-align: center; }
#res-best { font-size: 14px; color: var(--hud-dim); }
#res-btns { display: flex; gap: 14px; margin-top: 8px; }
#res-btns button, #pause-overlay button, #error-overlay button {
  min-width: 132px; height: 50px; border-radius: 25px; font-size: 16px; font-weight: 700;
  background: var(--glass); border: 1px solid rgba(0,229,255,.3); color: var(--hud-text); }
#res-btns #btn-menu, #pause-overlay #btn-quit { border-color: rgba(255,255,255,.14); color: var(--hud-dim); }

/* ============ 暂停遮罩 ============ */
#pause-overlay { position: fixed; inset: 0; z-index: 28; display: flex; flex-direction: column;
  gap: 14px; align-items: center; justify-content: center; background: rgba(7,11,20,.78); }
#pause-overlay::before { content: '已暂停'; font-size: 22px; font-weight: 800; letter-spacing: .2em;
  color: var(--hud-text); margin-bottom: 8px; }

/* ============ 错误遮罩 ============ */
#error-overlay { position: fixed; inset: 0; z-index: 99; display: flex; flex-direction: column;
  gap: 16px; align-items: center; justify-content: center; background: var(--bg); }
#error-msg { font-size: 16px; color: var(--hud-text); max-width: 300px; text-align: center; line-height: 1.7; }

/* ============ 横屏适配（≥700px 宽）============ */
@media (orientation: landscape) and (min-width: 700px) {
  #menu { flex-direction: row; flex-wrap: wrap; gap: 26px; padding: 32px; }
  #menu-title { font-size: 56px; }
  #track-cards { max-width: none; }
  .track-card { max-width: 200px; }
  #hud-speed { right: auto; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); text-align: center; }
  #minimap { width: 150px; height: 200px; }
  #btn-brake { right: 40px; bottom: calc(24px + env(safe-area-inset-bottom)); }
  #corner-arrow { bottom: calc(240px + env(safe-area-inset-bottom)); }
}

/* ============ 无障碍 ============ */
@media (prefers-reduced-motion: reduce) {
  #menu-title { animation: none; }
}
:focus-visible { outline: 2px solid var(--neon-cyan); outline-offset: 2px; }
