:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 20% 20%, #1e293b, #020617 70%);
  color: #e2e8f0;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.game-shell {
  width: min(100vw, 1000px);
  padding: 1rem;
  text-align: center;
  position: relative; /* Anchor for HUD */
}

h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.2rem, 2.8vw, 2rem);
  letter-spacing: 0.03em;
}

#gameCanvas {
  width: 100%;
  height: auto;
  border: 2px solid #334155;
  border-radius: 10px;
  display: block;
  background: #0f172a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.help {
  margin: 0.75rem 0 0;
  color: #cbd5e1;
  font-size: 0.92rem;
}

/* Touch HUD */
#touchHud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Let clicks pass through to canvas if not on buttons */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 10;
}

.hud-btn {
  position: absolute;
  pointer-events: auto;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(30, 41, 59, 0.6);
  color: #f1f5f9;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: transform 0.1s, background 0.1s;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.hud-btn:active {
  transform: scale(0.95);
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255, 255, 255, 0.6);
}

.hud-btn.large {
  width: clamp(64px, 12vw, 96px);
  height: clamp(64px, 12vw, 96px);
  font-size: clamp(12px, 3vw, 16px);
}

.hud-btn.small {
  width: clamp(40px, 7vw, 56px);
  height: clamp(40px, 7vw, 56px);
  font-size: clamp(14px, 4vw, 20px);
}

.top-left {
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
}

.top-right {
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
}

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

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

/* Rotate Overlay */
#rotateOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(2, 6, 23, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  color: #f1f5f9;
  text-align: center;
  transition: opacity 0.3s;
}

#rotateOverlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.rotate-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.rotate-icon {
  font-size: 4rem;
  animation: rotate-anim 2s infinite ease-in-out;
}

@keyframes rotate-anim {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(90deg); }
  75% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

/* Hide help text on small screens */
@media (max-width: 600px) {
  .help {
    display: none;
  }
}

/* Fullscreen Button */
.fullscreen-btn {
  position: absolute;
  bottom: max(120px, env(safe-area-inset-bottom) + 80px);
  right: max(20px, env(safe-area-inset-right));
  width: clamp(40px, 6vw, 56px);
  height: clamp(40px, 6vw, 56px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(30, 41, 59, 0.6);
  color: #f1f5f9;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 4vw, 20px);
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: transform 0.1s, background 0.1s;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 15; /* Above HUD, below rotate overlay */
  pointer-events: auto;
}

.fullscreen-btn:hover,
.fullscreen-btn:focus {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255, 255, 255, 0.6);
  transform: scale(1.05);
}

.fullscreen-btn:active {
  transform: scale(0.95);
  background: rgba(30, 41, 59, 0.9);
}

/* Portrait lock: when rotateOverlay is shown, disable in-game touch HUD and fullscreen button */
.portrait-lock #touchHud {
  display: none;
}

.portrait-lock .fullscreen-btn {
  display: none;
}
