:root {
  color-scheme: dark;
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: #081016;
  color: #f6fbff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background:
    radial-gradient(circle at 50% 0%, rgba(67, 189, 255, 0.18), transparent 42%),
    linear-gradient(180deg, #101b26 0%, #071016 100%);
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-width: 320px;
  min-height: 540px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #09202a;
}

/* ── HUD ── */
.hud {
  position: absolute;
  inset: 14px 14px auto 14px;
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 8px;
  pointer-events: none;
}

.stat {
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(4, 15, 21, 0.62);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
}

.stat span {
  display: block;
  margin-bottom: 2px;
  color: rgba(246, 251, 255, 0.62);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.stat strong {
  display: block;
  font-size: clamp(16px, 2.6vw, 26px);
  line-height: 1;
  white-space: nowrap;
}

/* ── Health bar ── */
.health-bar {
  position: absolute;
  left: 14px;
  top: 84px;
  z-index: 3;
  display: grid;
  grid-template-columns: auto minmax(120px, 220px) auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(4, 15, 21, 0.62);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.health-bar span,
.health-bar strong {
  color: rgba(246, 251, 255, 0.9);
  font-size: 12px;
  font-weight: 900;
}

.health-bar div {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
}

.health-bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #65df88, #f7d857, #ff4f60);
  box-shadow: 0 0 16px rgba(101, 223, 136, 0.4);
  transition: width 180ms ease;
}

.health-bar.is-critical {
  border-color: rgba(255, 79, 96, 0.72);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.28),
    0 0 20px rgba(255, 79, 96, 0.34);
}

.health-bar.is-critical i {
  background: linear-gradient(90deg, #ff4f60, #ff7b54);
  animation: criticalPulse 420ms ease-in-out infinite alternate;
}

@keyframes criticalPulse {
  from { filter: brightness(0.86); }
  to   { filter: brightness(1.45); }
}

/* ── Power (boost) bar ── */
.power-bar {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  height: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(5, 16, 21, 0.68);
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.power-bar div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f7d857, #ff7b54, #79f2ff);
  box-shadow: 0 0 22px rgba(121, 242, 255, 0.72);
  transition: width 120ms linear;
  border-radius: inherit;
}

/* ── Combo display ── */
.combo-display {
  position: absolute;
  right: 18px;
  top: 130px;
  z-index: 3;
  pointer-events: none;
  text-align: right;
  opacity: 0;
  transition: opacity 0.2s;
}

.combo-display.active {
  opacity: 1;
}

.combo-count {
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #f7d857, #ff7b54);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(255, 123, 84, 0.5));
}

.combo-label {
  font-size: 13px;
  font-weight: 700;
  color: rgba(246, 251, 255, 0.7);
  letter-spacing: 0.08em;
}

.combo-mult {
  font-size: 18px;
  font-weight: 900;
  color: #79f2ff;
}

/* ── Mobile joystick controls ── */
.mobile-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px 20px 24px;
  pointer-events: none;
}

/* Joystick */
.joystick {
  pointer-events: auto;
  width: 130px;
  height: 130px;
  position: relative;
}

.joystick-base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(4, 15, 21, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.joystick-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(247, 216, 87, 0.9), rgba(255, 123, 84, 0.9));
  border: 2px solid rgba(255, 255, 255, 0.3);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 16px rgba(255, 123, 84, 0.4);
  transition: transform 0.08s ease-out;
  pointer-events: none;
}

.joystick-knob.active {
  transition: none;
  box-shadow: 0 4px 20px rgba(255, 123, 84, 0.6);
}

/* Boost button */
.boost-btn {
  pointer-events: auto;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid rgba(121, 242, 255, 0.4);
  background:
    radial-gradient(circle at 50% 30%, rgba(121, 242, 255, 0.35), transparent 50%),
    linear-gradient(135deg, rgba(247, 216, 87, 0.95), rgba(255, 123, 84, 0.9));
  color: #1d1305;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 28px rgba(255, 123, 84, 0.35), 0 0 20px rgba(121, 242, 255, 0.2);
  backdrop-filter: blur(10px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, filter 0.1s;
}

.boost-btn span {
  font-size: 20px;
  font-weight: 1000;
  pointer-events: none;
}

.boost-btn:active {
  transform: scale(0.92);
  filter: brightness(1.2);
}

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(8, 16, 22, 0.3), rgba(8, 16, 22, 0.78));
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(520px, 100%);
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(6, 17, 24, 0.86);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(18px);
  text-align: center;
}

.kicker {
  margin: 0 0 6px;
  color: #79f2ff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 60px);
  line-height: 1.05;
}

#message {
  margin: 12px auto 16px;
  max-width: 36rem;
  color: rgba(246, 251, 255, 0.76);
  font-size: 15px;
  line-height: 1.7;
}

/* ── Stars ── */
.stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 36px;
}

.stars .star {
  opacity: 0.2;
  transition: opacity 0.3s, transform 0.3s;
}

.stars .star.earned {
  opacity: 1;
  transform: scale(1.1);
  filter: drop-shadow(0 0 8px rgba(247, 216, 87, 0.6));
}

/* ── Stats line ── */
.stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: rgba(246, 251, 255, 0.6);
  flex-wrap: wrap;
}

.stats .stat-item {
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
}

.stats .stat-item strong {
  color: #f7d857;
}

/* ── Controls hint ── */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}

.controls span {
  min-width: 80px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(246, 251, 255, 0.82);
  font-size: 12px;
}

/* ── Buttons ── */
.menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

button {
  width: min(280px, 100%);
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 17px;
  font-weight: 900;
  transition: transform 0.1s, filter 0.1s;
}

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

#startButton {
  background: linear-gradient(135deg, #f7d857, #ff7b54);
  color: #1d1305;
  box-shadow: 0 12px 32px rgba(255, 123, 84, 0.35);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #f6fbff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: none;
  font-size: 15px;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

button:focus-visible {
  outline: 3px solid #79f2ff;
  outline-offset: 4px;
}

/* ── Pause ── */
.pause-hint {
  color: rgba(246, 251, 255, 0.5);
  font-size: 14px;
  margin: 12px 0 20px;
}

/* ── Garage ── */
.garage-panel {
  max-height: 80vh;
  overflow-y: auto;
}

.garage-coins {
  font-size: 18px;
  font-weight: 800;
  color: #f7d857;
  margin: 8px 0 16px;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.upgrade-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
}

.upgrade-icon {
  font-size: 28px;
  line-height: 1;
}

.upgrade-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.upgrade-name {
  font-size: 14px;
  font-weight: 700;
}

.upgrade-desc {
  font-size: 11px;
  color: rgba(246, 251, 255, 0.5);
}

.upgrade-level {
  display: flex;
  gap: 3px;
  margin-top: 2px;
}

.upgrade-level i {
  display: block;
  width: 14px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
}

.upgrade-level i.filled {
  background: linear-gradient(90deg, #f7d857, #ff7b54);
}

.upgrade-btn {
  min-width: 80px;
  min-height: 36px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(135deg, #f7d857, #ff7b54);
  color: #1d1305;
}

.upgrade-btn:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(246, 251, 255, 0.3);
  cursor: default;
}

.upgrade-btn.maxed {
  background: rgba(101, 223, 136, 0.2);
  color: #65df88;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .hud {
    inset: 8px 8px auto 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    min-height: 44px;
    padding: 6px 8px;
  }

  .stat:nth-child(n+4) {
    display: none;
  }

  .power-bar {
    left: 8px;
    right: 8px;
    bottom: 160px;
    height: 14px;
  }

  .health-bar {
    left: 8px;
    right: 8px;
    top: 120px;
    grid-template-columns: auto 1fr auto;
  }

  .mobile-controls {
    display: flex;
  }

  .panel {
    padding: 18px 14px;
  }

  .combo-display {
    top: 160px;
    right: 12px;
  }

  .combo-count {
    font-size: 32px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .power-bar {
    bottom: 160px;
  }

  .health-bar {
    left: 8px;
    right: 8px;
    top: 120px;
    grid-template-columns: auto 1fr auto;
  }

  .mobile-controls {
    display: flex;
  }
}

@media (max-width: 380px) {
  .joystick {
    width: 110px;
    height: 110px;
  }

  .joystick-base {
    width: 100px;
    height: 100px;
  }

  .joystick-knob {
    width: 44px;
    height: 44px;
  }

  .boost-btn {
    width: 68px;
    height: 68px;
  }
}
