* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050711;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #f0f4ff;
}

#game-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#screen-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
  transition: opacity 0.08s ease-out;
}

#low-hp-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  box-shadow: inset 0 0 95px 36px rgba(255, 20, 60, 0.72);
  animation: dangerPulse 0.7s infinite alternate ease-in-out;
}

@keyframes dangerPulse {
  0%   { opacity: 0.35; }
  100% { opacity: 0.98; }
}

#speed-lines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  background: radial-gradient(circle at center, transparent 58%, rgba(0, 245, 212, 0.26) 100%);
  box-shadow: inset 0 0 65px rgba(0, 245, 212, 0.4);
}

#floating-labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.ai-tag {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 1px 4px #000;
}

.ai-tag.ace span.name-txt {
  color: #ffd700;
}

.ai-tag .crown {
  font-size: 16px;
  filter: drop-shadow(0 0 6px #ffd700);
}

.ai-hp-bg {
  width: 54px;
  height: 5px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 3px;
  overflow: hidden;
}

.ai-hp-bar {
  height: 100%;
  background: #ff4d6d;
  transition: width 0.1s linear;
}

.dmg-popup {
  position: fixed;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: 900;
  color: #ff2a6d;
  text-shadow: 0 0 10px #000, 0 2px 0 #000;
  pointer-events: none;
  z-index: 15;
  animation: popFloat 0.95s ease-out forwards;
  white-space: nowrap;
}

.dmg-popup.heal {
  color: #00f5d4;
}

.dmg-popup.upgrade {
  color: #f0abfc;
  font-size: 25px;
}

@keyframes popFloat {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.7); }
  25%  { opacity: 1; transform: translate(-50%, -95%) scale(1.28); }
  100% { opacity: 0; transform: translate(-50%, -175%) scale(0.95); }
}

/* 頂部 HUD */
#top-hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 10;
  pointer-events: none;
  gap: 10px;
}

.hud-group {
  display: flex;
  gap: 8px;
  pointer-events: auto;
  flex-wrap: wrap;
}

.stat-pill {
  background: rgba(12, 18, 36, 0.9);
  border: 1.5px solid rgba(0, 240, 255, 0.45);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  backdrop-filter: blur(6px);
}

.rank-pill {
  border-color: #ffd700;
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.28);
}

.stat-pill .label {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 1px;
}

.stat-pill span:last-child {
  font-size: 23px;
  font-weight: 900;
  line-height: 1.15;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 420px;
  max-width: 46vw;
}

.hp-wrapper {
  width: 100%;
  background: rgba(9, 14, 28, 0.94);
  border: 2px solid rgba(0, 245, 212, 0.55);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.65);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.hp-wrapper.danger {
  border-color: #ff2a6d;
  box-shadow: 0 0 22px rgba(255, 42, 109, 0.85);
}

.hp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #38bdf8;
  margin-bottom: 6px;
}

.hp-num {
  font-size: 16px;
  font-weight: 900;
  color: #00f5d4;
  text-shadow: 0 0 8px rgba(0, 245, 212, 0.5);
}

.hp-track {
  width: 100%;
  height: 16px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  overflow: hidden;
}

#hud-hp-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #10b981, #00f5d4, #38bdf8);
  box-shadow: 0 0 12px rgba(0, 245, 212, 0.6);
  transition: width 0.15s ease, background 0.2s ease;
}

#hud-hp-fill.danger {
  background: linear-gradient(90deg, #ff0055, #ff5e00);
  box-shadow: 0 0 14px rgba(255, 0, 85, 0.85);
}

.upgrade-strip {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.upg-badge {
  flex: 1;
  text-align: center;
  font-size: 12.5px;
  font-weight: 900;
  color: #f5d0fe;
  background: rgba(192, 38, 211, 0.26);
  padding: 4px 6px;
  border-radius: 7px;
  border: 1.5px solid rgba(232, 121, 249, 0.55);
  transition: transform 0.2s, background 0.2s;
}

.upg-badge.leveled {
  background: rgba(217, 70, 239, 0.48);
  border-color: #f0abfc;
  color: #fff;
  box-shadow: 0 0 10px rgba(232, 121, 249, 0.5);
}

#status-banner {
  background: rgba(255, 42, 109, 0.95);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 7px 18px;
  border-radius: 22px;
  letter-spacing: 0.5px;
  box-shadow: 0 0 16px rgba(255, 42, 109, 0.8);
  white-space: nowrap;
}

#status-banner.info {
  background: rgba(0, 187, 249, 0.95);
  box-shadow: 0 0 16px rgba(0, 187, 249, 0.8);
}

#status-banner.upgrade {
  background: rgba(192, 38, 211, 0.96);
  box-shadow: 0 0 18px rgba(217, 70, 239, 0.9);
}

.hidden {
  display: none !important;
}

.toggle-btn {
  background: rgba(16, 24, 48, 0.88);
  color: #cbd5e1;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.toggle-btn.active {
  border-color: #00f5d4;
  color: #00f5d4;
}

#countdown-banner {
  position: fixed;
  top: 36%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 88px;
  font-weight: 900;
  font-style: italic;
  color: #ffd700;
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.9), 0 4px 0 #b45309;
  z-index: 20;
  pointer-events: none;
  text-align: center;
}

#countdown-banner.go {
  color: #00f5d4;
  text-shadow: 0 0 34px rgba(0, 245, 212, 0.95), 0 4px 0 #0f766e;
}

/* 底部動態能量條 */
#telemetry-bars {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 10;
  pointer-events: none;
}

.bar-box {
  width: 205px;
  background: rgba(9, 14, 28, 0.9);
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.bar-box.active-blue {
  border-color: #38bdf8;
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.75);
  transform: translateY(-2px);
}

.bar-box.active-orange {
  border-color: #fb923c;
  box-shadow: 0 0 22px rgba(251, 146, 60, 0.9);
  transform: translateY(-2px);
}

.bar-box.active-ultra {
  border-color: #e879f9;
  box-shadow: 0 0 28px rgba(232, 121, 249, 1.0);
  transform: translateY(-4px) scale(1.04);
}

.bar-box.active-purple {
  border-color: #c084fc;
  box-shadow: 0 0 20px rgba(192, 132, 252, 0.85);
  transform: translateY(-2px);
}

.bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.bar-tag {
  font-size: 11px;
  font-weight: 900;
  color: #f1f5f9;
  letter-spacing: 0.5px;
}

.bar-val {
  font-size: 11px;
  font-weight: 900;
  color: #38bdf8;
}

.mini-track {
  position: relative;
  width: 100%;
  height: 11px;
  background: #1e293b;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.tier-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.75);
  z-index: 2;
}

@keyframes energyFlow {
  0%   { background-position: 0 0; }
  100% { background-position: 28px 0; }
}

#drift-fill {
  width: 0%;
  height: 100%;
  background-color: #38bdf8;
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.35) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.35) 50%,
    rgba(255, 255, 255, 0.35) 75%,
    transparent 75%,
    transparent
  );
  background-size: 14px 14px;
  animation: energyFlow 0.45s linear infinite;
}

#draft-fill {
  width: 0%;
  height: 100%;
  background-color: #a855f7;
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.35) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.35) 50%,
    rgba(255, 255, 255, 0.35) 75%,
    transparent 75%,
    transparent
  );
  background-size: 14px 14px;
  animation: energyFlow 0.4s linear infinite;
}

#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 12;
}

.touch-left {
  position: absolute;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: max(22px, env(safe-area-inset-left));
  display: flex;
  gap: 16px;
  pointer-events: auto;
}

.joystick-area {
  width: 176px;
  height: 112px;
  align-items: center;
  justify-content: center;
}

.joystick-base {
  position: relative;
  width: 168px;
  height: 84px;
  border-radius: 42px;
  background: rgba(15, 23, 42, 0.72);
  border: 2px solid rgba(0, 245, 212, 0.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 18px rgba(0, 245, 212, 0.15);
}

.joystick-ticks {
  width: 100%;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: rgba(148, 163, 184, 0.65);
  pointer-events: none;
}

.joystick-knob {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #38bdf8, #0284c7);
  border: 2.5px solid #e0f2fe;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.8);
  transform: translateX(0px);
  pointer-events: none;
}

.touch-right {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(22px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.weapon-slots {
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: #fff;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.06s, border-color 0.1s, background 0.1s;
}

.ctrl-btn.pressed {
  transform: scale(0.93);
  background: rgba(0, 240, 255, 0.32);
  border-color: #00f0ff;
}

.dir-btn {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  font-size: 32px;
}

.drift-btn {
  width: 164px;
  height: 76px;
  border-radius: 38px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1px;
  border-color: rgba(56, 189, 248, 0.7);
}

.drift-btn small {
  font-size: 10px;
  opacity: 0.85;
}

.drift-btn.charge-1 {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.25);
  box-shadow: 0 0 22px rgba(56, 189, 248, 0.85);
}

.drift-btn.charge-2 {
  border-color: #fb923c;
  background: rgba(251, 146, 60, 0.3);
  box-shadow: 0 0 24px rgba(251, 146, 60, 0.92);
}

.drift-btn.charge-3 {
  border-color: #e879f9;
  background: rgba(217, 70, 239, 0.38);
  box-shadow: 0 0 30px rgba(232, 121, 249, 1.0);
}

.fire-btn {
  width: 82px;
  height: 82px;
  border-radius: 18px;
  border: 2px solid rgba(250, 204, 21, 0.45);
}

.fire-btn.has-item {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.28);
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.65);
}

.key-badge {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 11px;
  font-weight: 900;
  background: rgba(0, 0, 0, 0.75);
  color: #facc15;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid rgba(250, 204, 21, 0.5);
}

.w-icon {
  font-size: 30px;
  margin-top: 6px;
}

.w-name {
  font-size: 10.5px;
  font-weight: 800;
  margin-top: 2px;
}

@media (min-width: 960px) {
  .fire-btn {
    width: 96px;
    height: 96px;
  }
  .w-icon {
    font-size: 36px;
  }
  .w-name {
    font-size: 11.5px;
  }
  .drift-btn {
    width: 202px;
    height: 78px;
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 18, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 35;
  padding: 16px;
  pointer-events: auto;
}

.overlay-card {
  max-width: 630px;
  width: 100%;
  background: #0f172a;
  border: 1.5px solid rgba(0, 240, 255, 0.5);
  border-radius: 18px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.8);
}

.result-banner {
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.18), rgba(0, 245, 212, 0.18));
  border: 1.5px solid #ffd700;
  color: #ffd700;
  font-size: 18px;
  font-weight: 900;
  padding: 10px 16px;
  border-radius: 12px;
  margin: 12px 0 6px;
}

.overlay-card h1 {
  font-size: 28px;
  letter-spacing: 1.5px;
}

.overlay-card .accent {
  color: #00f5d4;
}

.subtitle {
  color: #94a3b8;
  font-size: 13.5px;
  margin: 8px 0 14px;
}

.tips-list {
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 18px;
  list-style: none;
}

.tips-list li {
  margin-bottom: 7px;
}

.tips-list strong {
  color: #00f5d4;
}

.primary-btn {
  background: linear-gradient(135deg, #00f5d4, #00bbf9);
  color: #050811;
  border: none;
  border-radius: 12px;
  padding: 14px 26px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  width: 100%;
  touch-action: manipulation;
}

.primary-btn:active {
  transform: scale(0.97);
}

.key-hint {
  margin-top: 12px;
  font-size: 12px;
  color: #94a3b8;
}
