:root {
  --cyan: #8ce9ef;
  --blue: #75acdf;
  --violet: #bda2ff;
  --text: #eaf0f8;
  --dim: #b6c3d6;
  --panel: rgba(10, 14, 24, 0.83);
  --line: rgba(169, 186, 220, 0.32);
  --gold: #ffbe82;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #02030a;
  color: var(--text);
  font-family: 'Noto Sans SC', system-ui, sans-serif;
  user-select: none;
}

#app, #app canvas { position: fixed; inset: 0; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }

.label { font-size: 12px; letter-spacing: 0.2em; color: var(--dim); }
.big, .mid, .speed, .tag { font-family: 'Orbitron', sans-serif; text-shadow: 0 2px 8px #090d17, 0 0 12px rgba(140, 233, 239, 0.22); }
.big { font-size: 30px; font-weight: 700; margin-bottom: 8px; }
.mid { font-size: 20px; font-weight: 700; }

.hud-tl { position: absolute; top: calc(20px + env(safe-area-inset-top, 0px)); left: calc(24px + env(safe-area-inset-left, 0px)); }
.hud-score {
  width: fit-content; margin-bottom: 10px; padding: 5px 11px 7px;
  border: 1px solid rgba(249, 186, 116, 0.48); border-left: 2px solid #f9ba74;
  border-radius: 3px 8px 8px 3px; background: rgba(23, 17, 16, 0.87);
}
.hud-score .label { color: #f5c693; font-weight: 700; }
.hud-score-value {
  color: #fff0ce; font: 700 clamp(18px, 3.2vw, 30px)/1.15 'Orbitron', sans-serif;
  font-variant-numeric: tabular-nums; text-shadow: 0 0 10px rgba(217, 143, 67, 0.35);
}
.hud-tr { position: absolute; top: calc(20px + env(safe-area-inset-top, 0px)); right: calc(24px + env(safe-area-inset-right, 0px)); text-align: right; }
.tag { display: inline-block; font-family: 'Noto Sans SC'; font-size: 12px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 20px; margin-bottom: 8px; color: var(--cyan); }

/* 连跳能量：满了闪光提醒 */
.energy { width: 190px; margin: 14px 0 0 auto; text-align: left; }
.energy-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; letter-spacing: 0.12em; color: var(--dim); }
.energy-head b { font-family: 'Orbitron'; font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.energy-bar { height: 10px; margin-top: 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); overflow: hidden; border: 1px solid rgba(120, 170, 255, 0.25); }
#energy-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7971c9, var(--violet)); }
.energy-hint { margin-top: 5px; font-size: 12px; font-weight: 700; color: var(--cyan); opacity: 0; transition: opacity 0.2s; }
.energy.full .energy-bar { border-color: var(--cyan); animation: energy-pulse 0.9s ease-in-out infinite; }
.energy.full #energy-fill { background: linear-gradient(90deg, var(--cyan), #fff, var(--cyan)); background-size: 200% 100%; animation: energy-shine 1.2s linear infinite; }
.energy.full .energy-head b { color: var(--cyan); text-shadow: 0 0 10px var(--cyan); }
.energy.full .energy-hint { opacity: 1; animation: energy-blink 0.9s ease-in-out infinite; }
@keyframes energy-pulse { 0%, 100% { box-shadow: 0 0 4px rgba(0, 255, 240, 0.4); } 50% { box-shadow: 0 0 18px rgba(0, 255, 240, 1), 0 0 34px rgba(0, 255, 240, 0.5); } }
@keyframes energy-shine { from { background-position: 200% 0; } to { background-position: 0 0; } }
@keyframes energy-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .energy.full .energy-bar, .energy.full #energy-fill, .energy.full .energy-hint { animation: none; } }

.progress {
  position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  width: min(40vw, 420px); height: 6px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.1); overflow: hidden;
}
#hud-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--violet)); box-shadow: 0 0 10px var(--violet); }

.hud-bottom { position: absolute; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); text-align: center; }
.speed-row { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.speed { font-size: 52px; font-weight: 900; }
.vmax { font-family: 'Orbitron', sans-serif; font-size: 18px; font-weight: 700; color: #7dffb0; min-width: 64px; }
.vmax.down { color: #ff8a7a; }
.unit { font-family: 'Orbitron'; font-size: 13px; color: var(--dim); }
.speedbar { width: 280px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin-top: 4px; }
#hud-speed-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--cyan)); box-shadow: 0 0 12px var(--cyan); transition: width 0.08s linear; }
#hud-speed-fill.boost { background: linear-gradient(90deg, var(--cyan), #fff); }

#radar { position: absolute; right: calc(20px + env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); width: 200px; height: 200px; filter: drop-shadow(0 0 6px rgba(0, 200, 255, 0.4)); }

#hud-tip {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) scale(0.9);
  font-size: 28px; font-weight: 900; letter-spacing: 0.15em; color: var(--cyan);
  text-shadow: 0 0 16px var(--cyan); opacity: 0; transition: opacity 0.2s, transform 0.2s;
}
#hud-tip.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

#countdown {
  position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%);
  font-family: 'Orbitron'; font-size: 120px; font-weight: 900; color: #fff;
  text-shadow: 0 0 24px var(--violet), 0 0 44px var(--violet); pointer-events: none;
}
#countdown.pop { animation: pop 0.9s ease-out; }
@media (prefers-reduced-motion: reduce) { #countdown.pop { animation: none; } }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.85; } }

/* ---------- 面板 ---------- */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: radial-gradient(ellipse at center, rgba(2, 3, 12, 0.15), rgba(2, 3, 12, 0.56));
}
#menu {
  isolation: isolate;
  background-image: none;
  background-position: center;
  background-size: cover;
}
.menu-booting #menu .panel { visibility: hidden; }
.skyline-menu #menu { background-image: url('assets/level1/sky/skyline.webp'); }
.wasteland-menu #menu {
  --panel: rgba(28, 21, 20, 0.88);
  --line: rgba(222, 164, 116, 0.38);
  --text: #fcf0e3;
  --dim: #d9c3af;
  --violet: #ffc596;
  --cyan: #ffd8af;
  background-color: #231913;
  background-image: url('assets/level1/themes/wasteland/menu.webp');
}
#menu::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(2, 3, 12, 0.11), rgba(2, 3, 12, 0.42));
}
#skyline-motion {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease-in-out;
}
#skyline-motion.ready { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #skyline-motion { display: none; } }
.panel {
  width: min(760px, 100%); max-height: 100%; overflow: auto;
  padding: 36px 40px; border: 1px solid var(--line); border-top-color: var(--violet); border-radius: 4px 18px 4px 18px;
  background: linear-gradient(147deg, rgba(135, 160, 196, 0.13), transparent 38%), var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: 0 22px 60px rgba(0, 0, 10, 0.65);
  text-align: center;
}
.panel.small { width: min(440px, 100%); }

h1 { margin: 0; font-family: 'Orbitron', 'Noto Sans SC', sans-serif; font-size: 56px; font-weight: 900; letter-spacing: 0.1em; background: linear-gradient(178deg, #ffffff 12%, #d8e6f4 46%, #a4afcf 80%); -webkit-background-clip: text; background-clip: text; color: transparent; }
h1 .alt { display: block; font-family: 'Orbitron', 'Noto Sans SC', sans-serif; font-size: 15px; letter-spacing: 0.45em; margin-top: 8px; color: var(--violet); -webkit-text-fill-color: var(--violet); }
h1 .logo { display: block; max-width: min(520px, 100%); max-height: 180px; margin: 0 auto; object-fit: contain; }
h2 { margin: 0 0 20px; font-size: 34px; font-weight: 900; letter-spacing: 0.1em; }
.sub { color: var(--dim); margin: 14px 0 26px; }

.track-select { margin-bottom: 18px; text-align: left; }
.track-select p { margin: 0 0 8px; color: var(--dim); font-size: 12px; font-weight: 700; }
.track-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.track-choices a {
  --track-accent: #91e5f0;
  display: grid; gap: 2px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 4px 8px 4px 8px;
  background: rgba(255, 255, 255, 0.035); color: var(--text); text-decoration: none;
}
.track-choices [data-track="wasteland"] { --track-accent: #ffc18e; }
.track-choices b { color: inherit; font-size: 14px; }
.track-choices small { color: var(--dim); font-size: 11px; }
.track-choices a:hover { border-color: var(--track-accent); }
.track-choices a:focus-visible { outline: 2px solid var(--track-accent); outline-offset: 2px; }
.skyline-menu .track-choices [data-track="skyline"],
.wasteland-menu .track-choices [data-track="wasteland"] {
  border-color: var(--track-accent); box-shadow: inset 3px 0 var(--track-accent);
  background: rgba(255, 255, 255, 0.08); color: var(--track-accent);
}
.wasteland-menu #menu .panel {
  background: linear-gradient(147deg, rgba(208, 140, 92, 0.15), transparent 42%), var(--panel);
}
.wasteland-menu #menu h1 { background-image: linear-gradient(178deg, #fff4e3 12%, #f5d4b8 46%, #d6a17a 80%); }
.wasteland-menu #menu .modes button { background: linear-gradient(135deg, rgba(190, 126, 82, 0.2), rgba(156, 82, 66, 0.08)); }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.modes button {
  position: relative; display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  padding: 20px 22px; border-radius: 2px 10px 2px 10px; border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(112, 161, 198, 0.19), rgba(157, 128, 227, 0.07));
  color: var(--text); cursor: pointer; font-family: inherit; text-align: left; transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.modes button:hover { transform: translateY(-2px); border-color: var(--cyan); box-shadow: 0 0 18px rgba(140, 233, 239, 0.15); }
.modes b { font-size: 22px; }
.modes small { color: var(--dim); font-size: 13px; }
.modes .lb-tag { font-style: normal; font-size: 12px; font-weight: 700; color: var(--gold); border: 1px solid rgba(255, 190, 130, 0.46); border-radius: 3px; padding: 2px 8px; align-self: flex-start; }
.modes em { font-style: normal; font-family: 'Orbitron'; font-size: 13px; color: var(--cyan); }
.modes kbd { position: absolute; top: 14px; right: 14px; }

kbd {
  display: inline-block; min-width: 24px; padding: 2px 7px; margin: 0 2px;
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 6px;
  font-family: 'Orbitron', 'Noto Sans SC'; font-size: 12px; color: var(--text); background: rgba(255, 255, 255, 0.05);
}

.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 22px; font-size: 14px; color: var(--dim); margin-bottom: 18px; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; font-size: 13px; color: var(--dim); margin-bottom: 14px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.hole { border: 1px dashed rgba(160, 180, 230, 0.6); }
.hint { font-size: 12px; color: var(--dim); margin: 0; }
.credits { font-size: 11px; line-height: 1.5; color: #93a3ba; margin: 14px 0 0; }

.stats { display: grid; gap: 10px; margin-bottom: 26px; }
.stats div { display: flex; justify-content: space-between; padding: 10px 16px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.stats span { color: var(--dim); }
.stats b { font-family: 'Orbitron'; }
#result.record h2 { color: var(--cyan); text-shadow: 0 0 20px var(--cyan); }

.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.actions button {
  padding: 12px 24px; border-radius: 10px; border: 1px solid var(--cyan); cursor: pointer;
  background: rgba(0, 255, 240, 0.12); color: var(--text); font-family: inherit; font-size: 15px; font-weight: 700;
}
.actions button:hover { background: rgba(0, 255, 240, 0.25); }
.actions button.ghost { border-color: var(--line); background: transparent; }

/* ---------- 语言切换 ---------- */
.lang-btn {
  position: fixed; z-index: 20;
  top: calc(16px + env(safe-area-inset-top, 0px)); right: calc(16px + env(safe-area-inset-right, 0px));
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: rgba(8, 12, 30, 0.7); color: var(--text); cursor: pointer;
  font-family: 'Orbitron', 'Noto Sans SC', sans-serif; font-size: 13px; font-weight: 700;
}
.lang-btn:hover { border-color: var(--cyan); }
body.in-run .lang-btn { display: none; }

/* ---------- 音乐 / 音效开关（菜单和比赛中都在左下角） ---------- */
.sound-ctl {
  position: fixed; z-index: 20; display: flex; gap: 8px;
  left: calc(16px + env(safe-area-inset-left, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.sound-ctl button {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 9px; border-radius: 20px;
  border: 1px solid var(--line); background: rgba(8, 12, 30, 0.7); color: var(--text); cursor: pointer;
  font-family: 'Noto Sans SC', sans-serif; font-size: 12px; font-weight: 700;
}
.sound-ctl button:hover { border-color: var(--cyan); }
.sound-ctl svg { width: 16px; height: 16px; fill: none; stroke: var(--cyan); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sound-ctl .slash { display: none; stroke: #ff5a7a; }
.sound-ctl button[aria-pressed="false"] { color: var(--dim); }
.sound-ctl button[aria-pressed="false"] svg { stroke: var(--dim); }
.sound-ctl button[aria-pressed="false"] .slash { display: inline; }

/* ---------- 菜单 + 排行榜 ---------- */
.panel.wide { width: min(1080px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; text-align: center; }
.menu-main { min-width: 0; }
.controls i { font-style: normal; }

.board {
  --standings-columns: 1.1rem minmax(0, 1fr) 2.9rem 3.5rem 3.55rem;
  min-width: 0; display: flex; flex-direction: column; gap: 12px;
  text-align: left; padding-left: 28px; border-left: 1px solid var(--line);
}
.board h3 { margin: 0; font-size: 18px; letter-spacing: 0.08em; }
.nick-big {
  width: 100%; margin-bottom: 22px; padding: 12px 16px; border-radius: 10px;
  border: 1px solid var(--cyan); background: rgba(255, 255, 255, 0.05); color: var(--text);
  font-family: inherit; font-size: 20px; font-weight: 700; text-align: center;
}
.nick-big:focus { outline: none; box-shadow: 0 0 18px rgba(0, 255, 240, 0.35); }
#nick-modal { z-index: 30; }
.nick-transfer { color: var(--cyan); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg.full { display: flex; }
.seg button { flex: 1; padding: 6px 10px; border: 0; background: transparent; color: var(--dim); cursor: pointer; font-family: inherit; font-size: 12px; }
.seg button.on { background: rgba(0, 255, 240, 0.16); color: var(--text); }
.seg button:disabled { opacity: 0.35; cursor: default; }
.lb-note { margin: 0; font-size: 12px; color: var(--dim); min-height: 1em; }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 300px; overflow-y: auto; }
.lb-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.035); font-size: 14px; }
.lb-list li.me { background: rgba(0, 255, 240, 0.12); box-shadow: inset 0 0 0 1px rgba(0, 255, 240, 0.35); }
.lb-list .rk { font-family: 'Orbitron'; font-weight: 700; color: var(--dim); }
.lb-list li:nth-child(1) .rk { color: var(--gold); }
.lb-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .nm small { color: var(--cyan); margin-left: 6px; }
.lb-list .sc { font-family: 'Orbitron'; font-variant-numeric: tabular-nums; }
.lb-standings-head, .lb-list.standings li:not(.empty) {
  display: grid; grid-template-columns: var(--standings-columns); gap: 4px; align-items: center;
  padding-inline: 6px;
}
.lb-standings-head {
  margin-bottom: -8px; padding-bottom: 3px;
  border-bottom: 1px solid var(--line); font-size: 10px; font-weight: 700; color: var(--dim);
}
.lb-standings-head, .lb-list.standings { scrollbar-gutter: stable; }
.lb-standings-head { overflow: hidden; }
.lb-standings-head .standings-name { grid-column: span 2; }
.lb-list.standings li:not(.empty) { font-size: 12px; }
.lb-list.standings .nm { white-space: normal; overflow-wrap: anywhere; }
.lb-standings-head .sc, .lb-list.standings .sc { text-align: right; }
.lb-list.standings .sc { font-family: inherit; font-size: 11px; }
.lb-standings-head .sc-skyline, .lb-list.standings .sc-skyline { color: #a6dce7; }
.lb-standings-head .sc-wasteland, .lb-list.standings .sc-wasteland { color: #f1c5a1; }
.lb-standings-head .sc-total, .lb-list.standings .sc-total { color: var(--text); font-weight: 800; }
.lb-list .empty { display: block; color: var(--dim); background: transparent; font-size: 13px; }
.nick { display: grid; gap: 6px; font-size: 12px; color: var(--dim); margin-top: auto; }
.nick input {
  padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05);
  color: var(--text); font-family: inherit; font-size: 14px;
}
.nick input:focus { outline: none; border-color: var(--cyan); }
.nick input[readonly] { color: var(--dim); }
.nick-error { margin: -8px 0 16px; color: #ffc2b8; font-size: 14px; }
#nick-modal .actions button:disabled { opacity: 0.55; cursor: wait; }
.rank-line { margin: -12px 0 22px; color: var(--cyan); font-size: 14px; min-height: 1em; }

button:focus-visible, input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

@media (min-width: 1050px) {
  :is(.skyline-menu, .wasteland-menu) #menu { justify-content: flex-start; padding-inline: 5vw; }
  :is(.skyline-menu, .wasteland-menu) #menu .panel.wide {
    width: min(900px, 74vw);
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 22px;
    padding: 30px;
  }
  :is(.skyline-menu, .wasteland-menu) #menu .board { padding-left: 16px; }
}

@media (max-width: 900px) {
  .panel.wide { grid-template-columns: 1fr; }
  .board { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); padding-top: 20px; }
}

@media (max-width: 640px) {
  h1 { font-size: 38px; }
  .panel { padding: 24px 18px; }
  .modes { grid-template-columns: 1fr; }
  #radar { width: 130px; height: 130px; }
  .speed { font-size: 36px; }
  .speedbar { width: 180px; }
}

@media (max-width: 420px) {
  .wasteland-menu #hud-best { font-size: 15px; }
  .hud-score { padding-inline: 8px; }
  .hud-score-value { font-size: 16px; }
  .board { --standings-columns: repeat(3, minmax(0, 1fr)); }
  .lb-standings-head .standings-name { display: none; }
  .lb-list.standings li:not(.empty) { position: relative; }
  .lb-list.standings .rk { position: absolute; inset: 6px auto auto 6px; }
  .lb-list.standings .nm { grid-column: 1 / -1; padding-left: 1.2rem; }
}
