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

body {
  background: #1a1a2e;
  overflow: hidden;
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 100svh;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #2d2d44;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  pointer-events: none;
  z-index: 10;
}

.hud-item {
  background: rgba(0, 0, 0, 0.55);
  border-radius: 12px;
  padding: 6px 12px;
  color: #fff;
  font-size: 13px;
  min-width: 160px;
}

.hud-label {
  font-weight: 700;
  font-size: 14px;
}

.hp-bar {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  margin: 4px 0;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #4ade80, #22c55e);
  border-radius: 5px;
  transition: width 0.3s ease, background 0.3s ease;
}

.hp-fill.warning {
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
}

.hp-fill.danger {
  background: linear-gradient(90deg, #f87171, #ef4444);
}

.hud-stat {
  font-size: 12px;
  color: #d1d5db;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  backdrop-filter: blur(4px);
}

.overlay-box {
  background: linear-gradient(160deg, #1e1e3a, #2a2a4e);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 32px 28px;
  text-align: center;
  color: #fff;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.overlay-box h1 {
  font-size: 28px;
  margin-bottom: 12px;
  line-height: 1.2;
}

.overlay-box p {
  color: #b0b8d0;
  margin: 6px 0;
  line-height: 1.5;
  font-size: 14px;
}

.controls-info {
  margin: 14px 0;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  font-size: 13px;
  color: #c0c8e0;
  line-height: 1.8;
}

.big-btn {
  display: inline-block;
  padding: 14px 32px;
  border: none;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  margin-top: 16px;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.big-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.5);
}

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

.big-btn.btn-success {
  background: linear-gradient(135deg, #22c55e, #10b981);
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.4);
}
.big-btn.btn-success:hover {
  box-shadow: 0 12px 32px rgba(34, 197, 94, 0.5);
}

.big-btn.btn-gold {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.4);
}
.big-btn.btn-gold:hover {
  box-shadow: 0 12px 32px rgba(245, 158, 11, 0.5);
}

.level-complete-box {
  border-color: rgba(34, 197, 94, 0.3);
}
.level-complete-box h1 {
  color: #4ade80;
}

.game-complete-box {
  border-color: rgba(245, 158, 11, 0.3);
  background: linear-gradient(160deg, #1e1e3a, #2a2a4e, #1e1e3a);
}
.game-complete-box h1 {
  color: #fbbf24;
  font-size: 32px;
}

.mode-toggle {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

.mode-btn {
  padding: 8px 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: transparent;
  color: #b0b8d0;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: rgba(99, 102, 241, 0.3);
  border-color: #6366f1;
  color: #fff;
}

.items-info {
  margin: 8px 0 0;
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  font-size: 13px;
  color: #c0c8e0;
  line-height: 1.8;
}

/* Unlock popup */
.unlock-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a1a2e;
  padding: 16px 28px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 700;
  z-index: 50;
  animation: popIn 0.4s ease-out;
  box-shadow: 0 8px 32px rgba(251, 191, 36, 0.5);
}

@keyframes popIn {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  60% { transform: translate(-50%, -50%) scale(1.15); }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Touch Controls */
#touch-controls {
  position: absolute;
  bottom: 30px;
  left: 0;
  right: 0;
  display: none;
  justify-content: center;
  align-items: flex-end;
  z-index: 20;
  pointer-events: none;
}

/* Virtual Joystick */
#joystick-zone {
  position: relative;
  pointer-events: auto;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-base {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0.08) 60%, rgba(99, 102, 241, 0.03) 100%);
  border: 2px solid rgba(99, 102, 241, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.15), inset 0 0 20px rgba(99, 102, 241, 0.05);
}

#joystick-stick {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(139, 92, 246, 0.7), rgba(99, 102, 241, 0.5));
  border: 2px solid rgba(167, 139, 250, 0.6);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.2);
  transition: box-shadow 0.15s;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

#joystick-stick.active {
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  border-color: rgba(167, 139, 250, 0.8);
}

/* Direction indicators on joystick base - using a wrapper approach */
.joystick-dir {
  position: absolute;
  color: rgba(167, 139, 250, 0.25);
  font-size: 11px;
  pointer-events: none;
  line-height: 1;
}
.joystick-dir.dir-up { top: 7px; left: 50%; transform: translateX(-50%); }
.joystick-dir.dir-down { bottom: 7px; left: 50%; transform: translateX(-50%); }
.joystick-dir.dir-left { left: 7px; top: 50%; transform: translateY(-50%); }
.joystick-dir.dir-right { right: 7px; top: 50%; transform: translateY(-50%); }

/* D-Pad */
.touch-pad {
  display: none; /* Hidden by default, joystick preferred */
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.touch-row {
  display: flex;
  gap: 6px;
}

.touch-btn {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 16px;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: rgba(255, 255, 255, 0.8);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: background 0.1s, transform 0.1s;
}

.touch-btn:active {
  background: rgba(99, 102, 241, 0.45);
  transform: scale(0.92);
}

/* Show touch controls on touch devices */
@media (hover: none) and (pointer: coarse) {
  #touch-controls {
    display: flex !important;
  }
  /* On wider phones, show joystick; on narrow phones, show d-pad */
  #joystick-zone {
    display: flex;
  }
}

/* Small phones: switch to D-Pad (more compact) */
@media (max-width: 360px) {
  #joystick-zone {
    display: none !important;
  }
  .touch-pad {
    display: flex !important;
  }
  .touch-btn {
    width: 56px;
    height: 56px;
    font-size: 18px;
  }
}

/* General mobile responsive */
@media (max-width: 480px) {
  .hud-item {
    min-width: 120px;
    font-size: 11px;
    padding: 4px 8px;
  }
  .hud-label { font-size: 12px; }
  .hud-stat { font-size: 10px; }
  .overlay-box h1 { font-size: 22px; }
  .overlay-box { padding: 20px 16px; }
  .big-btn { font-size: 15px; padding: 12px 24px; }
}
