* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a1628;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

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

#hud > div {
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.hud-btn {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.3);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
}

.hud-btn:hover {
  background: rgba(255,255,255,0.2);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 22, 40, 0.88);
  z-index: 20;
  transition: opacity 0.3s;
  overflow-y: auto;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  font-size: clamp(32px, 7vw, 64px);
  color: #fff;
  text-shadow: 0 0 20px rgba(100, 200, 255, 0.6), 0 4px 8px rgba(0,0,0,0.4);
  margin-bottom: 16px;
  letter-spacing: 4px;
}

.overlay h2 {
  font-size: clamp(18px, 4vw, 28px);
  color: #8ec8f0;
  margin-bottom: 12px;
}

.instructions {
  text-align: center;
  color: #c0dff0;
  font-size: clamp(14px, 3vw, 20px);
  margin-bottom: 20px;
  line-height: 1.8;
}

.control-hint {
  color: #8ec8f0;
  font-size: clamp(12px, 2.5vw, 16px);
  margin-top: 4px;
}

button {
  padding: 14px 48px;
  font-size: clamp(16px, 3vw, 22px);
  font-weight: bold;
  color: #fff;
  background: linear-gradient(135deg, #2196F3, #0d47a1);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 16px rgba(33, 150, 243, 0.4);
  pointer-events: auto;
}

button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(33, 150, 243, 0.6);
}

button:active {
  transform: scale(0.97);
}

#total-coins-menu, #pause-total-coins {
  color: #ffd700;
  font-size: clamp(16px, 3.5vw, 22px);
  font-weight: bold;
  margin-bottom: 20px;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

#earned-coins {
  color: #ffd700;
  font-size: clamp(14px, 3vw, 20px);
  margin: 8px 0;
  font-weight: bold;
}

#final-score, #final-distance, #final-highscore {
  color: #e0f0ff;
  font-size: clamp(16px, 4vw, 28px);
  margin: 8px 0;
  font-weight: bold;
}

#final-highscore {
  color: #ffd700;
  margin-bottom: 12px;
}

/* Shop */
#shop-container {
  width: 100%;
  max-width: 600px;
  margin-bottom: 20px;
}

#shop-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 45vh;
  overflow-y: auto;
  padding: 4px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 12px 16px;
  transition: background 0.15s;
}

.shop-item:hover {
  background: rgba(255, 255, 255, 0.14);
}

.shop-icon {
  font-size: 32px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  flex-shrink: 0;
}

.shop-info {
  flex: 1;
  min-width: 0;
}

.shop-name {
  color: #fff;
  font-size: clamp(14px, 3vw, 18px);
  font-weight: bold;
}

.shop-desc {
  color: #8ec8f0;
  font-size: clamp(11px, 2.2vw, 14px);
  margin-top: 2px;
}

.shop-buy-btn {
  padding: 8px 20px;
  font-size: clamp(13px, 2.5vw, 16px);
  border-radius: 8px;
  flex-shrink: 0;
}

.shop-buy-btn.can-buy {
  background: linear-gradient(135deg, #FF9800, #E65100);
  box-shadow: 0 3px 12px rgba(255, 152, 0, 0.4);
}

.shop-buy-btn.can-buy:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 152, 0, 0.6);
}

.shop-buy-btn.owned {
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
  box-shadow: 0 3px 12px rgba(76, 175, 80, 0.3);
  cursor: default;
}

.shop-buy-btn.cant-buy {
  background: rgba(255,255,255,0.15);
  color: #888;
  cursor: not-allowed;
  box-shadow: none;
}

.shop-buy-btn.cant-buy:hover {
  transform: none;
}

/* HUD center section - transparent background so durability bar shows clearly */
#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 180px;
  background: transparent !important;
  padding: 0 !important;
}

#distance-display {
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

/* Durability bar */
#durability-bar-container {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  backdrop-filter: blur(4px);
  min-width: 180px;
}

#durability-bar-label {
  font-size: 12px;
  color: #ccc;
  white-space: nowrap;
}

#durability-bar-bg {
  flex: 1;
  height: 14px;
  background: rgba(255,255,255,0.15);
  border-radius: 7px;
  overflow: hidden;
}

#durability-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ffffff, #e0e0e0);
  border-radius: 7px;
  transition: width 0.15s ease;
}

#durability-bar-fill.mid {
  background: linear-gradient(90deg, #ff9800, #ffc107) !important;
}

#durability-bar-fill.low {
  background: linear-gradient(90deg, #f44336, #ff5722) !important;
}

/* Active effects indicators */
#active-effects {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: none;
  z-index: 10;
}

.effect-badge {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  backdrop-filter: blur(4px);
}

.effect-badge.shield-active {
  background: rgba(33, 150, 243, 0.6);
  border: 1px solid rgba(100, 200, 255, 0.5);
}

.effect-badge.shield-used {
  background: rgba(255, 255, 255, 0.15);
  color: #666;
  text-decoration: line-through;
}

/* Level Select Grid */
#level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 800px;
  padding: 10px;
  margin-bottom: 20px;
}

.level-card {
  position: relative;
  height: 120px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 3px solid rgba(255,255,255,0.2);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
  background-size: cover;
  background-position: center;
  background-color: #1a3050;
}

.level-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.2) 50%, rgba(0,0,0,0.05) 100%);
  z-index: 1;
}

.level-card > * {
  position: relative;
  z-index: 2;
}

.level-card:hover:not(.locked) {
  transform: scale(1.05);
  box-shadow: 0 8px 24px rgba(100, 200, 255, 0.3);
  border-color: rgba(100, 200, 255, 0.6);
}

.level-card.locked {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(0.6);
}

.level-card.locked::after {
  content: '\1F512';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  z-index: 3;
}

.level-card.completed {
  border-color: rgba(255, 215, 0, 0.5);
}

.level-card.current {
  border-color: rgba(100, 200, 255, 0.8);
  animation: currentPulse 2s ease-in-out infinite;
}

@keyframes currentPulse {
  0%, 100% { box-shadow: 0 0 12px rgba(100, 200, 255, 0.3); }
  50% { box-shadow: 0 0 24px rgba(100, 200, 255, 0.6); }
}

.level-num {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.2);
}

.level-card.completed .level-num {
  background: rgba(255, 215, 0, 0.6);
}

.level-card.current .level-num {
  background: rgba(33, 150, 243, 0.6);
}

.level-name {
  color: #fff;
  font-size: clamp(13px, 2.5vw, 16px);
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  margin-top: auto;
}

.level-target {
  color: rgba(255, 255, 255, 0.75);
  font-size: clamp(10px, 2vw, 12px);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  margin-top: 2px;
}

.level-status {
  font-size: clamp(11px, 2vw, 13px);
  margin-top: 3px;
  color: #ffd700;
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

.level-card.locked .level-status {
  color: #888;
}

#durability-section {
  width: 100%;
  max-width: 600px;
  margin-bottom: 16px;
  text-align: center;
}

#dur-info {
  color: #c0dff0;
  font-size: clamp(13px, 2.5vw, 16px);
  margin-bottom: 8px;
}

#upgrade-dur-btn {
  padding: 10px 28px;
  font-size: clamp(13px, 2.5vw, 16px);
  border-radius: 10px;
  background: linear-gradient(135deg, #FF9800, #E65100);
  box-shadow: 0 3px 12px rgba(255, 152, 0, 0.4);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

#upgrade-dur-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 152, 0, 0.6);
}

#upgrade-dur-btn.cant-afford {
  background: rgba(255,255,255,0.1);
  color: #888;
  cursor: not-allowed;
  box-shadow: none;
}

#upgrade-dur-btn.cant-afford:hover {
  transform: none;
}

.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#complete-stars {
  font-size: clamp(28px, 6vw, 48px);
  color: #ffd700;
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.5);
  margin: 10px 0;
}

#go-reason {
  color: #f0a0a0;
  font-size: clamp(14px, 3vw, 18px);
  margin: 8px 0;
  text-align: center;
}

/* Slope indicator in HUD */
#slope-indicator {
  font-size: 13px;
  font-weight: bold;
  margin-top: 2px;
  padding: 2px 8px;
  border-radius: 6px;
  min-width: 60px;
  text-align: center;
}

.slope-up {
  color: #ff6b4a;
  text-shadow: 0 0 6px rgba(255, 107, 74, 0.5);
}

.slope-down {
  color: #4ac0ff;
  text-shadow: 0 0 6px rgba(74, 192, 255, 0.5);
}

.slope-flat {
  color: #aaa;
}
