:root {
  --bg: #0a0e1a;
  --fg: #e8f0ff;
  --accent: #00d4ff;
  --accent2: #ff6b35;
  --gold: #ffd700;
  --danger: #ff3b5c;
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.15);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Helvetica Neue", sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overscroll-behavior: none;
  touch-action: none;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

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

/* ========== HUD ========== */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  pointer-events: none;
}

.top-hud {
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.brand-mark {
  font-size: 22px;
}

.score-display {
  display: flex;
  gap: 24px;
  align-items: center;
  padding: 8px 18px;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 52px;
}

.score-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.6;
}

.score-value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.coin-color {
  color: var(--gold);
}

/* ========== Speed badge ========== */

.speed-badge {
  position: absolute;
  top: 80px;
  right: 20px;
  padding: 8px 14px;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  z-index: 10;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.speed-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.5;
}

.speed-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.speed-badge.boost {
  transform: scale(1.12);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
  border-color: rgba(0, 212, 255, 0.5);
}

/* ========== Hit flash（撞击时的红色闪屏） ========== */

.hit-flash {
  position: absolute;
  inset: 0;
  z-index: 18;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(255, 40, 60, 0.55) 100%);
  transition: opacity 0.12s ease;
}

.hit-flash.show {
  opacity: 1;
}

/* ========== New record badge ========== */

.new-record {
  padding: 6px 20px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #1a1400;
  background: linear-gradient(135deg, var(--gold), #ffb830);
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(255, 215, 0, 0.45);
  animation: record-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.new-record.hidden {
  display: none;
}

@keyframes record-pop {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ========== Start screen ========== */

.start-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 14, 26, 0.7), rgba(10, 14, 26, 0.95));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 20;
  transition: opacity 0.4s ease;
}

.start-layer.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 56px;
  background: var(--glass);
  backdrop-filter: blur(30px) saturate(200%);
  -webkit-backdrop-filter: blur(30px) saturate(200%);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.game-title {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 16px rgba(0, 212, 255, 0.3));
}

.game-subtitle {
  font-size: 14px;
  letter-spacing: 6px;
  text-transform: uppercase;
  opacity: 0.4;
  margin-bottom: 8px;
}

.start-button, .restart-button {
  padding: 14px 48px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #0098ff);
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 212, 255, 0.3);
}

.start-button:hover, .restart-button:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 32px rgba(0, 212, 255, 0.45);
}

.start-button:active, .restart-button:active {
  transform: translateY(0) scale(0.98);
}

.version-badge {
  font-size: 12px;
  opacity: 0.4;
  letter-spacing: 1px;
}

.controls-hint {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  opacity: 0.7;
}

.hint-icon {
  font-size: 18px;
  min-width: 24px;
  text-align: center;
}

/* ========== Game over screen ========== */

.gameover-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 14, 26, 0.7), rgba(10, 14, 26, 0.95));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 20;
  transition: opacity 0.4s ease;
}

.gameover-layer.hidden {
  opacity: 0;
  pointer-events: none;
}

.gameover-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 56px;
  background: var(--glass);
  backdrop-filter: blur(30px) saturate(200%);
  -webkit-backdrop-filter: blur(30px) saturate(200%);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.gameover-title {
  font-size: 36px;
  font-weight: 900;
  color: var(--danger);
  letter-spacing: 2px;
}

.gameover-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 240px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 16px;
  border-bottom: 1px solid var(--glass-border);
}

.stat-row span {
  opacity: 0.6;
}

.stat-row strong {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.best-row {
  border-bottom: none;
  padding-top: 12px;
  border-top: 1px solid var(--glass-border);
}

.best-row strong {
  color: var(--gold);
}

/* ========== Touch zone (swipe area) ========== */

.touch-zone {
  position: absolute;
  inset: 0;
  z-index: 5;
  touch-action: none;
}

/* ========== On-screen touch buttons ========== */

/* ========== Virtual joystick（左下角虚拟摇杆） ========== */
/* 横屏握持时左手拇指自然落在左下角，摇杆放这里不用挪手；
   右手拇指仍然可以在屏幕任意位置滑动 */

.joystick {
  position: absolute;
  left: max(24px, env(safe-area-inset-left, 24px));
  bottom: max(10%, calc(env(safe-area-inset-bottom, 0px) + 40px));
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 2px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.joystick.active {
  border-color: rgba(0, 212, 255, 0.45);
  box-shadow: 0 0 24px rgba(0, 212, 255, 0.25);
}

/* 四个方向的提示箭头 */
.joy-hint {
  position: absolute;
  font-size: 14px;
  opacity: 0.35;
  pointer-events: none;
}

.joy-up { top: 8px; left: 50%; transform: translateX(-50%); }
.joy-down { bottom: 8px; left: 50%; transform: translateX(-50%); }
.joy-left { left: 10px; top: 50%; transform: translateY(-50%); }
.joy-right { right: 10px; top: 50%; transform: translateY(-50%); }

.joystick-knob {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(120, 225, 255, 0.85), rgba(0, 150, 220, 0.75));
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 -4px 10px rgba(0, 40, 80, 0.4);
  pointer-events: none;
  transition: transform 0.16s cubic-bezier(0.22, 1.4, 0.36, 1); /* 松手弹回 */
}

.joystick.active .joystick-knob {
  transition: none; /* 拖动时无延迟跟手 */
}

/* ========== Animations ========== */

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 8px 24px rgba(0, 212, 255, 0.3); }
  50% { box-shadow: 0 8px 32px rgba(0, 212, 255, 0.5); }
}

.start-button {
  animation: pulse-glow 2s ease-in-out infinite;
}

/* ========== Responsive ========== */

@media (max-width: 768px) {
  .brand {
    font-size: 14px;
  }
  .brand-mark {
    font-size: 18px;
  }
  .score-display {
    gap: 12px;
  }
  .score-value {
    font-size: 18px;
  }
  .score-label {
    font-size: 9px;
  }
  .game-title {
    font-size: 36px;
  }
  .start-panel {
    padding: 36px 32px;
  }
  .gameover-panel {
    padding: 32px 32px;
  }
  .joystick {
    width: 132px;
    height: 132px;
  }
  .joystick-knob {
    width: 56px;
    height: 56px;
  }
}

@media (max-width: 480px) {
  .score-display {
    gap: 10px;
  }
  .score-value {
    font-size: 16px;
  }
  .joystick {
    width: 118px;
    height: 118px;
    left: max(14px, env(safe-area-inset-left, 14px));
  }
  .joystick-knob {
    width: 50px;
    height: 50px;
  }
}
