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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

#ui-root {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

#ui-root > * {
  pointer-events: auto;
}

/* HUD */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  user-select: none;
}

.hud-left, .hud-right, .hud-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 16px;
}

.hud-item {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7), 0 0 2px rgba(0,0,0,0.9);
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.hud-item.timer {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.hud-item .gem-icon {
  color: #5ef;
  text-shadow: 0 0 8px rgba(80,230,255,0.6);
}

.hud-item .life-icon {
  color: #f55;
  text-shadow: 0 0 8px rgba(255,80,80,0.5);
}

.hud-pause-btn {
  pointer-events: auto;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

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

/* Menus */
.menu-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.menu-overlay.title-screen {
  background: radial-gradient(ellipse at 50% 30%, #0a0a2e 0%, #000010 100%);
}

.title-text {
  font-size: clamp(42px, 10vw, 80px);
  font-weight: 900;
  color: #fff;
  text-align: center;
  letter-spacing: 6px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #a0e0ff 0%, #ff80c0 50%, #ffcc40 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(160, 224, 255, 0.4));
}

.title-subtitle {
  font-size: clamp(14px, 3vw, 20px);
  color: rgba(255,255,255,0.5);
  letter-spacing: 8px;
  text-transform: uppercase;
  margin-bottom: 48px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 220px;
}

.menu-btn {
  padding: 14px 32px;
  font-size: 18px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.05) 100%);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  letter-spacing: 1px;
}

.menu-btn:hover {
  background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0.1) 100%);
  border-color: rgba(255,255,255,0.3);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(100,180,255,0.2);
}

.menu-btn:active {
  transform: translateY(0);
}

.menu-btn.primary {
  background: linear-gradient(135deg, rgba(80,180,255,0.3) 0%, rgba(180,80,255,0.2) 100%);
  border-color: rgba(100,180,255,0.4);
}

.menu-btn.primary:hover {
  background: linear-gradient(135deg, rgba(80,180,255,0.45) 0%, rgba(180,80,255,0.35) 100%);
  box-shadow: 0 4px 24px rgba(80,180,255,0.35);
}

.menu-title {
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 32px;
  letter-spacing: 2px;
}

/* Level complete overlay */
.level-complete-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  pointer-events: auto;
}

.level-complete-title {
  font-size: clamp(32px, 8vw, 56px);
  font-weight: 900;
  color: #ffcc40;
  text-shadow: 0 0 30px rgba(255,204,64,0.5);
  margin-bottom: 16px;
  letter-spacing: 4px;
}

.level-complete-stats {
  color: rgba(255,255,255,0.8);
  font-size: 20px;
  margin-bottom: 8px;
  text-align: center;
}

.level-complete-stars {
  font-size: 36px;
  margin: 16px 0 32px;
  letter-spacing: 8px;
}

.star-filled {
  color: #ffcc40;
  text-shadow: 0 0 12px rgba(255,204,64,0.6);
}

.star-empty {
  color: rgba(255,255,255,0.2);
}

/* Starfield canvas for title */
.starfield-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Touch joystick */
.touch-joystick {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  display: none;
}

.touch-joystick.active {
  display: block;
}

.joystick-base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
}

.joystick-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  border: 2px solid rgba(255,255,255,0.4);
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  transition: background 0.1s;
}

/* Loading screen */
.loading-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000010;
  color: rgba(255,255,255,0.6);
  font-size: 16px;
  letter-spacing: 2px;
  pointer-events: auto;
  z-index: 100;
}

.loading-bar {
  width: 200px;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: 16px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5ef, #f5f);
  border-radius: 2px;
  transition: width 0.3s;
}
