/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-color: #080c16;
  --border-color: #0f3460;
  --accent-gold: #ffd700;
  --accent-crimson: #e94560;
  --accent-green: #4caf50;
  --canvas-w: 700px;
  --canvas-h: 550px;
}

body {
  background: var(--bg-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Press Start 2P', 'Segoe UI', 'Noto Sans TC', system-ui, sans-serif;
  color: #fff;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#game-wrapper {
  text-align: center;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}

.game-title {
  font-size: 1.5rem;
  margin-bottom: 8px;
  letter-spacing: 2px;
  font-weight: 700;
  text-shadow: 0 0 12px rgba(76, 175, 80, 0.7);
  color: #e0f2fe;
}

/* ===== HUD ===== */
#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: linear-gradient(135deg, #131b2e, #1a2238);
  border-radius: 12px 12px 0 0;
  width: var(--canvas-w);
  max-width: 100vw;
  font-size: 0.95rem;
  border: 2px solid var(--border-color);
  border-bottom: none;
  box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.1);
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-label {
  color: #94a3b8;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-value {
  font-weight: bold;
  color: var(--accent-gold);
  font-size: 1.15rem;
  font-family: 'Courier New', Courier, monospace;
}

.high-score {
  color: var(--accent-crimson);
}

#lives-display {
  letter-spacing: 2px;
}

.icon-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #f8fafc;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: #334155;
  border-color: #64748b;
  transform: scale(1.05);
}

/* ===== Game Screen & Canvas Container ===== */
#canvas-container {
  position: relative;
  width: var(--canvas-w);
  height: var(--canvas-h);
  max-width: 100vw;
  background: #000;
  border: 2px solid var(--border-color);
  border-radius: 0 0 12px 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

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

/* Screen shake for feedback */
@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, 1px); }
  80% { transform: translate(3px, -1px); }
}

#canvas-container.shake {
  animation: screenShake 0.3s ease-out;
}

/* ===== Overlays (Start, Win, GameOver) ===== */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 11, 25, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(6px);
  padding: 20px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

.overlay::before,
.overlay::after {
  content: '';
  margin: auto;
}

.overlay.hidden {
  display: none !important;
}

.overlay h2 {
  font-size: 2.2rem;
  margin-bottom: 12px;
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 215, 0, 0.6);
  letter-spacing: 2px;
}

.overlay p {
  font-size: 1rem;
  margin: 6px 0;
  color: #cbd5e1;
}

.overlay .highlight {
  color: var(--accent-gold);
  font-weight: bold;
  font-size: 1.4rem;
  font-family: 'Courier New', monospace;
}

.instructions-box {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 14px 20px;
  margin: 14px 0;
  text-align: left;
  line-height: 1.8;
  max-width: 480px;
  width: 100%;
  font-size: 0.9rem;
}

.instructions-box kbd {
  background: #334155;
  border: 1px solid #64748b;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.85rem;
  color: #f1f5f9;
}

.bear-preview-box {
  margin: 10px 0;
}

.btn-group {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.btn {
  padding: 12px 28px;
  font-size: 1.1rem;
  font-weight: bold;
  background: linear-gradient(135deg, #e94560, #c62828);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  letter-spacing: 1px;
  box-shadow: 0 4px 14px rgba(233, 69, 96, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(233, 69, 96, 0.6);
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: linear-gradient(135deg, #334155, #1e293b);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.btn-secondary:hover {
  box-shadow: 0 6px 20px rgba(71, 85, 105, 0.4);
}

.toast {
  margin-top: 10px;
  padding: 6px 14px;
  background: #059669;
  color: white;
  border-radius: 6px;
  font-size: 0.85rem;
  display: none;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Mobile Virtual Controls ===== */
#mobile-controls {
  display: none;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

.d-btn {
  width: 64px;
  height: 64px;
  font-size: 1.8rem;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 2px solid #334155;
  color: #f8fafc;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.1s, transform 0.1s;
}

.d-btn:active {
  background: #3b82f6;
  border-color: #60a5fa;
  transform: scale(0.94);
}

/* ===== Responsive Adaptations ===== */
@media (max-width: 740px) {
  :root {
    --canvas-w: 96vw;
    --canvas-h: calc(96vw * 550 / 700);
  }
  .game-title {
    font-size: 1.15rem;
  }
  #mobile-controls {
    display: grid;
  }
  #hud {
    font-size: 0.85rem;
    padding: 8px 12px;
  }
  .hud-value {
    font-size: 1rem;
  }
  .overlay {
    padding: 10px 8px;
  }
  .overlay h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }
  .bear-preview-box {
    margin: 4px 0;
  }
  .bear-preview-box canvas {
    width: 44px;
    height: 44px;
  }
  .overlay p {
    font-size: 0.82rem;
    margin: 2px 0;
  }
  .instructions-box {
    padding: 6px 10px;
    margin: 6px 0;
    line-height: 1.4;
    font-size: 0.75rem;
  }
  .instructions-box p {
    margin: 2px 0;
  }
  .btn {
    padding: 8px 18px;
    font-size: 0.95rem;
  }
}
