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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: "Courier New", Courier, monospace;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
}

#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#touch-controls.hidden { display: none; }

#joystick-zone,
#action-buttons,
#btn-start,
#btn-pause {
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#joystick-zone {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 110px;
  height: 110px;
  border: 2px solid rgba(255, 140, 0, 0.5);
  border-radius: 50%;
  background: rgba(0, 40, 0, 0.35);
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 140, 0, 0.85);
  border: 2px solid #fff;
}

#action-buttons {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#action-buttons button,
#btn-start,
#btn-pause {
  min-width: 72px;
  min-height: 48px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  color: #000;
  background: #ff8c00;
  border: 2px solid #fff;
  border-radius: 8px;
}

#btn-start {
  position: absolute;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: none;
  min-width: 200px;
  min-height: 56px;
  font-size: 16px;
  z-index: 12;
}

#btn-pause {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: none;
  min-width: 64px;
  min-height: 36px;
  font-size: 12px;
}

body[data-scene="title"] #btn-start,
body[data-scene="end"] #btn-start { display: block; }

body[data-scene="play"] #btn-pause { display: block; }

body[data-scene="title"] #joystick-zone,
body[data-scene="end"] #joystick-zone,
body[data-scene="title"] #action-buttons,
body[data-scene="end"] #action-buttons {
  display: none;
}

#action-buttons button:active,
#btn-start:active,
#btn-pause:active { background: #ffa533; }

#btn-motion.active { background: #7cfc00; }

#motion-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 32, 0, 0.95);
  border: 2px solid #ff8c00;
  color: #fff;
  padding: 16px;
  z-index: 20;
  min-width: 260px;
  text-align: center;
}

#motion-panel.hidden { display: none; }

#motion-panel p { margin-bottom: 12px; font-size: 13px; line-height: 1.4; }

#motion-panel button {
  margin: 6px;
  padding: 8px 14px;
  font-family: inherit;
  background: #ff8c00;
  border: 2px solid #fff;
  color: #000;
  font-weight: bold;
}

#motion-panel label {
  display: block;
  margin-top: 10px;
  font-size: 12px;
}

#rotate-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  color: #ff8c00;
  font-size: 18px;
  z-index: 30;
}

#rotate-hint.hidden { display: none; }