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

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(180deg, #1a0a0a 0%, #2d1515 50%, #1a0a0a 100%);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(255, 80, 20, 0.3), 0 0 120px rgba(200, 40, 0, 0.2);
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  background: #0d0505;
  cursor: none;
  max-width: 100%;
  width: auto;
  height: auto;
  aspect-ratio: 800 / 600;
  object-fit: contain;
}

@media (pointer: fine) {
  #game-canvas {
    cursor: none;
  }
}

@media (pointer: coarse) {
  #game-canvas {
    cursor: default;
  }
}

#game-canvas.hidden {
  visibility: hidden;
}

/* 手機版：留邊，遊戲畫面縮小，讓底座與主角全身都看得見 */
body.touch-device #game-container {
  padding: 12px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
}
body.touch-device #game-canvas {
  max-height: 100dvh;
  max-width: 98vw;
}

/* HUD */
#hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}

#level-display {
  font-size: 1rem;
  font-weight: 700;
  color: #ffaa44;
  margin-right: 12px;
  text-shadow: 0 0 8px rgba(255, 140, 50, 0.8);
}

#score-display {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ff6b35;
  text-shadow: 0 0 10px rgba(255, 100, 50, 0.8);
}

/* Overlay screens */
#start-screen,
#game-over-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(10, 2, 2, 0.92);
  z-index: 10;
  padding: 2rem;
  padding: max(2rem, env(safe-area-inset-top)) max(2rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left));
}

#game-over-screen {
  display: none;
}

#game-over-screen.visible {
  display: flex;
}

#start-screen h1,
#game-over-screen h1 {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  background: linear-gradient(180deg, #ff6b35, #ff3d00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

#start-screen p,
#game-over-screen p {
  color: #ccc;
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
}

.controls-hint {
  color: #888;
  font-size: 0.95rem;
  margin-bottom: 2rem;
  text-align: center;
}

.controls-hint span {
  color: #ff6b35;
  font-weight: 600;
}

.touch-only {
  display: none !important;
}

body.touch-device .touch-only {
  display: block !important;
}

body.touch-device #keyboard-hint {
  display: none !important;
}

#start-btn,
#restart-btn {
  padding: 0.9rem 2.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #ff6b35, #e63900);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow: 0 4px 20px rgba(255, 80, 20, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#start-btn:hover,
#restart-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(255, 80, 20, 0.5);
}

#start-btn:active,
#restart-btn:active {
  transform: scale(0.98);
}

#final-score {
  font-size: 1.5rem;
  color: #ff6b35 !important;
  font-weight: 700;
  margin-bottom: 1.5rem !important;
}

/* Touch control: 向左在左邊、向右在右邊（橫放時左鍵左側、右鍵右側），貼齊畫面最下方 */
#touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  z-index: 5;
  pointer-events: none;
}

#touch-controls button {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  pointer-events: auto;
  width: 100px;
  height: 100px;
  min-width: 100px;
  min-height: 100px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.92);
  font-size: 2rem;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
}

#touch-left {
  left: max(20px, env(safe-area-inset-left));
}

#touch-right {
  right: max(20px, env(safe-area-inset-right));
}

#touch-controls button:active {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(0.96);
}

@media (max-width: 480px) {
  #touch-controls button {
    width: 88px;
    height: 88px;
    min-width: 88px;
    min-height: 88px;
    font-size: 1.75rem;
  }
}
